private CompoundShape CreateCompoundShape(Hacd hacd, Vector3 localScaling) { var wavefrontWriter = new WavefrontWriter("file_convex.obj"); var convexDecomposition = new ConvexDecomposition(wavefrontWriter) { LocalScaling = localScaling }; for (int c = 0; c < hacd.NClusters; c++) { int trianglesLen = hacd.GetNTrianglesCH(c) * 3; if (trianglesLen == 0) { continue; } var triangles = new long[trianglesLen]; int nVertices = hacd.GetNPointsCH(c); var points = new double[nVertices * 3]; hacd.GetCH(c, points, triangles); var verticesArray = new Vector3[nVertices]; int vi3 = 0; for (int vi = 0; vi < nVertices; vi++) { verticesArray[vi] = new Vector3( (float)points[vi3], (float)points[vi3 + 1], (float)points[vi3 + 2]); vi3 += 3; } convexDecomposition.Result(verticesArray, triangles); } wavefrontWriter.Dispose(); // Combine convex shapes into a compound shape var compoundShape = new CompoundShape(); for (int i = 0; i < convexDecomposition.ConvexShapes.Count; i++) { Vector3 centroid = convexDecomposition.ConvexCentroids[i]; var convexShape = convexDecomposition.ConvexShapes[i]; Matrix trans = Matrix.Translation(centroid); if (_enableSat) { convexShape.InitializePolyhedralFeatures(); } compoundShape.AddChildShape(trans, convexShape); PhysicsHelper.CreateBody(1.0f, trans, convexShape, World); } return(compoundShape); }
private CompoundShape CreateCompoundShape(Hacd hacd, Vector3 localScaling) { var wavefrontWriter = new WavefrontWriter("file_convex.obj"); var convexDecomposition = new ConvexDecomposition(wavefrontWriter) { LocalScaling = localScaling }; for (int c = 0; c < hacd.NClusters; c++) { int trianglesLen = hacd.GetNTrianglesCH(c) * 3; if (trianglesLen == 0) { continue; } Vector3[] points; int[] triangles; hacd.GetCH(c, out points, out triangles); convexDecomposition.Result(points, triangles); } wavefrontWriter.Dispose(); // Combine convex shapes into a compound shape var compoundShape = new CompoundShape(); for (int i = 0; i < convexDecomposition.ConvexShapes.Count; i++) { Vector3 centroid = convexDecomposition.ConvexCentroids[i]; var convexShape = convexDecomposition.ConvexShapes[i]; Matrix trans = Matrix.Translation(centroid); if (_enableSat) { convexShape.InitializePolyhedralFeatures(); } compoundShape.AddChildShape(trans, convexShape); LocalCreateRigidBody(1.0f, trans, convexShape); } return(compoundShape); }