Patches

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.

To create a patch object from scratch, create an Editable_Patch scene object to create an empty patch object and use the geometry & topology creations functions below to fill the patch out, then use the patch.update() function to complete construction.

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.

patch.getNumVerts

patch.setNumVerts [keep:]

?

patch.getNumVecs ?

patch.setNumVecs [keep:]

?

patch.getNumPatches

patch.setNumPatches [keep:]

?

patch.getNumEdges

patch.setNumEdges [keep:]

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.

patch.getVert

patch.setVert

?

patch.getVec

patch.setVec

?

The following two functions are the main mechanism for creating individual patches in the patch mesh:

patch.makeQuadPatch

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

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

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.

patch.getVertVecs

?

patch.getVertPatches

?

patch.getVertEdges

?

patch.getVecVert

?

patch.getVecPatches

?

patch.getEdgeVert1

?

patch.getEdgeVert2

?

patch.getEdgeVec12

?

patch.getEdgeVec21

?

The following functions access and manipulate the texture mapping information in the patch object:

patch.getNumMaps

patch.setNumMaps [keep:]

?

patch.getMapSupport

patch.setMapSupport [init:]

?

patch.getNumMapVerts

patch.setNumMapVerts [keep:]

?

patch.getMapVert

patch.setMapVert

?

patch.getMapPatch

patch.setMapPatch

?

patch.maxMapChannels

?

patch.setNumMapPatches [keep:]

?

The following functions get and set the material ID for the patch object as a whole or for individual patches:

patch.getMtlID

patch.setMtlID

?

patch.getPatchMtlID

patch.setPatchMtlID

?

The following functions access and control viewport and renderer tessellation and visibility:

patch.setMeshSteps

patch.getMeshSteps

?

patch.setMeshStepsRender

patch.getMeshStepsRender

?

patch.setShowInterior

patch.getShowInterior

?

patch.setAdaptive

patch.getAdaptive

?

The following functions access topology info for the specified sub-object:

patch.getEdges []

patch.getPatches []

patch.getVectors

?

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

?

The following functions perform various high-level operations on a patch object:

patch.weldVerts

patch.weld2Verts

patch.weldEdges

patch.deletePatchParts

patch.clonePatchParts

patch.subdivideEdges

patch.subdividePatches

patch.addTriPatch

patch.addQuadPatch

?

The following functions get and manipulate surface normal information. Again, normal vectors are given in MAXScript's current working coordinate context.

patch.patchNormal

patch.edgeNormal

patch.updatePatchNormals

patch.flipPatchNormal

patch.unifyNormals

patch.autoSmooth

?

The following functions access and change the vertex and interior vertex types:

patch.changeVertType #corner|#coplanar

patch.getVertType -> #corner or #coplanar

patch.changePatchInteriorType #automatic|#manual

patch.getPatchInteriorType -> #automatic or #manual

?

The following function returns the current mesh tessellation for the patch object:

patch.getMesh

?

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.

patch.interpTriPatch

patch.interpQuadPatch

?

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

patch const StructDef

patchOps const StructDef

Patch_Select - superclass: modifier

Patch : GeometryClass