Exemplo n.º 1
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;
        }
Exemplo n.º 2
0
        protected override unsafe ConvexHullDecompositionDataItem[] OnConvexHullDecomposite(
            Vec3[] vertices, int[] indices, int maxTrianglesInDecimatedMesh, int maxVerticesPerConvexHull)
        {
            if (hacdInstance == null)
            {
                hacdInstance = HACDWrapper.Init();
            }

            double[] points = new double[vertices.Length * 3];
            for (int n = 0; n < vertices.Length; n++)
            {
                points[n * 3 + 0] = vertices[n].X;
                points[n * 3 + 1] = vertices[n].Y;
                points[n * 3 + 2] = vertices[n].Z;
            }

            bool result;

            fixed(double *pPoints = points)
            {
                fixed(int *pIndices = indices)
                {
                    result = HACDWrapper.Compute(hacdInstance, pPoints, vertices.Length, pIndices,
                                                 indices.Length / 3, maxTrianglesInDecimatedMesh, maxVerticesPerConvexHull);
                }
            }

            if (!result)
            {
                return(null);
            }

            int clusterCount = HACDWrapper.GetClusterCount(hacdInstance);

            ConvexHullDecompositionDataItem[] items = new ConvexHullDecompositionDataItem[clusterCount];

            for (int nCluster = 0; nCluster < clusterCount; nCluster++)
            {
                int clusterPointCount;
                int clusterTriangleCount;
                HACDWrapper.GetBufferSize(hacdInstance, nCluster, out clusterPointCount,
                                          out clusterTriangleCount);

                double[] clusterPoints  = new double[clusterPointCount * 3];
                int[]    clusterIndices = new int[clusterTriangleCount * 3];

                fixed(double *pPoints = clusterPoints)
                {
                    fixed(int *pIndices = clusterIndices)
                    {
                        HACDWrapper.GetBuffer(hacdInstance, nCluster, pPoints, pIndices);
                    }
                }

                Vec3[] clusterVertices = new Vec3[clusterPointCount];
                for (int n = 0; n < clusterPointCount; n++)
                {
                    clusterVertices[n] = new Vec3(
                        (float)clusterPoints[n * 3 + 0],
                        (float)clusterPoints[n * 3 + 1],
                        (float)clusterPoints[n * 3 + 2]);
                }

                items[nCluster] = new ConvexHullDecompositionDataItem(clusterVertices, clusterIndices);
            }

            HACDWrapper.ClearComputed(hacdInstance);

            return(items);
        }