public void SetMeshable(Meshable imeshable, Vector3?direction = null) { meshable = imeshable; Vector3 vectu; BoundingBox bbox = null; if (direction.HasValue) { vectu = direction.Value; bbox = meshable.GetBoundingBox(vectu); meshable.bbox = bbox; } else if (meshable.bbox == null) { //Debug.Log("bounding box not found !!!"); vectu = new Vector3(1, 0, 0); bbox = meshable.GetBoundingBox(vectu); meshable.bbox = bbox; } else { //Debug.Log("assigning existing bounding box"); bbox = meshable.bbox; } ConformToBBox(bbox); stale = true; }
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)); }
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; } }
public static Meshable[] DivideFormToLength(Meshable mb, float length, int axis) { float total = mb.bbox.size[axis]; int count = Mathf.RoundToInt(total / length); return(DivideFormByCount(mb, count, axis)); }
public override List <Meshable> ExecuteShape(ShapeObject inSo) { float[] size = new float[3]; for (int i = 0; i < 3; i++) { size[i] = ((ParameterGroup)paramGroups["Size"]).parameters[i].Value; } //Vector3 vpos = Vector3.zero; Vector3 vpos = inSo.Position; //Vector3 vsize = new Vector3(size[0], size[1], size[2]); Vector3[] pts = new Vector3[4]; Vector3 vx = new Vector3(size[0], 0, 0); Vector3 vy = new Vector3(0, size[1], 0); Vector3 vz = new Vector3(0, 0, size[2]); pts[0] = vpos; pts[1] = vpos + vx; pts[2] = pts[1] + vz; pts[3] = pts[0] + vz; Polygon pg = new Polygon(pts); Meshable f = pg.Extrude(vy); List <Meshable> outs = new List <Meshable>(); outs.Add(f); AssignNames(outs); return(outs); }
public void SetMeshable(Meshable imeshable, Vector3?direction = null) { meshable = imeshable; Vector3 vectu; if (direction.HasValue) { vectu = direction.Value; } else { vectu = new Vector3(1, 0, 0); } BoundingBox bbox = meshable.GetBoundingBox(vectu); transform.position = bbox.vertices[0]; transform.LookAt(bbox.vertices[3]); Size = bbox.size; Mesh mesh = meshable.GetNormalizedMesh(bbox); GetComponent <MeshFilter>().mesh = mesh; print("mesh.verticeCount=" + mesh.vertexCount.ToString()); }
public override List <Meshable> ExecuteShape(ShapeObject so) { float d = ((ParameterGroup)paramGroups["Position"]).parameters[0].Value; int axis = (int)((ParameterGroup)paramGroups["Axis"]).parameters[0].Value; //get scale Vector3 scale = new Vector3(1, 1, 1); scale[axis] = d; Vector3[] vects = so.Vects; Vector3 origin = so.transform.position; //get the splited meshables Meshable mb = so.meshable; Meshable scaledMb = mb.Scale(scale, vects, origin, true); //TODO: just scale the bbox scaledMb.bbox = BoundingBox.CreateFromPoints(scaledMb.vertices, so.meshable.bbox); //outMeshables.Add(scaledMb); List <Meshable> outs = new List <Meshable>(); outs.Add(scaledMb); AssignNames(outs); //AssignNames(outMeshables.ToArray()); return(outs); //Rule.Execute() will take care of the outMeshables }
public static ShapeObject CreateMeshable(Meshable mb) { ShapeObject so = ShapeObject.CreateBasic(); Vector3 ld = mb.direction; so.SetMeshable(mb, ld); return(so); }
public void SetMeshable(Meshable imeshable, BoundingBox refBbox) { meshable = imeshable; Vector3 vectu; BoundingBox bbox = meshable.GetBoundingBox(refBbox); ConformToBBox(bbox); stale = true; }
public static ShapeObject CreateMeshable(Meshable mb, Vector3?direction = null) { ShapeObject so = ShapeObject.CreateBasic(); //Debug.Log("direction=" + direction.Value); so.SetMeshable(mb, direction); return(so); }
public static Meshable[] DivideFormByDivsRatio(Meshable mb, float[] divs, int axis) { List <Meshable> outMeshable = new List <Meshable>(); if (divs.Length == 0) { outMeshable.Add((Meshable)mb.Clone()); return(outMeshable.ToArray()); } Vector3 n = mb.bbox.vects[axis]; //Debug.Log("n=" + n); Vector3 org = mb.bbox.vertices[0]; Vector3 offset = n * divs[0] * mb.bbox.size[axis]; org += offset; //Debug.Log("offset=" + offset); Plane pln = new Plane(n, org); Meshable[] splits = mb.SplitByPlane(pln); if (splits[0] != null) { splits[0].bbox = BoundingBox.CreateFromPoints(splits[0].vertices, mb.bbox); outMeshable.Add(splits[0]); } else { throw new System.Exception("splits[0] is null!"); } Meshable remain = splits[1]; int counter = 0; while (remain != null && counter < divs.Length) { org += offset; //Debug.Log("org=" + org); pln = new Plane(n, org); splits = remain.SplitByPlane(pln); //splits = Rules.Bisect.SplitByPlane(remain, pln); if (splits[0] != null) { splits[0].bbox = BoundingBox.CreateFromPoints(splits[0].vertices, mb.bbox); outMeshable.Add(splits[0]); } else { break; //throw new System.Exception("splits[0] is null!"); } remain = splits[1]; counter++; } return(outMeshable.ToArray()); }
public void AddFace(string name, Meshable face, float bayWidth = 6) { if (!faces.ContainsKey(name)) { faces[name] = new List <Facade>(); } Facade fc = new Facade(face, name, bayWidth); faces[name].Add(fc); }
public override void Execute() { //outMeshables.Clear(); int rqEdgeCount = (int)(((ParameterGroup)paramGroups["EdgeCount"]).parameters[0].Value); int rqArea = (int)(((ParameterGroup)paramGroups["Area"]).parameters[0].Value); //outputs.shapes.Clear(); List <ShapeObject> pass = new List <ShapeObject>(); List <ShapeObject> fail = new List <ShapeObject>(); foreach (ShapeObject so in inputs.shapes) { Meshable m = so.meshable; int edgeCount; float area; if (m.GetType() == typeof(SGGeometry.Extrusion)) { Extrusion etx = (Extrusion)m; edgeCount = etx.polygon.vertices.Length; area = etx.polygon.Area(); } else if (m.GetType() == typeof(SGGeometry.Polygon)) { Polygon pg = (Polygon)m; edgeCount = pg.vertices.Length; area = pg.Area(); } else { area = -1; edgeCount = -1; } bool meetEdgeCount = false; if (rqEdgeCount < 0) { meetEdgeCount = true; } if (rqEdgeCount == edgeCount) { meetEdgeCount = true; } if (area >= rqArea && meetEdgeCount) { pass.Add(so); } else { fail.Add(so); } } UpdateOutputShapes(pass); }
public override List <Meshable> ExecuteShape(ShapeObject so) { float dx = ((ParameterGroup)paramGroups["SizeAddition"]).parameters[0].Value; float dy = ((ParameterGroup)paramGroups["SizeAddition"]).parameters[1].Value; float dz = ((ParameterGroup)paramGroups["SizeAddition"]).parameters[2].Value; //get Size Vector3 size = new Vector3(dx, dy, dz); if (randRange.HasValue) { float min = randRange.Value[0]; float max = randRange.Value[1]; for (int i = 0; i < 3; i++) { size[i] = size[i] * (1 + Random.Range(min, max)); } } if (size.z > size.x) { size.x = size.z; } Vector3 scale = new Vector3(1, 1, 1); Vector3 soSize = so.transform.localScale; for (int i = 0; i < 3; i++) { scale[i] = 1 + (size[i] / soSize[i]); } Vector3[] vects = so.Vects; Vector3 origin = so.transform.position; //get the splited meshables Meshable mb = so.meshable; Meshable scaledMb = mb.Scale(scale, vects, origin, true); //TODO: just scale the bbox scaledMb.bbox = BoundingBox.CreateFromPoints(scaledMb.vertices, so.meshable.bbox); //outMeshables.Add(scaledMb); List <Meshable> outs = new List <Meshable>(); outs.Add(scaledMb); AssignNames(outs); //AssignNames(outMeshables.ToArray()); return(outs); //Rule.Execute() will take care of the outMeshables }
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"; }
public static Meshable[] DivideFormByCount(Meshable mb, int count, int axis) { float ratio = (float)1 / (float)count; float[] divs = new float[count]; for (int i = 0; i < divs.Length; i++) { divs[i] = ratio; //Debug.LogFormat("ratio[{0}]={1}", i,ratio); } return(DivideFormByDivsRatio(mb, divs, axis)); }
void Load() { mb = GetComponent <ShapeObject>().meshable; mesh = GetComponent <MeshFilter>().mesh; osps = new List <OSP>(); foreach (Meshable m in ((CompositMeshable)mb).components) { //foreach (Vector3 v in m.vertices) for (int i = 0; i < m.vertices.Length; i++) { osps.Add(new OSP(i.ToString())); } } }
public override List <Meshable> ExecuteShape(ShapeObject so) { float dx = ((ParameterGroup)paramGroups["Scale"]).parameters[0].Value; float dy = ((ParameterGroup)paramGroups["Scale"]).parameters[1].Value; float dz = ((ParameterGroup)paramGroups["Scale"]).parameters[2].Value; //round to divisible by 4 float h = so.Size[1] * dy; h -= h % 4; dy = h / so.Size[1]; Vector3 scale = new Vector3(dx, dy, dz); if (randRange.HasValue) { float min = randRange.Value[0]; float max = randRange.Value[1]; for (int i = 0; i < 3; i++) { scale[i] = scale[i] * (1 + Random.Range(min, max)); } } Vector3[] vects = so.Vects; Vector3 origin = so.transform.position; if (alignment.HasValue) { origin = so.meshable.bbox.GetOriginFromAlignment(alignment.Value); } //get the splited meshables Meshable mb = so.meshable; Meshable scaledMb = mb.Scale(scale, vects, origin, true); //TODO: just scale the bbox scaledMb.bbox = BoundingBox.CreateFromPoints(scaledMb.vertices, so.meshable.bbox); //outMeshables.Add(scaledMb); List <Meshable> outs = new List <Meshable>(); outs.Add(scaledMb); AssignNames(outs); //AssignNames(outMeshables.ToArray()); return(outs); //Rule.Execute() will take care of the outMeshables }
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"; } }
private void UpdateDic(Dictionary <string, Meshable> dic) { if (dic != null && dic.Values.Count > 0) { string[] keys = dic.Keys.ToArray <string>(); for (int i = 0; i < keys.Length; i++) { string guid = keys[i]; if (dic.ContainsKey(guid)) { Meshable mb = dic[guid]; UpdateGeometry(guid, mb); } } dic.Clear(); } }
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); } }
public void CutShapeObjectsToFloors() { List <ShapeObject> sos = new List <ShapeObject>(); if (floorHeight == null) { throw new System.Exception("floorHeight=null"); } if (floorHeight.Count < 1) { throw new System.Exception("floor count<1"); } //Debug.Log("CutShapeObjectsToFloors"); //Debug.Log(floorHeight.Count); //foreach (float h in floorHeight.heights) Debug.Log(h); for (int i = 0; i < floorHeight.Count; i++) { List <Meshable> mbs = new List <Meshable>(); float h = floorHeight.heights[i]; foreach (Grammar g in grammars) { foreach (ShapeObject o in g.stagedOutputs[g.stagedOutputs.Count - 1].shapes) { Meshable remain; Meshable mb = CutShapeObjectToFloors(o.meshable, h, out remain); if (mb != null) { mbs.Add(mb); } if (remain == null) { break; } mb = CutShapeObjectToFloors(remain, h, out remain); if (mb != null) { mbs.Add(mb); } } } floors[i].SetMeshables(mbs); } }
public static List <Meshable> SplitByPlane(Meshable mb, Plane pln) { List <Meshable> outs = new List <Meshable>(); //get the splited meshables Meshable[] temp = new Meshable[0]; temp = mb.SplitByPlane(pln); for (int i = 0; i < temp.Length; i++) { if (temp[i] != null) { //Debug.Log("---------------------->creating boundong box"); temp[i].bbox = BoundingBox.CreateFromPoints(temp[i].vertices, mb.bbox); outs.Add(temp[i]); } } return(outs); }
public Meshable CutShapeObjectToFloors(Meshable form, float h, out Meshable remain) { //add cuted meshables to floor and return the remaining meshable Vector3 bot = ((Extrusion)form).polygon.vertices[0]; Plane? cutter = null; if (h > bot.y) { cutter = new Plane(Vector3.up, new Vector3(0, h, 0)); } if (cutter.HasValue) { Meshable[] splits = form.SplitByPlane(cutter.Value); remain = splits[1]; if (splits[0] != null) { return(splits[0]); } } remain = null; return(null); }
public static void ScaleForm(Meshable mb, Vector3 scale, Alignment?alignment = null) { Vector3 org = mb.bbox.GetOriginFromAlignment(alignment); mb.Scale(scale, mb.bbox.vects, org, false); }
public Facade(Meshable face, string name, float width = 6, float height = float.NaN) : this(face, width, height) { facadeType = name; }
public Facade(Meshable face, float width = 6, float height = float.NaN) { this.face = face; bayWidth = width; bayHeight = height; }
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; } } }
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; } } }
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()); }