// Converts an OBJMesh (assumed to be a tri-mesh) to a bullet-friendly structure public static BulletOBJMesh BulletMeshFromUnity(OBJLoader.OBJMesh mesh) { BulletOBJMesh btmesh = new BulletOBJMesh(); btmesh.vertices = new float[mesh.vertices.Count * 3]; for (int i = 0; i < mesh.vertices.Count; i++) { UnityEngine.Vector3 curVert = mesh.vertices[i]; btmesh.vertices[i * 3 + 0] = curVert[0]; btmesh.vertices[i * 3 + 1] = curVert[1]; btmesh.vertices[i * 3 + 2] = curVert[2]; } List <int> indList = new List <int>(); for (int i = 0; i < mesh.faces.Count; i++) { int[] faceIndices = mesh.faces[i].indexes; for (int j = 0; j < faceIndices.Length; j++) { int idx = faceIndices[j]; indList.Add(faceIndices[j]); } } btmesh.indices = indList.ToArray(); return(btmesh); }
public BulletOBJMesh Scale(float x, float y, float z) { BulletOBJMesh scaledMesh = new BulletOBJMesh(); scaledMesh.vertices = new float[vertices.Length]; scaledMesh.indices = new int[indices.Length]; vertices.CopyTo(scaledMesh.vertices, 0); indices.CopyTo(scaledMesh.indices, 0); for (int i = 0; i < (int)scaledMesh.vertices.Length / 3; i++) { scaledMesh.vertices[i * 3 + 0] *= x; scaledMesh.vertices[i * 3 + 1] *= y; scaledMesh.vertices[i * 3 + 2] *= z; } return(scaledMesh); }