Patch : GeometryClass

Patches are the general editable versions of all the patch objects, in the same way that Editable Meshes relate to geometry objects. They are the objects that a patch is converted to when you apply an Edit Patch modifier and the result of collapsing a modifier stack on a patch base object. While MAXScript lets you construct patches, there are no properties or methods for accessing or modifying the sub-objects (vertices, edges, and patches) within the patch object.

Constructor

Quadpatch ...

Tripatch ...

To create a Patch scene object from scratch, you call the Patch constructor function,

for example:

Quadpatch pos:[10,10,10] name:"foo"

This creates an empty patch.

convertTo Editable_Patch -- mapped

Converts the given scene node to a Patch object. If the object cannot be converted (typically, if it is not a geometry object), the function returns undefined. Any modifiers present will be collapsed. The collapseStack() function can also be used as can the collapse button in the modifier stack dialog in 3ds Max; both generate a Patch, but will only do so if there is at least one modifier present.

Properties

A control vertex and its tangents are available as properties once a controller has been assigned to the control vertex. The number of tangents for a control vertex is the number of edges associated with the control vertex. Controllers can not be assigned to the control vertices using MAXScript. If a TriPatch object is collapsed to a SplineShape, and some of its control vertices are animated, the properties for the control vertices and tangents would be similar to:

$TriPatch01.Vertex_1 Point3 value: [-21.5,-6.4,0] -- animatable

$TriPatch01.Vertex_1_Vector_1 Point3 value: [-21.5,-2.1,0] -- animatable

$TriPatch01.Vertex_1_Vector_2 Point3 value: [-7.1,-6.4,0] -- animatable

$TriPatch01.Vertex_2 Point3 value: [21.5,-6.4,0] -- animatable

$TriPatch01.Vertex_2_Vector_1 Point3 value: [7.1,-6.4,0] -- animatable

$TriPatch01.Vertex_2_Vector_2 Point3 value: [7.1,-2.1,0] -- animatable

See also Class and Object Inspector Functions for details on accessing the patch vertices and tangents. The controller values assigned to the vertices and tangent handles is in object space. See Using Node Transform Properties for information on converting between world space to object space.

Methods

getPatchSteps

Returns the number of steps the patch uses in the viewports, and reflects the View Steps spinner in the Modify panel.

setPatchSteps

Sets the number of View Steps used by the editable patch object to the specified value.

Editable Patch Modify Panel Command Modes and Operations

A suite of methods provide the ability for a script to invoke Editable Patch and Edit Mesh Modify panel modes and operations, corresponding to buttons available at various mesh sub-object levels. These methods reside in the patchOps global structure. These methods effectively "push the button" in the Modify panel. In order to use these methods, the node must be selected and the Modify panel open. In the description of these methods, the first argument should be interpreted as either an Editable Patch node where the modifier stack level is at the base object, or an Edit Patch modifier where the modifier stack level is at the Edit Patch. In all cases, the following methods work at the current sub-object level, but only if that level is appropriate for the invoked operation.

The follow methods invoke one of the 'user-interaction' button operations in the Editable Patch Modify panel, acting on the currently selected sub-objects. These methods highlight the corresponding button in the Geometry rollout and start the operation, at which point the user interactively completes the operation. These methods return after starting the operation, and before the user completes the operation, so care should be taken to ensure that your script does not interfere with the operation. Invoking any of these methods is the same as clicking on the associated button in the Modify panel. Calling a method when the operation is already in effect (either due to a user action or a MAXScript command) causes the operation to be terminated and the highlight is removed from the button.

patchOps.startAttach

Enters "Attach" command mode - valid in all Sub-Object levels, and when not in Sub-Object mode.

patchOps.startBevel

Enters "Bevel" command mode - valid in Patch Sub-Object level.

patchOps.startBind

Enters "Bind" command mode - valid in Vertex Sub-Object level.

patchOps.startCreate

Enters "Create" command mode - valid in Vertex, Patch, and Element Sub-Object levels.

patchOps.startExtrude

Enters "Extrude" command mode - valid in Patch Sub-Object level.

patchOps.startFlipNormalMode

Enters "Flip Normal" command mode - valid in Patch and Element Sub-Object levels.

patchOps.startWeldTarget

Enters "Weld Target" command mode - valid in Vertex Sub-Object level.

The following methods invoke one of the 'instantaneous' button operations in the Editable Patch Modify panel, acting on the currently selected sub-objects:

patchOps.addTri

Adds a TriPatch to the selected edge - valid in Edge Sub-Object level.

patchOps.addQuad

Adds a QuadPatch to the selected edge - valid in Edge Sub-Object level.

patchOps.break

Creates a new vertex for each patch attached to the selected sub-objects - valid in Vertex and Edge Sub-Object levels.

patchOps.clearAllSG

Clears the smoothing groups on the currently selected patches - valid in Face, Polygon, and Element Sub-Object levels.

patchOps.createShapeFromEdges

Displays Create Shape dialog allowing the user to specify an object name for the shape to create from the selected edges. Valid in Edge Sub-Object level.

patchOps.delete

Deletes the selected sub-objects - valid in all Sub-Object levels.

patchOps.detach

Displays Detach dialog allowing the user to specify an object name. Valid in Patch Sub-Object level.

patchOps.flipNormal

Flips the normal of the selected patches - valid in Patch and Element Sub-Object levels.

patchOps.hide

Hides the selected sub-objects - valid in all Sub-Object levels.

patchOps.selectByID

Display a Select By Material ID dialog and choose patches with the specified material ID - valid in Patch and Element Sub-Object levels.

patchOps.selectBySG

Display a Select By Smooth Groups dialog and choose patches with the specified smoothing groupd IDs - valid in Patch and Element Sub-Object levels.

patchOps.selectOpenEdges

Selects all edges with only one patch. Valid in Edge Sub-Object level.

patchOps.subdivide

Divides the selected sub-objects - valid in Edge and Patch Sub-Object levels.

patchOps.unbind

Unbinds the selected vertices - valid in Vertex Sub-Object level.

patchOps.unifyNormal

Unifies the normals of the selected patches - valid in Patch and Element Sub-Object levels.

patchOps.unhideAll

Unhides all hidden sub-objects -valid in all Sub-Object levels, and when not in Sub-Object mode.

patchOps.weld

Welds the selected vertices - valid in Vertex Sub-Object level.

The following methods are available in 3ds Max 6 and higher:

patchOps.growSelection

Grows the selection - valid in all Sub-Object levels except for Handle.

patchOps.shrinkSelection

Shrink the selection - valid in all Sub-Object levels except for Handle.

patchOps.selectEdgeRing

Select a ring of edges - valid in Edge Sub-Object level.

patchOps.selectEdgeLoop

Select a loop of edges - valid in Edge Sub-Object level.

patchOps.patchSmooth

Smooth the patch by avergaing the Handles.

patchOps.toggleShadedFaces

Toggle shaded faces

There is also a patch structure containing a large number of functions for creating, modifying and accessing patch objects.

The following function is used to get the type of the patch.

patch.getPatchType < patch_object >

Returns #triPatch, #quadPatch, #undefPatch, or 'undefined'. A value of #undefPatch may be returned by third-party-defined patch object. A value of 'undefined' will be returned if the internal patch type is not in the list of defined values.

Get and set the overall geometry of the patch

Set keep:true to the setNumXXX functions for them to retain existing vertex/vector/patch/edge data. This value defaults to false, which cleans out the geometry

patch.getNumVerts ?

Returns the number of vertices as integer value

patch.setNumVerts [keep:]

Sets the number of vertices to the integer value

patch.getNumVecs

Returns the number of vectors as integer value

patch.setNumVecs [keep:]

Sets the number of vectors to the integer value

patch.getNumPatches ?

Returns the number of patches as integer value

patch.setNumPatches [keep:]

Sets the number of patches to the integer value

patch.getNumEdges ?

Returns the number of edges as integer value

patch.setNumEdges [keep:]

Sets the number of edges to the integer value

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.

patch.getVert

Returns the indexed vertex as Point3 value

patch.setVert

Sets the indexed vertex to the Point3 value

patch.getVec

Returns the indexed vector as Point3 value

patch.setVec

Sets the indexed vector to the Point3 value

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

Update a Patch object:

patch.update

Forces all 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. If you make the changes otherwise, an invalid patch may be passed to MAX, possibly causing a crash. The patch.update() function is similar in function and purpose to the update() function in mesh object scripting.

Accessing the topology of an existing patch object:

They return either indexes or arrays of indexes of the sub-objects requested. For example, getVertVecs() returns an array of the vectors coming out of the specified vertex.

patch.getVertVecs -> integer_array

patch.getVertPatches -> integer_array

patch.getVertEdges -> integer_array

patch.getVecVert -> integer

patch.getVecPatches -> integer_array

patch.getEdgeVert1 -> integer

patch.getEdgeVert2 -> integer

patch.getEdgeVec12 -> integer

patch.getEdgeVec21 -> integer

Accessing and manipulating the texture mapping information

patch.setNumMaps [keep:]

patch.getNumMaps -> integer

patch.setMapSupport [init:]

patch.getMapSupport -> boolean

patch.maxMapChannels

patch.setNumMapVerts [keep:]

patch.getNumMapVerts

patch.setNumMapPatches [keep:]

patch.getMapVert

patch.setMapVert

patch.getMapPatch

patch.setMapPatch

Getting and setting the material ID of the whole object or individual patches

patch.getPatchMtlID -> integer

patch.setPatchMtlID

Note:

The material ID value returned by patch.getPatchMtlID and set by patch.setPatchMtlID are now 1-based. The material ID value was 0-based in 3ds Max 4.

patch.getMtlID -> integer

patch.setMtlID

Note:

The patch.getMtlID and patch.setMtlID methods have been removed from MAXScript.

Accessing and controlling viewport and renderer tesselation and visibility

patch.setMeshSteps

patch.getMeshSteps

patch.setMeshStepsRender

patch.getMeshStepsRender

patch.setShowInterior

patch.getShowInterior

patch.setAdaptive

patch.getAdaptive

Accessing topology info for the specified sub-object

patch.getEdges [] -> integer_array

patch.getPatches [] -> integer_array

patch.getVectors -> integer_array

Transforming all vertices and vectors in the patch object by the given matrix

patch.transform

This transform happens in object local space.

Performing 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

etting and manipulating surface normal information

patch.patchNormal

patch.edgeNormal

patch.updatePatchNormals

patch.flipPatchNormal

patch.unifyNormals

patch.autoSmooth

Normal vectors are given in MAXScript's current working coordinate context.

ccessing and changing the vertex and interior vertex types

patch.changeVertType #corner|#coplanar

patch.getVertType -> #corner or #coplanar

patch.changePatchInteriorType #automatic|#manual

patch.getPatchInteriorType -> #automatic or #manual

Accessing the current mesh tesselation for the patch object

patch.getMesh -> mesh value

Interpolating individual patch surfaces

patch.interpTriPatch -> point3

patch.interpQuadPatch -> point3

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.

See also

Node Common Properties, Operators, and Methods

MAXWrapper Common Properties, Operators, and Methods

Value Common Properties, Operators, and Methods

Class and Object Inspector Functions

Scripting Vertex and Control Point Animation