/** * Helper function which will slice the provided object with the provided plane * and instantiate and return the final GameObjects * * This function will return null if the object failed to slice */ public static GameObject[] SliceInstantiate(GameObject obj, Plane pl, bool genCrossSection = true) { SlicedHull slice = Slice(obj, pl, genCrossSection); if (slice == null) { return(null); } GameObject upperHull = slice.CreateUpperHull(obj); GameObject lowerHull = slice.CreateLowerHull(obj); if (upperHull != null && lowerHull != null) { return(new GameObject[] { upperHull, lowerHull }); } // otherwise return only the upper hull if (upperHull != null) { return(new GameObject[] { upperHull }); } // otherwise return only the lower hull if (lowerHull != null) { return(new GameObject[] { lowerHull }); } // nothing to return, so return nothing! return(null); }
public static GameObject[] SliceInstantiate(this GameObject obj, Plane pl, TextureRegion cuttingRegion, Material crossSectionMaterial = null) { SlicedHull slice = Slicer.Slice(obj, pl, cuttingRegion, crossSectionMaterial); if (slice == null) { return(null); } GameObject upperHull = slice.CreateUpperHull(obj, crossSectionMaterial); GameObject lowerHull = slice.CreateLowerHull(obj, crossSectionMaterial); if (upperHull != null && lowerHull != null) { return(new GameObject[] { upperHull, lowerHull }); } // otherwise return only the upper hull if (upperHull != null) { return(new GameObject[] { upperHull }); } // otherwise return only the lower hull if (lowerHull != null) { return(new GameObject[] { lowerHull }); } // nothing to return, so return nothing! return(null); }
/** * Helper function which will slice the provided object with the provided plane * and instantiate and return the final GameObjects * * This function will return null if the object failed to slice */ public static GameObject[] SliceInstantiate(GameObject obj, Plane pl, bool genCrossSection = true) { SlicedHull slice = Slice(obj, pl, genCrossSection); if (slice == null) { return(null); } GameObject upperHull = slice.CreateUpperHull(); if (upperHull != null) { // set the positional information upperHull.transform.position = obj.transform.position; upperHull.transform.rotation = obj.transform.rotation; upperHull.transform.localScale = obj.transform.localScale; // the the material information upperHull.GetComponent <Renderer>().sharedMaterials = obj.GetComponent <MeshRenderer>().sharedMaterials; } GameObject lowerHull = slice.CreateLowerHull(); if (lowerHull != null) { // set the positional information lowerHull.transform.position = obj.transform.position; lowerHull.transform.rotation = obj.transform.rotation; lowerHull.transform.localScale = obj.transform.localScale; // the the material information lowerHull.GetComponent <Renderer>().sharedMaterials = obj.GetComponent <MeshRenderer>().sharedMaterials; } // return both if upper and lower hulls were generated if (upperHull != null && lowerHull != null) { return(new GameObject[] { upperHull, lowerHull }); } // otherwise return only the upper hull if (upperHull != null) { return(new GameObject[] { upperHull }); } // otherwise return null return(null); }