aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorRobert Adams2011-08-26 20:51:05 -0700
committerBlueWall2011-08-28 16:50:54 -0400
commit18037d41c45b7a00170a7badddd3ef1d8ad2a25c (patch)
treec3f0193b66c5875872ead38cf9616b72b6dcaada
parentAdd level of detail specification to optionally reduce the number of vertices... (diff)
downloadopensim-SC-18037d41c45b7a00170a7badddd3ef1d8ad2a25c.zip
opensim-SC-18037d41c45b7a00170a7badddd3ef1d8ad2a25c.tar.gz
opensim-SC-18037d41c45b7a00170a7badddd3ef1d8ad2a25c.tar.bz2
opensim-SC-18037d41c45b7a00170a7badddd3ef1d8ad2a25c.tar.xz
Move GetMeshKey from buried inside Meshmerizer to a public method on PrimitiveBaseShape
Signed-off-by: BlueWall <jamesh@bluewallgroup.com>
Diffstat (limited to '')
-rw-r--r--OpenSim/Framework/PrimitiveBaseShape.cs61
-rw-r--r--OpenSim/Region/Physics/Meshing/Meshmerizer.cs63
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
859 } 859 }
860 } 860 }
861 861
862 public ulong GetMeshKey(Vector3 size, float lod)
863 {
864 ulong hash = 5381;
865
866 hash = djb2(hash, this.PathCurve);
867 hash = djb2(hash, (byte)((byte)this.HollowShape | (byte)this.ProfileShape));
868 hash = djb2(hash, this.PathBegin);
869 hash = djb2(hash, this.PathEnd);
870 hash = djb2(hash, this.PathScaleX);
871 hash = djb2(hash, this.PathScaleY);
872 hash = djb2(hash, this.PathShearX);
873 hash = djb2(hash, this.PathShearY);
874 hash = djb2(hash, (byte)this.PathTwist);
875 hash = djb2(hash, (byte)this.PathTwistBegin);
876 hash = djb2(hash, (byte)this.PathRadiusOffset);
877 hash = djb2(hash, (byte)this.PathTaperX);
878 hash = djb2(hash, (byte)this.PathTaperY);
879 hash = djb2(hash, this.PathRevolutions);
880 hash = djb2(hash, (byte)this.PathSkew);
881 hash = djb2(hash, this.ProfileBegin);
882 hash = djb2(hash, this.ProfileEnd);
883 hash = djb2(hash, this.ProfileHollow);
884
885 // TODO: Separate scale out from the primitive shape data (after
886 // scaling is supported at the physics engine level)
887 byte[] scaleBytes = size.GetBytes();
888 for (int i = 0; i < scaleBytes.Length; i++)
889 hash = djb2(hash, scaleBytes[i]);
890
891 // Include LOD in hash, accounting for endianness
892 byte[] lodBytes = new byte[4];
893 Buffer.BlockCopy(BitConverter.GetBytes(lod), 0, lodBytes, 0, 4);
894 if (!BitConverter.IsLittleEndian)
895 {
896 Array.Reverse(lodBytes, 0, 4);
897 }
898 for (int i = 0; i < lodBytes.Length; i++)
899 hash = djb2(hash, lodBytes[i]);
900
901 // include sculpt UUID
902 if (this.SculptEntry)
903 {
904 scaleBytes = this.SculptTexture.GetBytes();
905 for (int i = 0; i < scaleBytes.Length; i++)
906 hash = djb2(hash, scaleBytes[i]);
907 }
908
909 return hash;
910 }
911
912 private ulong djb2(ulong hash, byte c)
913 {
914 return ((hash << 5) + hash) + (ulong)c;
915 }
916
917 private ulong djb2(ulong hash, ushort c)
918 {
919 hash = ((hash << 5) + hash) + (ulong)((byte)c);
920 return ((hash << 5) + hash) + (ulong)(c >> 8);
921 }
922
862 public byte[] ExtraParamsToBytes() 923 public byte[] ExtraParamsToBytes()
863 { 924 {
864// m_log.DebugFormat("[EXTRAPARAMS]: Called ExtraParamsToBytes()"); 925// m_log.DebugFormat("[EXTRAPARAMS]: Called ExtraParamsToBytes()");
diff --git a/OpenSim/Region/Physics/Meshing/Meshmerizer.cs b/OpenSim/Region/Physics/Meshing/Meshmerizer.cs
index faecce4..53d5e4c 100644
--- a/OpenSim/Region/Physics/Meshing/Meshmerizer.cs
+++ b/OpenSim/Region/Physics/Meshing/Meshmerizer.cs
@@ -193,67 +193,6 @@ namespace OpenSim.Region.Physics.Meshing
193 m_log.Error("****** PrimMesh Parameters ******\n" + primMesh.ParamsToDisplayString()); 193 m_log.Error("****** PrimMesh Parameters ******\n" + primMesh.ParamsToDisplayString());
194 } 194 }
195 195
196 private ulong GetMeshKey(PrimitiveBaseShape pbs, Vector3 size, float lod)
197 {
198 ulong hash = 5381;
199
200 hash = djb2(hash, pbs.PathCurve);
201 hash = djb2(hash, (byte)((byte)pbs.HollowShape | (byte)pbs.ProfileShape));
202 hash = djb2(hash, pbs.PathBegin);
203 hash = djb2(hash, pbs.PathEnd);
204 hash = djb2(hash, pbs.PathScaleX);
205 hash = djb2(hash, pbs.PathScaleY);
206 hash = djb2(hash, pbs.PathShearX);
207 hash = djb2(hash, pbs.PathShearY);
208 hash = djb2(hash, (byte)pbs.PathTwist);
209 hash = djb2(hash, (byte)pbs.PathTwistBegin);
210 hash = djb2(hash, (byte)pbs.PathRadiusOffset);
211 hash = djb2(hash, (byte)pbs.PathTaperX);
212 hash = djb2(hash, (byte)pbs.PathTaperY);
213 hash = djb2(hash, pbs.PathRevolutions);
214 hash = djb2(hash, (byte)pbs.PathSkew);
215 hash = djb2(hash, pbs.ProfileBegin);
216 hash = djb2(hash, pbs.ProfileEnd);
217 hash = djb2(hash, pbs.ProfileHollow);
218
219 // TODO: Separate scale out from the primitive shape data (after
220 // scaling is supported at the physics engine level)
221 byte[] scaleBytes = size.GetBytes();
222 for (int i = 0; i < scaleBytes.Length; i++)
223 hash = djb2(hash, scaleBytes[i]);
224
225 // Include LOD in hash, accounting for endianness
226 byte[] lodBytes = new byte[4];
227 Buffer.BlockCopy(BitConverter.GetBytes(lod), 0, lodBytes, 0, 4);
228 if (!BitConverter.IsLittleEndian)
229 {
230 Array.Reverse(lodBytes, 0, 4);
231 }
232 for (int i = 0; i < lodBytes.Length; i++)
233 hash = djb2(hash, lodBytes[i]);
234
235 // include sculpt UUID
236 if (pbs.SculptEntry)
237 {
238 scaleBytes = pbs.SculptTexture.GetBytes();
239 for (int i = 0; i < scaleBytes.Length; i++)
240 hash = djb2(hash, scaleBytes[i]);
241 }
242
243 return hash;
244 }
245
246 private ulong djb2(ulong hash, byte c)
247 {
248 return ((hash << 5) + hash) + (ulong)c;
249 }
250
251 private ulong djb2(ulong hash, ushort c)
252 {
253 hash = ((hash << 5) + hash) + (ulong)((byte)c);
254 return ((hash << 5) + hash) + (ulong)(c >> 8);
255 }
256
257 /// <summary> 196 /// <summary>
258 /// Add a submesh to an existing list of coords and faces. 197 /// Add a submesh to an existing list of coords and faces.
259 /// </summary> 198 /// </summary>
@@ -777,7 +716,7 @@ namespace OpenSim.Region.Physics.Meshing
777 716
778 // If this mesh has been created already, return it instead of creating another copy 717 // If this mesh has been created already, return it instead of creating another copy
779 // For large regions with 100k+ prims and hundreds of copies of each, this can save a GB or more of memory 718 // For large regions with 100k+ prims and hundreds of copies of each, this can save a GB or more of memory
780 key = GetMeshKey(primShape, size, lod); 719 key = primShape.GetMeshKey(size, lod);
781 if (m_uniqueMeshes.TryGetValue(key, out mesh)) 720 if (m_uniqueMeshes.TryGetValue(key, out mesh))
782 return mesh; 721 return mesh;
783 722