diff options
Diffstat (limited to 'OpenSim/Region/Physics/UbitMeshing')
-rw-r--r-- | OpenSim/Region/Physics/UbitMeshing/Mesh.cs | 78 | ||||
-rw-r--r-- | OpenSim/Region/Physics/UbitMeshing/Meshmerizer.cs | 40 |
2 files changed, 102 insertions, 16 deletions
diff --git a/OpenSim/Region/Physics/UbitMeshing/Mesh.cs b/OpenSim/Region/Physics/UbitMeshing/Mesh.cs index 98c0f0b..47e0cf4 100644 --- a/OpenSim/Region/Physics/UbitMeshing/Mesh.cs +++ b/OpenSim/Region/Physics/UbitMeshing/Mesh.cs | |||
@@ -48,8 +48,14 @@ namespace OpenSim.Region.Physics.Meshing | |||
48 | int m_indexCount = 0; | 48 | int m_indexCount = 0; |
49 | public float[] m_normals; | 49 | public float[] m_normals; |
50 | Vector3 m_centroid; | 50 | Vector3 m_centroid; |
51 | int m_centroidDiv; | 51 | float m_obbXmin; |
52 | float m_obbXmax; | ||
53 | float m_obbYmin; | ||
54 | float m_obbYmax; | ||
55 | float m_obbZmin; | ||
56 | float m_obbZmax; | ||
52 | 57 | ||
58 | int m_centroidDiv; | ||
53 | 59 | ||
54 | private class vertexcomp : IEqualityComparer<Vertex> | 60 | private class vertexcomp : IEqualityComparer<Vertex> |
55 | { | 61 | { |
@@ -77,6 +83,14 @@ namespace OpenSim.Region.Physics.Meshing | |||
77 | m_triangles = new List<Triangle>(); | 83 | m_triangles = new List<Triangle>(); |
78 | m_centroid = Vector3.Zero; | 84 | m_centroid = Vector3.Zero; |
79 | m_centroidDiv = 0; | 85 | m_centroidDiv = 0; |
86 | m_obbXmin = float.MaxValue; | ||
87 | m_obbXmax = float.MinValue; | ||
88 | m_obbYmin = float.MaxValue; | ||
89 | m_obbYmax = float.MinValue; | ||
90 | m_obbZmin = float.MaxValue; | ||
91 | m_obbZmax = float.MinValue; | ||
92 | |||
93 | |||
80 | } | 94 | } |
81 | 95 | ||
82 | public int RefCount { get; set; } | 96 | public int RefCount { get; set; } |
@@ -102,6 +116,35 @@ namespace OpenSim.Region.Physics.Meshing | |||
102 | return result; | 116 | return result; |
103 | } | 117 | } |
104 | 118 | ||
119 | public void addVertexLStats(Vertex v) | ||
120 | { | ||
121 | float x = v.X; | ||
122 | float y = v.Y; | ||
123 | float z = v.Z; | ||
124 | |||
125 | m_centroid.X += x; | ||
126 | m_centroid.Y += y; | ||
127 | m_centroid.Z += z; | ||
128 | m_centroidDiv++; | ||
129 | |||
130 | if (x > m_obbXmax) | ||
131 | m_obbXmax = x; | ||
132 | else if (x < m_obbXmin) | ||
133 | m_obbXmin = x; | ||
134 | |||
135 | if (y > m_obbYmax) | ||
136 | m_obbYmax = y; | ||
137 | else if (y < m_obbYmin) | ||
138 | m_obbYmin = y; | ||
139 | |||
140 | if (z > m_obbZmax) | ||
141 | m_obbZmax = z; | ||
142 | else if (z < m_obbZmin) | ||
143 | m_obbZmin = z; | ||
144 | |||
145 | } | ||
146 | |||
147 | |||
105 | public void Add(Triangle triangle) | 148 | public void Add(Triangle triangle) |
106 | { | 149 | { |
107 | if (m_pinnedIndex.IsAllocated || m_pinnedVertexes.IsAllocated || m_indicesPtr != IntPtr.Zero || m_verticesPtr != IntPtr.Zero) | 150 | if (m_pinnedIndex.IsAllocated || m_pinnedVertexes.IsAllocated || m_indicesPtr != IntPtr.Zero || m_verticesPtr != IntPtr.Zero) |
@@ -127,26 +170,17 @@ namespace OpenSim.Region.Physics.Meshing | |||
127 | if (!m_vertices.ContainsKey(triangle.v1)) | 170 | if (!m_vertices.ContainsKey(triangle.v1)) |
128 | { | 171 | { |
129 | m_vertices[triangle.v1] = m_vertices.Count; | 172 | m_vertices[triangle.v1] = m_vertices.Count; |
130 | m_centroid.X += triangle.v1.X; | 173 | addVertexLStats(triangle.v1); |
131 | m_centroid.Y += triangle.v1.Y; | ||
132 | m_centroid.Z += triangle.v1.Z; | ||
133 | m_centroidDiv++; | ||
134 | } | 174 | } |
135 | if (!m_vertices.ContainsKey(triangle.v2)) | 175 | if (!m_vertices.ContainsKey(triangle.v2)) |
136 | { | 176 | { |
137 | m_vertices[triangle.v2] = m_vertices.Count; | 177 | m_vertices[triangle.v2] = m_vertices.Count; |
138 | m_centroid.X += triangle.v2.X; | 178 | addVertexLStats(triangle.v2); |
139 | m_centroid.Y += triangle.v2.Y; | ||
140 | m_centroid.Z += triangle.v2.Z; | ||
141 | m_centroidDiv++; | ||
142 | } | 179 | } |
143 | if (!m_vertices.ContainsKey(triangle.v3)) | 180 | if (!m_vertices.ContainsKey(triangle.v3)) |
144 | { | 181 | { |
145 | m_vertices[triangle.v3] = m_vertices.Count; | 182 | m_vertices[triangle.v3] = m_vertices.Count; |
146 | m_centroid.X += triangle.v3.X; | 183 | addVertexLStats(triangle.v3); |
147 | m_centroid.Y += triangle.v3.Y; | ||
148 | m_centroid.Z += triangle.v3.Z; | ||
149 | m_centroidDiv++; | ||
150 | } | 184 | } |
151 | m_triangles.Add(triangle); | 185 | m_triangles.Add(triangle); |
152 | } | 186 | } |
@@ -159,6 +193,24 @@ namespace OpenSim.Region.Physics.Meshing | |||
159 | return Vector3.Zero; | 193 | return Vector3.Zero; |
160 | } | 194 | } |
161 | 195 | ||
196 | public Vector3 GetOBB() | ||
197 | { | ||
198 | float x, y, z; | ||
199 | if (m_centroidDiv > 0) | ||
200 | { | ||
201 | x = (m_obbXmax - m_obbXmin) * 0.5f; | ||
202 | y = (m_obbYmax - m_obbYmin) * 0.5f; | ||
203 | z = (m_obbZmax - m_obbZmin) * 0.5f; | ||
204 | } | ||
205 | else // ?? | ||
206 | { | ||
207 | x = 0.5f; | ||
208 | y = 0.5f; | ||
209 | z = 0.5f; | ||
210 | } | ||
211 | return new Vector3(x, y, z); | ||
212 | } | ||
213 | |||
162 | public void CalcNormals() | 214 | public void CalcNormals() |
163 | { | 215 | { |
164 | int iTriangles = m_triangles.Count; | 216 | int iTriangles = m_triangles.Count; |
diff --git a/OpenSim/Region/Physics/UbitMeshing/Meshmerizer.cs b/OpenSim/Region/Physics/UbitMeshing/Meshmerizer.cs index 4c40175..44c8972 100644 --- a/OpenSim/Region/Physics/UbitMeshing/Meshmerizer.cs +++ b/OpenSim/Region/Physics/UbitMeshing/Meshmerizer.cs | |||
@@ -1061,6 +1061,42 @@ namespace OpenSim.Region.Physics.Meshing | |||
1061 | 1061 | ||
1062 | private static Vector3 m_MeshUnitSize = new Vector3(0.5f, 0.5f, 0.5f); | 1062 | private static Vector3 m_MeshUnitSize = new Vector3(0.5f, 0.5f, 0.5f); |
1063 | 1063 | ||
1064 | public IMesh GetMesh(String primName, PrimitiveBaseShape primShape, Vector3 size, float lod, bool isPhysical, bool convex) | ||
1065 | { | ||
1066 | Mesh mesh = null; | ||
1067 | |||
1068 | if (size.X < 0.01f) size.X = 0.01f; | ||
1069 | if (size.Y < 0.01f) size.Y = 0.01f; | ||
1070 | if (size.Z < 0.01f) size.Z = 0.01f; | ||
1071 | |||
1072 | AMeshKey key = GetMeshUniqueKey(primShape, size, (byte)lod, convex); | ||
1073 | lock (m_uniqueMeshes) | ||
1074 | { | ||
1075 | m_uniqueMeshes.TryGetValue(key, out mesh); | ||
1076 | |||
1077 | if (mesh != null) | ||
1078 | { | ||
1079 | mesh.RefCount++; | ||
1080 | return mesh; | ||
1081 | } | ||
1082 | } | ||
1083 | |||
1084 | // try to find a identical mesh on meshs recently released | ||
1085 | lock (m_uniqueReleasedMeshes) | ||
1086 | { | ||
1087 | m_uniqueReleasedMeshes.TryGetValue(key, out mesh); | ||
1088 | if (mesh != null) | ||
1089 | { | ||
1090 | m_uniqueReleasedMeshes.Remove(key); | ||
1091 | lock (m_uniqueMeshes) | ||
1092 | m_uniqueMeshes.Add(key, mesh); | ||
1093 | mesh.RefCount = 1; | ||
1094 | return mesh; | ||
1095 | } | ||
1096 | } | ||
1097 | return null; | ||
1098 | } | ||
1099 | |||
1064 | public IMesh CreateMesh(String primName, PrimitiveBaseShape primShape, Vector3 size, float lod, bool isPhysical, bool convex) | 1100 | public IMesh CreateMesh(String primName, PrimitiveBaseShape primShape, Vector3 size, float lod, bool isPhysical, bool convex) |
1065 | { | 1101 | { |
1066 | #if SPAM | 1102 | #if SPAM |
@@ -1068,15 +1104,13 @@ namespace OpenSim.Region.Physics.Meshing | |||
1068 | #endif | 1104 | #endif |
1069 | 1105 | ||
1070 | Mesh mesh = null; | 1106 | Mesh mesh = null; |
1071 | // ulong key = 0; | ||
1072 | |||
1073 | 1107 | ||
1074 | if (size.X < 0.01f) size.X = 0.01f; | 1108 | if (size.X < 0.01f) size.X = 0.01f; |
1075 | if (size.Y < 0.01f) size.Y = 0.01f; | 1109 | if (size.Y < 0.01f) size.Y = 0.01f; |
1076 | if (size.Z < 0.01f) size.Z = 0.01f; | 1110 | if (size.Z < 0.01f) size.Z = 0.01f; |
1077 | 1111 | ||
1078 | // try to find a identical mesh on meshs in use | 1112 | // try to find a identical mesh on meshs in use |
1079 | // key = primShape.GetMeshKey(size, lod, convex); | 1113 | |
1080 | AMeshKey key = GetMeshUniqueKey(primShape,size,(byte)lod, convex); | 1114 | AMeshKey key = GetMeshUniqueKey(primShape,size,(byte)lod, convex); |
1081 | 1115 | ||
1082 | lock (m_uniqueMeshes) | 1116 | lock (m_uniqueMeshes) |