/// <summary> /// UI function for drawing Shape data to the Scene window in a tree form. /// </summary> /// <param name="shape">The shape to show content for.</param> /// <param name="indent">The amount to indent the tree information.</param> void DoUIShape(BShape shape, float indent) { GUILayout.BeginHorizontal(); GUILayout.Space(indent); GUILayout.Box("SHAPE"); shape.name = GUILayout.TextField(shape.name, GUILayout.Width(200.0f)); GUILayout.EndHorizontal(); foreach (BLoop loop in shape.loops) { this.DoUILoop(loop, indent + 20.0f); } }
/// <summary> /// Create fill geometry for a shape, or update the geometry if it already exists. /// </summary> /// <param name="bs">The shape to fill.</param> /// <param name="ft">The fill type.</param> /// <param name="width">The outline width of the fill. Only relevant for ft values that have an outline.</param> public void UpdateForFill(BShape bs, FillType ft, float width) { FillEntry fe; if (this.fillEntries.TryGetValue(bs, out fe) == false) { GameObject go = new GameObject("ShapeFill"); MeshFilter mf = go.AddComponent <MeshFilter>(); MeshRenderer mr = go.AddComponent <MeshRenderer>(); fe.go = go; fe.mf = mf; fe.mr = mr; this.fillEntries.Add(bs, fe); } Mesh m = new Mesh(); fe.mf.mesh = m; fe.mesh = m; if (ft == FillType.Filled) { List <int> triangles = new List <int>(); Vector2Repo vectorRepo = new Vector2Repo(); FillSession session = new FillSession(); session.ExtractFillLoops(bs); session.GetTriangles(triangles, vectorRepo, true, FillIsland.WindingRequirement.Clockwise, true); fe.mesh.SetVertices(vectorRepo.GetVector3Array()); fe.mesh.SetIndices(triangles, MeshTopology.Triangles, 0); Material matFill = new Material(this.standardShader); matFill.color = Color.white; fe.mr.sharedMaterial = matFill; } else if (ft == FillType.Outlined) { List <int> triangles = new List <int>(); Vector2Repo vectorRepo = new Vector2Repo(); FillSession session = new FillSession(); session.ExtractFillLoops(bs); foreach (FillIsland fi in session.islands) { fi.MakeOutlineBridged(width); } session.GetTriangles(triangles, vectorRepo, true, FillIsland.WindingRequirement.Clockwise, true); fe.mesh.SetVertices(vectorRepo.GetVector3Array()); fe.mesh.SetIndices(triangles, MeshTopology.Triangles, 0); Material matStroke = new Material(this.standardShader); matStroke.color = Color.black; fe.mr.sharedMaterial = matStroke; } else if (ft == FillType.FilledAndOutlined) { List <int> triangles = new List <int>(); List <int> strokeTris = new List <int>(); Vector2Repo vectorRepo = new Vector2Repo(); FillSession session = new FillSession(); session.ExtractFillLoops(bs); FillSession outSession = session.Clone(); session.GetTriangles(triangles, vectorRepo, true, FillIsland.WindingRequirement.Clockwise, true); foreach (FillIsland fi in outSession.islands) { fi.MakeOutlineBridged(width); } outSession.GetTriangles(strokeTris, vectorRepo, true, FillIsland.WindingRequirement.Clockwise, true); fe.mesh.subMeshCount = 2; fe.mesh.SetVertices(vectorRepo.GetVector3Array()); fe.mesh.SetIndices(triangles, MeshTopology.Triangles, 0); fe.mesh.SetIndices(strokeTris, MeshTopology.Triangles, 1); Material matFill = new Material(this.standardShader); matFill.color = Color.white; Material matStroke = new Material(this.standardShader); matStroke.color = Color.black; fe.mr.sharedMaterials = new Material[] { matFill, matStroke }; } }