Skip to content

Instantly share code, notes, and snippets.

@zwcloud
Created November 11, 2015 04:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zwcloud/b05d7e1c01e10cd44a62 to your computer and use it in GitHub Desktop.
Save zwcloud/b05d7e1c01e10cd44a62 to your computer and use it in GitHub Desktop.
MaxScript that convert a mesh into text.
tmesh = $Mesh0
num_verts = $Mesh0.numverts
num_faces = $Mesh0.numfaces
format "%,%\n" num_verts num_faces
units.MetricType = #meters
for v = 1 to num_verts do
(
vert = getVert tmesh v
if(abs vert.x < 0.001f) then vert.x = 0f
if(abs vert.y < 0.001f) then vert.y = 0f
if(abs vert.z < 0.001f) then vert.z = 0f
format "new Vector3(%f, %f, %f),\n" \
(units.formatValue vert.x)\
(units.formatValue vert.y)\
(units.formatValue vert.z)\
)
format "\n"
for f = 1 to num_faces do
(
face = getFace tmesh f
format "%,%,%," \
((face.x-1)as integer) \
((face.y-1)as integer) \
((face.z-1)as integer)
)
format "\n"
texture_coords = #()
for count = 1 to num_faces do
(
local face = getFace tmesh count
local t_face = getTVFace tmesh count
texture_coords[face.x] = getTVert tmesh t_face.x
texture_coords[face.y] = getTVert tmesh t_face.y
texture_coords[face.z] = getTVert tmesh t_face.z
)
for tex_coord in texture_coords do
(
format "new Vector2(%f, %f),\n" \
(tex_coord.x) \
(tex_coord.y)
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment