0% found this document useful (0 votes)
22 views7 pages

Mesh Diagrid

Uploaded by

icehena
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views7 pages

Mesh Diagrid

Uploaded by

icehena
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

SimPlE diagrid mESH/CoNtiNuEd

the last section of the code specifies how a user creates Untitled Type a Keyword or phrase

the diagrid and how the software should react to mouse 3DS Edit Tools
MAXScript
Group
Help
Views Create Modifiers Animation Graph Editors Rendering Lighting Analysis Customize

clicks and drags. When a user clicks the mouse, the All View Create Selection

location of the click (gridPoint) is considered the origin of Graphite Modeling Tools
Polygon Modeling
Freeform Selection Object Paint

the mesh. When the user moves the mouse, the second
Diagrid Mesh002
click is used to derive the width and the length of the mesh. Modifier List

this is identical to how a user creates a 2d rectangle. FFD 3x3x3


Control Points

Pressing the escape key stops the creation of the diagrid. Lattice
Set Volume

since the diagrid mesh is created as a scripted plugin, it


behaves exactly like other geometries. its parameters can
FFD Parameters
Display:

be modified in the modify panel as well as animated using


Lattice

Source Volume

the timeline. Finally, the mesh surface can be manipulated Deform:

Only In Volume
by adding modifiers such as edit Mesh or FFd 3x3x3 (fig. All Ver tices

66). a complex organic form can be similarly achieved (fig. Control Points:
Reset

67). in this case, a hollowed out diagrid mesh was distorted Animate All

using the bend and spherify built-in modifiers. to achieve Conform to Shape

Inside Points

the final organic form, the geometry was then thickened and Outside Points

smoothed using the built-in shell and turbosmooth modifiers. Offset : 0.05

About
35 / 100

0 10 20 30 40 50 60 70 80 90 100
modPanel.setCurrent0bject $.m X: Y: Auto Key Selected
diagridmesh_plugin_def Click and drag to pan a non Set Key Key Filters... 35

fig. 66 A modified diagrid mesh using the FFD 3x3x3 modifier.

fig. 67 A process of modifying a simple diagrid into a


curvilinear, organic form, using geometry modifiers.
Tutorial Deriving a diagrid mesh
from a NURBS surface
In this second tutorial on subdivision, we will derive a diagrid u and v as horizontal and vertical increments in the case of a
mesh from any NURBS surface. The MAXScript environment simple flat rectangular plane, in reality, they are normalized (i.e. 0
allows procedural access to its built-in NURBS representations, to 1) parametric offsets along two directions on any undulating
facilitating the construction of new geometries that can surface. We can iterate through the u and v parameters of a
subdivide the surface according to any desired topology. NURBS surface and request the 3D coordinates of a point on
As we have seen above, 3ds Max provides some built-in the surface that exists at that particular u and v parametric
topologies, but in this case we would like to create our own. coordinate. This allows us to create a pattern of vertices of our
NURBS surfaces contain formulas for surface and curve choosing and a set of triangular faces that connect them.
interpolation and approximation based on a derivation of points
in the u and v directions of the surface. While you can think of

Unlike the previous tutorial, we will create a scripted utility called DiagridMesh rather than a scripted plugin.
Open 3ds Max, save and close any prior scenes, create a new empty scene and choose MAXScript
New Script from the top menu. In the script window that opens, type the following algorithm:

1 utility DiagridMesh “Diagrid Mesh”


2 (
3 global u = 10 -- the number of u steps.
4 global v = 10 -- the number of v steps.
5 global vertices = #() -- the array of vertices.
6 global faces = #() -- the array of faces.
7 global nc -- the number of columns.
8 global nr -- the number of rows.
9 global selectedObject = undefined -- the selected object.
10 global ns -- the NURBS set (derived from the selected object).
11 global minu, maxu -- the minimum and maximum u values for the surface.
12 global minv, maxv -- the minimum and maximum v values for the surface.
13 global udist, vdist -- the unit u and unit v distances.
14 global resultingMesh
15
16 global globalCounter = 1 -- a counter we will use to generate a unique name.
17
18 -- A function to select only NURBS surfaces.
19 fn nurbs_filt obj = (classOf obj == NURBSSurf)
20
21 pickbutton selectNURBS “Select NURBS” width:140 filter:nurbs_filt
22 edittext selectedObject_tf “NURBS: “ text:”NONE” readonly:true width:138
23
24 group “Parameters”
25 (
26 spinner u_spinner “U:” type:#integer range:[1,10000,u]
27 spinner v_spinner “V:” type:#integer range:[1,10000,v]
28 )
Deriving a diagrid mesh from a NURBS surface
/CONTINUED
29
30 button generate_button “Generate Diagrid” enabled:true
31
32 on selectNURBS picked obj do
33 (
34 --see if the user did not cancel the picking.
35 if obj != undefined do
36 (
37 selectedObject = obj
38 -- display the name of the object on the button.
39 selectedObject_tf.text = obj.name
40 )
41 )
42
43 on u_spinner changed amt do
44 (
45 u = amt
46 )
47
48 on v_spinner changed amt do
49 (
50 v = amt
51 )
52
53 on generate_button pressed do
54 (
55 resultingMesh = undefined
56 nc = u*2
57 nr = v
58
59 if (selectedObject == undefined) then
60 (
61 return false
62 )
63
64 if (isDeleted selectedObject) then
65 (
66 return false
67 )
68
69 -- Get the NURBS set from the selected object.
Subdivision 95

70 ns = getnurbsset selectedObject #relational


71
72 for k = 1 to ns.count by 1 do
73 (
74
75 if ((superClassOf ns[k]) == NURBSSurface) then
76 (
77
78 -- Delete any pre-existing vertices.
79 for i = 1 to vertices.count by 1 do
80 (
81 deleteItem vertices 1
82 )
83
84 -- Delete any pre-existing faces.
85 for i = 1 to faces.count by 1 do
86 (
87 deleteItem faces 1
88 )
89
90 minu = ns[k].uParameterRangeMin
91 maxu = ns[k].uParameterRangeMax
92
93 minv = ns[k].vParameterRangeMin
94 maxv = ns[k].vParameterRangeMax
95
96 udist = 1.0 / (float) nc
97 vdist = 1.0 / (float) nr
98 oddeven = 2
99
100 -- Create Vertices.
101 for i = 0 to nc by 1 do
102 (
103 case of(
104 (mod oddeven 2 != 0) : (offset = 0.5; deduct = 1)
105 (mod oddeven 2 == 0) : (offset = 0.0; deduct = 0)
106 )
107 for j = 0 to (nr - deduct) by 1 do
108 (
109 vx = i/(float) nc
110 vy = (j+offset)/(float) nr
111 append vertices (evalpos ns[k] (minu + (maxu-minu)*vx) (minv + (maxv-minv)*vy))
112 )
Deriving a diagrid mesh from a NURBS surface
/CONTINUED
113 oddeven = oddeven + 1
114 )
115
116 if(ns[k].closedInV == false) then
117 (
118 -- Create left and right triangular edges for open NURBS surfaces.
119 for i = 1 to nc by 2 do
120 (
121 v1 = (i - 1)*(nr + 1) - ((i - 1)/2) + 1
122 v2 = (i - 1)*(nr + 1) - ((i - 1)/2) + 1 + (nr + 1)
123 v3 = (i + 1)*(nr + 1) - ((i + 1)/2) + 1
124 append faces [v1, v2, v3]
125
126 v1 = (i + 1)*(nr + 1) - ((i + 1)/2) + nr + 1
127 v2 = (i - 1)*(nr + 1) - ((i - 1)/2) + nr + (nr + 1)
128 v3 = (i - 1)*(nr + 1) - ((i - 1)/2) + nr + 1
129 append faces [v1, v2, v3]
130 )
131 )
132 else
133 (
134 -- Create triangles for closed NURBS surfaces.
135 for i = 1 to nc by 2 do
136 (
137 v1 = (i - 1)*(nr + 1) - ((i - 1)/2) + 1
138 v2 = (i - 1)*(nr + 1) - ((i - 1)/2) + 1 + (nr + 1)
139 v3 = (i - 1)*(nr + 1) - ((i - 1)/2) + nr + (nr + 1)
140 append faces [v1, v2, v3]
141
142 v1 = (i - 1)*(nr + 1) - ((i - 1)/2) + nr + (nr + 1)
143 v2 = (i - 1)*(nr + 1) - ((i - 1)/2) + 1 + (nr + 1)
144 v3 = (i + 1)*(nr + 1) - ((i + 1)/2) + nr + 1
145 append faces [v1, v2, v3]
146 )
147 )
148
149 -- Create first set of triangles.
150 for i = 1 to nc by 2 do
151 (
152 for j = 1 to nr by 1 do
153 (
Subdivision 97

154 v1 = (i - 1)*(nr + 1) - ((i - 1)/2) + j


155 v2 = (i - 1)*(nr + 1) - ((i - 1)/2) + j + 1
156 v3 = (i - 1)*(nr + 1) - ((i - 1)/2) + j + (nr + 1)
157 append faces [v1, v2, v3]
158
159 if (j < nr) then
160 (
161 v1 = (i - 1)*(nr + 1) - ((i - 1)/2) + j + (nr + 1)
162 v2 = (i - 1)*(nr + 1) - ((i - 1)/2) + j + 1
163 v3 = (i - 1)*(nr + 1) - ((i - 1)/2) + j + (nr + 2)
164 append faces [v1, v2, v3]
165 )
166 )
167 )
168
169 -- Create second set of triangles.
170 for i = 3 to (nc+1) by 2 do
171 (
172 for j = 1 to nr by 1 do
173 (
174 v1 = (i - 1)*(nr + 1) - ((i - 1)/2) + j + 1
175 v2 = (i - 1)*(nr + 1) - ((i - 1)/2) + j
176 v3 = (i - 3)*(nr + 1) - ((i - 3)/2) + j + (nr + 1)
177 append faces [v1, v2, v3]
178
179 if (j < nr) then
180 (
181 v1 = (i - 3)*(nr + 1) - ((i - 3)/2) + j + (nr + 1)
182 v2 = (i - 3)*(nr + 1) - ((i - 3)/2) + j + 1 + (nr + 1)
183 v3 = (i - 1)*(nr + 1) - ((i - 1)/2) + j + 1
184 append faces [v1, v2, v3]
185 )
186 )
187 )
188
189 -- Create the mesh.
190 m = mesh vertices:vertices faces:faces
191
192 -- Weld any congruent vertices.
193 allVerts = #{1..(m.numVerts)} -- get all verts list.
194 meshop.weldVertsByThreshold m allVerts 0.001
195
196 -- Set the mesh properties and position at same location as original surface.
Deriving a diagrid mesh from a NURBS surface
/CONTINUED
197 m.name = selectedObject.name+”-”+(k as string)+”-diagrid”
198 m.rotation = selectedObject.rotation
199 m.scale = selectedObject.scale
200 m.pos = selectedObject.pos
201
202 if((resultingMesh == undefined) or (isDeleted resultingMesh)) then
203 (
204 resultingMesh = copy m
205 )
206 else
207 (
208 resultingMesh += m
209 )
210 delete m
211
212 -- Make the mesh the current selection.
213 resultingMesh.name = selectedObject.name+”-Diagrid”+(formattedPrint globalCounter format:”03d”)+”-
”+(u as string)+”X”+(v as string)
214 select resultingMesh
215 )
216 )
217 globalCounter = globalCounter + 1
218 )
219 )

Save your script and then choose Tools Evaluate All to run the script.
Set the viewport display to display face edges by clicking on the display
mode (e.g. Realistic or Smooth+Highlights in the upper left corner of the
viewport) and choosing that option. This will enable you to see the diagrid
lines when you derive the surface. Next, create a NURBS surface.
To run the actual script utility, go to Utilities (hammer icon)  MAXScript 
Utilities (Pull-down menu) Diagrid Mesh. Use the pick button, titled Select tip CREATING A NURBS
NURBS, to select the NURBS surface from the scene. You can choose any SURFACE
number of u and v sections (rows and columns). Once you have selected the
desired parameters, press the Generate Diagrid button. This will generate To create a NURBS surface, select
an editable mesh diagrid at the same location as the original NURBS surface. Create Geometry NURBS
Select the move command and move the diagrid so you can view it (fig. Surfaces CV Surf and drag a rectangle
68). The diagrid will have the same name as the original NURBS surface in the viewport. If you wish to undulate the
surface, select it, go to the modify panel,
followed by the suffix “-Diagrid” and additional identifying numbers.
click on the + sign next to the word ‘NURBS
Surfaces’ to open the sub-objects list and
then choose Surface CV. You can then select
one or more of the yellow control vertices in
the viewport and move them in any direction
to undulate the surface. Once done,
deselect Surface CV and select the whole
NURBS surface.

You might also like