function export_one_triangle fp tri_index =
(
tri_vertices = getFace $ tri_index -- only index
tri_uvws = getTVFace $ tri_index
format "triangle #%\n" tri_index to:fp
for i = 1 to 3 do
(
v = getVert $ tri_vertices[i]
uv = getTVert $ tri_uvws[i]
format "v%: xyz(%,%,%) uv(%,%)\n" i v[1] v[2] v[3] uv[1] uv[2] to:fp
)
format "\n" to:fp
)
function export_uv fp =
(
m = $.material
if m == undefined then return undefined
bm = getSubTexmap m 2
if bm == undefined then return undefined
format "tex: %\n" bm.filename to:fp
)
filename = getSaveFileName types:"Data(*.dat)|*.dat|All|*.*|"
if filename != undefined then
(
convertToMesh $
fp = openFile filename mode:"wt"
export_uv fp
num = getNumFaces $ -- triangle num
for i = 1 to num do
(
export_one_triangle fp i
)
fclose fp
)
------------------------------------------------------------------------------
tex: E:\texture.PNG
triangle #1
v1: xyz(-10.0,-10.0,0.0) uv(1.0,0.0)
v2: xyz(-10.0,10.0,0.0) uv(1.0,1.0)
v3: xyz(10.0,10.0,0.0) uv(0.0,1.0)
triangle #2
v1: xyz(10.0,10.0,0.0) uv(0.0,1.0)
v2: xyz(10.0,-10.0,0.0) uv(0.0,0.0)
v3: xyz(-10.0,-10.0,0.0) uv(1.0,0.0)
...
------------------------------------------------------------------------------
关于 uv,可以说说关于 channel 的东西。
channel 0 - vertex color
channel 1 - uvw map
一个 mesh face 必然有对应的 texture and color face。这个是 3dmax channel 的基本使用规则。
getTVFace 取得对应的 uv face;getTVert 取得对应的 uv 坐标。
要重点理解下这个,getSubTexmap 取得 material 的某个 texmap。
如上图,material 的 texmap 一共有24个,所以 getNumSubTexmaps m 返回24,而 getSubTexmap m 2 其实是取第二个 texmap,也就是 diffuse color 这个。
参考资料:
[3ds Max Objects]
==> [Editable Meshes, Splines, ...]
==> [Editable_Mesh and TriMesh]
==> [Mesh Texture Vertex Methods] & [Understanding Texture Coordinates and Vertex Colors]
[3ds Max Objects]
==> [Material: MAXWrapper]
==> [Material Common Properties, Operators, and Methods]
[3ds Max Objects]
==> [TextureMap: Material]
==> [TextureMap Types]
==> [BitmapTexture: TextureMap]
目录中类似 TextureMap: Material 的文字,表示 TextureMap 继承自 Material。
怎么玩 UVW Map,这里有份简单的 tutorial。
评论