Patches

Topic: version 4 MAXScript New Features/Editable Patch

There is a patch function package containing a large number of functions for creating, modifying and accessing patch objects. The sub-object selection system in MAXScript has also been extended to cover patch objects.

Note: Any set of changes to a patch object using the following functions do not fully take effect until the 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 may 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 info.

<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.

Note: 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 mask

patch.makeTriPatch <obj> <index> <va> <vab> <vba> <vb> <vbc> <vcb> <vc> <vca> <vac> <i1> <i2> <i3> <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.

vca = Vector ca.

vac = Vector ac.

i1 = Interior 1.

i2 = Interior 2.

i3 = Interior 3.

sm = The smoothing group mask

The 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 making the changes otherwise and invalid patch may bepassed to MAX possibly causing a crash. The patch.update() function is similar in function and purpose 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.

Example:

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:

patch.setNumMaps <obj> <num> [keep:<bool>]

<integer>     patch.getNumMaps <obj>  

patch.setMapSupport <obj> <map_chan> [init:<boolean>]

<boolean>     patch.getMapSupport <obj> <map_chan>  

patch.maxMapChannels <obj>

patch.setNumMapVerts <obj> <map_chan> <num> [keep:<boolean>]

<integer>     patch.getNumMapVerts <obj> <map_index>

patch.setNumMapPatches <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>

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 viewport and renderer tessellation and visibility:

patch.setMeshSteps <obj> <steps>

patch.getMeshSteps <obj>

patch.setMeshStepsRender <obj> <steps>

patch.getMeshStepsRender <obj>

patch.setShowInterior <obj> <bool>

patch.getShowInterior <obj>

patch.setAdaptive <obj> <bool>

patch.getAdaptive <obj>

The following functions access topology info 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 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>  -> #corner or #coplanar

patch.changePatchInteriorType <obj> <patch> #automatic|#manual

patch.getPatchInteriorType <obj> <patch>  -> #automatic or #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>   

SubObject Selection

The following methods require a selection to operate on. Using them with out selection will give no 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 $

See also