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,379 @@
|
|
|
1
|
+
using System.Collections;
|
|
2
|
+
using System.Collections.Generic;
|
|
3
|
+
using System.Linq;
|
|
4
|
+
using UnityEngine;
|
|
5
|
+
|
|
6
|
+
namespace Mtree
|
|
7
|
+
{
|
|
8
|
+
public class Splines
|
|
9
|
+
{
|
|
10
|
+
Stack<Queue<TreePoint>> splines;
|
|
11
|
+
public Queue<Vector3> verts;
|
|
12
|
+
public Queue<Vector3> normals;
|
|
13
|
+
public Queue<int> triangles;
|
|
14
|
+
public Queue<Vector2> uvs;
|
|
15
|
+
public Queue<Color> colors;
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
public Splines(Stack<Queue<TreePoint>> points)
|
|
20
|
+
{
|
|
21
|
+
splines = points;
|
|
22
|
+
verts = new Queue<Vector3>();
|
|
23
|
+
uvs = new Queue<Vector2>();
|
|
24
|
+
normals = new Queue<Vector3>();
|
|
25
|
+
triangles = new Queue<int>();
|
|
26
|
+
colors = new Queue<Color>();
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
public void GenerateMeshData(float resolutionMultiplier, int minResolution, AnimationCurve rootShape, float radiusMultiplier
|
|
30
|
+
, float rootRadius, float rootInnerRadius, float rootHeight, float RootResolutionMultiplier, int flaresNumber, float displacmentStrength
|
|
31
|
+
, float displacmentSize, float spinAmount,float VColBarkModifier)
|
|
32
|
+
{
|
|
33
|
+
Queue<int> trianglesWithBadNormals = new Queue<int>(); // Triangles whose verts have been displaced, needing their normals to be recalculated
|
|
34
|
+
Queue<Vector2Int> duplicatedVertexIndexes = new Queue<Vector2Int>(); // Used when recalculating normals to avoid shading seams
|
|
35
|
+
int[] trunkTriangles = null;
|
|
36
|
+
Vector3[] trunkVertices = null;
|
|
37
|
+
Queue<BarycentricCoordinates> projectedVertices = new Queue<BarycentricCoordinates>();
|
|
38
|
+
bool isTrunk = true;
|
|
39
|
+
while (splines.Count > 0) // Each spline is an entire branch
|
|
40
|
+
{
|
|
41
|
+
SimplexNoiseGenerator noiseGenerator = new SimplexNoiseGenerator(new int[] { 0x16, 0x38, 0x32, 0x2c, 0x0d, 0x13, 0x07, 0x2a });
|
|
42
|
+
Queue<TreePoint> spline = splines.Pop();
|
|
43
|
+
int lastResolution = -1;
|
|
44
|
+
float uv_height = 0f;
|
|
45
|
+
while (spline.Count > 0) // drawing each node inside the branch
|
|
46
|
+
{
|
|
47
|
+
TreePoint point = spline.Dequeue();
|
|
48
|
+
point.radius = Mathf.Max(point.radius, 0.001f);
|
|
49
|
+
int resolution = getResolution(point, minResolution, rootRadius, rootHeight, resolutionMultiplier);
|
|
50
|
+
|
|
51
|
+
Vector3[] newVerts;
|
|
52
|
+
|
|
53
|
+
int n = verts.Count;
|
|
54
|
+
|
|
55
|
+
if (lastResolution == -1 && point.parentRadius != 0 && point.type == NodeType.FromTrunk)
|
|
56
|
+
{
|
|
57
|
+
newVerts = AddCircleWrapped(point.position, point.direction, point.radius, resolution, point.parentRadius, point.parentDirection, displacmentStrength);
|
|
58
|
+
ProjectBranchesOnTrunk(trunkTriangles, trunkVertices, ref newVerts, projectedVertices, n);
|
|
59
|
+
}
|
|
60
|
+
else
|
|
61
|
+
{
|
|
62
|
+
newVerts = AddCircle(point.position, point.direction, point.radius, resolution, uv_height * spinAmount * point.radius);
|
|
63
|
+
}
|
|
64
|
+
duplicatedVertexIndexes.Enqueue(new Vector2Int(n, n + resolution - 1));
|
|
65
|
+
BridgeLoops(newVerts, point, lastResolution, uv_height, n, getFillingGapRate(lastResolution, resolution), flaresNumber, rootRadius, rootInnerRadius, rootHeight, radiusMultiplier,
|
|
66
|
+
rootShape, noiseGenerator, displacmentSize, displacmentStrength, trianglesWithBadNormals,VColBarkModifier);
|
|
67
|
+
if (spline.Count > 0)
|
|
68
|
+
{
|
|
69
|
+
float rad = point.radius;
|
|
70
|
+
if (point.type == NodeType.Flare)
|
|
71
|
+
rad += rootRadius * rootShape.Evaluate(point.position.y / rootHeight) * radiusMultiplier;
|
|
72
|
+
uv_height += (point.position - spline.Peek().position).magnitude / rad;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
lastResolution = resolution;
|
|
76
|
+
}
|
|
77
|
+
if (isTrunk)
|
|
78
|
+
{
|
|
79
|
+
trunkTriangles = triangles.ToArray();
|
|
80
|
+
trunkVertices = verts.ToArray();
|
|
81
|
+
isTrunk = false;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
RecalculateNormals(duplicatedVertexIndexes, trianglesWithBadNormals, projectedVertices);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
void BridgeLoops(Vector3[] loop, TreePoint point, int lastResolution, float uvHeight, int n, int fillingGapRate, int flaresNumber,
|
|
88
|
+
float rootRadius, float rootInnerRadius, float rootHeight, float radiusMultiplier, AnimationCurve rootShape, SimplexNoiseGenerator noiseGenerator,
|
|
89
|
+
float displacementSize, float displacementStrength, Queue<int> trianglesWithBadNormals, float VColBarkModifier)
|
|
90
|
+
{
|
|
91
|
+
int resolution = loop.Length;
|
|
92
|
+
int gaps = lastResolution - resolution; //difference between the two loops
|
|
93
|
+
for (int i = 0; i < resolution; i++)
|
|
94
|
+
{
|
|
95
|
+
Vector3 vert = loop[i];
|
|
96
|
+
Vector3 normal = (vert - point.position).normalized;
|
|
97
|
+
|
|
98
|
+
Vector3 nrm = (vert - point.position).normalized;
|
|
99
|
+
if (lastResolution == -1)
|
|
100
|
+
{
|
|
101
|
+
Vector3 orthoDir = Vector3.ProjectOnPlane(point.direction, point.parentDirection).normalized;
|
|
102
|
+
Vector3 center = (loop[0] + loop[resolution / 2]) / 2 - orthoDir * point.parentRadius;
|
|
103
|
+
Vector3 pos = Vector3.Project(vert - center, point.parentDirection) + center;
|
|
104
|
+
nrm = (vert - pos).normalized;
|
|
105
|
+
}
|
|
106
|
+
bool badNormals = false;
|
|
107
|
+
if (point.type == NodeType.Trunk || point.type == NodeType.Flare) //Trunk displacement
|
|
108
|
+
{
|
|
109
|
+
vert += noiseGenerator.noiseGradient(vert * displacementSize / radiusMultiplier, flat: true) / 5 * point.radius * displacementStrength;
|
|
110
|
+
badNormals = true;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
if (point.type == NodeType.Flare) // root flares displacement
|
|
114
|
+
{
|
|
115
|
+
float angle = i * 1f / (resolution - 1) * 2 * Mathf.PI;
|
|
116
|
+
float displacement = Mathf.Lerp(Mathf.Abs(Mathf.Sin(angle * flaresNumber / 2f)), 1, rootInnerRadius) * rootRadius * rootShape.Evaluate(point.position.y / rootHeight) * radiusMultiplier;
|
|
117
|
+
vert += normal * displacement;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
verts.Enqueue(vert);
|
|
121
|
+
normals.Enqueue(nrm);
|
|
122
|
+
uvs.Enqueue(new Vector2(i * 1f / (resolution - 1), uvHeight / 3.2f) * -1);
|
|
123
|
+
if (i > 0 && lastResolution > 0)
|
|
124
|
+
{
|
|
125
|
+
if (badNormals)
|
|
126
|
+
{
|
|
127
|
+
trianglesWithBadNormals.Enqueue(triangles.Count);
|
|
128
|
+
trianglesWithBadNormals.Enqueue(triangles.Count + 3);
|
|
129
|
+
}
|
|
130
|
+
AddTriangle(n - lastResolution + i - 1, n + i - 1, n - lastResolution + i);
|
|
131
|
+
AddTriangle(n + i - 1, n + i, n - lastResolution + i);
|
|
132
|
+
if (i % fillingGapRate == 0 && gaps > 0) // filling a gap
|
|
133
|
+
{
|
|
134
|
+
if (badNormals)
|
|
135
|
+
trianglesWithBadNormals.Enqueue(triangles.Count);
|
|
136
|
+
AddTriangle(n - lastResolution + i, n + i, n - lastResolution + i + 1);
|
|
137
|
+
gaps--;
|
|
138
|
+
lastResolution--;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
Color col = new Color((point.distanceFromOrigin / 10) * VColBarkModifier, 0, 0);
|
|
142
|
+
colors.Enqueue(col);
|
|
143
|
+
}
|
|
144
|
+
if (gaps > 0) // Fill eventual remaining gap
|
|
145
|
+
{
|
|
146
|
+
for (int i = 0; i < gaps; i++)
|
|
147
|
+
{
|
|
148
|
+
AddTriangle(n - lastResolution + resolution + i - 1, n + resolution - 1, n - lastResolution + resolution + i);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
int getFillingGapRate(int lastResolution, int resolution)
|
|
155
|
+
{
|
|
156
|
+
int gaps = lastResolution - resolution; //difference between the two loops
|
|
157
|
+
int fillingGapRate = int.MaxValue; //rate at which an additional triangle must be created
|
|
158
|
+
if (gaps > resolution)
|
|
159
|
+
resolution = gaps; // increase resolution when there are too many gaps to fill
|
|
160
|
+
if (gaps > 0)
|
|
161
|
+
fillingGapRate = resolution / gaps;
|
|
162
|
+
|
|
163
|
+
return fillingGapRate;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
int getResolution(TreePoint point, int minResolution, float rootRadius, float rootHeight, float resolutionMultiplier)
|
|
167
|
+
{
|
|
168
|
+
int resolution = (int)((point.radius) * resolutionMultiplier * 7);
|
|
169
|
+
|
|
170
|
+
if (point.type == NodeType.Flare)
|
|
171
|
+
resolution += (int)(rootRadius * (Mathf.Pow(1 - Mathf.Max(0, point.position.y / rootHeight), 2)) * resolutionMultiplier * 3);
|
|
172
|
+
|
|
173
|
+
if (resolution < minResolution)
|
|
174
|
+
resolution = minResolution;
|
|
175
|
+
resolution++;
|
|
176
|
+
return resolution;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
public void RecalculateNormals(Queue<Vector2Int> duplicatedVerts, Queue<int> selectedTriangles, Queue<BarycentricCoordinates> projectedVertices)
|
|
180
|
+
{
|
|
181
|
+
Vector3[] newNormals = normals.ToArray();
|
|
182
|
+
HashSet<int> overidenIndexes = new HashSet<int>();
|
|
183
|
+
Vector3[] Verts = verts.ToArray();
|
|
184
|
+
int[] Tris = triangles.ToArray();
|
|
185
|
+
int n = Tris.Length;
|
|
186
|
+
foreach (int i in selectedTriangles)
|
|
187
|
+
{
|
|
188
|
+
int a = Tris[i];
|
|
189
|
+
int b = Tris[i + 1];
|
|
190
|
+
int c = Tris[i + 2];
|
|
191
|
+
|
|
192
|
+
if (!overidenIndexes.Contains(a))
|
|
193
|
+
{
|
|
194
|
+
newNormals[a] = Vector3.zero;
|
|
195
|
+
overidenIndexes.Add(a);
|
|
196
|
+
}
|
|
197
|
+
if (!overidenIndexes.Contains(b))
|
|
198
|
+
{
|
|
199
|
+
newNormals[b] = Vector3.zero;
|
|
200
|
+
overidenIndexes.Add(b);
|
|
201
|
+
}
|
|
202
|
+
if (!overidenIndexes.Contains(c))
|
|
203
|
+
{
|
|
204
|
+
newNormals[c] = Vector3.zero;
|
|
205
|
+
overidenIndexes.Add(c);
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
Vector3 nrm = Vector3.Cross(Verts[b] - Verts[a], Verts[c] - Verts[a]);
|
|
209
|
+
|
|
210
|
+
newNormals[a] += nrm;
|
|
211
|
+
newNormals[b] += nrm;
|
|
212
|
+
newNormals[c] += nrm;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
foreach (int i in overidenIndexes)
|
|
216
|
+
{
|
|
217
|
+
newNormals[i].Normalize();
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
foreach (Vector2Int indexes in duplicatedVerts)
|
|
221
|
+
{
|
|
222
|
+
int x = indexes.x;
|
|
223
|
+
int y = indexes.y;
|
|
224
|
+
Vector3 nrm = (newNormals[x] + newNormals[y]) / 2;
|
|
225
|
+
newNormals[x] = newNormals[y] = nrm;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
|
|
229
|
+
foreach (BarycentricCoordinates coords in projectedVertices)
|
|
230
|
+
{
|
|
231
|
+
newNormals[coords.index] = (newNormals[coords.i1] * coords.w1 + newNormals[coords.i2] * coords.w2 + newNormals[coords.i3] * coords.w3);
|
|
232
|
+
//newNormals[coords.index] = Vector3.up;
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
normals = new Queue<Vector3>(newNormals);
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
public static Vector3[] AddCircle(Vector3 position, Vector3 direction, float radius, int resolution, float spinAngle)
|
|
239
|
+
{
|
|
240
|
+
Vector3[] verts = new Vector3[resolution];
|
|
241
|
+
Quaternion rotation = Quaternion.FromToRotation(Vector3.up, direction);
|
|
242
|
+
for (int i = 0; i < resolution; i++)
|
|
243
|
+
{
|
|
244
|
+
float angle = Mathf.PI * 2 * ((float)i / (resolution - 1)) + spinAngle;
|
|
245
|
+
Vector3 vert = new Vector3(Mathf.Cos(angle) * radius, 0, Mathf.Sin(angle) * radius);
|
|
246
|
+
verts[i] = rotation * vert + position;
|
|
247
|
+
}
|
|
248
|
+
return verts;
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
public static Vector3[] AddCircleWrapped(Vector3 position, Vector3 direction, float radius, int resolution, float parentRadius, Vector3 parentDirection, float displcementStrength)
|
|
252
|
+
{
|
|
253
|
+
Vector3[] verts = new Vector3[resolution];
|
|
254
|
+
Vector3 orthoDir = Vector3.ProjectOnPlane(direction, parentDirection).normalized;
|
|
255
|
+
Quaternion rotation = Quaternion.FromToRotation(Vector3.up, orthoDir);
|
|
256
|
+
Vector3 tangent = Vector3.Cross(parentDirection, orthoDir);
|
|
257
|
+
float scale = Mathf.Sqrt(Mathf.Pow(Mathf.Tan(90 - Vector3.Angle(direction, parentDirection) * Mathf.PI / 180), 2) + 1);
|
|
258
|
+
scale = Mathf.Min(scale, 4f) / 4;
|
|
259
|
+
Matrix4x4 scaleMat = Matrix4x4.identity;
|
|
260
|
+
scaleMat[0, 0] += parentDirection.x * scale;
|
|
261
|
+
scaleMat[1, 1] += parentDirection.y * scale;
|
|
262
|
+
scaleMat[2, 2] += parentDirection.z * scale;
|
|
263
|
+
for (int i = 0; i < resolution; i++)
|
|
264
|
+
{
|
|
265
|
+
float angle = Mathf.PI * 2 * ((float)i / (resolution - 1));
|
|
266
|
+
Vector3 vert = new Vector3(Mathf.Cos(angle) * radius, 0, Mathf.Sin(angle) * radius);
|
|
267
|
+
vert = (rotation * vert);
|
|
268
|
+
float wrap = Mathf.Sin(Mathf.Acos(Mathf.Clamp01(Mathf.Abs(Vector3.Dot(vert, tangent)) / parentRadius))) * parentRadius;
|
|
269
|
+
vert = scaleMat.MultiplyPoint(vert);
|
|
270
|
+
vert += orthoDir * wrap;
|
|
271
|
+
vert += position + parentDirection * Vector3.Dot(direction, parentDirection) * parentRadius;
|
|
272
|
+
verts[i] = vert;
|
|
273
|
+
}
|
|
274
|
+
return verts;
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
public void AddTriangle(int a, int b, int c)
|
|
278
|
+
{
|
|
279
|
+
triangles.Enqueue(a);
|
|
280
|
+
triangles.Enqueue(b);
|
|
281
|
+
triangles.Enqueue(c);
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
public void ProjectBranchesOnTrunk(int[] trunkTriangles, Vector3[] trunkVertices, ref Vector3[] vertices, Queue<BarycentricCoordinates> projectedVertices, int verticesCount)
|
|
285
|
+
{
|
|
286
|
+
Vector3[] centers = new Vector3[trunkTriangles.Length / 3];
|
|
287
|
+
for (int i = 0; i < centers.Length; i++)
|
|
288
|
+
centers[i] = (trunkVertices[trunkTriangles[i * 3]] + trunkVertices[trunkTriangles[i * 3 + 1]] + trunkVertices[trunkTriangles[i * 3 + 2]]) / 3;
|
|
289
|
+
|
|
290
|
+
for (int i = 0; i < vertices.Length; i++)
|
|
291
|
+
{
|
|
292
|
+
Vector3 vert = vertices[i];
|
|
293
|
+
int closestTriangle = 0;
|
|
294
|
+
float minDist = Mathf.Infinity;
|
|
295
|
+
for (int j = 0; j < centers.Length; j++)
|
|
296
|
+
{
|
|
297
|
+
float dist = Vector3.SqrMagnitude(centers[j] - vert);
|
|
298
|
+
if (dist < minDist)
|
|
299
|
+
{
|
|
300
|
+
minDist = dist;
|
|
301
|
+
closestTriangle = j * 3;
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
Vector3 projectedVert = ClosestPointOnTriangle(trunkVertices[trunkTriangles[closestTriangle]], trunkVertices[trunkTriangles[closestTriangle + 1]], trunkVertices[trunkTriangles[closestTriangle + 2]], vertices[i]);
|
|
306
|
+
Vector3 coordinates = Barycentric(projectedVert, trunkVertices[trunkTriangles[closestTriangle]], trunkVertices[trunkTriangles[closestTriangle + 1]], trunkVertices[trunkTriangles[closestTriangle + 2]]);
|
|
307
|
+
projectedVertices.Enqueue(new BarycentricCoordinates(verticesCount + i, trunkTriangles[closestTriangle], trunkTriangles[closestTriangle], trunkTriangles[closestTriangle], coordinates));
|
|
308
|
+
vertices[i] = projectedVert;
|
|
309
|
+
}
|
|
310
|
+
//vertices[i] = centers[closestTriangle / 3];
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
public Vector3 ClosestPointOnTriangle(Vector3 v1, Vector3 v2, Vector3 v3, Vector3 point)
|
|
314
|
+
{
|
|
315
|
+
Vector3 normal = Vector3.Cross(v1 - v2, v1 - v3);
|
|
316
|
+
return Vector3.ProjectOnPlane(point - v1, normal) + v1;
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
private Vector3 Barycentric(Vector3 p, Vector3 a, Vector3 b, Vector3 c)
|
|
320
|
+
{
|
|
321
|
+
Vector3 v0 = b - a;
|
|
322
|
+
Vector3 v1 = c - a;
|
|
323
|
+
Vector3 v2 = p - a;
|
|
324
|
+
float d00 = Vector3.Dot(v0, v0);
|
|
325
|
+
float d01 = Vector3.Dot(v0, v1);
|
|
326
|
+
float d11 = Vector3.Dot(v1, v1);
|
|
327
|
+
float d20 = Vector3.Dot(v2, v0);
|
|
328
|
+
float d21 = Vector3.Dot(v2, v1);
|
|
329
|
+
float denom = d00 * d11 - d01 * d01;
|
|
330
|
+
|
|
331
|
+
Vector3 coordinates = Vector3.zero;
|
|
332
|
+
coordinates.y = (d11 * d20 - d01 * d21) / denom;
|
|
333
|
+
coordinates.z = (d00 * d21 - d01 * d20) / denom;
|
|
334
|
+
coordinates.x = 1.0f - coordinates.y - coordinates.z;
|
|
335
|
+
|
|
336
|
+
return coordinates;
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
public struct Vector2Int
|
|
342
|
+
{
|
|
343
|
+
public int x;
|
|
344
|
+
public int y;
|
|
345
|
+
|
|
346
|
+
public Vector2Int(int x, int y)
|
|
347
|
+
{
|
|
348
|
+
this.x = x;
|
|
349
|
+
this.y = y;
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
public struct BarycentricCoordinates
|
|
355
|
+
{
|
|
356
|
+
public int index; // the index of the vertex/normal that is described by the coordinates
|
|
357
|
+
|
|
358
|
+
public int i1; // the index of the first vertex of the triangle
|
|
359
|
+
public int i2; // the index of the second vertex of the triangle
|
|
360
|
+
public int i3; // the index of the third vertex of the triangle
|
|
361
|
+
|
|
362
|
+
public float w1; // the weight of the first vertex
|
|
363
|
+
public float w2; // the weight of the second vertex
|
|
364
|
+
public float w3; // the weight of the third vertex
|
|
365
|
+
|
|
366
|
+
public BarycentricCoordinates(int index, int i1, int i2, int i3, Vector3 coordinates)
|
|
367
|
+
{
|
|
368
|
+
this.index = index;
|
|
369
|
+
|
|
370
|
+
this.i1 = i1;
|
|
371
|
+
this.i2 = i2;
|
|
372
|
+
this.i3 = i3;
|
|
373
|
+
|
|
374
|
+
w1 = coordinates.x;
|
|
375
|
+
w2 = coordinates.y;
|
|
376
|
+
w3 = coordinates.z;
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
}
|
|
@@ -0,0 +1,290 @@
|
|
|
1
|
+
#if UNITY_EDITOR
|
|
2
|
+
using System.Collections;
|
|
3
|
+
using System.Collections.Generic;
|
|
4
|
+
using UnityEditor;
|
|
5
|
+
using UnityEngine;
|
|
6
|
+
using UnityEngine.Rendering;
|
|
7
|
+
using System.Linq;
|
|
8
|
+
|
|
9
|
+
namespace Mtree
|
|
10
|
+
{
|
|
11
|
+
class Billboard
|
|
12
|
+
{
|
|
13
|
+
private Camera cam;
|
|
14
|
+
private GameObject target;
|
|
15
|
+
private int width = 512;
|
|
16
|
+
private int height = 512;
|
|
17
|
+
private Texture2D[] sides;
|
|
18
|
+
private Rect[] rects;
|
|
19
|
+
private float ZBuffer = 0.03f;
|
|
20
|
+
private float TopCardPosition = 0.5f;
|
|
21
|
+
private bool hasTopCard,isSingleSided;
|
|
22
|
+
int cards = 2;
|
|
23
|
+
public Billboard(Camera cam, GameObject target, int width, int height, float TopCardPosition, bool hasTopCard, bool isSingleSided)
|
|
24
|
+
{
|
|
25
|
+
this.cam = cam;
|
|
26
|
+
this.target = target;
|
|
27
|
+
this.width = width;
|
|
28
|
+
this.height = height;
|
|
29
|
+
this.TopCardPosition = TopCardPosition;
|
|
30
|
+
this.isSingleSided = isSingleSided;
|
|
31
|
+
|
|
32
|
+
if (isSingleSided)
|
|
33
|
+
cards += 2;
|
|
34
|
+
if (hasTopCard && !isSingleSided)
|
|
35
|
+
cards += 1;
|
|
36
|
+
if (hasTopCard && isSingleSided)
|
|
37
|
+
cards += 2;
|
|
38
|
+
|
|
39
|
+
sides = new Texture2D[cards];
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
public void SetupCamera()
|
|
45
|
+
{
|
|
46
|
+
float rw = width;
|
|
47
|
+
rw /= Screen.width;
|
|
48
|
+
float rh = height;
|
|
49
|
+
rh /= Screen.height;
|
|
50
|
+
|
|
51
|
+
Bounds bb = target.GetComponent<Renderer>().bounds;
|
|
52
|
+
|
|
53
|
+
cam.transform.position = bb.center;
|
|
54
|
+
cam.nearClipPlane = -bb.extents.x;
|
|
55
|
+
cam.farClipPlane = bb.extents.x;
|
|
56
|
+
cam.orthographicSize = bb.extents.y;
|
|
57
|
+
cam.aspect = bb.extents.x / bb.extents.y * 2;
|
|
58
|
+
|
|
59
|
+
if (cam.aspect <= 1)
|
|
60
|
+
width = (int)(height * cam.aspect);
|
|
61
|
+
else
|
|
62
|
+
height = (int)(width / cam.aspect);
|
|
63
|
+
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
public void Render(string path)
|
|
67
|
+
{
|
|
68
|
+
Bounds bb = target.GetComponent<Renderer>().bounds;
|
|
69
|
+
int layer = target.layer;
|
|
70
|
+
target.layer = 31;
|
|
71
|
+
cam.cullingMask = 1 << 31;
|
|
72
|
+
var originalPos = cam.transform.position;
|
|
73
|
+
cam.transform.position = new Vector3(target.transform.position.x, bb.center.y, target.transform.position.z);
|
|
74
|
+
for (int i = 0; i < cards; i++)
|
|
75
|
+
{
|
|
76
|
+
RenderTexture currentRT = RenderTexture.active;
|
|
77
|
+
RenderTexture camText = new RenderTexture(width, height, 16);
|
|
78
|
+
|
|
79
|
+
cam.targetTexture = camText;
|
|
80
|
+
RenderTexture.active = cam.targetTexture;
|
|
81
|
+
cam.Render();
|
|
82
|
+
Texture2D image = new Texture2D(cam.targetTexture.width, cam.targetTexture.height);
|
|
83
|
+
image.ReadPixels(new Rect(0, 0, cam.targetTexture.width, cam.targetTexture.height), 0, 0);
|
|
84
|
+
|
|
85
|
+
if (i == 5)
|
|
86
|
+
{
|
|
87
|
+
Color32[] originalPixels = image.GetPixels32().Reverse().ToArray();
|
|
88
|
+
var flippedPixels =
|
|
89
|
+
Enumerable.Range(0, image.width * image.height)
|
|
90
|
+
.Select(index =>
|
|
91
|
+
{
|
|
92
|
+
int x = index % image.width;
|
|
93
|
+
int y = index / image.width;
|
|
94
|
+
x = image.width - 1 - x;
|
|
95
|
+
return originalPixels[y * image.width + x];
|
|
96
|
+
}
|
|
97
|
+
);
|
|
98
|
+
image.SetPixels32(flippedPixels.ToArray());
|
|
99
|
+
}
|
|
100
|
+
image.Apply();
|
|
101
|
+
RenderTexture.active = currentRT;
|
|
102
|
+
sides[i] = image;
|
|
103
|
+
|
|
104
|
+
if (isSingleSided)
|
|
105
|
+
{
|
|
106
|
+
if (i < 3)
|
|
107
|
+
cam.transform.Rotate(Vector3.up * 90);
|
|
108
|
+
if (i == 3)
|
|
109
|
+
{
|
|
110
|
+
cam.ResetAspect();
|
|
111
|
+
cam.aspect = 1;
|
|
112
|
+
cam.orthographicSize = Mathf.Max(bb.extents.x, bb.extents.z) * 2;
|
|
113
|
+
|
|
114
|
+
cam.transform.position = originalPos;
|
|
115
|
+
var t = cam.transform.position;
|
|
116
|
+
cam.transform.position = new Vector3(t.x, bb.extents.y * 2, t.z);
|
|
117
|
+
cam.transform.Rotate(Vector3.right * 90);
|
|
118
|
+
cam.farClipPlane = bb.extents.y * 3;
|
|
119
|
+
cam.nearClipPlane = -bb.extents.y * 3;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
}
|
|
123
|
+
if (!isSingleSided)
|
|
124
|
+
{
|
|
125
|
+
if (i == 0)
|
|
126
|
+
cam.transform.Rotate(Vector3.up * 90);
|
|
127
|
+
if (i == 1)
|
|
128
|
+
{
|
|
129
|
+
cam.ResetAspect();
|
|
130
|
+
cam.aspect = 1;
|
|
131
|
+
cam.orthographicSize = Mathf.Max(bb.extents.x, bb.extents.z) * 2;
|
|
132
|
+
|
|
133
|
+
cam.transform.position = originalPos;
|
|
134
|
+
cam.transform.Rotate(Vector3.up * 180);
|
|
135
|
+
var t = cam.transform.position;
|
|
136
|
+
cam.transform.position = new Vector3(t.x, bb.extents.y * 2, t.z);
|
|
137
|
+
cam.transform.Rotate(Vector3.right * 90);
|
|
138
|
+
cam.farClipPlane = bb.extents.y * 3;
|
|
139
|
+
cam.nearClipPlane = -bb.extents.y * 3;
|
|
140
|
+
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
Texture2D atlas = new Texture2D(width, height);
|
|
147
|
+
rects = atlas.PackTextures(sides, 0, Mathf.Min(height, width) * cards);
|
|
148
|
+
Utils.DilateTexture(atlas, 100);
|
|
149
|
+
byte[] bytes = atlas.EncodeToPNG();
|
|
150
|
+
System.IO.File.WriteAllBytes(path, bytes);
|
|
151
|
+
AssetDatabase.SaveAssets();
|
|
152
|
+
AssetDatabase.Refresh();
|
|
153
|
+
target.layer = layer;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
public Mesh CreateMesh()
|
|
157
|
+
{
|
|
158
|
+
Vector3[] verts = new Vector3[cards * 4];
|
|
159
|
+
Vector3[] normals = new Vector3[cards * 4];
|
|
160
|
+
Vector2[] uvs = new Vector2[cards * 4];
|
|
161
|
+
int[] triangles = new int[cards * 6];
|
|
162
|
+
|
|
163
|
+
Bounds bb = target.GetComponent<MeshRenderer>().bounds;
|
|
164
|
+
float maxTC = Mathf.Max(bb.extents.x, bb.extents.z);
|
|
165
|
+
for (int i = 0; i < cards; i++)
|
|
166
|
+
{
|
|
167
|
+
var count = i;
|
|
168
|
+
|
|
169
|
+
if (i == 4 || i == 2 && !isSingleSided)
|
|
170
|
+
count = 0;
|
|
171
|
+
|
|
172
|
+
float angle = 90f * count + 180;
|
|
173
|
+
Vector3 x = Quaternion.Euler(0f, angle, 0f) * Vector3.left * bb.extents.x * 2;
|
|
174
|
+
Vector3 normal = Quaternion.Euler(0f, angle, 0f) * Vector3.back;
|
|
175
|
+
Vector3 y = Vector3.up * bb.extents.y * 2;
|
|
176
|
+
|
|
177
|
+
Vector3 v0 = x;
|
|
178
|
+
Vector3 v1 = x + y;
|
|
179
|
+
Vector3 v2 = y - x;
|
|
180
|
+
Vector3 v3 = -x;
|
|
181
|
+
|
|
182
|
+
|
|
183
|
+
if (i == 0 && isSingleSided)
|
|
184
|
+
{
|
|
185
|
+
|
|
186
|
+
v0.z += ZBuffer;
|
|
187
|
+
v1.z += ZBuffer;
|
|
188
|
+
v2.z += ZBuffer;
|
|
189
|
+
v3.z += ZBuffer;
|
|
190
|
+
}
|
|
191
|
+
if (i == 1 && isSingleSided)
|
|
192
|
+
{
|
|
193
|
+
|
|
194
|
+
v0.x += ZBuffer;
|
|
195
|
+
v1.x += ZBuffer;
|
|
196
|
+
v2.x += ZBuffer;
|
|
197
|
+
v3.x += ZBuffer;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
if (i == 4 || !isSingleSided && i == 2)
|
|
201
|
+
{
|
|
202
|
+
float height = Mathf.Lerp(0, bb.extents.y * 2, TopCardPosition);
|
|
203
|
+
float bbX = bb.extents.x * 2 - (rects[i].width / 2);
|
|
204
|
+
float bbZ = bb.extents.z * 2 - (rects[i].height / 2);
|
|
205
|
+
|
|
206
|
+
v0 = new Vector3(-bbX, height, bbZ);
|
|
207
|
+
v1 = new Vector3(bbX, height, bbZ);
|
|
208
|
+
v2 = new Vector3(bbX, height, -bbZ);
|
|
209
|
+
v3 = new Vector3(-bbX, height, -bbZ);
|
|
210
|
+
|
|
211
|
+
}
|
|
212
|
+
if (i == 5)
|
|
213
|
+
{
|
|
214
|
+
float height = Mathf.Lerp(0, bb.extents.y * 2, TopCardPosition) - ZBuffer;
|
|
215
|
+
float bbX = bb.extents.x * 2 - (rects[i-1].width / 2);
|
|
216
|
+
float bbZ = bb.extents.z * 2 - (rects[i-1].height / 2);
|
|
217
|
+
|
|
218
|
+
v0 = new Vector3(bbX, height, bbZ);
|
|
219
|
+
v1 = new Vector3(-bbX, height, bbZ);
|
|
220
|
+
v2 = new Vector3(-bbX, height, -bbZ);
|
|
221
|
+
v3 = new Vector3(bbX, height, -bbZ);
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
|
|
225
|
+
verts[4 * i + 0] = v0;
|
|
226
|
+
verts[4 * i + 1] = v1;
|
|
227
|
+
verts[4 * i + 2] = v2;
|
|
228
|
+
verts[4 * i + 3] = v3;
|
|
229
|
+
|
|
230
|
+
x.Normalize();
|
|
231
|
+
float normalFacing = 50f;
|
|
232
|
+
Vector3 n0 = (x + normalFacing * normal).normalized;
|
|
233
|
+
Vector3 n1 = (x + normalFacing * normal).normalized;
|
|
234
|
+
Vector3 n2 = (-x + normalFacing * normal).normalized;
|
|
235
|
+
Vector3 n3 = (-x + normalFacing * normal).normalized;
|
|
236
|
+
|
|
237
|
+
|
|
238
|
+
normals[4 * i] = n0;
|
|
239
|
+
normals[4 * i + 1] = n1;
|
|
240
|
+
normals[4 * i + 2] = n2;
|
|
241
|
+
normals[4 * i + 3] = n3;
|
|
242
|
+
|
|
243
|
+
triangles[6 * i] = 4 * i;
|
|
244
|
+
triangles[6 * i + 1] = 4 * i + 1;
|
|
245
|
+
triangles[6 * i + 2] = 4 * i + 2;
|
|
246
|
+
triangles[6 * i + 3] = 4 * i + 2;
|
|
247
|
+
triangles[6 * i + 4] = 4 * i + 3;
|
|
248
|
+
triangles[6 * i + 5] = 4 * i;
|
|
249
|
+
|
|
250
|
+
Vector2 c = rects[i].center;
|
|
251
|
+
Vector2 u = new Vector2();
|
|
252
|
+
Vector2 v = new Vector2();
|
|
253
|
+
|
|
254
|
+
u = new Vector2(rects[i].max.x - c.x, 0f);
|
|
255
|
+
v = new Vector2(0f, rects[i].max.y - c.y);
|
|
256
|
+
|
|
257
|
+
|
|
258
|
+
uvs[4 * i] = c + u - v;
|
|
259
|
+
uvs[4 * i + 1] = c + u + v;
|
|
260
|
+
uvs[4 * i + 2] = c - u + v;
|
|
261
|
+
uvs[4 * i + 3] = c - u - v;
|
|
262
|
+
|
|
263
|
+
}
|
|
264
|
+
Mesh mesh = new Mesh
|
|
265
|
+
{
|
|
266
|
+
vertices = verts,
|
|
267
|
+
triangles = triangles,
|
|
268
|
+
uv = uvs,
|
|
269
|
+
normals = normals
|
|
270
|
+
};
|
|
271
|
+
return mesh;
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
public Material CreateMaterial(Texture tex, bool usingHDRP)
|
|
275
|
+
{
|
|
276
|
+
Bounds bb = target.GetComponent<MeshRenderer>().bounds;
|
|
277
|
+
var pipeline = GraphicsSettings.defaultRenderPipeline;
|
|
278
|
+
Shader shader = Utils.GetBillboardShader();
|
|
279
|
+
if (usingHDRP)
|
|
280
|
+
shader = Shader.Find("Mtree/SRP/Billboard HDRP");
|
|
281
|
+
Material mat = new Material(shader);
|
|
282
|
+
mat.mainTexture = tex;
|
|
283
|
+
mat.SetFloat("_AlphaClip", 1);
|
|
284
|
+
return mat;
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
}
|
|
290
|
+
#endif
|