public static Meshable[] DivideFormByDivsRatio(Meshable mb, float[] divs, int axis) { List <Meshable> outMeshable = new List <Meshable>(); if (divs.Length == 0) { outMeshable.Add((Meshable)mb.Clone()); return(outMeshable.ToArray()); } Vector3 n = mb.bbox.vects[axis]; //Debug.Log("n=" + n); Vector3 org = mb.bbox.vertices[0]; Vector3 offset = n * divs[0] * mb.bbox.size[axis]; org += offset; //Debug.Log("offset=" + offset); Plane pln = new Plane(n, org); Meshable[] splits = mb.SplitByPlane(pln); if (splits[0] != null) { splits[0].bbox = BoundingBox.CreateFromPoints(splits[0].vertices, mb.bbox); outMeshable.Add(splits[0]); } else { throw new System.Exception("splits[0] is null!"); } Meshable remain = splits[1]; int counter = 0; while (remain != null && counter < divs.Length) { org += offset; //Debug.Log("org=" + org); pln = new Plane(n, org); splits = remain.SplitByPlane(pln); //splits = Rules.Bisect.SplitByPlane(remain, pln); if (splits[0] != null) { splits[0].bbox = BoundingBox.CreateFromPoints(splits[0].vertices, mb.bbox); outMeshable.Add(splits[0]); } else { break; //throw new System.Exception("splits[0] is null!"); } remain = splits[1]; counter++; } return(outMeshable.ToArray()); }
public static List <Meshable> SplitByPlane(Meshable mb, Plane pln) { List <Meshable> outs = new List <Meshable>(); //get the splited meshables Meshable[] temp = new Meshable[0]; temp = mb.SplitByPlane(pln); for (int i = 0; i < temp.Length; i++) { if (temp[i] != null) { //Debug.Log("---------------------->creating boundong box"); temp[i].bbox = BoundingBox.CreateFromPoints(temp[i].vertices, mb.bbox); outs.Add(temp[i]); } } return(outs); }
public Meshable CutShapeObjectToFloors(Meshable form, float h, out Meshable remain) { //add cuted meshables to floor and return the remaining meshable Vector3 bot = ((Extrusion)form).polygon.vertices[0]; Plane? cutter = null; if (h > bot.y) { cutter = new Plane(Vector3.up, new Vector3(0, h, 0)); } if (cutter.HasValue) { Meshable[] splits = form.SplitByPlane(cutter.Value); remain = splits[1]; if (splits[0] != null) { return(splits[0]); } } remain = null; return(null); }