From 2d88394cd59d9bf747b77c242b75bd923b0bc5af Mon Sep 17 00:00:00 2001 From: dahlia Date: Thu, 14 Oct 2010 13:10:03 -0700 Subject: laying some groundwork for mesh physics --- OpenSim/Region/Physics/Meshing/Meshmerizer.cs | 150 ++++++++++++++------------ 1 file changed, 80 insertions(+), 70 deletions(-) (limited to 'OpenSim/Region/Physics/Meshing/Meshmerizer.cs') diff --git a/OpenSim/Region/Physics/Meshing/Meshmerizer.cs b/OpenSim/Region/Physics/Meshing/Meshmerizer.cs index cf57c0a..e1203ea 100644 --- a/OpenSim/Region/Physics/Meshing/Meshmerizer.cs +++ b/OpenSim/Region/Physics/Meshing/Meshmerizer.cs @@ -256,102 +256,112 @@ namespace OpenSim.Region.Physics.Meshing PrimMesh primMesh; PrimMesher.SculptMesh sculptMesh; - List coords; - List faces; + List coords = new List(); + List faces = new List(); Image idata = null; string decodedSculptFileName = ""; if (primShape.SculptEntry) { - if (cacheSculptMaps && primShape.SculptTexture != UUID.Zero) + if (((OpenMetaverse.SculptType)primShape.SculptType) == SculptType.Mesh) + { + // add code for mesh physics proxy generation here + m_log.Debug("[MESH]: mesh proxy generation not implemented yet "); + return null; + + } + else { - decodedSculptFileName = System.IO.Path.Combine(decodedSculptMapPath, "smap_" + primShape.SculptTexture.ToString()); - try + if (cacheSculptMaps && primShape.SculptTexture != UUID.Zero) { - if (File.Exists(decodedSculptFileName)) + decodedSculptFileName = System.IO.Path.Combine(decodedSculptMapPath, "smap_" + primShape.SculptTexture.ToString()); + try { - idata = Image.FromFile(decodedSculptFileName); + if (File.Exists(decodedSculptFileName)) + { + idata = Image.FromFile(decodedSculptFileName); + } } - } - catch (Exception e) - { - m_log.Error("[SCULPT]: unable to load cached sculpt map " + decodedSculptFileName + " " + e.Message); + catch (Exception e) + { + m_log.Error("[SCULPT]: unable to load cached sculpt map " + decodedSculptFileName + " " + e.Message); + } + //if (idata != null) + // m_log.Debug("[SCULPT]: loaded cached map asset for map ID: " + primShape.SculptTexture.ToString()); } - //if (idata != null) - // m_log.Debug("[SCULPT]: loaded cached map asset for map ID: " + primShape.SculptTexture.ToString()); - } - if (idata == null) - { - if (primShape.SculptData == null || primShape.SculptData.Length == 0) - return null; - - try + if (idata == null) { - OpenMetaverse.Imaging.ManagedImage unusedData; - OpenMetaverse.Imaging.OpenJPEG.DecodeToImage(primShape.SculptData, out unusedData, out idata); - unusedData = null; + if (primShape.SculptData == null || primShape.SculptData.Length == 0) + return null; + + try + { + OpenMetaverse.Imaging.ManagedImage unusedData; + OpenMetaverse.Imaging.OpenJPEG.DecodeToImage(primShape.SculptData, out unusedData, out idata); + unusedData = null; - //idata = CSJ2K.J2kImage.FromBytes(primShape.SculptData); + //idata = CSJ2K.J2kImage.FromBytes(primShape.SculptData); - if (cacheSculptMaps && idata != null) + if (cacheSculptMaps && idata != null) + { + try { idata.Save(decodedSculptFileName, ImageFormat.MemoryBmp); } + catch (Exception e) { m_log.Error("[SCULPT]: unable to cache sculpt map " + decodedSculptFileName + " " + e.Message); } + } + } + catch (DllNotFoundException) { - try { idata.Save(decodedSculptFileName, ImageFormat.MemoryBmp); } - catch (Exception e) { m_log.Error("[SCULPT]: unable to cache sculpt map " + decodedSculptFileName + " " + e.Message); } + m_log.Error("[PHYSICS]: OpenJpeg is not installed correctly on this system. Physics Proxy generation failed. Often times this is because of an old version of GLIBC. You must have version 2.4 or above!"); + return null; + } + catch (IndexOutOfRangeException) + { + m_log.Error("[PHYSICS]: OpenJpeg was unable to decode this. Physics Proxy generation failed"); + return null; + } + catch (Exception ex) + { + m_log.Error("[PHYSICS]: Unable to generate a Sculpty physics proxy. Sculpty texture decode failed: " + ex.Message); + return null; } } - catch (DllNotFoundException) - { - m_log.Error("[PHYSICS]: OpenJpeg is not installed correctly on this system. Physics Proxy generation failed. Often times this is because of an old version of GLIBC. You must have version 2.4 or above!"); - return null; - } - catch (IndexOutOfRangeException) - { - m_log.Error("[PHYSICS]: OpenJpeg was unable to decode this. Physics Proxy generation failed"); - return null; - } - catch (Exception ex) + + PrimMesher.SculptMesh.SculptType sculptType; + switch ((OpenMetaverse.SculptType)primShape.SculptType) { - m_log.Error("[PHYSICS]: Unable to generate a Sculpty physics proxy. Sculpty texture decode failed: " + ex.Message); - return null; + case OpenMetaverse.SculptType.Cylinder: + sculptType = PrimMesher.SculptMesh.SculptType.cylinder; + break; + case OpenMetaverse.SculptType.Plane: + sculptType = PrimMesher.SculptMesh.SculptType.plane; + break; + case OpenMetaverse.SculptType.Torus: + sculptType = PrimMesher.SculptMesh.SculptType.torus; + break; + case OpenMetaverse.SculptType.Sphere: + sculptType = PrimMesher.SculptMesh.SculptType.sphere; + break; + default: + sculptType = PrimMesher.SculptMesh.SculptType.plane; + break; } - } - PrimMesher.SculptMesh.SculptType sculptType; - switch ((OpenMetaverse.SculptType)primShape.SculptType) - { - case OpenMetaverse.SculptType.Cylinder: - sculptType = PrimMesher.SculptMesh.SculptType.cylinder; - break; - case OpenMetaverse.SculptType.Plane: - sculptType = PrimMesher.SculptMesh.SculptType.plane; - break; - case OpenMetaverse.SculptType.Torus: - sculptType = PrimMesher.SculptMesh.SculptType.torus; - break; - case OpenMetaverse.SculptType.Sphere: - sculptType = PrimMesher.SculptMesh.SculptType.sphere; - break; - default: - sculptType = PrimMesher.SculptMesh.SculptType.plane; - break; - } + bool mirror = ((primShape.SculptType & 128) != 0); + bool invert = ((primShape.SculptType & 64) != 0); - bool mirror = ((primShape.SculptType & 128) != 0); - bool invert = ((primShape.SculptType & 64) != 0); + sculptMesh = new PrimMesher.SculptMesh((Bitmap)idata, sculptType, (int)lod, false, mirror, invert); + + idata.Dispose(); - sculptMesh = new PrimMesher.SculptMesh((Bitmap)idata, sculptType, (int)lod, false, mirror, invert); - - idata.Dispose(); + sculptMesh.DumpRaw(baseDir, primName, "primMesh"); - sculptMesh.DumpRaw(baseDir, primName, "primMesh"); + sculptMesh.Scale(size.X, size.Y, size.Z); - sculptMesh.Scale(size.X, size.Y, size.Z); - - coords = sculptMesh.coords; - faces = sculptMesh.faces; + coords = sculptMesh.coords; + faces = sculptMesh.faces; + } } else { -- cgit v1.1 From bcdd03c1cfcfab72d6ee4199bd1232ff3a748d6e Mon Sep 17 00:00:00 2001 From: dahlia Date: Thu, 14 Oct 2010 20:25:31 -0700 Subject: more work in progress on mesh physics - still non-functional --- OpenSim/Region/Physics/Meshing/Meshmerizer.cs | 69 ++++++++++++++++++++++++++- 1 file changed, 67 insertions(+), 2 deletions(-) (limited to 'OpenSim/Region/Physics/Meshing/Meshmerizer.cs') diff --git a/OpenSim/Region/Physics/Meshing/Meshmerizer.cs b/OpenSim/Region/Physics/Meshing/Meshmerizer.cs index e1203ea..df44be3 100644 --- a/OpenSim/Region/Physics/Meshing/Meshmerizer.cs +++ b/OpenSim/Region/Physics/Meshing/Meshmerizer.cs @@ -30,9 +30,11 @@ using System; using System.Collections.Generic; using OpenSim.Framework; using OpenSim.Region.Physics.Manager; -using OpenMetaverse; +using OpenMetaverse; +using OpenMetaverse.StructuredData; using System.Drawing; -using System.Drawing.Imaging; +using System.Drawing.Imaging; +using System.IO.Compression; using PrimMesher; using log4net; using Nini.Config; @@ -268,6 +270,69 @@ namespace OpenSim.Region.Physics.Meshing { // add code for mesh physics proxy generation here m_log.Debug("[MESH]: mesh proxy generation not implemented yet "); + + OSD meshOsd; + + if (primShape.SculptData.Length > 0) + { + + + m_log.Debug("[MESH]: asset data length: " + primShape.SculptData.Length.ToString()); + byte[] header = Util.StringToBytes256(""); + + ////dump to debugging file + //string filename = System.IO.Path.Combine(decodedSculptMapPath, "mesh_" + primShape.SculptTexture.ToString()); + //BinaryWriter writer = new BinaryWriter(File.Open(filename, FileMode.Create)); + //writer.Write(primShape.SculptData); + //writer.Close(); + + } + else + { + m_log.Error("[MESH]: asset data is zero length"); + return null; + } + + try + { + meshOsd = OSDParser.DeserializeLLSDBinary(primShape.SculptData, true); + } + catch (Exception e) + { + m_log.Error("[MESH]: exception decoding mesh asset: " + e.ToString()); + return null; + } + + if (meshOsd is OSDMap) + { + OSDMap map = (OSDMap)meshOsd; + //foreach (string name in map.Keys) + // m_log.Debug("[MESH]: key:" + name + " value:" + map[name].AsString()); + OSDMap physicsParms = (OSDMap)map["physics_shape"]; + int physOffset = physicsParms["offset"].AsInteger(); + int physSize = physicsParms["size"].AsInteger(); + + if (physOffset < 0 || physSize == 0) + return null; // no mesh data in asset + + m_log.Debug("[MESH]: physOffset:" + physOffset.ToString() + " physSize:" + physSize.ToString()); + //MemoryStream ms = new MemoryStream(primShape.SculptData, physOffset, physSize); + //GZipStream gzStream = new GZipStream(ms, CompressionMode.Decompress); + + //int maxSize = physSize * 5; // arbitrary guess + //byte[] readBuffer = new byte[maxSize]; + + //int bytesRead = gzStream.Read(readBuffer, 0, maxSize); + + //OSD physMeshOsd = OSDParser.DeserializeLLSDBinary(readBuffer); + + + + + + } + + //just bail out for now until mesh code is finished return null; } -- cgit v1.1 From 0308982c58c16bfa005a401d0345b2e58b759c44 Mon Sep 17 00:00:00 2001 From: Teravus Ovares (Dan Olivares) Date: Thu, 14 Oct 2010 23:32:33 -0400 Subject: one more silly line ending thing.... *If you have problems, fetch the tree and rebase. Signed-off-by: Teravus Ovares (Dan Olivares) --- OpenSim/Region/Physics/Meshing/Meshmerizer.cs | 142 +++++++++++++------------- 1 file changed, 71 insertions(+), 71 deletions(-) (limited to 'OpenSim/Region/Physics/Meshing/Meshmerizer.cs') diff --git a/OpenSim/Region/Physics/Meshing/Meshmerizer.cs b/OpenSim/Region/Physics/Meshing/Meshmerizer.cs index df44be3..3e3a0f0 100644 --- a/OpenSim/Region/Physics/Meshing/Meshmerizer.cs +++ b/OpenSim/Region/Physics/Meshing/Meshmerizer.cs @@ -30,10 +30,10 @@ using System; using System.Collections.Generic; using OpenSim.Framework; using OpenSim.Region.Physics.Manager; -using OpenMetaverse; +using OpenMetaverse; using OpenMetaverse.StructuredData; using System.Drawing; -using System.Drawing.Imaging; +using System.Drawing.Imaging; using System.IO.Compression; using PrimMesher; using log4net; @@ -266,75 +266,75 @@ namespace OpenSim.Region.Physics.Meshing if (primShape.SculptEntry) { - if (((OpenMetaverse.SculptType)primShape.SculptType) == SculptType.Mesh) - { - // add code for mesh physics proxy generation here - m_log.Debug("[MESH]: mesh proxy generation not implemented yet "); - - OSD meshOsd; - - if (primShape.SculptData.Length > 0) - { - - - m_log.Debug("[MESH]: asset data length: " + primShape.SculptData.Length.ToString()); - byte[] header = Util.StringToBytes256(""); - - ////dump to debugging file - //string filename = System.IO.Path.Combine(decodedSculptMapPath, "mesh_" + primShape.SculptTexture.ToString()); - //BinaryWriter writer = new BinaryWriter(File.Open(filename, FileMode.Create)); - //writer.Write(primShape.SculptData); - //writer.Close(); - - } - else - { - m_log.Error("[MESH]: asset data is zero length"); - return null; - } - - try - { - meshOsd = OSDParser.DeserializeLLSDBinary(primShape.SculptData, true); - } - catch (Exception e) - { - m_log.Error("[MESH]: exception decoding mesh asset: " + e.ToString()); - return null; - } - - if (meshOsd is OSDMap) - { - OSDMap map = (OSDMap)meshOsd; - //foreach (string name in map.Keys) - // m_log.Debug("[MESH]: key:" + name + " value:" + map[name].AsString()); - OSDMap physicsParms = (OSDMap)map["physics_shape"]; - int physOffset = physicsParms["offset"].AsInteger(); - int physSize = physicsParms["size"].AsInteger(); - - if (physOffset < 0 || physSize == 0) - return null; // no mesh data in asset - - m_log.Debug("[MESH]: physOffset:" + physOffset.ToString() + " physSize:" + physSize.ToString()); - //MemoryStream ms = new MemoryStream(primShape.SculptData, physOffset, physSize); - //GZipStream gzStream = new GZipStream(ms, CompressionMode.Decompress); - - //int maxSize = physSize * 5; // arbitrary guess - //byte[] readBuffer = new byte[maxSize]; - - //int bytesRead = gzStream.Read(readBuffer, 0, maxSize); - - //OSD physMeshOsd = OSDParser.DeserializeLLSDBinary(readBuffer); - - - - - - } - - //just bail out for now until mesh code is finished - return null; - + if (((OpenMetaverse.SculptType)primShape.SculptType) == SculptType.Mesh) + { + // add code for mesh physics proxy generation here + m_log.Debug("[MESH]: mesh proxy generation not implemented yet "); + + OSD meshOsd; + + if (primShape.SculptData.Length > 0) + { + + + m_log.Debug("[MESH]: asset data length: " + primShape.SculptData.Length.ToString()); + byte[] header = Util.StringToBytes256(""); + + ////dump to debugging file + //string filename = System.IO.Path.Combine(decodedSculptMapPath, "mesh_" + primShape.SculptTexture.ToString()); + //BinaryWriter writer = new BinaryWriter(File.Open(filename, FileMode.Create)); + //writer.Write(primShape.SculptData); + //writer.Close(); + + } + else + { + m_log.Error("[MESH]: asset data is zero length"); + return null; + } + + try + { + meshOsd = OSDParser.DeserializeLLSDBinary(primShape.SculptData, true); + } + catch (Exception e) + { + m_log.Error("[MESH]: exception decoding mesh asset: " + e.ToString()); + return null; + } + + if (meshOsd is OSDMap) + { + OSDMap map = (OSDMap)meshOsd; + //foreach (string name in map.Keys) + // m_log.Debug("[MESH]: key:" + name + " value:" + map[name].AsString()); + OSDMap physicsParms = (OSDMap)map["physics_shape"]; + int physOffset = physicsParms["offset"].AsInteger(); + int physSize = physicsParms["size"].AsInteger(); + + if (physOffset < 0 || physSize == 0) + return null; // no mesh data in asset + + m_log.Debug("[MESH]: physOffset:" + physOffset.ToString() + " physSize:" + physSize.ToString()); + //MemoryStream ms = new MemoryStream(primShape.SculptData, physOffset, physSize); + //GZipStream gzStream = new GZipStream(ms, CompressionMode.Decompress); + + //int maxSize = physSize * 5; // arbitrary guess + //byte[] readBuffer = new byte[maxSize]; + + //int bytesRead = gzStream.Read(readBuffer, 0, maxSize); + + //OSD physMeshOsd = OSDParser.DeserializeLLSDBinary(readBuffer); + + + + + + } + + //just bail out for now until mesh code is finished + return null; + } else { -- cgit v1.1