/// <summary> /// Crear Collider a partir de TgcMesh. /// Los triangulos se calculan CounterClock-Wise. /// Crea el BoundingSphere del Collider. /// </summary> /// <param name="mesh">TgcMesh</param> /// <returns>Collider creado</returns> public static TriangleMeshCollider fromMesh(TgcMesh mesh) { TriangleMeshCollider collider = new TriangleMeshCollider(); //Cargar triangulos Vector3[] vertices = mesh.getVertexPositions(); int triangleCount = vertices.Length / 3; collider.triangles = new Triangle[triangleCount]; for (int i = 0; i < triangleCount; i++) { //Invertir orden de vertices para que la normal quede CounterClock-Wise collider.triangles[i] = new Triangle( vertices[i * 3 + 2], vertices[i * 3 + 1], vertices[i * 3] ); } //Crear BoundingSphere collider.BoundingSphere = TgcBoundingSphere.computeFromMesh(mesh); return collider; }
/// <summary> /// Crear Collider a partir de TgcMesh. /// Los triangulos se calculan CounterClock-Wise. /// Crea el BoundingSphere del Collider. /// </summary> /// <param name="mesh">TgcMesh</param> /// <returns>Collider creado</returns> public static TriangleMeshCollider fromMesh(TgcMesh mesh) { TriangleMeshCollider collider = new TriangleMeshCollider(); //Cargar triangulos Vector3[] vertices = mesh.getVertexPositions(); int triangleCount = vertices.Length / 3; collider.triangles = new Triangle[triangleCount]; for (int i = 0; i < triangleCount; i++) { //Invertir orden de vertices para que la normal quede CounterClock-Wise collider.triangles[i] = new Triangle( vertices[i * 3 + 2], vertices[i * 3 + 1], vertices[i * 3] ); } //Crear BoundingSphere collider.BoundingSphere = TgcBoundingSphere.computeFromMesh(mesh); return(collider); }