Skip to content

Commit

Permalink
Merge pull request #8 from radiatoryang/develop
Browse files Browse the repository at this point in the history
fix leaves positioning, alignment, and density
  • Loading branch information
radiatoryang authored Aug 13, 2020
2 parents a45b3fa + a114010 commit fbe9653
Show file tree
Hide file tree
Showing 18 changed files with 8 additions and 10 deletions.
14 changes: 6 additions & 8 deletions Editor/Scripts/IvyMesh.cs
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ static bool GenerateMeshData(IvyGraph ivyGraph, IvyProfile ivyProfile, bool forc
// simple multiplier, just to make it a more dense
for (int i = 0; i < 1; ++i)
{
var leafPositions = GetAllSamplePosAlongRoot( root, p.ivyLeafSize );
var leafPositions = GetAllSamplePosAlongRoot( root, p.ivyLeafSize * Mathf.Clamp(1f - p.leafSunlightBonus, 0.69f, 1f) * Mathf.Clamp(1f - p.leafProbability, 0.69f, 1f) );

// for(int n=0; n<root.nodes.Count; n++)
foreach ( var kvp in leafPositions )
Expand Down Expand Up @@ -410,28 +410,26 @@ static bool GenerateMeshData(IvyGraph ivyGraph, IvyProfile ivyProfile, bool forc
}

IvyNode previousNode = root.nodes[Mathf.Max(0, n - 1)];
float randomSpreadHack = 0.25f;
if ( n <= 1 || n == root.nodes.Count-1 ) {
randomSpreadHack = 0f;
}

// randomize leaf probability // guarantee a leaf on the first or last node
if ( (Random.value + groundedness > 1f - p.leafProbability) || randomSpreadHack == 0f )
if ( (Random.value + groundedness > 1f - p.leafProbability) || n <= 1 || n == root.nodes.Count-1 )
{
cache.leafPoints.Add( node.p );
allLeafPoints.Add( node.p );

//center of leaf quad
Vector3 up = (newLeafPos - previousNode.p).normalized;
Vector3 right = Vector3.Cross( up, node.c );
Vector3 center = newLeafPos - node.c.normalized * 0.05f + (up * Random.Range(-1f, 1f) + right * Random.Range(-1f, 1f) ) * randomSpreadHack * p.ivyLeafSize;
// Vector3 center = newLeafPos - node.c.normalized * 0.05f + (up * Random.Range(-1f, 1f) + right * Random.Range(-1f, 1f) ) * randomSpreadHack * p.ivyLeafSize;
Vector3 center = newLeafPos - node.c.normalized * 0.05f;

//size of leaf
float sizeWeight = 1.5f - ( Mathf.Abs(Mathf.Cos(2.0f * Mathf.PI)) * 0.5f + 0.5f);
float leafSize = p.ivyLeafSize * sizeWeight + Random.Range(-p.ivyLeafSize, p.ivyLeafSize) * 0.1f + (p.ivyLeafSize * groundedness);
leafSize = Mathf.Max( 0.01f, leafSize);

Quaternion facing = node.c.sqrMagnitude < 0.001f ? Quaternion.identity : Quaternion.LookRotation( Vector3.Lerp(-node.c, Vector3.up, Mathf.Clamp01(0.68f - Mathf.Abs(groundedness)) * ivyProfile.leafSunlightBonus), Random.onUnitSphere);
// Quaternion facing = node.c.sqrMagnitude < 0.001f ? Quaternion.identity : Quaternion.LookRotation( Vector3.Lerp(-node.c, Vector3.up, Mathf.Clamp01(0.68f - Mathf.Abs(groundedness)) * ivyProfile.leafSunlightBonus), Random.onUnitSphere);
Quaternion facing = node.c.sqrMagnitude < 0.001f ? Quaternion.identity : Quaternion.LookRotation( Vector3.Lerp(-node.c, Vector3.up, Mathf.Clamp01(0.68f - Mathf.Abs(groundedness)) * ivyProfile.leafSunlightBonus));
AddLeafVertex(cache, center, new Vector3(-1f, 1f, 0f), leafSize, facing);
AddLeafVertex(cache, center, new Vector3(1f, 1f, 0f), leafSize, facing);
AddLeafVertex(cache, center, new Vector3(-1f, -1f, 0f), leafSize, facing);
Expand Down
4 changes: 2 additions & 2 deletions Editor/Scripts/IvyProfileEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ public override void OnInspectorGUI () {
ivyProfile.ivyLeafSize = EditorGUILayout.Slider(content, ivyProfile.ivyLeafSize, 0.05f, 1f);

content = new GUIContent("Leaf Density %", "How many leaves on each branch. 0% means no leaves, 100% is very bushy.\n(default: 50%)");
ivyProfile.leafProbability = EditorGUILayout.IntSlider(content, Mathf.RoundToInt(ivyProfile.leafProbability * 100f), 0, 150) * 0.01f;
ivyProfile.leafProbability = EditorGUILayout.IntSlider(content, Mathf.RoundToInt(ivyProfile.leafProbability * 100f), 0, 100) * 0.01f;

if ( ivyProfile.leafProbability == 0f ) {
EditorGUILayout.HelpBox("No leaves when Leaf Density is 0%", MessageType.Warning);
Expand Down Expand Up @@ -208,7 +208,7 @@ public override void OnInspectorGUI () {
ivyProfile.branchTaper = EditorGUILayout.IntSlider(content, Mathf.RoundToInt(ivyProfile.branchTaper * 100f), 0, 100) * 0.01f;

content = new GUIContent("Leaf Sunlight %", "Approximates how ivy wants to be in the sun. Leaves will face upwards more. Ivy will grow more leaves on floors / roofs, and fewer leaves on ceilings. 0% means leaves will spawn evenly regardless of surface, and align leaves with surface.\n(default: 100%)");
ivyProfile.leafSunlightBonus = EditorGUILayout.IntSlider(content, Mathf.RoundToInt(ivyProfile.leafSunlightBonus * 100f), 0, 150) * 0.01f;
ivyProfile.leafSunlightBonus = EditorGUILayout.IntSlider(content, Mathf.RoundToInt(ivyProfile.leafSunlightBonus * 100f), 0, 100) * 0.01f;

EditorGUI.indentLevel--;
EditorGUILayout.Space();
Expand Down
Binary file modified Runtime/Materials/IvyBranchWood.mat
Binary file not shown.
Binary file modified Runtime/Textures/IvyLeafDead1_Alpha.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Runtime/Textures/IvyLeafDead1_Diffuse.tga
Binary file not shown.
Binary file modified Runtime/Textures/IvyLeafDead2_Alpha.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Runtime/Textures/IvyLeafDead2_Diffuse.tga
Binary file not shown.
Binary file modified Runtime/Textures/IvyLeafMature_Alpha.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Runtime/Textures/IvyLeafMature_Diffuse.tga
Binary file not shown.
Binary file modified Runtime/Textures/IvyLeafMature_Normal.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Runtime/Textures/IvyLeafMature_Roughness.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Runtime/Textures/IvyLeafMature_Roughness_Lighter.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Runtime/Textures/IvyLeafMature_Translucence.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Runtime/Textures/IvyLeafYoung_Alpha.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Runtime/Textures/IvyLeafYoung_Diffuse.tga
Binary file not shown.
Binary file modified Runtime/Textures/IvyLeafYoung_Height.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Runtime/Textures/IvyLeafYoung_Normal.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Runtime/Textures/IvyLeafYoung_Roughness.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit fbe9653

Please sign in to comment.