[Hide Content]From 85f0936fa936d08671ccd80e352fdb0c9b278814 Mon Sep 17 00:00:00 2001
From: Robert Adams <robert.adams@intel.com>
Date: Fri, 26 Aug 2011 20:51:05 -0700
Subject: [PATCH 1/2] Move GetMeshKey from buried inside Meshmerizer to a public method on PrimitiveBaseShape
---
OpenSim/Framework/PrimitiveBaseShape.cs | 61 ++++++++++++++++++++++++
OpenSim/Region/Physics/Meshing/Meshmerizer.cs | 63 +------------------------
2 files changed, 62 insertions(+), 62 deletions(-)
diff --git a/OpenSim/Framework/PrimitiveBaseShape.cs b/OpenSim/Framework/PrimitiveBaseShape.cs
index d873071..1b6a1d2 100644
--- a/OpenSim/Framework/PrimitiveBaseShape.cs
+++ b/OpenSim/Framework/PrimitiveBaseShape.cs
@@ -859,6 +859,67 @@ namespace OpenSim.Framework
}
}
+ public ulong GetMeshKey(Vector3 size, float lod)
+ {
+ ulong hash = 5381;
+
+ hash = djb2(hash, this.PathCurve);
+ hash = djb2(hash, (byte)((byte)this.HollowShape | (byte)this.ProfileShape));
+ hash = djb2(hash, this.PathBegin);
+ hash = djb2(hash, this.PathEnd);
+ hash = djb2(hash, this.PathScaleX);
+ hash = djb2(hash, this.PathScaleY);
+ hash = djb2(hash, this.PathShearX);
+ hash = djb2(hash, this.PathShearY);
+ hash = djb2(hash, (byte)this.PathTwist);
+ hash = djb2(hash, (byte)this.PathTwistBegin);
+ hash = djb2(hash, (byte)this.PathRadiusOffset);
+ hash = djb2(hash, (byte)this.PathTaperX);
+ hash = djb2(hash, (byte)this.PathTaperY);
+ hash = djb2(hash, this.PathRevolutions);
+ hash = djb2(hash, (byte)this.PathSkew);
+ hash = djb2(hash, this.ProfileBegin);
+ hash = djb2(hash, this.ProfileEnd);
+ hash = djb2(hash, this.ProfileHollow);
+
+ // TODO: Separate scale out from the primitive shape data (after
+ // scaling is supported at the physics engine level)
+ byte[] scaleBytes = size.GetBytes();
+ for (int i = 0; i < scaleBytes.Length; i++)
+ hash = djb2(hash, scaleBytes[i]);
+
+ // Include LOD in hash, accounting for endianness
+ byte[] lodBytes = new byte[4];
+ Buffer.BlockCopy(BitConverter.GetBytes(lod), 0, lodBytes, 0, 4);
+ if (!BitConverter.IsLittleEndian)
+ {
+ Array.Reverse(lodBytes, 0, 4);
+ }
+ for (int i = 0; i < lodBytes.Length; i++)
+ hash = djb2(hash, lodBytes[i]);
+
+ // include sculpt UUID
+ if (this.SculptEntry)
+ {
+ scaleBytes = this.SculptTexture.GetBytes();
+ for (int i = 0; i < scaleBytes.Length; i++)
+ hash = djb2(hash, scaleBytes[i]);
+ }
+
+ return hash;
+ }
+
+ private ulong djb2(ulong hash, byte c)
+ {
+ return ((hash << 5) + hash) + (ulong)c;
+ }
+
+ private ulong djb2(ulong hash, ushort c)
+ {
+ hash = ((hash << 5) + hash) + (ulong)((byte)c);
+ return ((hash << 5) + hash) + (ulong)(c >> 8);
+ }
+
public byte[] ExtraParamsToBytes()
{
// m_log.DebugFormat("[EXTRAPARAMS]: Called ExtraParamsToBytes()");
diff --git a/OpenSim/Region/Physics/Meshing/Meshmerizer.cs b/OpenSim/Region/Physics/Meshing/Meshmerizer.cs
index e81b982..07396ff 100644
--- a/OpenSim/Region/Physics/Meshing/Meshmerizer.cs
+++ b/OpenSim/Region/Physics/Meshing/Meshmerizer.cs
@@ -193,67 +193,6 @@ namespace OpenSim.Region.Physics.Meshing
m_log.Error("****** PrimMesh Parameters ******\n" + primMesh.ParamsToDisplayString());
}
- private ulong GetMeshKey(PrimitiveBaseShape pbs, Vector3 size, float lod)
- {
- ulong hash = 5381;
-
- hash = djb2(hash, pbs.PathCurve);
- hash = djb2(hash, (byte)((byte)pbs.HollowShape | (byte)pbs.ProfileShape));
- hash = djb2(hash, pbs.PathBegin);
- hash = djb2(hash, pbs.PathEnd);
- hash = djb2(hash, pbs.PathScaleX);
- hash = djb2(hash, pbs.PathScaleY);
- hash = djb2(hash, pbs.PathShearX);
- hash = djb2(hash, pbs.PathShearY);
- hash = djb2(hash, (byte)pbs.PathTwist);
- hash = djb2(hash, (byte)pbs.PathTwistBegin);
- hash = djb2(hash, (byte)pbs.PathRadiusOffset);
- hash = djb2(hash, (byte)pbs.PathTaperX);
- hash = djb2(hash, (byte)pbs.PathTaperY);
- hash = djb2(hash, pbs.PathRevolutions);
- hash = djb2(hash, (byte)pbs.PathSkew);
- hash = djb2(hash, pbs.ProfileBegin);
- hash = djb2(hash, pbs.ProfileEnd);
- hash = djb2(hash, pbs.ProfileHollow);
-
- // TODO: Separate scale out from the primitive shape data (after
- // scaling is supported at the physics engine level)
- byte[] scaleBytes = size.GetBytes();
- for (int i = 0; i < scaleBytes.Length; i++)
- hash = djb2(hash, scaleBytes[i]);
-
- // Include LOD in hash, accounting for endianness
- byte[] lodBytes = new byte[4];
- Buffer.BlockCopy(BitConverter.GetBytes(lod), 0, lodBytes, 0, 4);
- if (!BitConverter.IsLittleEndian)
- {
- Array.Reverse(lodBytes, 0, 4);
- }
- for (int i = 0; i < lodBytes.Length; i++)
- hash = djb2(hash, lodBytes[i]);
-
- // include sculpt UUID
- if (pbs.SculptEntry)
- {
- scaleBytes = pbs.SculptTexture.GetBytes();
- for (int i = 0; i < scaleBytes.Length; i++)
- hash = djb2(hash, scaleBytes[i]);
- }
-
- return hash;
- }
-
- private ulong djb2(ulong hash, byte c)
- {
- return ((hash << 5) + hash) + (ulong)c;
- }
-
- private ulong djb2(ulong hash, ushort c)
- {
- hash = ((hash << 5) + hash) + (ulong)((byte)c);
- return ((hash << 5) + hash) + (ulong)(c >> 8);
- }
-
/// <summary>
/// Add a submesh to an existing list of coords and faces.
/// </summary>
@@ -751,7 +690,7 @@ namespace OpenSim.Region.Physics.Meshing
// If this mesh has been created already, return it instead of creating another copy
// For large regions with 100k+ prims and hundreds of copies of each, this can save a GB or more of memory
- key = GetMeshKey(primShape, size, lod);
+ key = primShape.GetMeshKey(size, lod);
if (m_uniqueMeshes.TryGetValue(key, out mesh))
return mesh;
--
1.7.2.3