diff options
author | Dahlia Trimble | 2008-07-11 17:22:37 +0000 |
---|---|---|
committer | Dahlia Trimble | 2008-07-11 17:22:37 +0000 |
commit | 3646cc32c45353eafe630e75fe39cabd1bd8b106 (patch) | |
tree | dc8a29b2f4a5cf67db983f6b4e612362039aad3f | |
parent | * Oops, turn off permissions debugging I stupidly hardcoded (diff) | |
download | opensim-SC-3646cc32c45353eafe630e75fe39cabd1bd8b106.zip opensim-SC-3646cc32c45353eafe630e75fe39cabd1bd8b106.tar.gz opensim-SC-3646cc32c45353eafe630e75fe39cabd1bd8b106.tar.bz2 opensim-SC-3646cc32c45353eafe630e75fe39cabd1bd8b106.tar.xz |
Experimental physics optimization: prims with all 3 dimensions less than 0.2 meters will be meshed as a simple box
-rw-r--r-- | OpenSim/Region/Physics/Meshing/Meshmerizer.cs | 101 |
1 files changed, 101 insertions, 0 deletions
diff --git a/OpenSim/Region/Physics/Meshing/Meshmerizer.cs b/OpenSim/Region/Physics/Meshing/Meshmerizer.cs index 4511c4c..55a1bec 100644 --- a/OpenSim/Region/Physics/Meshing/Meshmerizer.cs +++ b/OpenSim/Region/Physics/Meshing/Meshmerizer.cs | |||
@@ -64,6 +64,8 @@ namespace OpenSim.Region.Physics.Meshing | |||
64 | #endif | 64 | #endif |
65 | private const float DEG_TO_RAD = 0.01745329238f; | 65 | private const float DEG_TO_RAD = 0.01745329238f; |
66 | 66 | ||
67 | private float minSizeForComplexMesh = 0.2f; // prims with all dimensions smaller than this will have a bounding box mesh | ||
68 | |||
67 | // TODO: unused | 69 | // TODO: unused |
68 | // private static void IntersectionParameterPD(PhysicsVector p1, PhysicsVector r1, PhysicsVector p2, | 70 | // private static void IntersectionParameterPD(PhysicsVector p1, PhysicsVector r1, PhysicsVector p2, |
69 | // PhysicsVector r2, ref float lambda, ref float mu) | 71 | // PhysicsVector r2, ref float lambda, ref float mu) |
@@ -422,6 +424,95 @@ namespace OpenSim.Region.Physics.Meshing | |||
422 | 424 | ||
423 | } | 425 | } |
424 | 426 | ||
427 | /// <summary> | ||
428 | /// creates a simple box mesh of the specified size | ||
429 | /// </summary> | ||
430 | /// <param name="minX"></param> | ||
431 | /// <param name="maxX"></param> | ||
432 | /// <param name="minY"></param> | ||
433 | /// <param name="maxY"></param> | ||
434 | /// <param name="minZ"></param> | ||
435 | /// <param name="maxZ"></param> | ||
436 | /// <returns></returns> | ||
437 | private static Mesh CreateSimpleBoxMesh(float minX, float maxX, float minY, float maxY, float minZ, float maxZ) | ||
438 | { | ||
439 | Mesh box = new Mesh(); | ||
440 | |||
441 | // bottom | ||
442 | |||
443 | //box.Add(new Vertex(maxX, maxY, minZ)); | ||
444 | //box.Add(new Vertex(minX, maxY, minZ)); | ||
445 | //box.Add(new Vertex(minX, minY, minZ)); | ||
446 | //box.Add(new Vertex(maxX, minY, minZ)); | ||
447 | |||
448 | box.Add(new Vertex(minX, maxY, minZ)); | ||
449 | box.Add(new Vertex(maxX, maxY, minZ)); | ||
450 | box.Add(new Vertex(maxX, minY, minZ)); | ||
451 | box.Add(new Vertex(minX, minY, minZ)); | ||
452 | |||
453 | box.Add(new Triangle(box.vertices[0], box.vertices[1], box.vertices[2])); | ||
454 | box.Add(new Triangle(box.vertices[0], box.vertices[2], box.vertices[3])); | ||
455 | |||
456 | // top | ||
457 | |||
458 | box.Add(new Vertex(maxX, maxY, maxZ)); | ||
459 | box.Add(new Vertex(minX, maxY, maxZ)); | ||
460 | box.Add(new Vertex(minX, minY, maxZ)); | ||
461 | box.Add(new Vertex(maxX, minY, maxZ)); | ||
462 | |||
463 | box.Add(new Triangle(box.vertices[4], box.vertices[5], box.vertices[6])); | ||
464 | box.Add(new Triangle(box.vertices[4], box.vertices[6], box.vertices[7])); | ||
465 | |||
466 | // sides | ||
467 | |||
468 | box.Add(new Triangle(box.vertices[5], box.vertices[0], box.vertices[3])); | ||
469 | box.Add(new Triangle(box.vertices[5], box.vertices[3], box.vertices[6])); | ||
470 | |||
471 | box.Add(new Triangle(box.vertices[1], box.vertices[0], box.vertices[5])); | ||
472 | box.Add(new Triangle(box.vertices[1], box.vertices[5], box.vertices[4])); | ||
473 | |||
474 | box.Add(new Triangle(box.vertices[7], box.vertices[1], box.vertices[4])); | ||
475 | box.Add(new Triangle(box.vertices[7], box.vertices[2], box.vertices[1])); | ||
476 | |||
477 | box.Add(new Triangle(box.vertices[3], box.vertices[2], box.vertices[7])); | ||
478 | box.Add(new Triangle(box.vertices[3], box.vertices[7], box.vertices[6])); | ||
479 | |||
480 | return box; | ||
481 | } | ||
482 | |||
483 | |||
484 | /// <summary> | ||
485 | /// Creates a simple bounding box mesh for a complex input mesh | ||
486 | /// </summary> | ||
487 | /// <param name="meshIn"></param> | ||
488 | /// <returns></returns> | ||
489 | private static Mesh CreateBoundingBoxMesh(Mesh meshIn) | ||
490 | { | ||
491 | float minX = float.MaxValue; | ||
492 | float maxX = float.MinValue; | ||
493 | float minY = float.MaxValue; | ||
494 | float maxY = float.MinValue; | ||
495 | float minZ = float.MaxValue; | ||
496 | float maxZ = float.MinValue; | ||
497 | |||
498 | foreach (Vertex v in meshIn.vertices) | ||
499 | { | ||
500 | if (v != null) | ||
501 | { | ||
502 | if (v.X < minX) minX = v.X; | ||
503 | if (v.Y < minY) minY = v.Y; | ||
504 | if (v.Z < minZ) minZ = v.Z; | ||
505 | |||
506 | if (v.X > maxX) maxX = v.X; | ||
507 | if (v.Y > maxY) maxY = v.Y; | ||
508 | if (v.Z > maxZ) maxZ = v.Z; | ||
509 | } | ||
510 | } | ||
511 | |||
512 | return CreateSimpleBoxMesh(minX, maxX, minY, maxY, minZ, maxZ); | ||
513 | } | ||
514 | |||
515 | |||
425 | private static Mesh CreateBoxMesh(String primName, PrimitiveBaseShape primShape, PhysicsVector size) | 516 | private static Mesh CreateBoxMesh(String primName, PrimitiveBaseShape primShape, PhysicsVector size) |
426 | // Builds the z (+ and -) surfaces of a box shaped prim | 517 | // Builds the z (+ and -) surfaces of a box shaped prim |
427 | { | 518 | { |
@@ -1967,6 +2058,7 @@ namespace OpenSim.Region.Physics.Meshing | |||
1967 | public IMesh CreateMesh(String primName, PrimitiveBaseShape primShape, PhysicsVector size, float lod) | 2058 | public IMesh CreateMesh(String primName, PrimitiveBaseShape primShape, PhysicsVector size, float lod) |
1968 | { | 2059 | { |
1969 | Mesh mesh = null; | 2060 | Mesh mesh = null; |
2061 | |||
1970 | if (primShape.SculptEntry && primShape.SculptType != (byte)0 && primShape.SculptData.Length > 0) | 2062 | if (primShape.SculptEntry && primShape.SculptType != (byte)0 && primShape.SculptData.Length > 0) |
1971 | { | 2063 | { |
1972 | 2064 | ||
@@ -2081,6 +2173,15 @@ namespace OpenSim.Region.Physics.Meshing | |||
2081 | // } | 2173 | // } |
2082 | //} | 2174 | //} |
2083 | 2175 | ||
2176 | if (mesh != null && size.X < minSizeForComplexMesh && size.Y < minSizeForComplexMesh && size.Z < minSizeForComplexMesh) | ||
2177 | { | ||
2178 | #if SPAM | ||
2179 | Console.WriteLine("Meshmerizer: prim " + primName + " has a size of " + size.ToString() + " which is below threshold of " + minSizeForComplexMesh.ToString() + " - creating simple bounding box" ); | ||
2180 | #endif | ||
2181 | mesh = CreateBoundingBoxMesh(mesh); | ||
2182 | mesh.DumpRaw(baseDir, primName, "Z extruded"); | ||
2183 | } | ||
2184 | |||
2084 | return mesh; | 2185 | return mesh; |
2085 | } | 2186 | } |
2086 | 2187 | ||