コード例 #1
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);
		}
コード例 #2
0
        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;
        }
コード例 #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);
        }
コード例 #4
0
        public static TriangleMeshShapeDesc CreateTriangleMesh(this Physics physics, StaticMeshData meshData)
        {
            // create descriptor for triangle mesh
            TriangleMeshShapeDesc triangleMeshShapeDesc = null;
            TriangleMeshDesc      triangleMeshDesc      = new TriangleMeshDesc();

            triangleMeshDesc.PinPoints <float>(meshData.Points, 0, sizeof(float) * 3);
            triangleMeshDesc.PinTriangles <uint>(meshData.Indices, 0, sizeof(uint) * 3);
            triangleMeshDesc.VertexCount   = (uint)meshData.Vertices.Length;
            triangleMeshDesc.TriangleCount = (uint)meshData.TriangleCount;

            MemoryStream stream = new MemoryStream(1024);

            CookingInterface.InitCooking();

            if (CookingInterface.CookTriangleMesh(triangleMeshDesc, stream))
            {
                stream.Seek(0, SeekOrigin.Begin);
                TriangleMesh triangleMesh = physics.CreateTriangleMesh(stream);
                triangleMeshShapeDesc = new TriangleMeshShapeDesc(triangleMesh);
                CookingInterface.CloseCooking();
            }

            triangleMeshDesc.UnpinAll();
            return(triangleMeshShapeDesc);
        }
コード例 #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);
        }
コード例 #6
0
        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);
            }

        }
コード例 #7
0
        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);
            }
        }
コード例 #8
0
        public void CookTriangleMesh()
        {
            using (var physics = CreatePhysicsAndScene())
            {
                // Create a grid of triangles to be our cloth
                var clothGrid = new VertexGrid(25, 25);

                var cooking = physics.Physics.CreateCooking();

                var desc = new TriangleMeshDesc()
                {
                    Points    = clothGrid.Points,
                    Triangles = clothGrid.Indices
                };

                var stream = new MemoryStream();

                bool result = cooking.CookTriangleMesh(desc, stream);

                Assert.IsTrue(result);
            }
        }
コード例 #9
0
ファイル: CookTest.cs プロジェクト: zwagoth/PhysX.net
		public void CookTriangleMesh()
		{
			using (var physics = CreatePhysicsAndScene())
			{
				// Create a grid of triangles to be our cloth
				var clothGrid = new VertexGrid(25, 25);

				var cooking = physics.Physics.CreateCooking();

				var desc = new TriangleMeshDesc()
				{
					Points = clothGrid.Points,
					Triangles = clothGrid.Indices
				};

				var stream = new MemoryStream();

				bool result = cooking.CookTriangleMesh(desc, stream);

				Assert.IsTrue(result);
			}
		}
コード例 #10
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);
        }
コード例 #11
0
        public void CookTriangleMesh()
        {
            using (var physics = CreatePhysicsAndScene())
            {
                // Create a grid of triangles to be our triangle-mesh
                var clothGrid = new VertexGrid(25, 25);

                using (var cooking = physics.Physics.CreateCooking())
                {
                    var desc = new TriangleMeshDesc()
                    {
                        Points    = clothGrid.Points,
                        Triangles = clothGrid.Indices
                    };

                    var stream = new MemoryStream();

                    var result = cooking.CookTriangleMesh(desc, stream);

                    Assert.AreEqual(TriangleMeshCookingResult.Success, result);
                }
            }
        }
コード例 #12
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);
                }
            }
        }
コード例 #13
0
        public static TriangleMeshShapeDesc CreateTriangleMesh(StaticMeshData meshData)
        {
            // create descriptor for triangle mesh
            TriangleMeshShapeDesc triangleMeshShapeDesc = null;
            TriangleMeshDesc triangleMeshDesc = new TriangleMeshDesc();
            triangleMeshDesc.PinPoints<float>(meshData.Points, 0, sizeof(float) * 3);
            triangleMeshDesc.PinTriangles<uint>(meshData.Indices, 0, sizeof(uint) * 3);
            triangleMeshDesc.VertexCount = (uint)meshData.Vertices.Length;
            triangleMeshDesc.TriangleCount = (uint)meshData.TriangleCount;

            MemoryStream stream = new MemoryStream(1024);
            CookingInterface.InitCooking();

            if (CookingInterface.CookTriangleMesh(triangleMeshDesc, stream))
            {
                stream.Seek(0, SeekOrigin.Begin);
                TriangleMesh triangleMesh = OgreWindow.Instance.physics.CreateTriangleMesh(stream);
                triangleMeshShapeDesc = new TriangleMeshShapeDesc(triangleMesh);
                CookingInterface.CloseCooking();
            }

            triangleMeshDesc.UnpinAll();
            return triangleMeshShapeDesc;
        }
コード例 #14
0
        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;
        }
コード例 #15
0
ファイル: Mesh.cs プロジェクト: stephensmitchell-forks/Igneel
        public TriangleMesh CreateTriangleMesh()
        {
            TriangleMesh triangleMesh;

            TriangleMeshDesc desc = new TriangleMeshDesc();

            desc.Name   = Name;
            desc.Flags |= Is16BitIndices ? MeshFlag.BIT_INDICES_16 : 0;
            desc.Flags |= MeshFlag.HARDWARE_MESH;

            desc.NumTriangles        = FaceCount;
            desc.NumVertices         = VertexCount;
            desc.TriangleStrideBytes = 3 * (Is16BitIndices ? sizeof(short) : sizeof(int));
            desc.PointStrideBytes    = VertexDescriptor.SizeOf(IASemantic.Position, 0);
            int stride = desc.PointStrideBytes;

            var ibData   = _ib.Map(MapType.Read);
            var vbStream = _vb.Map(MapType.Read);

            try
            {
                int posOffset = VertexDescriptor.OffsetOf(IASemantic.Position, 0);
                int size      = _vd.Size;

                byte[] positions = new byte[desc.NumVertices * stride];
                unsafe
                {
                    fixed(byte *desPter = positions)
                    {
                        byte *srcPter = (byte *)vbStream + posOffset;
                        byte *pter    = desPter;

                        for (int i = 0; i < desc.NumVertices; i++, srcPter += size, pter += stride)
                        {
                            *(Vector3 *)pter = *(Vector3 *)(srcPter);
                        }

                        desc.Points    = (IntPtr)desPter;
                        desc.Triangles = ibData;

                        //Cooking.Create();

                        //Cooking.InitCooking();
                        //byte[] stream = Cooking.CookTriangleMesh(desc);

                        //Cooking.CloseCooking();

                        //desc.Dispose();

                        //triangleMesh = new TriangleMesh(stream) { Name = Name, UserData = this };

                        triangleMesh             = PhysicManager.Sigleton.CreateTriangleMesh(desc);
                        triangleMesh.GraphicMesh = this;
                    }
                }
            }
            finally
            {
                _vb.Unmap();
                _ib.Unmap();
            }

            return(triangleMesh);
        }
コード例 #16
0
ファイル: RigidBodiesSample.cs プロジェクト: kpko/PhysX.Net
		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);
		}
コード例 #17
0
ファイル: ShapeGeometryTest.cs プロジェクト: kpko/PhysX.Net
		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);
		}
コード例 #18
0
ファイル: PyObject.cs プロジェクト: VividCoder/SpaceRPG
        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);
        }