public PhysxTriangleMesh(PhysxPhysicWorld PhysxPhysicWorld, IModelo model,Microsoft.Xna.Framework.Matrix localTransformation, Microsoft.Xna.Framework.Matrix worldTransformation, Microsoft.Xna.Framework.Vector3 scale, MaterialDescription MaterialDescription) { Microsoft.Xna.Framework.Vector3[] vertices = null; int[] indices = null; ExtractData(ref vertices, ref indices, model); TriangleMeshDesc meshDesc = new TriangleMeshDesc(); Vector3[] points = new Vector3[vertices.Count()]; for (int i = 0; i < vertices.Count(); i++) { points[i] = vertices[i].AsPhysX(); } meshDesc.Points = points; meshDesc.SetTriangles<int>(indices); //meshDesc.Triangles = indices; MemoryStream ms = new MemoryStream(); if(PhysxPhysicWorld.Cooking.CookTriangleMesh(meshDesc,ms)==false) { PloobsEngine.Engine.Logger.ActiveLogger.LogMessage("Cant Cook Model",Engine.Logger.LogLevel.FatalError); } ms.Position = 0; TriangleMesh triangleMesh = PhysxPhysicWorld.Physix.CreateTriangleMesh(ms); staticActor = PhysxPhysicWorld.Physix.CreateRigidStatic(worldTransformation.AsPhysX()); TriangleMeshGeometry TriangleMeshGeometry = new TriangleMeshGeometry(triangleMesh,new MeshScale(scale.AsPhysX(),Quaternion.Identity)); material = PhysxPhysicWorld.Physix.CreateMaterial(MaterialDescription.StaticFriction, MaterialDescription.DynamicFriction, MaterialDescription.Bounciness); aTriMeshShape = staticActor.CreateShape(TriangleMeshGeometry, material, localTransformation.AsPhysX()); this.Scale = scale; }
public void CreateTriangleMeshShape() { var physics = CreatePhysicsAndScene(); var material = physics.Physics.CreateMaterial(0.5f, 0.5f, 0.1f); var actor = physics.Physics.CreateRigidDynamic(); var grid = new ClothTestGrid(10, 10); var triangleMeshDesc = new TriangleMeshDesc(); triangleMeshDesc.Points = grid.Points; triangleMeshDesc.SetTriangles(grid.Indices); var cooking = physics.Physics.CreateCooking(); var cookedStream = new MemoryStream(); bool result = cooking.CookTriangleMesh(triangleMeshDesc, cookedStream); Assert.IsTrue(result); cookedStream.Position = 0; var triangleMesh = physics.Physics.CreateTriangleMesh(cookedStream); var triangleMeshGeometry = new TriangleMeshGeometry(triangleMesh); var shape = actor.CreateShape(triangleMeshGeometry, material); physics.Scene.AddActor(actor); }
public void GetTriangleMeshGeometry() { var material = _physics.Physics.CreateMaterial(0.5f, 0.5f, 0.1f); var actor = _physics.Physics.CreateRigidDynamic(); // Triangle mesh can only be created on a kinematic actor actor.RigidBodyFlags = RigidBodyFlag.Kinematic; var grid = new ClothTestGrid(10, 10); var triangleMeshDesc = new TriangleMeshDesc(); triangleMeshDesc.Points = grid.Points; triangleMeshDesc.SetTriangles(grid.Indices); MemoryStream cookedStream; using (var cooking = _physics.Physics.CreateCooking()) { cookedStream = new MemoryStream(); var result = cooking.CookTriangleMesh(triangleMeshDesc, cookedStream); Assert.AreEqual(TriangleMeshCookingResult.Success, result); cookedStream.Position = 0; } var triangleMesh = _physics.Physics.CreateTriangleMesh(cookedStream); var triangleMeshGeometry = new TriangleMeshGeometry(triangleMesh); var shape = actor.CreateShape(triangleMeshGeometry, material); // var retrievedTriangleMeshGeom = shape.GetTriangleMeshGeometry(); Assert.IsNotNull(retrievedTriangleMeshGeom); Assert.AreEqual(triangleMesh, retrievedTriangleMeshGeom.TriangleMesh); Assert.AreEqual(GeometryType.TriangleMesh, retrievedTriangleMeshGeom.Type); Assert.AreEqual(new MeshScale(new Vector3(1), Quaternion.Identity), retrievedTriangleMeshGeom.Scale); Assert.AreEqual((MeshGeometryFlag)0, retrievedTriangleMeshGeom.MeshFlags); }
public static void CookTriangleMesh(PhysxPhysicWorld PhysxPhysicWorld, IModelo model, FileStream FileStream) { Microsoft.Xna.Framework.Vector3[] vertices = null; int[] indices = null; ExtractData(ref vertices, ref indices, model); TriangleMeshDesc meshDesc = new TriangleMeshDesc(); Vector3[] points = new Vector3[vertices.Count()]; for (int i = 0; i < vertices.Count(); i++) { points[i] = vertices[i].AsPhysX(); } meshDesc.Points = points; meshDesc.SetTriangles <int>(indices); if (PhysxPhysicWorld.Cooking.CookTriangleMesh(meshDesc, FileStream) == false) { PloobsEngine.Engine.Logger.ActiveLogger.LogMessage("Cant Cook Model", Engine.Logger.LogLevel.FatalError); } }
public static void CookTriangleMesh(PhysxPhysicWorld PhysxPhysicWorld, IModelo model, FileStream FileStream) { Microsoft.Xna.Framework.Vector3[] vertices = null; int[] indices = null; ExtractData(ref vertices, ref indices, model); TriangleMeshDesc meshDesc = new TriangleMeshDesc(); Vector3[] points = new Vector3[vertices.Count()]; for (int i = 0; i < vertices.Count(); i++) { points[i] = vertices[i].AsPhysX(); } meshDesc.Points = points; meshDesc.SetTriangles<int>(indices); if (PhysxPhysicWorld.Cooking.CookTriangleMesh(meshDesc, FileStream) == false) { PloobsEngine.Engine.Logger.ActiveLogger.LogMessage("Cant Cook Model", Engine.Logger.LogLevel.FatalError); } }
public void CreateTriangleMeshShape() { using (var physics = CreatePhysicsAndScene()) { var material = physics.Physics.CreateMaterial(0.5f, 0.5f, 0.1f); var actor = physics.Physics.CreateRigidDynamic(); // Triangle mesh can only be created on a kinematic actor actor.RigidBodyFlags = RigidBodyFlag.Kinematic; var grid = new TestGrid(10, 10); var triangleMeshDesc = new TriangleMeshDesc(); triangleMeshDesc.Points = grid.Points; triangleMeshDesc.SetTriangles(grid.Indices); using (var cooking = physics.Physics.CreateCooking()) { var cookedStream = new MemoryStream(); var result = cooking.CookTriangleMesh(triangleMeshDesc, cookedStream); Assert.AreEqual(TriangleMeshCookingResult.Success, result); cookedStream.Position = 0; var triangleMesh = physics.Physics.CreateTriangleMesh(cookedStream); var triangleMeshGeometry = new TriangleMeshGeometry(triangleMesh); var shape = actor.CreateShape(triangleMeshGeometry, material); physics.Scene.AddActor(actor); } } }
public PhysxTriangleMesh(PhysxPhysicWorld PhysxPhysicWorld, IModelo model, Microsoft.Xna.Framework.Matrix localTransformation, Microsoft.Xna.Framework.Matrix worldTransformation, Microsoft.Xna.Framework.Vector3 scale, MaterialDescription MaterialDescription) { Microsoft.Xna.Framework.Vector3[] vertices = null; int[] indices = null; ExtractData(ref vertices, ref indices, model); TriangleMeshDesc meshDesc = new TriangleMeshDesc(); Vector3[] points = new Vector3[vertices.Count()]; for (int i = 0; i < vertices.Count(); i++) { points[i] = vertices[i].AsPhysX(); } meshDesc.Points = points; meshDesc.SetTriangles <int>(indices); //meshDesc.Triangles = indices; MemoryStream ms = new MemoryStream(); if (PhysxPhysicWorld.Cooking.CookTriangleMesh(meshDesc, ms) == false) { PloobsEngine.Engine.Logger.ActiveLogger.LogMessage("Cant Cook Model", Engine.Logger.LogLevel.FatalError); } ms.Position = 0; TriangleMesh triangleMesh = PhysxPhysicWorld.Physix.CreateTriangleMesh(ms); staticActor = PhysxPhysicWorld.Physix.CreateRigidStatic(worldTransformation.AsPhysX()); TriangleMeshGeometry TriangleMeshGeometry = new TriangleMeshGeometry(triangleMesh, new MeshScale(scale.AsPhysX(), Quaternion.Identity)); material = PhysxPhysicWorld.Physix.CreateMaterial(MaterialDescription.StaticFriction, MaterialDescription.DynamicFriction, MaterialDescription.Bounciness); aTriMeshShape = staticActor.CreateShape(TriangleMeshGeometry, material, localTransformation.AsPhysX()); this.Scale = scale; }
public void GetTriangleMeshGeometry() { var material = _physics.Physics.CreateMaterial(0.5f, 0.5f, 0.1f); var actor = _physics.Physics.CreateRigidDynamic(); // Triangle mesh can only be created on a kinematic actor actor.Flags = RigidDynamicFlags.Kinematic; var grid = new ClothTestGrid(10, 10); var triangleMeshDesc = new TriangleMeshDesc(); triangleMeshDesc.Points = grid.Points; triangleMeshDesc.SetTriangles(grid.Indices); MemoryStream cookedStream; using (var cooking = _physics.Physics.CreateCooking()) { cookedStream = new MemoryStream(); bool result = cooking.CookTriangleMesh(triangleMeshDesc, cookedStream); Assert.IsTrue(result); cookedStream.Position = 0; } var triangleMesh = _physics.Physics.CreateTriangleMesh(cookedStream); var triangleMeshGeometry = new TriangleMeshGeometry(triangleMesh); var shape = actor.CreateShape(triangleMeshGeometry, material); // var retrievedTriangleMeshGeom = shape.GetTriangleMeshGeometry(); Assert.IsNotNull(retrievedTriangleMeshGeom); Assert.AreEqual(triangleMesh, retrievedTriangleMeshGeom.TriangleMesh); Assert.AreEqual(GeometryType.TriangleMesh, retrievedTriangleMeshGeom.Type); Assert.AreEqual(new MeshScale(new Vector3(1), Quaternion.Identity), retrievedTriangleMeshGeom.Scale); Assert.AreEqual((MeshGeometryFlag)0, retrievedTriangleMeshGeom.MeshFlags); }