public static void DrawGeometry(HkGeometry geometry, MatrixD worldMatrix, Color color, bool depthRead = false, bool shaded = false) { var msg = MyRenderProxy.PrepareDebugDrawTriangles(); try { for (int i = 0; i < geometry.TriangleCount; i++) { int a, b, c, m; geometry.GetTriangle(i, out a, out b, out c, out m); msg.AddIndex(a); msg.AddIndex(b); msg.AddIndex(c); } for (int i = 0; i < geometry.VertexCount; i++) { msg.AddVertex(geometry.GetVertex(i)); } } finally { MyRenderProxy.DebugDrawTriangles(msg, worldMatrix, color, depthRead, shaded); } }
public static void DrawGeometry(HkGeometry geometry, MatrixD worldMatrix, Color color, bool depthRead = false, bool shaded = false) { MyRenderMessageDebugDrawTriangles msgInterface = MyRenderProxy.PrepareDebugDrawTriangles(); try { int triangleIndex = 0; while (true) { int num2; int num3; int num4; int num5; if (triangleIndex >= geometry.TriangleCount) { for (int i = 0; i < geometry.VertexCount; i++) { msgInterface.AddVertex(geometry.GetVertex(i)); } break; } geometry.GetTriangle(triangleIndex, out num2, out num3, out num4, out num5); msgInterface.AddIndex(num2); msgInterface.AddIndex(num3); msgInterface.AddIndex(num4); triangleIndex++; } } finally { msgInterface.Color = color; MyRenderProxy.DebugDrawTriangles(msgInterface, new MatrixD?(worldMatrix), depthRead, shaded, false, false); } }
public void DrawGeometry(HkGeometry geometry, MatrixD worldMatrix, Color color, bool depthRead = false, bool shaded = false) { MyRenderMessageDebugDrawTriangles triangles = MyRenderProxy.PrepareDebugDrawTriangles(); for (int i = 0; i < geometry.TriangleCount; i++) { int num2; int num3; int num4; int num5; geometry.GetTriangle(i, out num2, out num3, out num4, out num5); triangles.AddIndex(num2); triangles.AddIndex(num3); triangles.AddIndex(num4); } for (int j = 0; j < geometry.VertexCount; j++) { triangles.AddVertex(geometry.GetVertex(j)); } }
private void AddPhysicalShape(HkShape shape, Matrix rdWorldMatrix) { switch (shape.ShapeType) { case Havok.HkShapeType.Box: Havok.HkBoxShape box = (HkBoxShape)shape; Vector3D vMin = new Vector3D(-box.HalfExtents.X, -box.HalfExtents.Y, -box.HalfExtents.Z); Vector3D vMax = new Vector3D(box.HalfExtents.X, box.HalfExtents.Y, box.HalfExtents.Z); BoundingBoxD boundingBox = new BoundingBoxD(vMin, vMax); BoundingBoxToTranslatedTriangles(boundingBox, rdWorldMatrix); break; case Havok.HkShapeType.List: var listShape = (HkListShape)shape; var iterator = listShape.GetIterator(); while (iterator.IsValid) { AddPhysicalShape(iterator.CurrentValue, rdWorldMatrix); iterator.Next(); } break; case HkShapeType.Mopp: var compoundShape = (HkMoppBvTreeShape)shape; AddPhysicalShape(compoundShape.ShapeCollection, rdWorldMatrix); break; case HkShapeType.ConvexTransform: var transformShape = (HkConvexTransformShape)shape; AddPhysicalShape(transformShape.ChildShape, transformShape.Transform * rdWorldMatrix); break; case HkShapeType.ConvexTranslate: var translateShape = (HkConvexTranslateShape)shape; var mat = Matrix.CreateTranslation(translateShape.Translation); AddPhysicalShape((HkShape)translateShape.ChildShape, mat * rdWorldMatrix); break; case HkShapeType.Sphere: var sphereShape = (HkSphereShape)shape; m_icosphereMesh.AddTrianglesToWorldVertices(rdWorldMatrix.Translation, sphereShape.Radius); break; case HkShapeType.Capsule: return; ProfilerShort.Begin("Capsule"); var capsuleShape = (HkCapsuleShape)shape; Line line = new Line(capsuleShape.VertexA, capsuleShape.VertexB); m_capsuleMesh.AddTrianglesToWorldVertices(rdWorldMatrix, capsuleShape.Radius, line); ProfilerShort.End(); break; case HkShapeType.ConvexVertices: var convexShape = (HkConvexVerticesShape)shape; HkGeometry geometry = new HkGeometry(); Vector3 center; convexShape.GetGeometry(geometry, out center); for (int i = 0; i < geometry.TriangleCount; i++) { int i0, i1, i2, materialIndex; geometry.GetTriangle(i, out i0, out i1, out i2, out materialIndex); m_worldVertices.Triangles.Add(m_worldVertices.VerticesMaxValue + i0); m_worldVertices.Triangles.Add(m_worldVertices.VerticesMaxValue + i1); m_worldVertices.Triangles.Add(m_worldVertices.VerticesMaxValue + i2); } for (int i = 0; i < geometry.VertexCount; i++) { Vector3 vec = geometry.GetVertex(i); Vector3.Transform(ref vec, ref rdWorldMatrix, out vec); m_worldVertices.Vertices.Add(vec); } m_worldVertices.VerticesMaxValue += geometry.VertexCount; break; default: // For breakpoint. Don't judge me :( break; } }
private unsafe void AddPhysicalShape(HkShape shape, Matrix rdWorldMatrix) { switch (shape.ShapeType) { case HkShapeType.Sphere: { HkSphereShape shape7 = (HkSphereShape)shape; m_icosphereMesh.AddTrianglesToWorldVertices(rdWorldMatrix.Translation, shape7.Radius); return; } case HkShapeType.Cylinder: case HkShapeType.Triangle: case HkShapeType.TriSampledHeightFieldCollection: case HkShapeType.TriSampledHeightFieldBvTree: break; case HkShapeType.Box: { HkBoxShape shape2 = (HkBoxShape)shape; Vector3D min = new Vector3D((double)-shape2.HalfExtents.X, (double)-shape2.HalfExtents.Y, (double)-shape2.HalfExtents.Z); Vector3D max = new Vector3D((double)shape2.HalfExtents.X, (double)shape2.HalfExtents.Y, (double)shape2.HalfExtents.Z); BoundingBoxD bbox = new BoundingBoxD(min, max); this.BoundingBoxToTranslatedTriangles(bbox, rdWorldMatrix); return; } case HkShapeType.Capsule: return; case HkShapeType.ConvexVertices: { Vector3 vector; HkConvexVerticesShape shape9 = (HkConvexVerticesShape)shape; HkGeometry geometry = new HkGeometry(); shape9.GetGeometry(geometry, out vector); int triangleIndex = 0; while (true) { int num2; int num3; int num4; int num5; if (triangleIndex >= geometry.TriangleCount) { int vertexIndex = 0; while (true) { if (vertexIndex >= geometry.VertexCount) { WorldVerticesInfo worldVertices = m_worldVertices; worldVertices.VerticesMaxValue += geometry.VertexCount; break; } Vector3 vertex = geometry.GetVertex(vertexIndex); Vector3 *vectorPtr1 = (Vector3 *)ref vertex; Vector3.Transform(ref (Vector3) ref vectorPtr1, ref rdWorldMatrix, out vertex); m_worldVertices.Vertices.Add(vertex); vertexIndex++; } break; } geometry.GetTriangle(triangleIndex, out num2, out num3, out num4, out num5); m_worldVertices.Triangles.Add(m_worldVertices.VerticesMaxValue + num2); m_worldVertices.Triangles.Add(m_worldVertices.VerticesMaxValue + num3); m_worldVertices.Triangles.Add(m_worldVertices.VerticesMaxValue + num4); triangleIndex++; } break; } case HkShapeType.List: { HkShapeContainerIterator iterator = ((HkListShape)shape).GetIterator(); while (iterator.IsValid) { this.AddPhysicalShape(iterator.CurrentValue, rdWorldMatrix); iterator.Next(); } return; } case HkShapeType.Mopp: { HkMoppBvTreeShape shape4 = (HkMoppBvTreeShape)shape; this.AddPhysicalShape((HkShape)shape4.ShapeCollection, rdWorldMatrix); return; } case HkShapeType.ConvexTranslate: { HkConvexTranslateShape shape6 = (HkConvexTranslateShape)shape; Matrix matrix = Matrix.CreateTranslation(shape6.Translation); this.AddPhysicalShape((HkShape)shape6.ChildShape, matrix * rdWorldMatrix); return; } case HkShapeType.ConvexTransform: { HkConvexTransformShape shape5 = (HkConvexTransformShape)shape; this.AddPhysicalShape((HkShape)shape5.ChildShape, shape5.Transform * rdWorldMatrix); return; } default: return; } }
/* public Vector3D? GetNextPathPoint(Vector3D initialPosition, Vector3D targetPosition) { List<Vector3D> path = GetPathPoints(initialPosition, targetPosition); for(int i = 0; i < path.Count-1 ; i++) { var worldPoint = path[i];// LocalPositionToWorldPosition(path[i]); var nextWorldPoint = path[i + 1]; //LocalPositionToWorldPosition(path[i+1]); MyRenderProxy.DebugDrawLine3D(worldPoint, nextWorldPoint, Color.Red, Color.Red, true); MyRenderProxy.DebugDrawSphere(nextWorldPoint, 0.3f, Color.Yellow, 1f, true); } // First point is initialPosition if (path.Count >= 2) return path[1]; //LocalPositionToWorldPosition(path[1]); else return null; } */ #region DebugDraw public void DrawGeometry(HkGeometry geometry, MatrixD worldMatrix, Color color, bool depthRead = false, bool shaded = false) { var msg = MyRenderProxy.PrepareDebugDrawTriangles(); try { ProfilerShort.Begin("MyExternalPathfinfing.GetGeometryTriangles"); for (int i = 0; i < geometry.TriangleCount; i++) { int a, b, c, m; geometry.GetTriangle(i, out a, out b, out c, out m); msg.AddIndex(a); msg.AddIndex(b); msg.AddIndex(c); } for (int i = 0; i < geometry.VertexCount; i++) msg.AddVertex(geometry.GetVertex(i)); ProfilerShort.End(); } finally { MyRenderProxy.DebugDrawTriangles(msg, worldMatrix, color, depthRead, shaded); } }