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.
Files changed (290) hide show
  1. package/.github/workflows/npm.yml +19 -0
  2. package/CHANGELOG.md +17 -0
  3. package/CHANGELOG.md.meta +7 -0
  4. package/Documentation~/Documentation.md +3 -0
  5. package/Editor/BranchEditor.cs +545 -0
  6. package/Editor/BranchEditor.cs.meta +16 -0
  7. package/Editor/EditorCallbacks.cs +69 -0
  8. package/Editor/EditorCallbacks.cs.meta +11 -0
  9. package/Editor/MTree.Editor.asmdef +18 -0
  10. package/Editor/MTree.Editor.asmdef.meta +7 -0
  11. package/Editor/MenuItem.cs +31 -0
  12. package/Editor/MenuItem.cs.meta +11 -0
  13. package/Editor/MtreeBezierInspector.cs +161 -0
  14. package/Editor/MtreeBezierInspector.cs.meta +11 -0
  15. package/Editor/MtreeEditor.cs +434 -0
  16. package/Editor/MtreeEditor.cs.meta +11 -0
  17. package/Editor/TemplateInspector.cs +66 -0
  18. package/Editor/TemplateInspector.cs.meta +12 -0
  19. package/Editor/ValuesEditor.cs +18 -0
  20. package/Editor/ValuesEditor.cs.meta +11 -0
  21. package/Editor/VertexColorAdjustmentEditor.cs +169 -0
  22. package/Editor/VertexColorAdjustmentEditor.cs.meta +11 -0
  23. package/Editor.meta +8 -0
  24. package/LICENSE +21 -0
  25. package/LICENSE.meta +7 -0
  26. package/README.md +68 -0
  27. package/README.md.meta +7 -0
  28. package/Resources/Mtree/MtreeBillboardCamera.prefab +204 -0
  29. package/Resources/Mtree/MtreeBillboardCamera.prefab.meta +8 -0
  30. package/Resources/Mtree/Sprites/DeleteCrossSprite.png +0 -0
  31. package/Resources/Mtree/Sprites/DeleteCrossSprite.png.meta +116 -0
  32. package/Resources/Mtree/Sprites/TreeFunctionSprite.png +0 -0
  33. package/Resources/Mtree/Sprites/TreeFunctionSprite.png.meta +116 -0
  34. package/Resources/Mtree/Sprites/TreeFunctionSpriteSelected.psd +0 -0
  35. package/Resources/Mtree/Sprites/TreeFunctionSpriteSelected.psd.meta +116 -0
  36. package/Resources/Mtree/Sprites.meta +8 -0
  37. package/Resources/Mtree/Vertex Color Editor/Mtree Vertex Color GameObject.prefab +104 -0
  38. package/Resources/Mtree/Vertex Color Editor/Mtree Vertex Color GameObject.prefab.meta +7 -0
  39. package/Resources/Mtree/Vertex Color Editor.meta +8 -0
  40. package/Resources/Mtree/branches.fbx +0 -0
  41. package/Resources/Mtree/branches.fbx.meta +137 -0
  42. package/Resources/Mtree.meta +8 -0
  43. package/Resources.meta +8 -0
  44. package/Runtime/AO/DensityAO.cs +203 -0
  45. package/Runtime/AO/DensityAO.cs.meta +11 -0
  46. package/Runtime/AO/KDTree.cs +169 -0
  47. package/Runtime/AO/KDTree.cs.meta +11 -0
  48. package/Runtime/AO/WeightedRandom.cs +74 -0
  49. package/Runtime/AO/WeightedRandom.cs.meta +11 -0
  50. package/Runtime/AO.meta +8 -0
  51. package/Runtime/Bezier/Bezier.cs +69 -0
  52. package/Runtime/Bezier/Bezier.cs.meta +11 -0
  53. package/Runtime/Bezier/MtreeBezier.cs +185 -0
  54. package/Runtime/Bezier/MtreeBezier.cs.meta +11 -0
  55. package/Runtime/Bezier.meta +8 -0
  56. package/Runtime/ExampleSceneManager.cs +165 -0
  57. package/Runtime/ExampleSceneManager.cs.meta +11 -0
  58. package/Runtime/LODValues.cs +44 -0
  59. package/Runtime/LODValues.cs.meta +11 -0
  60. package/Runtime/LeafPoint.cs +135 -0
  61. package/Runtime/LeafPoint.cs.meta +11 -0
  62. package/Runtime/MTree.Runtime.asmdef +3 -0
  63. package/Runtime/MTree.Runtime.asmdef.meta +7 -0
  64. package/Runtime/MTree.cs +569 -0
  65. package/Runtime/MTree.cs.meta +11 -0
  66. package/Runtime/MtreeComponent.cs +482 -0
  67. package/Runtime/MtreeComponent.cs.meta +11 -0
  68. package/Runtime/MtreeVariables.cs +11 -0
  69. package/Runtime/MtreeVariables.cs.meta +11 -0
  70. package/Runtime/MtreeWind.cs +94 -0
  71. package/Runtime/MtreeWind.cs.meta +11 -0
  72. package/Runtime/Node.cs +331 -0
  73. package/Runtime/Node.cs.meta +11 -0
  74. package/Runtime/SimplexNoise.cs +166 -0
  75. package/Runtime/SimplexNoise.cs.meta +11 -0
  76. package/Runtime/Splines.cs +379 -0
  77. package/Runtime/Splines.cs.meta +11 -0
  78. package/Runtime/TreeBilboard.cs +290 -0
  79. package/Runtime/TreeBilboard.cs.meta +11 -0
  80. package/Runtime/TreeFunctions/BranchFunction.cs +92 -0
  81. package/Runtime/TreeFunctions/BranchFunction.cs.meta +11 -0
  82. package/Runtime/TreeFunctions/GrowFunction.cs +81 -0
  83. package/Runtime/TreeFunctions/GrowFunction.cs.meta +11 -0
  84. package/Runtime/TreeFunctions/LeafFunction.cs +111 -0
  85. package/Runtime/TreeFunctions/LeafFunction.cs.meta +11 -0
  86. package/Runtime/TreeFunctions/RootsFunction.cs +77 -0
  87. package/Runtime/TreeFunctions/RootsFunction.cs.meta +11 -0
  88. package/Runtime/TreeFunctions/SplitFunction.cs +50 -0
  89. package/Runtime/TreeFunctions/SplitFunction.cs.meta +11 -0
  90. package/Runtime/TreeFunctions/TreeFunctionAsset.cs +105 -0
  91. package/Runtime/TreeFunctions/TreeFunctionAsset.cs.meta +11 -0
  92. package/Runtime/TreeFunctions/TrunkFunction.cs +88 -0
  93. package/Runtime/TreeFunctions/TrunkFunction.cs.meta +11 -0
  94. package/Runtime/TreeFunctions.meta +8 -0
  95. package/Runtime/TreePoint.cs +27 -0
  96. package/Runtime/TreePoint.cs.meta +11 -0
  97. package/Runtime/TreeTemplate.cs +50 -0
  98. package/Runtime/TreeTemplate.cs.meta +12 -0
  99. package/Runtime/Utils.cs +268 -0
  100. package/Runtime/Utils.cs.meta +11 -0
  101. package/Runtime/VSProIntegration.cs +132 -0
  102. package/Runtime/VSProIntegration.cs.meta +11 -0
  103. package/Runtime.meta +8 -0
  104. package/Samples~/ExampleTemplates/Examples/Birch.asset +364 -0
  105. package/Samples~/ExampleTemplates/Examples/Birch.asset.meta +8 -0
  106. package/Samples~/ExampleTemplates/Examples/Bush.asset +385 -0
  107. package/Samples~/ExampleTemplates/Examples/Bush.asset.meta +8 -0
  108. package/Samples~/ExampleTemplates/Examples/Eastern Pine.asset +482 -0
  109. package/Samples~/ExampleTemplates/Examples/Eastern Pine.asset.meta +8 -0
  110. package/Samples~/ExampleTemplates/Examples/FantasyTree.asset +406 -0
  111. package/Samples~/ExampleTemplates/Examples/FantasyTree.asset.meta +8 -0
  112. package/Samples~/ExampleTemplates/Examples/Fern.asset +291 -0
  113. package/Samples~/ExampleTemplates/Examples/Fern.asset.meta +8 -0
  114. package/Samples~/ExampleTemplates/Examples/High Poly.asset +300 -0
  115. package/Samples~/ExampleTemplates/Examples/High Poly.asset.meta +8 -0
  116. package/Samples~/ExampleTemplates/Examples/LightingData.asset +0 -0
  117. package/Samples~/ExampleTemplates/Examples/LightingData.asset.meta +8 -0
  118. package/Samples~/ExampleTemplates/Examples/Materials/Bark/Bark Birch Outline.mat +196 -0
  119. package/Samples~/ExampleTemplates/Examples/Materials/Bark/Bark Birch Outline.mat.meta +8 -0
  120. package/Samples~/ExampleTemplates/Examples/Materials/Bark/Bark Birch.mat +196 -0
  121. package/Samples~/ExampleTemplates/Examples/Materials/Bark/Bark Birch.mat.meta +8 -0
  122. package/Samples~/ExampleTemplates/Examples/Materials/Bark/Bark Fern.mat +181 -0
  123. package/Samples~/ExampleTemplates/Examples/Materials/Bark/Bark Fern.mat.meta +8 -0
  124. package/Samples~/ExampleTemplates/Examples/Materials/Bark/Bark HighPoly.mat +201 -0
  125. package/Samples~/ExampleTemplates/Examples/Materials/Bark/Bark HighPoly.mat.meta +8 -0
  126. package/Samples~/ExampleTemplates/Examples/Materials/Bark/Bark Oak.mat +208 -0
  127. package/Samples~/ExampleTemplates/Examples/Materials/Bark/Bark Oak.mat.meta +8 -0
  128. package/Samples~/ExampleTemplates/Examples/Materials/Bark/Bark Palm.mat +180 -0
  129. package/Samples~/ExampleTemplates/Examples/Materials/Bark/Bark Palm.mat.meta +8 -0
  130. package/Samples~/ExampleTemplates/Examples/Materials/Bark/Bark Pine.mat +206 -0
  131. package/Samples~/ExampleTemplates/Examples/Materials/Bark/Bark Pine.mat.meta +8 -0
  132. package/Samples~/ExampleTemplates/Examples/Materials/Bark/Bark Ponderossa.mat +206 -0
  133. package/Samples~/ExampleTemplates/Examples/Materials/Bark/Bark Ponderossa.mat.meta +8 -0
  134. package/Samples~/ExampleTemplates/Examples/Materials/Bark/Bark Poplar.mat +172 -0
  135. package/Samples~/ExampleTemplates/Examples/Materials/Bark/Bark Poplar.mat.meta +8 -0
  136. package/Samples~/ExampleTemplates/Examples/Materials/Bark.meta +8 -0
  137. package/Samples~/ExampleTemplates/Examples/Materials/Example Scene/Floor.mat +392 -0
  138. package/Samples~/ExampleTemplates/Examples/Materials/Example Scene/Floor.mat.meta +8 -0
  139. package/Samples~/ExampleTemplates/Examples/Materials/Example Scene.meta +8 -0
  140. package/Samples~/ExampleTemplates/Examples/Materials/Leafs/Leafs Fern.mat +202 -0
  141. package/Samples~/ExampleTemplates/Examples/Materials/Leafs/Leafs Fern.mat.meta +8 -0
  142. package/Samples~/ExampleTemplates/Examples/Materials/Leafs/Leafs HighPoly.mat +265 -0
  143. package/Samples~/ExampleTemplates/Examples/Materials/Leafs/Leafs HighPoly.mat.meta +8 -0
  144. package/Samples~/ExampleTemplates/Examples/Materials/Leafs/Leafs Needles.mat +267 -0
  145. package/Samples~/ExampleTemplates/Examples/Materials/Leafs/Leafs Needles.mat.meta +8 -0
  146. package/Samples~/ExampleTemplates/Examples/Materials/Leafs/Leafs Palm.mat +232 -0
  147. package/Samples~/ExampleTemplates/Examples/Materials/Leafs/Leafs Palm.mat.meta +8 -0
  148. package/Samples~/ExampleTemplates/Examples/Materials/Leafs/Leafs Palmate.mat +250 -0
  149. package/Samples~/ExampleTemplates/Examples/Materials/Leafs/Leafs Palmate.mat.meta +8 -0
  150. package/Samples~/ExampleTemplates/Examples/Materials/Leafs/Leafs Pine.mat +247 -0
  151. package/Samples~/ExampleTemplates/Examples/Materials/Leafs/Leafs Pine.mat.meta +8 -0
  152. package/Samples~/ExampleTemplates/Examples/Materials/Leafs/Leafs Poplar.mat +223 -0
  153. package/Samples~/ExampleTemplates/Examples/Materials/Leafs/Leafs Poplar.mat.meta +8 -0
  154. package/Samples~/ExampleTemplates/Examples/Materials/Leafs/Leafs Serrate Outline.mat +262 -0
  155. package/Samples~/ExampleTemplates/Examples/Materials/Leafs/Leafs Serrate Outline.mat.meta +8 -0
  156. package/Samples~/ExampleTemplates/Examples/Materials/Leafs/Leafs Serrate.mat +281 -0
  157. package/Samples~/ExampleTemplates/Examples/Materials/Leafs/Leafs Serrate.mat.meta +8 -0
  158. package/Samples~/ExampleTemplates/Examples/Materials/Leafs/Leafs Stone Pine.mat +267 -0
  159. package/Samples~/ExampleTemplates/Examples/Materials/Leafs/Leafs Stone Pine.mat.meta +8 -0
  160. package/Samples~/ExampleTemplates/Examples/Materials/Leafs/Leafs Willow.mat +236 -0
  161. package/Samples~/ExampleTemplates/Examples/Materials/Leafs/Leafs Willow.mat.meta +8 -0
  162. package/Samples~/ExampleTemplates/Examples/Materials/Leafs.meta +8 -0
  163. package/Samples~/ExampleTemplates/Examples/Materials.meta +8 -0
  164. package/Samples~/ExampleTemplates/Examples/Oak.asset +364 -0
  165. package/Samples~/ExampleTemplates/Examples/Oak.asset.meta +8 -0
  166. package/Samples~/ExampleTemplates/Examples/Old Oak.asset +364 -0
  167. package/Samples~/ExampleTemplates/Examples/Old Oak.asset.meta +8 -0
  168. package/Samples~/ExampleTemplates/Examples/Palm.asset +500 -0
  169. package/Samples~/ExampleTemplates/Examples/Palm.asset.meta +8 -0
  170. package/Samples~/ExampleTemplates/Examples/Pine 2.asset +387 -0
  171. package/Samples~/ExampleTemplates/Examples/Pine 2.asset.meta +8 -0
  172. package/Samples~/ExampleTemplates/Examples/Pine.asset +405 -0
  173. package/Samples~/ExampleTemplates/Examples/Pine.asset.meta +8 -0
  174. package/Samples~/ExampleTemplates/Examples/Ponderossa Pine.asset +478 -0
  175. package/Samples~/ExampleTemplates/Examples/Ponderossa Pine.asset.meta +8 -0
  176. package/Samples~/ExampleTemplates/Examples/Poplar.asset +309 -0
  177. package/Samples~/ExampleTemplates/Examples/Poplar.asset.meta +8 -0
  178. package/Samples~/ExampleTemplates/Examples/ReflectionProbe-0.exr +0 -0
  179. package/Samples~/ExampleTemplates/Examples/ReflectionProbe-0.exr.meta +117 -0
  180. package/Samples~/ExampleTemplates/Examples/Small Pine.asset +273 -0
  181. package/Samples~/ExampleTemplates/Examples/Small Pine.asset.meta +8 -0
  182. package/Samples~/ExampleTemplates/Examples/Small Tree.asset +364 -0
  183. package/Samples~/ExampleTemplates/Examples/Small Tree.asset.meta +8 -0
  184. package/Samples~/ExampleTemplates/Examples/Textures/Bark/Bark_Birch_C.png +0 -0
  185. package/Samples~/ExampleTemplates/Examples/Textures/Bark/Bark_Birch_C.png.meta +74 -0
  186. package/Samples~/ExampleTemplates/Examples/Textures/Bark/Bark_Birch_N.png +0 -0
  187. package/Samples~/ExampleTemplates/Examples/Textures/Bark/Bark_Birch_N.png.meta +96 -0
  188. package/Samples~/ExampleTemplates/Examples/Textures/Bark/Bark_Damaged_C.png +0 -0
  189. package/Samples~/ExampleTemplates/Examples/Textures/Bark/Bark_Damaged_C.png.meta +116 -0
  190. package/Samples~/ExampleTemplates/Examples/Textures/Bark/Bark_Damaged_N.png +0 -0
  191. package/Samples~/ExampleTemplates/Examples/Textures/Bark/Bark_Damaged_N.png.meta +116 -0
  192. package/Samples~/ExampleTemplates/Examples/Textures/Bark/Bark_Decidious_1_C.png +0 -0
  193. package/Samples~/ExampleTemplates/Examples/Textures/Bark/Bark_Decidious_1_C.png.meta +132 -0
  194. package/Samples~/ExampleTemplates/Examples/Textures/Bark/Bark_Decidious_1_N.png +0 -0
  195. package/Samples~/ExampleTemplates/Examples/Textures/Bark/Bark_Decidious_1_N.png.meta +116 -0
  196. package/Samples~/ExampleTemplates/Examples/Textures/Bark/Bark_Decidious_2_C.png +0 -0
  197. package/Samples~/ExampleTemplates/Examples/Textures/Bark/Bark_Decidious_2_C.png.meta +132 -0
  198. package/Samples~/ExampleTemplates/Examples/Textures/Bark/Bark_Decidious_3_C.png +0 -0
  199. package/Samples~/ExampleTemplates/Examples/Textures/Bark/Bark_Decidious_3_C.png.meta +132 -0
  200. package/Samples~/ExampleTemplates/Examples/Textures/Bark/Bark_Decidious_3_N.png +0 -0
  201. package/Samples~/ExampleTemplates/Examples/Textures/Bark/Bark_Decidious_3_N.png.meta +116 -0
  202. package/Samples~/ExampleTemplates/Examples/Textures/Bark/Bark_Decidious_4_C.png +0 -0
  203. package/Samples~/ExampleTemplates/Examples/Textures/Bark/Bark_Decidious_4_C.png.meta +132 -0
  204. package/Samples~/ExampleTemplates/Examples/Textures/Bark/Bark_Decidious_4_N.png +0 -0
  205. package/Samples~/ExampleTemplates/Examples/Textures/Bark/Bark_Decidious_4_N.png.meta +116 -0
  206. package/Samples~/ExampleTemplates/Examples/Textures/Bark/Bark_Oak_C.png +0 -0
  207. package/Samples~/ExampleTemplates/Examples/Textures/Bark/Bark_Oak_C.png.meta +74 -0
  208. package/Samples~/ExampleTemplates/Examples/Textures/Bark/Bark_Oak_N.png +0 -0
  209. package/Samples~/ExampleTemplates/Examples/Textures/Bark/Bark_Oak_N.png.meta +96 -0
  210. package/Samples~/ExampleTemplates/Examples/Textures/Bark/Bark_Palm_C.png +0 -0
  211. package/Samples~/ExampleTemplates/Examples/Textures/Bark/Bark_Palm_C.png.meta +74 -0
  212. package/Samples~/ExampleTemplates/Examples/Textures/Bark/Bark_Palm_N.bmp +0 -0
  213. package/Samples~/ExampleTemplates/Examples/Textures/Bark/Bark_Palm_N.bmp.meta +96 -0
  214. package/Samples~/ExampleTemplates/Examples/Textures/Bark/Bark_Pine_C.png +0 -0
  215. package/Samples~/ExampleTemplates/Examples/Textures/Bark/Bark_Pine_C.png.meta +74 -0
  216. package/Samples~/ExampleTemplates/Examples/Textures/Bark/Bark_Pine_N.png +0 -0
  217. package/Samples~/ExampleTemplates/Examples/Textures/Bark/Bark_Pine_N.png.meta +96 -0
  218. package/Samples~/ExampleTemplates/Examples/Textures/Bark.meta +8 -0
  219. package/Samples~/ExampleTemplates/Examples/Textures/Branch/Branch Serrate_C.png +0 -0
  220. package/Samples~/ExampleTemplates/Examples/Textures/Branch/Branch Serrate_C.png.meta +96 -0
  221. package/Samples~/ExampleTemplates/Examples/Textures/Branch/Branch Serrate_N.png +0 -0
  222. package/Samples~/ExampleTemplates/Examples/Textures/Branch/Branch Serrate_N.png.meta +96 -0
  223. package/Samples~/ExampleTemplates/Examples/Textures/Branch/Branch_Needles_C.png +0 -0
  224. package/Samples~/ExampleTemplates/Examples/Textures/Branch/Branch_Needles_C.png.meta +99 -0
  225. package/Samples~/ExampleTemplates/Examples/Textures/Branch/Branch_Needles_N.png +0 -0
  226. package/Samples~/ExampleTemplates/Examples/Textures/Branch/Branch_Needles_N.png.meta +96 -0
  227. package/Samples~/ExampleTemplates/Examples/Textures/Branch/Branch_Palmate_C.png +0 -0
  228. package/Samples~/ExampleTemplates/Examples/Textures/Branch/Branch_Palmate_C.png.meta +99 -0
  229. package/Samples~/ExampleTemplates/Examples/Textures/Branch/Branch_Palmate_N.png +0 -0
  230. package/Samples~/ExampleTemplates/Examples/Textures/Branch/Branch_Palmate_N.png.meta +96 -0
  231. package/Samples~/ExampleTemplates/Examples/Textures/Branch/Branch_Pine_1_C.png +0 -0
  232. package/Samples~/ExampleTemplates/Examples/Textures/Branch/Branch_Pine_1_C.png.meta +88 -0
  233. package/Samples~/ExampleTemplates/Examples/Textures/Branch/Branch_Pine_1_N.png +0 -0
  234. package/Samples~/ExampleTemplates/Examples/Textures/Branch/Branch_Pine_1_N.png.meta +96 -0
  235. package/Samples~/ExampleTemplates/Examples/Textures/Branch/Branch_Pine_2_C.png +0 -0
  236. package/Samples~/ExampleTemplates/Examples/Textures/Branch/Branch_Pine_2_C.png.meta +96 -0
  237. package/Samples~/ExampleTemplates/Examples/Textures/Branch/Branch_Pine_2_N.png +0 -0
  238. package/Samples~/ExampleTemplates/Examples/Textures/Branch/Branch_Pine_2_N.png.meta +96 -0
  239. package/Samples~/ExampleTemplates/Examples/Textures/Branch/Branch_Poplar_C.png +0 -0
  240. package/Samples~/ExampleTemplates/Examples/Textures/Branch/Branch_Poplar_C.png.meta +96 -0
  241. package/Samples~/ExampleTemplates/Examples/Textures/Branch/Branch_Poplar_N.png +0 -0
  242. package/Samples~/ExampleTemplates/Examples/Textures/Branch/Branch_Poplar_N.png.meta +96 -0
  243. package/Samples~/ExampleTemplates/Examples/Textures/Branch.meta +8 -0
  244. package/Samples~/ExampleTemplates/Examples/Textures/Color Ramp/Ramp_PSD.psd +0 -0
  245. package/Samples~/ExampleTemplates/Examples/Textures/Color Ramp/Ramp_PSD.psd.meta +76 -0
  246. package/Samples~/ExampleTemplates/Examples/Textures/Color Ramp/Ramp_Toon.png +0 -0
  247. package/Samples~/ExampleTemplates/Examples/Textures/Color Ramp/Ramp_Toon.png.meta +76 -0
  248. package/Samples~/ExampleTemplates/Examples/Textures/Color Ramp.meta +8 -0
  249. package/Samples~/ExampleTemplates/Examples/Textures/Single Leafs/Leaf_Fern_C.png +0 -0
  250. package/Samples~/ExampleTemplates/Examples/Textures/Single Leafs/Leaf_Fern_C.png.meta +99 -0
  251. package/Samples~/ExampleTemplates/Examples/Textures/Single Leafs/Leaf_Fern_N.png +0 -0
  252. package/Samples~/ExampleTemplates/Examples/Textures/Single Leafs/Leaf_Fern_N.png.meta +88 -0
  253. package/Samples~/ExampleTemplates/Examples/Textures/Single Leafs/Leaf_Palm_C.png +0 -0
  254. package/Samples~/ExampleTemplates/Examples/Textures/Single Leafs/Leaf_Palm_C.png.meta +88 -0
  255. package/Samples~/ExampleTemplates/Examples/Textures/Single Leafs/Leaf_Palm_N.png +0 -0
  256. package/Samples~/ExampleTemplates/Examples/Textures/Single Leafs/Leaf_Palm_N.png.meta +88 -0
  257. package/Samples~/ExampleTemplates/Examples/Textures/Single Leafs/Leaf_Willow_C.png +0 -0
  258. package/Samples~/ExampleTemplates/Examples/Textures/Single Leafs/Leaf_Willow_C.png.meta +99 -0
  259. package/Samples~/ExampleTemplates/Examples/Textures/Single Leafs/Leaf_Willow_N.png +0 -0
  260. package/Samples~/ExampleTemplates/Examples/Textures/Single Leafs/Leaf_Willow_N.png.meta +88 -0
  261. package/Samples~/ExampleTemplates/Examples/Textures/Single Leafs/Single_Serrated_C.png +0 -0
  262. package/Samples~/ExampleTemplates/Examples/Textures/Single Leafs/Single_Serrated_C.png.meta +96 -0
  263. package/Samples~/ExampleTemplates/Examples/Textures/Single Leafs/Single_Serrated_N.png +0 -0
  264. package/Samples~/ExampleTemplates/Examples/Textures/Single Leafs/Single_Serrated_N.png.meta +96 -0
  265. package/Samples~/ExampleTemplates/Examples/Textures/Single Leafs.meta +8 -0
  266. package/Samples~/ExampleTemplates/Examples/Textures.meta +8 -0
  267. package/Samples~/ExampleTemplates/Examples/Willow.asset +364 -0
  268. package/Samples~/ExampleTemplates/Examples/Willow.asset.meta +8 -0
  269. package/Samples~/ExampleTemplates/Examples.meta +8 -0
  270. package/Samples~/ExampleTemplates/Examples.unity +12660 -0
  271. package/Samples~/ExampleTemplates/Examples.unity.meta +7 -0
  272. package/Samples~/ExampleTemplates.meta +8 -0
  273. package/Shaders/BarkShader.shadergraph +17215 -0
  274. package/Shaders/BarkShader.shadergraph.meta +10 -0
  275. package/Shaders/Editor/BarkEditor.cs +100 -0
  276. package/Shaders/Editor/BarkEditor.cs.meta +11 -0
  277. package/Shaders/Editor/LeafEditor.cs +173 -0
  278. package/Shaders/Editor/LeafEditor.cs.meta +11 -0
  279. package/Shaders/Editor.meta +8 -0
  280. package/Shaders/LeafShader.shadergraph +34803 -0
  281. package/Shaders/LeafShader.shadergraph.meta +10 -0
  282. package/Shaders/MTree.Shaders.asmdef +3 -0
  283. package/Shaders/MTree.Shaders.asmdef.meta +7 -0
  284. package/Shaders/leafFunctions.hlsl +201 -0
  285. package/Shaders/leafFunctions.hlsl.meta +7 -0
  286. package/Shaders/vertexFunc.hlsl +55 -0
  287. package/Shaders/vertexFunc.hlsl.meta +7 -0
  288. package/Shaders.meta +8 -0
  289. package/package.json +36 -0
  290. package/package.json.meta +7 -0
@@ -0,0 +1,569 @@
1
+ using System.Collections;
2
+ using System.Collections.Generic;
3
+ using UnityEngine;
4
+
5
+ namespace Mtree
6
+ {
7
+ public class MTree
8
+ {
9
+ public List<Node> stems;
10
+ public Vector3[] verts;
11
+ public Vector3[] normals;
12
+ public Vector2[] uvs;
13
+ public int[] triangles;
14
+ public int[] leafTriangles;
15
+ public Color[] colors;
16
+ public Transform treeTransform;
17
+ public float colorMultiplier;
18
+ private Queue<LeafPoint> leafPoints;
19
+
20
+
21
+ public MTree(Transform transform)
22
+ {
23
+ stems = new List<Node>();
24
+ leafPoints = new Queue<LeafPoint>();
25
+ treeTransform = transform;
26
+ }
27
+
28
+
29
+ public void AddTrunk(Vector3 position, Vector3 direction, float length, AnimationCurve radius, float radiusMultiplier, float resolution
30
+ , float randomness, int creator, AnimationCurve rootShape, float rootRadius, float rootHeight, float RootResolutionMultiplier
31
+ , float originAttraction)
32
+ {
33
+ MtreeBezier bezier = treeTransform.GetComponent<MtreeBezier>();
34
+ float remainingLength = length;
35
+ Node extremity = new Node(position, radius.Evaluate(0) * radiusMultiplier, direction, creator, NodeType.Flare);
36
+ stems.Add(extremity);
37
+
38
+ if (!bezier || bezier && !bezier.MTreeDoBezier) {
39
+ while (remainingLength > 0)
40
+ {
41
+ float res = resolution;
42
+ NodeType type = NodeType.Trunk;
43
+ Vector3 tangent = Vector3.Cross(direction, Random.onUnitSphere);
44
+ if (length - remainingLength < rootHeight)
45
+ {
46
+ tangent /= RootResolutionMultiplier * 2;
47
+ res *= RootResolutionMultiplier;
48
+ type = NodeType.Flare;
49
+ }
50
+
51
+ float branchLength = 1f / res;
52
+ Vector3 dir = randomness * tangent + extremity.direction * (1 - randomness);
53
+ Vector3 originAttractionVector = (position - extremity.position) * originAttraction;
54
+ originAttractionVector.y = 0;
55
+ dir += originAttractionVector;
56
+ dir.Normalize();
57
+ if (remainingLength <= branchLength)
58
+ branchLength = remainingLength;
59
+ remainingLength -= branchLength;
60
+
61
+ Vector3 pos = extremity.position + dir * branchLength;
62
+ float rad = radius.Evaluate(1 - remainingLength / length) * radiusMultiplier;
63
+ //if (length - remainingLength < rootHeight)
64
+ // rad += radiusMultiplier * rootRadius * rootShape.Evaluate((length - remainingLength) / rootHeight);
65
+ Node child = new Node(pos, rad, dir, creator, type, distancToOrigin: length-remainingLength);
66
+ extremity.children.Add(child);
67
+ extremity = child;
68
+ }
69
+ }
70
+
71
+ if (bezier && bezier.MTreeDoBezier) {
72
+ length = bezier.GetLength ();
73
+ remainingLength = length;
74
+ while (remainingLength > 1f / resolution)
75
+ {
76
+ float step = 1 - (remainingLength / length);
77
+ Vector3 stepDir = bezier.GetDirection(step);
78
+ Vector3 stepPos = bezier.GetPoint(step) - treeTransform.position;
79
+
80
+ float res = resolution;
81
+ NodeType type = NodeType.Trunk;
82
+ Vector3 tangent = Vector3.Cross(direction, Random.onUnitSphere);
83
+ if (length - remainingLength < rootHeight)
84
+ {
85
+ tangent /= RootResolutionMultiplier * 2;
86
+ res *= RootResolutionMultiplier;
87
+ type = NodeType.Flare;
88
+ }
89
+
90
+ float branchLength = 1f / res;
91
+ Vector3 dir = randomness * tangent + stepDir * (1 - randomness);
92
+ Vector3 originAttractionVector = (position - stepPos) * originAttraction;
93
+ originAttractionVector.y = 0;
94
+ dir += originAttractionVector;
95
+ dir.Normalize();
96
+ if (remainingLength <= branchLength)
97
+ branchLength = remainingLength;
98
+ remainingLength -= branchLength;
99
+
100
+ Vector3 pos = stepPos + dir * branchLength;
101
+ float rad = radius.Evaluate(1 - remainingLength / length) * radiusMultiplier;
102
+ //if (length - remainingLength < rootHeight)
103
+ // rad += radiusMultiplier * rootRadius * rootShape.Evaluate((length - remainingLength) / rootHeight);
104
+ Node child = new Node(pos, rad, dir, creator, type, distancToOrigin: length-remainingLength);
105
+ extremity.children.Add(child);
106
+ extremity = child;
107
+ }
108
+ }
109
+
110
+
111
+ }
112
+
113
+ public void AddRoots(int selection, RootsFunction rootsFunction)
114
+ {
115
+ Queue<Node> candidatesParents = SelectNodes(
116
+ (Node node) =>
117
+ {
118
+ if (node.creator != selection || node.children.Count == 0)
119
+ return false;
120
+ if (node.position.y > rootsFunction.end || node.children[0].position.y < rootsFunction.start)
121
+ return false;
122
+ return true;
123
+ });
124
+
125
+
126
+ Queue<Node> candidates = new Queue<Node>();
127
+
128
+ float angleStep = 68.75f;
129
+ Vector3 tangent = Random.onUnitSphere;
130
+ float remainder = 0f;
131
+ float rootsPerMeter = rootsFunction.number / (rootsFunction.end - rootsFunction.start + .001f);
132
+ foreach (Node parent in candidatesParents)
133
+ {
134
+ float deltaHeight = Mathf.Abs(Mathf.Min(rootsFunction.end, parent.children[0].position.y) - Mathf.Max(rootsFunction.start, parent.position.y));
135
+ float targetRootsCount = deltaHeight * rootsPerMeter + remainder;
136
+ int rootsCount = (int)targetRootsCount;
137
+ remainder = targetRootsCount - rootsCount;
138
+
139
+ float startFactor = 0f;
140
+ float endFactor = 1f;
141
+ startFactor = Mathf.Clamp01((rootsFunction.start - parent.position.y) / deltaHeight);
142
+ endFactor = Mathf.Clamp01((rootsFunction.end - parent.position.y) / deltaHeight);
143
+
144
+ for (int i = 0; i < rootsCount; i++)
145
+ {
146
+ float childPosFactor = Random.Range(startFactor, endFactor);
147
+ tangent = Vector3.ProjectOnPlane(tangent, parent.direction).normalized;
148
+ tangent = Quaternion.AngleAxis(angleStep, parent.direction) * tangent;
149
+ Vector3 childDir = Vector3.Slerp(-parent.direction, tangent, rootsFunction.angle);
150
+ float childRadius = parent.radius * rootsFunction.radius * Random.Range(.5f,1f);
151
+ Vector3 childOriginPos = Vector3.Lerp(parent.position, parent.children[0].position, childPosFactor) + tangent * (parent.radius - childRadius);
152
+ Vector3 childPos = childOriginPos + childDir * .1f;
153
+
154
+ Node childOrigin = new Node(childOriginPos, childRadius, childDir, rootsFunction.id, NodeType.Branch, positionInBranch: childPosFactor);
155
+ Node child = new Node(childPos, childRadius, childDir, rootsFunction.id, NodeType.Branch, positionInBranch: 1);
156
+
157
+ childOrigin.children.Add(child);
158
+ parent.children.Add(childOrigin);
159
+ candidates.Enqueue(child);
160
+
161
+ if (candidates.Count >= rootsFunction.number)
162
+ break;
163
+ }
164
+ if (candidates.Count >= rootsFunction.number)
165
+ break;
166
+ }
167
+
168
+ foreach (Node extremity in candidates)
169
+ {
170
+ extremity.AddGrowth(rootsFunction.length);
171
+ }
172
+
173
+ float branchGrowthStep = 1 / (rootsFunction.resolution + Mathf.Epsilon);
174
+ while (candidates.Count > 0)
175
+ {
176
+ Node extremity = candidates.Dequeue();
177
+
178
+ float rad = rootsFunction.shape.Evaluate(extremity.growth.GrowthPercentage(.1f)) * extremity.growth.initialRadius;
179
+ float extremitySplitProba = rootsFunction.splitProbaCurve.Evaluate(extremity.growth.GrowthPercentage()) * rootsFunction.splitProba;
180
+ var modifiers = new Queue<System.Func<Vector3, Node, Vector3>>();
181
+ modifiers.Enqueue((dir, node) => MoveToGroundModifier(dir, node, rootsFunction.groundHeight, rootsFunction.attractionStrength));
182
+ Queue<Node> children = extremity.Grow(branchGrowthStep, extremitySplitProba, 2, rad, rootsFunction.radius, rootsFunction.angle, rootsFunction.id, rootsFunction.randomness, 0, treeTransform, 0, .7f, obstacleAvoidance:false, modifiers:modifiers);
183
+ foreach (Node child in children)
184
+ {
185
+ candidates.Enqueue(child);
186
+ }
187
+ }
188
+ }
189
+
190
+ private Vector3 MoveToGroundModifier(Vector3 dir, Node node, float groundHeight, float attractionStrength)
191
+ {
192
+ float sqrDistFromStem = node.position.x * node.position.x + node.position.z * node.position.z;
193
+ float planePosition = groundHeight - sqrDistFromStem*.2f;
194
+
195
+ dir.y *= Mathf.Lerp(.5f, 1, Mathf.Abs(node.position.y - planePosition));
196
+ dir.y += (planePosition - (node.position.y + dir.y*.3f) ) * .5f * attractionStrength;
197
+
198
+ //dir.y *= .5f;
199
+ return dir;
200
+ }
201
+
202
+ public void Grow(float length, AnimationCurve lengthCurve, float resolution, float splitProba, AnimationCurve probaCurve, float splitAngle
203
+ , int maxSplits, int selection, int creator, float randomness, AnimationCurve radius, float splitRadius, float upAttraction
204
+ , float gravityStrength, float flatten, float minRadius, bool obstacleAvoidance)
205
+ {
206
+ float maxHeight = 0;
207
+ Queue<Node> extremities = GetSelection(selection, true, ref maxHeight);
208
+ int n = extremities.Count;
209
+
210
+ for(int i=0; i<n; i++) // Update Growth information for the extremities to grow
211
+ {
212
+ Node ext = extremities.Dequeue();
213
+
214
+ float growthLength = length * lengthCurve.Evaluate(ext.position.y / maxHeight); // The length of this specific branch after growth
215
+ ext.AddGrowth(growthLength);
216
+ extremities.Enqueue(ext);
217
+ }
218
+
219
+ float branchLength = 1 / resolution;
220
+ while (extremities.Count > 0)
221
+ {
222
+ Queue<Node> newExtremities = new Queue<Node>();
223
+ while (extremities.Count > 0)
224
+ {
225
+ Node extremity = extremities.Dequeue();
226
+
227
+ float rad = radius.Evaluate(extremity.growth.GrowthPercentage(branchLength)) * extremity.growth.initialRadius;
228
+ if (rad < minRadius)
229
+ rad = minRadius;
230
+ float extremitySplitProba = probaCurve.Evaluate(extremity.growth.GrowthPercentage()) * splitProba;
231
+ Queue<Node> children = extremity.Grow(branchLength, extremitySplitProba, maxSplits, rad, splitRadius, splitAngle, creator, randomness, upAttraction, treeTransform, gravityStrength, flatten, obstacleAvoidance);
232
+ if (rad == minRadius)
233
+ continue;
234
+ foreach (Node child in children)
235
+ {
236
+ newExtremities.Enqueue(child);
237
+ }
238
+
239
+ }
240
+ extremities = newExtremities;
241
+ }
242
+ }
243
+
244
+
245
+
246
+
247
+ public void Split(int selection, int expectedNumber, float splitAngle, int creator, float splitRadius, float startLength
248
+ , float spread, float flatten)
249
+ {
250
+
251
+ Queue<Node> candidates = GetSplitCandidates(selection, startLength);
252
+ MtreeBezier bezier = treeTransform.GetComponent<MtreeBezier>(); Vector3 direction = Vector3.zero;
253
+ if(bezier && bezier.MTreeLeafDirection)
254
+ direction = bezier.s_branchdirection;
255
+
256
+ float totalLength = 0;
257
+ foreach (Node ext in candidates)
258
+ totalLength += (ext.position - ext.children[0].position).magnitude;
259
+
260
+ float splitPerMeter = expectedNumber / totalLength;
261
+
262
+ float remainder = 0f;
263
+
264
+ foreach (Node ext in candidates)
265
+ {
266
+ float distToChild = (ext.position - ext.children[0].position).magnitude;
267
+
268
+ float targetSplitNumber = distToChild * splitPerMeter + remainder;
269
+ int number = (int)targetSplitNumber;
270
+ remainder = targetSplitNumber - number;
271
+
272
+ Vector3 randomVect = Random.onUnitSphere;
273
+ if (flatten > 0)
274
+ randomVect = Vector3.Lerp(randomVect, Vector3.up, flatten).normalized * (Random.Range(0, 1) * 2 - 1);
275
+ Vector3 tangent = Vector3.Cross(randomVect, ext.direction);
276
+ Quaternion rot = Quaternion.AngleAxis(360f / number, ext.direction);
277
+ Vector3 spreadDirection = ext.children[0].direction;
278
+ for (int i = 0; i < number; i++)
279
+ {
280
+ float blend = Random.value * spread;
281
+ float rad = Mathf.Lerp(ext.radius * splitRadius, ext.children[0].radius * splitRadius, blend);
282
+ Vector3 pos = ext.position + spreadDirection * blend * distToChild;
283
+ Vector3 dir = Vector3.LerpUnclamped(ext.direction, tangent, splitAngle * (1-ext.positionInBranch*.7f)).normalized + direction;
284
+ float radiusFactor = Mathf.Clamp01(rad);
285
+ Node child0 = new Node(pos, ext.radius * radiusFactor + rad * (1-radiusFactor), dir, creator, distancToOrigin: ext.distanceFromOrigin + blend * distToChild);
286
+ child0.branchVariation = ext.branchVariation;
287
+ if (ext.type == NodeType.Trunk || ext.type == NodeType.Flare)
288
+ child0.type = NodeType.FromTrunk;
289
+ Node child1 = new Node(pos + dir * ext.radius / Mathf.Max(0.3f,Vector3.Dot(dir, tangent)) * 1f, rad, dir, creator, distancToOrigin: ext.distanceFromOrigin + blend * distToChild);
290
+ child1.branchVariation = ext.branchVariation;
291
+ child0.children.Add(child1);
292
+
293
+ child0.growth.canBeSplit = false;
294
+ ext.children.Add(child0);
295
+ tangent = rot * tangent;
296
+ }
297
+
298
+ }
299
+
300
+ }
301
+
302
+ public void TwigSplit(int expectedNumber, float splitAngle, float splitRadius, float startLength)
303
+ {
304
+ Queue<Node> candidates = GetSplitCandidates(0, startLength);
305
+
306
+ float totalLength = 0;
307
+ foreach (Node ext in candidates)
308
+ totalLength += (ext.position - ext.children[0].position).magnitude;
309
+
310
+ float splitPerMeter = expectedNumber / totalLength;
311
+
312
+ float remainder = 0f;
313
+ int side = 1;
314
+ foreach (Node ext in candidates)
315
+ {
316
+ float distToChild = (ext.position - ext.children[0].position).magnitude;
317
+ float targetSplitNumber = distToChild * splitPerMeter + remainder;
318
+ int number = (int)targetSplitNumber;
319
+ remainder = targetSplitNumber - number;
320
+
321
+
322
+ Vector3 spreadDirection = ext.children[0].direction;
323
+ for (int i = 0; i < number; i++)
324
+ {
325
+ float blend = i * 1f / number;
326
+ float rad = Mathf.Lerp(ext.radius * splitRadius, ext.children[0].radius * splitRadius, blend);
327
+ Vector3 pos = ext.position + spreadDirection * distToChild * blend;
328
+ Quaternion rot = Quaternion.AngleAxis(splitAngle * side, Vector3.up);
329
+ Vector3 dir = rot * ext.direction;
330
+ float radiusFactor = Mathf.Clamp01(rad);
331
+ Node child0 = new Node(pos, ext.radius * radiusFactor + rad * (1 - radiusFactor), dir, 1, distancToOrigin: ext.distanceFromOrigin + blend * distToChild);
332
+ child0.branchVariation = ext.branchVariation;
333
+ if (ext.type == NodeType.Trunk || ext.type == NodeType.Flare)
334
+ child0.type = NodeType.FromTrunk;
335
+ child0.growth.canBeSplit = true;
336
+ ext.children.Add(child0);
337
+ side *= -1;
338
+ }
339
+ }
340
+ }
341
+
342
+
343
+ public void AddBranches(int selection, float length, AnimationCurve lengthCurve, float resolution, int number, float splitProba, AnimationCurve splitProbaCurve
344
+ , float angle, float randomness, AnimationCurve shape, float radius, float upAttraction, int creator
345
+ , float start, float gravityStrength, float flatten, float minRadius, bool obstacleAvoidance)
346
+ {
347
+ Split(selection, number, angle, creator, radius, start, 1, flatten);
348
+ Grow(length, lengthCurve, resolution, splitProba, splitProbaCurve, .3f, 2, creator, creator, randomness, shape, .9f, upAttraction, gravityStrength, flatten, minRadius, obstacleAvoidance);
349
+ }
350
+
351
+
352
+ public void AddLeafs(float maxRadius, int number, Mesh[] mesh, float size, bool overrideNormals, float minWeight, float maxWeight, int selection,
353
+ float leafAngle, bool procedural, float length, float resolution, int uLoops, float gravityStrength)
354
+ {
355
+ Queue<LeafCandidate> candidates = new Queue<LeafCandidate>();
356
+ float totalLength = 0f;
357
+ foreach (Node stem in stems)
358
+ stem.GetLeafCandidates(candidates, maxRadius * stem.radius, ref totalLength, selection);
359
+ if (number < 1)
360
+ number = 2;
361
+ if (number > candidates.Count)
362
+ {
363
+ ExtendLeafCandidates(candidates, number);
364
+ }
365
+
366
+ LeafCandidate[] leafSpawners = Sample(candidates.ToArray(), number);
367
+ foreach (LeafCandidate spawner in leafSpawners)
368
+ {
369
+
370
+ Vector3 direction = spawner.direction;
371
+ direction.y /= 3;
372
+ Vector3 dir = Vector3.LerpUnclamped(direction, Vector3.down, Random.Range(minWeight, maxWeight));
373
+ Quaternion rot = Quaternion.Euler(0, Random.Range(-leafAngle, leafAngle), 0);
374
+ dir = rot * dir;
375
+ leafPoints.Enqueue(new LeafPoint(spawner.position, dir, spawner.size * size, mesh, overrideNormals, spawner.distanceFromOrigin, length, uLoops, resolution, procedural, gravityStrength));
376
+ }
377
+ }
378
+
379
+ void ExtendLeafCandidates(Queue<LeafCandidate> candidates, int number)
380
+ {
381
+ LeafCandidate[] candidateArray = candidates.ToArray();
382
+ int dupliNumber = 0;
383
+ int candidatesNotAtEnd = 0;
384
+ foreach (LeafCandidate l in candidateArray)
385
+ {
386
+ if (!l.isEnd)
387
+ candidatesNotAtEnd++;
388
+ }
389
+ dupliNumber = candidatesNotAtEnd == 0 ? 0 : number / candidatesNotAtEnd;
390
+
391
+ foreach (LeafCandidate candidate in candidateArray)
392
+ {
393
+ //if (candidate.isEnd)
394
+ // continue;
395
+ for (int i=0; i<dupliNumber; i++)
396
+ {
397
+ Vector3 position = candidate.position + candidate.direction * candidate.parentBranchLength * (i + 1) / (dupliNumber + 1);
398
+ //position = Vector3.zero;
399
+ candidates.Enqueue(new LeafCandidate(position, candidate.direction, candidate.size, candidate.parentBranchLength, candidate.distanceFromOrigin, candidate.isEnd));
400
+ }
401
+ }
402
+ }
403
+
404
+
405
+ LeafCandidate[] Sample(LeafCandidate[] candidates, int number)
406
+ {
407
+ number = Mathf.Min(candidates.Length, number);
408
+ LeafCandidate[] result = new LeafCandidate[number];
409
+ for (int i=0; i<number; i++)
410
+ {
411
+ int index = Random.Range(i, candidates.Length - 1);
412
+ result[i] = candidates[index];
413
+ candidates[index] = candidates[i];
414
+ }
415
+
416
+ return result;
417
+ }
418
+
419
+ private Queue<Node> GetSelection(int selection, bool extremitiesOnly, ref float maxHeight)
420
+ {
421
+ Queue<Node> selected = new Queue<Node>();
422
+ foreach (Node stem in stems)
423
+ {
424
+ stem.GetSelection(selected, selection, extremitiesOnly, ref maxHeight);
425
+ }
426
+ return selected;
427
+ }
428
+
429
+
430
+ private Queue<Node> GetSplitCandidates(int selection, float start)
431
+ {
432
+ Queue<Node> selected = new Queue<Node>();
433
+ foreach (Node stem in stems)
434
+ {
435
+ stem.branchVariation = Random.Range(0, 1f);
436
+ stem.UpdatePositionInBranch();
437
+ stem.GetSplitCandidates(selected, selection, start, start);
438
+ }
439
+ return selected;
440
+ }
441
+
442
+
443
+ private Queue<Node> SelectNodes(System.Func<Node, bool> filter)
444
+ {
445
+ Queue<Node> selection = new Queue<Node>();
446
+ foreach (Node stem in stems)
447
+ {
448
+ SelectNodesRec(stem, ref selection, filter);
449
+ }
450
+ return selection;
451
+ }
452
+
453
+ private void SelectNodesRec(Node node, ref Queue<Node> selection, System.Func<Node, bool> filter)
454
+ {
455
+ if (filter(node))
456
+ {
457
+ selection.Enqueue(node);
458
+ }
459
+ foreach (Node child in node.children)
460
+ {
461
+ SelectNodesRec(child, ref selection, filter);
462
+ }
463
+ }
464
+
465
+ public void Simplify(float angleThreshold, float radiusTreshold)
466
+ {
467
+ foreach(Node stem in stems)
468
+ {
469
+ stem.Simplify(null, angleThreshold, radiusTreshold);
470
+ }
471
+ }
472
+
473
+
474
+ public void GenerateMeshData(TrunkFunction trunk, float simplifyLeafs, float radialResolution,float VColBarkModifier,float VColLeafModifier)
475
+ {
476
+ Stack<Queue<TreePoint>> treePoints = new Stack<Queue<TreePoint>>();
477
+ foreach (Node stem in stems)
478
+ {
479
+ Stack<Queue<TreePoint>> newPoints = stem.ToSplines();
480
+ while (newPoints.Count > 0)
481
+ {
482
+ treePoints.Push(newPoints.Pop());
483
+ }
484
+ }
485
+ Splines splines = new Splines(treePoints);
486
+ splines.GenerateMeshData(7 * radialResolution, 3, trunk.rootShape, trunk.radiusMultiplier, trunk.rootRadius, trunk.rootInnerRadius, trunk.rootHeight, trunk.rootResolution
487
+ , trunk.flareNumber, trunk.displacementStrength, trunk.displacementSize, trunk.spinAmount,VColBarkModifier);
488
+
489
+
490
+ Queue<int> leafTriangles = new Queue<int>();
491
+ GenerateLeafData(splines.verts, splines.normals, splines.uvs, leafTriangles, splines.verts.Count, splines.colors, simplifyLeafs,VColBarkModifier,VColLeafModifier);
492
+ verts = splines.verts.ToArray();
493
+ normals = splines.normals.ToArray();
494
+ uvs = splines.uvs.ToArray();
495
+ triangles = splines.triangles.ToArray();
496
+ colors = splines.colors.ToArray();
497
+ this.leafTriangles = leafTriangles.ToArray();
498
+ }
499
+
500
+
501
+ public void GenerateLeafData(Queue<Vector3> leafVerts, Queue<Vector3> leafNormals, Queue<Vector2> leafUvs, Queue<int> leafTriangles, int vertexOffset, Queue<Color> colors,
502
+ float simplify,float VColBarkModifier,float VColLeafModifier)
503
+ {
504
+ foreach(LeafPoint l in leafPoints)
505
+ {
506
+ Mesh leafMesh = l.GetMesh(simplify > .1f ? 1 : 0);
507
+ if (leafMesh == null || Random.value < simplify) // don't create the leaf when no object is available or when simplifying
508
+ continue;
509
+
510
+ int n = leafMesh.vertexCount;
511
+ Quaternion rot = Quaternion.FromToRotation(Vector3.forward, l.direction);
512
+ rot = Quaternion.LookRotation(l.direction);
513
+ float randomWindPhase = Random.value; // used is wind shader to randomise vertex displacement phase
514
+ float maxDistance = 0f;
515
+ float minDistance = Mathf.Infinity;
516
+ float[] distances = new float[n];
517
+ for (int i = 0; i < n; i++) // iterating over leaf object vertices
518
+ {
519
+ Vector3 vert = leafMesh.vertices[i];
520
+ Vector3 normal = leafMesh.normals[i];
521
+ if (!l.procedural)
522
+ {
523
+ normal = rot * normal;
524
+ vert = rot * vert * l.size * (1 + simplify * .5f) + l.position;
525
+ }
526
+ leafVerts.Enqueue(vert);
527
+ if (l.overrideNormals)
528
+ {
529
+ leafNormals.Enqueue(l.position.normalized);
530
+ }
531
+ else
532
+ {
533
+ leafNormals.Enqueue(normal);
534
+ }
535
+ leafUvs.Enqueue(leafMesh.uv[i]);
536
+ float distance = Vector3.Distance(l.position, vert);
537
+ maxDistance = Mathf.Max(maxDistance, distance);
538
+ minDistance = Mathf.Min(minDistance, distance);
539
+ distances[i] = distance;
540
+ }
541
+ for (int i=0; i<n; i++)
542
+ {
543
+
544
+ float blueChannel = (distances[i] - minDistance);
545
+ colors.Enqueue(new Color((l.distanceFromOrigin/10) * VColBarkModifier, randomWindPhase , blueChannel * VColLeafModifier));
546
+ }
547
+ int m = leafMesh.triangles.Length;
548
+ for (int i = 0; i < m; i++) // creating the triangles
549
+ {
550
+ leafTriangles.Enqueue(leafMesh.triangles[i] + vertexOffset);
551
+ }
552
+ vertexOffset += n; // used when creating submeshes for the mesh component
553
+
554
+ }
555
+ }
556
+
557
+
558
+ public List<Vector3> DebugPositions()
559
+ {
560
+ List<Vector3> positions = new List<Vector3>();
561
+ foreach(Node stem in stems)
562
+ {
563
+ stem.DebugPosRec(positions);
564
+ }
565
+ return positions;
566
+ }
567
+ }
568
+
569
+ }
@@ -0,0 +1,11 @@
1
+ fileFormatVersion: 2
2
+ guid: 18050f45cb79ca04192c5fd42e706a5b
3
+ MonoImporter:
4
+ externalObjects: {}
5
+ serializedVersion: 2
6
+ defaultReferences: []
7
+ executionOrder: 0
8
+ icon: {instanceID: 0}
9
+ userData:
10
+ assetBundleName:
11
+ assetBundleVariant: