Skip to content

Commit

Permalink
Merge pull request #10 from radiatoryang/develop
Browse files Browse the repository at this point in the history
v1.2 bugfix for 2019+ compile errors
  • Loading branch information
radiatoryang authored Nov 1, 2020
2 parents 233e5d5 + e20e3cf commit feac4e6
Show file tree
Hide file tree
Showing 21 changed files with 5,128 additions and 488 deletions.
16 changes: 1 addition & 15 deletions Editor/Scripts/IvyCore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public class IvyCore
public static IvyCore Instance;

public static double lastRefreshTime { get; private set; }
static double refreshInterval = 0.1;
static double refreshInterval = 0.04;

public static List<IvyBehavior> ivyBehaviors = new List<IvyBehavior>();

Expand Down Expand Up @@ -185,20 +185,6 @@ public static void ForceStopGrowing()
}
}

[MenuItem("Hedera/Open HederaExampleScene.unity")]
public static void OpenExampleScene () {
var scenes = AssetDatabase.FindAssets("HederaExampleScene t:Scene");
if ( scenes != null && scenes.Length > 0) {
scenes[0] = AssetDatabase.GUIDToAssetPath( scenes[0] );
} else {
Debug.LogWarning( "Hedera > Open HederaExampleScene couldn't find the example scene, which is usually in Assets/Hedera/Example/HederaExampleScene.unity ... you may have renamed the scene file or deleted it.");
return;
}
if ( UnityEditor.SceneManagement.EditorSceneManager.SaveCurrentModifiedScenesIfUserWantsTo() ) {
UnityEditor.SceneManagement.EditorSceneManager.OpenScene( scenes[0], UnityEditor.SceneManagement.OpenSceneMode.Single);
}
}

public static IvyGraph SeedNewIvyGraph(IvyProfile ivyProfile, Vector3 seedPos, Vector3 primaryGrowDir, Vector3 adhesionVector, Transform root, bool generateMeshPreview=false)
{
var graph = new IvyGraph();
Expand Down
2 changes: 1 addition & 1 deletion Editor/Scripts/IvyEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ public override void OnInspectorGUI()
// if Gizmos aren't drawn in scene view, then we can't paint anything since OnSceneGUI() is no longer called... but this warning is only supported in Unity 2019.1 or newer
// see issue: https://github.com/radiatoryang/hedera/issues/6
#if UNITY_2019_1_OR_NEWER
if ( SceneView.drawGizmos == false) {
if ( SceneView.lastActiveSceneView.drawGizmos == false) {
GUI.enabled = false;
EditorGUILayout.HelpBox("Gizmos are disabled in the Scene View, which breaks OnSceneGUI(), so ivy painting is disabled.", MessageType.Error);
}
Expand Down
19 changes: 14 additions & 5 deletions Editor/Scripts/IvyMesh.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,19 @@ public class IvyMesh
static List<int> leafTrianglesAll = new List<int>(16384);
static List<Color> leafColorsAll = new List<Color>(4096);
static Mesh branchMesh, leafMesh;
static Quaternion lastLeafFacing = Quaternion.identity;

public static void InitOrRefreshRoot(IvyGraph ivyGraph, IvyProfile ivyProfile) {
if ( ivyGraph.rootGO == null ) {
ivyGraph.rootGO = new GameObject("HederaObject");
ivyGraph.rootGO.transform.SetParent( ivyGraph.rootBehavior );
}
SetStaticEditorFlag( ivyGraph.rootGO, StaticEditorFlags.BatchingStatic, ivyProfile.markMeshAsStatic );
#if UNITY_2019_2_OR_NEWER
SetStaticEditorFlag( ivyGraph.rootGO, StaticEditorFlags.ContributeGI, ivyProfile.useLightmapping );
#else
SetStaticEditorFlag( ivyGraph.rootGO, StaticEditorFlags.LightmapStatic, ivyProfile.useLightmapping );
#endif
var rootTrans = ivyGraph.rootGO.transform;
rootTrans.position = ivyGraph.seedPos;
rootTrans.rotation = Quaternion.identity;
Expand Down Expand Up @@ -185,7 +190,11 @@ static void CheckMeshDataAsset(ref long meshID, IvyDataAsset myAsset, IvyProfile

static void RefreshMeshObject(MeshFilter mf, IvyProfile ivyProfile) {
SetStaticEditorFlag( mf.gameObject, StaticEditorFlags.BatchingStatic, ivyProfile.markMeshAsStatic );
#if UNITY_2019_2_OR_NEWER
SetStaticEditorFlag( mf.gameObject, StaticEditorFlags.ContributeGI, ivyProfile.useLightmapping );
#else
SetStaticEditorFlag( mf.gameObject, StaticEditorFlags.LightmapStatic, ivyProfile.useLightmapping );
#endif
var branchTrans = mf.transform;
branchTrans.localPosition = Vector3.zero;
branchTrans.localRotation = Quaternion.identity;
Expand Down Expand Up @@ -429,11 +438,11 @@ static bool GenerateMeshData(IvyGraph ivyGraph, IvyProfile ivyProfile, bool forc
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));
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);
AddLeafVertex(cache, center, new Vector3(1f, -1f, 0f), leafSize, facing);
lastLeafFacing = node.c.sqrMagnitude < 0.001f ? lastLeafFacing : 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, lastLeafFacing);
AddLeafVertex(cache, center, new Vector3(1f, 1f, 0f), leafSize, lastLeafFacing);
AddLeafVertex(cache, center, new Vector3(-1f, -1f, 0f), leafSize, lastLeafFacing);
AddLeafVertex(cache, center, new Vector3(1f, -1f, 0f), leafSize, lastLeafFacing);

cache.leafUVs.Add(new Vector2(1.0f, 1.0f));
cache.leafUVs.Add(new Vector2(0.0f, 1.0f));
Expand Down
7 changes: 7 additions & 0 deletions Runtime/Shaders/HederaIvyFoliage.shader
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ Shader "Nature/HederaIvyFoliage" {

_ShakeTime ("Shake Time", Float) = 1.0
_ShakeBending ("Shake Amount", Float) = 1.0

[ToggleOff] _SpecularHighlights("Specular Highlights", Float) = 1.0
[ToggleOff] _GlossyReflections("Glossy Reflections", Float) = 1.0
}

SubShader {
Expand All @@ -27,6 +30,10 @@ Shader "Nature/HederaIvyFoliage" {

CGPROGRAM
#pragma surface surf Standard fullforwardshadows alphatest:_Cutoff vertex:vert addshadow
#pragma shader_feature _NORMALMAP
#pragma shader_feature _METALLICGLOSSMAP
#pragma shader_feature _ _SPECULARHIGHLIGHTS_OFF
#pragma shader_feature _ _GLOSSYREFLECTIONS_OFF
#pragma target 3.0

fixed4 _Color;
Expand Down
File renamed without changes.
8 changes: 8 additions & 0 deletions Samples/ExampleIvyScene.meta

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

File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit feac4e6

Please sign in to comment.