Beispiel #1
0
        /// <summary>
        /// Creates a Soft body from a .bxda file [NOT YET PROPERLY IMPLEMENTED?]
        /// </summary>
        /// <param name="filePath"></param>
        /// <param name="worldInfo"></param>
        public void CreateSoftBody(string filePath, SoftBodyWorldInfo worldInfo)
        {
            BXDAMesh mesh = new BXDAMesh();

            mesh.ReadFromFile(filePath);
            List <Vector3> verts = new List <Vector3>();

            //Soft body construction
            verts = mesh.AllColliderVertices().ToList();

            SoftBody temp = SoftBodyHelpers.CreateFromConvexHull(worldInfo, verts.ToArray());
            //BulletObject = temp;
        }
Beispiel #2
0
        /// <summary>
        /// Turns a BXDA mesh into a CompoundShape centered around the origin
        /// </summary>
        /// <param name="mesh"></param>
        /// <returns></returns>
        private static CompoundShape GetShape(BXDAMesh mesh)
        {
            CompoundShape shape = new CompoundShape();

            Vector3[] meshVertices = mesh.AllColliderVertices().ToArray();

            for (int i = 0; i < mesh.colliders.Count; i++)
            {
                BXDAMesh.BXDASubMesh  sub      = mesh.colliders[i];
                Vector3[]             vertices = sub.GetVertexData();
                StridingMeshInterface sMesh    = MeshUtilities.CenteredBulletShapeFromSubMesh(sub);

                //Add the shape at a location relative to the compound shape such that the compound shape is centered at (0, 0) but child shapes are properly placed
                shape.AddChildShape(Matrix4.CreateTranslation(MeshUtilities.MeshCenterRelative(sub, mesh)), new ConvexTriangleMeshShape(sMesh));
                Console.WriteLine("Successfully created and added sub shape");
            }

            return(shape);
        }
Beispiel #3
0
        /// <summary>
        /// Gets the center of a mesh's vertices
        /// </summary>
        /// <param name="mesh"></param>
        /// <returns></returns>
        public static Vector3 MeshCenter(BXDAMesh mesh)
        {
            IEnumerable <Vector3> verts = mesh.AllColliderVertices();

            return(verts.Aggregate(Vector3.Add) / verts.Count());
        }
Beispiel #4
0
 /// <summary>
 /// Gets the center of a sub mesh relative to the entire BXDA mesh
 /// </summary>
 /// <param name="subMesh"></param>
 /// <param name="vertices"></param>
 /// <returns></returns>
 public static Vector3 MeshCenterRelative(BXDAMesh.BXDASubMesh subMesh, BXDAMesh mesh)
 {
     return(MeshCenter(subMesh) - MeshCenter(mesh.AllColliderVertices()));
 }