Beispiel #1
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 TestGrid(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 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);
                }
            }
        }