Exemplo n.º 1
0
            public void Execute(MeshingStage meshingStage)
            {
                Tuple <PhysX.Math.Vector3[], int[]>      data        = meshingStage._terrainMesher.GenerateTrimeshDataFromHeightmap(Terrain);
                Tuple <PhysX.TriangleMesh, MemoryStream> trimeshData = meshingStage._terrainMesher.GenerateTrimeshFromIndexedTriangles(data.Item1, data.Item2);

                CompleteCallback(trimeshData);
            }
Exemplo n.º 2
0
            private void GenerateBasicShapeAndComplete(MeshingStage meshingStage, ulong meshHash)
            {
                Tuple <PhysX.Geometry, ShapeType> result = meshingStage.GenerateBasicPhysXShape(Shape);
                PhysicsShape phyShape = new PhysicsShape(result.Item1, result.Item2, meshHash);

                //basic shapes are not cached

                //we are done here, call back to caller
                this.CompletedDelegate(phyShape);
            }
Exemplo n.º 3
0
            private static PhysicsShape CreatePhysicsShapeFromTrimeshAndCache(MeshingStage meshingStage, ulong meshHash, PhysX.TriangleMeshGeometry triMesh)
            {
                PhysicsShape phyShape;

                phyShape = new PhysicsShape(triMesh, ShapeType.TriMesh, meshHash);
                phyShape.AddRef();

                //complex shapes are cached
                meshingStage.CacheShape(meshHash, phyShape, ShapeType.TriMesh);
                return(phyShape);
            }
Exemplo n.º 4
0
            private static PhysicsShape CreatePhysicsShapeFromConvexSetAndCache(MeshingStage meshingStage, ulong meshHash, List <PhysX.ConvexMeshGeometry> convexes)
            {
                PhysicsShape phyShape;

                phyShape            = new PhysicsShape(convexes, meshHash);
                phyShape.Complexity = convexes.Count;
                phyShape.AddRef();

                //complex shapes are cached
                meshingStage.CacheShape(meshHash, phyShape, ShapeType.DecomposedConvexHulls);
                return(phyShape);
            }
Exemplo n.º 5
0
            private static PhysicsShape CreatePhysicsShapeFromSingleConvexAndCache(MeshingStage meshingStage, ulong meshHash, PhysX.ConvexMeshGeometry convex)
            {
                PhysicsShape phyShape;

                phyShape = new PhysicsShape(new List <PhysX.ConvexMeshGeometry> {
                    convex
                }, meshHash, true);
                phyShape.AddRef();

                //complex shapes are cached
                meshingStage.CacheShape(meshHash, phyShape, ShapeType.SingleConvex);
                return(phyShape);
            }
Exemplo n.º 6
0
 public void Execute(MeshingStage meshingStage)
 {
     if (Shape != null && Shape.DecRef() == 0)
     {
         if (Shape.Type == ShapeType.PrimitiveBox || Shape.Type == ShapeType.PrimitiveSphere ||
             Shape.Type == ShapeType.Null)
         {
             //primitive shapes are not cached
             Shape.Dispose();
         }
         else
         {
             meshingStage.UncacheShape(Shape.Hash, Shape, Shape.Type);
         }
     }
 }
Exemplo n.º 7
0
            private void GenerateTrimeshAndComplete(MeshingStage meshingStage, ulong meshHash)
            {
                PhysicsShape phyShape;

                PhysX.TriangleMeshGeometry triMesh = meshingStage.GeneratePhysXTrimeshShape(PrimName, Shape, Size, MeshingStage.SCULPT_MESH_LOD, IsDynamic);

                if (triMesh == null)
                {
                    //meshing  or one of its prereq steps failed, generate a bounding box
                    PhysX.Geometry geom = meshingStage.GeneratePhysXBoxShape(Shape);
                    //basic shapes are not cached
                    phyShape = new PhysicsShape(geom, ShapeType.PrimitiveBox, meshHash);
                }
                else
                {
                    phyShape = CreatePhysicsShapeFromTrimeshAndCache(meshingStage, meshHash, triMesh);
                }

                //we are done here, call back to caller
                this.CompletedDelegate(phyShape);
            }
Exemplo n.º 8
0
            public void Execute(MeshingStage meshingStage)
            {
                //short circuit null shapes
                if (Shape.PreferredPhysicsShape == OpenMetaverse.PhysicsShapeType.None)
                {
                    this.CompletedDelegate(PhysicsShape.Null);
                    return;
                }

                ulong meshHash = Shape.GetMeshKey(Size, MeshingStage.SCULPT_MESH_LOD);

                //check to see if we have this shape in the cache
                PhysicsShape phyShape;

                if (meshingStage.TryGetCachedShape(meshHash, Shape, IsDynamic, out phyShape))
                {
                    phyShape.AddRef();

                    //we are done here, call back to caller
                    this.CompletedDelegate(phyShape);

                    return;
                }

                int meshingBegan = Environment.TickCount;

                var bestShape = ShapeDeterminer.FindBestShape(Shape, IsDynamic);

                //first try to extract serialized shapes
                if (!TryExtractSerializedShapes(meshingStage, meshHash, bestShape))
                {
                    //failure, generate
                    GenerateShapes(meshingStage, meshHash, bestShape);
                }

                if (Settings.Instance.InstrumentMeshing)
                {
                    m_log.InfoFormat("[STATS]: PHYSX_MESHING_TIME,{0},{1}", bestShape, Environment.TickCount - meshingBegan);
                }
            }
Exemplo n.º 9
0
            private void GenerateConvexSetAndComplete(MeshingStage meshingStage, ulong meshHash)
            {
                PhysicsShape phyShape;

                //we need to mesh this object into convex hulls appropriate for dynamic objects
                List <PhysX.ConvexMeshGeometry> convexes = meshingStage.GenerateComplexPhysXShape(meshHash, PrimName, Shape, Size, MeshingStage.SCULPT_MESH_LOD, IsDynamic);

                if (convexes == null)
                {
                    //meshing  or one of its prereq steps failed, generate a bounding box
                    PhysX.Geometry geom = meshingStage.GeneratePhysXBoxShape(Shape);
                    //basic shapes are not cached
                    phyShape = new PhysicsShape(geom, ShapeType.PrimitiveBox, meshHash);
                }
                else
                {
                    phyShape = CreatePhysicsShapeFromConvexSetAndCache(meshingStage, meshHash, convexes);
                }

                //we are done here, call back to caller
                this.CompletedDelegate(phyShape);
            }
Exemplo n.º 10
0
            public void Execute(MeshingStage meshingStage)
            {
                //short circuit null shapes
                if (Shape.PreferredPhysicsShape == OpenMetaverse.PhysicsShapeType.None)
                {
                    this.CompletedDelegate(PhysicsShape.Null);
                    return;
                }

                ulong meshHash = Shape.GetMeshKey(Size, MeshingStage.SCULPT_MESH_LOD);

                //check to see if we have this shape in the cache
                PhysicsShape phyShape;
                if (meshingStage.TryGetCachedShape(meshHash, Shape, IsDynamic, out phyShape))
                {
                    phyShape.AddRef();

                    //we are done here, call back to caller
                    this.CompletedDelegate(phyShape);

                    return;
                }

                int meshingBegan = Environment.TickCount;

                var bestShape = ShapeDeterminer.FindBestShape(Shape, IsDynamic);

                //first try to extract serialized shapes 
                if (!TryExtractSerializedShapes(meshingStage, meshHash, bestShape))
                {
                    //failure, generate
                    GenerateShapes(meshingStage, meshHash, bestShape);
                }

                if (Settings.Instance.InstrumentMeshing)
                {
                    m_log.InfoFormat("[STATS]: PHYSX_MESHING_TIME,{0},{1}", bestShape, Environment.TickCount - meshingBegan);
                }
            }
Exemplo n.º 11
0
            private void GenerateShapes(MeshingStage meshingStage, ulong meshHash, ShapeType bestShape)
            {
                //if we've gotten here, and this is from a crossing, we must have the
                //serialized physics shape data. if for whatever reason we don't, we
                //need to fall back to a basic shape to prevent the crossing from
                //trying to pull assets while we're trying to move an object to the
                //new region
                if (FromCrossing)
                {
                    bestShape = ShapeType.PrimitiveBox;
                }

                switch (bestShape)
                {
                case ShapeType.PrimitiveBox:
                case ShapeType.PrimitiveSphere:
                    this.GenerateBasicShapeAndComplete(meshingStage, meshHash);
                    break;

                case ShapeType.DecomposedConvexHulls:
                    this.GenerateConvexSetAndComplete(meshingStage, meshHash);
                    break;

                case ShapeType.TriMesh:
                    this.GenerateTrimeshAndComplete(meshingStage, meshHash);
                    break;

                case ShapeType.SingleConvex:
                    this.GenerateSingleConvexAndComplete(meshingStage, meshHash);
                    break;

                case ShapeType.Null:
                    this.CompletedDelegate(PhysicsShape.Null);
                    break;

                default:
                    throw new ArgumentException("Unable to generate an appropriate PhysX shape for the given parameters");
                }
            }
Exemplo n.º 12
0
            private static PhysicsShape CreatePhysicsShapeFromConvexSetAndCache(MeshingStage meshingStage, ulong meshHash, List<PhysX.ConvexMeshGeometry> convexes)
            {
                PhysicsShape phyShape;
                phyShape = new PhysicsShape(convexes, meshHash);
                phyShape.Complexity = convexes.Count;
                phyShape.AddRef();

                //complex shapes are cached
                meshingStage.CacheShape(meshHash, phyShape, ShapeType.DecomposedConvexHulls);
                return phyShape;
            }
Exemplo n.º 13
0
            private void GenerateBasicShapeAndComplete(MeshingStage meshingStage, ulong meshHash)
            {
                Tuple<PhysX.Geometry, ShapeType> result = meshingStage.GenerateBasicPhysXShape(Shape);
                PhysicsShape phyShape = new PhysicsShape(result.Item1, result.Item2, meshHash);

                //basic shapes are not cached

                //we are done here, call back to caller
                this.CompletedDelegate(phyShape);
            }
Exemplo n.º 14
0
            private void GenerateConvexSetAndComplete(MeshingStage meshingStage, ulong meshHash)
            {
                PhysicsShape phyShape;

                //we need to mesh this object into convex hulls appropriate for dynamic objects
                List<PhysX.ConvexMeshGeometry> convexes = meshingStage.GenerateComplexPhysXShape(meshHash, PrimName, Shape, Size, MeshingStage.SCULPT_MESH_LOD, IsDynamic);

                if (convexes == null)
                {
                    //meshing  or one of its prereq steps failed, generate a bounding box
                    PhysX.Geometry geom = meshingStage.GeneratePhysXBoxShape(Shape);
                    //basic shapes are not cached
                    phyShape = new PhysicsShape(geom, ShapeType.PrimitiveBox, meshHash);
                }
                else
                {
                    phyShape = CreatePhysicsShapeFromConvexSetAndCache(meshingStage, meshHash, convexes);
                }

                //we are done here, call back to caller
                this.CompletedDelegate(phyShape);
            }
Exemplo n.º 15
0
            private static PhysicsShape CreatePhysicsShapeFromTrimeshAndCache(MeshingStage meshingStage, ulong meshHash, PhysX.TriangleMeshGeometry triMesh)
            {
                PhysicsShape phyShape;
                phyShape = new PhysicsShape(triMesh, ShapeType.TriMesh, meshHash);
                phyShape.AddRef();

                //complex shapes are cached
                meshingStage.CacheShape(meshHash, phyShape, ShapeType.TriMesh);
                return phyShape;
            }
Exemplo n.º 16
0
            private void GenerateTrimeshAndComplete(MeshingStage meshingStage, ulong meshHash)
            {
                PhysicsShape phyShape;
                PhysX.TriangleMeshGeometry triMesh = meshingStage.GeneratePhysXTrimeshShape(PrimName, Shape, Size, MeshingStage.SCULPT_MESH_LOD, IsDynamic);

                if (triMesh == null)
                {
                    //meshing  or one of its prereq steps failed, generate a bounding box
                    PhysX.Geometry geom = meshingStage.GeneratePhysXBoxShape(Shape);
                    //basic shapes are not cached
                    phyShape = new PhysicsShape(geom, ShapeType.PrimitiveBox, meshHash);
                }
                else
                {
                    phyShape = CreatePhysicsShapeFromTrimeshAndCache(meshingStage, meshHash, triMesh);
                }

                //we are done here, call back to caller
                this.CompletedDelegate(phyShape);
            }
Exemplo n.º 17
0
 public void Execute(MeshingStage meshingStage)
 {
     if (Shape != null && Shape.DecRef() == 0)
     {
         if (Shape.Type == ShapeType.PrimitiveBox || Shape.Type == ShapeType.PrimitiveSphere
             || Shape.Type == ShapeType.Null)
         {
             //primitive shapes are not cached
             Shape.Dispose();
         }
         else
         {
             meshingStage.UncacheShape(Shape.Hash, Shape, Shape.Type);
         }
     }
 }
Exemplo n.º 18
0
        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);
        }
Exemplo n.º 19
0
            public void Execute(MeshingStage meshingStage)
            {
                Tuple<PhysX.Math.Vector3[], int[]> data = meshingStage._terrainMesher.GenerateTrimeshDataFromHeightmap(Terrain);
                Tuple<PhysX.TriangleMesh, MemoryStream> trimeshData = meshingStage._terrainMesher.GenerateTrimeshFromIndexedTriangles(data.Item1, data.Item2);

                CompleteCallback(trimeshData);
            }
Exemplo n.º 20
0
            private bool TryExtractSerializedShapes(MeshingStage meshingStage, ulong meshHash, ShapeType bestShape)
            {
                if (SerializedShapes == null)
                {
                    return(false);
                }
                if (bestShape != ShapeType.TriMesh && bestShape != ShapeType.DecomposedConvexHulls && bestShape != ShapeType.SingleConvex)
                {
                    return(false);                                                                                                                       //we only handle these types
                }
                using (PhysX.Collection coll = meshingStage._scene.Physics.CreateCollection())
                {
                    using (MemoryStream ms = new MemoryStream(SerializedShapes))
                    {
                        if (!coll.Deserialize(ms))
                        {
                            m_log.Warn("[InWorldz.PhysxPhysics]: Geometry deserialization failed");
                            return(false);
                        }
                    }

                    if (coll.DeserializedObjects.Count > 0)
                    {
                        PhysicsShape phyShape;

                        if (coll.DeserializedObjects[0] is PhysX.ConvexMesh)
                        {
                            List <PhysX.ConvexMesh> target = new List <PhysX.ConvexMesh>(coll.DeserializedObjects.Cast <PhysX.ConvexMesh>());
                            var geoms = new List <PhysX.ConvexMeshGeometry>(target.Select(item => new PhysX.ConvexMeshGeometry(item)));

                            if (bestShape == ShapeType.DecomposedConvexHulls)
                            {
                                phyShape = CreatePhysicsShapeFromConvexSetAndCache(meshingStage, meshHash, geoms);
                            }
                            else if (bestShape == ShapeType.SingleConvex)
                            {
                                phyShape = CreatePhysicsShapeFromSingleConvexAndCache(meshingStage, meshHash, geoms[0]);
                            }
                            else
                            {
                                m_log.Warn("[InWorldz.PhysxPhysics]: Serialized geoms were convex, but best shape doesnt match");
                                return(false);
                            }
                        }
                        else if (coll.DeserializedObjects[0] is PhysX.TriangleMesh)
                        {
                            List <PhysX.TriangleMesh> target = new List <PhysX.TriangleMesh>(coll.DeserializedObjects.Cast <PhysX.TriangleMesh>());
                            var geoms = new List <PhysX.TriangleMeshGeometry>(target.Select(item => new PhysX.TriangleMeshGeometry(item)));

                            if (target.Count == 1)
                            {
                                phyShape = CreatePhysicsShapeFromTrimeshAndCache(meshingStage, meshHash, geoms[0]);
                            }
                            else
                            {
                                m_log.Warn("[InWorldz.PhysxPhysics]: Oddity. Got more than one serialized trimesh back");
                                return(false);
                            }
                        }
                        else
                        {
                            m_log.Warn("[InWorldz.PhysxPhysics]: Oddity. Serialized geoms weren't convex or trimesh");
                            return(false);
                        }

                        this.CompletedDelegate(phyShape);
                        return(true);
                    }
                    else
                    {
                        //no geom?
                        m_log.Warn("[InWorldz.PhysxPhysics]: Oddity. Didnt find any geom even though we were supplied with a serialized collection");
                        return(false);
                    }
                }
            }
Exemplo n.º 21
0
            private bool TryExtractSerializedShapes(MeshingStage meshingStage, ulong meshHash, ShapeType bestShape)
            {
                if (SerializedShapes == null) return false;
                if (bestShape != ShapeType.TriMesh && bestShape != ShapeType.DecomposedConvexHulls && bestShape != ShapeType.SingleConvex) return false; //we only handle these types

                using (PhysX.Collection coll = meshingStage._scene.Physics.CreateCollection())
                {
                    using (MemoryStream ms = new MemoryStream(SerializedShapes))
                    {
                        if (! coll.Deserialize(ms))
                        {
                            m_log.Warn("[InWorldz.PhysxPhysics]: Geometry deserialization failed");
                            return false;
                        }
                    }

                    if (coll.DeserializedObjects.Count > 0)
                    {
                        PhysicsShape phyShape;

                        if (coll.DeserializedObjects[0] is PhysX.ConvexMesh)
                        {
                            List<PhysX.ConvexMesh> target = new List<PhysX.ConvexMesh>(coll.DeserializedObjects.Cast<PhysX.ConvexMesh>());
                            var geoms = new List<PhysX.ConvexMeshGeometry>(target.Select(item => new PhysX.ConvexMeshGeometry(item)));

                            if (bestShape == ShapeType.DecomposedConvexHulls)
                            {
                                phyShape = CreatePhysicsShapeFromConvexSetAndCache(meshingStage, meshHash, geoms);
                            }
                            else if (bestShape == ShapeType.SingleConvex)
                            {
                                phyShape = CreatePhysicsShapeFromSingleConvexAndCache(meshingStage, meshHash, geoms[0]);
                            }
                            else
                            {
                                m_log.Warn("[InWorldz.PhysxPhysics]: Serialized geoms were convex, but best shape doesnt match");
                                return false;
                            }
                        }
                        else if (coll.DeserializedObjects[0] is PhysX.TriangleMesh)
                        {
                            List<PhysX.TriangleMesh> target = new List<PhysX.TriangleMesh>(coll.DeserializedObjects.Cast<PhysX.TriangleMesh>());
                            var geoms = new List<PhysX.TriangleMeshGeometry>(target.Select(item => new PhysX.TriangleMeshGeometry(item)));

                            if (target.Count == 1)
                            {
                                phyShape = CreatePhysicsShapeFromTrimeshAndCache(meshingStage, meshHash, geoms[0]);
                            }
                            else
                            {
                                m_log.Warn("[InWorldz.PhysxPhysics]: Oddity. Got more than one serialized trimesh back");
                                return false;
                            }
                        }
                        else
                        {
                            m_log.Warn("[InWorldz.PhysxPhysics]: Oddity. Serialized geoms weren't convex or trimesh");
                            return false;
                        }

                        this.CompletedDelegate(phyShape);
                        return true;
                    }
                    else
                    {
                        //no geom?
                        m_log.Warn("[InWorldz.PhysxPhysics]: Oddity. Didnt find any geom even though we were supplied with a serialized collection");
                        return false;
                    }
                }
            }
Exemplo n.º 22
0
            private void GenerateShapes(MeshingStage meshingStage, ulong meshHash, ShapeType bestShape)
            {
                //if we've gotten here, and this is from a crossing, we must have the 
                //serialized physics shape data. if for whatever reason we don't, we
                //need to fall back to a basic shape to prevent the crossing from 
                //trying to pull assets while we're trying to move an object to the
                //new region
                if (FromCrossing)
                {
                    bestShape = ShapeType.PrimitiveBox;
                }

                switch (bestShape)
                {
                    case ShapeType.PrimitiveBox:
                    case ShapeType.PrimitiveSphere:
                        this.GenerateBasicShapeAndComplete(meshingStage, meshHash);
                        break;

                    case ShapeType.DecomposedConvexHulls:
                        this.GenerateConvexSetAndComplete(meshingStage, meshHash);
                        break;

                    case ShapeType.TriMesh:
                        this.GenerateTrimeshAndComplete(meshingStage, meshHash);
                        break;

                    case ShapeType.SingleConvex:
                        this.GenerateSingleConvexAndComplete(meshingStage, meshHash);
                        break;

                    case ShapeType.Null:
                        this.CompletedDelegate(PhysicsShape.Null);
                        break;

                    default:
                        throw new ArgumentException("Unable to generate an appropriate PhysX shape for the given parameters");
                }
            }
Exemplo n.º 23
0
        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);
        }
Exemplo n.º 24
0
            private static PhysicsShape CreatePhysicsShapeFromSingleConvexAndCache(MeshingStage meshingStage, ulong meshHash, PhysX.ConvexMeshGeometry convex)
            {
                PhysicsShape phyShape;
                phyShape = new PhysicsShape(new List<PhysX.ConvexMeshGeometry> { convex }, meshHash, true);
                phyShape.AddRef();

                //complex shapes are cached
                meshingStage.CacheShape(meshHash, phyShape, ShapeType.SingleConvex);
                return phyShape;
            }