顯示具有 Programming 標籤的文章。 顯示所有文章
顯示具有 Programming 標籤的文章。 顯示所有文章

2013年11月25日 星期一

[Python] Photoshop 檔案輸出工具 : Export files with each layer set (Python + comtypes + PyQt)

  Photoshop檔案輸出工具試作,以Python 2.7 + comtypes + PyQt 4作成。其中使用comtypes是由於win32com無法處理2維陣列(參考:Python and photoshop- code snippets by Pete Hanshaw)。

  功能是自動的將所有的layers及每個layerSet(group)各別輸出成一個檔案(如下圖),另外還有layerSet的名稱過濾功能以及可自訂的輸出路徑,輸出的檔案名稱依據layerSet的name。


  寫到到目前為止遇到一個奇怪的問題無法解決,就是會無法獲得layerSets的length(app.activeDocument.layerSets.length),會出現NameError: Name length not found的錯誤訊息,另外看到有人使用len(layerSets)獲取length(參考:Photoshop scripting with Python @ Tech Art Tiki),但我用起來一樣會返回錯誤訊息(TypeError: object of type 'Dispatch' has no len()),也許是因為comtypes的關係吧?改天再來繼續完善。

目前完成的code
以下則是最單純的輸出功能的code供參考


參考資料:

2013年8月29日 星期四

[Unity] 更改Asset的Import Settings後,執行ImportAsset以正確更新

  當利用script進行批次的Import Settings設定時,需注意設定參數完成之後得要重新Import Asset才能夠讓Unity成功判讀到你的更改,不然會發生在Inspector中的資訊是對的,但執行Save Project後卻還是沒有正確寫入到Prefab或meta檔案之中。

舉例:
// 設定貼圖檔案的圖片壓縮格式
textureImporter.textureFormat = TextureImporterFormat.PVRTC_RGBA4;
// 設定了Import Settings之後再使用AssetDatabase.ImportAsset進行asset的更新
AssetDatabase.ImportAsset(path, ImportAssetOptions.ForceUpdate );

參考資料

2013年8月1日 星期四

[Unity] Shader試作 可調整Rim Light效果的Fragment Shader

嘗試撰寫Shader的紀錄。
這是一個帶有類似Rim Light效果及Tint Color,並且可以與原始的Texture做Blending的不受光Fragment Shader,用於角色受擊效果。

Shader "Custom/Unlit Transparent Cutout With Color" {
 Properties {
  _Color ("Color (RGB) Blending (A)", Color) = (1,0,0,0)
  _MainTex ("Base (RGB) Trans (A)", 2D) = "white" {}
  _Cutoff ("Alpha cutoff", Range(0,1)) = 0.5
 }
 
 // Fragment shader by Janus Huang
 SubShader {
 
  Tags {"Queue"="AlphaTest" "IgnoreProjector"="True" "RenderType"="TransparentCutout"}
  Blend SrcAlpha OneMinusSrcAlpha
  Lighting Off
  
  Pass {
   CGPROGRAM
   #pragma vertex vert
   #pragma fragment frag
   #include "UnityCG.cginc"
   
   struct appdata {
    fixed4 vertex : POSITION;
    fixed3 normal : NORMAL;
    fixed2 texcoord : TEXCOORD0;
   };
   
   struct v2f {
    fixed4 pos : SV_POSITION;
    fixed2 uv : TEXCOORD0;
    fixed4 color : COLOR;
   };
   
   fixed4 _MainTex_ST;
   fixed4 _Color;
   fixed _Cutoff;
   
   v2f vert (appdata_base v) {
    v2f o;
    
    o.pos = mul (UNITY_MATRIX_MVP, v.vertex);
    fixed3 viewDir = normalize(ObjSpaceViewDir(v.vertex));
    // 越是面向camera的vertex在dot計算後會獲得越大的計算結果
    fixed dotProduct = dot(v.normal, viewDir);
    // smoothstep用法同lerp, 但其曲線在頭尾都會趨緩
    o.color = smoothstep(0.5, 1, dotProduct);
    o.uv = TRANSFORM_TEX(v.texcoord, _MainTex);
    
    return o;
   }
   
   sampler2D _MainTex;
   
   fixed4 frag(v2f i) : COLOR {
    fixed4 texcol = tex2D(_MainTex, i.uv);
    // clip同AlphaTest
    clip( texcol.a - _Cutoff );
    // 受擊時的color計算 - 將貼圖加亮1.5倍後乘上dot計算後的黑白色(外黑內白)再加上_Color
    fixed3 hitColor = texcol.rgb * 1.5 * i.color.rgb + _Color.rgb;
    // 以_Color的alpha控制貼圖與受擊時的混合程度
    texcol.rgb = lerp( texcol.rgb, hitColor, _Color.a);

    return texcol;
   }   
   ENDCG
  }
 }
}


參考文章

2013年5月27日 星期一

[Unity] Shader - ShaderLab


參考資料:
相關資料:
參考範例:


人生第一次的shader撰寫XD,超陽春Unlit受擊變色用shader,透過shaderLab簡單的功能只要少少幾行就能完成!呈現的效果為,不受光影響,單一貼圖表現,可以透過Color property的alpha來控制貼圖與color間的混合

● Opaque版本
Shader "Custom/Unlit Opaque With Color" {
	Properties {
		_Color ("Color (RGB) Blending (A)", Color) = (1,0,0,0)
		_MainTex ("Base (RGB)", 2D) = "white" {}
	}
	SubShader {
		Tags {"RenderType"="Opaque" "IgnoreProjector"="True"}
		Lighting Off
		Cull back
		ZWrite On
		
		Pass {
			SetTexture [_MainTex] {
				ConstantColor [_Color]
				combine constant lerp(constant) texture
			}
		}
		
	}
	FallBack "Unlit/Diffuse"
}

● Transparent Cutout版本
Shader "Custom/Unlit Transparent Cutout With Color" {
	Properties {
		_Color ("Color (RGB) Blending (A)", Color) = (1,0,0,0)
		_MainTex ("Base (RGB) Trans (A)", 2D) = "white" {}
		_Cutoff ("Alpha cutoff", Range(0,1)) = 0.5
	}
	SubShader {
		Tags {"Queue"="AlphaTest" "IgnoreProjector"="True" "RenderType"="TransparentCutout"}
		Lighting Off
		Cull back
		ZWrite On
		Blend SrcAlpha OneMinusSrcAlpha
		
		Pass {
			Alphatest Greater [_Cutoff]
			SetTexture [_MainTex] {
				ConstantColor [_Color]
				combine constant lerp(constant) texture, texture
			}
		}
		
	}
	FallBack "Unlit/TransparentCutout"
}

2013年4月2日 星期二

Unity - Editor Script Coding - 編寫Editor Script之參考資料

入門站:
資料:

參考文章蒐集:
  • http://forum.unity3d.com/threads/92148-need-help-with-texture-import-setting-script

零散紀錄:
  • 取得Type
    GameObject.GetType().Name
  • 取得某個選擇中的Asset的路徑(亦可作用於目錄)
    AssetDatabase.GetAssetPath(OBJECT)
  • 取得 某個Asset檔案 內的所有元件
    AssetDatabase.LoadAllAssetsAtPath("AssetPath")

2012年5月9日 星期三

Regular Expressions

Regular Expressions 可簡稱 re / regex / regexp
中文則為:正則表示式、正規表示式...
下面的連結對RE有詳細的解說
http://www.regular-expressions.info/reference.html
Regular-Expressions.info
石頭閒語 : RE in JavaScript

RE JavaScript Tester

MAXscript不支援RE(至少Max9是),但是可以藉由dotNet來實行,請見下面連結
For obj in $ do : RE with MAXscript
rx = dotNetClass "System.Text.RegularExpressions.RegEx"
pattern = "^([A-Za-z0-9]+_){2}\d{3}"
s = "robot_leftArm_001"
if (((rx.match s pattern).success) == true) then (print "success") else (print "fail!")

2012年2月3日 星期五

Python 資訊收集

fcamel's blog: 學 Python 的入門書: 常看到有人問這問題,想說來寫篇心得,省得重覆回一樣的問題。 我在學 Python 前已學過別的程式語言,所以想找針對已學過程式的人的書。一開始翻許多人推薦的《Learning Python》,發現它是針對沒學過程式的人,有太多篇幅在介紹基本觀念 (如 if 是什麼 ),翻沒幾...

fcamel's blog: Python 的特別之處 (1): 從新手的眼中來看 Python,比較能看出 Python 和其它語言不同之處。最近有機會幫別人快速上手 Python,就順便整理一下我從中發覺 Python 較為突出的優點。 list、dictionary and string 平時 coding 最常用到的 container...


blur-devBlur Studio API's, Libraries and Tools : Python and 3dsMax

Dive Into PythonPython from novice to pro: Dive Into Python is a free Python book for experienced programmers. It was originally hosted at DiveIntoPython.org, but the author has pulled down all copies. It is being mirrored here. You can read the book online, or download it in a variety of formats. It is also available in multiple languages.

2011年9月1日 星期四

[Lua] 筆記 to 28

-- Example 18   -- if elseif else statement

c=3
if c==1 then
    print("c is 1")
elseif c==2 then
    print("c is 2")
else
    print("c isn't 1 or 2, c is "..tostring(c))
end


-- Example 19   -- Conditional assignment.
-- value = test and x or y

a=1
b=(a==1) and "one" or "not one"
print(b)

-- is equivalent to
a=1
if a==1 then
    b = "one"
else
    b = "not one"
end
print(b)


-------- Output ------

one
one


-------- Output ------

c isn't 1 or 2, c is 3



-- Example 20   -- while statement.

a=1
while a~=5 do -- Lua uses ~= to mean not equal
    a=a+1
    io.write(a.." ")
end


-------- Output ------

2 3 4 5
Press 'Enter' key for next example


-- Example 20   -- while statement.

a=1
while a~=5 do -- Lua uses ~= to mean not equal
    a=a+1
    io.write(a.." ")
end


-------- Output ------

2 3 4 5


-- Example 22   -- for statement.
-- Numeric iteration form.

-- Count from 1 to 4 by 1.
for a=1,4 do io.write(a) end

print()

-- Count from 1 to 6 by 3.
for a=1,6,3 do io.write(a) end


-------- Output ------

1234
14


-- Example 23   -- More for statement.
-- Sequential iteration form.

for key,value in pairs({1,2,3,4}) do print(key, value) end


-------- Output ------

1       1
2       2
3       3
4       4


-- Example 24   -- Printing tables.
-- Simple way to print tables.

a={1,2,3,4,"five","elephant", "mouse"}

for i,v in pairs(a) do print(i,v) end


-------- Output ------

1       1
2       2
3       3
4       4
5       five
6       elephant
7       mouse




2011年8月29日 星期一

Cry - Flow Graph 筆記

Done與Succeed/Fail的差別:Done是不管Succeed/Fail都會送出

在system.cfg中加速g_tpview_force_goc=1可防止攝影機穿越物件