aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorUbitUmarov2016-11-17 13:57:45 +0000
committerUbitUmarov2016-11-17 13:57:45 +0000
commit2db22bf064f14afcbfecacfb8006da5c44a6040c (patch)
tree9535f01d79bd5ec458ade95ab7e6821985dce58f
parent restore large useracconts expire time for testing (diff)
downloadopensim-SC-2db22bf064f14afcbfecacfb8006da5c44a6040c.zip
opensim-SC-2db22bf064f14afcbfecacfb8006da5c44a6040c.tar.gz
opensim-SC-2db22bf064f14afcbfecacfb8006da5c44a6040c.tar.bz2
opensim-SC-2db22bf064f14afcbfecacfb8006da5c44a6040c.tar.xz
minor changes to ubMeshmerizer memory use
-rw-r--r--OpenSim/Region/PhysicsModules/ubOdeMeshing/Mesh.cs131
-rw-r--r--OpenSim/Region/PhysicsModules/ubOdeMeshing/Meshmerizer.cs4
2 files changed, 67 insertions, 68 deletions
diff --git a/OpenSim/Region/PhysicsModules/ubOdeMeshing/Mesh.cs b/OpenSim/Region/PhysicsModules/ubOdeMeshing/Mesh.cs
index d9ea4a4..0cdaa60 100644
--- a/OpenSim/Region/PhysicsModules/ubOdeMeshing/Mesh.cs
+++ b/OpenSim/Region/PhysicsModules/ubOdeMeshing/Mesh.cs
@@ -39,6 +39,24 @@ namespace OpenSim.Region.PhysicsModule.ubODEMeshing
39{ 39{
40 public class MeshBuildingData 40 public class MeshBuildingData
41 { 41 {
42 private class vertexcomp : IEqualityComparer<Vertex>
43 {
44 public bool Equals(Vertex v1, Vertex v2)
45 {
46 if (v1.X == v2.X && v1.Y == v2.Y && v1.Z == v2.Z)
47 return true;
48 else
49 return false;
50 }
51 public int GetHashCode(Vertex v)
52 {
53 int a = v.X.GetHashCode();
54 int b = v.Y.GetHashCode();
55 int c = v.Z.GetHashCode();
56 return (a << 16) ^ (b << 8) ^ c;
57 }
58 }
59
42 public Dictionary<Vertex, int> m_vertices; 60 public Dictionary<Vertex, int> m_vertices;
43 public List<Triangle> m_triangles; 61 public List<Triangle> m_triangles;
44 public float m_obbXmin; 62 public float m_obbXmin;
@@ -49,6 +67,21 @@ namespace OpenSim.Region.PhysicsModule.ubODEMeshing
49 public float m_obbZmax; 67 public float m_obbZmax;
50 public Vector3 m_centroid; 68 public Vector3 m_centroid;
51 public int m_centroidDiv; 69 public int m_centroidDiv;
70
71 public MeshBuildingData()
72 {
73 vertexcomp vcomp = new vertexcomp();
74 m_vertices = new Dictionary<Vertex, int>(vcomp);
75 m_triangles = new List<Triangle>();
76 m_centroid = Vector3.Zero;
77 m_centroidDiv = 0;
78 m_obbXmin = float.MaxValue;
79 m_obbXmax = float.MinValue;
80 m_obbYmin = float.MaxValue;
81 m_obbYmax = float.MinValue;
82 m_obbZmin = float.MaxValue;
83 m_obbZmax = float.MinValue;
84 }
52 } 85 }
53 86
54 [Serializable()] 87 [Serializable()]
@@ -76,50 +109,20 @@ namespace OpenSim.Region.PhysicsModule.ubODEMeshing
76 public int RefCount { get; set; } 109 public int RefCount { get; set; }
77 public AMeshKey Key { get; set; } 110 public AMeshKey Key { get; set; }
78 111
79 private class vertexcomp : IEqualityComparer<Vertex> 112 public Mesh(bool forbuild)
80 { 113 {
81 public bool Equals(Vertex v1, Vertex v2) 114 if(forbuild)
82 { 115 m_bdata = new MeshBuildingData();
83 if (v1.X == v2.X && v1.Y == v2.Y && v1.Z == v2.Z)
84 return true;
85 else
86 return false;
87 }
88 public int GetHashCode(Vertex v)
89 {
90 int a = v.X.GetHashCode();
91 int b = v.Y.GetHashCode();
92 int c = v.Z.GetHashCode();
93 return (a << 16) ^ (b << 8) ^ c;
94 }
95 }
96
97 public Mesh()
98 {
99 vertexcomp vcomp = new vertexcomp();
100
101 m_bdata = new MeshBuildingData();
102 m_bdata.m_vertices = new Dictionary<Vertex, int>(vcomp);
103 m_bdata.m_triangles = new List<Triangle>();
104 m_bdata.m_centroid = Vector3.Zero;
105 m_bdata.m_centroidDiv = 0;
106 m_bdata.m_obbXmin = float.MaxValue;
107 m_bdata.m_obbXmax = float.MinValue;
108 m_bdata.m_obbYmin = float.MaxValue;
109 m_bdata.m_obbYmax = float.MinValue;
110 m_bdata.m_obbZmin = float.MaxValue;
111 m_bdata.m_obbZmax = float.MinValue;
112 m_obb = new Vector3(0.5f, 0.5f, 0.5f); 116 m_obb = new Vector3(0.5f, 0.5f, 0.5f);
113 m_obboffset = Vector3.Zero; 117 m_obboffset = Vector3.Zero;
114 } 118 }
115 119
116
117 public Mesh Scale(Vector3 scale) 120 public Mesh Scale(Vector3 scale)
118 { 121 {
119 if (m_verticesPtr == null || m_indicesPtr == null) 122 if (m_verticesPtr == null || m_indicesPtr == null)
120 return null; 123 return null;
121 124
122 Mesh result = new Mesh(); 125 Mesh result = new Mesh(false);
123 126
124 float x = scale.X; 127 float x = scale.X;
125 float y = scale.Y; 128 float y = scale.Y;
@@ -167,7 +170,7 @@ namespace OpenSim.Region.PhysicsModule.ubODEMeshing
167 170
168 public Mesh Clone() 171 public Mesh Clone()
169 { 172 {
170 Mesh result = new Mesh(); 173 Mesh result = new Mesh(false);
171 174
172 if (m_bdata != null) 175 if (m_bdata != null)
173 { 176 {
@@ -514,8 +517,6 @@ namespace OpenSim.Region.PhysicsModule.ubODEMeshing
514 if (m_indicesPtr == IntPtr.Zero) 517 if (m_indicesPtr == IntPtr.Zero)
515 indexes = getIndexListAsInt(); 518 indexes = getIndexListAsInt();
516 519
517 pinMemory();
518
519 float x, y, z; 520 float x, y, z;
520 521
521 if (m_bdata.m_centroidDiv > 0) 522 if (m_bdata.m_centroidDiv > 0)
@@ -543,55 +544,53 @@ namespace OpenSim.Region.PhysicsModule.ubODEMeshing
543 m_obb = new Vector3(x, y, z); 544 m_obb = new Vector3(x, y, z);
544 545
545 releaseBuildingMeshData(); 546 releaseBuildingMeshData();
547 pinMemory();
546 } 548 }
549
547 public bool ToStream(Stream st) 550 public bool ToStream(Stream st)
548 { 551 {
549 if (m_indicesPtr == IntPtr.Zero || m_verticesPtr == IntPtr.Zero) 552 if (m_indicesPtr == IntPtr.Zero || m_verticesPtr == IntPtr.Zero)
550 return false; 553 return false;
551 554
552 BinaryWriter bw = new BinaryWriter(st);
553 bool ok = true; 555 bool ok = true;
554 556
555 try 557 try
556 { 558 {
557 559 using(BinaryWriter bw = new BinaryWriter(st))
558 bw.Write(m_vertexCount); 560 {
559 bw.Write(m_indexCount); 561 bw.Write(m_vertexCount);
560 562 bw.Write(m_indexCount);
561 for (int i = 0; i < 3 * m_vertexCount; i++) 563
562 bw.Write(vertices[i]); 564 for (int i = 0; i < 3 * m_vertexCount; i++)
563 for (int i = 0; i < m_indexCount; i++) 565 bw.Write(vertices[i]);
564 bw.Write(indexes[i]); 566 for (int i = 0; i < m_indexCount; i++)
565 bw.Write(m_obb.X); 567 bw.Write(indexes[i]);
566 bw.Write(m_obb.Y); 568 bw.Write(m_obb.X);
567 bw.Write(m_obb.Z); 569 bw.Write(m_obb.Y);
568 bw.Write(m_obboffset.X); 570 bw.Write(m_obb.Z);
569 bw.Write(m_obboffset.Y); 571 bw.Write(m_obboffset.X);
570 bw.Write(m_obboffset.Z); 572 bw.Write(m_obboffset.Y);
573 bw.Write(m_obboffset.Z);
574 bw.Flush();
575 bw.Close();
576 }
571 } 577 }
572 catch 578 catch
573 { 579 {
574 ok = false; 580 ok = false;
575 } 581 }
576 582
577 if (bw != null)
578 {
579 bw.Flush();
580 bw.Close();
581 }
582
583 return ok; 583 return ok;
584 } 584 }
585 585
586 public static Mesh FromStream(Stream st, AMeshKey key) 586 public static Mesh FromStream(Stream st, AMeshKey key)
587 { 587 {
588 Mesh mesh = new Mesh(); 588 Mesh mesh = new Mesh(false);
589 mesh.releaseBuildingMeshData();
590 589
591 bool ok = true; 590 bool ok = true;
592 using(BinaryReader br = new BinaryReader(st)) 591 try
593 { 592 {
594 try 593 using(BinaryReader br = new BinaryReader(st))
595 { 594 {
596 mesh.m_vertexCount = br.ReadInt32(); 595 mesh.m_vertexCount = br.ReadInt32();
597 mesh.m_indexCount = br.ReadInt32(); 596 mesh.m_indexCount = br.ReadInt32();
@@ -613,10 +612,10 @@ namespace OpenSim.Region.PhysicsModule.ubODEMeshing
613 mesh.m_obboffset.Y = br.ReadSingle(); 612 mesh.m_obboffset.Y = br.ReadSingle();
614 mesh.m_obboffset.Z = br.ReadSingle(); 613 mesh.m_obboffset.Z = br.ReadSingle();
615 } 614 }
616 catch 615 }
617 { 616 catch
618 ok = false; 617 {
619 } 618 ok = false;
620 } 619 }
621 620
622 if (ok) 621 if (ok)
diff --git a/OpenSim/Region/PhysicsModules/ubOdeMeshing/Meshmerizer.cs b/OpenSim/Region/PhysicsModules/ubOdeMeshing/Meshmerizer.cs
index ca94034..98c2e71 100644
--- a/OpenSim/Region/PhysicsModules/ubOdeMeshing/Meshmerizer.cs
+++ b/OpenSim/Region/PhysicsModules/ubOdeMeshing/Meshmerizer.cs
@@ -182,7 +182,7 @@ namespace OpenSim.Region.PhysicsModule.ubODEMeshing
182 /// <returns></returns> 182 /// <returns></returns>
183 private static Mesh CreateSimpleBoxMesh(float minX, float maxX, float minY, float maxY, float minZ, float maxZ) 183 private static Mesh CreateSimpleBoxMesh(float minX, float maxX, float minY, float maxY, float minZ, float maxZ)
184 { 184 {
185 Mesh box = new Mesh(); 185 Mesh box = new Mesh(true);
186 List<Vertex> vertices = new List<Vertex>(); 186 List<Vertex> vertices = new List<Vertex>();
187 // bottom 187 // bottom
188 188
@@ -357,7 +357,7 @@ namespace OpenSim.Region.PhysicsModule.ubODEMeshing
357 int numCoords = coords.Count; 357 int numCoords = coords.Count;
358 int numFaces = faces.Count; 358 int numFaces = faces.Count;
359 359
360 Mesh mesh = new Mesh(); 360 Mesh mesh = new Mesh(true);
361 // Add the corresponding triangles to the mesh 361 // Add the corresponding triangles to the mesh
362 for (int i = 0; i < numFaces; i++) 362 for (int i = 0; i < numFaces; i++)
363 { 363 {