Ejemplo n.º 1
0
        private void BuildMesh(IShapeConfiguration configuration, IStyleConfig styleConfig, out Mesh mesh, out Dictionary <string, NodeMeshData> data)
        {
            var meshBuilder = new MeshBuilder();

            var tmpNodeMeshData = new Dictionary <string, NodeMeshData>();

            configuration.RootNode.TraverseBreadthFirst(node => {
                var shapeNode = (ShapeNode)node;
                var vol       = shapeNode.Value.Volume;

                if (node.IsLeaf && vol != null)
                {
                    var colStart = meshBuilder.Colors.Count;

                    vol.BuildMesh(meshBuilder, styleConfig);

                    var colAdded = meshBuilder.Colors.Count - colStart;

                    var md         = new NodeMeshData();
                    md.ColorsStart = colStart;
                    md.ColorsEnd   = md.ColorsStart + colAdded;

                    tmpNodeMeshData.Add(shapeNode.Id + "-" + shapeNode.Value.Rule.Symbol, md);
                }
            });

            mesh = meshBuilder.BuildMesh();
            mesh.RecalculateBounds();
            mesh.RecalculateNormals();
            mesh.Optimize();

            data = tmpNodeMeshData;
        }
Ejemplo n.º 2
0
        protected override void ApplyStyle(IStyleConfig styleConfig)
        {
            var faceColor = styleConfig.GetColor(this.Style, this.Theme, "face-color");

            foreach (var f in this.Faces)
            {
                f.Color = faceColor;
            }
        }
Ejemplo n.º 3
0
        protected override void ApplyStyle(IStyleConfig styleConfig)
        {
            var faceColor = styleConfig.GetColor(this.Style, this.Theme, "face-color");

            this.Faces[0].Color = faceColor;
            this.Faces[1].Color = faceColor;
            this.Faces[2].Color = faceColor;
            this.Faces[3].Color = faceColor;
        }
Ejemplo n.º 4
0
        protected override void ApplyStyle(IStyleConfig styleConfig)
        {
            var topColor  = styleConfig.GetColor(this.Style, this.Theme, "top-color");
            var sideColor = styleConfig.GetColor(this.Style, this.Theme, "side-color");

            this.Faces[0].Color = topColor;
            this.Faces[1].Color = topColor;
            this.Faces[2].Color = sideColor;
            this.Faces[3].Color = sideColor;
        }
Ejemplo n.º 5
0
        public Mesh BuildMesh(IStyleConfig styleConfig)
        {
            var meshBuilder = new MeshBuilder();

            this.BuildMesh(meshBuilder, styleConfig);

            var mesh = meshBuilder.BuildMesh();

            mesh.RecalculateBounds();
            mesh.RecalculateNormals();
            mesh.Optimize();

            return(mesh);
        }
Ejemplo n.º 6
0
        protected override void ApplyStyle(IStyleConfig styleConfig)
        {
            foreach (var groupName in this.groupNames)
            {
                var key   = string.Format("{0}-color", groupName);
                var color = styleConfig.GetColor(this.Style, this.Theme, key);

                foreach (var f in this.Faces)
                {
                    if (f.Name.StartsWith(string.Format("face-{0}", groupName), StringComparison.InvariantCultureIgnoreCase))
                    {
                        f.Color = color;
                    }
                }
            }
        }
Ejemplo n.º 7
0
        public virtual void BuildMesh(IMeshBuilder meshBuilder, IStyleConfig styleConfig)
        {
            this.ApplyStyle(styleConfig);

            var baseIndex = meshBuilder.Vertices.Count;

            foreach (var face in this.Faces)
            {
                var numVerts = face.Corners.Count;

                for (int i = 0; i < face.Corners.Count; i++)
                {
                    var v  = face.Corners[i].Position;
                    var uv = face.UVs[i];

                    var worldPos = this.Transform.Position + (this.Transform.Rotation * Vector3.Scale(v, this.Transform.Scale));

                    meshBuilder.Vertices.Add(worldPos);
                    meshBuilder.UVs.Add(uv);
                    meshBuilder.Colors.Add(face.Color);
                }

                if (numVerts == 3)
                {
                    meshBuilder.AddTriangle(baseIndex, baseIndex + 1, baseIndex + 2);
                }
                else if (numVerts == 4)
                {
                    meshBuilder.AddTriangle(baseIndex, baseIndex + 1, baseIndex + 3);
                    meshBuilder.AddTriangle(baseIndex + 1, baseIndex + 2, baseIndex + 3);
                }
                else
                {
                    throw new InvalidOperationException(string.Format("Cannot build mesh for faces with {0} vertices", numVerts));
                }

                baseIndex = meshBuilder.Vertices.Count;
            }
        }
Ejemplo n.º 8
0
 protected virtual void ApplyStyle(IStyleConfig styleConfig)
 {
 }
Ejemplo n.º 9
0
 protected override void ApplyStyle(IStyleConfig styleConfig)
 {
     this.Faces[0].Color = styleConfig.GetColor(this.Style, this.Theme, "face-color");
 }
Ejemplo n.º 10
0
        //  public static Color GetColor(this IStyleConfig styleConfig, string section, string key)
        //  {
        //      return (Color)styleConfig.GetStyle(section, key);
        //  }
        //
        //  public static Color GetColorOrDefault(this IStyleConfig styleConfig, string section, string key, Color defaultValue)
        //  {
        //      return (Color)(styleConfig.GetStyleOrDefault(section, key, null) ?? defaultValue);
        //  }

        public static Color GetColor(this IStyleConfig styleConfig, string style, string theme, string key)
        {
            return((Color)styleConfig.GetStyle(style, theme, key));
        }