diff --git a/Assets/Scenes/Ecosystem Simulation.unity b/Assets/Scenes/Ecosystem Simulation.unity index 64bbef5..5f11f96 100644 --- a/Assets/Scenes/Ecosystem Simulation.unity +++ b/Assets/Scenes/Ecosystem Simulation.unity @@ -11737,7 +11737,7 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 0013169faf7e2a24483f14d4dcd2611c, type: 3} m_Name: m_EditorClassIdentifier: - OverallSize: {x: 500, y: 500} + OverallSize: {x: 1000, y: 1000} Levels: - {fileID: 11400000, guid: 36751346e59f29e409b3874b0603be45, type: 2} - {fileID: 11400000, guid: a8156ca0bf27694458adbefdae0a24e1, type: 2} @@ -21772,15 +21772,15 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 985569e64189cbb469fd53f9e3b46c55, type: 3} m_Name: m_EditorClassIdentifier: - RandomTreeCountPerTick: 5 - RandomTickRate: 0.8 + RandomTreeCountPerTick: 10 + RandomTickRate: 1 CollectInitialChildTrees: 0 GenerateInitialTrees: 1 - InitialTreeCount: 100 + InitialTreeCount: 100000 InitialTreeGenerationBounds: m_Center: {x: 250, y: 10, z: 250} - m_Extent: {x: 250, y: 10, z: 250} - TestTreePrefab: {fileID: 2512629738840422531, guid: 0baa68192c27f434cb5441f33316dd05, type: 3} + m_Extent: {x: 240, y: 10, z: 240} + TestTreePrefab: {fileID: 2512629738840422531, guid: d649c620bb06319498b81b2c40f5c39b, type: 3} TestParameters: StemSize: 0.3 BranchSize: 0.1 @@ -21792,8 +21792,8 @@ MonoBehaviour: BranchAngle: 30 RadialBias: 0.2 AngleRandomness: 0.5 - GenerateBranchMesh: 1 - GenerateLeafMesh: 1 + GenerateBranchMesh: 0 + GenerateLeafMesh: 0 GenerateLeafColliders: 0 GenerateBranchColliders: 0 GrowThreshold: 60 @@ -21816,6 +21816,9 @@ MonoBehaviour: MaxBranchesPerNode: 3 PrunePercentage: 0.06 Seed: 0 + averageAge: 0 + averageAgeNonzero: 0 + maxAge: 0 --- !u!1 &545314996 GameObject: m_ObjectHideFlags: 0 @@ -23172,6 +23175,7 @@ MonoBehaviour: BeginTickTime: 0 TickTime: 0 EndTickTime: 0 + TotalTickTime: 0 --- !u!1 &583718243 GameObject: m_ObjectHideFlags: 0 diff --git a/Assets/TreeGrowth/Prefabs/Test Tree No Render.prefab b/Assets/TreeGrowth/Prefabs/Test Tree No Render.prefab new file mode 100644 index 0000000..490247c --- /dev/null +++ b/Assets/TreeGrowth/Prefabs/Test Tree No Render.prefab @@ -0,0 +1,86 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!1 &2512629738840422531 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 2512629738840422528} + - component: {fileID: 2512629738840422529} + m_Layer: 0 + m_Name: Test Tree No Render + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!4 &2512629738840422528 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 2512629738840422531} + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: 0, y: 0, z: 0} + m_LocalScale: {x: 1, y: 1, z: 1} + m_ConstrainProportionsScale: 0 + m_Children: [] + m_Father: {fileID: 0} + m_RootOrder: 0 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!114 &2512629738840422529 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 2512629738840422531} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: a04f9774aff229d4b80e003dea33c843, type: 3} + m_Name: + m_EditorClassIdentifier: + parameters: + StemSize: 0.3 + BranchSize: 0.1 + SizeFalloff: 0.9 + BranchLength: 2 + TrunkLength: 2 + TrunkThreshold: 0.2 + BranchLengthFalloff: 0.9 + BranchAngle: 30 + RadialBias: 0.2 + AngleRandomness: 0.5 + GenerateBranchMesh: 0 + GenerateLeafMesh: 0 + GenerateLeafColliders: 0 + GenerateBranchColliders: 0 + GrowThreshold: 60 + PruneThreshold: 40 + ReproduceThreshold: 80 + ReproduceAge: 70 + ReproduceAmount: 1 + GroundLayerMask: + serializedVersion: 2 + m_Bits: 0 + QuadsPerLeaf: 16 + LeafQuadRadius: 1.5 + LeafColliderSize: 0.2 + MeshSubdivisions: 5 + BranchColliderDepth: 6 + MutationAmount: 0.1 + MutationRate: 0.1 + Iterations: 100 + BatchSize: 5 + MaxBranchesPerNode: 3 + PrunePercentage: 0.06 + Seed: 0 + Iteration: 0 + ColorSchemes: [] + BranchColliders: {fileID: 0} + LeafColliders: {fileID: 0} + RayCastCount: 1 diff --git a/Assets/TreeGrowth/Prefabs/Test Tree No Render.prefab.meta b/Assets/TreeGrowth/Prefabs/Test Tree No Render.prefab.meta new file mode 100644 index 0000000..e051f96 --- /dev/null +++ b/Assets/TreeGrowth/Prefabs/Test Tree No Render.prefab.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: d649c620bb06319498b81b2c40f5c39b +PrefabImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/TreeGrowth/Prefabs/Test Tree.prefab b/Assets/TreeGrowth/Prefabs/Test Tree.prefab index 9e83c03..e5606be 100644 --- a/Assets/TreeGrowth/Prefabs/Test Tree.prefab +++ b/Assets/TreeGrowth/Prefabs/Test Tree.prefab @@ -30,8 +30,7 @@ Transform: m_LocalPosition: {x: 0, y: 0, z: 0} m_LocalScale: {x: 1, y: 1, z: 1} m_ConstrainProportionsScale: 0 - m_Children: - - {fileID: 2512629739063952857} + m_Children: [] m_Father: {fileID: 0} m_RootOrder: 0 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} @@ -103,18 +102,31 @@ MonoBehaviour: BranchSize: 0.1 SizeFalloff: 0.9 BranchLength: 2 + TrunkLength: 2 + TrunkThreshold: 0.2 BranchLengthFalloff: 0.9 BranchAngle: 30 + RadialBias: 0.2 AngleRandomness: 0.5 GenerateBranchMesh: 1 GenerateLeafMesh: 1 GenerateLeafColliders: 0 GenerateBranchColliders: 0 + GrowThreshold: 60 + PruneThreshold: 40 + ReproduceThreshold: 80 + ReproduceAge: 70 + ReproduceAmount: 1 + GroundLayerMask: + serializedVersion: 2 + m_Bits: 0 QuadsPerLeaf: 16 LeafQuadRadius: 1.5 LeafColliderSize: 0.2 MeshSubdivisions: 5 BranchColliderDepth: 6 + MutationAmount: 0.1 + MutationRate: 0.1 Iterations: 100 BatchSize: 5 MaxBranchesPerNode: 3 @@ -123,36 +135,5 @@ MonoBehaviour: Iteration: 0 ColorSchemes: [] BranchColliders: {fileID: 0} - LeafColliders: {fileID: 2512629739063952856} + LeafColliders: {fileID: 0} RayCastCount: 1 ---- !u!1 &2512629739063952856 -GameObject: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - serializedVersion: 6 - m_Component: - - component: {fileID: 2512629739063952857} - m_Layer: 0 - m_Name: Leaf Colliders - m_TagString: Untagged - m_Icon: {fileID: 0} - m_NavMeshLayer: 0 - m_StaticEditorFlags: 0 - m_IsActive: 1 ---- !u!4 &2512629739063952857 -Transform: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 2512629739063952856} - m_LocalRotation: {x: -0, y: -0, z: -0, w: 1} - m_LocalPosition: {x: 0, y: 0, z: 0} - m_LocalScale: {x: 1, y: 1, z: 1} - m_ConstrainProportionsScale: 0 - m_Children: [] - m_Father: {fileID: 2512629738840422528} - m_RootOrder: 0 - m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} diff --git a/Assets/TreeGrowth/Scripts/Generation/TreeGenerator.cs b/Assets/TreeGrowth/Scripts/Generation/TreeGenerator.cs index 28bb184..d31814c 100644 --- a/Assets/TreeGrowth/Scripts/Generation/TreeGenerator.cs +++ b/Assets/TreeGrowth/Scripts/Generation/TreeGenerator.cs @@ -5,8 +5,8 @@ namespace TreeGrowth.Generation { - [RequireComponent(typeof(MeshRenderer))] - [RequireComponent(typeof(MeshFilter))] + // [RequireComponent(typeof(MeshRenderer))] + // [RequireComponent(typeof(MeshFilter))] public class TreeGenerator : MonoBehaviour { #region Public @@ -24,14 +24,14 @@ public class TreeGenerator : MonoBehaviour #region Private private MeshFilter meshFilter; - private MeshRenderer meshRenderer; + // private MeshRenderer meshRenderer; private Node Root; #endregion public void Awake() { - this.meshFilter = this.GetComponent(); - this.meshRenderer = this.GetComponent(); + if (this.parameters.GenerateBranchMesh || this.parameters.GenerateLeafMesh) + this.meshFilter = this.GetComponent(); this.Reset(); } @@ -44,7 +44,8 @@ public void Reset() this.Iteration = 0; this.recalculateEnergy(); - this.meshFilter.sharedMesh = null; + if (this.parameters.GenerateBranchMesh || this.parameters.GenerateLeafMesh) + this.meshFilter.sharedMesh = null; if (this.parameters.GenerateBranchColliders) { @@ -420,7 +421,7 @@ private void generateColor() { if (item.Probability > roll) { - this.meshRenderer.materials[1].color = item.GetColor(); + // this.meshRenderer.materials[1].color = item.GetColor(); return; } else @@ -442,7 +443,7 @@ private void recalculateEnergy() } } - public float Age() + public int Age() { return this.Iteration; // map(0, this.parameters.Iterations, 0, 1, this.Iteration); } @@ -512,7 +513,10 @@ private static float map(float inLower, float inUpper, float outLower, float out public Mesh GetMesh() { - return this.meshFilter.mesh; + if (this.meshFilter == null) + return null; + else + return this.meshFilter.mesh; } } } \ No newline at end of file diff --git a/Assets/TreeGrowth/Scripts/TreeManager.cs b/Assets/TreeGrowth/Scripts/TreeManager.cs index 7ba4fc3..c00cac4 100644 --- a/Assets/TreeGrowth/Scripts/TreeManager.cs +++ b/Assets/TreeGrowth/Scripts/TreeManager.cs @@ -1,13 +1,13 @@ -using System.Diagnostics; -using System.Linq; using System; using System.Collections; using System.Collections.Generic; +using System.Diagnostics; +using System.Linq; using Managers.Interfaces; using SimDataStructure.Data; using SimDataStructure.Interfaces; -using UnityEngine; using TreeGrowth.Generation; +using UnityEngine; namespace TreeGrowth { @@ -100,8 +100,36 @@ public void Tick(float deltaTime) tickTrees(); } + public float averageAge = 0; + public float averageAgeNonzero = 0; + public int maxAge = 0; + public void EndTick(float deltaTime) { + averageAge = 0; + averageAgeNonzero = 0; + maxAge = int.MinValue; + + int notZeroCount = 0; + + foreach (TreeCellData tree in trees) + { + int age = tree.Generator.Age(); + + if (age != 0) + { + averageAgeNonzero += age; + notZeroCount++; + } + + if (age > maxAge) + maxAge = age; + + averageAge += age; + } + + averageAge = averageAge / trees.Count; + averageAgeNonzero = averageAgeNonzero / notZeroCount; } // private void Update() @@ -244,14 +272,14 @@ private void tickTrees() // continue; // } - if (tree.Hydration < tree.TreeParameters.PruneThreshold) - tree.Generator.Prune(tree.TreeParameters.PrunePercentage); + // if (tree.Hydration < tree.TreeParameters.PruneThreshold) + // tree.Generator.Prune(tree.TreeParameters.PrunePercentage); - if (tree.Hydration > tree.TreeParameters.GrowThreshold) - tree.Generator.IterateGrowth(tree.TreeParameters); + // if (tree.Hydration > tree.TreeParameters.GrowThreshold) + tree.Generator.IterateGrowth(tree.TreeParameters); - if (tree.Hydration > tree.TreeParameters.ReproduceThreshold && tree.Generator.Age() > tree.TreeParameters.ReproduceAge) - reproduceTree(tree); + // if (tree.Hydration > tree.TreeParameters.ReproduceThreshold && tree.Generator.Age() > tree.TreeParameters.ReproduceAge) + // reproduceTree(tree); float used = tree.Generator.CalculateWaterUseThisTick(); tree.Hydration -= used;