diff options
author | Teravus Ovares | 2008-06-15 19:34:48 +0000 |
---|---|---|
committer | Teravus Ovares | 2008-06-15 19:34:48 +0000 |
commit | 11d68ce0f5d84188d468004b918824feb6c57f0b (patch) | |
tree | 23ef0ad2fb86cc3d64bdf78d14beb15ed4e61014 /OpenSim/Region/Physics/Meshing/Extruder.cs | |
parent | Update svn properties. (diff) | |
download | opensim-SC_OLD-11d68ce0f5d84188d468004b918824feb6c57f0b.zip opensim-SC_OLD-11d68ce0f5d84188d468004b918824feb6c57f0b.tar.gz opensim-SC_OLD-11d68ce0f5d84188d468004b918824feb6c57f0b.tar.bz2 opensim-SC_OLD-11d68ce0f5d84188d468004b918824feb6c57f0b.tar.xz |
* 0001558: [PATCH] Add support for full collision geometry feature set for linear path prims (patch attached) By Dahlia. Thanks Dahlia!
* This update re-does the cube/cylinder/prism prims to dynamically add faces as twist is used.
Diffstat (limited to 'OpenSim/Region/Physics/Meshing/Extruder.cs')
-rw-r--r-- | OpenSim/Region/Physics/Meshing/Extruder.cs | 192 |
1 files changed, 192 insertions, 0 deletions
diff --git a/OpenSim/Region/Physics/Meshing/Extruder.cs b/OpenSim/Region/Physics/Meshing/Extruder.cs index 880a23a..baa2d9b 100644 --- a/OpenSim/Region/Physics/Meshing/Extruder.cs +++ b/OpenSim/Region/Physics/Meshing/Extruder.cs | |||
@@ -63,6 +63,11 @@ namespace OpenSim.Region.Physics.Meshing | |||
63 | public float pathTaperX = 0.0f; | 63 | public float pathTaperX = 0.0f; |
64 | public float pathTaperY = 0.0f; | 64 | public float pathTaperY = 0.0f; |
65 | 65 | ||
66 | /// <summary> | ||
67 | /// (deprecated) creates a 3 layer extruded mesh of a profile hull | ||
68 | /// </summary> | ||
69 | /// <param name="m"></param> | ||
70 | /// <returns></returns> | ||
66 | public Mesh Extrude(Mesh m) | 71 | public Mesh Extrude(Mesh m) |
67 | { | 72 | { |
68 | startParameter = float.MinValue; | 73 | startParameter = float.MinValue; |
@@ -245,6 +250,193 @@ namespace OpenSim.Region.Physics.Meshing | |||
245 | return result; | 250 | return result; |
246 | } | 251 | } |
247 | 252 | ||
253 | /// <summary> | ||
254 | /// Creates an extrusion of a profile along a linear path. Used to create prim types box, cylinder, and prism. | ||
255 | /// </summary> | ||
256 | /// <param name="m"></param> | ||
257 | /// <returns>A mesh of the extruded shape</returns> | ||
258 | public Mesh ExtrudeLinearPath(Mesh m) | ||
259 | { | ||
260 | Mesh result = new Mesh(); | ||
261 | |||
262 | Quaternion tt = new Quaternion(); | ||
263 | Vertex v2 = new Vertex(0, 0, 0); | ||
264 | |||
265 | Mesh newLayer; | ||
266 | Mesh lastLayer = null; | ||
267 | |||
268 | int step = 0; | ||
269 | int steps = 1; | ||
270 | |||
271 | float twistTotal = twistTop - twistBot; | ||
272 | // if the profile has a lot of twist, add more layers otherwise the layers may overlap | ||
273 | // and the resulting mesh may be quite inaccurate. This method is arbitrary and may not | ||
274 | // accurately match the viewer | ||
275 | float twistTotalAbs = System.Math.Abs(twistTotal); | ||
276 | if (twistTotalAbs > 0.01) | ||
277 | steps += (int)(twistTotalAbs * 3.66f); // dahlia's magic number ;) | ||
278 | |||
279 | #if SPAM | ||
280 | System.Console.WriteLine("ExtrudeLinearPath: twistTotalAbs: " + twistTotalAbs.ToString() + " steps: " + steps.ToString()); | ||
281 | #endif | ||
282 | |||
283 | double percentOfPathMultiplier = 1.0 / steps; | ||
284 | |||
285 | float start = -0.5f; | ||
286 | |||
287 | float stepSize = 1.0f / (float)steps; | ||
288 | |||
289 | float xProfileScale = 1.0f; | ||
290 | float yProfileScale = 1.0f; | ||
291 | |||
292 | float xOffset = 0.0f; | ||
293 | float yOffset = 0.0f; | ||
294 | float zOffset = start; | ||
295 | |||
296 | float xOffsetStepIncrement = pushX / steps; | ||
297 | float yOffsetStepIncrement = pushY / steps; | ||
298 | |||
299 | #if SPAM | ||
300 | System.Console.WriteLine("Extruder: twistTop: " + twistTop.ToString() + " twistbot: " + twistBot.ToString() + " twisttotal: " + twistTotal.ToString()); | ||
301 | System.Console.WriteLine("Extruder: taperBotFactorX: " + taperBotFactorX.ToString() + " taperBotFactorY: " + taperBotFactorY.ToString() | ||
302 | + " taperTopFactorX: " + taperTopFactorX.ToString() + " taperTopFactorY: " + taperTopFactorY.ToString()); | ||
303 | System.Console.WriteLine("Extruder: PathScaleX: " + pathScaleX.ToString() + " pathScaleY: " + pathScaleY.ToString()); | ||
304 | #endif | ||
305 | |||
306 | float percentOfPath = 0.0f; | ||
307 | bool done = false; | ||
308 | do // loop through the length of the path and add the layers | ||
309 | { | ||
310 | newLayer = m.Clone(); | ||
311 | |||
312 | if (taperBotFactorX < 1.0f) | ||
313 | xProfileScale = 1.0f - (1.0f - percentOfPath) * (1.0f - taperBotFactorX); | ||
314 | else if (taperTopFactorX < 1.0f) | ||
315 | xProfileScale = 1.0f - percentOfPath * (1.0f - taperTopFactorX); | ||
316 | else xProfileScale = 1.0f; | ||
317 | |||
318 | if (taperBotFactorY < 1.0f) | ||
319 | yProfileScale = 1.0f - (1.0f - percentOfPath) * (1.0f - taperBotFactorY); | ||
320 | else if (taperTopFactorY < 1.0f) | ||
321 | yProfileScale = 1.0f - percentOfPath * (1.0f - taperTopFactorY); | ||
322 | else yProfileScale = 1.0f; | ||
323 | |||
324 | #if SPAM | ||
325 | //System.Console.WriteLine("xProfileScale: " + xProfileScale.ToString() + " yProfileScale: " + yProfileScale.ToString()); | ||
326 | #endif | ||
327 | Vertex vTemp = new Vertex(0.0f, 0.0f, 0.0f); | ||
328 | |||
329 | // apply the taper to the profile before any rotations | ||
330 | if (xProfileScale != 1.0f || yProfileScale != 1.0f) | ||
331 | { | ||
332 | foreach (Vertex v in newLayer.vertices) | ||
333 | { | ||
334 | if (v != null) | ||
335 | { | ||
336 | v.X *= xProfileScale; | ||
337 | v.Y *= yProfileScale; | ||
338 | } | ||
339 | } | ||
340 | } | ||
341 | |||
342 | |||
343 | float twist = twistBot + (twistTotal * (float)percentOfPath); | ||
344 | #if SPAM | ||
345 | System.Console.WriteLine("Extruder: percentOfPath: " + percentOfPath.ToString() + " zOffset: " + zOffset.ToString() | ||
346 | + " xProfileScale: " + xProfileScale.ToString() + " yProfileScale: " + yProfileScale.ToString()); | ||
347 | #endif | ||
348 | |||
349 | // apply twist rotation to the profile layer and position the layer in the prim | ||
350 | |||
351 | Quaternion profileRot = new Quaternion(new Vertex(0.0f, 0.0f, -1.0f), twist); | ||
352 | foreach (Vertex v in newLayer.vertices) | ||
353 | { | ||
354 | if (v != null) | ||
355 | { | ||
356 | vTemp = v * profileRot; | ||
357 | v.X = vTemp.X + xOffset; | ||
358 | v.Y = vTemp.Y + yOffset; | ||
359 | v.Z = vTemp.Z + zOffset; | ||
360 | } | ||
361 | } | ||
362 | |||
363 | if (step == 0) // the first layer, invert normals | ||
364 | { | ||
365 | foreach (Triangle t in newLayer.triangles) | ||
366 | { | ||
367 | t.invertNormal(); | ||
368 | } | ||
369 | } | ||
370 | |||
371 | result.Append(newLayer); | ||
372 | |||
373 | int iLastNull = 0; | ||
374 | |||
375 | if (lastLayer != null) | ||
376 | { | ||
377 | int i, count = newLayer.vertices.Count; | ||
378 | |||
379 | for (i = 0; i < count; i++) | ||
380 | { | ||
381 | int iNext = (i + 1); | ||
382 | |||
383 | if (lastLayer.vertices[i] == null) // cant make a simplex here | ||
384 | { | ||
385 | iLastNull = i + 1; | ||
386 | } | ||
387 | else | ||
388 | { | ||
389 | if (i == count - 1) // End of list | ||
390 | iNext = iLastNull; | ||
391 | |||
392 | if (lastLayer.vertices[iNext] == null) // Null means wrap to begin of last segment | ||
393 | iNext = iLastNull; | ||
394 | |||
395 | result.Add(new Triangle(newLayer.vertices[i], lastLayer.vertices[i], newLayer.vertices[iNext])); | ||
396 | result.Add(new Triangle(newLayer.vertices[iNext], lastLayer.vertices[i], lastLayer.vertices[iNext])); | ||
397 | } | ||
398 | } | ||
399 | } | ||
400 | lastLayer = newLayer; | ||
401 | |||
402 | // calc the step for the next interation of the loop | ||
403 | |||
404 | if (step < steps) | ||
405 | { | ||
406 | step++; | ||
407 | percentOfPath += (float)percentOfPathMultiplier; | ||
408 | |||
409 | xOffset += xOffsetStepIncrement; | ||
410 | yOffset += yOffsetStepIncrement; | ||
411 | zOffset += stepSize; | ||
412 | } | ||
413 | else done = true; | ||
414 | |||
415 | } while (!done); // loop until all the layers in the path are completed | ||
416 | |||
417 | // scale the mesh to the desired size | ||
418 | float xScale = size.X; | ||
419 | float yScale = size.Y; | ||
420 | float zScale = size.Z; | ||
421 | |||
422 | foreach (Vertex v in result.vertices) | ||
423 | { | ||
424 | if (v != null) | ||
425 | { | ||
426 | v.X *= xScale; | ||
427 | v.Y *= yScale; | ||
428 | v.Z *= zScale; | ||
429 | } | ||
430 | } | ||
431 | |||
432 | return result; | ||
433 | } | ||
434 | |||
435 | /// <summary> | ||
436 | /// Extrudes a shape around a circular path. Used to create prim types torus, ring, and tube. | ||
437 | /// </summary> | ||
438 | /// <param name="m"></param> | ||
439 | /// <returns>a mesh of the extruded shape</returns> | ||
248 | public Mesh ExtrudeCircularPath(Mesh m) | 440 | public Mesh ExtrudeCircularPath(Mesh m) |
249 | { | 441 | { |
250 | Mesh result = new Mesh(); | 442 | Mesh result = new Mesh(); |