2016年12月27日 星期二

OTF轉TTF

google 的NotoSans字型,都只有OTF格式的,有些軟體只吃TTF,這樣就沒辦法用很麻煩,網路上有些地方有下載TTF格式的,但如果OTF那邊有更新就對應不到,因此想找個轉換方式。

後來找到這個指令

otfccdump input.otf | otfcc-c2q | otfccbuild -o output.ttf

otfccdump和 otfccbuild
來源是:
https://github.com/caryll/otfcc

前面是把otf轉成json,後面是把json build成ttf

中間的otfcc-c2q不確定是做什麼用的,感覺好像是把cubic轉成quad,但這個我在mac上一直裝不起來。
下載和安裝方法在:
https://github.com/caryll/otfcc-cubic2quad

我下npm install -g otfcc-c2q 在mac上裝完後,執行會有
這個env: node\r: No such file or directory問題,我再用dos2unix把裡面的js檔做轉換,結果又出現另一個 error
/usr/local/lib/node_modules/otfcc-c2q/ctq.js:65
var quadzs = cubicToQuad(z1.x, z1.y, z2.x, z2.y, z3.x, z3.y, z4.x, z4.y, 0.5);
                                                              ^

TypeError: Cannot read property 'x' of undefined

後來把otfcc-c2q拿掉,ttf一樣建得出來,所以不知會有什麼問題....


2015年12月4日 星期五

筆記 touch 設定

1.修改 /etc/system/config/scaling.conf
2.修改 /scirpts/hid-start.sh
 #usb touch
  devi-hid -P -r -R1024,768 touch;
 3.修改 /usr/lib/graphics/graphics.conf
  找到mtouch
    driver = devi
    options = height=768,width=1024,poll=1000
    display=1
 #   driver = lg-tsc101
 #   options = poll=1,verbose=3,skip_idle_disable=1,max_touchpoints=10

2015年9月18日 星期五

closure

之前在C#中聽過這個,但一直不知道是幹嘛用的。 現在又在lua中看到,想徹底了解一下。
    function newCounter ()
      local i = 0
      return function ()   -- anonymous function
               i = i + 1
               return i
             end
    end
    
    c1 = newCounter()
    print(c1())  --> 1
    print(c1())  --> 2

    c2 = newCounter()
    print(c2())  --> 1
    print(c1())  --> 3
    print(c2())  --> 2
這裡anonymous function使用了一個local variable i 去記count。但照理說已經離開了這個function的scope,這個i應該被清掉,而不是作用像個static variable。 這個i被視為一個up value 或又稱作是external local variable。 而當assign一個新的newCounter時,又會產生一個新的i。 "Technically speaking, what is a value in Lua is the closure, not the function. The function itself is just a prototype for closures." 因為 lua 的function被視為是first-class values。根據wiki 所謂的first-class function: "函數可以作為別的函數的參數、函數的返回值,賦值給變量或存儲在資料結構中。" 我想這種return anonymous function的做法像c1,c2 都被稱作是closure。 參考自 http://www.lua.org/pil/6.1.html

2015年4月8日 星期三

YUY420toRGB24 Shader

//shader
uniform sampler2D y_tex;
uniform sampler2D u_tex;
uniform sampler2D v_tex;
varying mediump vec2 vTexCoord;

const mediump vec3 R_cf = vec3(1.164383,  0.000000,  1.596027);
const mediump vec3 G_cf = vec3(1.164383, -0.391762, -0.812968);
const mediump vec3 B_cf = vec3(1.164383,  2.017232,  0.000000);
const mediump vec3 offset = vec3(-0.0625, -0.5, -0.5);
  
void main()
{
    precision mediump float;
    float y = texture2D(y_tex, vTexCoord).a;
    float u = texture2D(u_tex, vTexCoord).a;
    float v = texture2D(v_tex, vTexCoord).a;
    vec3 yuv = vec3(y,u,v);
    yuv += offset;
    gl_FragColor = vec4(0.0, 0.0, 0.0, 1.0);
    gl_FragColor.r = dot(yuv, R_cf);
    gl_FragColor.g = dot(yuv, G_cf);
    gl_FragColor.b = dot(yuv, B_cf);
} 

//init
 result = kzuSharedImageTextureCreate(kzuUIDomainGetResourceManager(kzuObjectNodeGetUIDomain(layerNode)), "video Y texture", 
   KZU_TEXTURE_CHANNELS_ALPHA, VideoGetWidth(video), VideoGetHeight(video), KZ_NULL,
   KZ_NULL, KZ_FALSE, &videoPlayer->y_texture);

 kzuTextureSetFilter(kzuSharedImageTextureToTexture(videoPlayer->y_texture), KZU_TEXTURE_FILTER_POINT_SAMPLE);

 result = kzuSharedImageTextureCreate(kzuUIDomainGetResourceManager(kzuObjectNodeGetUIDomain(layerNode)), "video U texture", 
   KZU_TEXTURE_CHANNELS_ALPHA, VideoGetWidth(video)/2, VideoGetHeight(video)/2, KZ_NULL,
   KZ_NULL, KZ_FALSE, &videoPlayer->u_texture);

 kzuTextureSetFilter(kzuSharedImageTextureToTexture(videoPlayer->u_texture), KZU_TEXTURE_FILTER_POINT_SAMPLE);

 result = kzuSharedImageTextureCreate(kzuUIDomainGetResourceManager(kzuObjectNodeGetUIDomain(layerNode)), "video V texture", 
   KZU_TEXTURE_CHANNELS_ALPHA, VideoGetWidth(video)/2, VideoGetHeight(video)/2, KZ_NULL,
   KZ_NULL, KZ_FALSE, &videoPlayer->v_texture);

 kzuTextureSetFilter(kzuSharedImageTextureToTexture(videoPlayer->v_texture), KZU_TEXTURE_FILTER_POINT_SAMPLE);

 struct KzuPropertyType* y_tex = kzuPropertyRegistryFindPropertyType("y_tex");
 struct KzuPropertyType* u_tex = kzuPropertyRegistryFindPropertyType("u_tex");
 struct KzuPropertyType* v_tex = kzuPropertyRegistryFindPropertyType("v_tex");
 
 result = kzuObjectNodeSetResourceIDResourceProperty(layerNode, y_tex,  kzuSharedImageTextureToResource(videoPlayer->y_texture));
 result = kzuObjectNodeSetResourceIDResourceProperty(layerNode, u_tex,  kzuSharedImageTextureToResource(videoPlayer->u_texture));
 result = kzuObjectNodeSetResourceIDResourceProperty(layerNode, v_tex,  kzuSharedImageTextureToResource(videoPlayer->v_texture));


//update
  result = kzuSharedImageTextureLock(videoplayer->y_texture);
  result = kzuSharedImageTextureLock(videoplayer->u_texture);
  result = kzuSharedImageTextureLock(videoplayer->v_texture);
  kzsErrorForward(result);
  result = kzuSharedImageTextureUpdate(videoplayer->y_texture, (kzByte*)data[0], videoWidth * videoHeight);
  kzsErrorForward(result);

  result = kzuSharedImageTextureUpdate(videoplayer->u_texture, (kzByte*)data[1], videoWidth * videoHeight / 4);
  kzsErrorForward(result);
  result = kzuSharedImageTextureUpdate(videoplayer->v_texture, (kzByte*)data[2], videoWidth * videoHeight / 4);
  kzsErrorForward(result);
  result = kzuSharedImageTextureUnlock(videoplayer->y_texture);
  result = kzuSharedImageTextureUnlock(videoplayer->u_texture);
  result = kzuSharedImageTextureUnlock(videoplayer->v_texture);
  kzsErrorForward(result);

2015年3月23日 星期一

Kanzi 在QNX video capture的問題

本來想用Kanzi的記憶體管理來建立Capture buffer 的大小,參考vcapture的例子,影像是用SCREEN_FORMAT_YUY2的格式。

大小應該是width*height*2

但這樣做,一直有random的crash或是不正常的綠邊,後來改自行malloc,但也不正確,影像會抖得很厲害。


最後只能用它的screen來create,才會得到穩定的效果

rc = screen_get_buffer_property_pv(video->screen_buf[i], SCREEN_PROPERTY_POINTER, &(video->pointers[i]));

推測是抓回來的capture data不只有yuy2的data,可能還有些其它的東西,導致size不大一樣。


但是即使這樣,畫面仍會規律的抖動。印log一直有drop frame的狀況。

經過很多交叉測試,發現是我用軟體做yuy2 to RGB24,速度太慢,導致會抖動。

後來只能用Shader來做。

每個frame不做軟體decode,把raw的fame data 傳到shader裡。

return (kzByte*)video->pointers[buf_idx];

因為是yuy2的格式,剛好找到一個Nvidia的Demo有提供一個轉換的shader

首先在kanzi那建立format為KZU_TEXTURE_CHANNELS_LUMINANCE_ALPHA的貼圖。
result = kzuSharedImageTextureCreate(kzuUIDomainGetResourceManager(kzuObjectNodeGetUIDomain(layerNode)), "video texture",
KZU_TEXTURE_CHANNELS_LUMINANCE_ALPHA, VideoCaptureGetWidth(video), VideoCaptureGetHeight(video), KZ_NULL,
KZ_NULL, KZ_FALSE, &videoCapturePlayer->texture);

update時把它寫入
result = kzuSharedImageTextureUpdate(videoCapturePlayer->texture, data, videoWidth * videoHeight * 2);


uniform sampler2D Texture;
uniform sampler2D TextureMask;
uniform lowp float BlendIntensity;
uniform lowp vec4 Ambient;
varying mediump vec2 vTexCoord;
varying highp vec2 vScreenPos;

// CCIR 601 standard
const mediump vec3 std601R = vec3(  1.0, -0.00092674, 1.4017        );
const mediump vec3 std601G = vec3(  1.0, -0.3437,    -0.71417    );
const mediump vec3 std601B = vec3( 1.0,  1.7722,     0.00099022         );
const mediump vec4 stdbias = vec4(  0, -0.5,       -0.5, 0       );

void main()
{
    precision mediump float;
 vec2 uv0, uv1;    
    float SrcTexWidth=720.0;
    float texel_sample = 1.0 / (SrcTexWidth);
    //float isOddUV = floor(fract((vTexCoord.x * SrcTexWidth) * 0.5) * 2.0);
    float isOddUV = fract(floor(vTexCoord.x * SrcTexWidth) * 0.5) * 2.0;
    uv0 = vTexCoord;
    uv1 = vTexCoord;
 //   vec2 screen_uv = vScreenPos.xy/vScreenPos.w;
  //  screen_uv = (screen_uv.xy + vec2(1.0)) / 2.0;
    // If (x,y) address is ODD,  then we need the (x-1,y) sample to decode it
    // If (x,y) address is EVEN, then we need the (x+1,y) sample to decode it.
 uv0.x = vTexCoord.x - (isOddUV * texel_sample);
 uv1.x = vTexCoord.x + texel_sample;
 uv1.y = vTexCoord.y;

 // we sample the neighboring texture samples
 vec4 texColor0 = texture2D( Texture, uv0 );
 vec4 texColor1 = texture2D( Texture, uv1 );
 vec4 mask = texture2D(TextureMask,vScreenPos);
 // For A8L8, assume A8<-alpha L8<-rgb
 texColor0.r = texColor0.r; // assign Y0 (1st position) automatic
 texColor0.g = texColor0.a; // assign U0 (2nd position)
 texColor0.b = texColor1.a; // assign V0 (3rd position)
 
 texColor1.r = texColor1.r; // assign Y1 (1st position) automatic
 texColor1.g = texColor0.a; // assign U0 (2nd position)
 texColor1.b = texColor1.a; // assign V0 (3rd position)
 
 // assume RGBA0 (Y0 U0)
 // assume RGBA1 (Y1 V0)
    // Let's just average the luma, to make it simple 
 texColor0 += stdbias;
 texColor0 *= (1.0-isOddUV);

 // assume RGBA0 (Y0 U0)
 // assume RGBA1 (Y1 V0)
 texColor1 += stdbias; 
 texColor1 *= (isOddUV);
 
 texColor0 = texColor0 + texColor1;
 vec4 color = vec4((texColor0.r + 1.37075*texColor0.b),
         (texColor0.r - (0.698001 *texColor0.b-0.337633*texColor0.g)),
           (texColor0.r +  1.73246*texColor0.g),
           1.0 );
           
    //vec4 color = vec4(dot(std601R, texColor0.rgb),
        //   dot(std601G, texColor0.rgb),
        //   dot(std601B, texColor0.rgb),
        //   1.0 );
   gl_FragColor.rgba = clamp(color.rgba,0.0,1.0);// *Ambient* BlendIntensity;
   gl_FragColor.a *=  ((1.0-mask.a));
    
}

不過,出來的顏色很奇怪。試了不同的轉換matrix都一樣,只好展開用微調的...猜測可能是kanzi在寫入sharetexutre時有做gamma correct,因為我找不到地方可以關掉,也不知道它有沒做,文件裡沒寫,只好先將就一下了...

2014年11月12日 星期三

QNX graphic path on vmware

整理筆記一下....
QNX® Software Development Platform 6.6 Graphics Patch [Patch ID 3875]

download下來後在pc上
參考
在command line執行下面bat設定環境變數
base_directory\qnx660-env.bat
再apply patch
applypatch -F download_path/patch-660-3875-660-Graphics-GA.tar

vmware上設置

1‧設定環境變數
  export GRAPHICS_ROOT=/usr/lib/graphics/vmware/
  export LD_LIBRARY_PATH=/usr/lib:/lib:/lib/dll:$GRAPHICS_ROOT:$LD_LIBRARY_PATH

2.copy patch的file到vmware。
  我先mount到pc下的share,並把相關的patch檔copy過去。

cp -f etc/system/config/scaling.conf /etc/system/config/scaling.conf
cp -f usr/share/gles/textures/brick_wall.tga /usr/share/gles/textures/brick_wall.tga
cp -f usr/share/gles/textures/bubble.png /usr/share/gles/textures/bubble.png
cp -f usr/share/images/wallpaper.jpg /usr/share/images/wallpaper.jpg
cp -f x86/bin/screeninfo /bin/screeninfo
cp -f x86/lib/dll/libwfdcfg-sample.so /lib/dll/libwfdcfg-sample.so
cp -f x86/lib/dll/screen-gles1.so /lib/dll/screen-gles1.so
cp -f x86/lib/dll/screen-gles2blt.so /lib/dll/screen-gles2blt.so
cp -f x86/lib/dll/screen-gles2.so /lib/dll/screen-gles2.so
cp -f x86/lib/dll/screen-sw.so /lib/dll/screen-sw.so
cp -f x86/lib/libgestures.so.1 /lib/libgestures.so.1
cp -f x86/lib/libinputevents.so.1 /lib/libinputevents.so.1
cp -f x86/lib/libkalman.so.1 /lib/libkalman.so.1
cp -f x86/lib/libmtouch-calib.so.1 /lib/libmtouch-calib.so.1
cp -f x86/lib/libmtouch-devi.so.1 /lib/libmtouch-devi.so.1
cp -f x86/lib/libmtouch-fake.so.1 /lib/libmtouch-fake.so.1
cp -f x86/lib/libmtouch-inject.so.1 /lib/libmtouch-inject.so.1
cp -f x86/sbin/gpu_drv /sbin/gpu_drv
cp -f x86/sbin/screen /sbin/screen
cp -f x86/usr/bin/calib-touch /usr/bin/calib-touch
cp -f x86/usr/bin/display_image /usr/bin/display_image
cp -f x86/usr/bin/egl-configs /usr/bin/egl-configs
cp -f x86/usr/bin/events /usr/bin/events
cp -f x86/usr/bin/font-freetype /usr/bin/font-freetype
cp -f x86/usr/bin/gles1-gears /usr/bin/gles1-gears
cp -f x86/usr/bin/gles2-gears /usr/bin/gles2-gears
cp -f x86/usr/bin/gles2-maze /usr/bin/gles2-maze
cp -f x86/usr/bin/gpudbg /usr/bin/gpudbg
cp -f x86/usr/bin/print-gestures /usr/bin/print-gestures
cp -f x86/usr/bin/screenshot /usr/bin/screenshot
cp -f x86/usr/bin/sw-vsync /usr/bin/sw-vsync
cp -f x86/usr/bin/vkey /usr/bin/vkey
cp -f x86/usr/bin/yuv-test /usr/bin/yuv-test
cp -f x86/usr/lib/graphics/vmware/graphics.conf /usr/lib/graphics/vmware/graphics.conf
cp -f x86/usr/lib/graphics/vmware/libAtcDecompressor.so /usr/lib/graphics/vmware/libAtcDecompressor.so
cp -f x86/usr/lib/graphics/vmware/libAtcDecompressor.so.1 /usr/lib/graphics/vmware/libAtcDecompressor.so.1
cp -f x86/usr/lib/graphics/vmware/libegl_gallium.so /usr/lib/graphics/vmware/libegl_gallium.so
cp -f x86/usr/lib/graphics/vmware/libHwEGL.so /usr/lib/graphics/vmware/libHwEGL.so
cp -f x86/usr/lib/graphics/vmware/libHwglapi.so /usr/lib/graphics/vmware/libHwglapi.so
cp -f x86/usr/lib/graphics/vmware/libHwGLESv1_CM_g.so /usr/lib/graphics/vmware/libHwGLESv1_CM_g.so
cp -f x86/usr/lib/graphics/vmware/libHwGLESv1_CM.so /usr/lib/graphics/vmware/libHwGLESv1_CM.so
cp -f x86/usr/lib/graphics/vmware/libHwGLESv2.so /usr/lib/graphics/vmware/libHwGLESv2.so
cp -f x86/usr/lib/graphics/vmware/libHwGPU.so /usr/lib/graphics/vmware/libHwGPU.so
cp -f x86/usr/lib/graphics/vmware/libHwWFDvmware.so /usr/lib/graphics/vmware/libHwWFDvmware.so
cp -f x86/usr/lib/graphics/vmware/libllvmpipe_drv.so /usr/lib/graphics/vmware/libllvmpipe_drv.so
cp -f x86/usr/lib/graphics/vmware/libmesa_texcompress_atc.so /usr/lib/graphics/vmware/libmesa_texcompress_atc.so
cp -f x86/usr/lib/graphics/vmware/libmesa_texcompress_pvrt.so /usr/lib/graphics/vmware/libmesa_texcompress_pvrt.so
cp -f x86/usr/lib/graphics/vmware/libmesa_texcompress.so /usr/lib/graphics/vmware/libmesa_texcompress.so
cp -f x86/usr/lib/graphics/vmware/libpipe_vmwgfx_drv.so /usr/lib/graphics/vmware/libpipe_vmwgfx_drv.so
cp -f x86/usr/lib/graphics/vmware/libst_HwGL_g.so /usr/lib/graphics/vmware/libst_HwGL_g.so
cp -f x86/usr/lib/graphics/vmware/libst_HwGL.so /usr/lib/graphics/vmware/libst_HwGL.so
cp -f x86/usr/lib/graphics/vmware/libvmwsvga.so /usr/lib/graphics/vmware/libvmwsvga.so
cp -f x86/usr/lib/libEGL.so.1 /usr/lib/libEGL.so.1
cp -f x86/usr/lib/libGLESv1_CL.so.1 /usr/lib/libGLESv1_CL.so.1
cp -f x86/usr/lib/libGLESv1_CM.so.1 /usr/lib/libGLESv1_CM.so.1
cp -f x86/usr/lib/libGLESv2.so.1 /usr/lib/libGLESv2.so.1
cp -f x86/usr/lib/libscreen.so.1 /usr/lib/libscreen.so.1
cp -f x86/usr/lib/libswblit.so.1 /usr/lib/libswblit.so.1
cp -f x86/usr/lib/libWFD.so.1 /usr/lib/libWFD.so.1
cp -f x86/lib/libgestures.so /lib/libgestures.so
cp -f x86/lib/libinputevents.so /lib/libinputevents.so
cp -f x86/lib/libkalman.so /lib/libkalman.so
cp -f x86/lib/libmtouch-calib.so /lib/libmtouch-calib.so
cp -f x86/lib/libmtouch-devi.so /lib/libmtouch-devi.so
cp -f x86/lib/libmtouch-fake.so /lib/libmtouch-fake.so
cp -f x86/lib/libmtouch-inject.so /lib/libmtouch-inject.so
cp -f x86/usr/lib/libEGL.so /usr/lib/libEGL.so
cp -f x86/usr/lib/libGLESv1_CL.so /usr/lib/libGLESv1_CL.so
cp -f x86/usr/lib/libGLESv1_CM.so /usr/lib/libGLESv1_CM.so
cp -f x86/usr/lib/libGLESv2.so /usr/lib/libGLESv2.so
cp -f x86/usr/lib/libscreen.so /usr/lib/libscreen.so
cp -f x86/usr/lib/libswblit.so /usr/lib/libswblit.so
cp -f x86/usr/lib/libWFD.so /usr/lib/libWFD.so
echo "Done!"

注意: 如果從window上編輯上面的成為.sh執行的話,記得要改換行字元,不然到QNX上時檔名結尾會多一個^M。在notepad ++ 的檔案格式轉換可改成unix就不會有這問題。

再執行
gpu_drv
screen
即可



2014年9月29日 星期一

Kanzi: Render Transparent Objects


在Kanzi裡畫半透明物件,比想像中麻煩一點,因為它不是你把物件用半透明材質,然後給個Transparent Queue就會幫你排序做好。

首先,必須在Composing > Pipeline 裡,加一個Property is Equal Filter。在Property Type選blendMode,Operation 選Include,Blend Mode選你的半透明物件所在的Mode。(這邊在弄時有發生怪事,Blend Mode怎麼設都不鳥我,preview視窗重開好幾次也沒用,後來不知怎突然可以用了...)

另一個要注意的點是,它是照物件上的Property排,所以你把BlendMode在Material裡設好,以為用了這個Material就會知道這個屬性。別傻了,它會當你是Opaque的物件....

接者同上步驟建一個畫Opaque的Filter。

然後在Composer建2個render pass 第一個畫Opaque物件。第二個畫半透明的Filter。(在Render Pass的Object Source選剛才的Filter)。把Color Buffer :Clear Enable > false, Depth Buffer: Clear Enable > False,Test Enable打開,Write Enable關掉。


發現怪事了嗎?

ZTest、ZWrite、甚至是Back , Front Culling不在Material上,而是在Render Pass上...WTF....Material要是複雜一點,不是要用一堆Render Pass..... 想到頭皮就發麻....

設完後,疑....排序怎是錯的....原來排序要自己再建一個Sorting Filter,Filter的Source選剛才的Transparent objects。同理,如果用到Tag Filter的話...我已經不敢想那個排列組合了.....

2014年9月24日 星期三

Kanzi StateMachine


在Editor中使用StateMachine 發現幾點要注意的地方

一開始想做一個循環的button,循環某一個State Manager

所以使用Toggle Button。

例如我有5個State,讓Toggle Button也有5個State對應。

首先先將Button中 加入一個Number of Toggle Button屬性,設成5

接著,新增Button: Toggle State 這個Trigger。之後,就對文件中的說明看不懂,試了很久才發現:

1.在Trigger Settings中,新增一個Condition,Property > Button Toggle State, Condition > =, Fixed Value > 0

2. Add一個Set property的Action,把State的值設成0。

3. 5個State的話,就要新增5個Button : Toggle State。

如果要有要使用State Manager: State Entered 這個Trigger的話,要加在Target物件(後面測試State Object跟Target都可以),而不是State Group,也不是Button上。同樣地也要在這個Trigger Setting中,設定Condition,不然只要State改變,都會進去。注意: Condition 中的Message Source要改成target物件。不能用預設值  後來發覺跟Message Source無關,是我的property名稱叫State,如果直接在下拉選單key入state 搜尋,會變成MessageArgument.StateManager.State ,但若在選單裡自己找,用選的,就會是我的state。應該是跟內建的名稱衝到,選到第一個是內建的名稱。

如果要用State Manager改變Target物件的屬性,記得要把Target上的對應屬性移掉。例如,在State Object上有Ambient Color這個屬性,要改變Sphere上的Ambient Color的話,要把Sphere上的Ambient Color 移掉。

這個設定成功後,才發現,原來Trigger 裡有一個State Manager: Go to Preview State 這個屬性。但一開始也試不出來,也沒文件。 後來試出,State Group 名稱設成要用的State Manager下的State Group,再把Dispatch Settings中的Routing Target,設成Target物件 (有State Manager那個)

這樣這個就可以做左右的循環State

後記:又出現問題了....用Go to Preview State的方式,沒辦法讓Target物件用它的State Property來判斷現在是在哪個State,前面的方式無法用。目前還找不到對應的值是什麼。後來用了一個蠢方法,在Property Type再增加一個叫State Name的property。在State Object上加入這個屬性,之後在Target物件上的Condition來判斷這個Name,就可以知道是在哪個State......不知正統的解法什麼

經過測試,在State Object上也可以用trigger知道State Enter,但State Left我搞不懂它的邏輯,在同一個State Object上,設Enter跟Left,在進入這個State時,會同時觸發。感覺是別人Left進這個State.....但又不知是誰的State進來呀 X的.... wtf

 用了一個蠢方式,設一個空Node 叫Pre State,上面有個像之前的StateName property。因為Left會發生在Enter之前,所以在Enter時,用Set Property 把空Node的StateName設定Current的名稱,因為left 進入時還沒更改,所以會抓到pre state,這樣就可以知道從哪State出來了..........應該有標準做法吧...但文件沒寫... x的

2014年9月23日 星期二

QNX專案設定

待補充....

剛建好專案,發覺無法Run。
原因是在Documentation中有一段講Communication with the QNX Neutrino RTOS

似乎在PC上debug也一定要有個平台才行

所以我用VMware跑一個評估版的QNX,ip在192.168.6.128

上面說裡面一定要跑一個qconn 的program, 評估版的本來就有

然後在專案裡,Perspective > QNX System Information
在Target Navigator view裡建一個New QNX Target
輸入剛才的ip,然後Finish

這樣IDE中的執行檔就可以Run

此外,如果發覺編完找不到Library,記得在Project Preference裡,加入Extra的library

(libscreen只要打screen就好,前面的lib不用打。)





2014年9月16日 星期二

從vmware的QNX連到 win7的shared folder

試了很久,google了半天,找不到為何連不過去

後來發現原因,原來是電腦名稱和別人衝到.....把名稱改了後就可以....囧 

在vm 裝評估版的QNX 在Windows開一個Shared folder

例如我的分享資料夾叫 Share, QNX的叫 mnt 然後打

 fs-cifs -l -vvvvvv //電腦名稱:電腦ip:/Share /mnt 

-l 是要輸入user name和password
-v 是debug訊息的多寡

 電腦名稱大小寫沒差
 username大小寫也沒差

2014年9月15日 星期一

Create Image form memory

最近在測試從網路上抓 Google map下來,但不知該怎把抓下來的圖轉成Kanzi可用的。

這個軟體目前資源很少呀,用的人不多,不像Unity3D,可以很簡單就做到。

跟網路的溝通我是用POCO這個library



 std::string url = URIinit();
 URI uri(url);
 std::string path(uri.getPathAndQuery());
 if (path.empty()) path = "/";

 HTTPClientSession session(uri.getHost(), uri.getPort());
 HTTPRequest request(HTTPRequest::HTTP_GET, path, HTTPMessage::HTTP_1_1);
 HTTPResponse response;
 session.sendRequest(request);
 std::istream &is = session.receiveResponse( response );


在Kanzi建立需要的資源:

 
 struct KzuResourceManager* resourceManager 
  = kzuUIDomainGetResourceManager(kzaApplicationGetUIDomain(application));

 struct KzcMemoryManager* memoryManager = kzcMemoryGetManager(resourceManager);
 struct KzcImage* image;
 struct KzuImageTexture* texture;

把拿到的stream轉成 char* buffer再轉成Kanzi 的stream格式。

 std::ostringstream oss( std::ios_base::binary);
 oss << is.rdbuf();
 std::string strConst = oss.str();
 int size = strConst.length();
 
 const char* buffer = strConst.c_str();
 

 kzsException error;
 struct KzcInputStream* outstrem;
 error = kzcInputStreamCreateFromMemory(memoryManager, (kzByte*)buffer, size,  KZC_IO_STREAM_ENDIANNESS_UNSPECIFIED, &outstrem);


再用Kanzi的load png的Api: kzcImageLoadPNG,因為我已經知道抓下來是png的格式,若是其它的,要用其它的函式。之前本來想直接用kzuImageTextureCreateFromMemory,這個函式,但發現抓下來的是png,在設定 KZU_TEXTURE_CHANNELS時會有問題,因為png用的是索引色,不是用R8G8B8這種格式,還要把抓下來的raw data做轉換。
 error = kzcImageLoadPNG(memoryManager, outstrem, false, &image);
 /* Create texture from image. */
 result = kzuImageTextureCreateFromImage(resourceManager, "Widget Texture", 
  image, KZU_TEXTURE_FILTER_BILINEAR, 
  KZU_TEXTURE_WRAP_REPEAT, 0.0f, 
  &texture);
 kzsErrorForward(result);
 struct KzuObjectNode* screenNode 
  = kzuScreenToObjectNode(kzaApplicationGetScreen(application));
 
 struct KzuObjectNode* plane = kzuObjectNodeGetRelative(screenNode, "#Plane");
 result = kzuObjectNodeSetResourceIDResourceProperty(plane, KZU_PROPERTY_TYPE_TEXTURE,  kzuImageTextureToResource(texture));
 kzsErrorForward(result);


如果是直接從file中讀取,也可以用這個方式。之前拿來debug用的。把從網路上抓下來的部分改成下面這段就可以
 std::fstream myfile("myfile.png", std::ios::in | std::ios::binary);
 std::filebuf* pbuf = myfile.rdbuf();
 std::size_t size = pbuf->pubseekoff (0,myfile.end,myfile.in);
 pbuf->pubseekpos (0,myfile.in);
 char* buffer=new char[size];
 // get file data
 pbuf->sgetn (buffer,size);
 myfile.close();


Kanzi C++ project

除了在設定中的:
C/C++
 -Advanced: Compiled as -> 改成 Compiled as C++ Code 外

也要把
-Code Generation: Enable C++ Exceptions 設成 /EHsc

參照:http://msdn.microsoft.com/zh-tw/library/1deeycx5.aspx

如果沒改,在編一些第三方函式庫會編不過...




2014年9月4日 星期四

建立Custom Component

1. 建立自已的KzuUiComponentNodeClass

2. 在configuration->onStartup = startup; 時註冊Factory

3. 為了2. 所以要建2個function:
       a. FactoryCreate //用來create component
       b. RegisterToFactory //用來註冊, 如果有要註冊Custom message也可以寫在這
   這會對應到在Editor中,建立的Custom Component name

4. 如果有要處理Message, Handler加在KzuUiComponentNodeClass的initialize function中。

 要在editor preview的話,編GL_21_release版的,ps:要把Editor關掉才能把dll蓋掉。

註冊custom message


 const struct KzuMessageType* MESSAGE_TEXTUREFONT_CHANGRD;
 {
  struct KzcMemoryManager* memoryManager = kzcMemoryGetManager(factory);
  struct KzuMessageType* messageType;
                
  //Message.Custom.FontChange 對應Editor裡的Custom Message Name
  result = kzuMessageRegistryAddMessageType(memoryManager, "Message.Custom.FontChange", KZU_MESSAGE_ROUTING_TUNNELLING_BUBBLING,        &messageType);
  kzsErrorForward(result);

  MESSAGE_TEXTUREFONT_CHANGRD = messageType;
 }

取得/設定 custom property

 {
    struct KzuPropertyType* UV_SET; 
    struct KzcVector4 uvs;

    //get property type
    UV_SET = kzuPropertyRegistryFindPropertyType("uv_modify");
    kzsAssert(kzcIsValidPointer(UV_SET));

    //get property
    uvs = kzuObjectNodeGetVector4PropertyDefault(textrue_font->planeNode, UV_SET);
    uvs.data[0] = (kzFloat)(uv_sets[index].x);
    uvs.data[1] = (kzFloat)(uv_sets[index].y);
    uvs.data[2] = (kzFloat)(uv_sets[index].z);
    uvs.data[3] = (kzFloat)(uv_sets[index].w);

    //set property
    result = kzuObjectNodeSetVector4Property(textrue_font->planeNode, UV_SET, uvs);
    kzsErrorForward(result);
}
在scene node底下的mesh的material,可以從node就直接get property來set,不用去get它的material

2014年8月15日 星期五

linux筆記

ldap.arcade.igs.com.tw

rm -rf 刪資料夾
新系統剛開始用時
vi /etc/ssh/sshd_config

PermitRootLogin yes
PermitEmptyPasswords yes

/etc/init.d/sshd restart


/etc/init.d/ntpd stop          //停止與其它人同步
ntpdate 10.1.1.254             //與server同步

svn co http://rd601/svn/pt/trunk trunk
svn update //要在code2端
chmod -R 777../
Xorg&
xterm&   //& 在背景執行

//ssh root@10.3.10.245 -p 412
ssh test@10.1.0.75 -p 412
ssh test@10.3.10.245 -p 22
password : linnet
su  //取得root
mount -t cifs -o username=brianchang,noserverino //10.1.254.52/brianchang /mnt

mount /dev/sdb1 /mnt

find ./ -name .svn -exec rm -rf '{}' \;
find . -type d -name ".svn"|xargs rm -rf

\\10.1.254.52 --> new code2 position

改開機default選項

mongo 筆記

http://docs.mongodb.org/manual/reference/operator/update/rename/
rename:

{
"occupation":"Doctor",
"name": {
   "first":"Jimmy",
   "additional":"Smith"
}

db.foo.update({}, {$rename:{"name.additional":"name.last"}}, false, true);
remap = function (x) {
  if (x.additional){
    db.foo.update({_id:x._id}, {$set:{"name.last":x.name.additional}, $unset:{"name.additional":1}});
  }
}

db.foo.find().forEach(remap);

db.students.update( { _id: 1 }, { $rename: { "nmae": "name" } } )
#rename all field
db.user.update({}, {$rename: {"session.play_data.Attack":"session.play_data.Power"}}, false, true)
#add all field
db.user.update({}, set{"session.play_data.Denfense":0}}, true, true)
[remove]
db.expTable.remove({'_id':ObjectId("52b29b8f5d89c90330cc23ad")})

#remove all documents in collection
db.expTable.remove()
#remove collections
db.expTable.drop()

[backup]
在command line下
mongodump --host 192.168.132.62 --port 27017 --out /backup/mongo-2013-01-17
#會存在 C:/backup/mongo-2013-01-17/
================[pymongo]================
from bson.objectid import ObjectId
#mike is a cursour
mike = testDB['posts'].find({'_id':ObjectId('52b144545d87c91b605dfca9')})

#modify a item
item = testDB['posts'].find({'_id':ObjectId('52b144545d87c91b605dfca9')})
item = item[0]
item['text'] = "haha"
testDB['posts'].save(item)

or

item = testDB['posts'].find_one({'_id':ObjectId('52b144545d87c91b605dfca9')})
testDB['posts'].update({'_id':ObjectId('52b144545d87c91b605dfca9')}, {"$set":{"text":"UCCU"}})

git 筆記

workdirectory --> Stage/Index --> repository --> Server
              add            commit          push

在專案底下使用 git init 開始一個新的 Git repo.

新增遠端儲存庫
git remote add [shortname] [url]
git remote add origin git@bitbucket.org:username/c-practice.git
欲從遠端擷取資料
$ git fetch [remote-name]

$ git push origin master 想要上傳 master 分支到 origin 伺服器

.gitignore
空白列或者以#開頭的列會被忽略
# 不要追蹤檔名為 .a 結尾的檔案
*.a
# 但是要追蹤 lib.a,即使上方已指定忽略所有的 .a 檔案
!lib.a
# 只忽略根目錄下的 TODO 檔案。 不包含子目錄下的 TODO
/TODO
# 忽略build/目錄下所有檔案
build/
# 忽略doc/notes.txt但不包含doc/server/arch.txt
doc/*.txt
# ignore all .txt files in the doc/ directory
doc/**/*.txt
#從repo中移掉某檔但不刪除
git rm --cached mylogfile.log
#add modify files, ingore untracked
git add -u (--update)
#add all files
git add -A
git commit -am  (add modify/delete file. not include untracked file)
同等於
git add -u, git commit -m

#checkout -> 移動Head的位置 到某個branch -b:若沒這個branch就建一個
git checkout -b Brian
#把 那個file revert
git checkout -- Assets/Artworks/Textures/girl.png.meta
同等於
git branch Brian
git checkout Brian
#把stage中某個file移掉
git reset filename

看某個file比較
git diff

2014年7月7日 星期一

GGX BRDF

最近很流行 也來試作一下
float G_Smith(float roughness, float NoV, float NoL)
   {
    //Schlich model
    //G(l,v,h) = G1(l)G1(v)
     float  k = (roughness + 1) * (roughness + 1) /8;
    return  (NoV / (NoV * (1 - k) + k)) *  (NoL / (NoL * (1 - k) + k));
   }
   
   fixed4 GGX_BRDF(float roughness, half3 lightDir, half3 viewDir, float3 Normal, fixed3 specularColor, fixed3 diffuseColor, fixed3 lightColor)
   {
      float pi = 3.14159;
      viewDir = normalize(viewDir);
      lightDir = normalize(lightDir);
      half3 h = normalize (lightDir + viewDir);
      float NdotL = max(0, dot ( Normal, lightDir));
      float NdotH = max (0, dot (Normal, h));
      float NdotV = max(0, dot(Normal, viewDir));
      float LdotH = max(0, dot(lightDir, h));
      float VdotH = max(0 , dot(viewDir, h));
      float3 Kd = 0;
          lightColor.rgb *= NdotL;
          Kd = diffuseColor * _MainColor / pi;
          half4 c;
          c.rgb = Kd * lightColor;
          
          //GGX NDF          
          float alpha =  roughness *  roughness;
          float beta = ((NdotH * NdotH) * (alpha*alpha -1.0) + 1.0);
          float Specular_D =  alpha * alpha/ (pi * beta * beta);
          fixed3 f0 = specularColor;
          float G = G_Smith(roughness, NdotV, NdotL);          
          float Specular_G = G * VdotH / (NdotH , NdotV);
          fixed3 Fschlick =  f0 + (fixed3(1,1,1) - f0)* pow(1 - LdotH, 5);
          c.rgb += Specular_D*Specular_G*Fschlick * lightColor.rgb;
          c.a = 1;
          return c;
   }

2014年7月1日 星期二

Get Selected AssetPath


常常寫EditorWindow但又常常忘了怎寫
把寫好的放上來,以後要改比較方便

順便提供一些小工具

當專案比較大時,資料夾結構很深,有時常需要知道asset的path。所以寫了一個小工具可以看Asset的path


using UnityEngine;
using System.Collections;
using UnityEditor;

public class GetSelectedAssetPath : EditorWindow {

 [MenuItem ("Window/GetSelectedAssetPath")]
 static void Init () {
  // Get existing open window or if none, make a new one:
  GetSelectedAssetPath window = (GetSelectedAssetPath)EditorWindow.GetWindow (typeof (GetSelectedAssetPath));
 }
 void OnGUI () {
  if (GUILayout.Button("Select", GUILayout.Width(60)))
  {
   Debug.Log(AssetDatabase.GetAssetPath(Selection.activeObject));
  }
 }

}