public PhysxPhysicWorld(Vector3 gravity, bool connectToRemoteDebugger = false)
        {
            physix = new PhysX.Physics(new ErrorCallbackImp(), true);            
            
            var sceneDesc = new SceneDesc()
            {
                Gravity = gravity.AsPhysX()                
            };
                        
            scene = physix.CreateScene(sceneDesc);
                                    
            this.scene.SetVisualizationParameter(VisualizationParameter.Scale, 1.0f);
            this.scene.SetVisualizationParameter(VisualizationParameter.CollisionShapes, true);
            this.scene.SetVisualizationParameter(VisualizationParameter.JointLocalFrames, true);
            this.scene.SetVisualizationParameter(VisualizationParameter.JointLimits, true);
            this.scene.SetVisualizationParameter(VisualizationParameter.ParticleSystemPosition, true);
            this.scene.SetVisualizationParameter(VisualizationParameter.ActorAxes, true);            

            // Connect to the remote debugger if it's there            
            if (connectToRemoteDebugger)
            {
                physix.ConnectToRemoteDebugger("localhost");
            }
            
            objs = new List<IPhysicObject>();
            ctns = new List<IPhysicConstraint>();

            cooking = physix.CreateCooking();

        }
        public PhysxPhysicWorld(Vector3 gravity, bool connectToRemoteDebugger = false)
        {
            physix = new PhysX.Physics(new ErrorCallbackImp(), true);

            var sceneDesc = new SceneDesc()
            {
                Gravity = gravity.AsPhysX()
            };

            scene = physix.CreateScene(sceneDesc);

            this.scene.SetVisualizationParameter(VisualizationParameter.Scale, 1.0f);
            this.scene.SetVisualizationParameter(VisualizationParameter.CollisionShapes, true);
            this.scene.SetVisualizationParameter(VisualizationParameter.JointLocalFrames, true);
            this.scene.SetVisualizationParameter(VisualizationParameter.JointLimits, true);
            this.scene.SetVisualizationParameter(VisualizationParameter.ParticleSystemPosition, true);
            this.scene.SetVisualizationParameter(VisualizationParameter.ActorAxes, true);

            // Connect to the remote debugger if it's there
            if (connectToRemoteDebugger)
            {
                physix.ConnectToRemoteDebugger("localhost");
            }

            objs = new List <IPhysicObject>();
            ctns = new List <IPhysicConstraint>();

            cooking = physix.CreateCooking();
        }
예제 #3
0
        public static void Initialise()
        {
            var eo = new ErrorOutput();

            Foundation = new Foundation(eo);
            PVD        = new Pvd(Foundation);
            Physics    = new PhysX.Physics(Foundation, false, PVD);

            PhysicsScene = Physics.CreateScene(); // TODO: SceneDesc

            PhysicsScene.SetVisualizationParameter(VisualizationParameter.Scale, 2.0f);
            PhysicsScene.SetVisualizationParameter(VisualizationParameter.CollisionShapes, true);
            PhysicsScene.SetVisualizationParameter(VisualizationParameter.JointLocalFrames, true);
            PhysicsScene.SetVisualizationParameter(VisualizationParameter.JointLimits, true);
            PhysicsScene.SetVisualizationParameter(VisualizationParameter.ActorAxes, true);

            PVD.Connect("localhost");
        }
예제 #4
0
        public static void InitSDK()
        {
            Foundation fd = new Foundation(new ECB());

            pvd    = new Pvd(fd);
            py     = new PhysX.Physics(fd, true, pvd);
            SceneD = new SceneDesc
            {
                Gravity = new System.Numerics.Vector3(0, 0, 0)
            };
            Scene = py.CreateScene(SceneD);
            Scene.SetVisualizationParameter(VisualizationParameter.Scale, 2.0f);
            Scene.SetVisualizationParameter(VisualizationParameter.CollisionShapes, true);
            Scene.SetVisualizationParameter(VisualizationParameter.ActorAxes, true);
            py.Pvd.Connect("localhost");
            // Scene.Gravity = new System.Numerics.Vector3(0, 0, 0);

            //PhysX.Material dm = Scene.get
        }
예제 #5
0
        public PhysxPhysicsSystem(World world) : base(world)
        {
            // Setup PhysX infra here

            this.physxFoundation = new PxFoundation(new ConsoleErrorCallback());
            this.physxScale      = new PxTolerancesScale()
            {
                Length = 0.1f,
                Speed  = 98.1f
            };

#if DEBUG
            pvd = new Pvd(this.physxFoundation);
            pvd.Connect("localhost", 5425, TimeSpan.FromSeconds(2), InstrumentationFlag.Debug);
            this.physxPhysics = new PxPhysics(this.physxFoundation, this.physxScale, false, pvd);
#else
            this.physxPhysics = new PxPhysics(this.physxFoundation, this.physxScale);
#endif
            this.defaultMat = this.physxPhysics.CreateMaterial(0.5f, 0.5f, 0.1f);

            this.characterControlMat = this.physxPhysics.CreateMaterial(0.5f, 0.5f, 0f);
            this.characterControlMat.RestitutionCombineMode = CombineMode.Minimum;

            this.frictionlessMat = this.physxPhysics.CreateMaterial(0f, 0f, 0f);
            this.frictionlessMat.RestitutionCombineMode = CombineMode.Minimum;
            this.frictionlessMat.Flags = MaterialFlags.DisableFriction;

            var sceneDesc = new SceneDesc(this.physxScale)
            {
                BroadPhaseType          = BroadPhaseType.SweepAndPrune,
                Gravity                 = world.Gravity,
                Flags                   = SceneFlag.EnableStabilization,
                SolverType              = SolverType.TGS,
                FilterShader            = new DefaultFilterShader(),
                BounceThresholdVelocity = 0.2f * world.Gravity.Length()
            };

            this.physxScene = this.physxPhysics.CreateScene(sceneDesc);

#if DEBUG
            this.physxScene.SetVisualizationParameter(VisualizationParameter.ContactPoint, true);
            this.physxScene.SetVisualizationParameter(VisualizationParameter.ContactNormal, true);
            this.physxScene.SetVisualizationParameter(VisualizationParameter.ContactForce, true);
            this.physxScene.SetVisualizationParameter(VisualizationParameter.ContactError, true);

            var pvdClient = this.physxScene.GetPvdSceneClient();
            pvdClient.SetScenePvdFlags(SceneVisualizationFlags.TransmitContacts | SceneVisualizationFlags.TransmitConstraints | SceneVisualizationFlags.TransmitSceneQueries);
#endif

            var cookingParams = new CookingParams()
            {
                Scale           = this.physxScale,
                AreaTestEpsilon = 0.001f,
                MidphaseDesc    = new MidphaseDesc()
                {
                    Bvh33Desc = new Bvh33MidphaseDesc()
                    {
                        MeshCookingHint = MeshCookingHint.SimulationPerformance
                    }
                },
                BuildTriangleAdjacencies = true,
                MeshCookingHint          = MeshCookingHint.SimulationPerformance,
                MeshWeldTolerance        = 0.001f
            };

            this.cooker            = this.physxPhysics.CreateCooking(cookingParams);
            this.controllerManager = this.physxScene.CreateControllerManager();

            var contactProv = new ContactModifyProxy();
            this.contactProvider = contactProv;
            this.physxScene.ContactModifyCallback = contactProv;

            this.simCallback = new SimulationCallback();
            this.physxScene.SetSimulationEventCallback(simCallback);
        }
예제 #6
0
        protected override void OnShown(EventArgs e)
        {
            var foundation = new Foundation(new Errors());

            var physx = new PhysX.Physics(foundation, checkRuntimeFiles: true);

            var apex = new ApexSdk(physx);

            var destructibleModule = apex.CreateModule <PhysX.Apex.Modules.Destructible.DestructibleModule>();

            var desc = destructibleModule.GetDefaultModuleDesc();

            destructibleModule.Initalize(desc);

            var apexSceneDesc = new ApexSceneDesc
            {
                UseDebugRenderable = true
            };

            var apexScene = apex.CreateScene(apexSceneDesc);

            var serializer = apex.CreateSerializer(SerializeType.Binary, apexScene);

            using (var stream = new StreamReader(@"C:\Development\Temp\Cube3.apb"))
            {
                var d = serializer.Deserialize(stream.BaseStream);

                var p = d[0];

                var asset = apex.CreateAsset(p, "Cube2");

                var destructibleAsset = asset as DestructibleAsset;

                var descParams = destructibleAsset.GetDefaultActorDesc();

                bool valid = asset.IsValidForCreation(descParams, apexScene);

                var actor = asset.CreateApexActor(descParams, apexScene);

                var destructibleActor = actor as DestructibleActor;
            }

            //physx::PxFileBuf* stream = _apexSdk->createStream("C:\\Development\\Temp\\Cube2.apx", physx::PxFileBuf::OPEN_READ_ONLY);

            //NxParameterized::Serializer::DeserializedData data;
            //NxParameterized::Serializer::ErrorType serError = s->deserialize(*stream, data);

            //NxParameterized::Interface *params = data[0];
            //NxApexAsset* asset = _apexSdk->createAsset(params, "Asset Name");

            //NxDestructibleAsset* destructibleAsset = static_cast<NxDestructibleAsset*>(asset);

            //NxParameterized::Interface* descParams = destructibleAsset->getDefaultActorDesc();

            //bool valid = asset->isValidForActorCreation(*descParams, *scene->UnmanagedPointer);

            ////NxParameterized::setParamMat44(*descParams, "globalPose", pose);

            //NxApexActor* actor = asset->createApexActor(*descParams, *scene->UnmanagedPointer);

            //NxDestructibleActor* destructibleActor = (NxDestructibleActor*)actor;
        }