1 --*************************************************************
\r
3 -- compute looped index
\r
4 fn exVertIndex index numPts =
\r
6 if (index == 0) then numPts
\r
7 else if (index == numPts + 1) then 1
\r
11 --*************************************************************
\r
13 -- compute the tangent of the given vertex
\r
14 fn getExtrudeTgt mesh index numPoints =
\r
18 i1 = getVert mesh (exVertIndex (index - 1) numPoints)
\r
19 --i2 = exVertIndex index numPoints
\r
20 i3 = getVert mesh (exVertIndex (index + 1) numPoints)
\r
23 dir.y = - (i3.x - i1.x)
\r
30 --*****************************************************
\r
31 -- compute the perimeter of the mesh to extrude
\r
32 fn computeWaterBorderPerimeter mesh =
\r
35 for i = 1 to (mesh.numverts - 1) do
\r
37 lenght = lenght + (distance (getVert mesh i) (getVert mesh i + 1))
\r
39 lenght = lenght + (distance (getVert mesh (mesh.numverts - 1)) (getVert mesh 1))
\r
45 --*************************************************************
\r
47 fn setWEFace mesh indexFace i1 i2 i3 =
\r
49 setFace mesh indexFace [i2, i1, i3]
\r
52 --*************************************************************
\r
54 plugin simpleMod waterStretch
\r
55 name: "WaterStretch"
\r
56 classID:#(0x1f7535ea, 0x36423d01)
\r
60 parameters params rollout:main
\r
62 tgts type:#point3tab tabSizeVariable: true
\r
63 vertsNb type:#integer
\r
64 amount1 type:#float ui:cAmount1 default:1
\r
65 amount2 type:#float ui:cAmount2 default:1
\r
66 amount3 type:#float ui:cAmount3 default:1
\r
67 amount4 type:#float ui:cAmount4 default:1
\r
69 rollout main "Parameters"
\r
71 spinner cAmount1 "amount 1" type:#float range:[-1000, 1000, 0.1]
\r
72 spinner cAmount2 "amount 2" type:#float range:[-1000, 1000, 0.1]
\r
73 spinner cAmount3 "amount 3" type:#float range:[-1000, 1000, 0.1]
\r
74 spinner cAmount4 "amount 4" type:#float range:[-1000, 1000, 0.1]
\r
78 print "rollout opened"
\r
79 if (numSlice < 2) then cAmount2.enabled = false
\r
80 if (numSlice < 3) then cAmount3.enabled = false
\r
81 if (numSlice < 4) then cAmount4.enabled = false
\r
86 if (i == 0) then return p
\r
87 if (vertsNb != 0) then
\r
89 if (i > vertsNb) then
\r
91 numSlice = (floor ((i - 1) / vertsNb)) as integer
\r
93 v0n = tgts[(i - (numSlice * vertsNb))]
\r
95 if (numSlice == 1) then amount = amount1
\r
96 if (numSlice == 2) then amount = amount1 + amount2
\r
97 if (numSlice == 3) then amount = amount1 + amount2 + amount3
\r
98 if (numSlice == 4) then amount = amount1 + amount2 + amount3 + amount4
\r
100 return (v0 + (amount * v0n))
\r
111 fn buildSlice sel startIndex numVerts slice nbSlice perimeter =
\r
115 for i = 1 to numVerts do
\r
117 setVert sel (i + startIndex + numVerts) (getVert sel i)
\r
118 setTVert sel (i + startIndex) [dist / perimeter, (slice - 1) / (nbSlice as float), 0]
\r
119 setTVert sel (i + startIndex + numVerts) [dist / perimeter, slice / (nbSlice as float), 0]
\r
120 if (i != numVerts) then
\r
122 dist = dist + (distance (getVert sel i) (getVert sel (i + 1)))
\r
126 -- setup faces index
\r
127 for i = 0 to (numVerts - 2) do
\r
129 setWEFace sel (2 * startIndex + 2 * i + 1) (startIndex + i + 1) (startIndex + i + numVerts+ 2) (startIndex + 1 + i + numVerts)
\r
130 setWEFace sel (2 * startIndex + 2 * i + 2) (startIndex + i + 1) (startIndex + i + 2) (startIndex + i + numVerts + 2)
\r
131 setTVFace sel (2 * startIndex + 2 * i + 1) (startIndex + i + numVerts + 2) (startIndex + i + 1) (startIndex + 1 + i + numVerts)
\r
132 setTVFace sel (2 * startIndex + 2 * i + 2) (startIndex + i + 2) (startIndex + i + 1) (startIndex + i + numVerts + 2)
\r
133 setVCFace sel (2 * startIndex + 2 * i + 1) [slice + 1, slice, slice + 1]
\r
134 setVCFace sel (2 * startIndex + 2 * i + 2) [slice, slice, slice + 1]
\r
140 setWEFace sel (2 * startIndex + 2 * i + 1) (startIndex + i + 1) (startIndex + numVerts + 1) (startIndex + 1 + i + numVerts)
\r
141 setWEFace sel (2 * startIndex + 2 * i + 2) (startIndex + i + 1) (startIndex + 1) (startIndex + numVerts+ 1)
\r
142 setTVFace sel (2 * startIndex + 2 * i + 1) (startIndex + numVerts + 1) (startIndex + i + 1) (startIndex + 1 + i + numVerts)
\r
143 setTVFace sel (2 * startIndex + 2 * i + 2) (startIndex + 1) (startIndex + i + 1) (startIndex + numVerts + 1)
\r
144 setVCFace sel (2 * startIndex + 2 * i + 1) [slice + 1, slice, slice + 1]
\r
145 setVCFace sel (2 * startIndex + 2 * i + 2) [slice, slice, slice + 1]
\r
148 utility ExtrudeWater "Extrude water"
\r
150 button extrude "extrude water"
\r
151 spinner cNumSlice "numSlices" type:#integer range:[1, 4, 1]
\r
154 on extrude pressed do
\r
156 numSlices = cNumSlice.value
\r
157 for currSel = 1 to selection.count do
\r
159 sel = selection[currSel]
\r
160 -- make a copy of the selection
\r
162 myCopy.name = myCopy.name + "_backup"
\r
164 --collapseStack sel
\r
165 perimeter = computeWaterBorderPerimeter sel
\r
166 initialNumVerts = sel.numverts + 1
\r
167 -- create additionnal vertices
\r
168 setNumVerts sel (initialNumVerts * (1 + numSlices)) true
\r
169 -- duplicate last vert (to avoid bad mapping)
\r
170 setVert sel initialNumVerts (getVert sel 1)
\r
171 setNumFaces sel (2 * initialNumVerts * numSlices) true
\r
174 setNumCPVVerts sel (numSlices + 1)
\r
176 for k = 1 to (numSlices + 1) do
\r
178 i = 255 - (255 * (k - 1) / numSlices)
\r
179 setVertColor sel k (color i i i i)
\r
182 -- vertex texture coordinates
\r
183 setNumTVerts sel (initialNumVerts * (1 + numSlices))
\r
187 for currSlice = 1 to numSlices do
\r
189 buildSlice sel ((currSlice - 1) * initialNumVerts) initialNumVerts currSlice numSlices perimeter
\r
192 modif = waterStretch()
\r
195 -- compute tangents
\r
196 for i = 1 to initialNumVerts do
\r
198 tg = getExtrudeTgt sel i initialNumVerts
\r
202 modif.vertsNb = initialNumVerts
\r
203 modif.numSlices = numSlices
\r
204 addModifier sel (vertexPaint())
\r
205 addModifier sel modif
\r
211 -- select vertices from a water extruded object
\r
212 fn selectVertices obj slice =
\r
214 local vertsNb = obj.numVerts
\r
216 for i = 1 to vertsNb do
\r
218 tab[i] = slice * vertsNb + i
\r
220 setVertSelection obj tab
\r
223 -- a macro to select one slice from a water extruded shape
\r
224 macroScript wsChooseSlice1 category:"NEVRAX Tools" tooltip:"Water / choose slice 1"
\r
226 if ($ != undefined) then
\r
233 macroScript wsChooseSlice2 category:"NEVRAX Tools" tooltip:"Water / choose slice 2"
\r
235 if ($ != undefined) then
\r
242 macroScript wsChooseSlice3 category:"NEVRAX Tools" tooltip:"Water / choose slice 3"
\r
244 if ($ != undefined) then
\r
251 macroScript wsChooseSlice4 category:"NEVRAX Tools" tooltip:"Water / choose slice 4"
\r
253 if ($ != undefined) then
\r