public static void BuiltinMaterialInit(PhysX.Physics physics) { // PhysX collision forces are very strong, so the ground restitution needs to be lowered significantly. GROUND = new Material(physics.CreateMaterial(0.4f, 0.35f, 0.05f), 1200.0f); GROUND.IsShared = true; // For navigable roads, people need a preset that acts mostly like ground. STONE = new Material(physics.CreateMaterial(0.5f, 0.35f, 0.05f), 2400.0f, (int)OpenMetaverse.Material.Stone); STONE.IsShared = true; METAL = new Material(physics.CreateMaterial(0.3f, 0.25f, 0.4f), 2700.0f, (int)OpenMetaverse.Material.Metal); METAL.IsShared = true; GLASS = new Material(physics.CreateMaterial(0.2f, 0.15f, 0.7f), 2500.0f, (int)OpenMetaverse.Material.Glass); GLASS.IsShared = true; WOOD = new Material(physics.CreateMaterial(0.6f, 0.55f, 0.5f), 1000.0f, (int)OpenMetaverse.Material.Wood); WOOD.IsShared = true; FLESH = new Material(physics.CreateMaterial(0.9f, 0.8f, 0.3f), 1400.0f, (int)OpenMetaverse.Material.Flesh); FLESH.IsShared = true; PLASTIC = new Material(physics.CreateMaterial(0.4f, 0.35f, 0.7f), 900.0f, (int)OpenMetaverse.Material.Plastic); PLASTIC.IsShared = true; RUBBER = new Material(physics.CreateMaterial(0.9f, 0.87f, 0.9f), 1100.0f, (int)OpenMetaverse.Material.Rubber); RUBBER.IsShared = true; MaterialsByOMVEnum = new Material[] { STONE, //0... METAL, GLASS, WOOD, FLESH, PLASTIC, RUBBER, WOOD //light.. which makes no sense is remapped to wood }; }
private Physics CreatePhysics(ErrorCallback errorCallback = null) { if (Physics.Instantiated) Assert.Fail("Physics is still created"); if (errorCallback == null) errorCallback = _errorLog = new ErrorLog(); if (_physics != null) { _physics.Dispose(); _physics = null; } if (_foundation != null) { _foundation.Dispose(); _foundation = null; } _foundation = new Foundation(errorCallback); _physics = new Physics(_foundation, checkRuntimeFiles: true); return _physics; }
private Physics CreatePhysics(ErrorCallback errorCallback = null) { if (Physics.Instantiated) { Assert.Fail("Physics is still created"); } if (errorCallback == null) { errorCallback = _errorLog = new ErrorLog(); } if (_physics != null) { _physics.Dispose(); _physics = null; } if (_foundation != null) { _foundation.Dispose(); _foundation = null; } _foundation = new Foundation(errorCallback); _physics = new Physics(_foundation, checkRuntimeFiles: true); return(_physics); }
public Material Duplicate(PhysX.Physics physics) { if (this.MaterialPreset != NO_PRESET) { return((Material)FindImpl((OpenMetaverse.Material) this.MaterialPreset)); } else { PhysX.Material baseMaterial = physics.CreateMaterial(StaticFriction, DynamicFriction, Restitution); return(new Material(baseMaterial, Density, GravityMultiplier)); } }
public Material ToLocalMaterial(PhysX.Physics physics) { if (this.MaterialPreset != NO_PRESET) { return((Material)FindImpl((OpenMetaverse.Material) this.MaterialPreset)); } else { _baseMaterial = physics.CreateMaterial(_serializedStaticFriction, _serializedDynamicFriction, _serializedRestitution); return(this); } }
public override void Initialize(IMesher meshmerizer, Nini.Config.IConfigSource config, OpenMetaverse.UUID regionId) { _regionId = regionId; _mesher = meshmerizer; m_log.Info("[InWorldz.PhysxPhysics] Creating PhysX scene"); if (config.Configs["InWorldz.PhysxPhysics"] != null) { Settings.Instance.UseVisualDebugger = config.Configs["InWorldz.PhysxPhysics"].GetBoolean("use_visual_debugger", false); Settings.Instance.UseCCD = config.Configs["InWorldz.PhysxPhysics"].GetBoolean("use_ccd", true); Settings.Instance.Gravity = config.Configs["InWorldz.PhysxPhysics"].GetFloat("gravity", -9.8f); Settings.Instance.ThrowOnSdkError = config.Configs["InWorldz.PhysxPhysics"].GetBoolean("throw_on_sdk_error", false); Settings.Instance.InstrumentMeshing = config.Configs["InWorldz.PhysxPhysics"].GetBoolean("instrument_meshing", false); } else { Settings.Instance.UseVisualDebugger = false; Settings.Instance.UseCCD = true; Settings.Instance.Gravity = -9.8f; Settings.Instance.ThrowOnSdkError = false; Settings.Instance.InstrumentMeshing = false; } Nini.Config.IConfig startupcfg = config.Configs["Startup"]; if (startupcfg != null) _gridmode = startupcfg.GetBoolean("gridmode", false); if (_foundation == null) { _foundation = new PhysX.Foundation(s_ErrorCallback); _physics = new PhysX.Physics(_foundation); Material.BuiltinMaterialInit(_physics); } _sceneDesc = new PhysX.SceneDesc(null, Settings.Instance.UseCCD); _sceneDesc.Gravity = new PhysX.Math.Vector3(0f, 0f, Settings.Instance.Gravity); _simEventDelegator = new SimulationEventCallbackDelegator(); _simEventDelegator.OnContactCallback += this.OnContact; _simEventDelegator.OnTriggerCallback += this.OnTrigger; _sceneDesc.SimulationEventCallback = _simEventDelegator; _scene = _physics.CreateScene(_sceneDesc); Preload(); if (Settings.Instance.UseCCD) { _scene.SetFlag(PhysX.SceneFlag.SweptIntegration, true); } if (Settings.Instance.UseVisualDebugger && _physics.RemoteDebugger != null) { _physics.RemoteDebugger.Connect("localhost", null, null, PhysX.VisualDebugger.VisualDebuggerConnectionFlag.Debug, null); } _controllerManager = _scene.CreateControllerManager(); CreateDefaults(); _terrainMesher = new Meshing.TerrainMesher(_scene); _terrainMgr = new TerrainManager(_scene, _terrainMesher, regionId); _meshingStage = new Meshing.MeshingStage(_scene, meshmerizer, _terrainMesher); _meshingStage.OnShapeNeedsFreeing += new Meshing.MeshingStage.ShapeNeedsFreeingDelegate(_meshingStage_OnShapeNeedsFreeing); _kinematicManager = new KinematicManager(); //fire up our work loop HeartbeatThread = Watchdog.StartThread(new ThreadStart(Heartbeat), "Physics Heartbeat", ThreadPriority.Normal, false); TimingThread = Watchdog.StartThread(new ThreadStart(DoTiming), string.Format("Physics Timing"), ThreadPriority.Highest, false); }
/// <summary> /// Fills out the physics material implementation from the description. Used when /// deserializing a physics material /// </summary> internal void FillMaterialFromDesc(PhysX.Physics physics) { PhysxMaterial = PhysxMaterial.ToLocalMaterial(physics); }
public override void Initialize(IMesher meshmerizer, Nini.Config.IConfigSource config, OpenMetaverse.UUID regionId) { _regionId = regionId; _mesher = meshmerizer; m_log.Info("[InWorldz.PhysxPhysics] Creating PhysX scene"); if (config.Configs["InWorldz.PhysxPhysics"] != null) { Settings.Instance.UseVisualDebugger = config.Configs["InWorldz.PhysxPhysics"].GetBoolean("use_visual_debugger", false); Settings.Instance.UseCCD = config.Configs["InWorldz.PhysxPhysics"].GetBoolean("use_ccd", true); Settings.Instance.Gravity = config.Configs["InWorldz.PhysxPhysics"].GetFloat("gravity", -9.8f); Settings.Instance.ThrowOnSdkError = config.Configs["InWorldz.PhysxPhysics"].GetBoolean("throw_on_sdk_error", false); Settings.Instance.InstrumentMeshing = config.Configs["InWorldz.PhysxPhysics"].GetBoolean("instrument_meshing", false); } else { Settings.Instance.UseVisualDebugger = false; Settings.Instance.UseCCD = true; Settings.Instance.Gravity = -9.8f; Settings.Instance.ThrowOnSdkError = false; Settings.Instance.InstrumentMeshing = false; } Nini.Config.IConfig startupcfg = config.Configs["Startup"]; if (startupcfg != null) { _gridmode = startupcfg.GetBoolean("gridmode", false); } if (_foundation == null) { _foundation = new PhysX.Foundation(s_ErrorCallback); _physics = new PhysX.Physics(_foundation); Material.BuiltinMaterialInit(_physics); } _sceneDesc = new PhysX.SceneDesc(null, Settings.Instance.UseCCD); _sceneDesc.Gravity = new PhysX.Math.Vector3(0f, 0f, Settings.Instance.Gravity); _simEventDelegator = new SimulationEventCallbackDelegator(); _simEventDelegator.OnContactCallback += this.OnContact; _simEventDelegator.OnTriggerCallback += this.OnTrigger; _sceneDesc.SimulationEventCallback = _simEventDelegator; _scene = _physics.CreateScene(_sceneDesc); Preload(); if (Settings.Instance.UseCCD) { _scene.SetFlag(PhysX.SceneFlag.SweptIntegration, true); } if (Settings.Instance.UseVisualDebugger && _physics.RemoteDebugger != null) { _physics.RemoteDebugger.Connect("localhost", null, null, PhysX.VisualDebugger.VisualDebuggerConnectionFlag.Debug, null); } _controllerManager = _scene.CreateControllerManager(); CreateDefaults(); _terrainMesher = new Meshing.TerrainMesher(_scene); _terrainMgr = new TerrainManager(_scene, _terrainMesher, regionId); _meshingStage = new Meshing.MeshingStage(_scene, meshmerizer, _terrainMesher); _meshingStage.OnShapeNeedsFreeing += new Meshing.MeshingStage.ShapeNeedsFreeingDelegate(_meshingStage_OnShapeNeedsFreeing); _kinematicManager = new KinematicManager(); //fire up our work loop HeartbeatThread = Watchdog.StartThread(new ThreadStart(Heartbeat), "Physics Heartbeat", ThreadPriority.Normal, false); TimingThread = Watchdog.StartThread(new ThreadStart(DoTiming), string.Format("Physics Timing"), ThreadPriority.Highest, false); }
public VehicleMotor(ref PhysxPrim _actor, ref VehicleProperties _props, ref PhysX.Physics _physics, ref PhysxScene _scene) { this._actor = _actor; this._props = _props; this._physics = _physics; this._scene = _scene; }
public VehicleDynamics(PhysxPrim physxPrim, VehicleProperties shadowProps, PhysX.Physics physics, PhysxScene scene) { _angularstatsX = new RunningStat(); _angularstatsY = new RunningStat(); _angularstatsZ = new RunningStat(); _linearstatsX = new RunningStat(); _linearstatsY = new RunningStat(); _linearstatsZ = new RunningStat(); _actor = physxPrim; _props = new VehicleProperties(); _physics = physics; _scene = scene; _motor = new VehicleMotor(ref _actor, ref _props, ref _physics, ref _scene); // Preset the defaults and new common keys. This ensures scripts with older versions of saved state // do not crash the simulator since the new keys do not exist in the old state. _props.Type = VehicleType.None; SetVehicleDefaults(_props); // Merge the new properties. _props.Merge(shadowProps); SetVehicleDefaultActions(); if (VehicleLimits.DebugVehicleChange) m_log.InfoFormat("[VehicleDynamics] constructed type={0} name={1} at {2}", _props.Type, _actor.SOPName, _actor.Position); //DisplayParameters(); }
public Material(PhysX.Physics physics, float staticFriction, float dynamicFriction, float restitution, float density, OpenMetaverse.Material presetNumber) : this(physics, staticFriction, dynamicFriction, restitution, density, GRAVITY_MULTIPLIER_DEFAULT) { MaterialPreset = (int)presetNumber; }
public Material(PhysX.Physics physics, float staticFriction, float dynamicFriction, float restitution, float density) { _baseMaterial = physics.CreateMaterial(staticFriction, dynamicFriction, restitution); Density = density; GravityMultiplier = GRAVITY_MULTIPLIER_DEFAULT; }
public Material(PhysX.Physics physics, float staticFriction, float dynamicFriction, float restitution, float density, float gravityMultiplier) { _baseMaterial = physics.CreateMaterial(staticFriction, dynamicFriction, restitution); Density = density; GravityMultiplier = gravityMultiplier; }
private void button1_Click(object sender, EventArgs e) { PhysX.Physics phys = new PhysX.Physics(); PhysX.SceneDesc desc = new PhysX.SceneDesc(); desc.Gravity = new PhysX.Math.Vector3(0f, 0f, -9.8f); PhysX.Scene scene = phys.CreateScene(desc); material = scene.Physics.CreateMaterial(0.5f, 0.5f, 0.1f); var conn = phys.ConnectToRemoteDebugger("localhost", null, null, null, PhysX.RemoteDebuggerConnectionFlags.Debug); /*scene.SetVisualizationParameter(PhysX.VisualizationParameter.Scale, 1.0f); * scene.SetVisualizationParameter(PhysX.VisualizationParameter.CollisionShapes, true); * scene.SetVisualizationParameter(PhysX.VisualizationParameter.JointLocalFrames, true); * scene.SetVisualizationParameter(PhysX.VisualizationParameter.JointLimits, true); * scene.SetVisualizationParameter(PhysX.VisualizationParameter.ParticleSystemPosition, true); * scene.SetVisualizationParameter(PhysX.VisualizationParameter.ActorAxes, true);*/ var hfGeom = this.CreateHfGeom(scene); while (true) { PhysX.RigidDynamic sphere = CreateSphere(scene, 0); sphere.Dispose(); PhysX.RigidStatic ground = CreateGround(scene, hfGeom); ground.Dispose(); GC.Collect(); } scene.AddActor(CreateGround(scene)); /*PhysX.RigidDynamic box1 = null; * for (int i = 0; i < 10; i += 2) * { * PhysX.RigidDynamic mahBox = CreateBox(scene, i); * scene.AddActor(mahBox); * * if (i == 0) * { * box1 = mahBox; * ((PhysX.Actor)box1).Flags = PhysX.ActorFlag.DisableGravity; * } * }*/ for (int i = 0; i < 10; i += 2) { PhysX.RigidDynamic mahBox = CreateSphere(scene, i); scene.AddActor(mahBox); } Stopwatch sw = new Stopwatch(); while (true) { sw.Start(); scene.Simulate(0.025f); scene.FetchResults(true); sw.Stop(); int sleep = 25 - (int)sw.ElapsedMilliseconds; if (sleep < 0) { sleep = 0; } System.Threading.Thread.Sleep(sleep); sw.Reset(); //label1.Text = DecomposeToPosition(mahBox.GlobalPose).ToString(); this.Update(); } }
private void button1_Click(object sender, EventArgs e) { PhysX.Physics phys = new PhysX.Physics(); PhysX.SceneDesc desc = new PhysX.SceneDesc(); desc.Gravity = new PhysX.Math.Vector3(0f, 0f, -9.8f); PhysX.Scene scene = phys.CreateScene(desc); material = scene.Physics.CreateMaterial(0.5f, 0.5f, 0.1f); var conn = phys.ConnectToRemoteDebugger("localhost", null, null, null, PhysX.RemoteDebuggerConnectionFlags.Debug); /*scene.SetVisualizationParameter(PhysX.VisualizationParameter.Scale, 1.0f); scene.SetVisualizationParameter(PhysX.VisualizationParameter.CollisionShapes, true); scene.SetVisualizationParameter(PhysX.VisualizationParameter.JointLocalFrames, true); scene.SetVisualizationParameter(PhysX.VisualizationParameter.JointLimits, true); scene.SetVisualizationParameter(PhysX.VisualizationParameter.ParticleSystemPosition, true); scene.SetVisualizationParameter(PhysX.VisualizationParameter.ActorAxes, true);*/ var hfGeom = this.CreateHfGeom(scene); while (true) { PhysX.RigidDynamic sphere = CreateSphere(scene, 0); sphere.Dispose(); PhysX.RigidStatic ground = CreateGround(scene, hfGeom); ground.Dispose(); GC.Collect(); } scene.AddActor(CreateGround(scene)); /*PhysX.RigidDynamic box1 = null; for (int i = 0; i < 10; i += 2) { PhysX.RigidDynamic mahBox = CreateBox(scene, i); scene.AddActor(mahBox); if (i == 0) { box1 = mahBox; ((PhysX.Actor)box1).Flags = PhysX.ActorFlag.DisableGravity; } }*/ for (int i = 0; i < 10; i += 2) { PhysX.RigidDynamic mahBox = CreateSphere(scene, i); scene.AddActor(mahBox); } Stopwatch sw = new Stopwatch(); while (true) { sw.Start(); scene.Simulate(0.025f); scene.FetchResults(true); sw.Stop(); int sleep = 25 - (int)sw.ElapsedMilliseconds; if (sleep < 0) sleep = 0; System.Threading.Thread.Sleep(sleep); sw.Reset(); //label1.Text = DecomposeToPosition(mahBox.GlobalPose).ToString(); this.Update(); } }