Working with Editable Meshes

 

   

Editable Mesh - Quick Navigation

Flipping Face Normals

The following function flips the face normal for all faces in the specified mesh object.

EXAMPLE

fn FlipObjNormal obj =
(
for f =1 to obj.numFaces do -- for each face in the mesh
(
verts=getface obj f -- get its 3 vertices as a point3
local tmp=verts.x -- swap the first and third vertices
verts.x=verts.z -- which flips the normal
verts.z=tmp -- (right-hand rule), and
setface obj f verts -- store the new vertex order for the face
)
update obj -- update object so 3ds Max sees the changes
)

Texture Vertices and Faces

The following script is an example of working with texture vertices and faces.

SCRIPT

-- function to apply planar mapping to an object
-- direction parameter specifies the axis the mapping is
-- perpendicular to, and can have a value of #x, #y, or #z
--
fn ApplyPlanarMap obj direction =
(local oldcoordsys, normalize_pos
-- in this case, the number of texture vertices is equal to the
-- number of mesh vertices
obj.numtverts=obj.numverts
-- build the texture vertex faces
buildTVFaces obj
-- operate in objects coordinate space. Save original coord system so we
-- can restore later.
oldcoordsys=set coordsys local
-- for each vertex in mesh, get it's position and normalize the position
-- to a range of [0,0,0] to [1,1,1]. This is the planar UVW space.
for v = 1 to obj.numverts do
( normalize_pos=((getvert obj v)-obj.min)/(obj.max-obj.min)
-- flip around position component values based on which direction the
-- planar mapping is perpendicular to
case direction of
(#x:( tmp=normalize_pos.x
normalize_pos.x=normalize_pos.y
normalize_pos.y=normalize_pos.z
normalize_pos.z=tmp
)
#y:( tmp=normalize_pos.y
normalize_pos.y=normalize_pos.z
normalize_pos.z=tmp
)
)
-- set the corresponding texture vertex "position"
settvert obj v normalize_pos
)
-- done "positioning" the texture vertices. Build the texture faces.
-- since in this case there is a 1-to-1 correspondence between mesh and
-- texture vertices, the vertex indices for a mesh face are also the
-- texture vertex indices for the texture faces.
for f = 1 to obj.numfaces do
setTVFace obj f (getface obj f)
-- all done. reset the coordinate system
set coordsys oldcoordsys
-- update the mesh so 3ds Max sees the changes

update obj
)
--
-- test bed. Create a sphere, apply a material, set the diffuse map
-- to a 2x3 tiled checker map, turn on viewport display of the
-- checker texture map, and call the ApplyPlanarMap function
--
g=geosphere()
convertToMesh g
g.material=standard()
g.material.maps[2]=checker()
g.material.maps[2].coordinates.u_tiling=2
g.material.maps[2].coordinates.v_tiling=3
showTextureMap g.material g.material.maps[2] true
ApplyPlanarMap g #x

OUTPUT:

ApplyPlanarMap() -- output of function declaration lines 5 to 45
$GeoSphere:GeoSphere02 @ [0.0,0.0,0.0] -- output line 51
$Editable_Mesh:GeoSphere02 @ [0.0,0.0,0.0] -- output line 52
Standard:Standard -- output line 53
Checker:Checker -- output line 54
2 -- output line 55
3 -- output line 56
OK -- output line 57
OK -- output line 58

See Also