diff options
author | Dahlia Trimble | 2008-10-10 08:22:13 +0000 |
---|---|---|
committer | Dahlia Trimble | 2008-10-10 08:22:13 +0000 |
commit | 7fbe942792b57c6867f3a7b98475c6c1a5cc56c8 (patch) | |
tree | 75b65b2dcf636fad5ffd86920768d7bb10af4273 /OpenSim/Region/Physics | |
parent | A bit more estate fudging (diff) | |
download | opensim-SC-7fbe942792b57c6867f3a7b98475c6c1a5cc56c8.zip opensim-SC-7fbe942792b57c6867f3a7b98475c6c1a5cc56c8.tar.gz opensim-SC-7fbe942792b57c6867f3a7b98475c6c1a5cc56c8.tar.bz2 opensim-SC-7fbe942792b57c6867f3a7b98475c6c1a5cc56c8.tar.xz |
refactoring PrimMesher to add viewer compatable features and some code cleanup
Diffstat (limited to 'OpenSim/Region/Physics')
-rw-r--r-- | OpenSim/Region/Physics/Meshing/Mesh.cs | 65 | ||||
-rw-r--r-- | OpenSim/Region/Physics/Meshing/Meshmerizer.cs | 1 | ||||
-rw-r--r-- | OpenSim/Region/Physics/Meshing/PrimMesher.cs | 308 |
3 files changed, 283 insertions, 91 deletions
diff --git a/OpenSim/Region/Physics/Meshing/Mesh.cs b/OpenSim/Region/Physics/Meshing/Mesh.cs index 06131a7..583b485 100644 --- a/OpenSim/Region/Physics/Meshing/Mesh.cs +++ b/OpenSim/Region/Physics/Meshing/Mesh.cs | |||
@@ -30,6 +30,7 @@ using System.Collections.Generic; | |||
30 | using System.IO; | 30 | using System.IO; |
31 | using System.Runtime.InteropServices; | 31 | using System.Runtime.InteropServices; |
32 | using OpenSim.Region.Physics.Manager; | 32 | using OpenSim.Region.Physics.Manager; |
33 | using PrimMesher; | ||
33 | 34 | ||
34 | namespace OpenSim.Region.Physics.Meshing | 35 | namespace OpenSim.Region.Physics.Meshing |
35 | { | 36 | { |
@@ -40,7 +41,7 @@ namespace OpenSim.Region.Physics.Meshing | |||
40 | GCHandle pinnedVirtexes; | 41 | GCHandle pinnedVirtexes; |
41 | GCHandle pinnedIndex; | 42 | GCHandle pinnedIndex; |
42 | public PrimMesh primMesh = null; | 43 | public PrimMesh primMesh = null; |
43 | //public float[] normals; | 44 | public float[] normals; |
44 | 45 | ||
45 | public Mesh() | 46 | public Mesh() |
46 | { | 47 | { |
@@ -142,6 +143,68 @@ namespace OpenSim.Region.Physics.Meshing | |||
142 | } | 143 | } |
143 | } | 144 | } |
144 | 145 | ||
146 | public void CalcNormals() | ||
147 | { | ||
148 | int iTriangles = triangles.Count; | ||
149 | |||
150 | this.normals = new float[iTriangles * 3]; | ||
151 | |||
152 | int i = 0; | ||
153 | foreach (Triangle t in triangles) | ||
154 | { | ||
155 | float ux, uy, uz; | ||
156 | float vx, vy, vz; | ||
157 | float wx, wy, wz; | ||
158 | |||
159 | ux = t.v1.X; | ||
160 | uy = t.v1.Y; | ||
161 | uz = t.v1.Z; | ||
162 | |||
163 | vx = t.v2.X; | ||
164 | vy = t.v2.Y; | ||
165 | vz = t.v2.Z; | ||
166 | |||
167 | wx = t.v3.X; | ||
168 | wy = t.v3.Y; | ||
169 | wz = t.v3.Z; | ||
170 | |||
171 | |||
172 | // Vectors for edges | ||
173 | float e1x, e1y, e1z; | ||
174 | float e2x, e2y, e2z; | ||
175 | |||
176 | e1x = ux - vx; | ||
177 | e1y = uy - vy; | ||
178 | e1z = uz - vz; | ||
179 | |||
180 | e2x = ux - wx; | ||
181 | e2y = uy - wy; | ||
182 | e2z = uz - wz; | ||
183 | |||
184 | |||
185 | // Cross product for normal | ||
186 | float nx, ny, nz; | ||
187 | nx = e1y * e2z - e1z * e2y; | ||
188 | ny = e1z * e2x - e1x * e2z; | ||
189 | nz = e1x * e2y - e1y * e2x; | ||
190 | |||
191 | // Length | ||
192 | float l = (float)Math.Sqrt(nx * nx + ny * ny + nz * nz); | ||
193 | float lReciprocal = 1.0f / l; | ||
194 | |||
195 | // Normalized "normal" | ||
196 | //nx /= l; | ||
197 | //ny /= l; | ||
198 | //nz /= l; | ||
199 | |||
200 | normals[i] = nx * lReciprocal; | ||
201 | normals[i + 1] = ny * lReciprocal; | ||
202 | normals[i + 2] = nz * lReciprocal; | ||
203 | |||
204 | i += 3; | ||
205 | } | ||
206 | } | ||
207 | |||
145 | public List<PhysicsVector> getVertexList() | 208 | public List<PhysicsVector> getVertexList() |
146 | { | 209 | { |
147 | List<PhysicsVector> result = new List<PhysicsVector>(); | 210 | List<PhysicsVector> result = new List<PhysicsVector>(); |
diff --git a/OpenSim/Region/Physics/Meshing/Meshmerizer.cs b/OpenSim/Region/Physics/Meshing/Meshmerizer.cs index 4e43a1b..b11efd8 100644 --- a/OpenSim/Region/Physics/Meshing/Meshmerizer.cs +++ b/OpenSim/Region/Physics/Meshing/Meshmerizer.cs | |||
@@ -31,6 +31,7 @@ using System.Collections.Generic; | |||
31 | using OpenSim.Framework; | 31 | using OpenSim.Framework; |
32 | using OpenSim.Region.Physics.Manager; | 32 | using OpenSim.Region.Physics.Manager; |
33 | using OpenMetaverse; | 33 | using OpenMetaverse; |
34 | using PrimMesher; | ||
34 | 35 | ||
35 | namespace OpenSim.Region.Physics.Meshing | 36 | namespace OpenSim.Region.Physics.Meshing |
36 | { | 37 | { |
diff --git a/OpenSim/Region/Physics/Meshing/PrimMesher.cs b/OpenSim/Region/Physics/Meshing/PrimMesher.cs index 5e08fdf..caf5966 100644 --- a/OpenSim/Region/Physics/Meshing/PrimMesher.cs +++ b/OpenSim/Region/Physics/Meshing/PrimMesher.cs | |||
@@ -27,12 +27,77 @@ | |||
27 | 27 | ||
28 | using System; | 28 | using System; |
29 | using System.Collections.Generic; | 29 | using System.Collections.Generic; |
30 | using System.Text; | ||
30 | using System.IO; | 31 | using System.IO; |
31 | using OpenSim.Region.Physics.Manager; | ||
32 | using OpenMetaverse; | ||
33 | 32 | ||
34 | namespace OpenSim.Region.Physics.Meshing | 33 | namespace PrimMesher |
35 | { | 34 | { |
35 | public struct Quat | ||
36 | { | ||
37 | /// <summary>X value</summary> | ||
38 | public float X; | ||
39 | /// <summary>Y value</summary> | ||
40 | public float Y; | ||
41 | /// <summary>Z value</summary> | ||
42 | public float Z; | ||
43 | /// <summary>W value</summary> | ||
44 | public float W; | ||
45 | |||
46 | public Quat(float x, float y, float z, float w) | ||
47 | { | ||
48 | X = x; | ||
49 | Y = y; | ||
50 | Z = z; | ||
51 | W = w; | ||
52 | } | ||
53 | |||
54 | public Quat(Coord axis, float angle) | ||
55 | { | ||
56 | axis = axis.Normalize(); | ||
57 | |||
58 | angle *= 0.5f; | ||
59 | float c = (float)Math.Cos(angle); | ||
60 | float s = (float)Math.Sin(angle); | ||
61 | |||
62 | X = axis.X * s; | ||
63 | Y = axis.Y * s; | ||
64 | Z = axis.Z * s; | ||
65 | W = c; | ||
66 | |||
67 | Normalize(); | ||
68 | } | ||
69 | |||
70 | public float Length() | ||
71 | { | ||
72 | return (float)Math.Sqrt(X * X + Y * Y + Z * Z + W * W); | ||
73 | } | ||
74 | |||
75 | public Quat Normalize() | ||
76 | { | ||
77 | const float MAG_THRESHOLD = 0.0000001f; | ||
78 | float mag = Length(); | ||
79 | |||
80 | // Catch very small rounding errors when normalizing | ||
81 | if (mag > MAG_THRESHOLD) | ||
82 | { | ||
83 | float oomag = 1f / mag; | ||
84 | X *= oomag; | ||
85 | Y *= oomag; | ||
86 | Z *= oomag; | ||
87 | W *= oomag; | ||
88 | } | ||
89 | else | ||
90 | { | ||
91 | X = 0f; | ||
92 | Y = 0f; | ||
93 | Z = 0f; | ||
94 | W = 1f; | ||
95 | } | ||
96 | |||
97 | return this; | ||
98 | } | ||
99 | } | ||
100 | |||
36 | public struct Coord | 101 | public struct Coord |
37 | { | 102 | { |
38 | public float X; | 103 | public float X; |
@@ -46,23 +111,119 @@ namespace OpenSim.Region.Physics.Meshing | |||
46 | this.Z = z; | 111 | this.Z = z; |
47 | } | 112 | } |
48 | 113 | ||
114 | public float Length() | ||
115 | { | ||
116 | return (float)Math.Sqrt(this.X * this.X + this.Y * this.Y + this.Z * this.Z); | ||
117 | } | ||
118 | |||
119 | public Coord Normalize() | ||
120 | { | ||
121 | const float MAG_THRESHOLD = 0.0000001f; | ||
122 | float mag = Length(); | ||
123 | |||
124 | // Catch very small rounding errors when normalizing | ||
125 | if (mag > MAG_THRESHOLD) | ||
126 | { | ||
127 | float oomag = 1.0f / mag; | ||
128 | this.X *= oomag; | ||
129 | this.Y *= oomag; | ||
130 | this.Z *= oomag; | ||
131 | } | ||
132 | else | ||
133 | { | ||
134 | this.X = 0.0f; | ||
135 | this.Y = 0.0f; | ||
136 | this.Z = 0.0f; | ||
137 | } | ||
138 | |||
139 | return this; | ||
140 | } | ||
141 | |||
49 | public override string ToString() | 142 | public override string ToString() |
50 | { | 143 | { |
51 | return this.X.ToString() + " " + this.Y.ToString() + " " + this.Z.ToString(); | 144 | return this.X.ToString() + " " + this.Y.ToString() + " " + this.Z.ToString(); |
52 | } | 145 | } |
146 | |||
147 | public static Coord Cross(Coord c1, Coord c2) | ||
148 | { | ||
149 | return new Coord( | ||
150 | c1.Y * c2.Z - c2.Y * c1.Z, | ||
151 | c1.Z * c2.X - c2.Z * c1.X, | ||
152 | c1.X * c2.Y - c2.X * c1.Y | ||
153 | ); | ||
154 | } | ||
155 | |||
156 | public static Coord operator *(Coord v, Quat q) | ||
157 | { | ||
158 | // From http://www.euclideanspace.com/maths/algebra/realNormedAlgebra/quaternions/transforms/ | ||
159 | |||
160 | Coord c2 = new Coord(0.0f, 0.0f, 0.0f); | ||
161 | |||
162 | c2.X = q.W * q.W * v.X + | ||
163 | 2f * q.Y * q.W * v.Z - | ||
164 | 2f * q.Z * q.W * v.Y + | ||
165 | q.X * q.X * v.X + | ||
166 | 2f * q.Y * q.X * v.Y + | ||
167 | 2f * q.Z * q.X * v.Z - | ||
168 | q.Z * q.Z * v.X - | ||
169 | q.Y * q.Y * v.X; | ||
170 | |||
171 | c2.Y = | ||
172 | 2f * q.X * q.Y * v.X + | ||
173 | q.Y * q.Y * v.Y + | ||
174 | 2f * q.Z * q.Y * v.Z + | ||
175 | 2f * q.W * q.Z * v.X - | ||
176 | q.Z * q.Z * v.Y + | ||
177 | q.W * q.W * v.Y - | ||
178 | 2f * q.X * q.W * v.Z - | ||
179 | q.X * q.X * v.Y; | ||
180 | |||
181 | c2.Z = | ||
182 | 2f * q.X * q.Z * v.X + | ||
183 | 2f * q.Y * q.Z * v.Y + | ||
184 | q.Z * q.Z * v.Z - | ||
185 | 2f * q.W * q.Y * v.X - | ||
186 | q.Y * q.Y * v.Z + | ||
187 | 2f * q.W * q.X * v.Y - | ||
188 | q.X * q.X * v.Z + | ||
189 | q.W * q.W * v.Z; | ||
190 | |||
191 | return c2; | ||
192 | } | ||
53 | } | 193 | } |
54 | 194 | ||
55 | public struct Face | 195 | public struct Face |
56 | { | 196 | { |
197 | // vertices | ||
57 | public int v1; | 198 | public int v1; |
58 | public int v2; | 199 | public int v2; |
59 | public int v3; | 200 | public int v3; |
60 | 201 | ||
202 | //normals | ||
203 | public int n1; | ||
204 | public int n2; | ||
205 | public int n3; | ||
206 | |||
61 | public Face(int v1, int v2, int v3) | 207 | public Face(int v1, int v2, int v3) |
62 | { | 208 | { |
63 | this.v1 = v1; | 209 | this.v1 = v1; |
64 | this.v2 = v2; | 210 | this.v2 = v2; |
65 | this.v3 = v3; | 211 | this.v3 = v3; |
212 | |||
213 | this.n1 = 0; | ||
214 | this.n2 = 0; | ||
215 | this.n3 = 0; | ||
216 | } | ||
217 | |||
218 | public Face(int v1, int v2, int v3, int n1, int n2, int n3) | ||
219 | { | ||
220 | this.v1 = v1; | ||
221 | this.v2 = v2; | ||
222 | this.v3 = v3; | ||
223 | |||
224 | this.n1 = n1; | ||
225 | this.n2 = n2; | ||
226 | this.n3 = n3; | ||
66 | } | 227 | } |
67 | } | 228 | } |
68 | 229 | ||
@@ -80,81 +241,6 @@ namespace OpenSim.Region.Physics.Meshing | |||
80 | } | 241 | } |
81 | } | 242 | } |
82 | 243 | ||
83 | //internal float angles3[][] = [ | ||
84 | //[0.0f, 1.0f, 0.0f], | ||
85 | //[0.33333333333333331f, -0.49999999999999978f, 0.86602540378443871f], | ||
86 | //[0.66666666666666663f, -0.50000000000000044f, -0.86602540378443837f], | ||
87 | //[1.0f, 1.0f, -2.4492127076447545e-016f]]; | ||
88 | /* | ||
89 | angles3 = [ | ||
90 | [0.0, 1.0, 0.0], | ||
91 | [0.33333333333333331, -0.49999999999999978, 0.86602540378443871], | ||
92 | [0.66666666666666663, -0.50000000000000044, -0.86602540378443837], | ||
93 | [1.0, 1.0, -2.4492127076447545e-016]] | ||
94 | |||
95 | angles4 = [ | ||
96 | [0.0, 1.0, 0.0], | ||
97 | [0.25, 0.0, 1.0], | ||
98 | [0.5, -1.0, 0.0], | ||
99 | [0.75, 0.0, -1.0], | ||
100 | [1.0, 1.0, 0.0]] | ||
101 | |||
102 | angles24 = [ | ||
103 | [0.0, 0.5, 0.0], | ||
104 | [0.041666666666666664, 0.48296291314453416, 0.12940952255126037], | ||
105 | [0.083333333333333329, 0.43301270189221935, 0.25], | ||
106 | [0.125, 0.35355339059327379, 0.35355339059327373], | ||
107 | [0.16666666666666666, 0.25, 0.4330127018922193], | ||
108 | [0.20833333333333331, 0.12940952255126048, 0.4829629131445341], | ||
109 | [0.25, 0.0, 0.5], | ||
110 | [0.29166666666666663, -0.12940952255126031, 0.48296291314453416], | ||
111 | [0.33333333333333331, -0.25, 0.43301270189221935], | ||
112 | [0.375, -0.35355339059327373, 0.35355339059327379], | ||
113 | [0.41666666666666663, -0.43301270189221924, 0.25], | ||
114 | [0.45833333333333331, -0.4829629131445341, 0.12940952255126051], | ||
115 | [0.5, -0.5, 0.0], | ||
116 | [0.54166666666666663, -0.48296291314453421, -0.12940952255126018], | ||
117 | [0.58333333333333326, -0.43301270189221941, -0.25], | ||
118 | [0.62499999999999989, -0.35355339059327395, -0.35355339059327356], | ||
119 | [0.66666666666666663, -0.25, -0.43301270189221919], | ||
120 | [0.70833333333333326, -0.12940952255126076, -0.48296291314453405], | ||
121 | [0.75, 0.0, -0.5], | ||
122 | [0.79166666666666663, 0.12940952255126015, -0.48296291314453421], | ||
123 | [0.83333333333333326, 0.25, -0.43301270189221952], | ||
124 | [0.875, 0.35355339059327368, -0.35355339059327384], | ||
125 | [0.91666666666666663, 0.43301270189221919, -0.25], | ||
126 | [0.95833333333333326, 0.48296291314453405, -0.12940952255126079], | ||
127 | [1.0, 0.5, 0.0]] | ||
128 | |||
129 | angles24 = [ | ||
130 | [0.0, 1.0, 0.0], | ||
131 | [0.041666666666666664, 0.96592582628906831, 0.25881904510252074], | ||
132 | [0.083333333333333329, 0.86602540378443871, 0.5], | ||
133 | [0.125, 0.70710678118654757, 0.70710678118654746], | ||
134 | [0.16666666666666667, 0.5, 0.8660254037844386], | ||
135 | [0.20833333333333331, 0.25881904510252096, 0.9659258262890682], | ||
136 | [0.25, 6.1230317691118863e-017, 1.0], | ||
137 | [0.29166666666666663, -0.25881904510252063, 0.96592582628906831], | ||
138 | [0.33333333333333333, -0.5, 0.86602540378443871], | ||
139 | [0.375, -0.70710678118654746, 0.70710678118654757], | ||
140 | [0.41666666666666663, -0.86602540378443849, 0.5], | ||
141 | [0.45833333333333331, -0.9659258262890682, 0.25881904510252102], | ||
142 | [0.5, -1.0, 1.2246063538223773e-016], | ||
143 | [0.54166666666666663, -0.96592582628906842, -0.25881904510252035], | ||
144 | [0.58333333333333326, -0.86602540378443882, -0.5], | ||
145 | [0.62499999999999989, -0.70710678118654791, -0.70710678118654713], | ||
146 | [0.66666666666666667, -0.5, -0.86602540378443837], | ||
147 | [0.70833333333333326, -0.25881904510252152, -0.96592582628906809], | ||
148 | [0.75, -1.8369095307335659e-016, -1.0], | ||
149 | [0.79166666666666663, 0.2588190451025203, -0.96592582628906842], | ||
150 | [0.83333333333333326, 0.5, -0.86602540378443904], | ||
151 | [0.875, 0.70710678118654735, -0.70710678118654768], | ||
152 | [0.91666666666666663, 0.86602540378443837, -0.5], | ||
153 | [0.95833333333333326, 0.96592582628906809, -0.25881904510252157], | ||
154 | [1.0, 1.0, -2.4492127076447545e-016]] | ||
155 | |||
156 | */ | ||
157 | |||
158 | internal class AngleList | 244 | internal class AngleList |
159 | { | 245 | { |
160 | private float iX, iY; // intersection point | 246 | private float iX, iY; // intersection point |
@@ -226,7 +312,7 @@ angles24 = [ | |||
226 | 312 | ||
227 | internal List<Angle> angles; | 313 | internal List<Angle> angles; |
228 | 314 | ||
229 | internal void makeAngles( int sides, float startAngle, float stopAngle ) | 315 | internal void makeAngles(int sides, float startAngle, float stopAngle) |
230 | { | 316 | { |
231 | angles = new List<Angle>(); | 317 | angles = new List<Angle>(); |
232 | double twoPi = System.Math.PI * 2.0; | 318 | double twoPi = System.Math.PI * 2.0; |
@@ -556,7 +642,7 @@ angles24 = [ | |||
556 | } | 642 | } |
557 | } | 643 | } |
558 | 644 | ||
559 | public void AddRot(Quaternion q) | 645 | public void AddRot(Quat q) |
560 | { | 646 | { |
561 | int i; | 647 | int i; |
562 | int numVerts = this.coords.Count; | 648 | int numVerts = this.coords.Count; |
@@ -565,7 +651,7 @@ angles24 = [ | |||
565 | for (i = 0; i < numVerts; i++) | 651 | for (i = 0; i < numVerts; i++) |
566 | { | 652 | { |
567 | vert = this.coords[i]; | 653 | vert = this.coords[i]; |
568 | Vertex v = new Vertex(vert.X, vert.Y, vert.Z) * q; | 654 | Coord v = new Coord(vert.X, vert.Y, vert.Z) * q; |
569 | 655 | ||
570 | vert.X = v.X; | 656 | vert.X = v.X; |
571 | vert.Y = v.Y; | 657 | vert.Y = v.Y; |
@@ -646,6 +732,7 @@ angles24 = [ | |||
646 | private const float twoPi = 2.0f * (float)Math.PI; | 732 | private const float twoPi = 2.0f * (float)Math.PI; |
647 | 733 | ||
648 | public List<Coord> coords; | 734 | public List<Coord> coords; |
735 | public List<Coord> normals; | ||
649 | public List<Face> faces; | 736 | public List<Face> faces; |
650 | 737 | ||
651 | public int sides = 4; | 738 | public int sides = 4; |
@@ -712,7 +799,7 @@ angles24 = [ | |||
712 | 799 | ||
713 | if (sides < 3) | 800 | if (sides < 3) |
714 | this.sides = 3; | 801 | this.sides = 3; |
715 | if ( hollowSides < 3) | 802 | if (hollowSides < 3) |
716 | this.hollowSides = 3; | 803 | this.hollowSides = 3; |
717 | if (profileStart < 0.0f) | 804 | if (profileStart < 0.0f) |
718 | this.profileStart = 0.0f; | 805 | this.profileStart = 0.0f; |
@@ -795,7 +882,7 @@ angles24 = [ | |||
795 | Profile profile = new Profile(this.sides, this.profileStart, this.profileEnd, hollow, this.hollowSides, true); | 882 | Profile profile = new Profile(this.sides, this.profileStart, this.profileEnd, hollow, this.hollowSides, true); |
796 | 883 | ||
797 | if (initialProfileRot != 0.0f) | 884 | if (initialProfileRot != 0.0f) |
798 | profile.AddRot(Quaternion.CreateFromAxisAngle(new Vector3(0.0f, 0.0f, 1.0f), initialProfileRot)); | 885 | profile.AddRot(new Quat(new Coord(0.0f, 0.0f, 1.0f), initialProfileRot)); |
799 | 886 | ||
800 | bool done = false; | 887 | bool done = false; |
801 | while (!done) | 888 | while (!done) |
@@ -819,7 +906,7 @@ angles24 = [ | |||
819 | 906 | ||
820 | float twist = twistBegin + twistTotal * percentOfPath; | 907 | float twist = twistBegin + twistTotal * percentOfPath; |
821 | if (twist != 0.0f) | 908 | if (twist != 0.0f) |
822 | newLayer.AddRot(Quaternion.CreateFromAxisAngle(new Vector3(0.0f, 0.0f, 1.0f), twist)); | 909 | newLayer.AddRot(new Quat(new Coord(0.0f, 0.0f, 1.0f), twist)); |
823 | 910 | ||
824 | newLayer.AddPos(xOffset, yOffset, zOffset); | 911 | newLayer.AddPos(xOffset, yOffset, zOffset); |
825 | 912 | ||
@@ -972,7 +1059,7 @@ angles24 = [ | |||
972 | Profile profile = new Profile(this.sides, this.profileStart, this.profileEnd, hollow, this.hollowSides, needEndFaces); | 1059 | Profile profile = new Profile(this.sides, this.profileStart, this.profileEnd, hollow, this.hollowSides, needEndFaces); |
973 | 1060 | ||
974 | if (initialProfileRot != 0.0f) | 1061 | if (initialProfileRot != 0.0f) |
975 | profile.AddRot(Quaternion.CreateFromAxisAngle(new Vector3(0.0f, 0.0f, 1.0f), initialProfileRot)); | 1062 | profile.AddRot(new Quat(new Coord(0.0f, 0.0f, 1.0f), initialProfileRot)); |
976 | 1063 | ||
977 | bool done = false; | 1064 | bool done = false; |
978 | while (!done) // loop through the length of the path and add the layers | 1065 | while (!done) // loop through the length of the path and add the layers |
@@ -980,7 +1067,7 @@ angles24 = [ | |||
980 | bool isEndLayer = false; | 1067 | bool isEndLayer = false; |
981 | if (angle == startAngle || angle >= endAngle) | 1068 | if (angle == startAngle || angle >= endAngle) |
982 | isEndLayer = true; | 1069 | isEndLayer = true; |
983 | 1070 | ||
984 | Profile newLayer = profile.Clone(isEndLayer && needEndFaces); | 1071 | Profile newLayer = profile.Clone(isEndLayer && needEndFaces); |
985 | 1072 | ||
986 | float xProfileScale = (1.0f - Math.Abs(this.skew)) * this.holeSizeX; | 1073 | float xProfileScale = (1.0f - Math.Abs(this.skew)) * this.holeSizeX; |
@@ -1019,12 +1106,12 @@ angles24 = [ | |||
1019 | 1106 | ||
1020 | // next apply twist rotation to the profile layer | 1107 | // next apply twist rotation to the profile layer |
1021 | if (twistTotal != 0.0f || twistBegin != 0.0f) | 1108 | if (twistTotal != 0.0f || twistBegin != 0.0f) |
1022 | newLayer.AddRot(Quaternion.CreateFromAxisAngle(new Vector3(0.0f, 0.0f, 1.0f), twist)); | 1109 | newLayer.AddRot(new Quat(new Coord(0.0f, 0.0f, 1.0f), twist)); |
1023 | 1110 | ||
1024 | // now orient the rotation of the profile layer relative to it's position on the path | 1111 | // now orient the rotation of the profile layer relative to it's position on the path |
1025 | // adding taperY to the angle used to generate the quat appears to approximate the viewer | 1112 | // adding taperY to the angle used to generate the quat appears to approximate the viewer |
1026 | //newLayer.AddRot(new Quaternion(new Vertex(1.0f, 0.0f, 0.0f), angle + this.topShearY * 0.9f)); | 1113 | //newLayer.AddRot(new Quaternion(new Vertex(1.0f, 0.0f, 0.0f), angle + this.topShearY * 0.9f)); |
1027 | newLayer.AddRot(Quaternion.CreateFromAxisAngle(new Vector3(1.0f, 0.0f, 0.0f), angle + this.topShearY)); | 1114 | newLayer.AddRot(new Quat(new Coord(1.0f, 0.0f, 0.0f), angle + this.topShearY)); |
1028 | newLayer.AddPos(xOffset, yOffset, zOffset); | 1115 | newLayer.AddPos(xOffset, yOffset, zOffset); |
1029 | 1116 | ||
1030 | if (angle == startAngle) | 1117 | if (angle == startAngle) |
@@ -1084,6 +1171,47 @@ angles24 = [ | |||
1084 | } | 1171 | } |
1085 | } | 1172 | } |
1086 | 1173 | ||
1174 | public Coord SurfaceNormal(int faceIndex) | ||
1175 | { | ||
1176 | int numFaces = faces.Count; | ||
1177 | if (faceIndex < 0 || faceIndex >= faces.Count) | ||
1178 | return new Coord(0.0f, 0.0f, 0.0f); | ||
1179 | |||
1180 | Face face = faces[faceIndex]; | ||
1181 | Coord c1 = coords[face.v1]; | ||
1182 | Coord c2 = coords[face.v2]; | ||
1183 | Coord c3 = coords[face.v3]; | ||
1184 | |||
1185 | Coord edge1 = new Coord(c2.X - c1.X, c2.Y - c1.Y, c2.Z - c1.Z); | ||
1186 | Coord edge2 = new Coord(c3.X - c1.X, c3.Y - c1.Y, c3.Z - c1.Z); | ||
1187 | |||
1188 | Coord normal = Coord.Cross(edge1, edge2); | ||
1189 | |||
1190 | normal.Normalize(); | ||
1191 | |||
1192 | return normal; | ||
1193 | } | ||
1194 | |||
1195 | public void CalcNormals() | ||
1196 | { | ||
1197 | int numFaces = faces.Count; | ||
1198 | this.normals = new List<Coord>(); | ||
1199 | |||
1200 | for (int i = 0; i < numFaces; i++) | ||
1201 | { | ||
1202 | Face face = faces[i]; | ||
1203 | |||
1204 | this.normals.Add(SurfaceNormal(i).Normalize()); | ||
1205 | |||
1206 | int normIndex = normals.Count - 1; | ||
1207 | face.n1 = normIndex; | ||
1208 | face.n2 = normIndex; | ||
1209 | face.n3 = normIndex; | ||
1210 | |||
1211 | this.faces[i] = face; | ||
1212 | } | ||
1213 | } | ||
1214 | |||
1087 | public void AddPos(float x, float y, float z) | 1215 | public void AddPos(float x, float y, float z) |
1088 | { | 1216 | { |
1089 | int i; | 1217 | int i; |
@@ -1100,7 +1228,7 @@ angles24 = [ | |||
1100 | } | 1228 | } |
1101 | } | 1229 | } |
1102 | 1230 | ||
1103 | public void AddRot(Quaternion q) | 1231 | public void AddRot(Quat q) |
1104 | { | 1232 | { |
1105 | int i; | 1233 | int i; |
1106 | int numVerts = this.coords.Count; | 1234 | int numVerts = this.coords.Count; |
@@ -1109,7 +1237,7 @@ angles24 = [ | |||
1109 | for (i = 0; i < numVerts; i++) | 1237 | for (i = 0; i < numVerts; i++) |
1110 | { | 1238 | { |
1111 | vert = this.coords[i]; | 1239 | vert = this.coords[i]; |
1112 | Vertex v = new Vertex(vert.X, vert.Y, vert.Z) * q; | 1240 | Coord v = new Coord(vert.X, vert.Y, vert.Z) * q; |
1113 | 1241 | ||
1114 | vert.X = v.X; | 1242 | vert.X = v.X; |
1115 | vert.Y = v.Y; | 1243 | vert.Y = v.Y; |