Пример #1
0
    // Use this for initialization
    void Start()
    {
        SOPoint sop = SOPoint.CreatePoint();

        SOPoint[] sops = new SOPoint[2];
        sops[0] = SOPoint.CreatePoint();
        sops[1] = SOPoint.CreatePoint(new Vector3(-30, 0, -40));

        float[] hs = new float[2];
        hs[0] = 60;
        hs[1] = 16;

        float[] ws = new float[2];
        ws[0] = 30;
        ws[1] = 45;

        Building[] buildings = new Building[2];

        for (int i = 0; i < sops.Length; i++)
        {
            buildings[i] = new Building();
            Grammar g1 = new Grammar();
            buildings[i].AddGrammar(g1);
            g1.name = "g1";
            g1.assignedObjects.Add(sops[i]);
            g1.AddRule(new Rules.CreateOperableBox("A", new Vector3(30, 60, 20)), false);
            g1.AddRule(new Rules.SizeBuilding3D("A", "A", new Vector3(ws[i], hs[i], 20)), false);
            g1.AddRule(new Rules.ApartmentLoadFilter("A", "SL", "DL", "CV"), false);
            g1.AddRule(new Rules.SingleLoaded("SL", "APT"), false);
            g1.AddRule(new Rules.DoubleLoaded("DL", "APT"), false);
            g1.AddRule(new Rules.CentralVoid("CV", "APT", "APT2"), false);

            Grammar g2 = new Grammar();
            g2.name     = "AptFormA";
            g2.category = GraphNode.Category.Bd_Massing;
            g2.inputs.names.Add("APT");
            g2.AddRule(new Rules.Bisect("APT", new string[] { "APT", "C" }, 0.4f, 0), false);
            g2.AddRule(new Rules.Bisect("C", new string[] { "C", "APT" }, 0.25f, 2), false);
            g2.AddRule(new Rules.Scale3D("C", "APT", new Vector3(1.3f, 0.7f, 1.6f), null, Alignment.NE), false);
            g1.AddRule(g2, false);

            g1.AddRule(new Rules.CalBuildingParams(new string[] { "APT" }), false);
            g1.AddRule(new Rules.ExtractFace(new string[] { "APT" }, "TOP", "TOP"), false);
            g1.AddRule(new Rules.DivideToFTFH("APT", new string[] { "APTL", "APTLM" }, 4), false);
            g1.AddRule(new Rules.PivotMirror("APTLM", "APTL", 0), false);
            g1.AddRule(new Rules.CspFlrToUnitsAbstract(new string[] { "APTL" }), false);

            g1.AddRule(new Rules.DcpFace5("APTL", new string[] { "F", "DELETE", "S", "DELETE", "BT" }), false);
            g1.AddRule(new Rules.Extrude("BT", "BT", -0.1f), false);
            g1.AddRule(new Rules.AggCW01("F", "F", 3, 4), false);
            g1.AddRule(new Rules.AggBasicSimp("S", "S", 3, 4), false);

            g1.Execute();
        }
        buildings[0].Invalidate();
        buildings[1].Invalidate();

        //SceneManager.buildingParamEditor.SetBuilding(buildings[0]);
        //SceneManager.SelectedGrammar = g1;
    }
Пример #2
0
    // Use this for initialization
    void Start()
    {
        so = SOPoint.CreatePoint(new Vector3(0, 0, 0));
        xp = SOPoint.CreatePoint(new Vector3(1000, 1000, 10000));

        pts[0] = new Vector3(0, 0, 0);
        pts[1] = new Vector3(50, 0, 0);
        pts[2] = new Vector3(50, 0, 50);
        //sos[3] = SOPoint.CreatePoint(new Vector3(20, 0, 30));
    }
Пример #3
0
    void Start()
    {
        Vector3[] pts1 = initShape1();

        Polygon pg1 = new Polygon(pts1);

        Extrusion f1 = pg1.Extrude(new Vector3(0, 40, 0));
        //ShapeObject so = ShapeObject.CreateMeshable(f1);
        //so.name = "A";

        ShapeObject so       = SOPoint.CreatePoint();
        Building    building = new Building();

        g1 = new Grammar();
        building.AddGrammar(g1);
        g1.name = "g1";
        so.SetGrammar(g1);

        //g1.AddRule(new Rules.CreateBox("A", new Vector3(0, 0, 0), new Vector3(10, 10, 10), new Vector3(0,0,0)));
        g1.AddRule(new Rules.CreateOperableBox("A", new Vector3(30, 60, 20)));
        g1.AddRule(new Rules.SizeBuilding3D("A", "A", new Vector3(40, 30, 20)));

        g1.AddRule(new Rules.ApartmentLoadFilter("A", "SL", "DL", "CV"));
        g1.AddRule(new Rules.SingleLoaded("SL", "APT"));
        g1.AddRule(new Rules.DoubleLoaded("DL", "APT"));
        g1.AddRule(new Rules.CentralVoid("CV", "APT", "APT2"));


        Grammar g2 = new Grammar();

        g2.name = "AptFormA";
        g2.AddRule(new Rules.Bisect("APT", new string[] { "APT", "C" }, 0.4f, 0), false);
        g2.AddRule(new Rules.Bisect("C", new string[] { "C", "APT" }, 0.25f, 2), false);
        g2.AddRule(new Rules.Scale3D("C", "APT", new Vector3(1.3f, 0.7f, 1.6f), null, Alignment.NE), false);


        g2.inputs.names.Add("APT");



        g1.AddRule(g2);
        //g1.AddRule(new Rules.DivideTo("APT", "APTL", 4, 1));
        //g1.AddRule(new Rules.DivideTo("APT2", "APTL", 4, 1));

        g1.AddRule(new Rules.DcpFace2("APT", new string[] { "APT", "APT" }));
        g1.AddRule(new Rules.DcpFace2("APT2", new string[] { "APT", "APT" }));


        //g1.AddRule(new Rules.DivideToFTFH("APT2", "APTL", 4));
        //g1.AddRule(new Rules.DivideToFTFH("APT", "APTL", 4));
        //g1.AddRule(new Rules.DcpFace2("APTL", new string[] { "Top", "Side" }));

        g1.Execute();
        SceneManager.SelectedGrammar = g1;
    }
Пример #4
0
    Grammar G1(SOPoint sop, float w, float h)
    {
        Grammar g1 = new Grammar();

        g1.name = "g1";
        g1.assignedObjects.Add(sop);
        g1.AddRule(new Rules.CreateOperableBox("A", new Vector3(w, h, 20)), false);
        g1.AddRule(new Rules.SizeBuilding3D("A", "A", new Vector3(w, h, 20)), false);
        g1.AddRule(new Rules.ApartmentLoadFilter("A", "SL", "DL", "CV"), false);
        g1.AddRule(new Rules.SingleLoaded("SL", "APT"), false);
        g1.AddRule(new Rules.DoubleLoaded("DL", "APT"), false);
        g1.AddRule(new Rules.CentralVoid("CV", "APT", "APT2"), false);
        return(g1);
    }
Пример #5
0
    public override ShapeObject Clone(bool geometryOnly = true)
    {
        SOPoint sop = SOPoint.CreatePoint(Position);

        if (geometryOnly)
        {
            return(sop);
        }
        sop.parentRule = parentRule;
        sop.name       = name;


        return(sop);
    }
Пример #6
0
    void PointGrid(int wCount, int hCount)
    {
        float w = 10;
        float h = 10;

        for (int i = 0; i < wCount; i++)
        {
            for (int j = 0; j < hCount; j++)
            {
                float   posX = w * (float)j;
                float   posZ = h * (float)i;
                Vector3 p    = new Vector3(posX, 0, posZ);
                SOPoint.CreatePoint(p);
            }
        }
    }
Пример #7
0
    ShapeObject createBuilding()
    {
        ShapeObject so = SOPoint.CreatePoint();
        Grammar     g  = new Grammar();
        Building    bp = new Building();

        bp.AddGrammar(g);
        so.SetGrammar(g);

        float h = Random.Range(9, 80);
        float w = Random.Range(30, 50);
        float d = Random.Range(15, 25);

        if (h < 30)
        {
            w = Random.Range(40, 60);
            d = Random.Range(30, 50);
        }
        g.AddRule(new Rules.CreateOperableBox("A", new Vector3(30, 60, 20)));
        g.AddRule(new Rules.SizeBuilding3D("A", "A", new Vector3(w, h, d)));
        g.AddRule(new Rules.ApartmentLoadFilter("A", "SL", "DL", "CV"));
        g.AddRule(new Rules.SingleLoaded("SL", "APT"));
        g.AddRule(new Rules.DoubleLoaded("DL", "APT"));
        g.AddRule(new Rules.CentralVoid("CV", "APT", "APT2"));


        Grammar g2 = new Grammar();

        g2.category = GraphNode.Category.Bd_Massing;
        g2.name     = "AptFormA";
        g2.inputs.names.Add("APT");
        g2.AddRule(new Rules.Bisect("APT", new string[] { "APT", "C" }, 0.4f, 0), false);
        g2.AddRule(new Rules.Bisect("C", new string[] { "C", "APT" }, 0.25f, 2), false);
        g2.AddRule(new Rules.Scale3D("C", "APT", new Vector3(1.3f, 0.7f, 1.6f), null, Alignment.NE), false);


        g.AddRule(g2);
        //g.AddRule(new Rules.ExtractFace(new string[] { "APT" }, "TOP", "TOP"), false);
        //g.AddRule(new Rules.DivideToFTFH("APT", "APTL", 4));
        //g.AddRule(new Rules.DivideToFTFH("APT2", "APTL", 4));

        //g.AddRule(new Rules.DcpA("A", 9, 3));
        return(so);
    }
Пример #8
0
    // Use this for initialization
    void Start()
    {
        Vector3[] pts = new Vector3[]
        {
            new Vector3(),
            new Vector3(35, 0, -4),
            new Vector3(50, 0, 0),
            new Vector3(50, 0, 15),
            new Vector3(0, 0, 15)
        };

        SOPoint    sop = SOPoint.CreatePoint();
        SGBuilding b1  = new SGBuilding();

        ShapeObject so2 = ShapeObject.CreateExtrusion(pts, 30);

        so2.meshable.bbox = BoundingBox.CreateFromPoints(so2.meshable.vertices, new Vector3(1, 0, 0));
        b1.SetGPlanning(G2(so2));
        b1.SetMassing(MassingGrammars.GB());
        b1.SetProgram(ProgramGrammars.APT1());
        b1.SetFacade(FacadeGrammars.CW01());

        SGBuilding b2  = new SGBuilding();
        SOPoint    so3 = SOPoint.CreatePoint(new Vector3(20, 0, 40));

        b2.SetGPlanning(G1(so3, 40, 60));
        b2.SetMassing(MassingGrammars.GA());
        b2.SetProgram(ProgramGrammars.APT1());
        b2.SetFacade(FacadeGrammars.CW01());



        SceneManager.SelectedGrammar  = b2.gPlaning;
        SceneManager.SelectedBuilding = b2;

        b1.MassingMode();
        b2.MassingMode();

        //b1.Execute();
        //b2.Execute();
        b2.UpdateParams();
    }
Пример #9
0
    public virtual void AddRand(ShapeObject so = null)
    {
        if (so == null)
        {
            so = SOPoint.CreatePoint();
        }

        Vector3 center = SGGeometry.SGUtility.CenterOfGravity(boundary);

        center[0] += Random.Range(-5, 5);
        center[2] += Random.Range(-5, 5);

        //float x = Random.Range(W(), E());
        //float y = 0;
        //float z = Random.Range(N(), S());
        //Vector3 p = new Vector3(x, y, z);
        Vector3 p = center;

        so.Position = p;
        particles.Add(so);
    }
Пример #10
0
    // Use this for initialization
    void Start()
    {
        //PointGrid(10, 20);

        //Vector3 p1 = new Vector3(0, 0, 0);
        //Vector3 p2 = new Vector3(1, 0, 0);
        //Vector3 p3 = new Vector3(1, 0, 2);
        //Vector3 p4 = new Vector3(1, 0, 1);

        //SGGeometry.Intersect.LineLine2D(p1, p2, p3, p4);

        boundary = new Vector3[]
        {
            new Vector3(0, 0, 0),
            new Vector3(10, 0, 0),
            new Vector3(10, 0, 10),
            new Vector3(-2, 0, 12),
        };

        so = SOPoint.CreatePoint();
        xp = SOPoint.CreatePoint();
    }
Пример #11
0
    // Use this for initialization
    void Start()
    {
        List <SGBuilding> buildings = new List <SGBuilding>();

        for (int i = 0; i < 5; i++)
        {
            SOPoint    sop      = SOPoint.CreatePoint(new Vector3(i * 40, 0, 0));
            SGBuilding building = SGBuilding.CreateApt(sop, new Vector3(30, 60, 15));
            building.Execute();

            buildings.Add(building);
        }

        buildings[buildings.Count - 1].ClearAllAssociated();
        buildings.RemoveAt(buildings.Count - 1);


        //building.ClearForDestroy();
        //Destroy(sop.gameObject);

        //building.Clear();
    }
Пример #12
0
    public static SOPoint CreatePoint(Vector3?location = null)
    {
        GameObject o = GameObject.CreatePrimitive(PrimitiveType.Sphere);


        SOPoint sop = o.AddComponent <SOPoint>();

        if (location == null)
        {
            location = new Vector3(0, 0, 0);
        }
        {
            sop.Position       = location.Value;
            sop.PositionOffset = new Vector3(0, 0, 0);
        }
        sop.Radius       = 1;
        sop.alwaysActive = true;
        BoxCollider bc = o.AddComponent <BoxCollider>();

        bc.center = o.transform.position;
        return(sop);
    }
Пример #13
0
    void Start()
    {
        //boundary = initShape1();
        boundary = initShapeL();
        BoundingBox bbox = BoundingBox.CreateFromPoints(boundary);

        Debug.Log(bbox.Format());

        designContext = new DesignContext(boundary);


        particleSystem = new SGPlaningParticleSystem(boundary);
        //particleSystem = new SGPlaningParticleSystemAT(boundary);
        //particleSystem = new SGParticleSystem(boundary);
        for (int i = 0; i < 10; i++)
        {
            //ShapeObject so = SOPoint.CreatePoint();
            ShapeObject so       = createBuilding();
            Building    building = so.grammar.building;
            building.SetRefPos(so);
            building.site = designContext;

            designContext.buildings.Add(building);
            particleSystem.AddRand(so);
        }

        SOPoint[] sops = new SOPoint[3];
        sops[0] = SOPoint.CreatePoint(new Vector3(60, 0, -30));
        sops[1] = SOPoint.CreatePoint(new Vector3(-30, 0, 80));
        sops[2] = SOPoint.CreatePoint(new Vector3(320, 0, 200));
        for (int i = 0; i < sops.Length; i++)
        {
            sops[i].sizable = false;
            float r = 20;
            sops[i].Size = new Vector3(r, r, r);
        }
        designContext.attractions.AddRange(sops);
    }
Пример #14
0
    public static SGBuilding CreateApt(SOPoint sop, Vector3 size)
    {
        SGBuilding building = new SGBuilding();
        Grammar    gp       = new Grammar();

        gp.name = "planing1";
        gp.inputs.shapes.Add(sop);
        gp.AddRule(new Rules.CreateOperableBox("A", new Vector3(30, 30, 20)));
        gp.AddRule(new Rules.SizeBuilding3D("A", "A", new Vector3(30, 20, 15)));
        gp.AddRule(new Rules.ResidentialLoadFilter("A", "IHUS", "DHUS", "A"));
        gp.AddRule(new Rules.ApartmentLoadFilter("A", "SL", "DL", "CV"), false);
        gp.AddRule(new Rules.SingleLoaded("SL", "APT"), false);
        gp.AddRule(new Rules.DoubleLoaded("DL", "APT"), false);
        gp.AddRule(new Rules.CentralVoid("CV", "APT", "APT2"), false);
        building.SetGPlanning(gp);
        building.SetMassing(MassingGrammars.GA());
        //building.SetFacade(FacadeGrammars.CW01());
        building.SetSize(size);
        sop.grammar = gp;
        //sop.onPositionChanged += delegate { building.Execute(); };
        //sop.onDestroy += delegate { building.ClearForDestroy(); };
        return(building);
    }
Пример #15
0
        public override void Execute()
        {
            if (matrix == null)
            {
                return;
            }
            PlaningScheme scheme = matrix.recommendedScheme;

            //Debug.Log("scheme="+scheme);
            if (scheme == null)
            {
                return;
            }
            //Debug.Log("has scheme");
            int total = 0;

            for (int i = 0; i < scheme.counts.Count; i++)
            {
                total += scheme.counts[i];
            }
            total = Mathf.Clamp(total, 0, inputs.shapes.Count);

            if (buildings == null)
            {
                buildings = new List <SGBuilding>();
            }
            else
            {
                //先删除多出来的building
                int dif = buildings.Count - total;
                for (int i = 0; i < dif; i++)
                {
                    int index = buildings.Count - 1;
                    buildings[index].ClearAllAssociated();
                    buildings.RemoveAt(index);
                }//for
            }


            int typeIndex = 0;
            int nextLevel = scheme.counts[0];

            for (int i = 0; i < total; i++)
            {
                if (i >= nextLevel)
                {
                    //Debug.LogFormat("i={0}, typeIndex={1}, total={2}", i, typeIndex,total);
                    typeIndex++;
                    nextLevel = nextLevel + scheme.counts[typeIndex];
                }

                ShapeObject so = inputs.shapes[i];
                //补足不够的building
                if (i >= buildings.Count)
                {
                    SOPoint    sop      = SOPoint.CreatePoint(new Vector3(i * 40, 0, 0));
                    SGBuilding building = SGBuilding.CreateApt(sop, new Vector3(30, 60, 15));
                    building.Execute();
                    buildings.Add(building);
                }


                BuildingType bt = scheme.buildingTypes[typeIndex];

                Vector3    size = new Vector3(bt.width, bt.height, bt.depth);
                SGBuilding b    = buildings[i];
                b.gPlaning.inputs.shapes[0].Position = so.Position;
                b.SetSize(size);
                b.Execute();
            }//for


            //update particle system
            if (psys != null)
            {
                psys.particles.Clear();
                for (int i = 0; i < buildings.Count; i++)
                {
                    GraphNode   g   = buildings[i].gPlaning;
                    ShapeObject sop = g.inputs.shapes[0];
                    psys.particles.Add(sop);
                }
            }
        }