aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim')
-rw-r--r--OpenSim/Region/Physics/Meshing/Extruder.cs193
-rw-r--r--OpenSim/Region/Physics/Meshing/HelperTypes.cs114
-rw-r--r--OpenSim/Region/Physics/Meshing/Meshmerizer.cs14
3 files changed, 39 insertions, 282 deletions
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
64 public float pathTaperY = 0.0f; 64 public float pathTaperY = 0.0f;
65 65
66 /// <summary> 66 /// <summary>
67 /// (deprecated) creates a 3 layer extruded mesh of a profile hull
68 /// </summary>
69 /// <param name="m"></param>
70 /// <returns></returns>
71 public Mesh Extrude(Mesh m)
72 {
73 startParameter = float.MinValue;
74 stopParameter = float.MaxValue;
75 // Currently only works for iSteps=1;
76 Mesh result = new Mesh();
77
78 Mesh workingPlus = m.Clone();
79 Mesh workingMiddle = m.Clone();
80 Mesh workingMinus = m.Clone();
81
82 Quaternion tt = new Quaternion();
83 Vertex v2 = new Vertex(0, 0, 0);
84
85 foreach (Vertex v in workingPlus.vertices)
86 {
87 if (v == null)
88 continue;
89
90 // This is the top
91 // Set the Z + .5 to match the rest of the scale of the mesh
92 // Scale it by Size, and Taper the scaling
93 v.Z = +.5f;
94 v.X *= (size.X * taperTopFactorX);
95 v.Y *= (size.Y * taperTopFactorY);
96 v.Z *= size.Z;
97
98 //Push the top of the object over by the Top Shear amount
99 v.X += pushX * size.X;
100 v.Y += pushY * size.Y;
101
102 if (twistTop != 0)
103 {
104 // twist and shout
105 tt = new Quaternion(new Vertex(0, 0, 1), twistTop);
106 v2 = v * tt;
107 v.X = v2.X;
108 v.Y = v2.Y;
109 v.Z = v2.Z;
110 }
111 }
112
113 foreach (Vertex v in workingMiddle.vertices)
114 {
115 if (v == null)
116 continue;
117
118 // This is the top
119 // Set the Z + .5 to match the rest of the scale of the mesh
120 // Scale it by Size, and Taper the scaling
121 v.Z *= size.Z;
122 v.X *= (size.X * ((taperTopFactorX + taperBotFactorX) /2));
123 v.Y *= (size.Y * ((taperTopFactorY + taperBotFactorY) / 2));
124
125 v.X += (pushX / 2) * size.X;
126 v.Y += (pushY / 2) * size.Y;
127 //Push the top of the object over by the Top Shear amount
128 if (twistMid != 0)
129 {
130 // twist and shout
131 tt = new Quaternion(new Vertex(0, 0, 1), twistMid);
132 v2 = v * tt;
133 v.X = v2.X;
134 v.Y = v2.Y;
135 v.Z = v2.Z;
136 }
137 }
138
139 foreach (Vertex v in workingMinus.vertices)
140 {
141 if (v == null)
142 continue;
143
144 // This is the bottom
145 v.Z = -.5f;
146 v.X *= (size.X * taperBotFactorX);
147 v.Y *= (size.Y * taperBotFactorY);
148 v.Z *= size.Z;
149
150 if (twistBot != 0)
151 {
152 // twist and shout
153 tt = new Quaternion(new Vertex(0, 0, 1), twistBot);
154 v2 = v * tt;
155 v.X = v2.X;
156 v.Y = v2.Y;
157 v.Z = v2.Z;
158 }
159 }
160
161 foreach (Triangle t in workingMinus.triangles)
162 {
163 t.invertNormal();
164 }
165
166 result.Append(workingMinus);
167 result.Append(workingMiddle);
168
169 int iLastNull = 0;
170
171 for (int i = 0; i < workingMiddle.vertices.Count; i++)
172 {
173 int iNext = i + 1;
174
175 if (workingMiddle.vertices[i] == null) // Can't make a simplex here
176 {
177 iLastNull = i + 1;
178 continue;
179 }
180
181 if (i == workingMiddle.vertices.Count - 1) // End of list
182 {
183 iNext = iLastNull;
184 }
185
186 if (workingMiddle.vertices[iNext] == null) // Null means wrap to begin of last segment
187 {
188 iNext = iLastNull;
189 }
190
191 Triangle tSide;
192 tSide = new Triangle(workingMiddle.vertices[i], workingMinus.vertices[i], workingMiddle.vertices[iNext]);
193 result.Add(tSide);
194
195 tSide =
196 new Triangle(workingMiddle.vertices[iNext], workingMinus.vertices[i], workingMinus.vertices[iNext]);
197 result.Add(tSide);
198 }
199 //foreach (Triangle t in workingPlus.triangles)
200 //{
201 //t.invertNormal();
202 // }
203 result.Append(workingPlus);
204
205 iLastNull = 0;
206 for (int i = 0; i < workingPlus.vertices.Count; i++)
207 {
208 int iNext = i + 1;
209
210 if (workingPlus.vertices[i] == null) // Can't make a simplex here
211 {
212 iLastNull = i + 1;
213 continue;
214 }
215
216 if (i == workingPlus.vertices.Count - 1) // End of list
217 {
218 iNext = iLastNull;
219 }
220
221 if (workingPlus.vertices[iNext] == null) // Null means wrap to begin of last segment
222 {
223 iNext = iLastNull;
224 }
225
226 Triangle tSide;
227 tSide = new Triangle(workingPlus.vertices[i], workingMiddle.vertices[i], workingPlus.vertices[iNext]);
228 result.Add(tSide);
229
230 tSide =
231 new Triangle(workingPlus.vertices[iNext], workingMiddle.vertices[i], workingMiddle.vertices[iNext]);
232 result.Add(tSide);
233 }
234
235 if (twistMid != 0)
236 {
237 foreach (Vertex v in result.vertices)
238 {
239 // twist and shout
240 if (v != null)
241 {
242 tt = new Quaternion(new Vertex(0, 0, -1), twistMid*2);
243 v2 = v * tt;
244 v.X = v2.X;
245 v.Y = v2.Y;
246 v.Z = v2.Z;
247 }
248 }
249 }
250 return result;
251 }
252
253 /// <summary>
254 /// Creates an extrusion of a profile along a linear path. Used to create prim types box, cylinder, and prism. 67 /// Creates an extrusion of a profile along a linear path. Used to create prim types box, cylinder, and prism.
255 /// </summary> 68 /// </summary>
256 /// <param name="m"></param> 69 /// <param name="m"></param>
@@ -350,7 +163,7 @@ namespace OpenSim.Region.Physics.Meshing
350 163
351 // apply twist rotation to the profile layer and position the layer in the prim 164 // apply twist rotation to the profile layer and position the layer in the prim
352 165
353 Quaternion profileRot = new Quaternion(new Vertex(0.0f, 0.0f, -1.0f), twist); 166 Quaternion profileRot = new Quaternion(new Vertex(0.0f, 0.0f, 1.0f), twist);
354 foreach (Vertex v in newLayer.vertices) 167 foreach (Vertex v in newLayer.vertices)
355 { 168 {
356 if (v != null) 169 if (v != null)
@@ -566,7 +379,7 @@ namespace OpenSim.Region.Physics.Meshing
566 // next apply twist rotation to the profile layer 379 // next apply twist rotation to the profile layer
567 if (twistTotal != 0.0f || twistBot != 0.0f) 380 if (twistTotal != 0.0f || twistBot != 0.0f)
568 { 381 {
569 Quaternion profileRot = new Quaternion(new Vertex(0.0f, 0.0f, -1.0f), twist); 382 Quaternion profileRot = new Quaternion(new Vertex(0.0f, 0.0f, 1.0f), twist);
570 foreach (Vertex v in newLayer.vertices) 383 foreach (Vertex v in newLayer.vertices)
571 { 384 {
572 if (v != null) 385 if (v != null)
@@ -581,7 +394,7 @@ namespace OpenSim.Region.Physics.Meshing
581 394
582 // now orient the rotation of the profile layer relative to it's position on the path 395 // now orient the rotation of the profile layer relative to it's position on the path
583 // adding pushY to the angle used to generate the quat appears to approximate the viewer 396 // adding pushY to the angle used to generate the quat appears to approximate the viewer
584 Quaternion layerRot = new Quaternion(new Vertex(-1.0f, 0.0f, 0.0f), (float)angle + pushY * 0.9f); 397 Quaternion layerRot = new Quaternion(new Vertex(1.0f, 0.0f, 0.0f), (float)angle + pushY * 0.9f);
585 foreach (Vertex v in newLayer.vertices) 398 foreach (Vertex v in newLayer.vertices)
586 { 399 {
587 if (v != null) 400 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
70 return c; 70 return c;
71 } 71 }
72 72
73
74 public Matrix4 computeMatrix()
75 {
76 return new Matrix4(this);
77 }
78 public void normalize() 73 public void normalize()
79 { 74 {
80 //float mag = length(); 75 //float mag = length();
@@ -95,77 +90,8 @@ public class Quaternion
95 return (float)Math.Sqrt(w * w + x * x + y * y + z * z); 90 return (float)Math.Sqrt(w * w + x * x + y * y + z * z);
96 } 91 }
97} 92}
98public class Matrix4 93
99{ 94
100 public float m00 = 0;
101 public float m01 = 0;
102 public float m02 = 0;
103 public float m03 = 0;
104 public float m10 = 0;
105 public float m11 = 0;
106 public float m12 = 0;
107 public float m13 = 0;
108 public float m20 = 0;
109 public float m21 = 0;
110 public float m22 = 0;
111 public float m23 = 0;
112 public float m30 = 0;
113 public float m31 = 0;
114 public float m32 = 0;
115 public float m33 = 1;
116
117 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)
118 {
119 m00 = m001;
120 m01 = m011;
121 m02 = m021;
122 m03 = m031;
123 m10 = m101;
124 m11 = m111;
125 m12 = m121;
126 m13 = m131;
127 m20 = m201;
128 m21 = m211;
129 m22 = m221;
130 m23 = m231;
131 m30 = m301;
132 m31 = m311;
133 m32 = m321;
134 m33 = m331;
135 }
136 public Matrix4()
137 {
138 }
139 public Matrix4(Quaternion r)
140 {
141 m00 = 1 - (2 * (r.y * r.y)) - (2 * (r.z * r.z));
142 m01 = (r.x * r.y * 2) - (r.w * r.z * 2);
143 m02 = (r.x * r.z * 2) + (r.w * r.y * 2);
144 m03 = 0f;
145 m10 = (r.x * r.y * 2) + (r.w * r.z * 2);
146 m11 = 1 - (2 * (r.x * r.x)) - (2 * (r.z * r.z));
147 m12 = (r.y * r.z * 2) - (r.w * r.x * 2);
148 m13 = 0f;
149 m20 = (r.x * r.z * 2) - (r.w * r.y * 2);
150 m21 = (r.y * r.z * 2) - (r.w * r.x * 2);
151 m22 = 1 - (2 * (r.x * r.x)) - (2 * (r.y * r.y));
152 m23 = 0f;
153 m30 = 0f;
154 m31 = 0f;
155 m32 = 0f;
156 m33 = 1f;
157 }
158 public Vertex transform(Vertex o)
159 {
160 Vertex r = new Vertex(0,0,0);
161 // w value implicitly 1 therefore the last + m3x actually represents (m3x * o.W) = m3x
162 // in calculating the dot product.
163 r.X = (m00 * o.X) + (m10 * o.Y) + (m20 * o.Z) + m30;
164 r.Y = (m01 * o.X) + (m11 * o.Y) + (m21 * o.Z) + m31;
165 r.Z = (m02 * o.X) + (m12 * o.Y) + (m22 * o.Z) + m32;
166 return r;
167 }
168}
169 95
170public class Vertex : PhysicsVector, IComparable<Vertex> 96public class Vertex : PhysicsVector, IComparable<Vertex>
171{ 97{
@@ -199,8 +125,40 @@ public class Vertex : PhysicsVector, IComparable<Vertex>
199#pragma warning disable 0108 125#pragma warning disable 0108
200 public static Vertex operator *(Vertex v, Quaternion q) 126 public static Vertex operator *(Vertex v, Quaternion q)
201 { 127 {
202 Matrix4 tm = q.computeMatrix(); 128 // From http://www.euclideanspace.com/maths/algebra/realNormedAlgebra/quaternions/transforms/
203 return tm.transform(v); 129
130 Vertex v2 = new Vertex(0f, 0f, 0f);
131
132 v2.X = q.w * q.w * v.X +
133 2f * q.y * q.w * v.Z -
134 2f * q.z * q.w * v.Y +
135 q.x * q.x * v.X +
136 2f * q.y * q.x * v.Y +
137 2f * q.z * q.x * v.Z -
138 q.z * q.z * v.X -
139 q.y * q.y * v.X;
140
141 v2.Y =
142 2f * q.x * q.y * v.X +
143 q.y * q.y * v.Y +
144 2f * q.z * q.y * v.Z +
145 2f * q.w * q.z * v.X -
146 q.z * q.z * v.Y +
147 q.w * q.w * v.Y -
148 2f * q.x * q.w * v.Z -
149 q.x * q.x * v.Y;
150
151 v2.Z =
152 2f * q.x * q.z * v.X +
153 2f * q.y * q.z * v.Y +
154 q.z * q.z * v.Z -
155 2f * q.w * q.y * v.X -
156 q.y * q.y * v.Z +
157 2f * q.w * q.x * v.Y -
158 q.x * q.x * v.Z +
159 q.w * q.w * v.Z;
160
161 return v2;
204 } 162 }
205 163
206 public static Vertex operator +(Vertex v1, Vertex v2) 164 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
1556 // m_log.DebugFormat("Starting cutting of the hollow shape from the prim {1}", 0, primName); 1556 // m_log.DebugFormat("Starting cutting of the hollow shape from the prim {1}", 0, primName);
1557 SimpleHull cuttedHull = SimpleHull.SubtractHull(outerHull, cutHull); 1557 SimpleHull cuttedHull = SimpleHull.SubtractHull(outerHull, cutHull);
1558 1558
1559 if ((primShape.ProfileCurve & 0x07) == (byte)ProfileShape.Circle)
1560 {
1561 Quaternion zFlip = new Quaternion(new Vertex(0.0f, 0.0f, 1.0f), (float)Math.PI);
1562 Vertex vTmp = new Vertex(0.0f, 0.0f, 0.0f);
1563 foreach (Vertex v in cuttedHull.getVertices())
1564 if (v != null)
1565 {
1566 vTmp = v * zFlip;
1567 v.X = vTmp.X;
1568 v.Y = vTmp.Y;
1569 v.Z = vTmp.Z;
1570 }
1571 }
1572
1573 outerHull = cuttedHull; 1559 outerHull = cuttedHull;
1574 } 1560 }
1575 1561