private PhysX.RigidStatic CreateGround(PhysX.Scene scene) { var hfGeom = this.CreateHfGeom(scene); return(this.CreateGround(scene, hfGeom)); //return CreateTriangle(scene); }
private PhysX.RigidDynamic CreateBox(PhysX.Scene scene, int offset) { const float HEIGHT = 20.0f; var rigid = scene.Physics.CreateRigidDynamic(); var shape = rigid.CreateShape(new PhysX.BoxGeometry(1.0f, 1.0f, 1.0f), material); rigid.GlobalPose = PhysX.Math.Matrix.Translation(130f, 130f, HEIGHT + offset); return(rigid); }
private PhysX.RigidStatic CreateGround(PhysX.Scene scene, PhysX.HeightFieldGeometry hfGeom) { var hfActor = scene.Physics.CreateRigidStatic(); hfActor.CreateShape(hfGeom, material); hfActor.GlobalPose = PhysX.Math.Matrix.RotationYawPitchRoll(0f, (float)Math.PI / 2, 0f) * PhysX.Math.Matrix.Translation(0f, 256 - 1, 0f); return(hfActor); //return CreateTriangle(scene); }
public PhysX.RigidStatic CreateTriangle(PhysX.Scene scene) { List <PhysX.Math.Vector3> Vertices = new List <PhysX.Math.Vector3>(); List <int> Indices = new List <int>(); PhysX.TriangleMeshDesc TriangleMeshDesc = new PhysX.TriangleMeshDesc() { Triangles = new int[12] { 0, 1, 2, 0, 3, 1, 3, 4, 1, 3, 5, 4 }, Points = new PhysX.Math.Vector3[6] { new PhysX.Math.Vector3 { X = 0, Y = 0, Z = 0 }, new PhysX.Math.Vector3 { X = 1, Y = 1, Z = 0 }, new PhysX.Math.Vector3 { X = 0, Y = 1, Z = 0 }, new PhysX.Math.Vector3 { X = 1, Y = 0, Z = 0 }, new PhysX.Math.Vector3 { X = 2, Y = 1, Z = 0 }, new PhysX.Math.Vector3 { X = 2, Y = 0, Z = 0 }, } }; MemoryStream ms = new MemoryStream(); PhysX.Cooking cook = scene.Physics.CreateCooking(); cook.CookTriangleMesh(TriangleMeshDesc, ms); cook.Dispose(); ms.Position = 0; PhysX.TriangleMesh triangleMesh = scene.Physics.CreateTriangleMesh(ms); PhysX.TriangleMeshGeometry triangleMeshShapeDesc = new PhysX.TriangleMeshGeometry(triangleMesh); //PhysX.Math.Matrix.RotationYawPitchRoll(0f, (float)Math.PI / 2, 0f) * PhysX.Math.Matrix.Translation(0f, 0f, 0f) var hfActor = scene.Physics.CreateRigidStatic(); hfActor.CreateShape(triangleMeshShapeDesc, scene.Physics.CreateMaterial(0.75f, 0.75f, 0.1f)); return(hfActor); }
private PhysX.RigidDynamic CreateSphere(PhysX.Scene scene, int offset) { const float HEIGHT = 20.0f; var rigid = scene.Physics.CreateRigidDynamic(); var shape = rigid.CreateShape(new PhysX.SphereGeometry(1.0f), material); rigid.GlobalPose = PhysX.Math.Matrix.Translation(128f, 128f, HEIGHT + offset); rigid.AngularDamping = 0.2f; rigid.LinearDamping = 0.2f; return(rigid); }
private PhysX.HeightFieldGeometry CreateHfGeom(PhysX.Scene scene) { const int rows = 256, columns = 256; var samples = CreateSampleGrid(rows, columns); var heightFieldDesc = new PhysX.HeightFieldDesc() { NumberOfRows = rows, NumberOfColumns = columns, Samples = samples }; PhysX.HeightField heightField = scene.Physics.CreateHeightField(heightFieldDesc); PhysX.HeightFieldGeometry hfGeom = new PhysX.HeightFieldGeometry(heightField, 0, 1.0f, 1.0f, 1.0f); return(hfGeom); }
public MeshingStage(PhysX.Scene scene, OpenSim.Region.Physics.Manager.IMesher mesher, TerrainMesher terrainMesher) { _scene = scene; _mesher = mesher; _terrainMesher = terrainMesher; PhysX.CookingParams cookParms = new PhysX.CookingParams { SkinWidth = 0.025f, SuppressTriangleMeshRemapTable = true, TargetPlatform = PhysX.Platform.PC }; _cooking = _scene.Physics.CreateCooking(cookParms); _singleConvexHullCache.OnShapeNeedsFreeing += new ShapeCache.ShapeNeedsFreeingDelegate(_shapeCache_OnShapeNeedsFreeing); _acdHullCache.OnShapeNeedsFreeing += new ShapeCache.ShapeNeedsFreeingDelegate(_shapeCache_OnShapeNeedsFreeing); _trimeshCache.OnShapeNeedsFreeing += new ShapeCache.ShapeNeedsFreeingDelegate(_shapeCache_OnShapeNeedsFreeing); _runThread = new Thread(new ThreadStart(this.QueueProcessorLoop)); _runThread.Name = "MeshingStage"; _runThread.Start(); }
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 TerrainMesher(PhysX.Scene parentScene) { _scene = parentScene; _cooking = _scene.Physics.CreateCooking(); }
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 TerrainManager(PhysX.Scene scene, Meshing.TerrainMesher mesher, UUID regionId) { _scene = scene; _terrainMesher = mesher; _regionId = regionId; }
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(); } }