private void _Voronoi(NvFractureTool fractureTool, NvMesh mesh)
    {
        NvVoronoiSitesGenerator sites = new NvVoronoiSitesGenerator(mesh);

        sites.uniformlyGenerateSitesInMesh(totalChunks);
        fractureTool.voronoiFracturing(0, sites);
    }
Пример #2
0
        private static List <Mesh> FractureMeshesInNvblast(int totalChunks, NvMesh nvMesh)
        {
            var fractureTool = new NvFractureTool();

            fractureTool.setRemoveIslands(false);
            fractureTool.setSourceMesh(nvMesh);
            var sites = new NvVoronoiSitesGenerator(nvMesh);

            sites.uniformlyGenerateSitesInMesh(totalChunks);
            fractureTool.voronoiFracturing(0, sites);
            fractureTool.finalizeFracturing();

            // Extract meshes
            var meshCount = fractureTool.getChunkCount();
            var meshes    = new List <Mesh>(fractureTool.getChunkCount());

            for (var i = 1; i < meshCount; i++)
            {
                meshes.Add(ExtractChunkMesh(fractureTool, i));
            }

            return(meshes);
        }
    private void _Visualize()
    {
        NvBlastExtUnity.setSeed(seed);

        CleanUp();
        if (source == null)
        {
            return;
        }

        GameObject ps = new GameObject("POINTS");

        ps.transform.position   = Vector3.zero;
        ps.transform.rotation   = Quaternion.identity;
        ps.transform.localScale = Vector3.one;

        Mesh ms = null;

        MeshFilter          mf  = source.GetComponent <MeshFilter>();
        SkinnedMeshRenderer smr = source.GetComponent <SkinnedMeshRenderer>();

        if (mf != null)
        {
            ms = source.GetComponent <MeshFilter>().sharedMesh;
        }
        if (smr != null)
        {
            smr.gameObject.transform.position   = Vector3.zero;
            smr.gameObject.transform.rotation   = Quaternion.identity;
            smr.gameObject.transform.localScale = Vector3.one;
            ms = new Mesh();
            smr.BakeMesh(ms);
            //ms = smr.sharedMesh;
            //OYM:储存mesh
        }

        if (ms == null)
        {
            return;
        }

        NvMesh mymesh = new NvMesh(ms.vertices, ms.normals, ms.uv, ms.vertexCount, ms.GetIndices(0), (int)ms.GetIndexCount(0));//OYM:这里是把mesh丢给一个dll并返回一个intptr

        NvVoronoiSitesGenerator sites = new NvVoronoiSitesGenerator(mymesh);

        //OYM:根据IntPtr获取voronoiSites
        if (fractureType == FractureTypes.Voronoi)
        {
            sites.uniformlyGenerateSitesInMesh(totalChunks);                                       //OYM:裂开
        }
        if (fractureType == FractureTypes.Clustered)
        {
            sites.clusteredSitesGeneration(clusters, sitesPerCluster, clusterRadius);                                         //OYM:拥挤
        }
        if (fractureType == FractureTypes.Skinned)
        {
            sites.boneSiteGeneration(smr); //OYM:骨骼
        }
        Vector3[] vs = sites.getSites();   //OYM:获取..我也不知道啥

        for (int i = 0; i < vs.Length; i++)
        {
            GameObject po = Instantiate(point, vs[i], Quaternion.identity, ps.transform); //OYM:把这些点标记出来
            po.hideFlags = HideFlags.NotEditable;                                         //OYM:不可车裂
        }

        ps.transform.rotation = source.transform.rotation;//OYM:把坐标拷走?
        ps.transform.position = source.transform.position;
    }