public void CookConvexMesh() { string teapotXml; using (var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("PhysX.Test.Resources.Teapot.DAE")) { var streamReader = new StreamReader(stream); teapotXml = streamReader.ReadToEnd(); } using (var physics = CreatePhysicsAndScene()) { var colladaLoader = new ColladaLoader(); // Read the vertices and indices from the Teapot.DAE collada file // This file is copied out to the TestResults folder using the DeploymentItem attribute on this class var teapot = colladaLoader.Load(teapotXml); using (var cooking = physics.Physics.CreateCooking()) { var desc = new ConvexMeshDesc(); desc.SetTriangles(teapot.Indices); desc.SetPositions(teapot.Vertices); desc.Flags = ConvexFlag.ComputeConvex; var stream = new MemoryStream(); var result = cooking.CookConvexMesh(desc, stream); Assert.IsFalse(physics.ErrorOutput.HasErrors, physics.ErrorOutput.LastError); Assert.AreEqual(ConvexMeshCookingResult.Success, result); } } }
public PxGhRigidStaticCMesh(Plane plane, List <Mesh> meshes, Material material) { ghMeshes = new List <GH_Mesh>(); List <Mesh> initialMeshes = new List <Mesh>(meshes); actor = PhysXManager.Physics.CreateRigidStatic(); foreach (Mesh initialMesh in initialMeshes) { Mesh meshLocal = initialMesh.DuplicateMesh(); meshLocal.Transform(Transform.PlaneToPlane(plane, Plane.WorldXY)); List <Vector3> points = new List <Vector3>(); foreach (Point3d v in meshLocal.Vertices) { points.Add(new Vector3((float)v.X, (float)v.Y, (float)v.Z)); } List <int> faceVertexIndices = new List <int>(); foreach (MeshFace face in meshLocal.Faces) { faceVertexIndices.Add(face.A); faceVertexIndices.Add(face.B); faceVertexIndices.Add(face.C); } ConvexMeshDesc convexMeshDescription = new ConvexMeshDesc(); convexMeshDescription.Flags = ConvexFlag.ComputeConvex; convexMeshDescription.SetPositions(points.ToArray()); convexMeshDescription.SetTriangles(faceVertexIndices.ToArray()); MemoryStream memoryStream = new MemoryStream(); PhysXManager.Physics.CreateCooking().CookConvexMesh(convexMeshDescription, memoryStream); memoryStream.Position = 0; ConvexMesh convexMesh = PhysXManager.Physics.CreateConvexMesh(memoryStream); ConvexMeshGeometry convexMeshGeometry = new ConvexMeshGeometry(convexMesh); actor.CreateShape(convexMeshGeometry, material); ghMeshes.Add(new GH_Mesh(meshLocal)); } actor.GlobalPose = plane.ToMatrix(); }
public PxGhRigidDynamiCompoundConvexMesh(List <Mesh> meshes, Plane frame, Material material, float mass, Vector3d initialLinearVelocity, Vector3d initialAngularVelocity) : base(frame, initialLinearVelocity, initialAngularVelocity) { DisplayMeshes = new List <Mesh>(meshes); foreach (Mesh mesh in DisplayMeshes) { mesh.Transform(Transform.PlaneToPlane(frame, Plane.WorldXY)); Vector3[] vertices = new Vector3[mesh.Vertices.Count]; for (int i = 0; i < vertices.Length; i++) { vertices[i] = mesh.Vertices[i].ToSystemVector(); } int[] faceVertexIndices = new int[mesh.Faces.Count * 3]; for (int i = 0; i < mesh.Faces.Count; i++) { MeshFace face = mesh.Faces[i]; faceVertexIndices[3 * i + 0] = face.A; faceVertexIndices[3 * i + 1] = face.B; faceVertexIndices[3 * i + 2] = face.C; } ConvexMeshDesc convexMeshDescription = new ConvexMeshDesc(); convexMeshDescription.Flags = ConvexFlag.ComputeConvex; convexMeshDescription.SetPositions(vertices); convexMeshDescription.SetTriangles(faceVertexIndices); MemoryStream memoryStream = new MemoryStream(); PxGhManager.Physics.CreateCooking().CookConvexMesh(convexMeshDescription, memoryStream); memoryStream.Position = 0; ConvexMesh convexMesh = PxGhManager.Physics.CreateConvexMesh(memoryStream); ConvexMeshGeometry convexMeshGeometry = new ConvexMeshGeometry(convexMesh); Actor.CreateShape(convexMeshGeometry, material); } Actor.SetMassAndUpdateInertia(mass); }
private void CreateConvexMesh(Scene scene, Material material) { var colladaLoader = new ColladaLoader(); var bunny = colladaLoader.Load(@"Teapot.DAE", this.Engine.GraphicsDevice); var convexMeshDesc = new ConvexMeshDesc { Flags = ConvexFlag.ComputeConvex }; convexMeshDesc.SetPositions(bunny.VertexPositions); convexMeshDesc.SetTriangles(bunny.Indices); var cooking = scene.Physics.CreateCooking(); var stream = new MemoryStream(); var cookResult = cooking.CookConvexMesh(convexMeshDesc, stream); stream.Position = 0; var convexMesh = scene.Physics.CreateConvexMesh(stream); var convexMeshGeom = new ConvexMeshGeometry(convexMesh) { Scale = new MeshScale(new Vector3(0.3f, 0.3f, 0.3f), Quaternion.Identity) }; var rigidActor = scene.Physics.CreateRigidDynamic(); // TODO: The Shape created here is now also an owner of the ConvexMesh object, // this needs to be incorp into the ObjectTable ownership logic rigidActor.CreateShape(convexMeshGeom, material); rigidActor.GlobalPose = Matrix4x4.CreateRotationX(-(float)System.Math.PI / 2) * Matrix4x4.CreateTranslation(0, 80, 0); scene.AddActor(rigidActor); }
public void CookConvexMesh() { using (var physics = CreatePhysicsAndScene()) { var vertices = Cuboid.CubeVertices(); var indices = Cuboid.CubeIndices(); var cooking = physics.Physics.CreateCooking(); var desc = new ConvexMeshDesc(); desc.SetTriangles(indices); desc.SetPositions(vertices); desc.Flags = ConvexFlag.Indices16Bit | ConvexFlag.ComputeConvex; var stream = new MemoryStream(); bool result = cooking.CookConvexMesh(desc, stream); Assert.IsFalse(physics.ErrorOutput.HasErrors, physics.ErrorOutput.LastError); Assert.IsTrue(result); } }
public PxGhRigidStaticCompoundConvexMesh(Plane frame, List <Mesh> meshes, Material material) { DisplayMeshes = new List <Mesh>(meshes); Actor.GlobalPose = frame.ToMatrix(); foreach (Mesh mesh in DisplayMeshes) { mesh.Transform(Transform.PlaneToPlane(frame, Plane.WorldXY)); Vector3[] vertices = new Vector3[mesh.Vertices.Count]; for (int i = 0; i < vertices.Length; i++) { vertices[i] = mesh.Vertices[i].ToSystemVector(); } int[] faceVertexIndices = new int[mesh.Faces.Count * 3]; for (int i = 0; i < mesh.Faces.Count; i++) { MeshFace face = mesh.Faces[i]; faceVertexIndices[3 * i + 0] = face.A; faceVertexIndices[3 * i + 1] = face.B; faceVertexIndices[3 * i + 2] = face.C; } ConvexMeshDesc convexMeshDescription = new ConvexMeshDesc(); convexMeshDescription.Flags = ConvexFlag.ComputeConvex; convexMeshDescription.SetPositions(vertices); convexMeshDescription.SetTriangles(faceVertexIndices); MemoryStream memoryStream = new MemoryStream(); PxGhManager.Physics.CreateCooking().CookConvexMesh(convexMeshDescription, memoryStream); memoryStream.Position = 0; ConvexMeshGeometry convexMeshGeometry = new ConvexMeshGeometry(PxGhManager.Physics.CreateConvexMesh(memoryStream)); Actor.CreateShape(convexMeshGeometry, material); } }
private void CreateConvexMesh(Scene scene, Material material) { var colladaLoader = new ColladaLoader(); var bunny = colladaLoader.Load(@"Teapot.DAE", this.Engine.GraphicsDevice); var convexMeshDesc = new ConvexMeshDesc() { Flags = ConvexFlag.ComputeConvex }; convexMeshDesc.SetPositions(bunny.VertexPositions); convexMeshDesc.SetTriangles(bunny.Indices); var cooking = scene.Physics.CreateCooking(); var stream = new MemoryStream(); var cookResult = cooking.CookConvexMesh(convexMeshDesc, stream); stream.Position = 0; var convexMesh = scene.Physics.CreateConvexMesh(stream); var convexMeshGeom = new ConvexMeshGeometry(convexMesh) { Scale = new MeshScale(new Vector3(0.3f, 0.3f, 0.3f), Quaternion.Identity) }; var rigidActor = scene.Physics.CreateRigidDynamic(); // TODO: The Shape created here is now also an owner of the ConvexMesh object, // this needs to be incorp into the ObjectTable ownership logic rigidActor.CreateShape(convexMeshGeom, material); rigidActor.GlobalPose = Matrix.RotationX(-(float)System.Math.PI / 2) * Matrix.Translation(0, 80, 0); scene.AddActor(rigidActor); }