29 using System.Collections.Generic;
31 namespace OpenSim.
Region.PhysicsModules.ConvexDecompositionDotNet
47 private const int WSCALE = 4;
82 mPlaneD = mNormal.ComputePlane(mP1, mP2, mP3);
87 return float3.dot(mNormal, t.mNormal);
93 bool hit = lineIntersectsTriangle(start, end, mP1, mP2, mP3, ref sect);
102 n.NearestPointInTriangle(p, mP1, mP2, mP3);
103 distance = p.Distance(n);
107 public void addTri(
int[] indices,
int i1,
int i2,
int i3, ref
int tcount)
109 indices[tcount * 3 + 0] = i1;
110 indices[tcount * 3 + 1] = i2;
111 indices[tcount * 3 + 2] = i3;
117 int[] indices =
new int[8 * 3];
121 addTri(indices, 0, 1, 2, ref tcount);
122 addTri(indices, 3, 4, 5, ref tcount);
124 addTri(indices, 0, 3, 4, ref tcount);
125 addTri(indices, 0, 4, 1, ref tcount);
127 addTri(indices, 1, 4, 5, ref tcount);
128 addTri(indices, 1, 5, 2, ref tcount);
130 addTri(indices, 0, 3, 5, ref tcount);
131 addTri(indices, 0, 5, 2, ref tcount);
133 List<float3> vertices =
new List<float3> { mP1, mP2, mP3, mNear1, mNear2, mNear3 };
134 List<int> indexList =
new List<int>(indices);
136 float v = Concavity.computeMeshVolume(vertices, indexList);
149 float3 dest = p + dir * 100000f;
151 intersect(p, dest, ref sect, plane);
153 return sect.Distance(p);
165 return DistToPt(p, plane);
170 const float THRESH = 0.001f;
171 float dd = Math.Abs(t.mPlaneD - mPlaneD);
174 dd = Math.Abs(t.mNormal.x - mNormal.x);
177 dd = Math.Abs(t.mNormal.y - mNormal.y);
180 dd = Math.Abs(t.mNormal.z - mNormal.z);
188 if (i == mI1 || i == mI2 || i == mI3)
213 float a = mConcavity * mP1.Area(mP2, mP3);
253 float d = x*plane.x + y*plane.y + z*plane.z + plane.w;
257 private static void intersect(float3 p1, float3 p2, ref float3 split, float4 plane)
259 float dp1 = DistToPt(p1, plane);
261 float3 dir =
new float3();
262 dir.x = p2[0] - p1[0];
263 dir.y = p2[1] - p1[1];
264 dir.z = p2[2] - p1[2];
266 float dot1 = dir[0] * plane[0] + dir[1] * plane[1] + dir[2] * plane[2];
267 float dot2 = dp1 - plane[3];
269 float t = -(plane[3] + dot2) / dot1;
271 split.x = (dir[0] * t) + p1[0];
272 split.y = (dir[1] * t) + p1[1];
273 split.z = (dir[2] * t) + p1[2];
276 private static bool rayIntersectsTriangle(float3 p, float3 d, float3 v0, float3 v1, float3 v2, out
float t)
280 float3 e1, e2, h, s, q;
285 h = float3.cross(d, e2);
286 a = float3.dot(e1, h);
288 if (a > -0.00001f && a < 0.00001f)
293 u = f * float3.dot(s, h);
295 if (u < 0.0f || u > 1.0f)
298 q = float3.cross(s, e1);
299 v = f * float3.dot(d, q);
300 if (v < 0.0f || u + v > 1.0f)
305 t = f * float3.dot(e2, q);
312 private static bool lineIntersectsTriangle(float3 rayStart, float3 rayEnd, float3 p1, float3 p2, float3 p3, ref float3 sect)
314 float3 dir = rayEnd - rayStart;
316 float d = (float)Math.Sqrt(dir[0] * dir[0] + dir[1] * dir[1] + dir[2] * dir[2]);
322 bool ret = rayIntersectsTriangle(rayStart, dir, p1, p2, p3, out t);
328 sect.x = rayStart.x + dir.x * t;
329 sect.y = rayStart.y + dir.y * t;
330 sect.z = rayStart.z + dir.z * t;
CTri(float3 p1, float3 p2, float3 p3, int i1, int i2, int i3)
bool clip(float3 start, ref float3 end)
float raySect(float3 p, float3 dir, ref float3 sect)
float planeDistance(float3 p)
void addWeighted(List< Wpoint > list)
Wpoint(float3 p, float w)
bool Concave(float3 p, ref float distance, ref float3 n)
void addTri(int[] indices, int i1, int i2, int i3, ref int tcount)