com.warwlock.mtree 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/workflows/npm.yml +19 -0
- package/CHANGELOG.md +17 -0
- package/CHANGELOG.md.meta +7 -0
- package/Documentation~/Documentation.md +3 -0
- package/Editor/BranchEditor.cs +545 -0
- package/Editor/BranchEditor.cs.meta +16 -0
- package/Editor/EditorCallbacks.cs +69 -0
- package/Editor/EditorCallbacks.cs.meta +11 -0
- package/Editor/MTree.Editor.asmdef +18 -0
- package/Editor/MTree.Editor.asmdef.meta +7 -0
- package/Editor/MenuItem.cs +31 -0
- package/Editor/MenuItem.cs.meta +11 -0
- package/Editor/MtreeBezierInspector.cs +161 -0
- package/Editor/MtreeBezierInspector.cs.meta +11 -0
- package/Editor/MtreeEditor.cs +434 -0
- package/Editor/MtreeEditor.cs.meta +11 -0
- package/Editor/TemplateInspector.cs +66 -0
- package/Editor/TemplateInspector.cs.meta +12 -0
- package/Editor/ValuesEditor.cs +18 -0
- package/Editor/ValuesEditor.cs.meta +11 -0
- package/Editor/VertexColorAdjustmentEditor.cs +169 -0
- package/Editor/VertexColorAdjustmentEditor.cs.meta +11 -0
- package/Editor.meta +8 -0
- package/LICENSE +21 -0
- package/LICENSE.meta +7 -0
- package/README.md +68 -0
- package/README.md.meta +7 -0
- package/Resources/Mtree/MtreeBillboardCamera.prefab +204 -0
- package/Resources/Mtree/MtreeBillboardCamera.prefab.meta +8 -0
- package/Resources/Mtree/Sprites/DeleteCrossSprite.png +0 -0
- package/Resources/Mtree/Sprites/DeleteCrossSprite.png.meta +116 -0
- package/Resources/Mtree/Sprites/TreeFunctionSprite.png +0 -0
- package/Resources/Mtree/Sprites/TreeFunctionSprite.png.meta +116 -0
- package/Resources/Mtree/Sprites/TreeFunctionSpriteSelected.psd +0 -0
- package/Resources/Mtree/Sprites/TreeFunctionSpriteSelected.psd.meta +116 -0
- package/Resources/Mtree/Sprites.meta +8 -0
- package/Resources/Mtree/Vertex Color Editor/Mtree Vertex Color GameObject.prefab +104 -0
- package/Resources/Mtree/Vertex Color Editor/Mtree Vertex Color GameObject.prefab.meta +7 -0
- package/Resources/Mtree/Vertex Color Editor.meta +8 -0
- package/Resources/Mtree/branches.fbx +0 -0
- package/Resources/Mtree/branches.fbx.meta +137 -0
- package/Resources/Mtree.meta +8 -0
- package/Resources.meta +8 -0
- package/Runtime/AO/DensityAO.cs +203 -0
- package/Runtime/AO/DensityAO.cs.meta +11 -0
- package/Runtime/AO/KDTree.cs +169 -0
- package/Runtime/AO/KDTree.cs.meta +11 -0
- package/Runtime/AO/WeightedRandom.cs +74 -0
- package/Runtime/AO/WeightedRandom.cs.meta +11 -0
- package/Runtime/AO.meta +8 -0
- package/Runtime/Bezier/Bezier.cs +69 -0
- package/Runtime/Bezier/Bezier.cs.meta +11 -0
- package/Runtime/Bezier/MtreeBezier.cs +185 -0
- package/Runtime/Bezier/MtreeBezier.cs.meta +11 -0
- package/Runtime/Bezier.meta +8 -0
- package/Runtime/ExampleSceneManager.cs +165 -0
- package/Runtime/ExampleSceneManager.cs.meta +11 -0
- package/Runtime/LODValues.cs +44 -0
- package/Runtime/LODValues.cs.meta +11 -0
- package/Runtime/LeafPoint.cs +135 -0
- package/Runtime/LeafPoint.cs.meta +11 -0
- package/Runtime/MTree.Runtime.asmdef +3 -0
- package/Runtime/MTree.Runtime.asmdef.meta +7 -0
- package/Runtime/MTree.cs +569 -0
- package/Runtime/MTree.cs.meta +11 -0
- package/Runtime/MtreeComponent.cs +482 -0
- package/Runtime/MtreeComponent.cs.meta +11 -0
- package/Runtime/MtreeVariables.cs +11 -0
- package/Runtime/MtreeVariables.cs.meta +11 -0
- package/Runtime/MtreeWind.cs +94 -0
- package/Runtime/MtreeWind.cs.meta +11 -0
- package/Runtime/Node.cs +331 -0
- package/Runtime/Node.cs.meta +11 -0
- package/Runtime/SimplexNoise.cs +166 -0
- package/Runtime/SimplexNoise.cs.meta +11 -0
- package/Runtime/Splines.cs +379 -0
- package/Runtime/Splines.cs.meta +11 -0
- package/Runtime/TreeBilboard.cs +290 -0
- package/Runtime/TreeBilboard.cs.meta +11 -0
- package/Runtime/TreeFunctions/BranchFunction.cs +92 -0
- package/Runtime/TreeFunctions/BranchFunction.cs.meta +11 -0
- package/Runtime/TreeFunctions/GrowFunction.cs +81 -0
- package/Runtime/TreeFunctions/GrowFunction.cs.meta +11 -0
- package/Runtime/TreeFunctions/LeafFunction.cs +111 -0
- package/Runtime/TreeFunctions/LeafFunction.cs.meta +11 -0
- package/Runtime/TreeFunctions/RootsFunction.cs +77 -0
- package/Runtime/TreeFunctions/RootsFunction.cs.meta +11 -0
- package/Runtime/TreeFunctions/SplitFunction.cs +50 -0
- package/Runtime/TreeFunctions/SplitFunction.cs.meta +11 -0
- package/Runtime/TreeFunctions/TreeFunctionAsset.cs +105 -0
- package/Runtime/TreeFunctions/TreeFunctionAsset.cs.meta +11 -0
- package/Runtime/TreeFunctions/TrunkFunction.cs +88 -0
- package/Runtime/TreeFunctions/TrunkFunction.cs.meta +11 -0
- package/Runtime/TreeFunctions.meta +8 -0
- package/Runtime/TreePoint.cs +27 -0
- package/Runtime/TreePoint.cs.meta +11 -0
- package/Runtime/TreeTemplate.cs +50 -0
- package/Runtime/TreeTemplate.cs.meta +12 -0
- package/Runtime/Utils.cs +268 -0
- package/Runtime/Utils.cs.meta +11 -0
- package/Runtime/VSProIntegration.cs +132 -0
- package/Runtime/VSProIntegration.cs.meta +11 -0
- package/Runtime.meta +8 -0
- package/Samples~/ExampleTemplates/Examples/Birch.asset +364 -0
- package/Samples~/ExampleTemplates/Examples/Birch.asset.meta +8 -0
- package/Samples~/ExampleTemplates/Examples/Bush.asset +385 -0
- package/Samples~/ExampleTemplates/Examples/Bush.asset.meta +8 -0
- package/Samples~/ExampleTemplates/Examples/Eastern Pine.asset +482 -0
- package/Samples~/ExampleTemplates/Examples/Eastern Pine.asset.meta +8 -0
- package/Samples~/ExampleTemplates/Examples/FantasyTree.asset +406 -0
- package/Samples~/ExampleTemplates/Examples/FantasyTree.asset.meta +8 -0
- package/Samples~/ExampleTemplates/Examples/Fern.asset +291 -0
- package/Samples~/ExampleTemplates/Examples/Fern.asset.meta +8 -0
- package/Samples~/ExampleTemplates/Examples/High Poly.asset +300 -0
- package/Samples~/ExampleTemplates/Examples/High Poly.asset.meta +8 -0
- package/Samples~/ExampleTemplates/Examples/LightingData.asset +0 -0
- package/Samples~/ExampleTemplates/Examples/LightingData.asset.meta +8 -0
- package/Samples~/ExampleTemplates/Examples/Materials/Bark/Bark Birch Outline.mat +196 -0
- package/Samples~/ExampleTemplates/Examples/Materials/Bark/Bark Birch Outline.mat.meta +8 -0
- package/Samples~/ExampleTemplates/Examples/Materials/Bark/Bark Birch.mat +196 -0
- package/Samples~/ExampleTemplates/Examples/Materials/Bark/Bark Birch.mat.meta +8 -0
- package/Samples~/ExampleTemplates/Examples/Materials/Bark/Bark Fern.mat +181 -0
- package/Samples~/ExampleTemplates/Examples/Materials/Bark/Bark Fern.mat.meta +8 -0
- package/Samples~/ExampleTemplates/Examples/Materials/Bark/Bark HighPoly.mat +201 -0
- package/Samples~/ExampleTemplates/Examples/Materials/Bark/Bark HighPoly.mat.meta +8 -0
- package/Samples~/ExampleTemplates/Examples/Materials/Bark/Bark Oak.mat +208 -0
- package/Samples~/ExampleTemplates/Examples/Materials/Bark/Bark Oak.mat.meta +8 -0
- package/Samples~/ExampleTemplates/Examples/Materials/Bark/Bark Palm.mat +180 -0
- package/Samples~/ExampleTemplates/Examples/Materials/Bark/Bark Palm.mat.meta +8 -0
- package/Samples~/ExampleTemplates/Examples/Materials/Bark/Bark Pine.mat +206 -0
- package/Samples~/ExampleTemplates/Examples/Materials/Bark/Bark Pine.mat.meta +8 -0
- package/Samples~/ExampleTemplates/Examples/Materials/Bark/Bark Ponderossa.mat +206 -0
- package/Samples~/ExampleTemplates/Examples/Materials/Bark/Bark Ponderossa.mat.meta +8 -0
- package/Samples~/ExampleTemplates/Examples/Materials/Bark/Bark Poplar.mat +172 -0
- package/Samples~/ExampleTemplates/Examples/Materials/Bark/Bark Poplar.mat.meta +8 -0
- package/Samples~/ExampleTemplates/Examples/Materials/Bark.meta +8 -0
- package/Samples~/ExampleTemplates/Examples/Materials/Example Scene/Floor.mat +392 -0
- package/Samples~/ExampleTemplates/Examples/Materials/Example Scene/Floor.mat.meta +8 -0
- package/Samples~/ExampleTemplates/Examples/Materials/Example Scene.meta +8 -0
- package/Samples~/ExampleTemplates/Examples/Materials/Leafs/Leafs Fern.mat +202 -0
- package/Samples~/ExampleTemplates/Examples/Materials/Leafs/Leafs Fern.mat.meta +8 -0
- package/Samples~/ExampleTemplates/Examples/Materials/Leafs/Leafs HighPoly.mat +265 -0
- package/Samples~/ExampleTemplates/Examples/Materials/Leafs/Leafs HighPoly.mat.meta +8 -0
- package/Samples~/ExampleTemplates/Examples/Materials/Leafs/Leafs Needles.mat +267 -0
- package/Samples~/ExampleTemplates/Examples/Materials/Leafs/Leafs Needles.mat.meta +8 -0
- package/Samples~/ExampleTemplates/Examples/Materials/Leafs/Leafs Palm.mat +232 -0
- package/Samples~/ExampleTemplates/Examples/Materials/Leafs/Leafs Palm.mat.meta +8 -0
- package/Samples~/ExampleTemplates/Examples/Materials/Leafs/Leafs Palmate.mat +250 -0
- package/Samples~/ExampleTemplates/Examples/Materials/Leafs/Leafs Palmate.mat.meta +8 -0
- package/Samples~/ExampleTemplates/Examples/Materials/Leafs/Leafs Pine.mat +247 -0
- package/Samples~/ExampleTemplates/Examples/Materials/Leafs/Leafs Pine.mat.meta +8 -0
- package/Samples~/ExampleTemplates/Examples/Materials/Leafs/Leafs Poplar.mat +223 -0
- package/Samples~/ExampleTemplates/Examples/Materials/Leafs/Leafs Poplar.mat.meta +8 -0
- package/Samples~/ExampleTemplates/Examples/Materials/Leafs/Leafs Serrate Outline.mat +262 -0
- package/Samples~/ExampleTemplates/Examples/Materials/Leafs/Leafs Serrate Outline.mat.meta +8 -0
- package/Samples~/ExampleTemplates/Examples/Materials/Leafs/Leafs Serrate.mat +281 -0
- package/Samples~/ExampleTemplates/Examples/Materials/Leafs/Leafs Serrate.mat.meta +8 -0
- package/Samples~/ExampleTemplates/Examples/Materials/Leafs/Leafs Stone Pine.mat +267 -0
- package/Samples~/ExampleTemplates/Examples/Materials/Leafs/Leafs Stone Pine.mat.meta +8 -0
- package/Samples~/ExampleTemplates/Examples/Materials/Leafs/Leafs Willow.mat +236 -0
- package/Samples~/ExampleTemplates/Examples/Materials/Leafs/Leafs Willow.mat.meta +8 -0
- package/Samples~/ExampleTemplates/Examples/Materials/Leafs.meta +8 -0
- package/Samples~/ExampleTemplates/Examples/Materials.meta +8 -0
- package/Samples~/ExampleTemplates/Examples/Oak.asset +364 -0
- package/Samples~/ExampleTemplates/Examples/Oak.asset.meta +8 -0
- package/Samples~/ExampleTemplates/Examples/Old Oak.asset +364 -0
- package/Samples~/ExampleTemplates/Examples/Old Oak.asset.meta +8 -0
- package/Samples~/ExampleTemplates/Examples/Palm.asset +500 -0
- package/Samples~/ExampleTemplates/Examples/Palm.asset.meta +8 -0
- package/Samples~/ExampleTemplates/Examples/Pine 2.asset +387 -0
- package/Samples~/ExampleTemplates/Examples/Pine 2.asset.meta +8 -0
- package/Samples~/ExampleTemplates/Examples/Pine.asset +405 -0
- package/Samples~/ExampleTemplates/Examples/Pine.asset.meta +8 -0
- package/Samples~/ExampleTemplates/Examples/Ponderossa Pine.asset +478 -0
- package/Samples~/ExampleTemplates/Examples/Ponderossa Pine.asset.meta +8 -0
- package/Samples~/ExampleTemplates/Examples/Poplar.asset +309 -0
- package/Samples~/ExampleTemplates/Examples/Poplar.asset.meta +8 -0
- package/Samples~/ExampleTemplates/Examples/ReflectionProbe-0.exr +0 -0
- package/Samples~/ExampleTemplates/Examples/ReflectionProbe-0.exr.meta +117 -0
- package/Samples~/ExampleTemplates/Examples/Small Pine.asset +273 -0
- package/Samples~/ExampleTemplates/Examples/Small Pine.asset.meta +8 -0
- package/Samples~/ExampleTemplates/Examples/Small Tree.asset +364 -0
- package/Samples~/ExampleTemplates/Examples/Small Tree.asset.meta +8 -0
- package/Samples~/ExampleTemplates/Examples/Textures/Bark/Bark_Birch_C.png +0 -0
- package/Samples~/ExampleTemplates/Examples/Textures/Bark/Bark_Birch_C.png.meta +74 -0
- package/Samples~/ExampleTemplates/Examples/Textures/Bark/Bark_Birch_N.png +0 -0
- package/Samples~/ExampleTemplates/Examples/Textures/Bark/Bark_Birch_N.png.meta +96 -0
- package/Samples~/ExampleTemplates/Examples/Textures/Bark/Bark_Damaged_C.png +0 -0
- package/Samples~/ExampleTemplates/Examples/Textures/Bark/Bark_Damaged_C.png.meta +116 -0
- package/Samples~/ExampleTemplates/Examples/Textures/Bark/Bark_Damaged_N.png +0 -0
- package/Samples~/ExampleTemplates/Examples/Textures/Bark/Bark_Damaged_N.png.meta +116 -0
- package/Samples~/ExampleTemplates/Examples/Textures/Bark/Bark_Decidious_1_C.png +0 -0
- package/Samples~/ExampleTemplates/Examples/Textures/Bark/Bark_Decidious_1_C.png.meta +132 -0
- package/Samples~/ExampleTemplates/Examples/Textures/Bark/Bark_Decidious_1_N.png +0 -0
- package/Samples~/ExampleTemplates/Examples/Textures/Bark/Bark_Decidious_1_N.png.meta +116 -0
- package/Samples~/ExampleTemplates/Examples/Textures/Bark/Bark_Decidious_2_C.png +0 -0
- package/Samples~/ExampleTemplates/Examples/Textures/Bark/Bark_Decidious_2_C.png.meta +132 -0
- package/Samples~/ExampleTemplates/Examples/Textures/Bark/Bark_Decidious_3_C.png +0 -0
- package/Samples~/ExampleTemplates/Examples/Textures/Bark/Bark_Decidious_3_C.png.meta +132 -0
- package/Samples~/ExampleTemplates/Examples/Textures/Bark/Bark_Decidious_3_N.png +0 -0
- package/Samples~/ExampleTemplates/Examples/Textures/Bark/Bark_Decidious_3_N.png.meta +116 -0
- package/Samples~/ExampleTemplates/Examples/Textures/Bark/Bark_Decidious_4_C.png +0 -0
- package/Samples~/ExampleTemplates/Examples/Textures/Bark/Bark_Decidious_4_C.png.meta +132 -0
- package/Samples~/ExampleTemplates/Examples/Textures/Bark/Bark_Decidious_4_N.png +0 -0
- package/Samples~/ExampleTemplates/Examples/Textures/Bark/Bark_Decidious_4_N.png.meta +116 -0
- package/Samples~/ExampleTemplates/Examples/Textures/Bark/Bark_Oak_C.png +0 -0
- package/Samples~/ExampleTemplates/Examples/Textures/Bark/Bark_Oak_C.png.meta +74 -0
- package/Samples~/ExampleTemplates/Examples/Textures/Bark/Bark_Oak_N.png +0 -0
- package/Samples~/ExampleTemplates/Examples/Textures/Bark/Bark_Oak_N.png.meta +96 -0
- package/Samples~/ExampleTemplates/Examples/Textures/Bark/Bark_Palm_C.png +0 -0
- package/Samples~/ExampleTemplates/Examples/Textures/Bark/Bark_Palm_C.png.meta +74 -0
- package/Samples~/ExampleTemplates/Examples/Textures/Bark/Bark_Palm_N.bmp +0 -0
- package/Samples~/ExampleTemplates/Examples/Textures/Bark/Bark_Palm_N.bmp.meta +96 -0
- package/Samples~/ExampleTemplates/Examples/Textures/Bark/Bark_Pine_C.png +0 -0
- package/Samples~/ExampleTemplates/Examples/Textures/Bark/Bark_Pine_C.png.meta +74 -0
- package/Samples~/ExampleTemplates/Examples/Textures/Bark/Bark_Pine_N.png +0 -0
- package/Samples~/ExampleTemplates/Examples/Textures/Bark/Bark_Pine_N.png.meta +96 -0
- package/Samples~/ExampleTemplates/Examples/Textures/Bark.meta +8 -0
- package/Samples~/ExampleTemplates/Examples/Textures/Branch/Branch Serrate_C.png +0 -0
- package/Samples~/ExampleTemplates/Examples/Textures/Branch/Branch Serrate_C.png.meta +96 -0
- package/Samples~/ExampleTemplates/Examples/Textures/Branch/Branch Serrate_N.png +0 -0
- package/Samples~/ExampleTemplates/Examples/Textures/Branch/Branch Serrate_N.png.meta +96 -0
- package/Samples~/ExampleTemplates/Examples/Textures/Branch/Branch_Needles_C.png +0 -0
- package/Samples~/ExampleTemplates/Examples/Textures/Branch/Branch_Needles_C.png.meta +99 -0
- package/Samples~/ExampleTemplates/Examples/Textures/Branch/Branch_Needles_N.png +0 -0
- package/Samples~/ExampleTemplates/Examples/Textures/Branch/Branch_Needles_N.png.meta +96 -0
- package/Samples~/ExampleTemplates/Examples/Textures/Branch/Branch_Palmate_C.png +0 -0
- package/Samples~/ExampleTemplates/Examples/Textures/Branch/Branch_Palmate_C.png.meta +99 -0
- package/Samples~/ExampleTemplates/Examples/Textures/Branch/Branch_Palmate_N.png +0 -0
- package/Samples~/ExampleTemplates/Examples/Textures/Branch/Branch_Palmate_N.png.meta +96 -0
- package/Samples~/ExampleTemplates/Examples/Textures/Branch/Branch_Pine_1_C.png +0 -0
- package/Samples~/ExampleTemplates/Examples/Textures/Branch/Branch_Pine_1_C.png.meta +88 -0
- package/Samples~/ExampleTemplates/Examples/Textures/Branch/Branch_Pine_1_N.png +0 -0
- package/Samples~/ExampleTemplates/Examples/Textures/Branch/Branch_Pine_1_N.png.meta +96 -0
- package/Samples~/ExampleTemplates/Examples/Textures/Branch/Branch_Pine_2_C.png +0 -0
- package/Samples~/ExampleTemplates/Examples/Textures/Branch/Branch_Pine_2_C.png.meta +96 -0
- package/Samples~/ExampleTemplates/Examples/Textures/Branch/Branch_Pine_2_N.png +0 -0
- package/Samples~/ExampleTemplates/Examples/Textures/Branch/Branch_Pine_2_N.png.meta +96 -0
- package/Samples~/ExampleTemplates/Examples/Textures/Branch/Branch_Poplar_C.png +0 -0
- package/Samples~/ExampleTemplates/Examples/Textures/Branch/Branch_Poplar_C.png.meta +96 -0
- package/Samples~/ExampleTemplates/Examples/Textures/Branch/Branch_Poplar_N.png +0 -0
- package/Samples~/ExampleTemplates/Examples/Textures/Branch/Branch_Poplar_N.png.meta +96 -0
- package/Samples~/ExampleTemplates/Examples/Textures/Branch.meta +8 -0
- package/Samples~/ExampleTemplates/Examples/Textures/Color Ramp/Ramp_PSD.psd +0 -0
- package/Samples~/ExampleTemplates/Examples/Textures/Color Ramp/Ramp_PSD.psd.meta +76 -0
- package/Samples~/ExampleTemplates/Examples/Textures/Color Ramp/Ramp_Toon.png +0 -0
- package/Samples~/ExampleTemplates/Examples/Textures/Color Ramp/Ramp_Toon.png.meta +76 -0
- package/Samples~/ExampleTemplates/Examples/Textures/Color Ramp.meta +8 -0
- package/Samples~/ExampleTemplates/Examples/Textures/Single Leafs/Leaf_Fern_C.png +0 -0
- package/Samples~/ExampleTemplates/Examples/Textures/Single Leafs/Leaf_Fern_C.png.meta +99 -0
- package/Samples~/ExampleTemplates/Examples/Textures/Single Leafs/Leaf_Fern_N.png +0 -0
- package/Samples~/ExampleTemplates/Examples/Textures/Single Leafs/Leaf_Fern_N.png.meta +88 -0
- package/Samples~/ExampleTemplates/Examples/Textures/Single Leafs/Leaf_Palm_C.png +0 -0
- package/Samples~/ExampleTemplates/Examples/Textures/Single Leafs/Leaf_Palm_C.png.meta +88 -0
- package/Samples~/ExampleTemplates/Examples/Textures/Single Leafs/Leaf_Palm_N.png +0 -0
- package/Samples~/ExampleTemplates/Examples/Textures/Single Leafs/Leaf_Palm_N.png.meta +88 -0
- package/Samples~/ExampleTemplates/Examples/Textures/Single Leafs/Leaf_Willow_C.png +0 -0
- package/Samples~/ExampleTemplates/Examples/Textures/Single Leafs/Leaf_Willow_C.png.meta +99 -0
- package/Samples~/ExampleTemplates/Examples/Textures/Single Leafs/Leaf_Willow_N.png +0 -0
- package/Samples~/ExampleTemplates/Examples/Textures/Single Leafs/Leaf_Willow_N.png.meta +88 -0
- package/Samples~/ExampleTemplates/Examples/Textures/Single Leafs/Single_Serrated_C.png +0 -0
- package/Samples~/ExampleTemplates/Examples/Textures/Single Leafs/Single_Serrated_C.png.meta +96 -0
- package/Samples~/ExampleTemplates/Examples/Textures/Single Leafs/Single_Serrated_N.png +0 -0
- package/Samples~/ExampleTemplates/Examples/Textures/Single Leafs/Single_Serrated_N.png.meta +96 -0
- package/Samples~/ExampleTemplates/Examples/Textures/Single Leafs.meta +8 -0
- package/Samples~/ExampleTemplates/Examples/Textures.meta +8 -0
- package/Samples~/ExampleTemplates/Examples/Willow.asset +364 -0
- package/Samples~/ExampleTemplates/Examples/Willow.asset.meta +8 -0
- package/Samples~/ExampleTemplates/Examples.meta +8 -0
- package/Samples~/ExampleTemplates/Examples.unity +12660 -0
- package/Samples~/ExampleTemplates/Examples.unity.meta +7 -0
- package/Samples~/ExampleTemplates.meta +8 -0
- package/Shaders/BarkShader.shadergraph +17215 -0
- package/Shaders/BarkShader.shadergraph.meta +10 -0
- package/Shaders/Editor/BarkEditor.cs +100 -0
- package/Shaders/Editor/BarkEditor.cs.meta +11 -0
- package/Shaders/Editor/LeafEditor.cs +173 -0
- package/Shaders/Editor/LeafEditor.cs.meta +11 -0
- package/Shaders/Editor.meta +8 -0
- package/Shaders/LeafShader.shadergraph +34803 -0
- package/Shaders/LeafShader.shadergraph.meta +10 -0
- package/Shaders/MTree.Shaders.asmdef +3 -0
- package/Shaders/MTree.Shaders.asmdef.meta +7 -0
- package/Shaders/leafFunctions.hlsl +201 -0
- package/Shaders/leafFunctions.hlsl.meta +7 -0
- package/Shaders/vertexFunc.hlsl +55 -0
- package/Shaders/vertexFunc.hlsl.meta +7 -0
- package/Shaders.meta +8 -0
- package/package.json +36 -0
- package/package.json.meta +7 -0
|
@@ -0,0 +1,482 @@
|
|
|
1
|
+
using System.Collections;
|
|
2
|
+
using System.Collections.Generic;
|
|
3
|
+
using UnityEngine;
|
|
4
|
+
using Mtree;
|
|
5
|
+
#if UNITY_EDITOR
|
|
6
|
+
using UnityEditor;
|
|
7
|
+
#endif
|
|
8
|
+
using System.IO;
|
|
9
|
+
#if UNITY_2018_3 || UNITY_2018_4
|
|
10
|
+
using UnityEngine.Experimental.Rendering;
|
|
11
|
+
using UnityEngine.Rendering;
|
|
12
|
+
#elif UNITY_2019_1_OR_NEWER
|
|
13
|
+
using UnityEngine.Rendering;
|
|
14
|
+
#endif
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
[RequireComponent(typeof(MeshFilter), typeof(MeshRenderer))]
|
|
18
|
+
public class MtreeComponent : MonoBehaviour
|
|
19
|
+
{
|
|
20
|
+
#if UNITY_EDITOR
|
|
21
|
+
public List<TreeFunctionAsset> treeFunctionsAssets;
|
|
22
|
+
public List<LODValues> LODs;
|
|
23
|
+
|
|
24
|
+
public int selectedFunctionIndex = 0; // Index of selected Function in editor
|
|
25
|
+
public int tabIndex = 0; // Index of selected tab in editor
|
|
26
|
+
public MTree tree;
|
|
27
|
+
public int LodIndex = 0;
|
|
28
|
+
public string saveTreeFolder = "Assets";
|
|
29
|
+
public int polycount = 0;
|
|
30
|
+
private Material leafMaterial;
|
|
31
|
+
private MeshFilter filter;
|
|
32
|
+
private ThreadHandleEditor aoBakingHandle;
|
|
33
|
+
public TreeTemplate template;
|
|
34
|
+
public int[] MtreeVersion;
|
|
35
|
+
public TreeFunctionAsset savedFunction;
|
|
36
|
+
public float VColBarkModifier = 1;
|
|
37
|
+
public float VColLeafModifier = 1;
|
|
38
|
+
public float BB_Brightness = 1;
|
|
39
|
+
public float BB_TopCardPositon = 0.5f;
|
|
40
|
+
public int BB_hasTopCard = 1;
|
|
41
|
+
public int BB_isSingleSided = 1;
|
|
42
|
+
|
|
43
|
+
public MtreeBezier mtreeBezier;
|
|
44
|
+
public int hasBezier = 0;
|
|
45
|
+
#if UNITY_2018_3_OR_NEWER
|
|
46
|
+
public bool isHDRP = false;
|
|
47
|
+
public RenderPipelineAsset hdrpAsset;
|
|
48
|
+
#endif
|
|
49
|
+
void InitializeTree()
|
|
50
|
+
{
|
|
51
|
+
MtreeVersion = MtreeVariables.MtreeVersion;
|
|
52
|
+
filter = GetComponent<MeshFilter>();
|
|
53
|
+
tree = new MTree(transform);
|
|
54
|
+
|
|
55
|
+
if(LODs == null || LODs.Count == 0)
|
|
56
|
+
for (int i = 0; i < 4; i++)
|
|
57
|
+
{
|
|
58
|
+
AddLODLevel(false);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
public void AddLODLevel(bool registerUndo = true)
|
|
63
|
+
{
|
|
64
|
+
LODValues previousLOD = null;
|
|
65
|
+
if (LODs == null || LODs.Count == 0)
|
|
66
|
+
LODs = new List<LODValues>();
|
|
67
|
+
else
|
|
68
|
+
previousLOD = LODs[LODs.Count - 1];
|
|
69
|
+
|
|
70
|
+
LODValues lod = ScriptableObject.CreateInstance<LODValues>();
|
|
71
|
+
lod.Init(previousLOD);
|
|
72
|
+
|
|
73
|
+
if (registerUndo)
|
|
74
|
+
{
|
|
75
|
+
Undo.RecordObject(this, "Added LOD level");
|
|
76
|
+
Undo.RegisterCreatedObjectUndo(lod, "Added LOD level");
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
LODs.Add(lod);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
public void UndoCallBack()
|
|
83
|
+
{
|
|
84
|
+
if (this != null)
|
|
85
|
+
GenerateTree();
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
public void AddTreeFunction<T>() where T : TreeFunctionAsset
|
|
89
|
+
{
|
|
90
|
+
T function = ScriptableObject.CreateInstance<T>();
|
|
91
|
+
AddTreeFunction(function);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
private void AddTreeFunction(TreeFunctionAsset function)
|
|
95
|
+
{
|
|
96
|
+
Undo.RecordObjects(treeFunctionsAssets.ToArray(), "Added function");
|
|
97
|
+
Undo.RecordObject(this, "Added function");
|
|
98
|
+
Undo.RegisterCreatedObjectUndo(function, "Added function");
|
|
99
|
+
|
|
100
|
+
TreeFunctionAsset parent = treeFunctionsAssets.Count == 0 ? null : treeFunctionsAssets[selectedFunctionIndex];
|
|
101
|
+
function.Init(parent);
|
|
102
|
+
selectedFunctionIndex = treeFunctionsAssets.Count;
|
|
103
|
+
treeFunctionsAssets.Add(function);
|
|
104
|
+
GenerateTree();
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
public void RandomizeTree()
|
|
108
|
+
{
|
|
109
|
+
Undo.RecordObjects(treeFunctionsAssets.ToArray(), "Randomized tree");
|
|
110
|
+
|
|
111
|
+
foreach (TreeFunctionAsset tf in treeFunctionsAssets)
|
|
112
|
+
{
|
|
113
|
+
tf.seed = Random.Range(0, 1000);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
public void UpdateTreeFunctions()
|
|
118
|
+
{
|
|
119
|
+
if (treeFunctionsAssets == null ||treeFunctionsAssets.Count == 0)
|
|
120
|
+
{
|
|
121
|
+
treeFunctionsAssets = new List<TreeFunctionAsset>();
|
|
122
|
+
AddTreeFunction<TrunkFunction>();
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
public void RemoveFunction(TreeFunctionAsset function)
|
|
127
|
+
{
|
|
128
|
+
Undo.RecordObjects(treeFunctionsAssets.ToArray(), "Removed function");
|
|
129
|
+
Undo.RecordObject(this, "Removed function");
|
|
130
|
+
|
|
131
|
+
treeFunctionsAssets.Remove(function);
|
|
132
|
+
function.parent.chiildren.Remove(function);
|
|
133
|
+
foreach (TreeFunctionAsset child in function.chiildren)
|
|
134
|
+
{
|
|
135
|
+
child.parent = function.parent;
|
|
136
|
+
child.parent.chiildren.Add(child);
|
|
137
|
+
}
|
|
138
|
+
selectedFunctionIndex = function.parent == null ? 0 : treeFunctionsAssets.IndexOf(function.parent);
|
|
139
|
+
|
|
140
|
+
Undo.DestroyObjectImmediate(function);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
private void ExecuteFunctions()
|
|
144
|
+
{
|
|
145
|
+
if (tree == null || LODs == null || LODs.Count == 0 || treeFunctionsAssets == null || treeFunctionsAssets.Count == 0)
|
|
146
|
+
InitializeTree();
|
|
147
|
+
|
|
148
|
+
if (treeFunctionsAssets == null || treeFunctionsAssets.Count == 0)
|
|
149
|
+
UpdateTreeFunctions();
|
|
150
|
+
|
|
151
|
+
foreach (TreeFunctionAsset function in treeFunctionsAssets)
|
|
152
|
+
{
|
|
153
|
+
function.Execute(tree);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
Mesh CreateMesh()
|
|
158
|
+
{
|
|
159
|
+
Mesh mesh = new Mesh();
|
|
160
|
+
|
|
161
|
+
|
|
162
|
+
if (treeFunctionsAssets.Count > 0)
|
|
163
|
+
tree.GenerateMeshData(treeFunctionsAssets[0] as TrunkFunction, LODs[LodIndex].simplifyLeafs, LODs[LodIndex].radialResolution,VColBarkModifier,VColLeafModifier);
|
|
164
|
+
|
|
165
|
+
mesh.vertices = tree.verts;
|
|
166
|
+
mesh.normals = tree.normals;
|
|
167
|
+
mesh.uv = tree.uvs;
|
|
168
|
+
Color[] colors = tree.colors;
|
|
169
|
+
if (tree.triangles.Length >= System.UInt16.MaxValue)
|
|
170
|
+
{
|
|
171
|
+
mesh.indexFormat = IndexFormat.UInt32;
|
|
172
|
+
}
|
|
173
|
+
else
|
|
174
|
+
{
|
|
175
|
+
mesh.indexFormat = IndexFormat.UInt16;
|
|
176
|
+
}
|
|
177
|
+
mesh.triangles = tree.triangles;
|
|
178
|
+
if (tree.leafTriangles.Length > 0)
|
|
179
|
+
{
|
|
180
|
+
mesh.subMeshCount = 2;
|
|
181
|
+
mesh.SetTriangles(tree.leafTriangles, 1);
|
|
182
|
+
}
|
|
183
|
+
mesh.colors = colors;
|
|
184
|
+
polycount = mesh.triangles.Length / 3;
|
|
185
|
+
return mesh;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
public void FromTemplate()
|
|
189
|
+
{
|
|
190
|
+
if (template == null)
|
|
191
|
+
return;
|
|
192
|
+
|
|
193
|
+
treeFunctionsAssets.Clear();
|
|
194
|
+
|
|
195
|
+
for (int i = 0; i < template.treeFunctions.Count; i++)
|
|
196
|
+
{
|
|
197
|
+
TreeFunctionAsset function = Instantiate(template.treeFunctions[i]);
|
|
198
|
+
treeFunctionsAssets.Add(function);
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
for (int i = 0; i < template.treeFunctions.Count; i++)
|
|
202
|
+
{
|
|
203
|
+
int parentIndex = template.treeFunctions.IndexOf(template.treeFunctions[i].parent);
|
|
204
|
+
TreeFunctionAsset parent = parentIndex == -1 ? null : treeFunctionsAssets[parentIndex];
|
|
205
|
+
treeFunctionsAssets[i].Init(parent, true);
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
public void BakeAo(bool async = false)
|
|
210
|
+
{
|
|
211
|
+
if (filter == null ||filter.sharedMesh == null)
|
|
212
|
+
{
|
|
213
|
+
GenerateTree();
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
if (aoBakingHandle != null)
|
|
217
|
+
aoBakingHandle.Abort();
|
|
218
|
+
|
|
219
|
+
if (async)
|
|
220
|
+
aoBakingHandle = DensityAO.BakeAoAsync(filter, gameObject, 2f, 3f);
|
|
221
|
+
else
|
|
222
|
+
DensityAO.BakeAo(filter, gameObject, 2f, 3f);
|
|
223
|
+
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
public Mesh GenerateTree(bool instantAo = false)
|
|
227
|
+
{
|
|
228
|
+
|
|
229
|
+
tree = null;
|
|
230
|
+
ExecuteFunctions();
|
|
231
|
+
tree.Simplify(LODs[LodIndex].simplifyAngleThreshold, LODs[LodIndex].simplifyRadiusThreshold);
|
|
232
|
+
Mesh mesh = CreateMesh();
|
|
233
|
+
filter.mesh = mesh;
|
|
234
|
+
|
|
235
|
+
BakeAo(!instantAo);
|
|
236
|
+
UpdateMaterials();
|
|
237
|
+
return mesh;
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
public void UpdateMaterials()
|
|
241
|
+
{
|
|
242
|
+
MeshRenderer renderer = GetComponent<MeshRenderer>();
|
|
243
|
+
if (tree.leafTriangles.Length == 0)
|
|
244
|
+
{
|
|
245
|
+
switch (renderer.sharedMaterials.Length)
|
|
246
|
+
{
|
|
247
|
+
case 1:
|
|
248
|
+
if (renderer.sharedMaterial == null)
|
|
249
|
+
{
|
|
250
|
+
Material mat = new Material(Utils.GetBarkShader());
|
|
251
|
+
renderer.sharedMaterial = mat;
|
|
252
|
+
}
|
|
253
|
+
break;
|
|
254
|
+
|
|
255
|
+
case 2:
|
|
256
|
+
leafMaterial = renderer.sharedMaterials[1];
|
|
257
|
+
renderer.sharedMaterials = new Material[] { renderer.sharedMaterials[0] };
|
|
258
|
+
break;
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
else
|
|
262
|
+
{
|
|
263
|
+
switch (renderer.sharedMaterials.Length)
|
|
264
|
+
{
|
|
265
|
+
case 0:
|
|
266
|
+
Material barkMat = new Material(Utils.GetBarkShader());
|
|
267
|
+
renderer.sharedMaterial = barkMat;
|
|
268
|
+
|
|
269
|
+
break;
|
|
270
|
+
|
|
271
|
+
case 1:
|
|
272
|
+
if (leafMaterial == null)
|
|
273
|
+
leafMaterial = new Material(Utils.GetLeafShader());
|
|
274
|
+
renderer.sharedMaterials = new Material[] { renderer.sharedMaterials[0], leafMaterial };
|
|
275
|
+
break;
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
private void Start()
|
|
281
|
+
{
|
|
282
|
+
Debug.LogWarning("A tree with Mtree component still attached is used, use trees exported as prefabs in order to optimize your scene. To export a tree, select it, go to the 'save as Prefab' tab and click on 'Save as prefab'");
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
|
|
286
|
+
public GameObject CreateBillboard(string path, string name, bool usingHDRP)
|
|
287
|
+
{
|
|
288
|
+
ResetGlobalWind();
|
|
289
|
+
GameObject camObject = Instantiate(Resources.Load("Mtree/MtreeBillboardCamera") as GameObject); // create billboard and render it
|
|
290
|
+
Camera cam = camObject.GetComponent<Camera>();
|
|
291
|
+
camObject.GetComponentInChildren<Light>().intensity = BB_Brightness;
|
|
292
|
+
Billboard bill = new Billboard(cam, gameObject, 512, 512, BB_TopCardPositon, BB_hasTopCard == 1, BB_isSingleSided == 1);
|
|
293
|
+
bill.SetupCamera();
|
|
294
|
+
string texturePath = path + name + "_billboard.png";
|
|
295
|
+
bill.Render(texturePath);
|
|
296
|
+
DestroyImmediate(camObject);
|
|
297
|
+
|
|
298
|
+
Mesh billboardMesh = bill.CreateMesh(); // create billboard mesh
|
|
299
|
+
AssetDatabase.CreateAsset(billboardMesh, path + name + "_LOD4.mesh");
|
|
300
|
+
|
|
301
|
+
GameObject billboard = new GameObject(name + "_LOD4"); // create billboard object and assign mesh
|
|
302
|
+
MeshFilter meshFilter = billboard.AddComponent<MeshFilter>();
|
|
303
|
+
meshFilter.mesh = billboardMesh;
|
|
304
|
+
MeshRenderer meshRenderer = billboard.AddComponent<MeshRenderer>();
|
|
305
|
+
|
|
306
|
+
Texture billboardTexture = (Texture2D)AssetDatabase.LoadAssetAtPath(texturePath, typeof(Texture2D)); // create material
|
|
307
|
+
Material mat = bill.CreateMaterial(billboardTexture,usingHDRP);
|
|
308
|
+
meshRenderer.sharedMaterial = mat;
|
|
309
|
+
AssetDatabase.CreateAsset(mat, path + name + "billboard.mat");
|
|
310
|
+
return billboard;
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
public Material[] SaveMaterials(string folderPath)
|
|
314
|
+
{
|
|
315
|
+
MeshRenderer renderer = GetComponent<MeshRenderer>();
|
|
316
|
+
Material[] materialsCopy = new Material[renderer.sharedMaterials.Length];
|
|
317
|
+
int matIndex = 0;
|
|
318
|
+
foreach (Material mat in renderer.sharedMaterials)
|
|
319
|
+
{
|
|
320
|
+
if (AssetDatabase.GetAssetPath(mat).Length == 0)
|
|
321
|
+
{
|
|
322
|
+
string matName = Path.GetFileName(mat.name);
|
|
323
|
+
string matPath = Path.Combine(folderPath, matName + ".mat");
|
|
324
|
+
Material matCopy = new Material(mat);
|
|
325
|
+
materialsCopy[matIndex] = matCopy;
|
|
326
|
+
AssetDatabase.CreateAsset(matCopy, matPath);
|
|
327
|
+
}
|
|
328
|
+
else
|
|
329
|
+
{
|
|
330
|
+
materialsCopy[matIndex] = mat;
|
|
331
|
+
}
|
|
332
|
+
matIndex++;
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
return materialsCopy;
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
|
|
339
|
+
Light[] lights = new Light[0];
|
|
340
|
+
public void ResetGlobalWind()
|
|
341
|
+
{
|
|
342
|
+
Shader.SetGlobalFloat("_WindStrength", 0);
|
|
343
|
+
Shader.SetGlobalFloat("_WindDirection", 0);
|
|
344
|
+
Shader.SetGlobalFloat("_WindPulse", 0);
|
|
345
|
+
Shader.SetGlobalFloat("_WindTurbulence", 0);
|
|
346
|
+
}
|
|
347
|
+
public void SaveAsPrefab(bool groupedSave = false,bool isHDRP = false)
|
|
348
|
+
{
|
|
349
|
+
var oldMesh = filter.sharedMesh;
|
|
350
|
+
string name = gameObject.name;
|
|
351
|
+
string path = saveTreeFolder;
|
|
352
|
+
if (string.IsNullOrEmpty(path))
|
|
353
|
+
return;
|
|
354
|
+
|
|
355
|
+
#if (UNITY_2017 || UNITY_2018_1 || UNITY_2018_2)
|
|
356
|
+
bool replacePrefab = false; //=> value never Used, taged by dan_wipf => used for unity up to 2018.2
|
|
357
|
+
#endif
|
|
358
|
+
|
|
359
|
+
if (!System.IO.Directory.Exists(path))
|
|
360
|
+
{
|
|
361
|
+
EditorUtility.DisplayDialog("Invalid Path", "The path is not valid, you can chose it with the find folder button", "Ok");
|
|
362
|
+
return;
|
|
363
|
+
}
|
|
364
|
+
if (AssetDatabase.LoadAssetAtPath(path + "/" + name + ".prefab", typeof(GameObject))) // Overriding prefab dialog
|
|
365
|
+
{
|
|
366
|
+
if (EditorUtility.DisplayDialog("Are you sure?", "The prefab already exists. Do you want to overwrite it?", "Yes", "No"))
|
|
367
|
+
{
|
|
368
|
+
FileUtil.DeleteFileOrDirectory(Path.Combine(path, name + "_meshes"));
|
|
369
|
+
#if (UNITY_2017 || UNITY_2018_1 || UNITY_2018_2)
|
|
370
|
+
replacePrefab = true; // => value never Used, taged by dan_wipf => used for unity up to 2018.2
|
|
371
|
+
#endif
|
|
372
|
+
}
|
|
373
|
+
else
|
|
374
|
+
{
|
|
375
|
+
name += "_1";
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
lights = FindObjectsOfType<Light>();
|
|
379
|
+
foreach (var dl in lights)
|
|
380
|
+
{
|
|
381
|
+
dl.enabled = false;
|
|
382
|
+
}
|
|
383
|
+
Mesh[] meshes = new Mesh[LODs.Count];
|
|
384
|
+
string meshesFolder = AssetDatabase.CreateFolder(path, name + "_meshes");
|
|
385
|
+
meshesFolder = AssetDatabase.GUIDToAssetPath(meshesFolder) + Path.DirectorySeparatorChar;
|
|
386
|
+
Material[] materials = SaveMaterials(meshesFolder);
|
|
387
|
+
GameObject TreeObject = new GameObject(name); // Tree game object
|
|
388
|
+
LODGroup group = TreeObject.AddComponent<LODGroup>(); // LOD Group
|
|
389
|
+
group.fadeMode = LODFadeMode.CrossFade;
|
|
390
|
+
LOD[] lods = new LOD[LODs.Count + 1];
|
|
391
|
+
|
|
392
|
+
// Generating Billboard
|
|
393
|
+
LodIndex = LODs.Count - 1;
|
|
394
|
+
GenerateTree(true);
|
|
395
|
+
GameObject billboard = CreateBillboard(meshesFolder, name, isHDRP);
|
|
396
|
+
Renderer[] bill_re = new Renderer[1] { billboard.GetComponent<MeshRenderer>() };
|
|
397
|
+
lods[lods.Length - 1] = new LOD(.01f, bill_re);
|
|
398
|
+
|
|
399
|
+
|
|
400
|
+
for (LodIndex = LODs.Count - 1; LodIndex >= 0; LodIndex--) // create and save all LOD meshes
|
|
401
|
+
{
|
|
402
|
+
string meshPath = meshesFolder + name + "_LOD" + LodIndex + ".mesh"; //updating path for each LOD
|
|
403
|
+
Mesh mesh = GenerateTree(instantAo:true);
|
|
404
|
+
meshes[LodIndex] = mesh;
|
|
405
|
+
AssetDatabase.CreateAsset(mesh, meshPath);
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
for (int i = 0; i < LODs.Count; i++) // assigning lod meshes to LOD array
|
|
409
|
+
{
|
|
410
|
+
GameObject go = new GameObject(name + "_LOD" + i.ToString());
|
|
411
|
+
go.transform.parent = TreeObject.transform;
|
|
412
|
+
MeshFilter mf = go.AddComponent<MeshFilter>();
|
|
413
|
+
mf.mesh = meshes[i];
|
|
414
|
+
Renderer[] re = new Renderer[1] { go.AddComponent<MeshRenderer>() }; // the renderer to put in LODs
|
|
415
|
+
re[0].sharedMaterials = materials;
|
|
416
|
+
float t = Mathf.Pow((i + 1) * 1f / (LODs.Count + 1), 1); // float between 0 and 1 following f(x) = pow(x, n)
|
|
417
|
+
lods[i] = new LOD((1 - t) * 0.9f + t * .01f, re); // assigning renderer
|
|
418
|
+
lods[i].fadeTransitionWidth = 0.25f;
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
billboard.transform.parent = TreeObject.transform; // making billboard child of tree object
|
|
422
|
+
|
|
423
|
+
|
|
424
|
+
group.SetLODs(lods); // assigning LODs to lod group
|
|
425
|
+
group.animateCrossFading = true;
|
|
426
|
+
group.RecalculateBounds();
|
|
427
|
+
|
|
428
|
+
string prefabPath = path + "/" + name + ".prefab";
|
|
429
|
+
|
|
430
|
+
Object prefab;
|
|
431
|
+
|
|
432
|
+
#if (UNITY_2017 || UNITY_2018_1 || UNITY_2018_2)
|
|
433
|
+
if (replacePrefab)
|
|
434
|
+
{
|
|
435
|
+
Object targetPrefab = AssetDatabase.LoadAssetAtPath(path + "/" + name + ".prefab", typeof(GameObject));
|
|
436
|
+
prefab = PrefabUtility.ReplacePrefab(TreeObject, targetPrefab, ReplacePrefabOptions.ConnectToPrefab);
|
|
437
|
+
}
|
|
438
|
+
else
|
|
439
|
+
prefab = PrefabUtility.CreatePrefab(prefabPath, TreeObject, ReplacePrefabOptions.ConnectToPrefab);
|
|
440
|
+
#else
|
|
441
|
+
prefab = PrefabUtility.SaveAsPrefabAssetAndConnect(TreeObject, prefabPath, InteractionMode.AutomatedAction);
|
|
442
|
+
#endif
|
|
443
|
+
|
|
444
|
+
AssetDatabase.SaveAssets();
|
|
445
|
+
DestroyImmediate(TreeObject);
|
|
446
|
+
if (!groupedSave)
|
|
447
|
+
{
|
|
448
|
+
// select newly created prefab in folder
|
|
449
|
+
Selection.activeObject = prefab;
|
|
450
|
+
// Also flash the folder yellow to highlight it
|
|
451
|
+
EditorGUIUtility.PingObject(prefab);
|
|
452
|
+
EditorUtility.DisplayDialog("Prefab saved !", "The prefab is saved, you can now delete the tree and use the prefab instead", "Ok");
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
LodIndex = 0;
|
|
456
|
+
filter.sharedMesh = oldMesh;
|
|
457
|
+
foreach (var dl in lights)
|
|
458
|
+
{
|
|
459
|
+
dl.enabled = true;
|
|
460
|
+
}
|
|
461
|
+
}
|
|
462
|
+
public void BezierManager(){
|
|
463
|
+
if (hasBezier == 1) {
|
|
464
|
+
mtreeBezier = gameObject.AddComponent<MtreeBezier> ();
|
|
465
|
+
mtreeBezier.MTreeDoBezier = true;
|
|
466
|
+
GenerateTree ();
|
|
467
|
+
}
|
|
468
|
+
if (mtreeBezier == null)
|
|
469
|
+
mtreeBezier = GetComponent<MtreeBezier> ();
|
|
470
|
+
|
|
471
|
+
if (hasBezier == 0 && mtreeBezier != null) {
|
|
472
|
+
mtreeBezier.MTreeDoBezier = false;
|
|
473
|
+
mtreeBezier.MTreeLeafDirection = false;
|
|
474
|
+
DestroyImmediate (mtreeBezier);
|
|
475
|
+
GenerateTree ();
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
#endif
|
|
482
|
+
}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
using System.Collections;
|
|
2
|
+
using System.Collections.Generic;
|
|
3
|
+
using UnityEngine;
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
[ExecuteInEditMode]
|
|
7
|
+
public class MtreeWind : MonoBehaviour {
|
|
8
|
+
|
|
9
|
+
[Header("Global Windzone")]
|
|
10
|
+
public WindZone windZone;
|
|
11
|
+
[Header("Mtree Wind Offset")]
|
|
12
|
+
public float windStrength = 0;
|
|
13
|
+
public float windDirection = 0;
|
|
14
|
+
public float windPulse = 0;
|
|
15
|
+
public float windTurbulence = 0;
|
|
16
|
+
[Range(0,1)]public float windRandomness = 1;
|
|
17
|
+
[Header("Billboard")]
|
|
18
|
+
public bool BillboardWind = false;
|
|
19
|
+
[Range(0,1)]public float BillboardWindInfluence = .5f;
|
|
20
|
+
|
|
21
|
+
// Updatecheck values
|
|
22
|
+
float m_windStrength, m_windDirection, m_windPulse, m_windTurbulence;
|
|
23
|
+
void Awake(){
|
|
24
|
+
windZone = (WindZone)FindObjectOfType(typeof(WindZone));
|
|
25
|
+
if(!windZone){
|
|
26
|
+
windZone = (WindZone)gameObject.AddComponent (typeof(WindZone));
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
void Update () {
|
|
31
|
+
if(windZone){
|
|
32
|
+
if(m_windStrength != windZone.windMain || m_windDirection != windZone.transform.rotation.eulerAngles.y || m_windPulse != windZone.windPulseFrequency || m_windTurbulence != windZone.windTurbulence){
|
|
33
|
+
UpdateWindZone();
|
|
34
|
+
m_windStrength = windZone.windMain;
|
|
35
|
+
m_windDirection = windZone.transform.rotation.eulerAngles.y;
|
|
36
|
+
m_windPulse = windZone.windPulseFrequency;
|
|
37
|
+
m_windTurbulence = windZone.windTurbulence;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
public void UpdateWind()
|
|
43
|
+
{
|
|
44
|
+
Shader.SetGlobalFloat("_WindStrength", windStrength);
|
|
45
|
+
Shader.SetGlobalFloat("_WindDirection",windDirection);
|
|
46
|
+
Shader.SetGlobalFloat("_WindPulse",windPulse);
|
|
47
|
+
Shader.SetGlobalFloat("_WindTurbulence",windTurbulence);
|
|
48
|
+
}
|
|
49
|
+
public void UpdateWindZone()
|
|
50
|
+
{
|
|
51
|
+
Shader.SetGlobalFloat("_WindStrength",windZone.windMain + windStrength);
|
|
52
|
+
Shader.SetGlobalFloat("_WindDirection",windZone.transform.localRotation.eulerAngles.y + windDirection);
|
|
53
|
+
Shader.SetGlobalFloat("_WindPulse",windZone.windPulseFrequency + windPulse);
|
|
54
|
+
Shader.SetGlobalFloat("_WindTurbulence",windZone.windTurbulence + windTurbulence);
|
|
55
|
+
}
|
|
56
|
+
public void OnValidate(){
|
|
57
|
+
|
|
58
|
+
Shader.SetGlobalFloat("_RandomWindOffset",windRandomness);
|
|
59
|
+
|
|
60
|
+
if(windZone)
|
|
61
|
+
UpdateWindZone();
|
|
62
|
+
if(!windZone)
|
|
63
|
+
UpdateWind();
|
|
64
|
+
|
|
65
|
+
if(BillboardWind){
|
|
66
|
+
Shader.SetGlobalInt("BillboardWindEnabled",0);
|
|
67
|
+
Shader.SetGlobalFloat("Billboard_WindStrength",BillboardWindInfluence);
|
|
68
|
+
}
|
|
69
|
+
if(!BillboardWind){
|
|
70
|
+
Shader.SetGlobalInt("BillboardWindEnabled",1);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
}
|
|
74
|
+
public void ResetToZero(){
|
|
75
|
+
windStrength = 0;
|
|
76
|
+
windDirection = 0;
|
|
77
|
+
windTurbulence = 0;
|
|
78
|
+
windPulse = 0;
|
|
79
|
+
UpdateWind ();
|
|
80
|
+
}
|
|
81
|
+
public void OnDisable(){
|
|
82
|
+
ResetToZero();
|
|
83
|
+
}
|
|
84
|
+
public void OnDestroy(){
|
|
85
|
+
ResetToZero ();
|
|
86
|
+
}
|
|
87
|
+
public void OnEnable(){
|
|
88
|
+
if (windZone)
|
|
89
|
+
UpdateWindZone ();
|
|
90
|
+
else
|
|
91
|
+
UpdateWind ();
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
}
|