29 using System.Collections.Generic;
32 namespace OpenSim.Region.PhysicsModules.ConvexDecompositionDotNet
34 public static class Concavity
38 public static float computeConcavity(List<float3> vertices, List<int> indices, ref
float4 plane, ref
float volume)
47 desc.MaxVertices = 256;
48 desc.SetHullFlag(HullFlag.QF_TRIANGLES);
49 desc.Vertices = vertices;
51 HullError ret = HullUtils.CreateConvexHull(desc, ref result);
59 List<CTri> tris =
new List<CTri>();
61 for (
int i = 0; i < result.Indices.Count / 3; i++)
63 int i1 = result.Indices[i * 3 + 0];
64 int i2 = result.Indices[i * 3 + 1];
65 int i3 = result.Indices[i * 3 + 2];
67 float3 p1 = result.OutputVertices[i1];
68 float3 p2 = result.OutputVertices[i2];
69 float3 p3 = result.OutputVertices[i3];
71 CTri t =
new CTri(p1, p2, p3, i1, i2, i3);
76 float totalVolume = 0;
78 List<CTri> ftris =
new List<CTri>();
79 List<CTri> input_mesh =
new List<CTri>();
81 for (
int i = 0; i < indices.Count / 3; i++)
83 int i1 = indices[i * 3 + 0];
84 int i2 = indices[i * 3 + 1];
85 int i3 = indices[i * 3 + 2];
91 CTri t =
new CTri(p1, p2, p3, i1, i2, i3);
95 for (
int i = 0; i < indices.Count / 3; i++)
97 int i1 = indices[i * 3 + 0];
98 int i2 = indices[i * 3 + 1];
99 int i3 = indices[i * 3 + 2];
105 CTri t =
new CTri(p1, p2, p3, i1, i2, i3);
107 featureMatch(t, tris, input_mesh);
111 float v = t.getVolume();
117 SplitPlane.computeSplitPlane(vertices, indices, ref plane);
124 public static bool featureMatch(
CTri m, List<CTri> tris, List<CTri> input_mesh)
127 float neardot = 0.707f;
130 for (
int i = 0; i < tris.Count; i++)
140 float dot = float3.dot(t.mNormal, m.mNormal);
144 float d1 = t.planeDistance(m.mP1);
145 float d2 = t.planeDistance(m.mP2);
146 float d3 = t.planeDistance(m.mP3);
148 if (d1 > 0.001f || d2 > 0.001f || d3 > 0.001f)
152 t.raySect(m.mP1, m.mNormal, ref m.mNear1);
153 t.raySect(m.mP2, m.mNormal, ref m.mNear2);
154 t.raySect(m.mP3, m.mNormal, ref m.mNear3);
163 m.mC1 = m.mP1.Distance(m.mNear1);
164 m.mC2 = m.mP2.Distance(m.mNear2);
165 m.mC3 = m.mP3.Distance(m.mNear3);
167 m.mConcavity = m.mC1;
170 m.mConcavity = m.mC2;
172 m.mConcavity = m.mC3;
180 return p1.x * p2.y * p3.z + p2.x * p3.y * p1.z + p3.x * p1.y * p2.z - p1.x * p3.y * p2.z - p2.x * p1.y * p3.z - p3.x * p2.y * p1.z;
183 public static float computeMeshVolume(List<float3> vertices, List<int> indices)
187 for (
int i = 0; i < indices.Count / 3; i++)
189 float3 p1 = vertices[indices[i * 3 + 0]];
190 float3 p2 = vertices[indices[i * 3 + 1]];
191 float3 p3 = vertices[indices[i * 3 + 2]];
193 volume += det(p1, p2, p3);
196 volume *= (1.0f / 6.0f);
202 public static float computeMeshVolume2(List<float3> vertices, List<int> indices)
207 for (
int i = 0; i < indices.Count / 3; i++)
209 float3 p1 = vertices[indices[i * 3 + 0]];
210 float3 p2 = vertices[indices[i * 3 + 1]];
211 float3 p3 = vertices[indices[i * 3 + 2]];
213 volume += tetVolume(p0, p1, p2, p3);
216 return volume * (1.0f / 6.0f);
225 float3 cross = float3.cross(b, c);
226 float volume = float3.dot(a, cross);
List< float3 > OutputVertices
Interactive OpenSim region server