From db4f8d129887cd4fdd5603918590b3c940191882 Mon Sep 17 00:00:00 2001 From: Dahlia Trimble Date: Fri, 29 May 2009 02:46:35 +0000 Subject: Experimental decoded sculpt map caching --- .../Region/Framework/Scenes/SceneObjectGroup.cs | 8 ++- OpenSim/Region/Framework/Scenes/SceneObjectPart.cs | 2 +- OpenSim/Region/Physics/Meshing/Meshmerizer.cs | 65 ++++++++++++++++------ 3 files changed, 55 insertions(+), 20 deletions(-) diff --git a/OpenSim/Region/Framework/Scenes/SceneObjectGroup.cs b/OpenSim/Region/Framework/Scenes/SceneObjectGroup.cs index e0a50a1..a60ae83 100644 --- a/OpenSim/Region/Framework/Scenes/SceneObjectGroup.cs +++ b/OpenSim/Region/Framework/Scenes/SceneObjectGroup.cs @@ -2967,8 +2967,12 @@ namespace OpenSim.Region.Framework.Scenes { if (part.Shape.SculptEntry && part.Shape.SculptTexture != UUID.Zero) { - m_scene.AssetService.Get( - part.Shape.SculptTexture.ToString(), part, AssetReceived); + // check if a previously decoded sculpt map has been cached + if (File.Exists(System.IO.Path.Combine("j2kDecodeCache", "smap_" + part.Shape.SculptTexture.ToString()))) + part.SculptTextureCallback(part.Shape.SculptTexture, null); + else + m_scene.AssetService.Get( + part.Shape.SculptTexture.ToString(), part, AssetReceived); } } } diff --git a/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs b/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs index 719b028..7065d2f 100644 --- a/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs +++ b/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs @@ -2268,7 +2268,7 @@ if (m_shape != null) { { if (m_shape.SculptEntry) { - if (texture != null) + //if (texture != null) // null could mean a cached sculpt map has been found { m_shape.SculptData = texture.Data; if (PhysActor != null) diff --git a/OpenSim/Region/Physics/Meshing/Meshmerizer.cs b/OpenSim/Region/Physics/Meshing/Meshmerizer.cs index 3e14fc4..21f922f 100644 --- a/OpenSim/Region/Physics/Meshing/Meshmerizer.cs +++ b/OpenSim/Region/Physics/Meshing/Meshmerizer.cs @@ -37,6 +37,7 @@ using System.Drawing.Imaging; using PrimMesher; using log4net; using System.Reflection; +using System.IO; namespace OpenSim.Region.Physics.Meshing { @@ -70,6 +71,8 @@ namespace OpenSim.Region.Physics.Meshing private const string baseDir = null; //"rawFiles"; #endif + private string decodedScultMapPath = "j2kDecodeCache"; + private float minSizeForComplexMesh = 0.2f; // prims with all dimensions smaller than this will have a bounding box mesh @@ -176,34 +179,62 @@ namespace OpenSim.Region.Physics.Meshing List faces; Image idata = null; + string decodedSculptFileName = ""; if (primShape.SculptEntry) { if (primShape.SculptData.Length == 0) return null; - try - { - ManagedImage managedImage; // we never use this - OpenJPEG.DecodeToImage(primShape.SculptData, out managedImage, out idata); - - } - 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) + if (primShape.SculptTexture != null) { - m_log.Error("[PHYSICS]: OpenJpeg was unable to decode this. Physics Proxy generation failed"); - return null; + decodedSculptFileName = System.IO.Path.Combine(decodedScultMapPath, "smap_" + primShape.SculptTexture.ToString()); + try + { + if (File.Exists(decodedSculptFileName)) + { + idata = Image.FromFile(decodedSculptFileName); + } + } + 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()); } - catch (Exception) + + if (idata == null) { - m_log.Error("[PHYSICS]: Unable to generate a Sculpty physics proxy. Sculpty texture decode failed!"); - return null; + try + { + ManagedImage managedImage; // we never use this + OpenJPEG.DecodeToImage(primShape.SculptData, out managedImage, out idata); + + //if (File.Exists(System.IO.Path.GetDirectoryName(decodedScultMapPath))) + try { idata.Save(decodedSculptFileName, ImageFormat.MemoryBmp); } + catch (Exception e) { m_log.Error("[SCULPT]: unable to cache sculpt map " + decodedSculptFileName + " " + e.Message); } + } + 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) + { + m_log.Error("[PHYSICS]: Unable to generate a Sculpty physics proxy. Sculpty texture decode failed!"); + return null; + } } + + PrimMesher.SculptMesh.SculptType sculptType; switch ((OpenMetaverse.SculptType)primShape.SculptType) { -- cgit v1.1