From 1dcad4ac6616a21216eeb139c901d98eed9169db Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Fri, 8 Jul 2011 17:58:01 +0100 Subject: minor: commented out log lines for future use and very small code tidy --- OpenSim/Region/Physics/Meshing/Meshmerizer.cs | 2 ++ 1 file changed, 2 insertions(+) (limited to 'OpenSim/Region/Physics/Meshing') diff --git a/OpenSim/Region/Physics/Meshing/Meshmerizer.cs b/OpenSim/Region/Physics/Meshing/Meshmerizer.cs index a5fe45b..be4ee41 100644 --- a/OpenSim/Region/Physics/Meshing/Meshmerizer.cs +++ b/OpenSim/Region/Physics/Meshing/Meshmerizer.cs @@ -643,6 +643,8 @@ namespace OpenSim.Region.Physics.Meshing public IMesh CreateMesh(String primName, PrimitiveBaseShape primShape, Vector3 size, float lod, bool isPhysical) { +// m_log.DebugFormat("[MESH]: Creating mesh for {0}", primName); + Mesh mesh = null; ulong key = 0; -- cgit v1.1 From b18ef976ff0e8bf2bc2fd8d8002007fcaafd0ed7 Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Fri, 8 Jul 2011 19:43:22 +0100 Subject: Fix interpretation of physics mesh proxies from mesh data As per http://wiki.secondlife.com/wiki/Mesh/Mesh_Asset_Format, some submesh blocks may just have the flag "NoGeometry" to signal that they provide no mesh data. If a block contains this, ignore it for meshing purposes rather than suffer a ClassCastException This fixes physics proxy meshing, so you can now walk through mesh doorways, properly stand on the trailer of mesh trucks, etc. To get mesh physics proxy, the UseMeshiesPhysicsMesh must be true in a [Mesh] config section in OpenSim.ini (example in OpenSimDefaults.ini). Convex hull physics not currently supported. --- OpenSim/Region/Physics/Meshing/Meshmerizer.cs | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'OpenSim/Region/Physics/Meshing') diff --git a/OpenSim/Region/Physics/Meshing/Meshmerizer.cs b/OpenSim/Region/Physics/Meshing/Meshmerizer.cs index be4ee41..38b9112 100644 --- a/OpenSim/Region/Physics/Meshing/Meshmerizer.cs +++ b/OpenSim/Region/Physics/Meshing/Meshmerizer.cs @@ -366,6 +366,8 @@ namespace OpenSim.Region.Physics.Meshing // physics_shape is an array of OSDMaps, one for each submesh if (decodedMeshOsd is OSDArray) { +// Console.WriteLine("decodedMeshOsd for {0} - {1}", primName, Util.GetFormattedXml(decodedMeshOsd)); + decodedMeshOsdArray = (OSDArray)decodedMeshOsd; foreach (OSD subMeshOsd in decodedMeshOsdArray) { @@ -373,6 +375,14 @@ namespace OpenSim.Region.Physics.Meshing { OSDMap subMeshMap = (OSDMap)subMeshOsd; +// Console.WriteLine("subMeshMap for {0} - {1}", primName, Util.GetFormattedXml((OSD)subMeshMap)); + + // As per http://wiki.secondlife.com/wiki/Mesh/Mesh_Asset_Format, some Mesh Level + // of Detail Blocks (maps) contain just a NoGeometry key to signal there is no + // geometry for this submesh. + if (subMeshMap.ContainsKey("NoGeometry") && ((OSDBoolean)subMeshMap["NoGeometry"])) + continue; + OpenMetaverse.Vector3 posMax = ((OSDMap)subMeshMap["PositionDomain"])["Max"].AsVector3(); OpenMetaverse.Vector3 posMin = ((OSDMap)subMeshMap["PositionDomain"])["Min"].AsVector3(); ushort faceIndexOffset = (ushort)coords.Count; -- cgit v1.1 From 40300c886cb84715bf1a81d90c4144dc44bbe8f7 Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Fri, 8 Jul 2011 20:36:01 +0100 Subject: refactor: Factor out AddSubMesh() method from long CraeteMeshFromPrimMesher() method Also remove some of the logging spam left in from the last commit. --- OpenSim/Region/Physics/Meshing/Meshmerizer.cs | 97 +++++++++++++++------------ 1 file changed, 53 insertions(+), 44 deletions(-) (limited to 'OpenSim/Region/Physics/Meshing') 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 { m_log.WarnFormat("[SCULPT]: Unable to create {0} directory: ", decodedSculptMapPath, e.Message); } - } /// @@ -156,7 +155,6 @@ namespace OpenSim.Region.Physics.Meshing return box; } - /// /// Creates a simple bounding box mesh for a complex input mesh /// @@ -193,7 +191,6 @@ namespace OpenSim.Region.Physics.Meshing m_log.Error(message); m_log.Error("\nPrim Name: " + primName); m_log.Error("****** PrimMesh Parameters ******\n" + primMesh.ParamsToDisplayString()); - } private ulong GetMeshKey(PrimitiveBaseShape pbs, Vector3 size, float lod) @@ -257,6 +254,54 @@ namespace OpenSim.Region.Physics.Meshing return ((hash << 5) + hash) + (ulong)(c >> 8); } + /// + /// Add a submesh to an existing list of coords and faces. + /// + /// + /// Size of entire object + /// + /// + private void AddSubMesh(OSDMap subMeshData, Vector3 size, List coords, List faces) + { + // Console.WriteLine("subMeshMap for {0} - {1}", primName, Util.GetFormattedXml((OSD)subMeshMap)); + + // As per http://wiki.secondlife.com/wiki/Mesh/Mesh_Asset_Format, some Mesh Level + // of Detail Blocks (maps) contain just a NoGeometry key to signal there is no + // geometry for this submesh. + if (subMeshData.ContainsKey("NoGeometry") && ((OSDBoolean)subMeshData["NoGeometry"])) + return; + + OpenMetaverse.Vector3 posMax = ((OSDMap)subMeshData["PositionDomain"])["Max"].AsVector3(); + OpenMetaverse.Vector3 posMin = ((OSDMap)subMeshData["PositionDomain"])["Min"].AsVector3(); + ushort faceIndexOffset = (ushort)coords.Count; + + byte[] posBytes = subMeshData["Position"].AsBinary(); + for (int i = 0; i < posBytes.Length; i += 6) + { + ushort uX = Utils.BytesToUInt16(posBytes, i); + ushort uY = Utils.BytesToUInt16(posBytes, i + 2); + ushort uZ = Utils.BytesToUInt16(posBytes, i + 4); + + Coord c = new Coord( + Utils.UInt16ToFloat(uX, posMin.X, posMax.X) * size.X, + Utils.UInt16ToFloat(uY, posMin.Y, posMax.Y) * size.Y, + Utils.UInt16ToFloat(uZ, posMin.Z, posMax.Z) * size.Z); + + coords.Add(c); + } + + byte[] triangleBytes = subMeshData["TriangleList"].AsBinary(); + for (int i = 0; i < triangleBytes.Length; i += 6) + { + ushort v1 = (ushort)(Utils.BytesToUInt16(triangleBytes, i) + faceIndexOffset); + ushort v2 = (ushort)(Utils.BytesToUInt16(triangleBytes, i + 2) + faceIndexOffset); + ushort v3 = (ushort)(Utils.BytesToUInt16(triangleBytes, i + 4) + faceIndexOffset); + Face f = new Face(v1, v2, v3); + faces.Add(f); + } + + return; + } private Mesh CreateMeshFromPrimMesher(string primName, PrimitiveBaseShape primShape, Vector3 size, float lod) { @@ -304,6 +349,7 @@ namespace OpenSim.Region.Physics.Meshing { m_log.Error("[MESH]: Exception deserializing mesh asset header:" + e.ToString()); } + start = data.Position; } @@ -315,9 +361,10 @@ namespace OpenSim.Region.Physics.Meshing physicsParms = (OSDMap)map["physics_shape"]; // old asset format else if (map.ContainsKey("physics_mesh")) physicsParms = (OSDMap)map["physics_mesh"]; // new asset format + if (physicsParms == null) { - m_log.Warn("[Mesh]: no recognized physics mesh found in mesh asset"); + m_log.Warn("[MESH]: no recognized physics mesh found in mesh asset"); return null; } @@ -372,46 +419,7 @@ namespace OpenSim.Region.Physics.Meshing foreach (OSD subMeshOsd in decodedMeshOsdArray) { if (subMeshOsd is OSDMap) - { - OSDMap subMeshMap = (OSDMap)subMeshOsd; - -// Console.WriteLine("subMeshMap for {0} - {1}", primName, Util.GetFormattedXml((OSD)subMeshMap)); - - // As per http://wiki.secondlife.com/wiki/Mesh/Mesh_Asset_Format, some Mesh Level - // of Detail Blocks (maps) contain just a NoGeometry key to signal there is no - // geometry for this submesh. - if (subMeshMap.ContainsKey("NoGeometry") && ((OSDBoolean)subMeshMap["NoGeometry"])) - continue; - - OpenMetaverse.Vector3 posMax = ((OSDMap)subMeshMap["PositionDomain"])["Max"].AsVector3(); - OpenMetaverse.Vector3 posMin = ((OSDMap)subMeshMap["PositionDomain"])["Min"].AsVector3(); - ushort faceIndexOffset = (ushort)coords.Count; - - byte[] posBytes = subMeshMap["Position"].AsBinary(); - for (int i = 0; i < posBytes.Length; i += 6) - { - ushort uX = Utils.BytesToUInt16(posBytes, i); - ushort uY = Utils.BytesToUInt16(posBytes, i + 2); - ushort uZ = Utils.BytesToUInt16(posBytes, i + 4); - - Coord c = new Coord( - Utils.UInt16ToFloat(uX, posMin.X, posMax.X) * size.X, - Utils.UInt16ToFloat(uY, posMin.Y, posMax.Y) * size.Y, - Utils.UInt16ToFloat(uZ, posMin.Z, posMax.Z) * size.Z); - - coords.Add(c); - } - - byte[] triangleBytes = subMeshMap["TriangleList"].AsBinary(); - for (int i = 0; i < triangleBytes.Length; i += 6) - { - ushort v1 = (ushort)(Utils.BytesToUInt16(triangleBytes, i) + faceIndexOffset); - ushort v2 = (ushort)(Utils.BytesToUInt16(triangleBytes, i + 2) + faceIndexOffset); - ushort v3 = (ushort)(Utils.BytesToUInt16(triangleBytes, i + 4) + faceIndexOffset); - Face f = new Face(v1, v2, v3); - faces.Add(f); - } - } + AddSubMesh(subMeshOsd as OSDMap, size, coords, faces); } } } @@ -643,6 +651,7 @@ namespace OpenSim.Region.Physics.Meshing Face f = faces[i]; mesh.Add(new Triangle(vertices[f.v1], vertices[f.v2], vertices[f.v3])); } + return mesh; } -- cgit v1.1 From e8ad8593b65e0d82d9ddf1ff4ea3536489856d72 Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Fri, 8 Jul 2011 20:58:44 +0100 Subject: refactor: eliminate redundant return statement --- OpenSim/Region/Physics/Meshing/Meshmerizer.cs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'OpenSim/Region/Physics/Meshing') diff --git a/OpenSim/Region/Physics/Meshing/Meshmerizer.cs b/OpenSim/Region/Physics/Meshing/Meshmerizer.cs index ad03cc8..e92e97b 100644 --- a/OpenSim/Region/Physics/Meshing/Meshmerizer.cs +++ b/OpenSim/Region/Physics/Meshing/Meshmerizer.cs @@ -299,8 +299,6 @@ namespace OpenSim.Region.Physics.Meshing Face f = new Face(v1, v2, v3); faces.Add(f); } - - return; } private Mesh CreateMeshFromPrimMesher(string primName, PrimitiveBaseShape primShape, Vector3 size, float lod) @@ -361,7 +359,7 @@ namespace OpenSim.Region.Physics.Meshing physicsParms = (OSDMap)map["physics_shape"]; // old asset format else if (map.ContainsKey("physics_mesh")) physicsParms = (OSDMap)map["physics_mesh"]; // new asset format - + if (physicsParms == null) { m_log.Warn("[MESH]: no recognized physics mesh found in mesh asset"); -- cgit v1.1 From 5e8900dfd058bd103cb6dcf8a57dc94683efd878 Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Sat, 9 Jul 2011 00:35:30 +0100 Subject: minor: code tidy and inserted log lines for future use. Unable to get to the bottom of why resizing a mesh fails to properly reset the physics proxy, when toggling phantom does After a mesh is generated, the existing sculptdata is set to zero in PrimitiveBaseShape to save memory When phantom is toggled, the sculptdata is regenerated before remeshing. But on resize, the sculptdata is not regenerated. So clearly, resetting sculptdata is possible, but haven't quite been able to pin down how this is being done when phantom is toggled. --- OpenSim/Region/Physics/Meshing/Meshmerizer.cs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'OpenSim/Region/Physics/Meshing') diff --git a/OpenSim/Region/Physics/Meshing/Meshmerizer.cs b/OpenSim/Region/Physics/Meshing/Meshmerizer.cs index e92e97b..b79e1a1 100644 --- a/OpenSim/Region/Physics/Meshing/Meshmerizer.cs +++ b/OpenSim/Region/Physics/Meshing/Meshmerizer.cs @@ -540,7 +540,6 @@ namespace OpenSim.Region.Physics.Meshing profileBegin = 0.5f * profileBegin + 0.5f; profileEnd = 0.5f * profileEnd + 0.5f; - } int hollowSides = sides; @@ -660,7 +659,9 @@ namespace OpenSim.Region.Physics.Meshing public IMesh CreateMesh(String primName, PrimitiveBaseShape primShape, Vector3 size, float lod, bool isPhysical) { -// m_log.DebugFormat("[MESH]: Creating mesh for {0}", primName); +#if SPAM + m_log.DebugFormat("[MESH]: Creating mesh for {0}", primName); +#endif Mesh mesh = null; ulong key = 0; -- cgit v1.1