aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/PhysicsModules/ConvexDecompositionDotNet/HullUtils.cs
diff options
context:
space:
mode:
authoronefang2019-09-11 16:36:50 +1000
committeronefang2019-09-11 16:36:50 +1000
commit50cd1ffd32f69228e566f2b0b89f86ea0d9fe489 (patch)
tree52f2ab0c04f1a5d7d6ac5dc872981b4b156447e7 /OpenSim/Region/PhysicsModules/ConvexDecompositionDotNet/HullUtils.cs
parentRenamed branch to SledjChisl. (diff)
parentBump to release flavour, build 0. (diff)
downloadopensim-SC_OLD-50cd1ffd32f69228e566f2b0b89f86ea0d9fe489.zip
opensim-SC_OLD-50cd1ffd32f69228e566f2b0b89f86ea0d9fe489.tar.gz
opensim-SC_OLD-50cd1ffd32f69228e566f2b0b89f86ea0d9fe489.tar.bz2
opensim-SC_OLD-50cd1ffd32f69228e566f2b0b89f86ea0d9fe489.tar.xz
Merge branch 'SledjChisl'
Diffstat (limited to 'OpenSim/Region/PhysicsModules/ConvexDecompositionDotNet/HullUtils.cs')
-rw-r--r--OpenSim/Region/PhysicsModules/ConvexDecompositionDotNet/HullUtils.cs79
1 files changed, 53 insertions, 26 deletions
diff --git a/OpenSim/Region/PhysicsModules/ConvexDecompositionDotNet/HullUtils.cs b/OpenSim/Region/PhysicsModules/ConvexDecompositionDotNet/HullUtils.cs
index 3903254..cf7161a 100644
--- a/OpenSim/Region/PhysicsModules/ConvexDecompositionDotNet/HullUtils.cs
+++ b/OpenSim/Region/PhysicsModules/ConvexDecompositionDotNet/HullUtils.cs
@@ -1,21 +1,21 @@
1/* The MIT License 1/* The MIT License
2 * 2 *
3 * Copyright (c) 2010 Intel Corporation. 3 * Copyright (c) 2010 Intel Corporation.
4 * All rights reserved. 4 * All rights reserved.
5 * 5 *
6 * Based on the convexdecomposition library from 6 * Based on the convexdecomposition library from
7 * <http://codesuppository.googlecode.com> by John W. Ratcliff and Stan Melax. 7 * <http://codesuppository.googlecode.com> by John W. Ratcliff and Stan Melax.
8 * 8 *
9 * Permission is hereby granted, free of charge, to any person obtaining a copy 9 * Permission is hereby granted, free of charge, to any person obtaining a copy
10 * of this software and associated documentation files (the "Software"), to deal 10 * of this software and associated documentation files (the "Software"), to deal
11 * in the Software without restriction, including without limitation the rights 11 * in the Software without restriction, including without limitation the rights
12 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 * copies of the Software, and to permit persons to whom the Software is 13 * copies of the Software, and to permit persons to whom the Software is
14 * furnished to do so, subject to the following conditions: 14 * furnished to do so, subject to the following conditions:
15 * 15 *
16 * The above copyright notice and this permission notice shall be included in 16 * The above copyright notice and this permission notice shall be included in
17 * all copies or substantial portions of the Software. 17 * all copies or substantial portions of the Software.
18 * 18 *
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
@@ -29,7 +29,7 @@ using System;
29using System.Collections.Generic; 29using System.Collections.Generic;
30using System.Diagnostics; 30using System.Diagnostics;
31 31
32namespace OpenSim.Region.PhysicsModule.ConvexDecompositionDotNet 32namespace OpenSim.Region.PhysicsModules.ConvexDecompositionDotNet
33{ 33{
34 public static class HullUtils 34 public static class HullUtils
35 { 35 {
@@ -763,7 +763,7 @@ namespace OpenSim.Region.PhysicsModule.ConvexDecompositionDotNet
763 } 763 }
764 else if ((vertflag[edge0.v].planetest | vertflag[edge1.v].planetest) == (0)) 764 else if ((vertflag[edge0.v].planetest | vertflag[edge1.v].planetest) == (0))
765 { 765 {
766 // both endpoints coplanar 766 // both endpoints coplanar
767 // must check a 3rd point to see if UNDER 767 // must check a 3rd point to see if UNDER
768 int e2 = e1 + 1; 768 int e2 = e1 + 1;
769 if (e2 >= convex.edges.Count || convex.edges[e2].p != currentplane) 769 if (e2 >= convex.edges.Count || convex.edges[e2].p != currentplane)
@@ -792,7 +792,7 @@ namespace OpenSim.Region.PhysicsModule.ConvexDecompositionDotNet
792 } 792 }
793 else if (vertflag[edge0.v].planetest == (1) && vertflag[edge1.v].planetest == (2)) 793 else if (vertflag[edge0.v].planetest == (1) && vertflag[edge1.v].planetest == (2))
794 { 794 {
795 // first is under 2nd is over 795 // first is under 2nd is over
796 796
797 edgeflag[e0].undermap = (short)under_edge_count; 797 edgeflag[e0].undermap = (short)under_edge_count;
798 tmpunderedges[under_edge_count].v = vertflag[edge0.v].undermap; 798 tmpunderedges[under_edge_count].v = vertflag[edge0.v].undermap;
@@ -815,7 +815,7 @@ namespace OpenSim.Region.PhysicsModule.ConvexDecompositionDotNet
815 vout = vertcountunder++; 815 vout = vertcountunder++;
816 } 816 }
817 under_edge_count++; 817 under_edge_count++;
818 /// hmmm something to think about: i might be able to output this edge regarless of 818 /// hmmm something to think about: i might be able to output this edge regarless of
819 // wheter or not we know v-in yet. ok i;ll try this now: 819 // wheter or not we know v-in yet. ok i;ll try this now:
820 tmpunderedges[under_edge_count].v = (byte)vout; 820 tmpunderedges[under_edge_count].v = (byte)vout;
821 tmpunderedges[under_edge_count].p = (byte)underplanescount; 821 tmpunderedges[under_edge_count].p = (byte)underplanescount;
@@ -834,7 +834,7 @@ namespace OpenSim.Region.PhysicsModule.ConvexDecompositionDotNet
834 } 834 }
835 else if (vertflag[edge0.v].planetest == (0) && vertflag[edge1.v].planetest == (2)) 835 else if (vertflag[edge0.v].planetest == (0) && vertflag[edge1.v].planetest == (2))
836 { 836 {
837 // first is coplanar 2nd is over 837 // first is coplanar 2nd is over
838 838
839 edgeflag[e0].undermap = -1; 839 edgeflag[e0].undermap = -1;
840 vout = vertflag[edge0.v].undermap; 840 vout = vertflag[edge0.v].undermap;
@@ -858,7 +858,7 @@ namespace OpenSim.Region.PhysicsModule.ConvexDecompositionDotNet
858 } 858 }
859 else if (vertflag[edge0.v].planetest == (2) && vertflag[edge1.v].planetest == (1)) 859 else if (vertflag[edge0.v].planetest == (2) && vertflag[edge1.v].planetest == (1))
860 { 860 {
861 // first is over next is under 861 // first is over next is under
862 // new vertex!!! 862 // new vertex!!!
863 Debug.Assert(vin == -1); 863 Debug.Assert(vin == -1);
864 if (e0 < edge0.ea) 864 if (e0 < edge0.ea)
@@ -901,7 +901,7 @@ namespace OpenSim.Region.PhysicsModule.ConvexDecompositionDotNet
901 } 901 }
902 else if (vertflag[edge0.v].planetest == (2) && vertflag[edge1.v].planetest == (0)) 902 else if (vertflag[edge0.v].planetest == (2) && vertflag[edge1.v].planetest == (0))
903 { 903 {
904 // first is over next is coplanar 904 // first is over next is coplanar
905 905
906 edgeflag[e0].undermap = -1; 906 edgeflag[e0].undermap = -1;
907 vin = vertflag[edge1.v].undermap; 907 vin = vertflag[edge1.v].undermap;
@@ -1074,14 +1074,27 @@ namespace OpenSim.Region.PhysicsModule.ConvexDecompositionDotNet
1074 public static int maxdirfiltered(List<float3> p, int count, float3 dir, byte[] allow) 1074 public static int maxdirfiltered(List<float3> p, int count, float3 dir, byte[] allow)
1075 { 1075 {
1076 //Debug.Assert(count != 0); 1076 //Debug.Assert(count != 0);
1077 int m = 0; 1077 int m = -1;
1078 float currDotm = float3.dot(p[0], dir); 1078 float currDotm = 0;
1079 float currDoti; 1079 float currDoti;
1080 1080
1081 while (allow[m] == 0) 1081 for (int i = 0; i < count; i++)
1082 m++; 1082 {
1083 if (allow[i] != 0)
1084 {
1085 currDotm = float3.dot(p[i], dir);
1086 m = i;
1087 break;
1088 }
1089 }
1083 1090
1084 for (int i = 1; i < count; i++) 1091 if(m == -1)
1092 {
1093 Debug.Assert(false);
1094 return m;
1095 }
1096
1097 for (int i = m + 1; i < count; i++)
1085 { 1098 {
1086 if (allow[i] != 0) 1099 if (allow[i] != 0)
1087 { 1100 {
@@ -1093,7 +1106,8 @@ namespace OpenSim.Region.PhysicsModule.ConvexDecompositionDotNet
1093 } 1106 }
1094 } 1107 }
1095 } 1108 }
1096 //Debug.Assert(m != -1); 1109
1110// Debug.Assert(m != -1);
1097 return m; 1111 return m;
1098 } 1112 }
1099 1113
@@ -1112,8 +1126,8 @@ namespace OpenSim.Region.PhysicsModule.ConvexDecompositionDotNet
1112 { 1126 {
1113 int mb; 1127 int mb;
1114 { 1128 {
1115 float s = (float)Math.Sin((3.14159264f / 180.0f) * (x)); 1129 float s = (float)Math.Sin(0.01745329f * x);
1116 float c = (float)Math.Cos((3.14159264f / 180.0f) * (x)); 1130 float c = (float)Math.Cos(0.01745329f * x);
1117 mb = maxdirfiltered(p, count, dir + (u * s + v * c) * 0.025f, allow); 1131 mb = maxdirfiltered(p, count, dir + (u * s + v * c) * 0.025f, allow);
1118 } 1132 }
1119 if (ma == m && mb == m) 1133 if (ma == m && mb == m)
@@ -1126,8 +1140,8 @@ namespace OpenSim.Region.PhysicsModule.ConvexDecompositionDotNet
1126 int mc = ma; 1140 int mc = ma;
1127 for (float xx = x - 40.0f; xx <= x; xx += 5.0f) 1141 for (float xx = x - 40.0f; xx <= x; xx += 5.0f)
1128 { 1142 {
1129 float s = (float)Math.Sin((3.14159264f / 180.0f) * (xx)); 1143 float s = (float)Math.Sin(0.01745329f * xx);
1130 float c = (float)Math.Cos((3.14159264f / 180.0f) * (xx)); 1144 float c = (float)Math.Cos(0.01745329f * xx);
1131 int md = maxdirfiltered(p, count, dir + (u * s + v * c) * 0.025f, allow); 1145 int md = maxdirfiltered(p, count, dir + (u * s + v * c) * 0.025f, allow);
1132 if (mc == m && md == m) 1146 if (mc == m && md == m)
1133 { 1147 {
@@ -1176,7 +1190,7 @@ namespace OpenSim.Region.PhysicsModule.ConvexDecompositionDotNet
1176 Debug.Assert(!(p0 == p1 || p0 == p2 || p0 == p3 || p1 == p2 || p1 == p3 || p2 == p3)); 1190 Debug.Assert(!(p0 == p1 || p0 == p2 || p0 == p3 || p1 == p2 || p1 == p3 || p2 == p3));
1177 if (float3.dot(verts[p3] - verts[p0], float3.cross(verts[p1] - verts[p0], verts[p2] - verts[p0])) < 0) 1191 if (float3.dot(verts[p3] - verts[p0], float3.cross(verts[p1] - verts[p0], verts[p2] - verts[p0])) < 0)
1178 { 1192 {
1179 Swap(ref p2, ref p3); 1193 return new int4(p0, p1, p3, p2);
1180 } 1194 }
1181 return new int4(p0, p1, p2, p3); 1195 return new int4(p0, p1, p2, p3);
1182 } 1196 }
@@ -1207,12 +1221,12 @@ namespace OpenSim.Region.PhysicsModule.ConvexDecompositionDotNet
1207 int j; 1221 int j;
1208 float3 bmin = new float3(verts[0]); 1222 float3 bmin = new float3(verts[0]);
1209 float3 bmax = new float3(verts[0]); 1223 float3 bmax = new float3(verts[0]);
1210 List<int> isextreme = new List<int>(verts.Count); 1224 byte[] isextreme = new byte[verts.Count];
1211 byte[] allow = new byte[verts.Count]; 1225 byte[] allow = new byte[verts.Count];
1212 for (j = 0; j < verts.Count; j++) 1226 for (j = 0; j < verts.Count; j++)
1213 { 1227 {
1214 allow[j] = 1; 1228 allow[j] = 1;
1215 isextreme.Add(0); 1229 isextreme[j] = 0;
1216 bmin = float3.VectorMin(bmin, verts[j]); 1230 bmin = float3.VectorMin(bmin, verts[j]);
1217 bmax = float3.VectorMax(bmax, verts[j]); 1231 bmax = float3.VectorMax(bmax, verts[j]);
1218 } 1232 }
@@ -1526,6 +1540,19 @@ namespace OpenSim.Region.PhysicsModule.ConvexDecompositionDotNet
1526 } 1540 }
1527 } 1541 }
1528 1542
1543 public static bool ComputeHull(List<float3> vertices, out List<int> indices)
1544 {
1545 List<HullTriangle> tris = new List<HullTriangle>();
1546
1547 bool ret = calchull(vertices, out indices, 0, tris);
1548 if (ret == false)
1549 {
1550 indices = new List<int>();
1551 return false;
1552 }
1553 return true;
1554 }
1555
1529 private static bool CleanupVertices(List<float3> svertices, out List<float3> vertices, float normalepsilon, out float3 scale) 1556 private static bool CleanupVertices(List<float3> svertices, out List<float3> vertices, float normalepsilon, out float3 scale)
1530 { 1557 {
1531 const float EPSILON = 0.000001f; 1558 const float EPSILON = 0.000001f;
@@ -1609,7 +1636,7 @@ namespace OpenSim.Region.PhysicsModule.ConvexDecompositionDotNet
1609 addPoint(ref vcount, vertices, x2, y2, z2); 1636 addPoint(ref vcount, vertices, x2, y2, z2);
1610 addPoint(ref vcount, vertices, x1, y2, z2); 1637 addPoint(ref vcount, vertices, x1, y2, z2);
1611 1638
1612 return true; // return cube 1639 return true; // return cube
1613 } 1640 }
1614 else 1641 else
1615 { 1642 {