Example #1
0
    public void SetMeshables(List <Meshable> mbs)
    {
        int diff = forms.Count - mbs.Count;

        for (int i = 0; i < diff; i++)
        {
            try
            {
                int index = forms.Count - 1;
                GameObject.Destroy(forms[index].gameObject);
                forms.RemoveAt(index);
            }
            catch { Debug.Log("Exception"); }
        }

        for (int i = 0; i < mbs.Count; i++)
        {
            if (i >= forms.Count)
            {
                forms.Add(ShapeObject.CreateMeshable(mbs[i]));
            }
            else
            {
                forms[i].SetMeshable(mbs[i]);
            }
            forms[i].name = "floor";
        }
    }
Example #2
0
        public void UpdateOutputShapes()
        {
            //List<string> newNames = new List<string>();
            //destroy extra shapes
            //Debug.Log(string.Format("{0} outputShapes:{1}, mesable:{2}", name, outputs.shapes.Count, outMeshables.Count));
            removeExtraOutputs();

            //update output shapes
            int shapeCount = outputs.shapes.Count;

            for (int i = 0; i < outMeshables.Count; i++)
            {
                Meshable mb = outMeshables[i];
                if (i < shapeCount)
                {
                    outputs.shapes[i].SetMeshable(mb);
                    outputs.shapes[i].name       = mb.name;
                    outputs.shapes[i].parentRule = this;
                    outputs.shapes[i].step       = step;
                    outputs.shapes[i].Invalidate();
                }//end if
                else
                {
                    ShapeObject so = ShapeObject.CreateMeshable(mb);
                    so.name       = mb.name;
                    so.parentRule = this;
                    so.step       = step;
                    outputs.shapes.Add(so);
                }
            }//end for i
             //Debug.Log(string.Format("{0} outputShapes:{1}, mesable:{2}", name, outputs.shapes.Count, outMeshables.Count));
        }
Example #3
0
    // Use this for initialization
    void Start()
    {
        Vector3[] pts = new Vector3[]
        {
            new Vector3(),
            new Vector3(100, 0, 0),
            new Vector3(100, 0, 100),
            new Vector3(0, 0, 100)
        };


        Meshable ext = new Extrusion(pts, 100);

        ext.bbox = BoundingBox.CreateFromPoints(ext.vertices, new Vector3(1, 0, 0));
        Meshable[] splits = ext.SplitByPlane(new Plane(Vector3.up, new Vector3(0, 20, 0)));

        ShapeObject A = ShapeObject.CreateMeshable(splits[0]);
        ShapeObject B = ShapeObject.CreateMeshable(splits[1]);

        A.name = "A";
        B.name = "B";

        Debug.Log("A=" + A.meshable.ToString() + " " + A.meshable.GetType().ToString() + A.meshable.bbox.position);
        Debug.Log("B=" + B.meshable.ToString() + " " + B.meshable.GetType().ToString() + B.meshable.bbox.position);

        splits = SGUtility.DivideFormToLength(B.meshable, 4, 1);
        foreach (Meshable m in splits)
        {
            ShapeObject.CreateMeshable(m);
        }
    }
Example #4
0
 public void SetForm(Meshable mb, ShapeObject parent)
 {
     if (!forms.ContainsKey(parent))
     {
         forms[parent] = ShapeObject.CreateMeshable(mb);
     }
     else
     {
         forms[parent].SetMeshable(mb);
     }
     forms[parent].name = "floor_form";
 }
Example #5
0
    // Use this for initialization
    void Start()
    {
        pts = initShape1();
        Polygon pg = new Polygon(pts);

        ShapeObject init = ShapeObject.CreateMeshable(pg);

        init.name = "init";

        Meshable[] pgs = pg.Offset(10, true);
        foreach (Meshable g in pgs)
        {
            ShapeObject.CreateMeshable(g);
        }
    }
Example #6
0
    // Use this for initialization
    void Start()
    {
        Vector3[]   pts = initShape1();
        Polygon     pg  = new Polygon(pts);
        ShapeObject pgo = ShapeObject.CreatePolygon(pts);
        Form        f   = pg.ExtrudeToForm(new Vector3(0, 40, 0));

        ShapeObject rf = ShapeObject.CreateMeshable(f);

        rf.name = "rf";

        //ShapeObject so = ShapeObject.CreateMeshable((Meshable)f.Clone());
        ShapeObject so = rf.Clone();

        //so.PivotMirror(0);
        so.PivotTurn(2);
    }
Example #7
0
    // Use this for initialization
    void Start()
    {
        Vector3[] pts = new Vector3[]
        {
            new Vector3(),
            new Vector3(30, 0, -5),
            new Vector3(50, 0, 0),
            new Vector3(50, 0, 20),
            new Vector3(0, 0, 20),
        };

        Polygon pg = new Polygon(pts);

        ShapeObject.CreateMeshable(pg);
        Extrusion ext = pg.Extrude(new Vector3(0, 20, 0));

        ShapeObject refo = ShapeObject.CreateMeshable(ext);

        refo.transform.Translate(new Vector3(0, 20, 0));

        ext.bbox = BoundingBox.CreateFromPoints(ext.vertices, new Vector3(1, 0, 0));

        //ShapeObject.CreateMeshable(ext);
        //Meshable[] mbs = SGUtility.DivideFormByCount(ext, 3, 0);
        Meshable[] mbs     = SGUtility.DivideFormToLength(ext, 10, 0);
        int        counter = 0;

        foreach (Meshable mb in mbs)
        {
            if (mb.bbox == null)
            {
                throw new System.Exception("null bbox");
            }
            SGUtility.ScaleForm(mb, new Vector3(0.9f, 0.3f, 0.9f), Alignment.Center3D);
            ShapeObject so = ShapeObject.CreateMeshable(mb);

            //so.transform.Translate(new Vector3(counter*1, 10, 0));

            counter += 1;
        }
    }
Example #8
0
    // Use this for initialization
    void Start()
    {
        Vector3[] pts = new Vector3[5];
        pts[0] = new Vector3(-80, 0, 46);
        pts[1] = new Vector3(-80, 0, -11);
        pts[2] = new Vector3(-10, 0, -54);
        pts[3] = new Vector3(103, 0, 25);
        pts[4] = new Vector3(96, 0, 70);
        Polyline    pl   = new Polyline(pts);
        Polygon     pg   = new Polygon(pts);
        Form        f    = pg.ExtrudeToForm(new Vector3(0, 30, 0));
        ShapeObject init = ShapeObject.CreateMeshable(f);

        Grammar g1 = new Grammar();

        g1.assignedObjects.Add(init);
        g1.AddRule(new Rules.Bisect("A", new string[] { "B", "C" }, 0.4f, 0), false);
        g1.AddRule(new Rules.Bisect("B", new string[] { "B", "C" }, 0.4f, 2), false);
        g1.AddRule(new Rules.Scale("C", "C", 1.5f, 1), false);
        g1.Execute();
    }
Example #9
0
    // Use this for initialization
    void Start()
    {
        GameObject prefab = Resources.Load("Components\\uinit") as GameObject;

        Vector3[] pts   = new Vector3[4];
        Vector3   v1    = (new Vector3(2, 0, 1)).normalized;
        float     scale = 2;

        pts[0] = Vector3.zero;
        pts[1] = pts[0] + v1 * scale;
        pts[2] = pts[1] + Vector3.up * scale * 2;
        pts[3] = pts[0] + Vector3.up * scale * 2;
        Polygon     pg = new Polygon(pts);
        ShapeObject so = ShapeObject.CreateMeshable(pg, v1);

        BoundingBox bbox = so.meshable.bbox;

        print(bbox.vects[0]);
        print(bbox.vects[1]);
        print(bbox.vects[2]);
        print(bbox.vertices[0]);
        print(bbox.vertices[3]);
        GenerateObjects(prefab, bbox, 30, 30);
    }