public ClothModel(GraphicFactory factory, PhysxPhysicWorld PhysxPhysicWorld, ClothMeshDescription clothMeshDesc, String ModelName,XNA.Vector3 scale, String diffuseTextureName = null) : base(factory, ModelName, false) { this._diffuseName = diffuseTextureName; Model model = factory.GetModel(ModelName); SimpleModel SimpleModel = new Modelo.SimpleModel(factory, ModelName,null,null,null,null,false); Vector3[] verts = null; Vector2[] tex = null; int[] inds = null; ExtractData(ref verts, ref inds, ref tex, SimpleModel,scale); SimpleModel.CleanUp(factory); VerticesNum = verts.Length; IndicesNum = inds.Length; clothMeshDesc.AllocateVertices<Vector3>(VerticesNum); clothMeshDesc.AllocateTriangles<int>(IndicesNum / 3); clothMeshDesc.VertexCount = VerticesNum; clothMeshDesc.TriangleCount = IndicesNum / 3; BatchInformation = new PloobsEngine.Modelo.BatchInformation(0, VerticesNum, IndicesNum / 3, 0, 0, VertexPositionNormalTexture.VertexDeclaration, VertexPositionNormalTexture.VertexDeclaration.VertexStride, PrimitiveType.TriangleList); BatchInformation.ModelLocalTransformation = XNA.Matrix.Identity; vertexPositionNormalTexture = new VertexPositionNormalTexture[VerticesNum]; BatchInformation.VertexBuffer = factory.CreateDynamicVertexBuffer(VertexPositionNormalTexture.VertexDeclaration, VerticesNum + (int)(1.2 * VerticesNum), BufferUsage.WriteOnly); BatchInformation.IndexBuffer = factory.CreateDynamicIndexBuffer(IndexElementSize.ThirtyTwoBits, IndicesNum + (int)(1.2 * IndicesNum), BufferUsage.WriteOnly); BatchInformation.IndexBuffer.SetData<int>(inds); clothMeshDesc.VerticesStream.SetData(verts); clothMeshDesc.TriangleStream.SetData(inds); XNA.Vector3[] pts = new XNA.Vector3[BatchInformation.NumVertices]; for (int i = 0; i < BatchInformation.NumVertices; i++) { vertexPositionNormalTexture[i].TextureCoordinate = tex[i].AsXNA(); vertexPositionNormalTexture[i].Position = verts[i].AsXNA(); pts[i] = vertexPositionNormalTexture[i].Position; } modelRadius = Microsoft.Xna.Framework.BoundingSphere.CreateFromPoints(pts).Radius; pts = null; // We are using 32 bit integers for our indices, so make sure the 16 bit flag is removed. // 32 bits are the default, so this isn't technically needed, but it's good to show in a sample clothMeshDesc.Flags &= ~MeshFlag.Indices16Bit; //clothMeshDesc.Flags |= (MeshFlag)((int)clothMeshDesc.Flags | (int)ClothMeshFlag.Tearable); // Write the cooked data to memory using (var memoryStream = new MemoryStream()) { Cooking.InitializeCooking(); Cooking.CookClothMesh(clothMeshDesc, memoryStream); Cooking.CloseCooking(); // Need to reset the position of the stream to the beginning memoryStream.Position = 0; ClothMesh = PhysxPhysicWorld.Core.CreateClothMesh(memoryStream); } LoadModel(factory, out BatchInformations, out TextureInformations); }
public ClothModel(GraphicFactory factory, PhysxPhysicWorld PhysxPhysicWorld, ClothMeshDescription clothMeshDesc, String ModelName, XNA.Vector3 scale, String diffuseTextureName = null) : base(factory, ModelName, false) { this._diffuseName = diffuseTextureName; Model model = factory.GetModel(ModelName); SimpleModel SimpleModel = new Modelo.SimpleModel(factory, ModelName, null, null, null, null, false); Vector3[] verts = null; Vector2[] tex = null; int[] inds = null; ExtractData(ref verts, ref inds, ref tex, SimpleModel, scale); SimpleModel.CleanUp(factory); VerticesNum = verts.Length; IndicesNum = inds.Length; clothMeshDesc.AllocateVertices <Vector3>(VerticesNum); clothMeshDesc.AllocateTriangles <int>(IndicesNum / 3); clothMeshDesc.VertexCount = VerticesNum; clothMeshDesc.TriangleCount = IndicesNum / 3; BatchInformation = new PloobsEngine.Modelo.BatchInformation(0, VerticesNum, IndicesNum / 3, 0, 0, VertexPositionNormalTexture.VertexDeclaration, VertexPositionNormalTexture.VertexDeclaration.VertexStride, PrimitiveType.TriangleList); BatchInformation.ModelLocalTransformation = XNA.Matrix.Identity; vertexPositionNormalTexture = new VertexPositionNormalTexture[VerticesNum]; BatchInformation.VertexBuffer = factory.CreateDynamicVertexBuffer(VertexPositionNormalTexture.VertexDeclaration, VerticesNum + (int)(1.2 * VerticesNum), BufferUsage.WriteOnly); BatchInformation.IndexBuffer = factory.CreateDynamicIndexBuffer(IndexElementSize.ThirtyTwoBits, IndicesNum + (int)(1.2 * IndicesNum), BufferUsage.WriteOnly); BatchInformation.IndexBuffer.SetData <int>(inds); clothMeshDesc.VerticesStream.SetData(verts); clothMeshDesc.TriangleStream.SetData(inds); XNA.Vector3[] pts = new XNA.Vector3[BatchInformation.NumVertices]; for (int i = 0; i < BatchInformation.NumVertices; i++) { vertexPositionNormalTexture[i].TextureCoordinate = tex[i].AsXNA(); vertexPositionNormalTexture[i].Position = verts[i].AsXNA(); pts[i] = vertexPositionNormalTexture[i].Position; } modelRadius = Microsoft.Xna.Framework.BoundingSphere.CreateFromPoints(pts).Radius; pts = null; // We are using 32 bit integers for our indices, so make sure the 16 bit flag is removed. // 32 bits are the default, so this isn't technically needed, but it's good to show in a sample clothMeshDesc.Flags &= ~MeshFlag.Indices16Bit; //clothMeshDesc.Flags |= (MeshFlag)((int)clothMeshDesc.Flags | (int)ClothMeshFlag.Tearable); // Write the cooked data to memory using (var memoryStream = new MemoryStream()) { Cooking.InitializeCooking(); Cooking.CookClothMesh(clothMeshDesc, memoryStream); Cooking.CloseCooking(); // Need to reset the position of the stream to the beginning memoryStream.Position = 0; ClothMesh = PhysxPhysicWorld.Core.CreateClothMesh(memoryStream); } LoadModel(factory, out BatchInformations, out TextureInformations); }