示例#1
0
        protected List <ExploderMesh> CutSingleMesh(MeshObject mesh)
        {
            var plane = cuttingPlane.GetPlane(mesh.mesh, cutAttempt);

            var triangulateHoles         = true;
            var crossSectionVertexColour = Color.white;
            var crossSectionUV           = new Vector4(0, 0, 1, 1);

            if (mesh.option)
            {
                triangulateHoles         = !mesh.option.Plane2D;
                crossSectionVertexColour = mesh.option.CrossSectionVertexColor;
                crossSectionUV           = mesh.option.CrossSectionUV;
                core.splitMeshIslands   |= mesh.option.SplitMeshIslands;
            }

            if (core.parameters.Use2DCollision)
            {
                triangulateHoles = false;
            }

            triangulateHoles &= !core.parameters.DisableTriangulation;

            List <ExploderMesh> meshes = null;

            cutter.Cut(mesh.mesh, mesh.transform, plane, triangulateHoles, core.parameters.DisableTriangulation, ref meshes, crossSectionVertexColour, crossSectionUV);

            if (meshes == null)
            {
                cutAttempt++;
            }

            return(meshes);
        }
示例#2
0
        private void Cut()
        {
            bool cutting      = true;
            var  cycleCounter = 0;

            cutAttempt = 0;

            while (cutting)
            {
                cycleCounter++;

                if (cycleCounter > core.parameters.TargetFragments)
                {
                    ExploderUtils.Log("Explode Infinite loop!");
                    break;
                }

                newFragments.Clear();
                meshToRemove.Clear();

                cutting = false;

                foreach (var mesh in meshSet)
                {
                    if (core.targetFragments[mesh.id] > 1)
                    {
                        var plane = cuttingPlane.GetPlane(mesh.mesh, cutAttempt);

                        var triangulateHoles         = true;
                        var crossSectionVertexColour = Color.white;
                        var crossSectionUV           = new Vector4(0, 0, 1, 1);

                        if (mesh.option)
                        {
                            triangulateHoles         = !mesh.option.Plane2D;
                            crossSectionVertexColour = mesh.option.CrossSectionVertexColor;
                            crossSectionUV           = mesh.option.CrossSectionUV;
                            core.splitMeshIslands   |= mesh.option.SplitMeshIslands;
                        }

                        if (core.parameters.Use2DCollision)
                        {
                            triangulateHoles = false;
                        }

                        List <ExploderMesh> meshes = null;
                        cutter.Cut(mesh.mesh, mesh.transform, plane, triangulateHoles, core.parameters.DisableTriangulation, ref meshes, crossSectionVertexColour, crossSectionUV);

                        cutting = true;

                        if (meshes != null)
                        {
                            foreach (var cutterMesh in meshes)
                            {
                                newFragments.Add(new MeshObject
                                {
                                    mesh = cutterMesh,

                                    material        = mesh.material,
                                    transform       = mesh.transform,
                                    id              = mesh.id,
                                    original        = mesh.original,
                                    skinnedOriginal = mesh.skinnedOriginal,
                                    bakeObject      = mesh.bakeObject,

                                    parent     = mesh.transform.parent,
                                    position   = mesh.transform.position,
                                    rotation   = mesh.transform.rotation,
                                    localScale = mesh.transform.localScale,

                                    option = mesh.option,
                                });
                            }

                            meshToRemove.Add(mesh);
                            core.targetFragments[mesh.id] -= 1;
                        }
                        else
                        {
                            cutAttempt++;
                        }
                    }
                }

                meshSet.ExceptWith(meshToRemove);
                meshSet.UnionWith(newFragments);
            }
        }