Skip to content

Commit

Permalink
changes forbtesting
Browse files Browse the repository at this point in the history
  • Loading branch information
AIP21 committed May 16, 2023
1 parent 95e8831 commit 6a85419
Show file tree
Hide file tree
Showing 6 changed files with 170 additions and 60 deletions.
20 changes: 12 additions & 8 deletions Assets/Scenes/Ecosystem Simulation.unity
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -23172,6 +23175,7 @@ MonoBehaviour:
BeginTickTime: 0
TickTime: 0
EndTickTime: 0
TotalTickTime: 0
--- !u!1 &583718243
GameObject:
m_ObjectHideFlags: 0
Expand Down
86 changes: 86 additions & 0 deletions Assets/TreeGrowth/Prefabs/Test Tree No Render.prefab
Original file line number Diff line number Diff line change
@@ -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
7 changes: 7 additions & 0 deletions Assets/TreeGrowth/Prefabs/Test Tree No Render.prefab.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

49 changes: 15 additions & 34 deletions Assets/TreeGrowth/Prefabs/Test Tree.prefab
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down Expand Up @@ -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
Expand All @@ -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}
22 changes: 13 additions & 9 deletions Assets/TreeGrowth/Scripts/Generation/TreeGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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<MeshFilter>();
this.meshRenderer = this.GetComponent<MeshRenderer>();
if (this.parameters.GenerateBranchMesh || this.parameters.GenerateLeafMesh)
this.meshFilter = this.GetComponent<MeshFilter>();

this.Reset();
}
Expand All @@ -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)
{
Expand Down Expand Up @@ -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
Expand All @@ -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);
}
Expand Down Expand Up @@ -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;
}
}
}
46 changes: 37 additions & 9 deletions Assets/TreeGrowth/Scripts/TreeManager.cs
Original file line number Diff line number Diff line change
@@ -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
{
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 6a85419

Please sign in to comment.