Esempio n. 1
0
        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());
        }
Esempio n. 2
0
 public void CloneTo(ShapeObject so, bool geometryOnly = true)
 {
     so.transform.position      = transform.position;
     so.transform.up            = transform.up;
     so.transform.localScale    = transform.localScale;
     so.transform.localRotation = transform.localRotation;
     so.meshable = (Meshable)(meshable.Clone());
     so.GetComponent <MeshFilter>().mesh = GetComponent <MeshFilter>().mesh;
     if (!geometryOnly)
     {
         so.name = name;
         so.step = step;
         //so.parentRule = parentRule;
     }
 }