Esempio n. 1
0
        public unsafe void Create(int numThreads, uint[] affinityMasks)
        {
            //create native scene
            if (affinityMasks != null)
            {
                fixed(uint *pAffinityMasks = affinityMasks)
                {
                    nativeScene = PhysXNativeWorld.CreateScene(numThreads, (IntPtr)pAffinityMasks);
                }
            }
            else
            {
                nativeScene = PhysXNativeWorld.CreateScene(numThreads, IntPtr.Zero);
            }

            UpdateGravity();

            for (int group0 = 0; group0 < 32; group0++)
            {
                for (int group1 = 0; group1 < 32; group1++)
                {
                    OnUpdateContactGroups(group0, group1, IsContactGroupsContactable(group0, group1));
                }
            }
        }
Esempio n. 2
0
        unsafe protected override void _OnMeshGeometryDestroy(_MeshGeometry geometry)
        {
            base._OnMeshGeometryDestroy(geometry);

            if (geometry.UserData != null)
            {
                MeshGeometryPhysXData data = (MeshGeometryPhysXData)geometry.UserData;

                if (data.checkRefCounter != 0)
                {
                    Log.Fatal("PhysXPhysicsWorld: OnMeshGeometryDestroy: data.checkRefCounter != 0.");
                }

                if (data.convexMeshes != null)
                {
                    foreach (IntPtr mesh in data.convexMeshes)
                    {
                        if (mesh != IntPtr.Zero)
                        {
                            PhysXNativeWorld.ReleaseConvexMesh(mesh);
                        }
                    }
                    data.convexMeshes = null;
                }
                if (data.triangleMesh != IntPtr.Zero)
                {
                    PhysXNativeWorld.ReleaseTriangleMesh(data.triangleMesh);
                    data.triangleMesh = IntPtr.Zero;
                }
            }
        }
Esempio n. 3
0
        protected override void OnShutdownLibrary()
        {
            if (shapesDictionary.Count != 0)
            {
                Log.Warning("PhysXPhysicsWorld: OnShutdownLibrary: shapesDictionary.Count != 0.");
            }

            PhysXNativeWorld.Destroy();

            if (hacdInstance != null)
            {
                try
                {
                    HACDWrapper.Shutdown(hacdInstance);
                }
                catch { }
                hacdInstance = null;
            }

            instance = null;
        }
Esempio n. 4
0
 public void Destroy()
 {
     PhysXNativeWorld.DestroyScene(nativeScene);
     nativeScene = IntPtr.Zero;
 }
Esempio n. 5
0
        //static NxAssertResponse ReportAssertViolation( IntPtr pMessage, IntPtr pFile, int line )
        //{
        //   string message = Wrapper.GetOutString( pMessage );
        //   string file = Wrapper.GetOutString( pFile );

        //   if( file == null )
        //      file = "NULL";
        //   string text = string.Format( "PhysXPhysicsSystem: {0} ({1}:{2})", message, file, line );

        //   Log.Fatal( text );

        //   return NxAssertResponse.NX_AR_BREAKPOINT;
        //}

        protected override bool OnInitLibrary(bool allowHardwareAcceleration, bool editor)
        {
            instance = this;

            NativeLibraryManager.PreLoadLibrary("PhysXNativeWrapper");

            //change current directory for loading PhysX dlls from specified NativeDlls directory.
            string saveCurrentDirectory = null;

            if (PlatformInfo.Platform == PlatformInfo.Platforms.Windows)
            {
                saveCurrentDirectory = Directory.GetCurrentDirectory();
                Directory.SetCurrentDirectory(NativeLibraryManager.GetNativeLibrariesDirectory());
            }

            try
            {
                preventLogErrors = true;

                reportErrorDelegate = ReportError;
                logDelegate         = LogMessage;
                IntPtr errorStringPtr;
                if (!PhysXNativeWorld.Init(reportErrorDelegate, out errorStringPtr, logDelegate, skinWidth))
                {
                    string errorString = Wrapper.GetOutString(errorStringPtr);
                    if (string.IsNullOrEmpty(errorString))
                    {
                        errorString = "Unknown error.";
                    }
                    Log.Fatal("PhysX: Initialization error: " + errorString);
                    return(false);
                }

                preventLogErrors = false;
            }
            finally
            {
                //restore current directory
                if (PlatformInfo.Platform == PlatformInfo.Platforms.Windows)
                {
                    Directory.SetCurrentDirectory(saveCurrentDirectory);
                }
            }

            //configs
            if (VirtualFile.Exists("Base/Constants/PhysicsSystem.config"))
            {
                TextBlock block = TextBlockUtils.LoadFromVirtualFile("Base/Constants/PhysicsSystem.config");
                if (block != null)
                {
                    TextBlock physXBlock = block.FindChild("physXSpecific");
                    if (physXBlock != null)
                    {
                        if (physXBlock.IsAttributeExist("supportHeightFields"))
                        {
                            supportHeightFields = bool.Parse(physXBlock.GetAttribute("supportHeightFields"));
                        }

                        if (physXBlock.IsAttributeExist("supportVehicles"))
                        {
                            supportVehicles = bool.Parse(physXBlock.GetAttribute("supportVehicles"));
                        }

                        if (physXBlock.IsAttributeExist("writeCacheForCookedTriangleMeshes"))
                        {
                            writeCacheForCookedTriangleMeshes = bool.Parse(
                                physXBlock.GetAttribute("writeCacheForCookedTriangleMeshes"));
                        }

                        if (physXBlock.IsAttributeExist("mainSceneMaxThreads"))
                        {
                            mainSceneMaxThreads = int.Parse(physXBlock.GetAttribute("mainSceneMaxThreads"));
                        }
                    }
                }
            }

            return(true);
        }