void Start() { // Get a reference to the GameObject var go = nonProBuilderMesh.gameObject; // Add a new uninitialized pb_Object var pb = go.AddComponent <pb_Object>(); // Create a new ProBuilder MeshImporter var importer = new pb_MeshImporter(pb); // Import from a GameObject - in this case we're loading and assigning to the same GameObject, but you may // load and apply to different Objects as well. importer.Import(go); // Since we're loading and setting from the same object, it is necessary to create a new mesh to avoid // overwriting the mesh that is being read from. nonProBuilderMesh.sharedMesh = new Mesh(); // Do something with the pb_Object. Here we're extruding every face on the object by .25. pb.Extrude(pb.faces, ExtrudeMethod.IndividualFaces, .25f); // Apply the imported geometry to the pb_Object pb.ToMesh(); // Rebuild UVs, Collisions, Tangents, etc. pb.Refresh(); }
/// <summary> /// Cuts out the cutouts from the given object at the given position (relative to the object). /// </summary> public static void CutOutObjects(pb_Object o, List <Cutout> cuts) { o.ToMesh(); o.Refresh(); Vector3 oldPostion = o.transform.position; Quaternion oldRotation = o.transform.rotation; o.transform.position = Vector3.zero; o.transform.rotation = Quaternion.identity; GameObject tempObject = new GameObject(); MeshFilter mf = tempObject.AddComponent <MeshFilter>(); mf.mesh = new CSG_Model(o.gameObject).ToMesh(); foreach (Cutout c in cuts) { c.obj.transform.position = c.location; mf.mesh = CSG.Subtract(mf.gameObject, c.obj.gameObject); } pb_MeshImporter mI = new pb_MeshImporter(o); mI.Import(tempObject, pb_MeshImporter.Settings.Default); o.transform.position = oldPostion; o.transform.rotation = oldRotation; Object.DestroyImmediate(tempObject); }