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/Meshing/Mesh.cs | |
parent | A bit more estate fudging (diff) | |
download | opensim-SC_OLD-7fbe942792b57c6867f3a7b98475c6c1a5cc56c8.zip opensim-SC_OLD-7fbe942792b57c6867f3a7b98475c6c1a5cc56c8.tar.gz opensim-SC_OLD-7fbe942792b57c6867f3a7b98475c6c1a5cc56c8.tar.bz2 opensim-SC_OLD-7fbe942792b57c6867f3a7b98475c6c1a5cc56c8.tar.xz |
refactoring PrimMesher to add viewer compatable features and some code cleanup
Diffstat (limited to 'OpenSim/Region/Physics/Meshing/Mesh.cs')
-rw-r--r-- | OpenSim/Region/Physics/Meshing/Mesh.cs | 65 |
1 files changed, 64 insertions, 1 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>(); |