private TreeFunctionAsset ToTrunkFunction(TreeFunctionAsset parent)
        {
            TrunkFunction function = ScriptableObject.CreateInstance <TrunkFunction>();

            function.Init(parent);
            function.number               = Tnumber;
            function.displacementSize     = TdisplacementSize;
            function.displacementStrength = TdisplacementStrength;
            function.seed             = seed;
            function.flareNumber      = TflareNumber;
            function.heightOffset     = TheightOffset;
            function.length           = Tlength;
            function.originAttraction = ToriginAttraction;
            function.radius           = Tradius;
            function.radiusMultiplier = TradiusMultiplier;
            function.randomness       = Trandomness;
            function.resolution       = Tresolution;
            function.rootHeight       = TrootHeight;
            function.rootInnerRadius  = TrootInnerRadius;
            function.rootRadius       = TrootRadius;
            function.rootResolution   = TrootResolution;
            function.rootShape        = TrootShape;
            function.spinAmount       = TspinAmount;

            return(function);
        }
예제 #2
0
        public static TreeTemplate CreateFromFunctions(List <TreeFunctionAsset> functionsToCopy, string path)
        {
            List <TreeFunctionAsset> treeFunctions = new List <TreeFunctionAsset>();

            for (int i = 0; i < functionsToCopy.Count; i++)
            {
                TreeFunctionAsset function = Instantiate(functionsToCopy[i]);
                treeFunctions.Add(function);
            }

            for (int i = 0; i < functionsToCopy.Count; i++)
            {
                int parentIndex          = functionsToCopy.IndexOf(functionsToCopy[i].parent);
                TreeFunctionAsset parent = parentIndex == -1 ? null : treeFunctions[parentIndex];
                treeFunctions[i].Init(parent, true);
            }

            TreeTemplate template = ScriptableObject.CreateInstance <TreeTemplate>();

            template.treeFunctions = treeFunctions;

            AssetDatabase.CreateAsset(template, path);

            template = AssetDatabase.LoadAssetAtPath <TreeTemplate>(path);

            for (int i = 0; i < treeFunctions.Count; i++)
            {
                AssetDatabase.AddObjectToAsset(treeFunctions[i], template);
            }

            AssetDatabase.SaveAssets();
            AssetDatabase.Refresh();

            return(template);
        }
예제 #3
0
 public virtual void Init(TreeFunctionAsset parent, bool preserveSettings = false)
 {
     this.parent = parent;
     if (parent != null)
     {
         parent.chiildren.Add(this);
     }
     chiildren = new List <TreeFunctionAsset>();
     id        = System.Guid.NewGuid().GetHashCode();
 }
 public override void Init(TreeFunctionAsset parent, bool preserveSettings = false)
 {
     base.Init(parent);
     name = "Grow";
     if (!preserveSettings)
     {
         Keyframe[] keys = new Keyframe[2] {
             new Keyframe(0f, 1f, 0f, 0f), new Keyframe(1f, 0f, -.5f, -1f)
         };
         radius = new AnimationCurve(keys);
     }
 }
        private TreeFunctionAsset ToSplitFunction(TreeFunctionAsset parent)
        {
            SplitFunction function = ScriptableObject.CreateInstance <SplitFunction>();

            function.Init(parent);
            function.number      = Snumber * 3;
            function.seed        = seed;
            function.splitAngle  = SsplitAngle;
            function.splitRadius = SsplitRadius;
            function.spread      = Sspread;
            function.start       = Sstart;
            return(function);
        }
        public override void OnInspectorGUI()
        {
            EditorGUIUtility.labelWidth = 135;
            int   functionCount        = template.treeFunctions.Count;
            int   rectHeightMultiplier = TreeFunctionAsset.height + TreeFunctionAsset.margin;
            int   rectHeight           = functionCount * rectHeightMultiplier; // get the height of the drawing window inside inspector
            Event e = Event.current;                                           // Get current event

            int heighIndex = 0;

            template.treeFunctions[0].UpdateRectRec(ref heighIndex, 0);

            EditorGUILayout.BeginVertical(EditorStyles.helpBox);
            EditorGUILayout.LabelField("Tree functions", EditorStyles.boldLabel);

            Rect rect = GUILayoutUtility.GetRect(10, 1000, rectHeight, rectHeight); // Create drawing window

            GUI.BeginClip(rect);

            for (int i = 0; i < template.treeFunctions.Count; i++)
            {
                template.treeFunctions[i].DrawFunction(i == selectedFuntionIndex, false);
            }

            GUI.EndClip();
            EditorGUILayout.EndVertical();

            if (e.type == EventType.MouseDown && e.button == 0) // If mouse button is pressed, get button pressed and act accordingly
            {
                for (int i = 0; i < functionCount; i++)
                {
                    TreeFunctionAsset tf = template.treeFunctions[i];

                    if (tf.rect.Contains(e.mousePosition - rect.position))
                    {
                        selectedFuntionIndex = i;
                        GUIUtility.ExitGUI();
                        break;
                    }
                }
            }

            EditorGUILayout.BeginVertical(EditorStyles.helpBox);
            TreeFunctionAsset selectedFunction = template.treeFunctions[selectedFuntionIndex];

            selectedFunction.DrawProperties();
            EditorGUILayout.EndVertical();
        }
예제 #7
0
        public override void Init(TreeFunctionAsset parent, bool preserveSettings = false)
        {
            base.Init(parent);
            name = "Branch";

            if (parent != null && !(parent is TrunkFunction) && !preserveSettings)
            {
                length          = 3;
                start           = .3f;
                angle           = .4f;
                number          = 120;
                resolution      = 1;
                splitProba      = .3f;
                radius          = .8f;
                shape           = AnimationCurve.Linear(0, 1, 1, .1f);
                randomness      = .4f;
                gravityStrength = 1f;
            }
        }
        private TreeFunctionAsset ToLeafFunction(TreeFunctionAsset parent)
        {
            LeafFunction function = ScriptableObject.CreateInstance <LeafFunction>();

            function.Init(parent);
            function.gravityStrength = LgravityStrength;
            function.leafType        = LleafType;
            function.length          = Llength;
            function.lengthCurve     = LlengthCurve;
            function.maxRadius       = LmaxRadius;
            function.maxWeight       = LmaxWeight;
            function.minWeight       = LminWeight;
            function.number          = Lnumber;
            function.overrideNormals = LoverrideNormals;
            function.resolution      = Lresolution;
            function.seed            = seed;
            function.size            = Lsize;
            function.uLoops          = LuLoops;
            return(function);
        }
        private TreeFunctionAsset ToBranchFunction(TreeFunctionAsset parent)
        {
            BranchFunction function = ScriptableObject.CreateInstance <BranchFunction>();

            function.Init(parent);
            function.angle           = Bangle;
            function.gravityStrength = BgravityStrength;
            function.length          = Blength;
            function.lengthCurve     = BlengthCurve;
            function.number          = Bnumber * 3;
            function.radius          = Bradius;
            function.randomness      = Brandomness;
            function.resolution      = Bresolution;
            function.seed            = seed;
            function.shape           = Bshape;
            function.splitProba      = BsplitProba;
            function.splitProbaCurve = BsplitProbaCurve;
            function.start           = Bstart;
            function.upAttraction    = BupAttraction;
            return(function);
        }
        private TreeFunctionAsset ToGrowFunction(TreeFunctionAsset parent)
        {
            GrowFunction function = ScriptableObject.CreateInstance <GrowFunction>();

            function.Init(parent);
            function.gravityStrength = GgravityStrength;
            function.length          = Glength;
            function.lengthCurve     = GlengthCurve;
            function.maxSplits       = GmaxSplits;
            function.radius          = Gradius;
            function.randomness      = Grandomness;
            function.resolution      = Gresolution;
            function.seed            = seed;
            function.splitAngle      = GsplitAngle;
            function.splitProba      = GsplitProba;
            function.splitProbaCurve = GsplitProbaCurve;
            function.splitRadius     = GsplitRadius;
            function.upAttraction    = GupAttraction;

            return(function);
        }
        public TreeFunctionAsset ToFunctionAsset(TreeFunctionAsset parent)
        {
            switch (type)
            {
            case FunctionType.Trunk:
                return(ToTrunkFunction(parent));

            case FunctionType.Grow:
                return(ToGrowFunction(parent));

            case FunctionType.Split:
                return(ToSplitFunction(parent));

            case FunctionType.Branch:
                return(ToBranchFunction(parent));

            case FunctionType.Leaf:
                return(ToLeafFunction(parent));

            default:
                return(null);
            }
        }
예제 #12
0
        private void DisplayFunctionsTab()
        {
            EditorGUIUtility.labelWidth = 135;
            int functionCount = tree.treeFunctionsAssets.Count; // Used in multiple for loops

            EditorGUI.BeginDisabledGroup(tree.treeFunctionsAssets[tree.selectedFunctionIndex].name == "Leaves");
            if (GUILayout.Button("Add function"))
            {
                GenericMenu addFunctionMenu = new GenericMenu();
                addFunctionMenu.AddItem(new GUIContent("Add branch"), false, tree.AddBranchFunction);
                addFunctionMenu.AddItem(new GUIContent("Add Leafs"), false, tree.AddLeafFunction);
                addFunctionMenu.AddItem(new GUIContent("Split"), false, tree.AddSplitFunction);
                addFunctionMenu.AddItem(new GUIContent("Grow"), false, tree.AddGrowFunction);
                addFunctionMenu.ShowAsContext();
            }
            EditorGUI.EndDisabledGroup();

            int   rectHeight = functionCount * rectHeightMultiplier;                       // get the height of the drawing window inside inspector
            Rect  rect       = GUILayoutUtility.GetRect(10, 1000, rectHeight, rectHeight); // Create drawing window
            Event e          = Event.current;                                              // Get current event

            int heighIndex = 0;

            tree.treeFunctionsAssets[0].UpdateRectRec(ref heighIndex, 0);

            if (e.type == EventType.MouseDown && e.button == 0) // If mouse button is pressed, get button pressed and act accordingly
            {
                for (int i = 0; i < functionCount; i++)
                {
                    TreeFunctionAsset tf = tree.treeFunctionsAssets[i];


                    if (tf.rect.Contains(e.mousePosition - rect.position))
                    {
                        if (tf.deleteRect.Contains(e.mousePosition - rect.position))
                        {
                            tree.RemoveFunction(tf);
                            UpdateTree();
                        }
                        else
                        {
                            serializedObject.FindProperty("selectedFunctionIndex").intValue = i;
                            serializedObject.ApplyModifiedProperties();
                        }
                        GUIUtility.ExitGUI();
                        break;
                    }
                }
            }
            if (e.type == EventType.MouseDown && e.button == 1)
            {
                for (int i = 0; i < functionCount; i++)
                {
                    TreeFunctionAsset tf = tree.treeFunctionsAssets[i];
                    if (tf.rect.Contains(e.mousePosition - rect.position))
                    {
                        var menu = new GenericMenu();
                        if (!tf.name.Contains("Trunk"))
                        {
                            menu.AddItem(new GUIContent("Copy Tree Function"), false, SaveTF);
                        }
                        else
                        {
                            menu.AddDisabledItem(new GUIContent("Copy Tree Function"));
                        }


                        if (tree.savedFunction != null && tree.treeFunctionsAssets[tree.selectedFunctionIndex].name != "Leaves")
                        {
                            menu.AddItem(new GUIContent("Paste Tree Function"), false, InsertTF);
                        }
                        else
                        {
                            menu.AddDisabledItem(new GUIContent("Paste Tree Function"));
                        }

                        menu.ShowAsContext();
                        e.Use();
                    }
                }
            }
            GUI.BeginClip(rect);

            for (int i = 0; i < tree.treeFunctionsAssets.Count; i++)
            {
                tree.treeFunctionsAssets[i].DrawFunction(i == tree.selectedFunctionIndex, i > 0);
            }

            GUI.EndClip();

            EditorGUI.BeginChangeCheck();
            EditorGUILayout.BeginVertical(EditorStyles.helpBox);

            if (GUILayout.Button("Randomize tree"))
            {
                tree.RandomizeTree();
            }

            TreeFunctionAsset selectedFunction = tree.treeFunctionsAssets[tree.selectedFunctionIndex];

            selectedFunction.DrawProperties();

            EditorGUILayout.EndVertical();
            EditorGUILayout.BeginVertical(EditorStyles.helpBox);
            var gs = new GUIStyle();

            gs.richText = true;
            EditorGUILayout.LabelField("<b>Vertex Color Adjustment</b> <i>(Baked Wind Settings)</i>", gs);
            EditorGUILayout.Slider(serializedObject.FindProperty("VColBarkModifier"), 0.1f, 5, new GUIContent("Stem Multiplier"));
            EditorGUILayout.Slider(serializedObject.FindProperty("VColLeafModifier"), 0.1f, 5, new GUIContent("Leaf Multiplier"));
            serializedObject.ApplyModifiedProperties();
            EditorGUILayout.EndVertical();
            if (EditorGUI.EndChangeCheck())
            {
                UpdateTree();
            }
            EditorGUILayout.Space();
            BezierMode();
        }
예제 #13
0
 public override void Init(TreeFunctionAsset parent, bool preserveSettings = false)
 {
     base.Init(parent);
     name = "Split";
 }
 public override void Init(TreeFunctionAsset parent, bool preserveSettings = false)
 {
     base.Init(parent);
     name           = "Leaves";
     customLeafMesh = null;
 }