aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region
diff options
context:
space:
mode:
authorJustin Clark-Casey (justincc)2011-07-08 20:36:01 +0100
committerJustin Clark-Casey (justincc)2011-07-08 20:36:01 +0100
commit40300c886cb84715bf1a81d90c4144dc44bbe8f7 (patch)
tree0c81b449ba5f1b063b1c880736bd7052c01fb3cc /OpenSim/Region
parentFix interpretation of physics mesh proxies from mesh data (diff)
downloadopensim-SC_OLD-40300c886cb84715bf1a81d90c4144dc44bbe8f7.zip
opensim-SC_OLD-40300c886cb84715bf1a81d90c4144dc44bbe8f7.tar.gz
opensim-SC_OLD-40300c886cb84715bf1a81d90c4144dc44bbe8f7.tar.bz2
opensim-SC_OLD-40300c886cb84715bf1a81d90c4144dc44bbe8f7.tar.xz
refactor: Factor out AddSubMesh() method from long CraeteMeshFromPrimMesher() method
Also remove some of the logging spam left in from the last commit.
Diffstat (limited to 'OpenSim/Region')
-rw-r--r--OpenSim/Region/Physics/Meshing/Meshmerizer.cs97
-rw-r--r--OpenSim/Region/Physics/OdePlugin/OdeScene.cs10
2 files changed, 58 insertions, 49 deletions
diff --git a/OpenSim/Region/Physics/Meshing/Meshmerizer.cs b/OpenSim/Region/Physics/Meshing/Meshmerizer.cs
index 38b9112..ad03cc8 100644
--- a/OpenSim/Region/Physics/Meshing/Meshmerizer.cs
+++ b/OpenSim/Region/Physics/Meshing/Meshmerizer.cs
@@ -100,7 +100,6 @@ namespace OpenSim.Region.Physics.Meshing
100 { 100 {
101 m_log.WarnFormat("[SCULPT]: Unable to create {0} directory: ", decodedSculptMapPath, e.Message); 101 m_log.WarnFormat("[SCULPT]: Unable to create {0} directory: ", decodedSculptMapPath, e.Message);
102 } 102 }
103
104 } 103 }
105 104
106 /// <summary> 105 /// <summary>
@@ -156,7 +155,6 @@ namespace OpenSim.Region.Physics.Meshing
156 return box; 155 return box;
157 } 156 }
158 157
159
160 /// <summary> 158 /// <summary>
161 /// Creates a simple bounding box mesh for a complex input mesh 159 /// Creates a simple bounding box mesh for a complex input mesh
162 /// </summary> 160 /// </summary>
@@ -193,7 +191,6 @@ namespace OpenSim.Region.Physics.Meshing
193 m_log.Error(message); 191 m_log.Error(message);
194 m_log.Error("\nPrim Name: " + primName); 192 m_log.Error("\nPrim Name: " + primName);
195 m_log.Error("****** PrimMesh Parameters ******\n" + primMesh.ParamsToDisplayString()); 193 m_log.Error("****** PrimMesh Parameters ******\n" + primMesh.ParamsToDisplayString());
196
197 } 194 }
198 195
199 private ulong GetMeshKey(PrimitiveBaseShape pbs, Vector3 size, float lod) 196 private ulong GetMeshKey(PrimitiveBaseShape pbs, Vector3 size, float lod)
@@ -257,6 +254,54 @@ namespace OpenSim.Region.Physics.Meshing
257 return ((hash << 5) + hash) + (ulong)(c >> 8); 254 return ((hash << 5) + hash) + (ulong)(c >> 8);
258 } 255 }
259 256
257 /// <summary>
258 /// Add a submesh to an existing list of coords and faces.
259 /// </summary>
260 /// <param name="subMeshData"></param>
261 /// <param name="size">Size of entire object</param>
262 /// <param name="coords"></param>
263 /// <param name="faces"></param>
264 private void AddSubMesh(OSDMap subMeshData, Vector3 size, List<Coord> coords, List<Face> faces)
265 {
266 // Console.WriteLine("subMeshMap for {0} - {1}", primName, Util.GetFormattedXml((OSD)subMeshMap));
267
268 // As per http://wiki.secondlife.com/wiki/Mesh/Mesh_Asset_Format, some Mesh Level
269 // of Detail Blocks (maps) contain just a NoGeometry key to signal there is no
270 // geometry for this submesh.
271 if (subMeshData.ContainsKey("NoGeometry") && ((OSDBoolean)subMeshData["NoGeometry"]))
272 return;
273
274 OpenMetaverse.Vector3 posMax = ((OSDMap)subMeshData["PositionDomain"])["Max"].AsVector3();
275 OpenMetaverse.Vector3 posMin = ((OSDMap)subMeshData["PositionDomain"])["Min"].AsVector3();
276 ushort faceIndexOffset = (ushort)coords.Count;
277
278 byte[] posBytes = subMeshData["Position"].AsBinary();
279 for (int i = 0; i < posBytes.Length; i += 6)
280 {
281 ushort uX = Utils.BytesToUInt16(posBytes, i);
282 ushort uY = Utils.BytesToUInt16(posBytes, i + 2);
283 ushort uZ = Utils.BytesToUInt16(posBytes, i + 4);
284
285 Coord c = new Coord(
286 Utils.UInt16ToFloat(uX, posMin.X, posMax.X) * size.X,
287 Utils.UInt16ToFloat(uY, posMin.Y, posMax.Y) * size.Y,
288 Utils.UInt16ToFloat(uZ, posMin.Z, posMax.Z) * size.Z);
289
290 coords.Add(c);
291 }
292
293 byte[] triangleBytes = subMeshData["TriangleList"].AsBinary();
294 for (int i = 0; i < triangleBytes.Length; i += 6)
295 {
296 ushort v1 = (ushort)(Utils.BytesToUInt16(triangleBytes, i) + faceIndexOffset);
297 ushort v2 = (ushort)(Utils.BytesToUInt16(triangleBytes, i + 2) + faceIndexOffset);
298 ushort v3 = (ushort)(Utils.BytesToUInt16(triangleBytes, i + 4) + faceIndexOffset);
299 Face f = new Face(v1, v2, v3);
300 faces.Add(f);
301 }
302
303 return;
304 }
260 305
261 private Mesh CreateMeshFromPrimMesher(string primName, PrimitiveBaseShape primShape, Vector3 size, float lod) 306 private Mesh CreateMeshFromPrimMesher(string primName, PrimitiveBaseShape primShape, Vector3 size, float lod)
262 { 307 {
@@ -304,6 +349,7 @@ namespace OpenSim.Region.Physics.Meshing
304 { 349 {
305 m_log.Error("[MESH]: Exception deserializing mesh asset header:" + e.ToString()); 350 m_log.Error("[MESH]: Exception deserializing mesh asset header:" + e.ToString());
306 } 351 }
352
307 start = data.Position; 353 start = data.Position;
308 } 354 }
309 355
@@ -315,9 +361,10 @@ namespace OpenSim.Region.Physics.Meshing
315 physicsParms = (OSDMap)map["physics_shape"]; // old asset format 361 physicsParms = (OSDMap)map["physics_shape"]; // old asset format
316 else if (map.ContainsKey("physics_mesh")) 362 else if (map.ContainsKey("physics_mesh"))
317 physicsParms = (OSDMap)map["physics_mesh"]; // new asset format 363 physicsParms = (OSDMap)map["physics_mesh"]; // new asset format
364
318 if (physicsParms == null) 365 if (physicsParms == null)
319 { 366 {
320 m_log.Warn("[Mesh]: no recognized physics mesh found in mesh asset"); 367 m_log.Warn("[MESH]: no recognized physics mesh found in mesh asset");
321 return null; 368 return null;
322 } 369 }
323 370
@@ -372,46 +419,7 @@ namespace OpenSim.Region.Physics.Meshing
372 foreach (OSD subMeshOsd in decodedMeshOsdArray) 419 foreach (OSD subMeshOsd in decodedMeshOsdArray)
373 { 420 {
374 if (subMeshOsd is OSDMap) 421 if (subMeshOsd is OSDMap)
375 { 422 AddSubMesh(subMeshOsd as OSDMap, size, coords, faces);
376 OSDMap subMeshMap = (OSDMap)subMeshOsd;
377
378// Console.WriteLine("subMeshMap for {0} - {1}", primName, Util.GetFormattedXml((OSD)subMeshMap));
379
380 // As per http://wiki.secondlife.com/wiki/Mesh/Mesh_Asset_Format, some Mesh Level
381 // of Detail Blocks (maps) contain just a NoGeometry key to signal there is no
382 // geometry for this submesh.
383 if (subMeshMap.ContainsKey("NoGeometry") && ((OSDBoolean)subMeshMap["NoGeometry"]))
384 continue;
385
386 OpenMetaverse.Vector3 posMax = ((OSDMap)subMeshMap["PositionDomain"])["Max"].AsVector3();
387 OpenMetaverse.Vector3 posMin = ((OSDMap)subMeshMap["PositionDomain"])["Min"].AsVector3();
388 ushort faceIndexOffset = (ushort)coords.Count;
389
390 byte[] posBytes = subMeshMap["Position"].AsBinary();
391 for (int i = 0; i < posBytes.Length; i += 6)
392 {
393 ushort uX = Utils.BytesToUInt16(posBytes, i);
394 ushort uY = Utils.BytesToUInt16(posBytes, i + 2);
395 ushort uZ = Utils.BytesToUInt16(posBytes, i + 4);
396
397 Coord c = new Coord(
398 Utils.UInt16ToFloat(uX, posMin.X, posMax.X) * size.X,
399 Utils.UInt16ToFloat(uY, posMin.Y, posMax.Y) * size.Y,
400 Utils.UInt16ToFloat(uZ, posMin.Z, posMax.Z) * size.Z);
401
402 coords.Add(c);
403 }
404
405 byte[] triangleBytes = subMeshMap["TriangleList"].AsBinary();
406 for (int i = 0; i < triangleBytes.Length; i += 6)
407 {
408 ushort v1 = (ushort)(Utils.BytesToUInt16(triangleBytes, i) + faceIndexOffset);
409 ushort v2 = (ushort)(Utils.BytesToUInt16(triangleBytes, i + 2) + faceIndexOffset);
410 ushort v3 = (ushort)(Utils.BytesToUInt16(triangleBytes, i + 4) + faceIndexOffset);
411 Face f = new Face(v1, v2, v3);
412 faces.Add(f);
413 }
414 }
415 } 423 }
416 } 424 }
417 } 425 }
@@ -643,6 +651,7 @@ namespace OpenSim.Region.Physics.Meshing
643 Face f = faces[i]; 651 Face f = faces[i];
644 mesh.Add(new Triangle(vertices[f.v1], vertices[f.v2], vertices[f.v3])); 652 mesh.Add(new Triangle(vertices[f.v1], vertices[f.v2], vertices[f.v3]));
645 } 653 }
654
646 return mesh; 655 return mesh;
647 } 656 }
648 657
diff --git a/OpenSim/Region/Physics/OdePlugin/OdeScene.cs b/OpenSim/Region/Physics/OdePlugin/OdeScene.cs
index b09e69e..87d22af 100644
--- a/OpenSim/Region/Physics/OdePlugin/OdeScene.cs
+++ b/OpenSim/Region/Physics/OdePlugin/OdeScene.cs
@@ -26,7 +26,7 @@
26 */ 26 */
27 27
28//#define USE_DRAWSTUFF 28//#define USE_DRAWSTUFF
29//#define DEBUG 29//#define SPAM
30 30
31using System; 31using System;
32using System.Collections.Generic; 32using System.Collections.Generic;
@@ -2463,7 +2463,7 @@ namespace OpenSim.Region.Physics.OdePlugin
2463 2463
2464 if (pbs.SculptEntry && !meshSculptedPrim) 2464 if (pbs.SculptEntry && !meshSculptedPrim)
2465 { 2465 {
2466#if DEBUG 2466#if SPAM
2467 m_log.Warn("NonMesh"); 2467 m_log.Warn("NonMesh");
2468#endif 2468#endif
2469 return false; 2469 return false;
@@ -2485,7 +2485,7 @@ namespace OpenSim.Region.Physics.OdePlugin
2485 && pbs.PathScaleX == 100 && pbs.PathScaleY == 100 2485 && pbs.PathScaleX == 100 && pbs.PathScaleY == 100
2486 && pbs.PathShearX == 0 && pbs.PathShearY == 0) 2486 && pbs.PathShearX == 0 && pbs.PathShearY == 0)
2487 { 2487 {
2488#if DEBUG 2488#if SPAM
2489 m_log.Warn("NonMesh"); 2489 m_log.Warn("NonMesh");
2490#endif 2490#endif
2491 return false; 2491 return false;
@@ -2566,12 +2566,12 @@ namespace OpenSim.Region.Physics.OdePlugin
2566 2566
2567 if (iPropertiesNotSupportedDefault == 0) 2567 if (iPropertiesNotSupportedDefault == 0)
2568 { 2568 {
2569#if DEBUG 2569#if SPAM
2570 m_log.Warn("NonMesh"); 2570 m_log.Warn("NonMesh");
2571#endif 2571#endif
2572 return false; 2572 return false;
2573 } 2573 }
2574#if DEBUG 2574#if SPAM
2575 m_log.Debug("Mesh"); 2575 m_log.Debug("Mesh");
2576#endif 2576#endif
2577 return true; 2577 return true;