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;
        }
Esempio n. 2
0
		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);
		}
Esempio n. 3
0
        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 PhysxTriangleMesh(PhysxPhysicWorld PhysxPhysicWorld, FileStream FileStream, Microsoft.Xna.Framework.Matrix localTransformation, Microsoft.Xna.Framework.Matrix worldTransformation, Microsoft.Xna.Framework.Vector3 scale, MaterialDescription MaterialDescription)
        {
            TriangleMesh triangleMesh = PhysxPhysicWorld.Physix.CreateTriangleMesh(FileStream);

            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;
        }
Esempio n. 5
0
        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);
        }
Esempio n. 6
0
        private void CreateTriangleMesh(Scene scene, Material material)
        {
            var colladaLoader = new ColladaLoader();
            var bunny         = colladaLoader.Load(@"Teapot.DAE", this.Engine.GraphicsDevice);

            var triangleMeshDesc = new TriangleMeshDesc()
            {
                Flags     = (MeshFlag)0,
                Triangles = bunny.Indices,
                Points    = bunny.VertexPositions
            };

            var cooking = scene.Physics.CreateCooking();

            var stream     = new MemoryStream();
            var cookResult = cooking.CookTriangleMesh(triangleMeshDesc, stream);

            stream.Position = 0;

            var triangleMesh = scene.Physics.CreateTriangleMesh(stream);

            var triangleMeshGeom = new TriangleMeshGeometry(triangleMesh)
            {
                Scale = new MeshScale(new Vector3(0.3f, 0.3f, 0.3f), Quaternion.Identity)
            };

            var rigidActor = scene.Physics.CreateRigidStatic();

            // TODO: The Shape created here is now also an owner of the TriangleMesh object,
            // this needs to be incorp into the ObjectTable ownership logic
            rigidActor.CreateShape(triangleMeshGeom, material);

            rigidActor.GlobalPose =
                Matrix4x4.CreateRotationX(-(float)System.Math.PI / 2) *
                Matrix4x4.CreateTranslation(0, 10, 0);

            scene.AddActor(rigidActor);
        }
Esempio n. 7
0
        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;
        }
Esempio n. 9
0
        public void CreateMesh(Scene.Entity3D ent)
        {
            System.Collections.Generic.List <OpenTK.Vector3> verts = ent.GetAllVerts();
            System.Collections.Generic.List <int>            tris  = ent.GetAllTris();


            System.Numerics.Vector3[] rvert = new System.Numerics.Vector3[verts.Count];

            int vi = 0;

            foreach (OpenTK.Vector3 v in verts)
            {
                rvert[vi] = new System.Numerics.Vector3(v.X, v.Y, v.Z);

                vi++;
            }

            int[] at = new int[tris.Count];

            for (int i = 0; i < tris.Count; i++)
            {
                at[i] = tris[i];
            }

            TriangleMeshDesc tm = new TriangleMeshDesc()
            {
                Flags     = 0,
                Triangles = at,
                Points    = rvert
            };

            Cooking cook = PhysicsManager.py.CreateCooking();

            MemoryStream str = new MemoryStream();
            TriangleMeshCookingResult cookr = cook.CookTriangleMesh(tm, str);

            str.Position = 0;

            TriangleMesh trim = PhysicsManager.py.CreateTriangleMesh(str);

            TriangleMeshGeometry trig = new TriangleMeshGeometry(trim);

            RID = PhysicsManager.py.CreateRigidStatic();

            Shape ns = RigidActorExt.CreateExclusiveShape(RID, trig, Mat);

            //RID.CreateShape ( trig, Mat );

            var wm = ent.WorldNoScale;

            float m11 = wm.M11;
            float m12 = wm.M12;
            float m13 = wm.M13;
            float m14 = wm.M14;

            float m21 = wm.M21;
            float m22 = wm.M22;
            float m23 = wm.M23;
            float m24 = wm.M24;

            float m31 = wm.M31;
            float m32 = wm.M32;
            float m33 = wm.M33;
            float m34 = wm.M34;

            float m41 = wm.M41;
            float m42 = wm.M42;
            float m43 = wm.M43;
            float m44 = wm.M44;

            System.Numerics.Matrix4x4 tp = new System.Numerics.Matrix4x4(m11, m12, m13, m14, m21, m22, m23, m24, m31, m32, m33, m34, m41, m42, m43, m44);

            // RID.GlobalPose = System.Numerics.Matrix4x4.CreateRotationX(-(float)System.Math.PI / 2);
            //RID.GlobalPosePosition = ent.LocalPos;

            PhysicsManager.Scene.AddActor(RID);
        }
Esempio n. 10
0
        private void AddCollider(RigidActor actor, ICollider collider)
        {
            if (collider is AggregateCollider agg)
            {
                foreach (var c in agg.ColliderComponents)
                {
                    AddCollider(actor, c);
                }
            }
            else if (collider is TriangleMeshCollider triCollider)
            {
                var desc = triCollider.GetDescriptor(GetMaterialIndices);

                // Avoiding offline cook path for now because
                //   1. Comments in Physx.Net imply memory leak using streams
                //   2. I don't want to deal with disk caching cooks yet
                var finalMesh = this.physxPhysics.CreateTriangleMesh(cooker, desc);

                var meshGeom = new TriangleMeshGeometry(finalMesh);

                RigidActorExt.CreateExclusiveShape(actor, meshGeom, globalMaterials, null);
            }
            else if (collider is TriangleModelCollider triModelCollider)
            {
                foreach (var mesh in triModelCollider.MeshColliders)
                {
                    var desc = mesh.GetDescriptor(GetMaterialIndices);

                    // Avoiding offline cook path for now because
                    //   1. Comments in Physx.Net imply memory leak using streams
                    //   2. I don't want to deal with disk caching cooks yet
                    var finalMesh = this.physxPhysics.CreateTriangleMesh(cooker, desc);

                    var meshGeom = new TriangleMeshGeometry(finalMesh);

                    RigidActorExt.CreateExclusiveShape(actor, meshGeom, globalMaterials, null);
                }
            }
            else if (collider is IVertexBasedCollider vertCollider)
            {
                var desc = new ConvexMeshDesc()
                {
                    Flags = ConvexFlag.ComputeConvex
                };
                desc.SetPositions(vertCollider.GetTransformedVertices());
                var mesh = this.physxPhysics.CreateConvexMesh(this.cooker, desc);
                var geom = new ConvexMeshGeometry(mesh);
                var mat  = this.GetOrCreateMaterial(vertCollider.PhysicsMaterial);
                // TODO: re-use shared shapes instead of creating exclusive
                RigidActorExt.CreateExclusiveShape(actor, geom, mat);
            }
            else if (collider is ConvexModelCollider modelCollider)
            {
                foreach (var verts in modelCollider.Meshes)
                {
                    var desc = new ConvexMeshDesc()
                    {
                        Flags = ConvexFlag.ComputeConvex
                    };
                    desc.SetPositions(verts);
                    var mesh = this.physxPhysics.CreateConvexMesh(this.cooker, desc);
                    var geom = new ConvexMeshGeometry(mesh);
                    var mat  = this.GetOrCreateMaterial(modelCollider.PhysicsMaterial);
                    // TODO: re-use shared shapes instead of creating exclusive
                    RigidActorExt.CreateExclusiveShape(actor, geom, mat);
                }
            }
        }
Esempio n. 11
0
		private void CreateTriangleMesh(Scene scene, Material material)
		{
			var colladaLoader = new ColladaLoader();
			var bunny = colladaLoader.Load(@"Teapot.DAE", this.Engine.GraphicsDevice);

			var triangleMeshDesc = new TriangleMeshDesc()
			{
				Flags = (MeshFlag)0,
				Triangles = bunny.Indices,
				Points = bunny.VertexPositions
			};

			var cooking = scene.Physics.CreateCooking();

			var stream = new MemoryStream();
			bool cookResult = cooking.CookTriangleMesh(triangleMeshDesc, stream);

			stream.Position = 0;

			var triangleMesh = scene.Physics.CreateTriangleMesh(stream);

			var triangleMeshGeom = new TriangleMeshGeometry(triangleMesh)
			{
				Scale = new MeshScale(new Vector3(0.3f, 0.3f, 0.3f), Quaternion.Identity)
			};

			var rigidActor = scene.Physics.CreateRigidStatic();

			// TODO: The Shape created here is now also an owner of the TriangleMesh object,
			// this needs to be incorp into the ObjectTable ownership logic
			rigidActor.CreateShape(triangleMeshGeom, material);

			rigidActor.GlobalPose =
				Matrix.RotationX(-(float)System.Math.PI / 2) *
				Matrix.Translation(0, 10, 0);

			scene.AddActor(rigidActor);
		}
        public PhysxTriangleMesh(PhysxPhysicWorld PhysxPhysicWorld, FileStream FileStream, Microsoft.Xna.Framework.Matrix localTransformation, Microsoft.Xna.Framework.Matrix worldTransformation, Microsoft.Xna.Framework.Vector3 scale, MaterialDescription MaterialDescription)
        {
            TriangleMesh triangleMesh = PhysxPhysicWorld.Physix.CreateTriangleMesh(FileStream);

            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;
        }
Esempio n. 13
0
		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);
		}