From 1d3677eb9b31cc9a1238caabd464538438d573af Mon Sep 17 00:00:00 2001 From: Dahlia Trimble Date: Fri, 1 Aug 2008 05:45:58 +0000 Subject: Thank you jhurliman for a meshmerizer patch that replaces the quaternion->matrix->vertex*matrix->vertex code with a direct transformation. --- OpenSim/Region/Physics/Meshing/Extruder.cs | 193 +------------------------- OpenSim/Region/Physics/Meshing/HelperTypes.cs | 114 +++++---------- OpenSim/Region/Physics/Meshing/Meshmerizer.cs | 14 -- 3 files changed, 39 insertions(+), 282 deletions(-) (limited to 'OpenSim') diff --git a/OpenSim/Region/Physics/Meshing/Extruder.cs b/OpenSim/Region/Physics/Meshing/Extruder.cs index 77bd9a4..b14deeb 100644 --- a/OpenSim/Region/Physics/Meshing/Extruder.cs +++ b/OpenSim/Region/Physics/Meshing/Extruder.cs @@ -64,193 +64,6 @@ namespace OpenSim.Region.Physics.Meshing public float pathTaperY = 0.0f; /// - /// (deprecated) creates a 3 layer extruded mesh of a profile hull - /// - /// - /// - public Mesh Extrude(Mesh m) - { - startParameter = float.MinValue; - stopParameter = float.MaxValue; - // Currently only works for iSteps=1; - Mesh result = new Mesh(); - - Mesh workingPlus = m.Clone(); - Mesh workingMiddle = m.Clone(); - Mesh workingMinus = m.Clone(); - - Quaternion tt = new Quaternion(); - Vertex v2 = new Vertex(0, 0, 0); - - foreach (Vertex v in workingPlus.vertices) - { - if (v == null) - continue; - - // This is the top - // Set the Z + .5 to match the rest of the scale of the mesh - // Scale it by Size, and Taper the scaling - v.Z = +.5f; - v.X *= (size.X * taperTopFactorX); - v.Y *= (size.Y * taperTopFactorY); - v.Z *= size.Z; - - //Push the top of the object over by the Top Shear amount - v.X += pushX * size.X; - v.Y += pushY * size.Y; - - if (twistTop != 0) - { - // twist and shout - tt = new Quaternion(new Vertex(0, 0, 1), twistTop); - v2 = v * tt; - v.X = v2.X; - v.Y = v2.Y; - v.Z = v2.Z; - } - } - - foreach (Vertex v in workingMiddle.vertices) - { - if (v == null) - continue; - - // This is the top - // Set the Z + .5 to match the rest of the scale of the mesh - // Scale it by Size, and Taper the scaling - v.Z *= size.Z; - v.X *= (size.X * ((taperTopFactorX + taperBotFactorX) /2)); - v.Y *= (size.Y * ((taperTopFactorY + taperBotFactorY) / 2)); - - v.X += (pushX / 2) * size.X; - v.Y += (pushY / 2) * size.Y; - //Push the top of the object over by the Top Shear amount - if (twistMid != 0) - { - // twist and shout - tt = new Quaternion(new Vertex(0, 0, 1), twistMid); - v2 = v * tt; - v.X = v2.X; - v.Y = v2.Y; - v.Z = v2.Z; - } - } - - foreach (Vertex v in workingMinus.vertices) - { - if (v == null) - continue; - - // This is the bottom - v.Z = -.5f; - v.X *= (size.X * taperBotFactorX); - v.Y *= (size.Y * taperBotFactorY); - v.Z *= size.Z; - - if (twistBot != 0) - { - // twist and shout - tt = new Quaternion(new Vertex(0, 0, 1), twistBot); - v2 = v * tt; - v.X = v2.X; - v.Y = v2.Y; - v.Z = v2.Z; - } - } - - foreach (Triangle t in workingMinus.triangles) - { - t.invertNormal(); - } - - result.Append(workingMinus); - result.Append(workingMiddle); - - int iLastNull = 0; - - for (int i = 0; i < workingMiddle.vertices.Count; i++) - { - int iNext = i + 1; - - if (workingMiddle.vertices[i] == null) // Can't make a simplex here - { - iLastNull = i + 1; - continue; - } - - if (i == workingMiddle.vertices.Count - 1) // End of list - { - iNext = iLastNull; - } - - if (workingMiddle.vertices[iNext] == null) // Null means wrap to begin of last segment - { - iNext = iLastNull; - } - - Triangle tSide; - tSide = new Triangle(workingMiddle.vertices[i], workingMinus.vertices[i], workingMiddle.vertices[iNext]); - result.Add(tSide); - - tSide = - new Triangle(workingMiddle.vertices[iNext], workingMinus.vertices[i], workingMinus.vertices[iNext]); - result.Add(tSide); - } - //foreach (Triangle t in workingPlus.triangles) - //{ - //t.invertNormal(); - // } - result.Append(workingPlus); - - iLastNull = 0; - for (int i = 0; i < workingPlus.vertices.Count; i++) - { - int iNext = i + 1; - - if (workingPlus.vertices[i] == null) // Can't make a simplex here - { - iLastNull = i + 1; - continue; - } - - if (i == workingPlus.vertices.Count - 1) // End of list - { - iNext = iLastNull; - } - - if (workingPlus.vertices[iNext] == null) // Null means wrap to begin of last segment - { - iNext = iLastNull; - } - - Triangle tSide; - tSide = new Triangle(workingPlus.vertices[i], workingMiddle.vertices[i], workingPlus.vertices[iNext]); - result.Add(tSide); - - tSide = - new Triangle(workingPlus.vertices[iNext], workingMiddle.vertices[i], workingMiddle.vertices[iNext]); - result.Add(tSide); - } - - if (twistMid != 0) - { - foreach (Vertex v in result.vertices) - { - // twist and shout - if (v != null) - { - tt = new Quaternion(new Vertex(0, 0, -1), twistMid*2); - v2 = v * tt; - v.X = v2.X; - v.Y = v2.Y; - v.Z = v2.Z; - } - } - } - return result; - } - - /// /// Creates an extrusion of a profile along a linear path. Used to create prim types box, cylinder, and prism. /// /// @@ -350,7 +163,7 @@ namespace OpenSim.Region.Physics.Meshing // apply twist rotation to the profile layer and position the layer in the prim - Quaternion profileRot = new Quaternion(new Vertex(0.0f, 0.0f, -1.0f), twist); + Quaternion profileRot = new Quaternion(new Vertex(0.0f, 0.0f, 1.0f), twist); foreach (Vertex v in newLayer.vertices) { if (v != null) @@ -566,7 +379,7 @@ namespace OpenSim.Region.Physics.Meshing // next apply twist rotation to the profile layer if (twistTotal != 0.0f || twistBot != 0.0f) { - Quaternion profileRot = new Quaternion(new Vertex(0.0f, 0.0f, -1.0f), twist); + Quaternion profileRot = new Quaternion(new Vertex(0.0f, 0.0f, 1.0f), twist); foreach (Vertex v in newLayer.vertices) { if (v != null) @@ -581,7 +394,7 @@ namespace OpenSim.Region.Physics.Meshing // now orient the rotation of the profile layer relative to it's position on the path // adding pushY to the angle used to generate the quat appears to approximate the viewer - Quaternion layerRot = new Quaternion(new Vertex(-1.0f, 0.0f, 0.0f), (float)angle + pushY * 0.9f); + Quaternion layerRot = new Quaternion(new Vertex(1.0f, 0.0f, 0.0f), (float)angle + pushY * 0.9f); foreach (Vertex v in newLayer.vertices) { if (v != null) diff --git a/OpenSim/Region/Physics/Meshing/HelperTypes.cs b/OpenSim/Region/Physics/Meshing/HelperTypes.cs index 418baf5..816b6bb 100644 --- a/OpenSim/Region/Physics/Meshing/HelperTypes.cs +++ b/OpenSim/Region/Physics/Meshing/HelperTypes.cs @@ -70,11 +70,6 @@ public class Quaternion return c; } - - public Matrix4 computeMatrix() - { - return new Matrix4(this); - } public void normalize() { //float mag = length(); @@ -95,77 +90,8 @@ public class Quaternion return (float)Math.Sqrt(w * w + x * x + y * y + z * z); } } -public class Matrix4 -{ - public float m00 = 0; - public float m01 = 0; - public float m02 = 0; - public float m03 = 0; - public float m10 = 0; - public float m11 = 0; - public float m12 = 0; - public float m13 = 0; - public float m20 = 0; - public float m21 = 0; - public float m22 = 0; - public float m23 = 0; - public float m30 = 0; - public float m31 = 0; - public float m32 = 0; - public float m33 = 1; - - public Matrix4(float m001, float m011, float m021, float m031, float m101, float m111, float m121, float m131, float m201, float m211, float m221, float m231, float m301, float m311, float m321, float m331) - { - m00 = m001; - m01 = m011; - m02 = m021; - m03 = m031; - m10 = m101; - m11 = m111; - m12 = m121; - m13 = m131; - m20 = m201; - m21 = m211; - m22 = m221; - m23 = m231; - m30 = m301; - m31 = m311; - m32 = m321; - m33 = m331; - } - public Matrix4() - { - } - public Matrix4(Quaternion r) - { - m00 = 1 - (2 * (r.y * r.y)) - (2 * (r.z * r.z)); - m01 = (r.x * r.y * 2) - (r.w * r.z * 2); - m02 = (r.x * r.z * 2) + (r.w * r.y * 2); - m03 = 0f; - m10 = (r.x * r.y * 2) + (r.w * r.z * 2); - m11 = 1 - (2 * (r.x * r.x)) - (2 * (r.z * r.z)); - m12 = (r.y * r.z * 2) - (r.w * r.x * 2); - m13 = 0f; - m20 = (r.x * r.z * 2) - (r.w * r.y * 2); - m21 = (r.y * r.z * 2) - (r.w * r.x * 2); - m22 = 1 - (2 * (r.x * r.x)) - (2 * (r.y * r.y)); - m23 = 0f; - m30 = 0f; - m31 = 0f; - m32 = 0f; - m33 = 1f; - } - public Vertex transform(Vertex o) - { - Vertex r = new Vertex(0,0,0); - // w value implicitly 1 therefore the last + m3x actually represents (m3x * o.W) = m3x - // in calculating the dot product. - r.X = (m00 * o.X) + (m10 * o.Y) + (m20 * o.Z) + m30; - r.Y = (m01 * o.X) + (m11 * o.Y) + (m21 * o.Z) + m31; - r.Z = (m02 * o.X) + (m12 * o.Y) + (m22 * o.Z) + m32; - return r; - } -} + + public class Vertex : PhysicsVector, IComparable { @@ -199,8 +125,40 @@ public class Vertex : PhysicsVector, IComparable #pragma warning disable 0108 public static Vertex operator *(Vertex v, Quaternion q) { - Matrix4 tm = q.computeMatrix(); - return tm.transform(v); + // From http://www.euclideanspace.com/maths/algebra/realNormedAlgebra/quaternions/transforms/ + + Vertex v2 = new Vertex(0f, 0f, 0f); + + v2.X = q.w * q.w * v.X + + 2f * q.y * q.w * v.Z - + 2f * q.z * q.w * v.Y + + q.x * q.x * v.X + + 2f * q.y * q.x * v.Y + + 2f * q.z * q.x * v.Z - + q.z * q.z * v.X - + q.y * q.y * v.X; + + v2.Y = + 2f * q.x * q.y * v.X + + q.y * q.y * v.Y + + 2f * q.z * q.y * v.Z + + 2f * q.w * q.z * v.X - + q.z * q.z * v.Y + + q.w * q.w * v.Y - + 2f * q.x * q.w * v.Z - + q.x * q.x * v.Y; + + v2.Z = + 2f * q.x * q.z * v.X + + 2f * q.y * q.z * v.Y + + q.z * q.z * v.Z - + 2f * q.w * q.y * v.X - + q.y * q.y * v.Z + + 2f * q.w * q.x * v.Y - + q.x * q.x * v.Z + + q.w * q.w * v.Z; + + return v2; } public static Vertex operator +(Vertex v1, Vertex v2) diff --git a/OpenSim/Region/Physics/Meshing/Meshmerizer.cs b/OpenSim/Region/Physics/Meshing/Meshmerizer.cs index 984114b..58da667 100644 --- a/OpenSim/Region/Physics/Meshing/Meshmerizer.cs +++ b/OpenSim/Region/Physics/Meshing/Meshmerizer.cs @@ -1556,20 +1556,6 @@ namespace OpenSim.Region.Physics.Meshing // m_log.DebugFormat("Starting cutting of the hollow shape from the prim {1}", 0, primName); SimpleHull cuttedHull = SimpleHull.SubtractHull(outerHull, cutHull); - if ((primShape.ProfileCurve & 0x07) == (byte)ProfileShape.Circle) - { - Quaternion zFlip = new Quaternion(new Vertex(0.0f, 0.0f, 1.0f), (float)Math.PI); - Vertex vTmp = new Vertex(0.0f, 0.0f, 0.0f); - foreach (Vertex v in cuttedHull.getVertices()) - if (v != null) - { - vTmp = v * zFlip; - v.X = vTmp.X; - v.Y = vTmp.Y; - v.Z = vTmp.Z; - } - } - outerHull = cuttedHull; } -- cgit v1.1