public FlowVertexNode[] AllNodes() { FlowVertexNode[] ans = new FlowVertexNode[3] { NodeA, NodeB, NodeC }; return(ans); }
public FlowVertexNode[] EachVertex() { FlowVertexNode[] verts = new FlowVertexNode[3]; verts [0] = A; verts [1] = B; verts [2] = C; return(verts); }
public MeshTri(FlowVertexNode _a, FlowVertexNode _b, FlowVertexNode _c) { this.A = _a; this.B = _b; this.C = _c; var bnds = this.EachVertex() .Select(k => new SpanOf <Vector3>(k.Location, k.Location)) .Aggregate((A, B) => new SpanOf <Vector3>(Vector3.Min(A.From, B.From), Vector3.Max(A.To, B.To))); this.CenterLocation = (bnds.From + bnds.To) * 0.5f; //(A.Location + B.Location + C.Location)/3.0f; this.CenterRadius = this.EachVertex() .Select(k => (k.Location - this.CenterLocation).magnitude) .Aggregate((a, b) => Mathf.Max(a, b)); }
EnergyLine CreateLineObjects(Transform parent, FlowVertexNode a, FlowVertexNode b) { GameObject go = GameObject.CreatePrimitive(PrimitiveType.Cube); go.name = "energy line"; go.transform.parent = parent; go.transform.position = Avg(a.Location, b.Location); go.transform.LookAt(b.Location); go.transform.localScale = new Vector3(DefaultLineThickness, DefaultLineThickness, (b.Location - a.Location).magnitude); go.GetComponent <Collider> ().enabled = false; go.GetComponent <MeshRenderer> ().material = this.MaterialForLines; var line = go.AddComponent <EnergyLine> (); line.NodeA = a; line.NodeB = b; return(line); }
void DoFixMissingComponents() { var flowNodes = GameObject.FindObjectsOfType <FlowVertexNode> (); for (int ci = 0; ci < this.transform.childCount; ci++) { var c = this.transform.GetChild(ci); if (c.GetComponent <FlowTriangle>() != null) { continue; } var mf = c.GetComponent <MeshFilter>(); if (mf != null) { var m = mf.mesh; List <FlowVertexNode> mynodes = new List <FlowVertexNode>(); for (int vi = 0; vi < 3; vi++) { var pos = m.vertices[vi] + c.transform.position; FlowVertexNode bestNode = null; float bestDist = 10000.0f; foreach (var fn in flowNodes) { var d = (fn.Location - pos).magnitude; if (d < bestDist) { bestNode = fn; bestDist = d; } } if (bestDist > 0.1f) { Debug.LogError("No node found!!!"); } mynodes.Add(bestNode); } FlowTriangle ft = c.gameObject.AddComponent <FlowTriangle>(); ft.NodeA = mynodes[0]; ft.NodeB = mynodes[1]; ft.NodeC = mynodes[2]; } } }
public bool ReferencesVertex(FlowVertexNode v) { return((A == v) || (B == v) || (C == v)); }