diff options
Diffstat (limited to 'OpenSim/Region/Physics/Meshing')
-rw-r--r-- | OpenSim/Region/Physics/Meshing/HelperTypes.cs | 62 | ||||
-rw-r--r-- | OpenSim/Region/Physics/Meshing/Mesh.cs | 13 | ||||
-rw-r--r-- | OpenSim/Region/Physics/Meshing/Meshmerizer.cs | 27 |
3 files changed, 64 insertions, 38 deletions
diff --git a/OpenSim/Region/Physics/Meshing/HelperTypes.cs b/OpenSim/Region/Physics/Meshing/HelperTypes.cs index 232245f..8cd8dcf 100644 --- a/OpenSim/Region/Physics/Meshing/HelperTypes.cs +++ b/OpenSim/Region/Physics/Meshing/HelperTypes.cs | |||
@@ -33,30 +33,52 @@ using OpenMetaverse; | |||
33 | using OpenSim.Region.Physics.Manager; | 33 | using OpenSim.Region.Physics.Manager; |
34 | using OpenSim.Region.Physics.Meshing; | 34 | using OpenSim.Region.Physics.Meshing; |
35 | 35 | ||
36 | public class Vertex : PhysicsVector, IComparable<Vertex> | 36 | public class Vertex : IComparable<Vertex> |
37 | { | 37 | { |
38 | Vector3 vector; | ||
39 | |||
40 | public float X | ||
41 | { | ||
42 | get { return vector.X; } | ||
43 | set { vector.X = value; } | ||
44 | } | ||
45 | |||
46 | public float Y | ||
47 | { | ||
48 | get { return vector.Y; } | ||
49 | set { vector.Y = value; } | ||
50 | } | ||
51 | |||
52 | public float Z | ||
53 | { | ||
54 | get { return vector.Z; } | ||
55 | set { vector.Z = value; } | ||
56 | } | ||
57 | |||
38 | public Vertex(float x, float y, float z) | 58 | public Vertex(float x, float y, float z) |
39 | : base(x, y, z) | ||
40 | { | 59 | { |
60 | vector.X = x; | ||
61 | vector.Y = y; | ||
62 | vector.Z = z; | ||
41 | } | 63 | } |
42 | 64 | ||
43 | public Vertex normalize() | 65 | public Vertex normalize() |
44 | { | 66 | { |
45 | float tlength = length(); | 67 | float tlength = vector.Length(); |
46 | if (tlength != 0) | 68 | if (tlength != 0f) |
47 | { | 69 | { |
48 | float mul = 1.0f / tlength; | 70 | float mul = 1.0f / tlength; |
49 | return new Vertex(X * mul, Y * mul, Z * mul); | 71 | return new Vertex(vector.X * mul, vector.Y * mul, vector.Z * mul); |
50 | } | 72 | } |
51 | else | 73 | else |
52 | { | 74 | { |
53 | return new Vertex(0, 0, 0); | 75 | return new Vertex(0f, 0f, 0f); |
54 | } | 76 | } |
55 | } | 77 | } |
56 | 78 | ||
57 | public Vertex cross(Vertex v) | 79 | public Vertex cross(Vertex v) |
58 | { | 80 | { |
59 | return new Vertex(Y * v.Z - Z * v.Y, Z * v.X - X * v.Z, X * v.Y - Y * v.X); | 81 | return new Vertex(vector.Y * v.Z - vector.Z * v.Y, vector.Z * v.X - vector.X * v.Z, vector.X * v.Y - vector.Y * v.X); |
60 | } | 82 | } |
61 | 83 | ||
62 | // disable warning: mono compiler moans about overloading | 84 | // disable warning: mono compiler moans about overloading |
@@ -160,9 +182,9 @@ public class Vertex : PhysicsVector, IComparable<Vertex> | |||
160 | return X * v.X + Y * v.Y + Z * v.Z; | 182 | return X * v.X + Y * v.Y + Z * v.Z; |
161 | } | 183 | } |
162 | 184 | ||
163 | public Vertex(PhysicsVector v) | 185 | public Vertex(Vector3 v) |
164 | : base(v.X, v.Y, v.Z) | ||
165 | { | 186 | { |
187 | vector = v; | ||
166 | } | 188 | } |
167 | 189 | ||
168 | public Vertex Clone() | 190 | public Vertex Clone() |
@@ -175,11 +197,15 @@ public class Vertex : PhysicsVector, IComparable<Vertex> | |||
175 | return new Vertex((float) Math.Cos(angle), (float) Math.Sin(angle), 0.0f); | 197 | return new Vertex((float) Math.Cos(angle), (float) Math.Sin(angle), 0.0f); |
176 | } | 198 | } |
177 | 199 | ||
200 | public float Length() | ||
201 | { | ||
202 | return vector.Length(); | ||
203 | } | ||
178 | 204 | ||
179 | public virtual bool Equals(Vertex v, float tolerance) | 205 | public virtual bool Equals(Vertex v, float tolerance) |
180 | { | 206 | { |
181 | PhysicsVector diff = this - v; | 207 | Vertex diff = this - v; |
182 | float d = diff.length(); | 208 | float d = diff.Length(); |
183 | if (d < tolerance) | 209 | if (d < tolerance) |
184 | return true; | 210 | return true; |
185 | 211 | ||
@@ -369,22 +395,22 @@ public class Triangle | |||
369 | return s1 + ";" + s2 + ";" + s3; | 395 | return s1 + ";" + s2 + ";" + s3; |
370 | } | 396 | } |
371 | 397 | ||
372 | public PhysicsVector getNormal() | 398 | public Vector3 getNormal() |
373 | { | 399 | { |
374 | // Vertices | 400 | // Vertices |
375 | 401 | ||
376 | // Vectors for edges | 402 | // Vectors for edges |
377 | PhysicsVector e1; | 403 | Vector3 e1; |
378 | PhysicsVector e2; | 404 | Vector3 e2; |
379 | 405 | ||
380 | e1 = new PhysicsVector(v1.X - v2.X, v1.Y - v2.Y, v1.Z - v2.Z); | 406 | e1 = new Vector3(v1.X - v2.X, v1.Y - v2.Y, v1.Z - v2.Z); |
381 | e2 = new PhysicsVector(v1.X - v3.X, v1.Y - v3.Y, v1.Z - v3.Z); | 407 | e2 = new Vector3(v1.X - v3.X, v1.Y - v3.Y, v1.Z - v3.Z); |
382 | 408 | ||
383 | // Cross product for normal | 409 | // Cross product for normal |
384 | PhysicsVector n = PhysicsVector.cross(e1, e2); | 410 | Vector3 n = Vector3.Cross(e1, e2); |
385 | 411 | ||
386 | // Length | 412 | // Length |
387 | float l = n.length(); | 413 | float l = n.Length(); |
388 | 414 | ||
389 | // Normalized "normal" | 415 | // Normalized "normal" |
390 | n = n/l; | 416 | n = n/l; |
diff --git a/OpenSim/Region/Physics/Meshing/Mesh.cs b/OpenSim/Region/Physics/Meshing/Mesh.cs index 4c3cf33..f781ff9 100644 --- a/OpenSim/Region/Physics/Meshing/Mesh.cs +++ b/OpenSim/Region/Physics/Meshing/Mesh.cs | |||
@@ -31,6 +31,7 @@ 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 | using PrimMesher; |
34 | using OpenMetaverse; | ||
34 | 35 | ||
35 | namespace OpenSim.Region.Physics.Meshing | 36 | namespace OpenSim.Region.Physics.Meshing |
36 | { | 37 | { |
@@ -141,12 +142,12 @@ namespace OpenSim.Region.Physics.Meshing | |||
141 | } | 142 | } |
142 | } | 143 | } |
143 | 144 | ||
144 | public List<PhysicsVector> getVertexList() | 145 | public List<Vector3> getVertexList() |
145 | { | 146 | { |
146 | List<PhysicsVector> result = new List<PhysicsVector>(); | 147 | List<Vector3> result = new List<Vector3>(); |
147 | foreach (Vertex v in m_vertices.Keys) | 148 | foreach (Vertex v in m_vertices.Keys) |
148 | { | 149 | { |
149 | result.Add(v); | 150 | result.Add(new Vector3(v.X, v.Y, v.Z)); |
150 | } | 151 | } |
151 | return result; | 152 | return result; |
152 | } | 153 | } |
@@ -174,6 +175,9 @@ namespace OpenSim.Region.Physics.Meshing | |||
174 | 175 | ||
175 | float[] result = getVertexListAsFloat(); | 176 | float[] result = getVertexListAsFloat(); |
176 | m_pinnedVertexes = GCHandle.Alloc(result, GCHandleType.Pinned); | 177 | m_pinnedVertexes = GCHandle.Alloc(result, GCHandleType.Pinned); |
178 | // Inform the garbage collector of this unmanaged allocation so it can schedule | ||
179 | // the next GC round more intelligently | ||
180 | GC.AddMemoryPressure(Buffer.ByteLength(result)); | ||
177 | 181 | ||
178 | return result; | 182 | return result; |
179 | } | 183 | } |
@@ -223,6 +227,9 @@ namespace OpenSim.Region.Physics.Meshing | |||
223 | 227 | ||
224 | int[] result = getIndexListAsInt(); | 228 | int[] result = getIndexListAsInt(); |
225 | m_pinnedIndex = GCHandle.Alloc(result, GCHandleType.Pinned); | 229 | m_pinnedIndex = GCHandle.Alloc(result, GCHandleType.Pinned); |
230 | // Inform the garbage collector of this unmanaged allocation so it can schedule | ||
231 | // the next GC round more intelligently | ||
232 | GC.AddMemoryPressure(Buffer.ByteLength(result)); | ||
226 | 233 | ||
227 | return result; | 234 | return result; |
228 | } | 235 | } |
diff --git a/OpenSim/Region/Physics/Meshing/Meshmerizer.cs b/OpenSim/Region/Physics/Meshing/Meshmerizer.cs index f609e73..fbe1949 100644 --- a/OpenSim/Region/Physics/Meshing/Meshmerizer.cs +++ b/OpenSim/Region/Physics/Meshing/Meshmerizer.cs | |||
@@ -31,7 +31,6 @@ 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 OpenMetaverse.Imaging; | ||
35 | using System.Drawing; | 34 | using System.Drawing; |
36 | using System.Drawing.Imaging; | 35 | using System.Drawing.Imaging; |
37 | using PrimMesher; | 36 | using PrimMesher; |
@@ -61,7 +60,6 @@ namespace OpenSim.Region.Physics.Meshing | |||
61 | public class Meshmerizer : IMesher | 60 | public class Meshmerizer : IMesher |
62 | { | 61 | { |
63 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | 62 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); |
64 | //private static readonly log4net.ILog m_log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | ||
65 | 63 | ||
66 | // Setting baseDir to a path will enable the dumping of raw files | 64 | // Setting baseDir to a path will enable the dumping of raw files |
67 | // raw files can be imported by blender so a visual inspection of the results can be done | 65 | // raw files can be imported by blender so a visual inspection of the results can be done |
@@ -160,7 +158,7 @@ namespace OpenSim.Region.Physics.Meshing | |||
160 | float minZ = float.MaxValue; | 158 | float minZ = float.MaxValue; |
161 | float maxZ = float.MinValue; | 159 | float maxZ = float.MinValue; |
162 | 160 | ||
163 | foreach (Vertex v in meshIn.getVertexList()) | 161 | foreach (Vector3 v in meshIn.getVertexList()) |
164 | { | 162 | { |
165 | if (v != null) | 163 | if (v != null) |
166 | { | 164 | { |
@@ -185,7 +183,7 @@ namespace OpenSim.Region.Physics.Meshing | |||
185 | 183 | ||
186 | } | 184 | } |
187 | 185 | ||
188 | private ulong GetMeshKey(PrimitiveBaseShape pbs, PhysicsVector size, float lod) | 186 | private ulong GetMeshKey(PrimitiveBaseShape pbs, Vector3 size, float lod) |
189 | { | 187 | { |
190 | ulong hash = 5381; | 188 | ulong hash = 5381; |
191 | 189 | ||
@@ -245,9 +243,9 @@ namespace OpenSim.Region.Physics.Meshing | |||
245 | hash = ((hash << 5) + hash) + (ulong)((byte)c); | 243 | hash = ((hash << 5) + hash) + (ulong)((byte)c); |
246 | return ((hash << 5) + hash) + (ulong)(c >> 8); | 244 | return ((hash << 5) + hash) + (ulong)(c >> 8); |
247 | } | 245 | } |
248 | |||
249 | 246 | ||
250 | private Mesh CreateMeshFromPrimMesher(string primName, PrimitiveBaseShape primShape, PhysicsVector size, float lod) | 247 | |
248 | private Mesh CreateMeshFromPrimMesher(string primName, PrimitiveBaseShape primShape, Vector3 size, float lod) | ||
251 | { | 249 | { |
252 | PrimMesh primMesh; | 250 | PrimMesh primMesh; |
253 | PrimMesher.SculptMesh sculptMesh; | 251 | PrimMesher.SculptMesh sculptMesh; |
@@ -281,16 +279,12 @@ namespace OpenSim.Region.Physics.Meshing | |||
281 | 279 | ||
282 | if (idata == null) | 280 | if (idata == null) |
283 | { | 281 | { |
284 | if (primShape.SculptData.Length == 0) | 282 | if (primShape.SculptData == null || primShape.SculptData.Length == 0) |
285 | return null; | 283 | return null; |
286 | 284 | ||
287 | try | 285 | try |
288 | { | 286 | { |
289 | ManagedImage managedImage; // we never use this | 287 | idata = CSJ2K.J2kImage.FromBytes(primShape.SculptData); |
290 | OpenJPEG.DecodeToImage(primShape.SculptData, out managedImage, out idata); | ||
291 | |||
292 | // Remove the reference to the encoded JPEG2000 data so it can be GCed | ||
293 | primShape.SculptData = Utils.EmptyBytes; | ||
294 | 288 | ||
295 | if (cacheSculptMaps) | 289 | if (cacheSculptMaps) |
296 | { | 290 | { |
@@ -315,8 +309,6 @@ namespace OpenSim.Region.Physics.Meshing | |||
315 | } | 309 | } |
316 | } | 310 | } |
317 | 311 | ||
318 | |||
319 | |||
320 | PrimMesher.SculptMesh.SculptType sculptType; | 312 | PrimMesher.SculptMesh.SculptType sculptType; |
321 | switch ((OpenMetaverse.SculptType)primShape.SculptType) | 313 | switch ((OpenMetaverse.SculptType)primShape.SculptType) |
322 | { | 314 | { |
@@ -351,7 +343,6 @@ namespace OpenSim.Region.Physics.Meshing | |||
351 | coords = sculptMesh.coords; | 343 | coords = sculptMesh.coords; |
352 | faces = sculptMesh.faces; | 344 | faces = sculptMesh.faces; |
353 | } | 345 | } |
354 | |||
355 | else | 346 | else |
356 | { | 347 | { |
357 | float pathShearX = primShape.PathShearX < 128 ? (float)primShape.PathShearX * 0.01f : (float)(primShape.PathShearX - 256) * 0.01f; | 348 | float pathShearX = primShape.PathShearX < 128 ? (float)primShape.PathShearX * 0.01f : (float)(primShape.PathShearX - 256) * 0.01f; |
@@ -466,6 +457,8 @@ namespace OpenSim.Region.Physics.Meshing | |||
466 | faces = primMesh.faces; | 457 | faces = primMesh.faces; |
467 | } | 458 | } |
468 | 459 | ||
460 | // Remove the reference to any JPEG2000 sculpt data so it can be GCed | ||
461 | primShape.SculptData = Utils.EmptyBytes; | ||
469 | 462 | ||
470 | int numCoords = coords.Count; | 463 | int numCoords = coords.Count; |
471 | int numFaces = faces.Count; | 464 | int numFaces = faces.Count; |
@@ -488,12 +481,12 @@ namespace OpenSim.Region.Physics.Meshing | |||
488 | return mesh; | 481 | return mesh; |
489 | } | 482 | } |
490 | 483 | ||
491 | public IMesh CreateMesh(String primName, PrimitiveBaseShape primShape, PhysicsVector size, float lod) | 484 | public IMesh CreateMesh(String primName, PrimitiveBaseShape primShape, Vector3 size, float lod) |
492 | { | 485 | { |
493 | return CreateMesh(primName, primShape, size, lod, false); | 486 | return CreateMesh(primName, primShape, size, lod, false); |
494 | } | 487 | } |
495 | 488 | ||
496 | public IMesh CreateMesh(String primName, PrimitiveBaseShape primShape, PhysicsVector size, float lod, bool isPhysical) | 489 | public IMesh CreateMesh(String primName, PrimitiveBaseShape primShape, Vector3 size, float lod, bool isPhysical) |
497 | { | 490 | { |
498 | Mesh mesh = null; | 491 | Mesh mesh = null; |
499 | ulong key = 0; | 492 | ulong key = 0; |