protected override void LoadPhysics(PhysX.Scene scene) { var material = scene.Physics.CreateMaterial(0.7f, 0.7f, 0.1f); var sphereA = scene.Physics.CreateRigidDynamic(); sphereA.CreateShape(new SphereGeometry(1), material); sphereA.GlobalPose = Matrix4x4.CreateTranslation(0, 30, 0); scene.AddActor(sphereA); // var sphereB = scene.Physics.CreateRigidDynamic(); sphereB.CreateShape(new SphereGeometry(1), material); sphereB.GlobalPose = Matrix4x4.CreateTranslation(0, 40, 0); scene.AddActor(sphereB); // var sphereC = scene.Physics.CreateRigidDynamic(); sphereC.CreateShape(new SphereGeometry(1), material); sphereC.GlobalPose = Matrix4x4.CreateTranslation(0, 50, 0); scene.AddActor(sphereC); _sphereC = sphereC; // var revoluteABJoint = scene.CreateJoint <RevoluteJoint>(sphereA, Matrix4x4.Identity, sphereB, Matrix4x4.Identity); revoluteABJoint.SetGlobalFrame(new Vector3(0, 35, 0), new Vector3(0, 0, 1)); revoluteABJoint.ConstraintFlags = ConstraintFlag.Visualization; var revoluteBCJoint = scene.CreateJoint <RevoluteJoint>(sphereB, Matrix4x4.Identity, sphereC, Matrix4x4.Identity); revoluteBCJoint.SetGlobalFrame(new Vector3(0, 45, 0), new Vector3(0, 0, 1)); revoluteBCJoint.ConstraintFlags = ConstraintFlag.Visualization; var revoluteAJoint = scene.CreateJoint <RevoluteJoint>(sphereA, Matrix4x4.Identity, null, Matrix4x4.Identity); revoluteAJoint.SetGlobalFrame(new Vector3(0, 30, 0), new Vector3(0, 0, 1)); revoluteAJoint.ConstraintFlags = ConstraintFlag.Visualization; }
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 }
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); }