private List <Mesh> PreformOperation(CSG.BooleanOperations _operation) { if (m_csgSettings.m_makeUniqueMeshes) { MeshFilter filterA = m_componentA.GetComponent <MeshFilter>(); Mesh meshA = (Mesh)Instantiate(filterA.sharedMesh); filterA.mesh = meshA; MeshFilter filterB = m_componentB.GetComponent <MeshFilter>(); Mesh meshB = (Mesh)Instantiate(filterB.sharedMesh); filterB.mesh = meshB; } List <Mesh> resultantMeshes = new List <Mesh>(); switch (_operation) { case CSG.BooleanOperations.None: { break; } case CSG.BooleanOperations.Union: { SetOperation(CSG.BooleanOperations.None); resultantMeshes.AddRange(CSG.CSG.Union(m_componentA, m_componentB, m_csgMeshSettings)); break; } case CSG.BooleanOperations.Subtract: { SetOperation(CSG.BooleanOperations.None); resultantMeshes.AddRange(CSG.CSG.Subtract(m_componentA, m_componentB, m_csgMeshSettings)); break; } case CSG.BooleanOperations.Intersect: { SetOperation(CSG.BooleanOperations.None); resultantMeshes.AddRange(CSG.CSG.Intersect(m_componentA, m_componentB, m_csgMeshSettings)); break; } default: { Debug.Log("Not a valid operation"); break; } } return(resultantMeshes); }
private void Update() { if (m_currentOperation != m_previousOperation) { List <Mesh> resultantMeshes = PreformOperation(m_currentOperation); MakeObjectsFromMeshes(resultantMeshes); if (m_csgSettings.m_destroyComponents) { Destroy(m_componentA); Destroy(m_componentB); } m_previousOperation = m_currentOperation; } }
public void SetOperation(CSG.BooleanOperations _operation) { m_previousOperation = m_currentOperation; m_currentOperation = _operation; }