예제 #1
0
        public override void Execute(MTree tree)
        {
            base.Execute(tree);

            Random.InitState(seed);
            int selection = parent == null ? 0 : parent.id;

            tree.Grow(length, lengthCurve, resolution, splitProba, splitProbaCurve, splitAngle, maxSplits, selection
                      , id, randomness, radius, splitRadius, upAttraction, gravityStrength, 0f, 0.001f);
        }
예제 #2
0
        public override void Execute(MTree tree)
        {
            base.Execute(tree);

            Random.InitState(seed);
            int selection = parent == null ? 0 : parent.id;

            tree.AddBranches(selection, length, lengthCurve, resolution, number, splitProba, splitProbaCurve, angle
                             , randomness, shape, radius, upAttraction, id, start, gravityStrength, 0f, 0.001f);
        }
예제 #3
0
        void UpdateBranch(bool normalShader = false)
        {
            switch (texSize)
            {
            case EnumTextureSize._512:
                textureSize = 512;
                break;

            case EnumTextureSize._1024:
                textureSize = 1024;
                break;

            case EnumTextureSize._2048:
                textureSize = 2048;
                break;

            case EnumTextureSize._4096:
                textureSize = 4096;
                break;
            }

            if (branchObject == null)
            {
                CreateBranchObject(normalShader);
            }

            CreateLeafMesh();
            MTree        branch = new MTree(branchObject.transform);
            TreeFunction trunkF = new TreeFunction(0, FunctionType.Trunk, null);

            float resolution = 20;

            Random.InitState(seed);


            branch.AddTrunk(Vector3.up, Vector3.forward, stemLength, AnimationCurve.Linear(0, 1, 1, .3f), radius, resolution, randomness / 3, 0, AnimationCurve.Linear(0, 1, 0, 0), 0, .01f, 1, 0);
            branch.TwigSplit(branchNumber, angle * 90f, .9f, 0f);
            branch.Grow(length, AnimationCurve.Linear(0, 1, 1, 1), resolution, splitProba, AnimationCurve.Linear(0, 1, 1, 1), angle, 2, 1, 1, randomness, AnimationCurve.Linear(0, 1, 1, .4f), .9f, 0f, 0f, 1f, 0.00001f);

            branch.AddLeafs(leafCovering, leafNumber, new Mesh[] { leafMesh }, leafSize, false, 0, 0, 1, leafAngle, false, 0, 0, 0, 0);

            Mesh mesh = CreateBranchMesh(branch, trunkF);

            branchObject.GetComponent <MeshFilter>().mesh = mesh;

            if (cameraObject == null)
            {
                CreateCameraObject();
            }
            RenderCamera();

            DestoyObjects();
        }
예제 #4
0
        Mesh CreateBranchMesh(MTree branch, TreeFunction trunkFunction)
        {
            Mesh mesh = new Mesh();

            branch.GenerateMeshData(trunkFunction, 0, 1);
            mesh.vertices = branch.verts;
            mesh.normals  = branch.normals;
            mesh.uv       = branch.uvs;
            Color[] colors = branch.colors;
            mesh.triangles = branch.triangles;
            if (branch.leafTriangles.Length > 0)
            {
                mesh.subMeshCount = 2;
                mesh.SetTriangles(branch.leafTriangles, 1);
            }
            mesh.colors = colors;
            return(mesh);
        }
        public override void Execute(MTree tree)
        {
            base.Execute(tree);

            Random.InitState(seed);
            int  selection  = parent == null ? 0 : parent.id;
            bool procedural = leafType == 5;

            Mesh[] leafMeshes = null;
            switch (leafType)
            {
            case 0:
                leafMeshes = new Mesh[] { Resources.LoadAll <Mesh>("Mtree/branches")[0] };
                break;

            case 1:
                leafMeshes = new Mesh[] { Resources.LoadAll <Mesh>("Mtree/branches")[1] };
                break;

            case 2:
                leafMeshes = new Mesh[] { Resources.LoadAll <Mesh>("Mtree/branches")[2], Resources.LoadAll <Mesh>("Mtree/branches")[3] };
                break;

            case 3:
                leafMeshes = new Mesh[] { Resources.LoadAll <Mesh>("Mtree/branches")[4], Resources.LoadAll <Mesh>("Mtree/branches")[5] };
                break;

            case 4:
                leafMeshes = new Mesh[] { Resources.LoadAll <Mesh>("Mtree/branches")[6] };
                break;

            case 5:
                leafMeshes = null;
                break;

            case 6:
                leafMeshes = new Mesh[] { customLeafMesh };
                break;
            }

            tree.AddLeafs(maxRadius, number, leafMeshes, size, overrideNormals, minWeight, maxWeight, selection, 70, procedural, length, resolution, uLoops, gravityStrength);
        }
        public void Execute(MTree tree)
        {
            int selection = parent == null ? 0 : parent.id;

            Random.InitState(seed);


            if (type == FunctionType.Trunk)
            {
                tree.AddTrunk(Vector3.down * TheightOffset, Vector3.up, Tlength, Tradius, TradiusMultiplier, Tresolution, Trandomness
                              , id, TrootShape, TrootRadius, TrootHeight, TrootResolution, ToriginAttraction);
            }


            if (type == FunctionType.Grow)
            {
                tree.Grow(Glength, GlengthCurve, Gresolution, GsplitProba, GsplitProbaCurve, GsplitAngle, GmaxSplits, selection
                          , id, Grandomness, Gradius, GsplitRadius, GupAttraction, GgravityStrength, 0f, 0.001f);
            }

            if (type == FunctionType.Split)
            {
                tree.Split(selection, Snumber, SsplitAngle, id, SsplitRadius, Sstart, Sspread, 0f);
            }

            if (type == FunctionType.Branch)
            {
                tree.AddBranches(selection, Blength, BlengthCurve, Bresolution, Bnumber, BsplitProba, BsplitProbaCurve, Bangle
                                 , Brandomness, Bshape, Bradius, BupAttraction, id, Bstart, BgravityStrength, 0f, 0.001f);
            }

            if (type == FunctionType.Leaf)
            {
                tree.AddLeafs(LmaxRadius, Lnumber, LleafMesh, Lsize, LoverrideNormals, LminWeight, LmaxWeight, selection, 70, Lprocedural, Llength, Lresolution, LuLoops, LgravityStrength);
            }
        }