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); }
protected List <ExploderMesh> CutSingleMesh(MeshObject mesh) { var randomPlaneNormal = new Vector3((float)random.NextDouble() * 2.0f - 1.0f, (float)random.NextDouble() * 2.0f - 1.0f, (float)random.NextDouble() * 2.0f - 1.0f); var plane = new Exploder.Plane(randomPlaneNormal, mesh.mesh.centroid); 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); return(meshes); }
private void Separate() { Debug.Assert(core.meshSet.Count == 1); Debug.DrawLine(core.parameters.HitPosition, core.parameters.HitPosition + core.parameters.ShotDir * 1000, Color.red, 10000); var mesh = core.meshSet.ElementAt(0); var plane = new Exploder.Plane(-core.parameters.ShotDir, core.parameters.HitPosition + core.parameters.ShotDir * 0.2f); List <ExploderMesh> meshes = null; 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; } cutter.Cut(mesh.mesh, mesh.transform, plane, triangulateHoles, core.parameters.DisableTriangulation, ref meshes, crossSectionVertexColour, crossSectionUV); core.meshSet.Clear(); if (meshes != null) { core.meshSet.Add(new MeshObject { mesh = meshes[0], material = mesh.material, transform = mesh.transform, id = mesh.id, original = mesh.original, skinnedOriginal = mesh.skinnedOriginal, parent = mesh.transform.parent, position = mesh.transform.position, rotation = mesh.transform.rotation, localScale = mesh.transform.localScale, option = mesh.option, }); var unityMesh = meshes[1].ToUnityMesh(); var meshFilter = mesh.original.GetComponent <MeshFilter>(); meshFilter.sharedMesh = unityMesh; } }
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); } }