aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Physics/Meshing/Extruder.cs
diff options
context:
space:
mode:
authorTeravus Ovares2008-05-29 20:20:50 +0000
committerTeravus Ovares2008-05-29 20:20:50 +0000
commit918f887c0c10fda33633548f3601bdf07d74edfd (patch)
tree2db5459288f52117a071fcc51c7f2d1d7a19a3b3 /OpenSim/Region/Physics/Meshing/Extruder.cs
parentMantis#1416. Thank you very much, Melanie for a patch that: (diff)
downloadopensim-SC_OLD-918f887c0c10fda33633548f3601bdf07d74edfd.zip
opensim-SC_OLD-918f887c0c10fda33633548f3601bdf07d74edfd.tar.gz
opensim-SC_OLD-918f887c0c10fda33633548f3601bdf07d74edfd.tar.bz2
opensim-SC_OLD-918f887c0c10fda33633548f3601bdf07d74edfd.tar.xz
* Applying Dahlia's interim path curve patch. it adds initial support for some tori/ring parameters. Thanks Dahlia!
* Some situations do not match the client's render of the tori, we know and are working on it. This is an initial support patch, so expect it to not be exact. * Some tapers are acting slightly odd. Will fix.
Diffstat (limited to 'OpenSim/Region/Physics/Meshing/Extruder.cs')
-rw-r--r--OpenSim/Region/Physics/Meshing/Extruder.cs211
1 files changed, 211 insertions, 0 deletions
diff --git a/OpenSim/Region/Physics/Meshing/Extruder.cs b/OpenSim/Region/Physics/Meshing/Extruder.cs
index c7dcf33..480ffda 100644
--- a/OpenSim/Region/Physics/Meshing/Extruder.cs
+++ b/OpenSim/Region/Physics/Meshing/Extruder.cs
@@ -47,6 +47,21 @@ namespace OpenSim.Region.Physics.Meshing
47 public float twistTop = 0; 47 public float twistTop = 0;
48 public float twistBot = 0; 48 public float twistBot = 0;
49 public float twistMid = 0; 49 public float twistMid = 0;
50 public float pathScaleX = 1.0f;
51 public float pathScaleY = 0.5f;
52 public float skew = 0.0f;
53 public float radius = 0.0f;
54 public float revolutions = 1.0f;
55
56 public float pathCutBegin = 0.0f;
57 public float pathCutEnd = 1.0f;
58
59 public ushort pathBegin = 0;
60 public ushort pathEnd = 0;
61
62 public float pathTaperX = 0.0f;
63 public float pathTaperY = 0.0f;
64
50 65
51 public Mesh Extrude(Mesh m) 66 public Mesh Extrude(Mesh m)
52 { 67 {
@@ -230,5 +245,201 @@ namespace OpenSim.Region.Physics.Meshing
230 } 245 }
231 return result; 246 return result;
232 } 247 }
248 public Mesh ExtrudeCircularPath(Mesh m)
249 {
250 //startParameter = float.MinValue;
251 //stopParameter = float.MaxValue;
252 // Currently only works for iSteps=1;
253 Mesh result = new Mesh();
254
255 Quaternion tt = new Quaternion();
256 Vertex v2 = new Vertex(0, 0, 0);
257
258 Mesh newLayer;
259 Mesh lastLayer = null;
260
261 int start = 0;
262 int step;
263 int steps = 24;
264
265 float twistTotal = twistTop - twistBot;
266 if (System.Math.Abs(twistTotal) > (float)System.Math.PI * 1.5) steps *= 2;
267 if (System.Math.Abs(twistTotal) > (float)System.Math.PI * 3.0) steps *= 2;
268
269 double percentOfPathMultiplier = 1.0 / steps;
270 double angleStepMultiplier = System.Math.PI * 2.0 / steps;
271
272 //System.Console.WriteLine("twistTop: " + twistTop.ToString() + " twistbot: " + twistBot.ToString() + " twisttotal: " + twistTotal.ToString());
273
274 float yPathScale = pathScaleY * 0.5f;
275 float skewStart = -skew;
276 float skewOffset = 0.0f;
277 float totalSkew = skew * 2.0f;
278
279
280 float startAngle = (float)(System.Math.PI * 2.0 * pathCutBegin * revolutions);
281 float endAngle = (float)(System.Math.PI * 2.0 * pathCutEnd * revolutions);
282 float stepSize = (float)0.2617993878; // 2*PI / 24 segments
283 step = (int)(startAngle / stepSize);
284 float angle = startAngle;
285
286 float xProfileScale = 1.0f;
287 float yProfileScale = 1.0f;
288
289 //System.Console.WriteLine("startAngle: " + startAngle.ToString() + " endAngle: " + endAngle.ToString() + " step: " + step.ToString());
290 bool done = false;
291
292 //System.Console.WriteLine(" PathScaleX: " + pathScaleX.ToString() + " pathScaleY: " + pathScaleY.ToString());
293
294 //System.Console.WriteLine("taperBotFactorX: " + taperBotFactorX.ToString() + " taperBotFactorY: " + taperBotFactorY.ToString()
295 // + " taperTopFactorX: " + taperTopFactorX.ToString() + " taperTopFactorY: " + taperTopFactorY.ToString());
296
297
298
299 do
300 {
301 float percentOfPath = 1.0f;
302
303 percentOfPath = (angle - startAngle) / (endAngle - startAngle); // endAngle should always be larger than startAngle
304
305 // System.Console.WriteLine("angle: " + angle.ToString() + " percentOfPath: " + percentOfPath.ToString());
306
307 if (pathTaperX > 0.001f) // can't really compare to 0.0f as the value passed is never exactly zero
308 xProfileScale = 1.0f - percentOfPath * pathTaperX;
309 else if (pathTaperX < -0.001f)
310 xProfileScale = 1.0f + (1.0f - percentOfPath) * pathTaperX;
311 else xProfileScale = 1.0f;
312
313 if (pathTaperY > 0.001f)
314 yProfileScale = 1.0f - percentOfPath * pathTaperY;
315 else if (pathTaperY < -0.001f)
316 yProfileScale = 1.0f + (1.0f - percentOfPath) * pathTaperY;
317 else yProfileScale = 1.0f;
318
319 float radiusScale;
320
321 if (radius > 0.001f)
322 radiusScale = 1.0f - radius * percentOfPath;
323 else if (radius < 0.001f)
324 radiusScale = 1.0f + radius * (1.0f - percentOfPath);
325 else radiusScale = 1.0f;
326
327 //radiusScale = 1.0f;
328
329 //System.Console.WriteLine("Extruder: radius: " + radius.ToString() + " radiusScale: " + radiusScale.ToString());
330
331
332
333
334
335 float twist = twistBot + (twistTotal * (float)percentOfPath);
336
337 float zOffset = (float)(System.Math.Sin(angle) * (0.5f - yPathScale)) * radiusScale;
338 float yOffset = (float)(System.Math.Cos(angle) * (0.5f - yPathScale)) * radiusScale;
339 float xOffset = 0.5f * (skewStart + totalSkew * (float)percentOfPath);
340
341 newLayer = m.Clone();
342
343 Vertex vTemp = new Vertex(0.0f, 0.0f, 0.0f);
344
345 if (twistTotal != 0.0f || twistBot != 0.0f)
346 {
347 Quaternion profileRot = new Quaternion(new Vertex(0.0f, 0.0f, -1.0f), twist);
348 foreach (Vertex v in newLayer.vertices)
349 {
350 if (v != null)
351 {
352 vTemp = v * profileRot;
353 v.X = vTemp.X;
354 v.Y = vTemp.Y;
355 v.Z = vTemp.Z;
356 }
357 }
358 }
359
360 Quaternion layerRot = new Quaternion(new Vertex(-1.0f, 0.0f, 0.0f), (float)angle);
361 foreach (Vertex v in newLayer.vertices)
362 {
363 if (v != null)
364 {
365 vTemp = v * layerRot;
366 v.X = xProfileScale * vTemp.X + xOffset;
367 v.Y = yProfileScale * vTemp.Y + yOffset;
368 v.Z = vTemp.Z + zOffset;
369 }
370 }
371
372 if (angle == startAngle) // last layer, invert normals
373 foreach (Triangle t in newLayer.triangles)
374 {
375 t.invertNormal();
376 }
377
378 result.Append(newLayer);
379
380 int iLastNull = 0;
381
382 if (lastLayer != null)
383 {
384 int i, count = newLayer.vertices.Count;
385
386 for (i = 0; i < count; i++)
387 {
388 int iNext = (i + 1);
389
390 if (lastLayer.vertices[i] == null) // cant make a simplex here
391 iLastNull = i + 1;
392 else
393 {
394 if (i == count - 1) // End of list
395 iNext = iLastNull;
396
397 if (lastLayer.vertices[iNext] == null) // Null means wrap to begin of last segment
398 iNext = iLastNull;
399
400 result.Add(new Triangle(newLayer.vertices[i], lastLayer.vertices[i], newLayer.vertices[iNext]));
401 result.Add(new Triangle(newLayer.vertices[iNext], lastLayer.vertices[i], lastLayer.vertices[iNext]));
402 }
403 }
404 }
405 lastLayer = newLayer;
406
407
408
409
410
411
412
413
414 // calc next angle
415
416 if (angle >= endAngle)
417 done = true;
418 else
419 {
420 angle = stepSize * ++step;
421 if (angle > endAngle)
422 angle = endAngle;
423 }
424 }
425 while (!done);
426
427
428
429 // scale the mesh to the desired size
430 float xScale = size.X;
431 float yScale = size.Y;
432 float zScale = size.Z;
433
434 foreach (Vertex v in result.vertices)
435 if (v != null)
436 {
437 v.X *= xScale;
438 v.Y *= yScale;
439 v.Z *= zScale;
440 }
441
442 return result;
443 }
233 } 444 }
234} 445}