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
    public void UnitMode()
    {
        Debug.LogFormat("mode==unit:{0},lastMode==unit:{1}", this.mode == DisplayMode.UNIT, this.lastMode == DisplayMode.UNIT);
        if (this.lastMode != DisplayMode.UNIT)
        {
            Debug.Log("re execute " + grammars[0].name);
            this.lastMode = DisplayMode.UNIT;
            this.mode     = DisplayMode.UNIT;
            grammars[0].Execute();
            Debug.Log("finish reExecute");
            return;
        }

        mode = DisplayMode.UNIT;
        foreach (ShapeObject o in grammars[0].stagedOutputs[grammars[0].stagedOutputs.Count - 1].shapes)
        {
            o.Show(false);
        }
        if (unitSOS == null)
        {
            unitSOS = new List <ShapeObject>();
        }
        //if (unitSOS == null || unitSOS.Count<1) return;
        if (units == null || units.Count < 1)
        {
            return;
        }
        int dif = unitSOS.Count - units[0].Count;

        if (dif > 0)
        {
            SGUtility.RemoveExtraShapeObjects(ref unitSOS, dif);
        }
        for (int i = 0; i < units[0].Count; i++)
        {
            if (i >= unitSOS.Count)
            {
                unitSOS.Add(ShapeObject.CreateBasic());
            }
            Meshable m = (Meshable)units[0][i].Clone();
            SGUtility.ScaleForm(m, new Vector3(0.9f, 0.7f, 1f), Alignment.Center3D);
            unitSOS[i].SetMeshable(m);
            unitSOS[i].Show(true);
        }
    }
Example #3
0
    public void visualize()
    {
        float minDif = 10000000;

        //when the site property is not given
        if (matrix.siteProp.gfa == 0)
        {
            for (int i = 0; i < matrix.cells.Count; i++)
            {
                GameObject cell = matrix.cells[i];
                cell.GetComponent <MeshRenderer>().material.color = Color.white;
                cell.transform.localScale = new Vector3(0.02f, 0.02f, 0.02f);
            }
            recommendedIndex = null;
            return;
        }

        //normal visualization
        for (int i = 0; i < matrix.cells.Count; i++)
        {
            GameObject cell = matrix.cells[i];
            float      d    = matrix.schemes[i].difGFA;
            d = Mathf.Abs(d);
            if (d < minDif)
            {
                minDif           = d;
                recommendedIndex = i;
            }
            float max = matrix.siteProp.gfa * 0.2f;

            float clampD = Mathf.Clamp(d, 800, max);
            float ratio  = 1 - (clampD / max);

            //Debug.LogFormat("siteArea={0}, plotRatio={1}", matrix.siteProp.siteArea, matrix.siteProp.plotRatio);
            //Debug.LogFormat("d={0}, campD={1},ratio={2}, max={3}", d, clampD, ratio, max);
            Color color = SGUtility.colorScale(colorSet, ratio);
            ratio = Mathf.Clamp(ratio, 0.2f, 1f);
            float r = matrix.cellSize * ratio;

            cell.GetComponent <MeshRenderer>().material.color = color;
            cell.transform.localScale = new Vector3(r, r, r);
        }
    }
Example #4
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 #5
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 #6
0
    public void SetRatio(float[] areas, string[] names, Color[] colors)
    {
        if (!gameObject.activeSelf)
        {
            return;
        }
        float total = 0;

        float[] ratios  = new float[areas.Length];
        float[] heights = new float[areas.Length];
        foreach (int area in areas)
        {
            total += area;
        }

        float hTotal = rect.sizeDelta[1];

        totalHGet = hTotal;

        DefaultControls.Resources rc = SceneManager.uiResources;
        float lowest = 0;

        for (int i = 0; i < ratios.Length; i++)
        {
            #region cal ratio
            ratios[i] = areas[i] / total;
            float h = ratios[i] * hTotal;
            #endregion

            #region GameObject management
            if (bars == null)
            {
                bars = new List <GameObject>();
            }
            if (texts == null)
            {
                texts = new List <GameObject>();
            }
            int dif = bars.Count - ratios.Length;
            if (dif > 0)
            {
                SGUtility.RemoveExtraGameObjects(ref bars, dif);
            }
            if (dif > 0)
            {
                SGUtility.RemoveExtraGameObjects(ref texts, dif);
            }

            if (i >= bars.Count)
            {
                GameObject bar = DefaultControls.CreateImage(rc);
                bar.transform.parent = transform;
                int cIndex = i % SchemeColor.ColorSetDefault.Length;
                bars.Add(bar);
            }
            if (i >= texts.Count)
            {
                GameObject text = DefaultControls.CreateText(rc);
                text.transform.parent = transform;
                int cIndex = i % SchemeColor.ColorSetDefault.Length;
                text.GetComponent <Text>().text = "";
                texts.Add(text);
            }
            #endregion

            //bars[i].GetComponent<Image>().material.color = SchemeColor.ColorSetDefault[i];
            bars[i].GetComponent <Image>().color = colors[i];
            RectTransform barRect = (RectTransform)bars[i].transform;
            barRect.anchorMax        = new Vector2(0, 1);
            barRect.anchorMin        = new Vector2(0, 1);
            barRect.pivot            = new Vector2(0, 1);
            barRect.localScale       = new Vector3(1, 1, 1);
            barRect.sizeDelta        = new Vector2(20, h);
            barRect.anchoredPosition = new Vector2(0, lowest);

            string message = string.Format("{0}: {1}% area={2}sqm",
                                           names[i],
                                           Mathf.Round(ratios[i] * 100),
                                           areas[i]);

            Text t = texts[i].GetComponent <Text>();
            t.text     = message;
            t.fontSize = 8;
            t.color    = Color.white;
            RectTransform textRect = (RectTransform)texts[i].transform;
            textRect.anchoredPosition = new Vector2(35, lowest);
            textRect.anchorMax        = new Vector2(0, 1);
            textRect.anchorMin        = new Vector2(0, 1);
            textRect.pivot            = new Vector2(0, 1);
            textRect.localScale       = new Vector3(1, 1, 1);
            textRect.sizeDelta        = new Vector2(500, 30);
            textRect.anchoredPosition = new Vector2(30, lowest);

            lowest -= h;
        }
    }
Example #7
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];
            }
        }