Example #1
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 #2
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 #3
0
        public override void Execute()
        {
            Debug.Log("executing " + name);
            Dictionary <SGBuilding, List <Meshable> > container = new Dictionary <SGBuilding, List <Meshable> >();

            foreach (ShapeObject o in inputs.shapes)
            {
                if (o.parentRule.grammar == null || o.parentRule.grammar.building == null)
                {
                    continue;
                }
                SGBuilding b = o.parentRule.grammar.sgbuilding;
                //Debug.Log(b.mode.ToString());
                //Debug.LogFormat("b.mode==unit{0}", b.mode == Building.DisplayMode.UNIT);
                if (b.displayMode != SGBuilding.DisplayMode.PROGRAM)
                {
                    continue;
                }

                Debug.Log("getting units");
                if (!container.ContainsKey(b))
                {
                    container[b] = new List <Meshable>();
                }
                Meshable[] units = SGUtility.DivideFormToLength(o.meshable, 3, 0);
                container[b].AddRange(units);
            }

            foreach (KeyValuePair <SGBuilding, List <Meshable> > kv in container)
            {
                SGBuilding b = kv.Key;
                b.units = new List <List <Meshable> >();
                b.units.Add(kv.Value);
            }

            outputs.shapes = inputs.shapes;
        }
Example #4
0
        public override void Execute()
        {
            //Debug.Log("Executing unit, input count="+inputs.shapes.Count);
            //if(sgbuilding!=null && sgbuilding.mode==SGBuilding.DisplayMode.PROGRAM)
            int           counter = -1;
            List <string> names   = new List <string>();
            Dictionary <string, Color> namedColors = new Dictionary <string, Color>();
            string namePrefix = outputs.names[0];

            outMeshables.Clear();
            List <Color> colors = new List <Color>();

            //Dictionary<float, List<Meshable>> sortedContainer = new Dictionary<float, List<Meshable>>();

            foreach (ShapeObject o in inputs.shapes)
            {
                if (o.name == inputs.names[0])
                {
                    Meshable[] units  = SGUtility.DivideFormToLength(o.meshable, 3, 0);
                    float      d      = o.Size[2];
                    string     mbname = namePrefix + d.ToString();
                    if (!namedColors.ContainsKey(mbname))
                    {
                        counter++;
                        int   colorIndex = counter % SchemeColor.ColorSetDefault.Length;
                        Color c          = SchemeColor.ColorSetDefault[colorIndex];
                        namedColors.Add(mbname, c);
                    }
                    foreach (Meshable mb in units)
                    {
                        mb.name = mbname;
                        mb.Scale(new Vector3(0.9f, 0.8f, 1f), mb.bbox.vects, mb.bbox.GetOriginFromAlignment(Alignment.Center), false);
                    }
                    outMeshables.AddRange(units);
                }
                if (inputs.names.Count > 1 && o.name == inputs.names[1])
                {
                    Meshable[] units  = SGUtility.DivideFormToLength(o.meshable, 3, 2);
                    float      d      = o.Size[2];
                    string     mbname = namePrefix + d.ToString();
                    if (!namedColors.ContainsKey(mbname))
                    {
                        counter++;
                        Color c = SchemeColor.ColorSetDefault[counter];
                        namedColors.Add(mbname, c);
                    }
                    foreach (Meshable mb in units)
                    {
                        mb.name = mbname;
                        mb.Scale(new Vector3(1f, 0.8f, 0.9f), mb.bbox.vects, mb.bbox.GetOriginFromAlignment(Alignment.Center), false);
                    }
                    outMeshables.AddRange(units);
                }
            }

            int dif = outputs.shapes.Count - outMeshables.Count;

            SGUtility.RemoveExtraShapeObjects(ref outputs.shapes, dif);
            //Debug.Log("outMeshable count=" + outMeshables.Count);
            for (int i = 0; i < outMeshables.Count; i++)
            {
                if (i >= outputs.shapes.Count)
                {
                    outputs.shapes.Add(ShapeObject.CreateBasic());
                }
                Meshable m = outMeshables[i];
                //Debug.Log("meshable=" + m.ToString());

                outputs.shapes[i].SetMeshable(m);
                outputs.shapes[i].name       = m.name;
                outputs.shapes[i].parentRule = this;
                outputs.shapes[i].GetComponent <MeshRenderer>().material.color = namedColors[m.name];
            }
        }