コード例 #1
0
        public static void DrawGizmos(this IShapeConfiguration configuration, Transform parent, bool showCorners = true, bool showEdges = true, bool showComponents = true)
        {
            configuration.RootNode.TraverseBreadthFirst(node => {
                var shapeNode = (ShapeNode)node;

                var vol = shapeNode.Value.Volume;

                if (vol != null)
                {
                    vol.DrawGizmos(parent);
                    if (showCorners)
                    {
                        vol.DrawCornerGizmos(parent);
                    }
                    if (showEdges)
                    {
                        vol.DrawEdgeGizmos(parent);
                    }
                    if (showComponents)
                    {
                        vol.DrawComponentGizmos(parent);
                    }
                }
            });
        }
コード例 #2
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;
        }
コード例 #3
0
        public void Execute(IShapeConfiguration configuration)
        {
            switch (Name)
            {
            case "Set":
            case "Vol":
                var volArgs = configuration.ResolveArgs(this.Arguments);
                var volName = volArgs [0].Value;
                //          var volStyle = volArgs.Length > 1 ? volArgs[1].Value : null;
                configuration.AddVolume(volName, volArgs);  // TODO: pass named args.
                break;

            case "Trans":
                var axes = configuration.ResolveArgs(this.Arguments).Select(x => Size.Parse(x.Value)).ToArray();
                configuration.TranslateScope(axes[0], axes[1], axes[2]);
                break;

            case "Rot":
                var rotAxes = configuration.ResolveArgs(this.Arguments).Select(x => float.Parse(x.Value)).ToArray();
                configuration.RotateScope(new Vector3(rotAxes [0], rotAxes [1], rotAxes [2]));
                break;

            case "Scale":
                var scaleSizes = configuration.ResolveArgs(this.Arguments).Select(x => Size.Parse(x.Value)).ToArray();
                configuration.ScaleScope(scaleSizes [0], scaleSizes [1], scaleSizes [2]);
                break;

            case "Push":
                configuration.PushScope();
                break;

            case "Pop":
                configuration.PopScope();
                break;

            case "Subdiv":
                var subdivArgs = configuration.ResolveArgs(this.Arguments);
                var sizes      = subdivArgs.Skip(1).Select(arg => Size.Parse(arg.Value)).ToArray();
                configuration.SplitDivideScope(subdivArgs [0].Value, sizes, Shapes);
                break;

            case "Comp":
                var compArgs = configuration.ResolveArgs(this.Arguments);
                configuration.SplitComponent(compArgs[0].Value, Shapes[0]);
                break;

            case "Repeat":
                var repeatArgs = configuration.ResolveArgs(this.Arguments);
                var repeatSize = Size.Parse(repeatArgs[1].Value);
                configuration.Repeat(repeatArgs[0].Value, repeatSize, Shapes[0]);
                break;

            default:
                throw new System.ArgumentException(string.Format("Unknown command: {0}", this.Name), "Name");
            }
        }
コード例 #4
0
    private void AddScopeComponentTextMeshes(IShapeConfiguration configuration)
    {
        configuration.RootNode.TraverseBreadthFirst(node => {
            var shapeNode = (ShapeNode)node;
            var vol       = shapeNode.Value.Volume;

            if (vol != null)
            {
                foreach (var comp in vol.Components)
                {
                    var name  = comp.Name;
                    var trans = comp.Transform;

                    var worldPos = vol.Transform.Position + (vol.Transform.Rotation * Vector3.Scale(trans.Position, vol.Transform.Scale));

                    var textGo = (GameObject)GameObject.Instantiate(this.faceTextPrefab);
                    textGo.transform.parent     = this.rootGo.transform;
                    var textMesh                = textGo.GetComponent <TextMesh>();
                    textMesh.text               = name;
                    textMesh.transform.position = worldPos;
                }
            }
        });
    }