Ejemplo n.º 1
0
    public override void OnInspectorGUI()
    {
        DrawDefaultInspector();

        TreeGenerator tree = (TreeGenerator)target;

        if (GUILayout.Button("Build"))
        {
            tree.Build();
        }
    }
Ejemplo n.º 2
0
        public void CanGenerateSimpleTree()
        {
            // ARRANGE
            var position = new Vector3(0, 0, 0);

            // ACT
            var treeGen = new TreeGenerator()
                          .SetTrunkGradient(_trunkGradient)
                          .SetFoliageGradient(_foliageGradient)
                          .SetPosition(position);

            var vertCount = treeGen.CalculateVertexCount();
            var meshData  = new MeshData(DummyMeshIndex.Default, vertCount);

            treeGen.Build(meshData);

            // ASSERT
            Assert.Greater(meshData.Vertices.Length, 0);
            Assert.Greater(meshData.Triangles.Length, 0);
            Assert.Greater(meshData.Colors.Length, 0);
        }
Ejemplo n.º 3
0
        private void CreateForest(IGameObject parent, Rule rule, Mesh mesh)
        {
            var trunkGradientKey   = rule.Evaluate <string>("trunk-color");
            var foliageGradientKey = rule.Evaluate <string>("foliage-color");
            int treeFreq           = (int)(1 / rule.EvaluateDefault <float>("tree-freq", 0.1f));
            // TODO reuse tree builder?
            // TODO behaviour should be set somehow
            var node = new Node();

            foreach (var triangle in mesh.Triangles)
            {
                // TODO reuse mesh and/or generator?
                if (triangle.Id % treeFreq != 0)
                {
                    continue;
                }

                var v0 = triangle.GetVertex(0);
                var v1 = triangle.GetVertex(1);
                var v2 = triangle.GetVertex(2);

                var center    = new Vector2d((v0.X + v1.X + v2.X) / 3, (v0.Y + v1.Y + v2.Y) / 3);
                var elevation = ElevationProvider.GetElevation(center);

                var treeGen = new TreeGenerator()
                              .SetTrunkGradient(CustomizationService.GetGradient(trunkGradientKey))
                              .SetFoliageGradient(CustomizationService.GetGradient(foliageGradientKey))
                              .SetPosition(new Vector3((float)center.X, elevation, (float)center.Y));

                var meshData = new MeshData(MeshDestroyIndex.Default, treeGen.CalculateVertexCount());
                meshData.GameObject  = GameObjectFactory.CreateNew("tree");
                meshData.MaterialKey = rule.GetMaterialKey();

                treeGen.Build(meshData);

                BuildObject(parent, meshData, rule, node);
            }
        }
Ejemplo n.º 4
0
        /// <inheritdoc />
        public override IGameObject BuildNode(Tile tile, Rule rule, Node node)
        {
            var mapPoint  = GeoProjection.ToMapCoordinate(tile.RelativeNullPoint, node.Point);
            var elevation = ElevationProvider.GetElevation(mapPoint);

            var trunkGradientKey   = rule.Evaluate <string>("trunk-color");
            var foliageGradientKey = rule.Evaluate <string>("foliage-color");

            var treeGen = new TreeGenerator()
                          .SetTrunkGradient(CustomizationService.GetGradient(trunkGradientKey))
                          .SetFoliageGradient(CustomizationService.GetGradient(foliageGradientKey))
                          .SetPosition(new Vector3((float)mapPoint.X, elevation, (float)mapPoint.Y));

            var meshData = new MeshData(MeshDestroyIndex.Default, treeGen.CalculateVertexCount());

            meshData.GameObject  = GameObjectFactory.CreateNew("tree " + node.Id);
            meshData.MaterialKey = rule.GetMaterialKey();

            treeGen.Build(meshData);

            BuildObject(tile.GameObject, meshData, rule, node);

            return(meshData.GameObject);
        }