Exemple #1
0
        private void DigitalRuneAdaptorScene()
        {
            //creating the simulation
            CreateScene();

            //definig a material
            var materialDesc = new MaterialDescription
            {
                DynamicFriction        = 0.5f,
                StaticFriction         = 0.5f,
                Restitution            = 0.7f,
                FrictionCombineMode    = CombineMode.Average,
                RestitutionCombineMode = CombineMode.Average
            };

            Nx.Material material = _scene.CreateMaterial(materialDesc);

            //creating the ground
            CreateGround(material);

            ////creating a Tower

            CreateTower(material, new NxVector3(1, 1, 1),
                        xCount: 5, yCount: 5, zCount: 5,
                        xSpace: 2, ySpace: 2, zSpace: 2,
                        xOffset: 0, yOffset: 2 + 10 / 2, zOffset: 0);
        }
Exemple #2
0
        protected override void LoadContent(GraphicInfo GraphicInfo, GraphicFactory factory, IContentManager contentManager)
        {
            PhysxPhysicWorld PhysxPhysicWorld = World.PhysicWorld as PhysxPhysicWorld;

            base.LoadContent(GraphicInfo, factory, contentManager);
            {
                SimpleModel simpleModel = new SimpleModel(factory, "Model//cenario");

                StillDesign.PhysX.Material material1 = PhysxPhysicWorld.CreatePhysicMaterial(
                    new StillDesign.PhysX.MaterialDescription()
                {
                    Restitution     = 0.3f,
                    DynamicFriction = 0.5f,
                    StaticFriction  = 1,
                }
                    );
                PhysxTriangleMesh tmesh = new PhysxTriangleMesh(PhysxPhysicWorld, simpleModel,
                                                                Matrix.Identity, Vector3.One, 1, material1);

                ForwardXNABasicShader shader    = new ForwardXNABasicShader(ForwardXNABasicShaderDescription.Default());
                ForwardMaterial       fmaterial = new ForwardMaterial(shader);
                IObject obj = new IObject(fmaterial, simpleModel, tmesh);
                this.World.AddObject(obj);
            }

            BallThrowPhysx28 BallThrowBullet = new BallThrowPhysx28(this.World, GraphicFactory);

            this.AttachCleanUpAble(BallThrowBullet);

            for (int i = 0; i < 10; i++)
            {
                StillDesign.PhysX.Material material2 = PhysxPhysicWorld.CreatePhysicMaterial(
                    new StillDesign.PhysX.MaterialDescription()
                {
                    Restitution            = PloobsEngine.Utils.StaticRandom.RandomBetween(0, 1),
                    DynamicFriction        = PloobsEngine.Utils.StaticRandom.RandomBetween(0, 1),
                    StaticFriction         = PloobsEngine.Utils.StaticRandom.RandomBetween(0, 1),
                    RestitutionCombineMode = CombineMode.Max,
                }
                    );

                ///Load a Model with a custom texture
                SimpleModel sm2 = new SimpleModel(factory, "Model\\ball");
                sm2.SetTexture(factory.CreateTexture2DColor(1, 1, Color.Green, false), TextureType.DIFFUSE);

                ForwardXNABasicShader nd = new ForwardXNABasicShader();
                IMaterial             m  = new ForwardMaterial(nd);

                SphereShapeDescription SphereGeometry = new SphereShapeDescription(5f);
                SphereGeometry.Material = material2;

                PhysxPhysicObject PhysxPhysicObject = new PhysxPhysicObject(SphereGeometry,
                                                                            0.5f, Matrix.CreateTranslation(new Vector3(100, 100, 50 * i)), Vector3.One * 5f);

                IObject o = new IObject(m, sm2, PhysxPhysicObject);
                this.World.AddObject(o);
            }
            this.World.CameraManager.AddCamera(new CameraFirstPerson(GraphicInfo));
        }
Exemple #3
0
 public Material(RigidBody rigidBody, PX.Material wrappedMaterial, MaterialDescriptor descriptor)
 {
     wrappedMaterial.DynamicFriction = descriptor.Friction;
     wrappedMaterial.StaticFriction  = descriptor.Friction;
     wrappedMaterial.Restitution     = descriptor.Restitution;
     _wrappedMaterial = wrappedMaterial;
     Configurator     = new BaseConfigurator <IMaterial>();
 }
Exemple #4
0
 public Material(RigidBody rigidBody, PX.Material wrappedMaterial, MaterialDescriptor descriptor)
 {
     wrappedMaterial.DynamicFriction = descriptor.Friction;
     wrappedMaterial.StaticFriction = descriptor.Friction;
     wrappedMaterial.Restitution = descriptor.Restitution;
     _wrappedMaterial = wrappedMaterial;
     Configurator = new BaseConfigurator<IMaterial>();
 }
Exemple #5
0
        private void CreateGround(Nx.Material material)
        {
            var planeShapeDesc = new PlaneShapeDescription(0, 1, 0, 0)
            {
                Material = material,
            };
            var actorDesc = new ActorDescription(planeShapeDesc)
            {
                BodyDescription = null,
                UserData        = _planeModel
            };

            _scene.CreateActor(actorDesc);
        }
Exemple #6
0
        private void CreateBoxes(Nx.Material material)
        {
            for (int x = 0; x < XCount; x++)
            {
                for (int y = 0; y < YCount; y++)
                {
                    for (int z = 0; z < ZCount; z++)
                    {
                        var rigidBodyDesc = new BodyDescription();

                        var boxDesc = new BoxShapeDescription
                        {
                            Material   = material,
                            Dimensions = new NxVector3(WidthX / 2, WidthY / 2, WidthZ / 2)
                        };

                        var actorDesc = new ActorDescription(boxDesc)
                        {
                            BodyDescription = rigidBodyDesc,
                            Density         = 10.0f,
                            GlobalPose      = NxMath.Matrix.Translation(
                                XOffset + x * XSpace - ((XCount - 1) * XSpace / 2),
                                YOffset + y * YSpace - ((YCount - 1) * YSpace / 2),
                                ZOffset + z * ZSpace - ((ZCount - 1) * ZSpace / 2)),
                            UserData = _boxModel
                        };

                        if (!actorDesc.IsValid())
                        {
                            throw new Exception("ActorDesc invalid!");
                        }

                        var actor = _scene.CreateActor(actorDesc);
                        if (actor == null)
                        {
                            throw new Exception("Actor invalid!");
                        }
                    }
                }
            }
        }
Exemple #7
0
        private void CreateTower(Nx.Material material, NxVector3 descriptor, int xCount, int yCount, int zCount, float xSpace, float ySpace, float zSpace, float xOffset, float yOffset, float zOffset)
        {
            for (int x = 0; x < xCount; x++)
            {
                for (int y = 0; y < yCount; y++)
                {
                    for (int z = 0; z < zCount; z++)
                    {
                        var rigidBodyDesc = new BodyDescription();

                        var boxDesc = new BoxShapeDescription
                        {
                            Material   = material,
                            Dimensions = new NxVector3(descriptor.X / 2, descriptor.Y / 2, descriptor.Z / 2)
                        };

                        var actorDesc = new ActorDescription(boxDesc)
                        {
                            BodyDescription = rigidBodyDesc,
                            Density         = 10.0f,
                            GlobalPose      = NxMath.Matrix.Translation(
                                xOffset + x * xSpace - ((xCount - 1) * xSpace / 2),
                                yOffset + y * ySpace - ((yCount - 1) * ySpace / 2),
                                zOffset + z * zSpace - ((zCount - 1) * zSpace / 2)),
                            UserData = _boxModel
                        };

                        if (!actorDesc.IsValid())
                        {
                            throw new Exception("ActorDesc invalid!");
                        }

                        var actor = _scene.CreateActor(actorDesc);
                        if (actor == null)
                        {
                            throw new Exception("Actor invalid!");
                        }
                    }
                }
            }
        }
Exemple #8
0
        private void SetupSimulation()
        {
            //creating the simulation
            CreateScene();

            //definig a material
            var materialDesc = new MaterialDescription
            {
                DynamicFriction        = Friction,
                StaticFriction         = Friction,
                Restitution            = Restitution,
                FrictionCombineMode    = CombineMode.Average,
                RestitutionCombineMode = CombineMode.Average
            };

            Nx.Material material = _scene.CreateMaterial(materialDesc);

            CreateGround(material);

            CreateBoxes(material);
        }
Exemple #9
0
        protected override void LoadContent(GraphicInfo GraphicInfo, GraphicFactory factory, IContentManager contentManager)
        {
            PhysxPhysicWorld PhysxPhysicWorld = World.PhysicWorld as PhysxPhysicWorld;

            base.LoadContent(GraphicInfo, factory, contentManager);


            ///Cosntruct a grid of vertices to make a cloth
            int w = 50;
            int h = 50;

            float hw = w / 2.0f;
            float hh = h / 2.0f;

            Vector3 p = new Vector3(0, 70, 0);

            var grid = VertexGrid.CreateGrid(w, h);

            ///Cloth Model (Code inside the demo)
            ClothModel ClothModel = new PloobsEngine.Modelo.ClothModel(factory, PhysxPhysicWorld,
                                                                       new ClothMeshDescription(), grid.Points, grid.TextCoords, grid.Indices, "Textures//fabric");

            ///Cloth Description
            var clothDesc = new ClothDescription()
            {
                Friction  = 0.5f,
                ClothMesh = ClothModel.ClothMesh,
                Flags     = ClothFlag.Gravity | ClothFlag.Bending | ClothFlag.CollisionTwoway | ClothFlag.Visualization | ClothFlag.SelfCollision,
                Thickness = 0.5f,
            };

            ///Adding Cloth Vertices
            clothDesc.MeshData.AllocatePositions <Vector3>(grid.Points.Length);
            clothDesc.MeshData.AllocateIndices <int>(grid.Indices.Length);
            clothDesc.MeshData.AllocateNormals <Vector3>(grid.Points.Length);

            clothDesc.MeshData.MaximumVertices = grid.Points.Length;
            clothDesc.MeshData.MaximumIndices  = grid.Indices.Length;

            clothDesc.MeshData.NumberOfVertices = grid.Points.Length;
            clothDesc.MeshData.NumberOfIndices  = grid.Indices.Length;



            ///Cloth Physic Model
            PhysxClothObject PhysxClothObject = new PloobsEngine.Physics.PhysxClothObject(clothDesc,
                                                                                          Matrix.CreateTranslation(-hw, 0, -hh) * Matrix.CreateTranslation(p));



            ForwardXNABasicShader ForwardXNABasicShader = new PloobsEngine.Material.ForwardXNABasicShader();
            ClothMaterial         ClothMaterial         = new ClothMaterial(ForwardXNABasicShader);
            IObject IObject = new PloobsEngine.SceneControl.IObject(ClothMaterial, ClothModel, PhysxClothObject);

            World.AddObject(IObject);


            {
                SimpleModel simpleModel = new SimpleModel(factory, "Model//table", "Textures//wood_dark");

                StillDesign.PhysX.Material material1 = PhysxPhysicWorld.CreatePhysicMaterial(
                    new StillDesign.PhysX.MaterialDescription()
                {
                    Restitution     = 0.3f,
                    DynamicFriction = 0.5f,
                    StaticFriction  = 1,
                }
                    );
                PhysxTriangleMesh tmesh = new PhysxTriangleMesh(PhysxPhysicWorld, simpleModel,
                                                                Matrix.Identity, Vector3.One, 1, material1);

                ForwardXNABasicShader shader    = new ForwardXNABasicShader(ForwardXNABasicShaderDescription.Default());
                ForwardMaterial       fmaterial = new ForwardMaterial(shader);
                IObject obj = new IObject(fmaterial, simpleModel, tmesh);
                this.World.AddObject(obj);
                shader.BasicEffect.EnableDefaultLighting();
            }
            {
                StillDesign.PhysX.Material material2 = PhysxPhysicWorld.CreatePhysicMaterial(
                    new StillDesign.PhysX.MaterialDescription()
                {
                    Restitution            = PloobsEngine.Utils.StaticRandom.RandomBetween(0, 1),
                    DynamicFriction        = PloobsEngine.Utils.StaticRandom.RandomBetween(0, 1),
                    StaticFriction         = PloobsEngine.Utils.StaticRandom.RandomBetween(0, 1),
                    RestitutionCombineMode = CombineMode.Max,
                }
                    );
                {
                    SimpleModel sm2 = new SimpleModel(factory, "Model\\ball");
                    sm2.SetTexture(factory.CreateTexture2DColor(1, 1, Color.Green, false), TextureType.DIFFUSE);

                    ForwardXNABasicShader nd = new ForwardXNABasicShader();
                    IMaterial             m  = new ForwardMaterial(nd);

                    SphereShapeDescription SphereGeometry = new SphereShapeDescription(5);
                    SphereGeometry.Material = material2;

                    PhysxPhysicObject PhysxPhysicObject = new PhysxPhysicObject(SphereGeometry,
                                                                                0.5f, Matrix.CreateTranslation(new Vector3(0, 50, 0)), Vector3.One * 5f);

                    IObject o = new IObject(m, sm2, PhysxPhysicObject);
                    this.World.AddObject(o);
                    nd.BasicEffect.EnableDefaultLighting();
                    PhysxPhysicObject.isMotionLess = true;
                }
            }



            BallThrowPhysx28 BallThrowBullet = new BallThrowPhysx28(this.World, GraphicFactory);

            BallThrowBullet.ballSize = 1;
            BallThrowBullet.Speed    = 20;
            this.AttachCleanUpAble(BallThrowBullet);
            this.World.CameraManager.AddCamera(new CameraFirstPerson(GraphicInfo));
        }
Exemple #10
0
        /// <summary>
        /// Initializes a new instance of the <see cref="PhysxTriangleMesh"/> class.
        /// Cooks the Model on the fly
        /// </summary>
        /// <param name="PhysxPhysicWorld">The physx physic world.</param>
        /// <param name="model">The model.</param>
        /// <param name="worldTransformation">The world transformation.</param>
        /// <param name="scale">The scale.</param>
        /// <param name="density">The density.</param>
        /// <param name="material">The material.</param>
        public PhysxTriangleMesh(PhysxPhysicWorld PhysxPhysicWorld, IModelo model, Microsoft.Xna.Framework.Matrix worldTransformation, Microsoft.Xna.Framework.Vector3 scale, float density = 1, StillDesign.PhysX.Material material = null)
        {
            Microsoft.Xna.Framework.Vector3[] vertices = null;
            int[] indices = null;
            ExtractData(ref vertices, ref indices, model);


            TriangleMeshDescription meshDesc = new TriangleMeshDescription();

            meshDesc.AllocateVertices <Microsoft.Xna.Framework.Vector3>(vertices.Count());
            meshDesc.VerticesStream.SetData <Microsoft.Xna.Framework.Vector3>(vertices);
            meshDesc.AllocateTriangles <int>(indices.Count());
            meshDesc.TriangleStream.SetData <int>(indices);
            meshDesc.Flags         = 0;
            meshDesc.VertexCount   = vertices.Count();
            meshDesc.TriangleCount = indices.Count();

            MemoryStream ms = new MemoryStream();

            Cooking.InitializeCooking();
            if (Cooking.CookTriangleMesh(meshDesc, ms) == false)
            {
                PloobsEngine.Engine.Logger.ActiveLogger.LogMessage("Cant Cook Model", Engine.Logger.LogLevel.FatalError);
            }
            Cooking.CloseCooking();

            ms.Position = 0;
            TriangleMesh triangleMesh = PhysxPhysicWorld.Core.CreateTriangleMesh(ms);
            TriangleMeshShapeDescription bunnyShapeDesc = new TriangleMeshShapeDescription();

            if (material != null)
            {
                bunnyShapeDesc.Material = material;
            }
            bunnyShapeDesc.TriangleMesh = triangleMesh;
            ActorDesc = new ActorDescription();
            ActorDesc.Shapes.Add(bunnyShapeDesc);
            ActorDesc.BodyDescription = null;
            ActorDesc.GlobalPose      = worldTransformation.AsPhysX();
            this.Scale = scale;
        }