A patch function package containing a large number of functions for creating, modifying, and accessing patch objects has been introduced in 3ds Max 4. The sub-object selection system in MAXScript has also been extended to cover patch objects.
The Editable Patch object in MAX was called 'Patch' in MAXScript. It has been renamed to 'Editable_Patch' to be consistent with Editable_Mesh and Editable_Poly, and to allow the new patch function package to be named 'patch'.
The MAXScript sub-object selection system has been extended to work with Editable Patch objects. This means that all the MAXScript VertexSelection, FaceSelection, and EdgeSelection properties and operations now work with patch objects. The 'face' sub-object selections in this system correspond to the 'patch' sub-object level when applied to patches.
The Patch functions. All the functions in this package take either a scene node containing an Editable Patch object or an Editable Patch base object as the first argument. QuadPatch and TriPatch objects need to be converted to Editable Patches for the Patch functions to be applicable. For example, when using the convertTo
$foo Editable_Patch.
To create a patch object from scratch, create an Editable_Patch scene object to create an empty patch object and use the geometry & topology creation functions below to fill the patch out, then use the patch.update
() function to complete the construction.
patch.update
() function is called on it. This makes construction substantially more efficient, but can leave a patch in an unstable state if the script that contains the changing code finishes before calling patch .update
on it, which might result in a MAX crash.Functions:
The following functions are used to get and set the overall geometry of the patch. Supply keep:true
to the setNumXXX functions for them to retain existing vertex/vector/patch/edge data, defaults to false, which cleans out the geometry.
The functions are largely direct calls to the methods of the same name on the MAX SDK class PatchMesh. See the SDK Help file Advanced Topic "Working with Patches", and the documentation for the main Patch system classes for more detailed information.
<integer> patch.getNumVerts <obj>
patch.setNumVerts <obj> <num> [keep:<boolean>]
<integer> patch.getNumVecs <obj>
patch.setNumVecs <obj> <num> [keep:<boolean>]
<integer> patch.getNumPatches <obj>
patch.setNumPatches <obj> <num> [keep:<boolean>]
<integer> patch.getNumEdges <obj>
patch.setNumEdges <obj> <num> [keep:<boolean>]
The following functions get and set individual vertex and vector handle locations. The vertex and vector coordinates are interpreted in MAXScript's current working coordinate context.
Consistent with the rest of MAXScript, all vertex/patch/vector/edge indexes start numbering at 1.
<point3> patch.getVert <obj> <index>
patch.setVert <obj> <index> <point3>
<point3> patch.getVec <obj> <index>
patch.setVec <obj> <index> <point3>
The following two functions are the main mechanism for creating individual patches in the patch mesh:
patch.makeQuadPatch <obj> <index> <va> <vab> <vba> <vb> <vbc> <vcb> <vc> <vcd> <vdc> <vd> <vda> <vad> <i1> <i2> <i3> <i4> <sm>
Where:
index
= The index of the patch to create (0> = index < numPatches).va
= The first vertex.vab
= Vector ab.vba
= Vector ba.vb
= The second vertex.vbc
= Vector bc.vcb
= Vector cb.vc
= The third vertex.vcd
= Vector cd.vdc
= Vector dc.vd
= The fourth vertex.vda
= Vector da.vad
= Vector ad.i1
= Interior 1.i2
= Interior 2.i3
= Interior 3.i4
= Interior 4.sm
= The smoothing group maskpatch.makeTriPatch <obj> <index> <va> <vab> <vba> <vb> <vbc> <vcb> <vc> <vca> <vac> <i1> <i2> <i3> <sm>
Where:
va
= The first vertex.vab
= Vector ab.vba
= Vector ba.vb
= The second vertex.vbc
= Vector bc.vcb
= Vector cb.vc
= The third vertex.vca
= Vector ca.vac
= Vector ac.i1
= Interior 1.i2
= Interior 2.i3
= Interior 3.sm
= The smoothing group maskThe following function forces all the geometry and topology caches to be rebuilt, change notifications to be sent, and a screen redraw request to be flagged.
You must call this function after making any changes to a path object before exiting the script. Otherwise, an invalid patch might be passed to MAX, which can cause a crash. The patch.update
() function is similar to the update() function in mesh object scripting.
patch.update <obj>
The following functions give access to the topology of an existing patch object. They return either indexes or arrays of indexes of the sub-objects requested.
getVertVecs()
returns an array of the vectors coming out of the specified vertex.
<integer_array> patch.getVertVecs <obj> <index>
<integer_array> patch.getVertPatches <obj> <index>
<integer_array> patch.getVertEdges <obj> <index>
<integer> patch.getVecVert <obj> <index>
<integer_array> patch.getVecPatches <obj> <index>
<integer> patch.getEdgeVert1 <obj> <index>
<integer> patch.getEdgeVert2 <obj> <index>
<integer> patch.getEdgeVec12 <obj> <index>
<integer> patch.getEdgeVec21 <obj> <index>
The following functions access and manipulate the texture mapping information in the patch object:
<integer> patch.getNumMaps <obj>
patch.setNumMaps <obj> <num> [keep:<boolean>]
<boolean> patch.getMapSupport <obj> <map_chan>
patch.setMapSupport <obj> <map_chan> [init:<boolean>]
<integer> patch.getNumMapVerts <obj> <map_index>
patch.setNumMapVerts <obj> <map_chan> <num> [keep:<boolean>]
<point3> patch.getMapVert <obj> <map_chan> <index>
patch.setMapVert <obj> <map_chan> <index> <point3>
<index_array> patch.getMapPatch <obj> <map_chan> <index>
patch.setMapPatch <obj> <map_chan> <index> <index_array>
patch.maxMapChannels <obj>
patch.setNumMapPatches <obj> <map_chan> <num> [keep:<boolean>]
The following functions get and set the material ID for the patch object as a whole or for individual patches:
<integer> patch.getMtlID <obj>
patch.setMtlID <obj> <mtl_id>
<integer>patch.getPatchMtlID <obj> <index>
patch.setPatchMtlID <obj> <patch_index> <mtl_id>
The following functions access and control the viewport and renderer tessellation and visibility:
patch.setMeshSteps <obj> <steps>
patch.getMeshSteps <obj>
patch.setMeshStepsRender <obj> <steps>
patch.getMeshStepsRender <obj>
patch.setShowInterior <obj> <boolean>
patch.getShowInterior <obj>
patch.setAdaptive <obj> <boolean>
patch.getAdaptive <obj>
The following functions access the topology information for the specified sub-object:
<integer_array> patch.getEdges <obj> <v1> [<v2>]
<integer_array> patch.getPatches <obj> <v1> [<v2>]
<integer_array> patch.getVectors <obj> <vert>
The following function transforms all the vertices and vectors in the patch object by the given matrix. This transform happens in the object local space.
patch.transform <obj> <matrix3>
The following functions perform various high-level operations on a patch object:
patch.weldVerts <obj> <threshold> <weldIdentical_bool> <startVert>
patch.weld2Verts <obj> <v1> <v2>
patch.weldEdges <obj>
patch.deletePatchParts <obj> <del_vert_bitarray> <del_patches_bitarray>
patch.clonePatchParts <obj> <patch_bit_array>
patch.subdivideEdges <obj> <propagate>
patch.subdividePatches <obj> <propagate>
patch.addTriPatch <obj>
patch.addQuadPatch <obj>
The following functions get and manipulate surface normal information. Again, normal vectors are given in MAXScript's current working coordinate context.
patch.patchNormal <obj> <patch>
patch.edgeNormal <obj> <edge>
patch.updatePatchNormals <obj>
patch.flipPatchNormal <obj> <patch>
patch.unifyNormals <obj>
patch.autoSmooth <obj> <angle> <useSel_bool> <preventIndirectSmoothing_bool>
The following functions access and change the vertex and interior vertex types:
patch.changeVertType <obj> <vert> #corner|#coplanar patch.getVertType <obj> <vert> ->#corneror#coplanar
patch.changePatchInteriorType <obj> <patch> #automatic|#manual patch.getPatchInteriorType <obj> <patch> ->#automaticor#manual
The following function returns the current mesh tessellation for the patch object:
<mesh value>patch.getMesh <obj>
The following functions are used to interpolate individual patch surfaces. A tri-patch interpolation takes u,v,w barycentric coordinates. A quad-patch takes u and c parameters. In both cases, the point returns is given in the current MAXScript working coordinate context.
<point3>patch.interpTriPatch <obj> <patch> <u> <v> <w>
<point3>patch.interpQuadPatch <obj> <patch> <u> <v>
The following functions are obsolete and should not be used:
patch.addHook
patch.hookFixTopology
patch.removeHook
patch.updateHooks
The following methods require a selection to operate on. Using them with out selection will not give results.
subDivideEdges:
Quadpatch lengthsegs:1 widthsegs:1 length:100 width:100 isSelected:on
convertTo $ Editable_Patch
$.selectededges = #{1}
patch.subdivideEdges $ false
patch.update $
subdividePatches:
Quadpatch lengthsegs:1 widthsegs:1 length:100 width:100 isSelected:on
convertTo $ Editable_Patch
$.selectedfaces = #{1}
patch.subdividePatches $ false
patch.update $
addTriPatch/addQuadPatch:
Quadpatch lengthsegs:1 widthsegs:1 length:100 width:100 isSelected:on
convertTo $ Editable_Patch
$.selectededges = #{1}
patch.addTriPatch $
patch.update $
$.selectededges = #{3}
patch.addQuadPatch $
patch.update $