コード例 #1
0
        public override void Execute()
        {
            //remove extra or add new
            int count   = (int)((ParameterGroup)paramGroups["Count"]).parameters[0].Value;
            int diff    = outputs.shapes.Count - inputs.shapes.Count;
            int absDiff = Mathf.Abs(diff);

            removeExtraOutputs();



            //update each output
            for (int i = 0; i < inputs.shapes.Count; i++)
            {
                if (i >= outputs.shapes.Count)
                {
                    outputs.shapes.Add(ShapeObject.CreateBasic());
                }
                //Debug.Log("cloning shapeobject, has bbox=" + (inputs.shapes[i].meshable.bbox != null));
                inputs.shapes[i].CloneTo(outputs.shapes[i]);
                //outputs.shapes[i].meshable.bbox = inputs.shapes[i].meshable.bbox;
                //Debug.Log("cloned, has bbox=" + (outputs.shapes[i].meshable.bbox != null));
                outputs.shapes[i].PivotTurn(count);
                outputs.shapes[i].parentRule = this;
            }
            AssignNames(outputs.shapes);
        }//end execute
コード例 #2
0
ファイル: TestPLaningMatrix.cs プロジェクト: ShaperGZ/SGBase
    public void updateDesign()
    {
        if (initShape == null)
        {
            initShape = ShapeObject.CreateBasic();
        }

        Polygon pg = new Polygon(boundaryPts);

        initShape.SetMeshable(pg);


        if (grammar == null)
        {
            grammar = new Grammar();
            grammar.inputs.shapes.Add(initShape);
            grammar.AddRule(new Rules.PivotTurn("A", "A", 2));
            grammar.AddRule(new Rules.DivideTo("A", new string[] { "A", "B" }, 30, 2), false);
            grammar.AddRule(new Rules.DivideTo("A", new string[] { "A", "A" }, 60, 0), false);
            grammar.AddRule(new Rules.Hide(new string[] { "B" }), false);
            grammar.AddRule(new Rules.Extrude("A", "A", 30), false);
            grammar.AddRule(new Rules.CreateBuilding("A", pm3, particleSystem), false);
        }

        grammar.Execute();
    }
コード例 #3
0
ファイル: ShapeObject.cs プロジェクト: ShaperGZ/SocketToUnity
    public virtual ShapeObject Clone(bool geometryOnly = true)
    {
        ShapeObject so = ShapeObject.CreateBasic();

        CloneTo(so);
        return(so);
    }
コード例 #4
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);
        Polygon pg = new Polygon(pts);
        Form    f  = pg.ExtrudeToForm(new Vector3(0, 30, 0));

        Vector3 nml = pts[4] - pts[0];

        nml.Normalize();
        Plane pln = new Plane(nml, new Vector3());

        Meshable[] forms = f.SplitByPlane(pln);

        ShapeObject so0 = ShapeObject.CreateBasic();

        so0.SetMeshable(forms[0]);
        so0.transform.position -= new Vector3(-20, 0, -20);

        ShapeObject so1 = ShapeObject.CreateBasic();

        so1.SetMeshable(forms[1]);
    }
コード例 #5
0
    private static void GenerateObjects(GameObject prefab, BoundingBox bbox, int countW, int countH)
    {
        Vector3 org    = bbox.position;
        float   totalW = bbox.size[0];
        float   totalH = bbox.size[1];
        float   stepW  = totalW / (float)countW;
        float   stepH  = totalH / (float)countH;

        print("stepW=" + stepW);
        print("stepH=" + stepH);

        Vector3 vectW = bbox.vects[0] * stepW;
        Vector3 vectH = bbox.vects[1] * stepH;
        Vector3 vectD = bbox.vects[2] * 1;

        for (int i = 0; i < countH; i++)
        {
            for (int j = 0; j < countW; j++)
            {
                Vector3   bp   = org + (vectW * j) + (vectH * i);
                Vector3[] ptsi = new Vector3[2];
                ptsi[0] = bp;
                ptsi[1] = ptsi[0] + vectW + vectH + vectD;
                BoundingBox bboxi = BoundingBox.CreateFromPoints(ptsi, vectW);

                ShapeObject shpo = ShapeObject.CreateBasic(prefab);
                shpo.ConformToBBoxTransform(bboxi);
            }
        }
    }
コード例 #6
0
ファイル: Conditional.cs プロジェクト: ShaperGZ/SGBase
        public override void Execute()
        {
            removeExtraOutputs();
            for (int i = 0; i < inputs.shapes.Count; i++)
            {
                Meshable m    = inputs.shapes[i].meshable;
                string   name = outputs.names[0];
                float    h    = inputs.shapes[i].Size[1];
                float    w    = inputs.shapes[i].Size[0];

                if (w < 10 && h <= 12)
                {
                    name = outputs.names[0];
                }
                else if (h < 15)
                {
                    name = outputs.names[1];
                }
                else
                {
                    name = outputs.names[2];
                }

                if (i >= outputs.shapes.Count)
                {
                    outputs.shapes.Add(ShapeObject.CreateBasic());
                }
                inputs.shapes[i].CloneTo(outputs.shapes[i]);
                outputs.shapes[i].name       = name;
                outputs.shapes[i].parentRule = this;
            }
        }
コード例 #7
0
    public static ShapeObject CreateMeshable(Meshable mb)
    {
        ShapeObject so = ShapeObject.CreateBasic();
        Vector3     ld = mb.direction;

        so.SetMeshable(mb, ld);
        return(so);
    }
コード例 #8
0
ファイル: ShapeObject.cs プロジェクト: ShaperGZ/SocketToUnity
    public static ShapeObject CreatePolygon(Vector3[] pts)
    {
        Polygon     pg = new Polygon(pts);
        ShapeObject so = ShapeObject.CreateBasic();
        Vector3?    ld = PointsBase.LongestDirection(pts);

        so.SetMeshable(pg, ld);
        return(so);
    }
コード例 #9
0
ファイル: ShapeObject.cs プロジェクト: ShaperGZ/SocketToUnity
    public static ShapeObject CreateMeshable(Meshable mb, Vector3?direction = null)
    {
        ShapeObject so = ShapeObject.CreateBasic();

        //Debug.Log("direction=" + direction.Value);
        so.SetMeshable(mb, direction);

        return(so);
    }
コード例 #10
0
        private int GenerateObjects(GameObject prefab, BoundingBox bbox, float stepW, float stepH, int totalObjectCount)
        {
            if (prefab == null)
            {
                prefab = Resources.Load(prefabPath) as GameObject;
            }
            Vector3 org    = bbox.position;
            float   totalW = bbox.size[0];
            float   totalH = bbox.size[1];



            int countW = Mathf.RoundToInt(totalW / stepW);
            int countH = Mathf.RoundToInt(totalH / stepH);

            if (countW < 1)
            {
                countW = 1;
            }
            if (countH < 1)
            {
                countH = 1;
            }

            float astepW = totalW / (float)countW;
            float astepH = totalH / (float)countH;


            Vector3 vectW = bbox.vects[0] * astepW;
            Vector3 vectH = bbox.vects[1] * astepH;
            Vector3 vectD = bbox.vects[2] * 1;

            for (int i = 0; i < countH; i++)
            {
                for (int j = 0; j < countW; j++)
                {
                    Vector3   bp   = org + (vectW * j) + (vectH * i);
                    Vector3[] ptsi = new Vector3[2];
                    ptsi[0] = bp;
                    ptsi[1] = ptsi[0] + vectW + vectH + vectD;
                    BoundingBox bboxi = BoundingBox.CreateFromPoints(ptsi, vectW);

                    if (totalObjectCount >= outputs.shapes.Count)
                    {
                        ShapeObject nso = ShapeObject.CreateBasic(prefab, true);
                        nso.parentRule = this;
                        outputs.shapes.Add(nso);
                    }
                    ShapeObject shpo = outputs.shapes[totalObjectCount];
                    shpo.ConformToBBoxTransform(bboxi);
                    totalObjectCount += 1;
                }
            }
            return(totalObjectCount);
        }
コード例 #11
0
ファイル: ShapeObject.cs プロジェクト: ShaperGZ/SocketToUnity
    public static ShapeObject CreateExtrusion(Vector3[] pts, float d)
    {
        Vector3   magUp = new Vector3(0, d, 0);
        Polygon   pg    = new Polygon(pts);
        Extrusion ext   = pg.Extrude(magUp);

        ShapeObject so = ShapeObject.CreateBasic();
        Vector3?    ld = PointsBase.LongestDirection(pts);

        so.SetMeshable(ext, ld);
        return(so);
    }
コード例 #12
0
ファイル: ShapeObject.cs プロジェクト: holonking/DeepPain
    public static ShapeObject CreateExtrusion(Vector3[] pts, float d)
    {
        Vector3 magUp = new Vector3(0, d, 0);
        Polygon pg    = new Polygon(pts);
        Form    ext   = pg.Extrude(magUp);

        Debug.Log("ext.verticesCount" + ext.vertices.Length.ToString());
        Debug.Log("ext.trianglesCount" + ext.triangles.Length.ToString());
        Debug.Log("ext.polygonCount" + ext.components.Count.ToString());

        ShapeObject so = ShapeObject.CreateBasic();
        Vector3?    ld = PointsBase.LongestDirection(pts);

        so.SetMeshable(ext, ld);
        return(so);
    }
コード例 #13
0
 private void UpdateGeometry(string guid, Meshable mb)
 {
     if (!shapePipeline.GetPipeline().ContainsKey(guid))
     {
         Debug.Log("字典添加新元素");
         shapePipeline.GetPipeline().Add(guid, ShapeObject.CreateBasic());
     }
     shapePipeline.GetPipeline()[guid].SetMeshable(mb);
     if (mb.name != "")
     {
         shapePipeline.GetPipeline()[guid].gameObject.name = mb.name;
     }
     else
     {
         shapePipeline.GetPipeline()[guid].gameObject.name = "gameObject";
     }
 }
コード例 #14
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);
        }
    }
コード例 #15
0
        public override void Execute()
        {
            string nameFronts = outputs.names[0];
            string nameBacks  = outputs.names[1];
            string nameSide   = outputs.names[2];
            string nameTop    = outputs.names[3];
            string nameBot    = outputs.names[4];

            List <Meshable> top          = new List <Meshable>();
            List <Meshable> bot          = new List <Meshable>();
            List <Meshable> sides        = new List <Meshable>();
            List <Meshable> fronts       = new List <Meshable>();
            List <Meshable> backs        = new List <Meshable>();
            List <Meshable> outMeshables = new List <Meshable>();

            for (int i = 0; i < inputs.shapes.Count; i++)
            {
                //Debug.Log("i=" + i);
                ShapeObject so = inputs.shapes[i];
                if (so != null && so.meshable.GetType() == typeof(Extrusion))
                {
                    //Debug.Log("is extrusion");
                    Extrusion ext = (Extrusion)so.meshable;
                    if (outputs.names[3] != "DELETE")
                    {
                        top.Add(ext.top);
                    }
                    if (outputs.names[4] != "DELETE")
                    {
                        bot.Add(ext.components[0]);
                    }
                    BoundingBox bbox    = ext.bbox;
                    Vector3     directF = bbox.vects[2].normalized;
                    foreach (Meshable m in ext.sides)
                    {
                        Vector3 v1  = (m.vertices[1] - m.vertices[0]).normalized;
                        Vector3 v2  = (m.vertices[3] - m.vertices[0]).normalized;
                        Vector3 n   = Vector3.Cross(v1, v2);
                        Vector3 nn  = n * -1;
                        float   dot = Vector3.Dot(directF, n);
                        //float dot2 = Vector3.Dot(new Vector3(0, 1, 0), nn);
                        //Debug.LogFormat("n={0}{3}, nn={1}{4}, vF={2} ", n,nn, directF,n==directF,nn==directF);
                        //if(Vector3.Distance(n,directF)<0.01f || Vector3.Distance(nn, directF) < 0.1f)
                        //if (n == directF )
                        //if (n.magnitude == 0) throw new System.Exception(n.ToString());
                        if (Vector3.Distance(n, directF) < 0.4f)
                        {
                            if (outputs.names[0] != "DELETE")
                            {
                                fronts.Add(m);
                            }
                        }
                        //else if (nn == directF)
                        else if (Vector3.Distance(nn, directF) < 0.4f)
                        {
                            if (outputs.names[1] != "DELETE")
                            {
                                backs.Add(m);
                            }
                        }
                        else
                        {
                            //Debug.Log(dot + "," + n+","+directF);
                            if (outputs.names[2] != "DELETE")
                            {
                                sides.Add(m);
                            }
                        }
                    }
                    //if (top == null) throw new System.Exception("top is null");
                    //for (int j = 0; j < ext.sides.Count; j++)
                    //{
                    //    Meshable m = ext.sides[j];
                    //    if (m == null) throw new System.Exception("side is null at " + j);
                    //}
                }
            }//for i

            outMeshables.AddRange(top);
            outMeshables.AddRange(bot);
            outMeshables.AddRange(sides);
            outMeshables.AddRange(fronts);
            //Debug.Log("meshable.count=" + outMeshables.Count);

            int count       = outMeshables.Count;
            int removeCount = outputs.shapes.Count - count;

            if (count > 0)
            {
                removeOutputsByCount(removeCount);
            }

            foreach (Meshable m in outMeshables)
            {
                //Debug.Log("m=" + m);
            }

            for (int i = 0; i < count; i++)
            {
                //if (outMeshables[i] == null) continue;
                if (i >= outputs.shapes.Count)
                {
                    ShapeObject nso = ShapeObject.CreateBasic();
                    nso.parentRule = this;
                    nso.step       = this.step;
                    outputs.shapes.Add(nso);
                }
                Meshable m = outMeshables[i];
                if (m == null)
                {
                    throw new System.Exception("side is null at " + i);
                }
                outputs.shapes[i].SetMeshable(m);
                if (fronts.Contains(m))
                {
                    outputs.shapes[i].name = nameFronts;
                }
                else if (backs.Contains(m))
                {
                    outputs.shapes[i].name = nameBacks;
                }
                else if (top.Contains(m))
                {
                    outputs.shapes[i].name = nameTop;
                }
                else if (bot.Contains(m))
                {
                    outputs.shapes[i].name = nameBot;
                }
                else
                {
                    outputs.shapes[i].name = nameSide;
                }
            }
        }
コード例 #16
0
        public override void Execute()
        {
            string nameSide = outputs.names[0];
            string nameTop  = outputs.names[1];

            List <Meshable> top          = new List <Meshable>();
            List <Meshable> sides        = new List <Meshable>();
            List <Meshable> outMeshables = new List <Meshable>();

            for (int i = 0; i < inputs.shapes.Count; i++)
            {
                //Debug.Log("i=" + i);
                ShapeObject so = inputs.shapes[i];
                if (so != null && so.meshable.GetType() == typeof(Extrusion))
                {
                    //Debug.Log("is extrusion");
                    Extrusion ext = (Extrusion)so.meshable;
                    top.Add(ext.top);
                    sides.AddRange(ext.sides);
                    if (top == null)
                    {
                        throw new System.Exception("top is null");
                    }
                    for (int j = 0; j < ext.sides.Count; j++)
                    {
                        Meshable m = ext.sides[j];
                        if (m == null)
                        {
                            throw new System.Exception("side is null at " + j);
                        }
                    }
                }
            }//for i

            outMeshables.AddRange(top);
            outMeshables.AddRange(sides);
            //Debug.Log("meshable.count=" + outMeshables.Count);

            int count       = outMeshables.Count;
            int removeCount = outputs.shapes.Count - count;

            if (count > 0)
            {
                removeOutputsByCount(removeCount);
            }

            foreach (Meshable m in outMeshables)
            {
                //Debug.Log("m=" + m);
            }

            for (int i = 0; i < count; i++)
            {
                //if (outMeshables[i] == null) continue;
                if (i >= outputs.shapes.Count)
                {
                    ShapeObject nso = ShapeObject.CreateBasic();
                    nso.parentRule = this;
                    nso.step       = this.step;
                    outputs.shapes.Add(nso);
                }
                Meshable m = outMeshables[i];
                if (m == null)
                {
                    throw new System.Exception("side is null at " + i);
                }
                outputs.shapes[i].SetMeshable(m);
                if (top.Contains(m))
                {
                    outputs.shapes[i].name = nameTop;
                }
                else
                {
                    outputs.shapes[i].name = nameSide;
                }
            }
        }
コード例 #17
0
ファイル: BuildingRules.cs プロジェクト: ShaperGZ/SGBase
        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];
            }
        }
コード例 #18
0
        public override void Execute()
        {
            string          name         = outputs.names[0];
            List <Meshable> outMeshables = new List <Meshable>();

            for (int i = 0; i < inputs.shapes.Count; i++)
            {
                //Debug.Log("i=" + i);
                ShapeObject so = inputs.shapes[i];
                if (so != null && so.meshable.GetType() == typeof(Extrusion))
                {
                    //Debug.Log("is extrusion");
                    Extrusion ext = (Extrusion)so.meshable;
                    if (extract == "TOP")
                    {
                        outMeshables.Add(ext.top);
                    }
                    else if (extract == "BOT")
                    {
                        outMeshables.Add(ext.bot);
                    }
                    else
                    {
                        outMeshables.AddRange(ext.sides);
                    }
                }
            }//for i
            //Debug.Log("outMeshables.Count=" + outMeshables.Count);
            int dif = extractedObjects.Count - outMeshables.Count;

            if (dif > 0)
            {
                for (int i = 0; i < dif; i++)
                {
                    int index = extractedObjects.Count - 1;
                    try
                    {
                        GameObject.Destroy(extractedObjects[index].gameObject);
                    }
                    catch { }
                    extractedObjects.RemoveAt(index);
                }
            }



            for (int i = 0; i < outMeshables.Count; i++)
            {
                //if (outMeshables[i] == null) continue;
                if (i >= extractedObjects.Count)
                {
                    ShapeObject nso = ShapeObject.CreateBasic();
                    nso.parentRule = this;
                    nso.step       = this.step;
                    nso.name       = name;
                    extractedObjects.Add(nso);
                }
                Meshable m = outMeshables[i];
                if (m == null)
                {
                    throw new System.Exception("side is null at " + i);
                }
                extractedObjects[i].SetMeshable(m);
                extractedObjects[i].GetComponent <MeshFilter>().mesh.RecalculateNormals();
                extractedObjects[i].name = name;
            }
            //Debug.Log("extractObjects.Count=" + extractedObjects.Count);
            outputs.shapes.Clear();
            outputs.shapes.AddRange(inputs.shapes.ToArray());
            outputs.shapes.AddRange(extractedObjects.ToArray());
        }