portals and dash. Also a bit of terrain building and level design

This commit is contained in:
2022-03-13 00:26:35 +02:00
parent 813cd0c451
commit e82799c36a
6242 changed files with 2160679 additions and 188245 deletions

View File

@@ -0,0 +1,156 @@
#if GRIFFIN
using UnityEngine;
using UnityEngine.Networking;
namespace Pinwheel.Griffin
{
public static class GAnalytics
{
public const string OS_WINDOWS = "http://bit.ly/34fMuhb";
public const string OS_MAC = "http://bit.ly/31XORUx";
public const string OS_LINUX = "http://bit.ly/34cUYWg";
public const string PLATFORM_PC = "http://bit.ly/333nKZq";
public const string PLATFORM_MOBILE = "http://bit.ly/349N0gA";
public const string PLATFORM_CONSOLE = "http://bit.ly/2NrXvVN";
public const string PLATFORM_WEB = "http://bit.ly/36dOsQZ";
public const string PLATFORM_OTHER = "http://bit.ly/2MZnuFm";
public const string XR_PROJECT = "http://bit.ly/2qYUhlr";
public const string COLOR_SPACE_GAMMA = "http://bit.ly/330OHwG";
public const string COLOR_SPACE_LINEAR = "http://bit.ly/349O7wM";
public const string RENDER_PIPELINE_BUILTIN = "http://bit.ly/2N091Jg";
public const string RENDER_PIPELINE_LIGHTWEIGHT = "http://bit.ly/36hxUro";
public const string RENDER_PIPELINE_UNIVERSAL = "http://bit.ly/34fbaX7";
public const string RENDER_PIPELINE_OTHER = "http://bit.ly/2piMkaf";
public const string INTEGRATION_AMPLIFY_SHADER_EDITOR = "http://bit.ly/2JBwfDw";
public const string INTEGRATION_POSEIDON = "http://bit.ly/2WrPEMc";
public const string INTEGRATION_CSHARP_WIZARD = "http://bit.ly/2MZsqdh";
public const string INTEGRATION_MESH_TO_FILE = "http://bit.ly/2Nr35b1";
public const string INTEGRATION_VEGETATION_STUDIO = "https://bit.ly/34kiPVB";
public const string INTEGRATION_MICRO_SPLAT = "https://bit.ly/3bwXtWS";
public const string MULTI_TERRAIN = "http://bit.ly/2q2M2Eh";
public const string WIND_ZONE = "http://bit.ly/2JCtjWY";
public const string CONVERT_FROM_UNITY_TERRAIN = "http://bit.ly/2WrphpN";
public const string WIZARD_CREATE_TERRAIN = "http://bit.ly/2PurvTT";
public const string WIZARD_SET_SHADER = "http://bit.ly/326NG5j";
public const string SHADING_COLOR_MAP = "http://bit.ly/323pzEg";
public const string SHADING_GRADIENT_LOOKUP = "http://bit.ly/2PB1WR0";
public const string SHADING_SPLAT = "http://bit.ly/2C0jmi1";
public const string SHADING_VERTEX_COLOR = "http://bit.ly/2q6Ty13";
public const string ENABLE_INSTANCING = "http://bit.ly/2PAjM6C";
public const string ENABLE_INTERACTIVE_GRASS = "http://bit.ly/2BWRMSD";
public const string IMPORT_UNITY_TERRAIN_DATA = "http://bit.ly/2JApdPl";
public const string IMPORT_POLARIS_V1_DATA = "http://bit.ly/34bKdDI";
public const string IMPORT_RAW = "http://bit.ly/2qZK5sO";
public const string IMPORT_TEXTURES = "http://bit.ly/2NqHYFY";
public const string EXPORT_UNITY_TERRAIN_DATA = "http://bit.ly/2N34cyT";
public const string EXPORT_RAW = "http://bit.ly/2Ws3XAg";
public const string EXPORT_TEXTURES = "http://bit.ly/335KGak";
public const string GROUP_OVERRIDE_GEOMETRY = "http://bit.ly/2N4ho6G";
public const string GROUP_OVERRIDE_SHADING = "http://bit.ly/31VkuOs";
public const string GROUP_OVERRIDE_RENDERING = "http://bit.ly/2NpGf3C";
public const string GROUP_OVERRIDE_FOLIAGE = "http://bit.ly/2qZMhR4";
public const string GROUP_REARRANGE = "http://bit.ly/2JDdW0t";
public const string GROUP_MATCH_EDGE = "http://bit.ly/2rDM46g";
public const string TPAINTER_ELEVATION = "http://bit.ly/2pg6dPe";
public const string TPAINTER_HEIGHT_SAMPLING = "http://bit.ly/36ihqiH";
public const string TPAINTER_TERRACE = "http://bit.ly/32XeeqE";
public const string TPAINTER_REMAP = "http://bit.ly/34fXZ8t";
public const string TPAINTER_NOISE = "http://bit.ly/2ptazlQ";
public const string TPAINTER_SUBDIV = "http://bit.ly/2qPboWu";
public const string TPAINTER_ALBEDO = "http://bit.ly/2otnoMz";
public const string TPAINTER_METALLIC = "http://bit.ly/2JwqyGG";
public const string TPAINTER_SMOOTHNESS = "http://bit.ly/2NpLkJm";
public const string TPAINTER_SPLAT = "http://bit.ly/36aCDLo";
public const string TPAINTER_CUSTOM = "http://bit.ly/33bdH4o";
public const string FPAINTER_PAINT_TREE = "http://bit.ly/36dGwzb";
public const string FPAINTER_SCALE_TREE = "http://bit.ly/2JzHJHt";
public const string FPAINTER_PAINT_GRASS = "http://bit.ly/2MWmfqm";
public const string FPAINTER_SCALE_GRASS = "http://bit.ly/2Pv2EiH";
public const string FPAINTER_CUSTOM = "http://bit.ly/34dvJ6f";
public const string OPAINTER_SPAWN = "http://bit.ly/36mPn1R";
public const string OPAINTER_SCALE = "http://bit.ly/2BRbHCC";
public const string OPAINTER_CUSTOM = "http://bit.ly/2PtNhHi";
public const string SPLINE_RAMP_MAKER = "http://bit.ly/3337V50";
public const string SPLINE_PATH_PAINTER = "http://bit.ly/2NsN7gD";
public const string SPLINE_FOLIAGE_SPAWNER = "http://bit.ly/3307hW0";
public const string SPLINE_FOLIAGE_REMOVER = "http://bit.ly/2WqoeGC";
public const string SPLINE_OBJECT_SPAWNER = "http://bit.ly/2qbnFEg";
public const string SPLINE_OBJECT_REMOVER = "http://bit.ly/2BVVxI4";
public const string STAMPER_GEOMETRY = "http://bit.ly/2q5nOJy";
public const string STAMPER_TEXTURE = "http://bit.ly/2JDEU8a";
public const string STAMPER_FOLIAGE = "http://bit.ly/321JIe3";
public const string STAMPER_OBJECT = "http://bit.ly/34ia3WC";
public const string NAVIGATION_HELPER = "http://bit.ly/2NqLwrM";
public const string BACKUP_CREATE = "http://bit.ly/2N2NzDf";
public const string BACKUP_RESTORE = "http://bit.ly/2r20Ofb";
public const string ASSET_EXPLORER_LINK_CLICK = "http://bit.ly/34iwLhr";
public const string HELP_OPEN_WINDOW = "http://bit.ly/2pv2i0N";
public const string BILLBOARD_SAVE = "http://bit.ly/333aaVY";
public const string TEXTURE_CREATOR_HEIGHT_MAP = "http://bit.ly/2WqqWvM";
public const string TEXTURE_CREATOR_HEIGHT_MAP_FROM_MESH = "http://bit.ly/2pv2YmR";
public const string TEXTURE_CREATOR_NORMAL_MAP = "http://bit.ly/2WrJdIW";
public const string TEXTURE_CREATOR_STEEPNESS_MAP = "http://bit.ly/2Py71cT";
public const string TEXTURE_CREATOR_NOISE_MAP = "http://bit.ly/2JzBtQ8";
public const string TEXTURE_CREATOR_COLOR_MAP = "http://bit.ly/2N37emP";
public const string TEXTURE_CREATOR_BLEND_MAP = "http://bit.ly/2Ws8H92";
public const string TEXTURE_CREATOR_FOLIAGE_DISTRIBUTION_MAP = "http://bit.ly/322zCJU";
public const string LINK_ONLINE_MANUAL = "http://bit.ly/2NvamGK";
public const string LINK_YOUTUBE = "http://bit.ly/2N0s2uU";
public const string LINK_FACEBOOK = "http://bit.ly/2pjN278";
public const string LINK_EXPLORE_ASSET = "http://bit.ly/2PFqDvs";
public const string THERMAL_EROSION = "https://bit.ly/3ujcght";
public const string HYDRAULIC_EROSION = "https://bit.ly/3fDFyn0";
public static void Record(string url, bool perProject = false)
{
#if UNITY_EDITOR
if (!GEditorSettings.Instance.general.enableAnalytics)
return;
if (string.IsNullOrEmpty(url))
return;
bool willRecord = true;
if (perProject && PlayerPrefs.HasKey(url))
{
willRecord = false;
}
if (!willRecord)
return;
if (perProject)
{
PlayerPrefs.SetInt(url, 1);
}
UnityWebRequest request = new UnityWebRequest(url);
request.SendWebRequest();
#endif
}
}
}
#endif

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 149589c472c32b645a6e995edbc66bc8
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,77 @@
#if GRIFFIN
using UnityEngine;
namespace Pinwheel.Griffin
{
public class GAssetExplorer : MonoBehaviour
{
public static string PINWHEEL_ASSETS_LINK = "https://assetstore.unity.com/publishers/17305?aid=1100l3QbW&pubref=p2-editor";
public static string VEGETATION_LINK = "https://assetstore.unity.com/lists/stylized-vegetation-120082?aid=1100l3QbW&pubref=p2-editor";
public static string ROCK_PROPS_LINK = "https://assetstore.unity.com/lists/stylized-rock-props-120083?aid=1100l3QbW&pubref=p2-editor";
public static string WATER_LINK = "https://assetstore.unity.com/lists/stylized-water-120085?aid=1100l3QbW&pubref=p2-editor";
public static string SKY_AMBIENT_LINK = "https://assetstore.unity.com/lists/stylized-sky-and-ambient-120088?aid=1100l3QbW&pubref=p2-editor";
public static string CHARACTER_LINK = "https://assetstore.unity.com/lists/stylized-character-120084?aid=1100l3QbW&pubref=p2-editor";
public static string POLARIS_LINK = "https://assetstore.unity.com/packages/slug/170400?aid=1100l3QbW&pubref=p2-editor";
public static string POSEIDON_LINK = "https://assetstore.unity.com/packages/vfx/shaders/substances/poseidon-low-poly-water-system-builtin-lwrp-153826?aid=1100l3QbW&pubref=p2-editor";
public static string JUPITER_LINK = "https://assetstore.unity.com/packages/slug/159992?aid=1100l3QbW&pubref=p2-editor";
public static string CSHARP_WIZARD_LINK = "https://assetstore.unity.com/packages/slug/104887";
public static string MESH_TO_FILE_LINK = "https://assetstore.unity.com/packages/slug/135071";
public static void ShowPolarisLink()
{
Application.OpenURL(POLARIS_LINK);
}
public static void ShowPoseidonLink()
{
Application.OpenURL(POSEIDON_LINK);
}
public static void ShowJupiterLink()
{
Application.OpenURL(JUPITER_LINK);
}
public static void ShowCSharpWizardLink()
{
Application.OpenURL(CSHARP_WIZARD_LINK);
}
public static void ShowMeshToFileLink()
{
Application.OpenURL(MESH_TO_FILE_LINK);
}
public static void ShowPinwheelAssets()
{
Application.OpenURL(PINWHEEL_ASSETS_LINK);
}
public static void ShowVegetationLink()
{
Application.OpenURL(VEGETATION_LINK);
}
public static void ShowRockPropsLink()
{
Application.OpenURL(ROCK_PROPS_LINK);
}
public static void ShowWaterLink()
{
Application.OpenURL(WATER_LINK);
}
public static void ShowSkyAmbientLink()
{
Application.OpenURL(SKY_AMBIENT_LINK);
}
public static void ShowCharacterLink()
{
Application.OpenURL(CHARACTER_LINK);
}
}
}
#endif

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 5640781f054826140b75c55b25c248b5
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,113 @@
#if GRIFFIN
using UnityEngine;
namespace Pinwheel.Griffin
{
public struct GCombineInfo
{
private Vector3[] vertices;
public Vector3[] Vertices
{
get
{
if (vertices == null)
vertices = new Vector3[0];
return vertices;
}
set
{
vertices = value;
}
}
private Vector2[] uvs;
public Vector2[] UVs
{
get
{
if (uvs == null)
uvs = new Vector2[0];
return uvs;
}
set
{
uvs = value;
}
}
private Color32[] colors;
public Color32[] Colors
{
get
{
if (colors == null)
colors = new Color32[0];
return colors;
}
set
{
colors = value;
}
}
private int[] triangles;
public int[] Triangles
{
get
{
if (triangles == null)
triangles = new int[0];
return triangles;
}
set
{
triangles = value;
}
}
private Matrix4x4 transform;
public Matrix4x4 Transform
{
get
{
return transform;
}
set
{
transform = value;
}
}
public GCombineInfo(Mesh m)
{
if (m != null)
{
vertices = m.vertices;
uvs = m.uv;
colors = m.colors32;
triangles = m.triangles;
transform = new Matrix4x4();
if (uvs.Length != vertices.Length)
{
uvs = new Vector2[vertices.Length];
GUtilities.Fill(uvs, Vector2.zero);
}
if (colors.Length != vertices.Length)
{
colors = new Color32[vertices.Length];
GUtilities.Fill(colors, Color.clear);
}
}
else
{
vertices = null;
uvs = null;
colors = null;
triangles = null;
transform = new Matrix4x4();
}
}
}
}
#endif

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 7617895925a4298499848b643ade95f6
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,82 @@
#if GRIFFIN
using System.Collections.Generic;
using UnityEngine;
namespace Pinwheel.Griffin
{
public static class GCombiner
{
public static GCombineInfo Combine(List<GCombineInfo> combines)
{
List<Vector3> vertices = new List<Vector3>();
List<Vector2> uvs = new List<Vector2>();
List<Color32> colors = new List<Color32>();
List<int> triangles = new List<int>();
for (int i = 0; i < combines.Count; ++i)
{
GCombineInfo c = combines[i];
int offset = vertices.Count;
for (int j = 0; j < c.Triangles.Length; ++j)
{
triangles.Add(offset + c.Triangles[j]);
}
for (int j = 0; j < c.Vertices.Length; ++j)
{
vertices.Add(c.Transform.MultiplyPoint(c.Vertices[j]));
}
uvs.AddRange(c.UVs);
colors.AddRange(c.Colors);
}
GCombineInfo result = new GCombineInfo();
result.Vertices = vertices.ToArray();
result.UVs = uvs.ToArray();
result.Colors = colors.ToArray();
result.Triangles = triangles.ToArray();
return result;
}
public static GCombineInfo Combine(GCombineInfo meshTemplate, List<Matrix4x4> transforms)
{
int vertexCount = meshTemplate.Vertices.Length * transforms.Count;
Vector3[] vertices = new Vector3[vertexCount];
Vector2[] uvs = new Vector2[vertexCount];
//Color32[] colors = new Color32[vertexCount];
int trisIndexCount = meshTemplate.Triangles.Length * transforms.Count;
int[] triangles = new int[trisIndexCount];
int currentVertIndex = 0;
int currentTrisIndex = 0;
for (int i = 0; i < transforms.Count; ++i)
{
int offset = currentVertIndex;
for (int j = 0; j < meshTemplate.Triangles.Length; ++j)
{
triangles[currentTrisIndex] = offset + meshTemplate.Triangles[j];
currentTrisIndex += 1;
}
for (int j = 0; j < meshTemplate.Vertices.Length; ++j)
{
vertices[currentVertIndex] = transforms[i].MultiplyPoint(meshTemplate.Vertices[j]);
uvs[currentVertIndex] = meshTemplate.UVs[j];
//colors[currentVertIndex] = meshTemplate.Colors[j];
currentVertIndex += 1;
}
}
GCombineInfo result = new GCombineInfo();
result.Vertices = vertices;
result.UVs = uvs;
//result.Colors = colors;
result.Triangles = triangles;
return result;
}
}
}
#endif

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: e9934c0ac7fea5b4b88b1261070e23bd
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,34 @@
#if GRIFFIN
using System.Diagnostics;
using Debug = UnityEngine.Debug;
namespace Pinwheel.Griffin
{
public static class GDebug
{
private static Stopwatch st = new Stopwatch();
public static void StartStopwatch()
{
st.Start();
}
public static void EndStopwatch()
{
st.Stop();
}
public static void LogStopwatchTimeMilis(string label = "")
{
Debug.Log(label + ": " + st.ElapsedMilliseconds);
st.Reset();
}
public static void LogTick()
{
Debug.Log(st.ElapsedTicks);
st.Reset();
}
}
}
#endif

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 638648854be69b8488bcd5f5b954965d
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,17 @@
#if GRIFFIN
using System;
namespace Pinwheel.Griffin
{
[AttributeUsage(AttributeTargets.All, AllowMultiple = false)]
public class GDisplayName : Attribute
{
public string DisplayName { get; set; }
public GDisplayName(string name)
{
DisplayName = name;
}
}
}
#endif

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 9ce76d1affdd39747a28aac9eb169654
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,16 @@
#if GRIFFIN
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
namespace Pinwheel.Griffin
{
//[CreateAssetMenu(menuName = "Griffin/Generic Container")]
public class GGenericContainer : ScriptableObject
{
public void Reset()
{
}
}
}
#endif

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: e8d352e597b8fb145a30e1db8fdba578
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,135 @@
#if GRIFFIN
using System.Collections.Generic;
using UnityEngine;
namespace Pinwheel.Griffin
{
public static class GGrassUtilities
{
public static Vector3[] GetVertices(GGrassShape shape, Matrix4x4 matrix)
{
Vector3[] vertices = null;
if (shape == GGrassShape.Quad)
{
vertices = new Vector3[]
{
new Vector3(-0.5f, 0, 0), new Vector3(-0.5f, 1, 0), new Vector3(0.5f, 1, 0),
new Vector3(-0.5f, 0, 0), new Vector3(0.5f, 1, 0), new Vector3(0.5f, 0, 0)
};
}
else if (shape == GGrassShape.Cross)
{
vertices = new Vector3[]
{
new Vector3(-0.5f, 0, 0), new Vector3(-0.5f, 1, 0), new Vector3(0.5f, 1, 0),
new Vector3(-0.5f, 0, 0), new Vector3(0.5f, 1, 0), new Vector3(0.5f, 0, 0),
new Vector3(0, 0, -0.5f), new Vector3(0, 1, -0.5f), new Vector3(0, 1, 0.5f),
new Vector3(0, 0, -0.5f), new Vector3(0, 1, 0.5f), new Vector3(0, 0, 0.5f),
};
}
else if (shape == GGrassShape.TriCross)
{
Vector3[] quads = new Vector3[]
{
new Vector3(-0.5f, 0, 0), new Vector3(-0.5f, 1, 0), new Vector3(0.5f, 1, 0),
new Vector3(-0.5f, 0, 0), new Vector3(0.5f, 1, 0), new Vector3(0.5f, 0, 0)
};
List<Vector3> verts = new List<Vector3>();
verts.AddRange(quads);
Matrix4x4 rotate60 = Matrix4x4.Rotate(Quaternion.Euler(0, -60, 0));
for (int i = 0; i < quads.Length; ++i)
{
verts.Add(rotate60.MultiplyPoint(quads[i]));
}
Matrix4x4 rotate120 = Matrix4x4.Rotate(Quaternion.Euler(0, -120, 0));
for (int i = 0; i < quads.Length; ++i)
{
verts.Add(rotate120.MultiplyPoint(quads[i]));
}
vertices = verts.ToArray();
}
for (int i = 0; i < vertices.Length; ++i)
{
vertices[i] = matrix.MultiplyPoint(vertices[i]);
}
return vertices;
}
public static Vector2[] GetUVs(GGrassShape shape)
{
Vector2[] uvs = null;
if (shape == GGrassShape.Quad)
{
uvs = new Vector2[]
{
Vector2.zero, Vector2.up, Vector2.one,
Vector2.zero, Vector2.one, Vector2.right
};
}
else if (shape == GGrassShape.Cross)
{
uvs = new Vector2[]
{
Vector2.zero, Vector2.up, Vector2.one,
Vector2.zero, Vector2.one, Vector2.right,
Vector2.zero, Vector2.up, Vector2.one,
Vector2.zero, Vector2.one, Vector2.right
};
}
else if (shape == GGrassShape.TriCross)
{
uvs = new Vector2[]
{
Vector2.zero, Vector2.up, Vector2.one,
Vector2.zero, Vector2.one, Vector2.right,
Vector2.zero, Vector2.up, Vector2.one,
Vector2.zero, Vector2.one, Vector2.right,
Vector2.zero, Vector2.up, Vector2.one,
Vector2.zero, Vector2.one, Vector2.right
};
}
return uvs;
}
public static Color[] GetColors(GGrassShape shape)
{
Color[] colors = null;
if (shape == GGrassShape.Quad)
{
colors = new Color[]
{
Color.clear, Color.white, Color.white,
Color.clear, Color.white, Color.clear
};
}
else if (shape == GGrassShape.Cross)
{
colors = new Color[]
{
Color.clear, Color.white, Color.white,
Color.clear, Color.white, Color.clear,
Color.clear, Color.white, Color.white,
Color.clear, Color.white, Color.clear
};
}
else if (shape == GGrassShape.TriCross)
{
colors = new Color[]
{
Color.clear, Color.white, Color.white,
Color.clear, Color.white, Color.clear,
Color.clear, Color.white, Color.white,
Color.clear, Color.white, Color.clear,
Color.clear, Color.white, Color.white,
Color.clear, Color.white, Color.clear
};
}
return colors;
}
}
}
#endif

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: b041351720487984ba7c35a4c9dde6f2
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,408 @@
#if GRIFFIN
using UnityEngine;
namespace Pinwheel.Griffin
{
public static class GInternalMaterials
{
private static Material unlitTextureMaterial;
public static Material UnlitTextureMaterial
{
get
{
if (unlitTextureMaterial == null)
{
unlitTextureMaterial = new Material(Shader.Find("Unlit/Texture"));
}
return unlitTextureMaterial;
}
}
private static Material unlitTransparentMaterial;
public static Material UnlitTransparentMaterial
{
get
{
if (unlitTransparentMaterial == null)
{
unlitTransparentMaterial = new Material(Shader.Find("Unlit/Transparent"));
}
return unlitTransparentMaterial;
}
}
private static Material copyTextureMaterial;
public static Material CopyTextureMaterial
{
get
{
if (copyTextureMaterial == null)
{
copyTextureMaterial = new Material(GRuntimeSettings.Instance.internalShaders.copyTextureShader);
}
return copyTextureMaterial;
}
}
private static Material subDivisionMapMaterial;
public static Material SubDivisionMapMaterial
{
get
{
if (subDivisionMapMaterial == null)
{
subDivisionMapMaterial = new Material(GRuntimeSettings.Instance.internalShaders.subDivisionMapShader);
subDivisionMapMaterial.SetFloat("_Epsilon", GCommon.SUB_DIV_EPSILON);
subDivisionMapMaterial.SetFloat("_PixelOffset", GCommon.SUB_DIV_PIXEL_OFFSET);
subDivisionMapMaterial.SetFloat("_Step", GCommon.SUB_DIV_STEP);
}
return subDivisionMapMaterial;
}
}
private static Material blurMaterial;
public static Material BlurMaterial
{
get
{
if (blurMaterial == null)
{
blurMaterial = new Material(GRuntimeSettings.Instance.internalShaders.blurShader);
}
return blurMaterial;
}
}
private static Material blurRadiusMaterial;
public static Material BlurRadiusMaterial
{
get
{
if (blurRadiusMaterial == null)
{
blurRadiusMaterial = new Material(GRuntimeSettings.Instance.internalShaders.blurRadiusShader);
}
return blurRadiusMaterial;
}
}
private static Material painterCursorProjectorMaterial;
public static Material PainterCursorProjectorMaterial
{
get
{
if (painterCursorProjectorMaterial == null)
{
painterCursorProjectorMaterial = new Material(GRuntimeSettings.Instance.internalShaders.painterCursorProjectorShader);
}
return painterCursorProjectorMaterial;
}
}
private static Material solidColorMaterial;
public static Material SolidColorMaterial
{
get
{
if (solidColorMaterial == null)
{
solidColorMaterial = new Material(GRuntimeSettings.Instance.internalShaders.solidColorShader);
}
return solidColorMaterial;
}
}
private static Material rampMakerMaterial;
public static Material RampMakerMaterial
{
get
{
if (rampMakerMaterial == null)
{
rampMakerMaterial = new Material(GRuntimeSettings.Instance.internalShaders.rampMakerShader);
}
return rampMakerMaterial;
}
}
private static Material geometryLivePreviewMaterial;
public static Material GeometryLivePreviewMaterial
{
get
{
if (geometryLivePreviewMaterial == null)
{
geometryLivePreviewMaterial = new Material(GRuntimeSettings.Instance.internalShaders.geometryLivePreviewShader);
}
return geometryLivePreviewMaterial;
}
}
private static Material geometricalHeightMapMaterial;
public static Material GeometricalHeightMapMaterial
{
get
{
if (geometricalHeightMapMaterial == null)
{
geometricalHeightMapMaterial = new Material(GRuntimeSettings.Instance.internalShaders.geometricalHeightMapShader);
}
return geometricalHeightMapMaterial;
}
}
private static Material foliageRemoverMaterial;
public static Material FoliageRemoverMaterial
{
get
{
if (foliageRemoverMaterial == null)
{
foliageRemoverMaterial = new Material(GRuntimeSettings.Instance.internalShaders.splineMaskShader);
}
return foliageRemoverMaterial;
}
}
private static Material maskVisualizerMaterial;
public static Material MaskVisualizerMaterial
{
get
{
if (maskVisualizerMaterial == null)
{
maskVisualizerMaterial = new Material(GRuntimeSettings.Instance.internalShaders.maskVisualizerShader);
}
return maskVisualizerMaterial;
}
}
private static Material stamperMaterial;
public static Material StamperMaterial
{
get
{
if (stamperMaterial == null)
{
stamperMaterial = new Material(GRuntimeSettings.Instance.internalShaders.stamperShader);
}
return stamperMaterial;
}
}
private static Material terrainNormalMapRendererMaterial;
public static Material TerrainNormalMapRendererMaterial
{
get
{
if (terrainNormalMapRendererMaterial == null)
{
terrainNormalMapRendererMaterial = new Material(GRuntimeSettings.Instance.internalShaders.terrainNormalMapShader);
}
return terrainNormalMapRendererMaterial;
}
}
private static Material terrainPerPixelNormalMapRendererMaterial;
public static Material TerrainPerPixelNormalMapRendererMaterial
{
get
{
if (terrainPerPixelNormalMapRendererMaterial == null)
{
terrainPerPixelNormalMapRendererMaterial = new Material(GRuntimeSettings.Instance.internalShaders.terrainPerPixelNormalMapShader);
}
return terrainPerPixelNormalMapRendererMaterial;
}
}
private static Material textureStamperBrushMaterial;
public static Material TextureStamperBrushMaterial
{
get
{
if (textureStamperBrushMaterial == null)
{
textureStamperBrushMaterial = new Material(GRuntimeSettings.Instance.internalShaders.textureStamperBrushShader);
}
return textureStamperBrushMaterial;
}
}
private static Material grassPreviewMaterial;
public static Material GrassPreviewMaterial
{
get
{
if (grassPreviewMaterial == null)
{
grassPreviewMaterial = new Material(GRuntimeSettings.Instance.internalShaders.grassPreviewShader);
}
return grassPreviewMaterial;
}
}
private static Material navHelperDummyGameObjectMaterial;
public static Material NavHelperDummyGameObjectMaterial
{
get
{
if (navHelperDummyGameObjectMaterial == null)
{
navHelperDummyGameObjectMaterial = new Material(GRuntimeSettings.Instance.internalShaders.navHelperDummyGameObjectShader);
}
Color cyan = Color.cyan;
navHelperDummyGameObjectMaterial.SetColor("_Color", new Color(cyan.r, cyan.g, cyan.b, 0.5f));
return navHelperDummyGameObjectMaterial;
}
}
private static Material splatsToAlbedoMaterial;
public static Material SplatsToAlbedoMaterial
{
get
{
if (splatsToAlbedoMaterial == null)
{
splatsToAlbedoMaterial = new Material(GRuntimeSettings.Instance.internalShaders.splatsToAlbedoShader);
}
return splatsToAlbedoMaterial;
}
}
private static Material unlitChannelMaskMaterial;
public static Material UnlitChannelMaskMaterial
{
get
{
if (unlitChannelMaskMaterial == null)
{
unlitChannelMaskMaterial = new Material(GRuntimeSettings.Instance.internalShaders.unlitChannelMaskShader);
}
return unlitChannelMaskMaterial;
}
}
private static Material channelToGrayscaleMaterial;
public static Material ChannelToGrayscaleMaterial
{
get
{
if (channelToGrayscaleMaterial == null)
{
channelToGrayscaleMaterial = new Material(GRuntimeSettings.Instance.internalShaders.channelToGrayscaleShader);
}
return channelToGrayscaleMaterial;
}
}
private static Material heightMapFromMeshMaterial;
public static Material HeightMapFromMeshMaterial
{
get
{
if (heightMapFromMeshMaterial == null)
{
heightMapFromMeshMaterial = new Material(GRuntimeSettings.Instance.internalShaders.heightMapFromMeshShader);
}
return heightMapFromMeshMaterial;
}
}
private static Material interactiveGrassVectorFieldMaterial;
public static Material InteractiveGrassVectorFieldMaterial
{
get
{
if (interactiveGrassVectorFieldMaterial == null)
{
interactiveGrassVectorFieldMaterial = new Material(GRuntimeSettings.Instance.internalShaders.interactiveGrassVectorFieldShader);
}
return interactiveGrassVectorFieldMaterial;
}
}
private static Material subdivLivePreviewMaterial;
public static Material SubdivLivePreviewMaterial
{
get
{
if (subdivLivePreviewMaterial == null)
{
subdivLivePreviewMaterial = new Material(GRuntimeSettings.Instance.internalShaders.subdivLivePreviewShader);
}
return subdivLivePreviewMaterial;
}
}
private static Material visibilityLivePreviewMaterial;
public static Material VisibilityLivePreviewMaterial
{
get
{
if (visibilityLivePreviewMaterial == null)
{
visibilityLivePreviewMaterial = new Material(GRuntimeSettings.Instance.internalShaders.visibilityLivePreviewShader);
}
return visibilityLivePreviewMaterial;
}
}
private static Material heightmapConverterEncodeRGMaterial;
public static Material HeightmapConverterEncodeRGMaterial
{
get
{
if (heightmapConverterEncodeRGMaterial == null)
{
heightmapConverterEncodeRGMaterial = new Material(GRuntimeSettings.Instance.internalShaders.heightmapConverterEncodeRGShader);
}
return heightmapConverterEncodeRGMaterial;
}
}
private static Material heightmapDecodeGrayscaleMaterial;
public static Material HeightmapDecodeGrayscaleMaterial
{
get
{
if (heightmapDecodeGrayscaleMaterial == null)
{
heightmapDecodeGrayscaleMaterial = new Material(GRuntimeSettings.Instance.internalShaders.heightmapDecodeGrayscaleShader);
}
return heightmapDecodeGrayscaleMaterial;
}
}
private static Material drawTex2DArraySliceMaterial;
public static Material DrawTex2DArraySliceMaterial
{
get
{
if (drawTex2DArraySliceMaterial == null)
{
drawTex2DArraySliceMaterial = new Material(GRuntimeSettings.Instance.internalShaders.drawTex2DArraySliceShader);
}
return drawTex2DArraySliceMaterial;
}
}
private static Material mask4ChannelsMaterial;
public static Material Mask4ChannelsMaterial
{
get
{
if (mask4ChannelsMaterial == null)
{
mask4ChannelsMaterial = new Material(GRuntimeSettings.Instance.internalShaders.mask4ChannelsShader);
}
return mask4ChannelsMaterial;
}
}
}
}
#endif

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 47eb467994582fb42a4a7b8ce54c706b
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,61 @@
#if GRIFFIN
using UnityEngine;
namespace Pinwheel.Griffin
{
[System.Serializable]
public struct GInternalShaderSettings
{
public Shader solidColorShader;
public Shader copyTextureShader;
public Shader subDivisionMapShader;
public Shader blurShader;
public Shader blurRadiusShader;
public Shader elevationPainterShader;
public Shader heightSamplingPainterShader;
public Shader subdivPainterShader;
public Shader painterCursorProjectorShader;
public Shader albedoPainterShader;
public Shader metallicPainterShader;
public Shader smoothnessPainterShader;
public Shader splatPainterShader;
public Shader visibilityPainterShader;
public Shader rampMakerShader;
public Shader pathPainterShader;
public Shader geometryLivePreviewShader;
public Shader geometricalHeightMapShader;
public Shader foliageRemoverShader;
public Shader maskVisualizerShader;
public Shader stamperShader;
public Shader terrainNormalMapShader;
public Shader terrainPerPixelNormalMapShader;
public Shader textureStamperBrushShader;
public Shader grassPreviewShader;
public Shader navHelperDummyGameObjectShader;
public Shader splatsToAlbedoShader;
public Shader unlitChannelMaskShader;
public Shader channelToGrayscaleShader;
public Shader heightMapFromMeshShader;
public Shader curveFilterShader;
public Shader invertFilterShader;
public Shader stepFilterShader;
public Shader warpFilterShader;
public Shader steepnessMapGeneratorShader;
public Shader noiseMapGeneratorShader;
public Shader hydraulicErosionFilter;
public Shader blendMapGeneratorShader;
public Shader distributionMapGeneratorShader;
public Shader interactiveGrassVectorFieldShader;
public Shader subdivLivePreviewShader;
public Shader visibilityLivePreviewShader;
public Shader terracePainterShader;
public Shader remapPainterShader;
public Shader noisePainterShader;
public Shader heightmapConverterEncodeRGShader;
public Shader heightmapDecodeGrayscaleShader;
public Shader drawTex2DArraySliceShader;
public Shader maskPainterShader;
public Shader mask4ChannelsShader;
}
}
#endif

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 7f1394c229877ef4da955c2356386b63
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,9 @@
#if GRIFFIN
namespace Pinwheel.Griffin
{
public enum GLightingModel
{
PBR, Lambert, BlinnPhong
}
}
#endif

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 6fb4810a37007be43845a7e51f953359
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,115 @@
#if GRIFFIN
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using System;
using Unity.Mathematics;
using static Unity.Mathematics.math;
namespace Pinwheel.Griffin
{
public struct Line2D
{
public float2 startPoint;
public float2 endPoint;
public float2 Direction
{
get
{
return normalize(endPoint - startPoint);
}
}
public float Length
{
get
{
return distance(startPoint, endPoint);
}
}
public float SqrLength
{
get
{
return distancesq(startPoint, endPoint);
}
}
public Line2D(float2 start, float2 end)
{
startPoint = start;
endPoint = end;
}
public Line2D(float x1, float y1, float x2, float y2)
{
startPoint = new float2(x1, y1);
endPoint = new float2(x2, y2);
}
public float GetX(float y)
{
float2 dir = endPoint - startPoint;
float a = -dir.y;
float b = dir.x;
float c = -(a * startPoint.x + b * startPoint.y);
float x = (-b * y - c) / a;
return x;
}
public float GetY(float x)
{
float2 dir = endPoint - startPoint;
float a = -dir.y;
float b = dir.x;
float c = -(a * startPoint.x + b * startPoint.y);
float y = (-a * x - c) / b;
return y;
}
public static bool Intersect(Line2D l1, Line2D l2, out float2 point)
{
bool result = false;
float x1 = l1.startPoint.x;
float x2 = l1.endPoint.x;
float x3 = l2.startPoint.x;
float x4 = l2.endPoint.x;
float y1 = l1.startPoint.y;
float y2 = l1.endPoint.y;
float y3 = l2.startPoint.y;
float y4 = l2.endPoint.y;
float denominator = (x1 - x2) * (y3 - y4) - (y1 - y2) * (x3 - x4);
if (denominator == 0)
{
point = new float2(0, 0);
result = false;
}
else
{
float xNumerator = (x1 * y2 - y1 * x2) * (x3 - x4) - (x1 - x2) * (x3 * y4 - y3 * x4);
float yNumerator = (x1 * y2 - y1 * x2) * (y3 - y4) - (y1 - y2) * (x3 * y4 - y3 * x4);
point = new float2(xNumerator / denominator, yNumerator / denominator);
float sqrLength1 = l1.SqrLength;
float sqrLength2 = l2.SqrLength;
if (distancesq(point, l1.startPoint) > sqrLength1 || distancesq(point, l1.endPoint) > sqrLength1)
{
result = false;
}
else if (distancesq(point, l2.startPoint) > sqrLength2 || distancesq(point, l2.endPoint) > sqrLength2)
{
result = false;
}
else
{
result = true;
}
}
return result;
}
}
}
#endif

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: e6e639d8dfc0d924e81a8c88d325ee54
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,742 @@
#if GRIFFIN
#if UNITY_EDITOR
using UnityEngine;
using UnityEngine.Rendering;
namespace Pinwheel.Griffin
{
public static class GLivePreviewDrawer
{
private static MaterialPropertyBlock previewPropertyBlock = new MaterialPropertyBlock();
public static void DrawGeometryLivePreview(GStylizedTerrain t, Camera cam, Texture newHeightMap, Rect dirtyRect)
{
if (t.transform.rotation != Quaternion.identity ||
t.transform.lossyScale != Vector3.one)
return;
Mesh previewMesh = GEditorSettings.Instance.livePreview.GetTriangleMesh(t.TerrainData.Geometry.MeshResolution);
Vector3 terrainSize = new Vector3(
t.TerrainData.Geometry.Width,
t.TerrainData.Geometry.Height,
t.TerrainData.Geometry.Length);
previewPropertyBlock.Clear();
previewPropertyBlock.SetTexture("_OldHeightMap", t.TerrainData.Geometry.HeightMap);
previewPropertyBlock.SetTexture("_NewHeightMap", newHeightMap);
previewPropertyBlock.SetTexture("_MainTex", newHeightMap);
previewPropertyBlock.SetFloat("_Height", t.TerrainData.Geometry.Height);
previewPropertyBlock.SetVector("_BoundMin", t.transform.position);
previewPropertyBlock.SetVector("_BoundMax", t.transform.TransformPoint(terrainSize));
Material mat = GInternalMaterials.GeometryLivePreviewMaterial;
mat.renderQueue = 4000;
int gridSize = t.TerrainData.Geometry.ChunkGridSize;
for (int x = 0; x < gridSize; ++x)
{
for (int z = 0; z < gridSize; ++z)
{
Rect uvRect = GCommon.GetUvRange(gridSize, x, z);
if (!uvRect.Overlaps(dirtyRect))
continue;
Vector3 localPos = new Vector3(
terrainSize.x * uvRect.x,
0f,
terrainSize.z * uvRect.y);
Vector3 worldPos = t.transform.TransformPoint(localPos);
Quaternion rotation = Quaternion.identity;
Vector3 scale = new Vector3(terrainSize.x * uvRect.width, 1, terrainSize.z * uvRect.height);
Graphics.DrawMesh(
previewMesh,
Matrix4x4.TRS(worldPos, rotation, scale),
mat,
LayerMask.NameToLayer("Default"),
cam,
0,
previewPropertyBlock);
}
}
}
public static void DrawGeometryLivePreview(GStylizedTerrain t, Camera cam, Texture newHeightMap, bool[] chunkCulling)
{
if (t.transform.rotation != Quaternion.identity ||
t.transform.lossyScale != Vector3.one)
return;
Mesh previewMesh = GEditorSettings.Instance.livePreview.GetTriangleMesh(t.TerrainData.Geometry.MeshResolution);
Vector3 terrainSize = new Vector3(
t.TerrainData.Geometry.Width,
t.TerrainData.Geometry.Height,
t.TerrainData.Geometry.Length);
previewPropertyBlock.Clear();
previewPropertyBlock.SetTexture("_OldHeightMap", t.TerrainData.Geometry.HeightMap);
previewPropertyBlock.SetTexture("_NewHeightMap", newHeightMap);
previewPropertyBlock.SetTexture("_MainTex", newHeightMap);
previewPropertyBlock.SetFloat("_Height", t.TerrainData.Geometry.Height);
previewPropertyBlock.SetVector("_BoundMin", t.transform.position);
previewPropertyBlock.SetVector("_BoundMax", t.transform.TransformPoint(terrainSize));
Material mat = GInternalMaterials.GeometryLivePreviewMaterial;
mat.renderQueue = 4000;
Rect[] chunkRects = t.GetChunkRects();
for (int i = 0; i < chunkRects.Length; ++i)
{
if (chunkCulling[i] == false)
continue;
Rect r = chunkRects[i];
Vector3 position = new Vector3(r.x, t.transform.position.y, r.y);
Quaternion rotation = Quaternion.identity;
Vector3 scale = new Vector3(r.width, 1, r.height);
Matrix4x4 trs = Matrix4x4.TRS(position, rotation, scale);
Graphics.DrawMesh(
previewMesh,
trs,
mat,
LayerMask.NameToLayer("Default"),
cam,
0,
previewPropertyBlock,
ShadowCastingMode.Off,
false,
null,
LightProbeUsage.Off,
null);
}
}
public static void DrawSubdivLivePreview(GStylizedTerrain t, Camera cam, Texture newHeightMap, Rect dirtyRect, Texture mask, Matrix4x4 worldPointToMaskMatrix)
{
if (t.transform.rotation != Quaternion.identity ||
t.transform.lossyScale != Vector3.one)
return;
t.TerrainData.Geometry.Internal_CreateNewSubDivisionMap(newHeightMap);
int baseResolution = t.TerrainData.Geometry.MeshBaseResolution;
int resolution = t.TerrainData.Geometry.MeshResolution;
int maxLevel = baseResolution + Mathf.Min(Mathf.FloorToInt(1f / GCommon.SUB_DIV_STEP), resolution - baseResolution);
Vector3 terrainSize = new Vector3(
t.TerrainData.Geometry.Width,
t.TerrainData.Geometry.Height,
t.TerrainData.Geometry.Length);
previewPropertyBlock.Clear();
previewPropertyBlock.SetColor("_Color", new Color(0, 0, 0, 0.6f));
previewPropertyBlock.SetTexture("_HeightMap", newHeightMap);
previewPropertyBlock.SetVector("_Dimension", terrainSize);
previewPropertyBlock.SetVector("_BoundMin", t.transform.position);
previewPropertyBlock.SetVector("_BoundMax", t.transform.TransformPoint(terrainSize));
previewPropertyBlock.SetTexture("_SubdivMap", t.TerrainData.Geometry.Internal_SubDivisionMap);
previewPropertyBlock.SetTexture("_Mask", mask);
previewPropertyBlock.SetMatrix("_WorldPointToMask", worldPointToMaskMatrix);
Material mat = GInternalMaterials.SubdivLivePreviewMaterial;
mat.renderQueue = 4000;
Mesh previewMesh = null;
int gridSize = t.TerrainData.Geometry.ChunkGridSize;
for (int x = 0; x < gridSize; ++x)
{
for (int z = 0; z < gridSize; ++z)
{
Rect uvRect = GCommon.GetUvRange(gridSize, x, z);
if (!uvRect.Overlaps(dirtyRect))
continue;
Vector3 localPos = new Vector3(
terrainSize.x * uvRect.x,
0f,
terrainSize.z * uvRect.y);
Vector3 worldPos = t.transform.TransformPoint(localPos);
Quaternion rotation = Quaternion.identity;
Vector3 scale = new Vector3(terrainSize.x * uvRect.width, 1, terrainSize.z * uvRect.height);
for (int i = baseResolution; i <= maxLevel; ++i)
{
previewMesh = GEditorSettings.Instance.livePreview.GetWireframeMesh(i);
previewPropertyBlock.SetVector("_SubdivRange", new Vector4(
(i - baseResolution) * GCommon.SUB_DIV_STEP,
i != maxLevel ? (i - baseResolution + 1) * GCommon.SUB_DIV_STEP : 1f,
0, 0));
Graphics.DrawMesh(
previewMesh,
Matrix4x4.TRS(worldPos, rotation, scale),
mat,
LayerMask.NameToLayer("Default"),
cam,
0,
previewPropertyBlock);
}
}
}
}
public static void DrawVisibilityLivePreview(GStylizedTerrain t, Camera cam, Texture newHeightMap, Rect dirtyRect, Texture mask, Matrix4x4 worldPointToMaskMatrix)
{
if (t.transform.rotation != Quaternion.identity ||
t.transform.lossyScale != Vector3.one)
return;
t.TerrainData.Geometry.Internal_CreateNewSubDivisionMap(newHeightMap);
int baseResolution = t.TerrainData.Geometry.MeshBaseResolution;
int resolution = t.TerrainData.Geometry.MeshResolution;
int maxLevel = baseResolution + Mathf.Min(Mathf.FloorToInt(1f / GCommon.SUB_DIV_STEP), resolution - baseResolution);
Vector3 terrainSize = new Vector3(
t.TerrainData.Geometry.Width,
t.TerrainData.Geometry.Height,
t.TerrainData.Geometry.Length);
previewPropertyBlock.Clear();
previewPropertyBlock.SetColor("_Color", new Color(0, 0, 0, 0.6f));
previewPropertyBlock.SetTexture("_HeightMap", newHeightMap);
previewPropertyBlock.SetVector("_Dimension", terrainSize);
previewPropertyBlock.SetVector("_BoundMin", t.transform.position);
previewPropertyBlock.SetVector("_BoundMax", t.transform.TransformPoint(terrainSize));
previewPropertyBlock.SetTexture("_SubdivMap", t.TerrainData.Geometry.Internal_SubDivisionMap);
if (mask == null)
mask = Texture2D.whiteTexture;
previewPropertyBlock.SetTexture("_Mask", mask);
previewPropertyBlock.SetMatrix("_WorldPointToMask", worldPointToMaskMatrix);
Material mat = GInternalMaterials.VisibilityLivePreviewMaterial;
mat.EnableKeyword("USE_MASK");
mat.renderQueue = 4000;
Mesh previewMesh = null;
int gridSize = t.TerrainData.Geometry.ChunkGridSize;
for (int x = 0; x < gridSize; ++x)
{
for (int z = 0; z < gridSize; ++z)
{
Rect uvRect = GCommon.GetUvRange(gridSize, x, z);
if (!uvRect.Overlaps(dirtyRect))
continue;
Vector3 localPos = new Vector3(
terrainSize.x * uvRect.x,
0f,
terrainSize.z * uvRect.y);
Vector3 worldPos = t.transform.TransformPoint(localPos);
Quaternion rotation = Quaternion.identity;
Vector3 scale = new Vector3(terrainSize.x * uvRect.width, 1, terrainSize.z * uvRect.height);
for (int i = baseResolution; i <= maxLevel; ++i)
{
previewMesh = GEditorSettings.Instance.livePreview.GetWireframeMesh(i);
previewPropertyBlock.SetVector("_SubdivRange", new Vector4(
(i - baseResolution) * GCommon.SUB_DIV_STEP,
i != maxLevel ? (i - baseResolution + 1) * GCommon.SUB_DIV_STEP : 1f,
0, 0));
Graphics.DrawMesh(
previewMesh,
Matrix4x4.TRS(worldPos, rotation, scale),
mat,
LayerMask.NameToLayer("Default"),
cam,
0,
previewPropertyBlock);
}
}
}
}
public static void DrawVisibilityLivePreview(GStylizedTerrain t, Camera cam, Texture newHeightMap, bool[] chunkCulling, Texture mask, Matrix4x4 worldPointToMaskMatrix)
{
if (t.transform.rotation != Quaternion.identity ||
t.transform.lossyScale != Vector3.one)
return;
t.TerrainData.Geometry.Internal_CreateNewSubDivisionMap(newHeightMap);
int baseResolution = t.TerrainData.Geometry.MeshBaseResolution;
int resolution = t.TerrainData.Geometry.MeshResolution;
int maxLevel = baseResolution + Mathf.Min(Mathf.FloorToInt(1f / GCommon.SUB_DIV_STEP), resolution - baseResolution);
Vector3 terrainSize = new Vector3(
t.TerrainData.Geometry.Width,
t.TerrainData.Geometry.Height,
t.TerrainData.Geometry.Length);
previewPropertyBlock.Clear();
previewPropertyBlock.SetColor("_Color", new Color(0, 0, 0, 0.6f));
previewPropertyBlock.SetTexture("_HeightMap", newHeightMap);
previewPropertyBlock.SetVector("_Dimension", terrainSize);
previewPropertyBlock.SetVector("_BoundMin", t.transform.position);
previewPropertyBlock.SetVector("_BoundMax", t.transform.TransformPoint(terrainSize));
previewPropertyBlock.SetTexture("_SubdivMap", t.TerrainData.Geometry.Internal_SubDivisionMap);
if (mask == null)
mask = Texture2D.whiteTexture;
previewPropertyBlock.SetTexture("_Mask", mask);
previewPropertyBlock.SetMatrix("_WorldPointToMask", worldPointToMaskMatrix);
Material mat = GInternalMaterials.VisibilityLivePreviewMaterial;
mat.EnableKeyword("USE_MASK");
mat.renderQueue = 4000;
Mesh previewMesh = null;
Rect[] chunkRects = t.GetChunkRects();
for (int i = 0; i < chunkRects.Length; ++i)
{
if (chunkCulling[i] == false)
continue;
Rect r = chunkRects[i];
Vector3 position = new Vector3(r.x, t.transform.position.y, r.y);
Quaternion rotation = Quaternion.identity;
Vector3 scale = new Vector3(r.width, 1, r.height);
Matrix4x4 trs = Matrix4x4.TRS(position, rotation, scale);
for (int res = baseResolution; res <= maxLevel; ++res)
{
previewMesh = GEditorSettings.Instance.livePreview.GetWireframeMesh(res);
previewPropertyBlock.SetVector("_SubdivRange", new Vector4(
(res - baseResolution) * GCommon.SUB_DIV_STEP,
res != maxLevel ? (res - baseResolution + 1) * GCommon.SUB_DIV_STEP : 1f,
0, 0));
Graphics.DrawMesh(
previewMesh,
trs,
mat,
LayerMask.NameToLayer("Default"),
cam,
0,
previewPropertyBlock,
ShadowCastingMode.Off,
false,
null,
LightProbeUsage.Off,
null);
}
}
}
public static void DrawVisibilityLivePreview(GStylizedTerrain t, Camera cam, Texture newHeightMap, Rect dirtyRect)
{
if (t.transform.rotation != Quaternion.identity ||
t.transform.lossyScale != Vector3.one)
return;
t.TerrainData.Geometry.Internal_CreateNewSubDivisionMap(newHeightMap);
int baseResolution = t.TerrainData.Geometry.MeshBaseResolution;
int resolution = t.TerrainData.Geometry.MeshResolution;
int maxLevel = baseResolution + Mathf.Min(Mathf.FloorToInt(1f / GCommon.SUB_DIV_STEP), resolution - baseResolution);
Vector3 terrainSize = new Vector3(
t.TerrainData.Geometry.Width,
t.TerrainData.Geometry.Height,
t.TerrainData.Geometry.Length);
previewPropertyBlock.Clear();
previewPropertyBlock.SetColor("_Color", new Color(0, 0, 0, 0.6f));
previewPropertyBlock.SetTexture("_HeightMap", newHeightMap);
previewPropertyBlock.SetVector("_Dimension", terrainSize);
previewPropertyBlock.SetVector("_BoundMin", t.transform.position);
previewPropertyBlock.SetVector("_BoundMax", t.transform.TransformPoint(terrainSize));
previewPropertyBlock.SetTexture("_SubdivMap", t.TerrainData.Geometry.Internal_SubDivisionMap);
Material mat = GInternalMaterials.VisibilityLivePreviewMaterial;
mat.DisableKeyword("USE_MASK");
mat.renderQueue = 4000;
Mesh previewMesh = null;
int gridSize = t.TerrainData.Geometry.ChunkGridSize;
for (int x = 0; x < gridSize; ++x)
{
for (int z = 0; z < gridSize; ++z)
{
Rect uvRect = GCommon.GetUvRange(gridSize, x, z);
if (!uvRect.Overlaps(dirtyRect))
continue;
Vector3 localPos = new Vector3(
terrainSize.x * uvRect.x,
0f,
terrainSize.z * uvRect.y);
Vector3 worldPos = t.transform.TransformPoint(localPos);
Quaternion rotation = Quaternion.identity;
Vector3 scale = new Vector3(terrainSize.x * uvRect.width, 1, terrainSize.z * uvRect.height);
for (int i = baseResolution; i <= maxLevel; ++i)
{
previewMesh = GEditorSettings.Instance.livePreview.GetWireframeMesh(i);
previewPropertyBlock.SetVector("_SubdivRange", new Vector4(
(i - baseResolution) * GCommon.SUB_DIV_STEP,
i != maxLevel ? (i - baseResolution + 1) * GCommon.SUB_DIV_STEP : 1f,
0, 0));
Graphics.DrawMesh(
previewMesh,
Matrix4x4.TRS(worldPos, rotation, scale),
mat,
LayerMask.NameToLayer("Default"),
cam,
0,
previewPropertyBlock);
}
}
}
}
public static void DrawAlbedoLivePreview(GStylizedTerrain t, Camera cam, Texture newAlbedo, Rect dirtyRect)
{
Material mat = t.TerrainData.Shading.MaterialToRender;
if (mat == null)
return;
previewPropertyBlock.Clear();
if (!string.IsNullOrEmpty(t.TerrainData.Shading.AlbedoMapPropertyName))
{
previewPropertyBlock.SetTexture(t.TerrainData.Shading.AlbedoMapPropertyName, newAlbedo);
}
GTerrainChunk[] chunks = t.GetChunks();
for (int i = 0; i < chunks.Length; ++i)
{
Rect uvRange = chunks[i].GetUvRange();
if (uvRange.Overlaps(dirtyRect))
{
Mesh chunkMesh = chunks[i].GetMesh(0);
if (chunkMesh != null)
{
Graphics.DrawMesh(
chunkMesh,
chunks[i].transform.localToWorldMatrix * Matrix4x4.Translate(Vector3.up * 0.01f),
mat,
chunks[i].gameObject.layer,
cam,
0,
previewPropertyBlock,
t.TerrainData.Rendering.CastShadow,
t.TerrainData.Rendering.ReceiveShadow);
}
}
}
}
public static void DrawMetallicSmoothnessLivePreview(GStylizedTerrain t, Camera cam, Texture newMetallicMap, Rect dirtyRect)
{
Material mat = t.TerrainData.Shading.MaterialToRender;
if (mat == null)
return;
previewPropertyBlock.Clear();
if (!string.IsNullOrEmpty(t.TerrainData.Shading.MetallicMapPropertyName))
{
previewPropertyBlock.SetTexture(t.TerrainData.Shading.MetallicMapPropertyName, newMetallicMap);
}
GTerrainChunk[] chunks = t.GetChunks();
for (int i = 0; i < chunks.Length; ++i)
{
Rect uvRange = chunks[i].GetUvRange();
if (uvRange.Overlaps(dirtyRect))
{
Mesh chunkMesh = chunks[i].GetMesh(0);
if (chunkMesh != null)
{
Graphics.DrawMesh(
chunkMesh,
chunks[i].transform.localToWorldMatrix * Matrix4x4.Translate(Vector3.up * 0.01f),
mat,
chunks[i].gameObject.layer,
cam,
0,
previewPropertyBlock,
t.TerrainData.Rendering.CastShadow,
t.TerrainData.Rendering.ReceiveShadow);
}
}
}
}
public static void DrawAMSLivePreview(GStylizedTerrain t, Camera cam, Texture newAlbedo, Texture newMetallicMap, Rect dirtyRect)
{
Material mat = t.TerrainData.Shading.MaterialToRender;
if (mat == null)
return;
previewPropertyBlock.Clear();
if (!string.IsNullOrEmpty(t.TerrainData.Shading.AlbedoMapPropertyName))
{
previewPropertyBlock.SetTexture(t.TerrainData.Shading.AlbedoMapPropertyName, newAlbedo);
}
if (!string.IsNullOrEmpty(t.TerrainData.Shading.MetallicMapPropertyName))
{
previewPropertyBlock.SetTexture(t.TerrainData.Shading.MetallicMapPropertyName, newMetallicMap);
}
GTerrainChunk[] chunks = t.GetChunks();
for (int i = 0; i < chunks.Length; ++i)
{
Rect uvRange = chunks[i].GetUvRange();
if (uvRange.Overlaps(dirtyRect))
{
Mesh chunkMesh = chunks[i].GetMesh(0);
if (chunkMesh != null)
{
Graphics.DrawMesh(
chunkMesh,
chunks[i].transform.localToWorldMatrix * Matrix4x4.Translate(Vector3.up * 0.01f),
mat,
chunks[i].gameObject.layer,
cam,
0,
previewPropertyBlock,
t.TerrainData.Rendering.CastShadow,
t.TerrainData.Rendering.ReceiveShadow);
}
}
}
}
public static void DrawAMSLivePreview(GStylizedTerrain t, Camera cam, Texture newAlbedo, Texture newMetallicMap, bool[] chunkCulling)
{
Material mat = t.TerrainData.Shading.MaterialToRender;
if (mat == null)
return;
previewPropertyBlock.Clear();
if (!string.IsNullOrEmpty(t.TerrainData.Shading.AlbedoMapPropertyName))
{
previewPropertyBlock.SetTexture(t.TerrainData.Shading.AlbedoMapPropertyName, newAlbedo);
}
if (!string.IsNullOrEmpty(t.TerrainData.Shading.MetallicMapPropertyName))
{
previewPropertyBlock.SetTexture(t.TerrainData.Shading.MetallicMapPropertyName, newMetallicMap);
}
int gridSize = t.TerrainData.Geometry.ChunkGridSize;
GTerrainChunk[] chunks = t.GetChunks();
for (int i = 0; i < chunks.Length; ++i)
{
int chunkIndex = GUtilities.To1DIndex((int)chunks[i].Index.x, (int)chunks[i].Index.y, gridSize);
if (chunkCulling[chunkIndex] == false)
continue;
Graphics.DrawMesh(
chunks[i].GetMesh(0),
chunks[i].transform.localToWorldMatrix * Matrix4x4.Translate(Vector3.up * 0.01f),
mat,
LayerMask.NameToLayer("Default"),
cam,
0,
previewPropertyBlock,
ShadowCastingMode.Off,
false,
null,
LightProbeUsage.Off,
null);
}
}
public static void DrawSplatLivePreview(GStylizedTerrain t, Camera cam, Texture[] newControlMaps, Rect dirtyRect)
{
Material mat = t.TerrainData.Shading.MaterialToRender;
if (mat == null)
return;
int controlMapResolution = t.TerrainData.Shading.SplatControlResolution;
int controlMapCount = t.TerrainData.Shading.SplatControlMapCount;
if (controlMapCount == 0)
return;
previewPropertyBlock.Clear();
for (int i = 0; i < controlMapCount; ++i)
{
if (!string.IsNullOrEmpty(t.TerrainData.Shading.SplatControlMapPropertyName))
{
previewPropertyBlock.SetTexture(t.TerrainData.Shading.SplatControlMapPropertyName + i, newControlMaps[i] ?? Texture2D.blackTexture);
}
}
GTerrainChunk[] chunks = t.GetChunks();
for (int i = 0; i < chunks.Length; ++i)
{
Rect uvRange = chunks[i].GetUvRange();
if (uvRange.Overlaps(dirtyRect))
{
Mesh chunkMesh = chunks[i].GetMesh(0);
if (chunkMesh != null)
{
Graphics.DrawMesh(
chunkMesh,
chunks[i].transform.localToWorldMatrix * Matrix4x4.Translate(Vector3.up * 0.01f),
mat,
chunks[i].gameObject.layer,
cam,
0,
previewPropertyBlock,
t.TerrainData.Rendering.CastShadow,
t.TerrainData.Rendering.ReceiveShadow);
}
}
}
}
public static void DrawSplatLivePreview(GStylizedTerrain t, Camera cam, Texture[] newControlMaps, bool[] chunkCulling)
{
Material mat = t.TerrainData.Shading.MaterialToRender;
if (mat == null)
return;
int controlMapCount = t.TerrainData.Shading.SplatControlMapCount;
if (controlMapCount == 0)
return;
previewPropertyBlock.Clear();
for (int i = 0; i < controlMapCount; ++i)
{
if (!string.IsNullOrEmpty(t.TerrainData.Shading.SplatControlMapPropertyName))
{
previewPropertyBlock.SetTexture(t.TerrainData.Shading.SplatControlMapPropertyName + i, newControlMaps[i] ?? Texture2D.blackTexture);
}
}
int gridSize = t.TerrainData.Geometry.ChunkGridSize;
GTerrainChunk[] chunks = t.GetChunks();
for (int i = 0; i < chunks.Length; ++i)
{
int chunkIndex = GUtilities.To1DIndex((int)chunks[i].Index.x, (int)chunks[i].Index.y, gridSize);
if (chunkCulling[chunkIndex] == false)
continue;
Graphics.DrawMesh(
chunks[i].GetMesh(0),
chunks[i].transform.localToWorldMatrix * Matrix4x4.Translate(Vector3.up * 0.01f),
mat,
LayerMask.NameToLayer("Default"),
cam,
0,
previewPropertyBlock,
ShadowCastingMode.Off,
false,
null,
LightProbeUsage.Off,
null);
}
}
public static void DrawMasksLivePreview(GStylizedTerrain t, Camera cam, Texture[] masks, Color[] colors, Rect dirtyRect, int channel = 0)
{
Material mat = GInternalMaterials.MaskVisualizerMaterial;
if (mat == null)
return;
previewPropertyBlock.Clear();
previewPropertyBlock.SetVector("_Dimension", new Vector4(t.TerrainData.Geometry.Width, t.TerrainData.Geometry.Height, t.TerrainData.Geometry.Length));
GTerrainChunk[] chunks = t.GetChunks();
for (int i = 0; i < chunks.Length; ++i)
{
Rect uvRange = chunks[i].GetUvRange();
if (uvRange.Overlaps(dirtyRect))
{
Mesh chunkMesh = chunks[i].GetMesh(0);
if (chunkMesh != null)
{
for (int j = 0; j < masks.Length; ++j)
{
previewPropertyBlock.SetColor("_Color", colors[j]);
previewPropertyBlock.SetTexture("_MainTex", masks[j]);
previewPropertyBlock.SetInt("_Channel", channel);
Graphics.DrawMesh(
chunkMesh,
chunks[i].transform.localToWorldMatrix * Matrix4x4.Translate(Vector3.up * 0.05f * j),
mat,
chunks[i].gameObject.layer,
cam,
0,
previewPropertyBlock,
t.TerrainData.Rendering.CastShadow,
t.TerrainData.Rendering.ReceiveShadow);
}
}
}
}
}
public static void DrawMasksLivePreview(GStylizedTerrain t, Camera cam, Texture[] masks, Color[] colors, bool[] chunkCulling, int channel = 0)
{
Material mat = GInternalMaterials.MaskVisualizerMaterial;
if (mat == null)
return;
previewPropertyBlock.Clear();
previewPropertyBlock.SetVector("_Dimension", new Vector4(t.TerrainData.Geometry.Width, t.TerrainData.Geometry.Height, t.TerrainData.Geometry.Length));
int gridSize = t.TerrainData.Geometry.ChunkGridSize;
GTerrainChunk[] chunks = t.GetChunks();
for (int i = 0; i < chunks.Length; ++i)
{
int chunkIndex = GUtilities.To1DIndex((int)chunks[i].Index.x, (int)chunks[i].Index.y, gridSize);
if (chunkCulling[chunkIndex] == false)
continue;
Mesh chunkMesh = chunks[i].GetMesh(0);
for (int j = 0; j < masks.Length; ++j)
{
previewPropertyBlock.SetColor("_Color", colors[j]);
previewPropertyBlock.SetTexture("_MainTex", masks[j]);
previewPropertyBlock.SetInt("_Channel", channel);
Graphics.DrawMesh(
chunkMesh,
chunks[i].transform.localToWorldMatrix * Matrix4x4.Translate(Vector3.up * 0.05f * j),
mat,
chunks[i].gameObject.layer,
cam,
0,
previewPropertyBlock,
t.TerrainData.Rendering.CastShadow,
t.TerrainData.Rendering.ReceiveShadow);
}
}
}
public static void DrawTerrainMask(GStylizedTerrain t, Camera cam)
{
if (t.TerrainData == null)
return;
GLivePreviewDrawer.DrawMasksLivePreview(
t, cam,
new Texture[] { t.TerrainData.Mask.MaskMapOrDefault },
new Color[] { Color.red },
GCommon.UnitRect);
}
public static void DrawMask4ChannelsLivePreview(GStylizedTerrain t, Camera cam, Texture masks, Rect dirtyRect)
{
Material mat = GInternalMaterials.Mask4ChannelsMaterial;
if (mat == null)
return;
previewPropertyBlock.Clear();
GTerrainChunk[] chunks = t.GetChunks();
for (int i = 0; i < chunks.Length; ++i)
{
Rect uvRange = chunks[i].GetUvRange();
if (uvRange.Overlaps(dirtyRect))
{
Mesh chunkMesh = chunks[i].GetMesh(0);
if (chunkMesh != null)
{
previewPropertyBlock.SetTexture("_MainTex", masks);
Graphics.DrawMesh(
chunkMesh,
chunks[i].transform.localToWorldMatrix * Matrix4x4.Translate(Vector3.up * 0.05f),
mat,
chunks[i].gameObject.layer,
cam,
0,
previewPropertyBlock,
t.TerrainData.Rendering.CastShadow,
t.TerrainData.Rendering.ReceiveShadow);
}
}
}
}
}
}
#endif
#endif

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: be5610f0d4bdad94d8e33c1f22a8620f
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,18 @@
#if GRIFFIN
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using Unity.Mathematics;
using static Unity.Mathematics.math;
namespace Pinwheel.Griffin
{
public static class GMath
{
public static float Float2Cross(float2 lhs, float2 rhs)
{
return lhs.y * rhs.x - lhs.x * rhs.y;
}
}
}
#endif

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: abfe054d8b10dca4b834067088c3e413
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,26 @@
#if GRIFFIN
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using Unity.Collections;
namespace Pinwheel.Griffin
{
public static class GNativeArrayUtilities
{
public static void Dispose<T>(NativeArray<T> array) where T : struct
{
try
{
if (array.IsCreated)
{
array.Dispose();
}
}
catch (System.InvalidOperationException)
{
}
}
}
}
#endif

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: ea486ed51c2aaad44a1ce11304bae193
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,160 @@
#if GRIFFIN
using UnityEngine;
using System.Collections.Generic;
#if UNITY_EDITOR
using UnityEditor;
#endif
namespace Pinwheel.Griffin
{
public class GNavigationHelper : MonoBehaviour
{
[SerializeField]
private int groupId;
public int GroupId
{
get
{
return groupId;
}
set
{
groupId = value;
}
}
public void CreateStaticObstacles()
{
transform.root.position = Vector3.zero;
transform.root.rotation = Quaternion.identity;
transform.root.localScale = Vector3.one;
transform.position = Vector3.zero;
transform.rotation = Quaternion.identity;
transform.localScale = Vector3.one;
try
{
IEnumerator<GStylizedTerrain> terrains = GStylizedTerrain.ActiveTerrains.GetEnumerator();
while (terrains.MoveNext())
{
GStylizedTerrain t = terrains.Current;
if (groupId < 0 ||
(groupId >= 0 && groupId == t.GroupId))
{
CreateStaticObstacles(t);
}
}
}
catch (GProgressCancelledException)
{
Debug.Log("Create static obstacles process canceled!");
#if UNITY_EDITOR
GCommonGUI.ClearProgressBar();
#endif
}
}
private void CreateStaticObstacles(GStylizedTerrain t)
{
if (t.TerrainData == null)
return;
if (t.TerrainData.Foliage.Trees == null)
return;
if (t.TerrainData.Foliage.Trees.Prototypes.Count == 0)
return;
#if UNITY_EDITOR
string title = "Creating static obstacles";
string info = t.name;
GCommonGUI.CancelableProgressBar(title, info, 0);
#endif
Vector3 terrainSize = new Vector3(
t.TerrainData.Geometry.Width,
t.TerrainData.Geometry.Height,
t.TerrainData.Geometry.Length);
Transform root = GUtilities.GetChildrenWithName(transform, string.Format("{0}_{1}", t.name, t.GetInstanceID()));
List<GTreePrototype> prototypes = t.TerrainData.Foliage.Trees.Prototypes;
GameObject[] templates = new GameObject[prototypes.Count];
for (int i = 0; i < prototypes.Count; ++i)
{
if (!prototypes[i].IsValid)
continue;
GameObject template = Instantiate(prototypes[i].Prefab) as GameObject;
Component[] components = template.GetComponentsInChildren<Component>();
for (int j = 0; j < components.Length; ++j)
{
if (components[j] is Collider)
GUtilities.DestroyObject(components[j]);
if (components[j] is MeshRenderer)
{
MeshRenderer mr = components[j] as MeshRenderer;
mr.sharedMaterials = new Material[] { GInternalMaterials.NavHelperDummyGameObjectMaterial };
mr.shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.Off;
mr.receiveShadows = false;
}
}
#if UNITY_EDITOR
GameObjectUtility.SetStaticEditorFlags(template, StaticEditorFlags.NavigationStatic);
#endif
template.name = prototypes[i].Prefab.name;
templates[i] = template;
}
List<GTreeInstance> instances = t.TerrainData.Foliage.TreeInstances;
for (int i = 0; i < instances.Count; ++i)
{
#if UNITY_EDITOR
GCommonGUI.CancelableProgressBar(title, info, i * 1.0f / instances.Count);
#endif
GTreeInstance tree = instances[i];
if (templates[tree.PrototypeIndex] == null)
continue;
GameObject g = Instantiate(templates[tree.PrototypeIndex]) as GameObject;
g.transform.parent = root;
Vector3 localPos = new Vector3(
tree.Position.x * terrainSize.x,
tree.Position.y * terrainSize.y,
tree.Position.z * terrainSize.z);
Vector3 worldPos = t.transform.TransformPoint(localPos);
g.transform.position = worldPos;
g.transform.rotation = tree.Rotation;
g.transform.localScale = tree.Scale;
g.name = templates[tree.PrototypeIndex].name;
}
for (int i = 0; i < templates.Length; ++i)
{
GUtilities.DestroyGameobject(templates[i]);
}
#if UNITY_EDITOR
GCommonGUI.ClearProgressBar();
#endif
}
public void DeleteStaticObstacles()
{
IEnumerator<GStylizedTerrain> terrains = GStylizedTerrain.ActiveTerrains.GetEnumerator();
while (terrains.MoveNext())
{
GStylizedTerrain t = terrains.Current;
if (groupId < 0 ||
(groupId >= 0 && groupId == t.GroupId))
{
DeleteStaticObstacles(t);
}
}
}
private void DeleteStaticObstacles(GStylizedTerrain t)
{
Transform root = GUtilities.GetChildrenWithName(transform, string.Format("{0}_{1}", t.name, t.GetInstanceID()));
GUtilities.DestroyGameobject(root.gameObject);
}
}
}
#endif

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 8a3b6f0716f5e5145ace8eff95c00c98
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,9 @@
#if GRIFFIN
namespace Pinwheel.Griffin
{
public enum GNormalMapMode
{
Sharp, Interpolated, PerPixel
}
}
#endif

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 7772edc54763e0c4abfcd23688e42651
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,9 @@
#if GRIFFIN
namespace Pinwheel.Griffin
{
public enum GNormalMapSpace
{
Local, Tangent
}
}
#endif

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 629577f656be30d489094d001789d6e5
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,110 @@
#if GRIFFIN
using UnityEngine;
namespace Pinwheel.Griffin
{
public class GObjectHelper : MonoBehaviour
{
[SerializeField]
private GStylizedTerrain terrain;
public GStylizedTerrain Terrain
{
get
{
return terrain;
}
set
{
terrain = value;
}
}
[SerializeField]
private GSnapMode snapMode;
public GSnapMode SnapMode
{
get
{
return snapMode;
}
set
{
snapMode = value;
}
}
[SerializeField]
private LayerMask layerMask;
public LayerMask LayerMask
{
get
{
return layerMask;
}
set
{
layerMask = value;
}
}
[SerializeField]
private bool alignToSurface;
public bool AlignToSurface
{
get
{
return alignToSurface;
}
set
{
alignToSurface = value;
}
}
public void Snap()
{
RaycastHit hit = new RaycastHit();
Ray r = new Ray();
r.direction = Vector3.down;
Transform[] children = GUtilities.GetChildrenTransforms(transform);
for (int i = 0; i < children.Length; ++i)
{
r.origin = new Vector3(children[i].position.x, 10000, children[i].position.z);
bool isHit = false;
if (SnapMode == GSnapMode.Terrain)
{
isHit = Terrain.Raycast(r, out hit, float.MaxValue);
}
else if (SnapMode == GSnapMode.World)
{
RaycastHit hitTerrain;
bool isHitTerrain = Terrain.Raycast(r, out hitTerrain, float.MaxValue);
float terrainHitPoint = isHitTerrain ? hitTerrain.point.y : -10000;
RaycastHit hitWorld;
bool isHitWorld = Physics.Raycast(r, out hitWorld, float.MaxValue, LayerMask);
float worldHitPoint = isHitWorld ? hitWorld.point.y : -10000;
isHit = isHitTerrain || isHitWorld;
hit = terrainHitPoint > worldHitPoint ? hitTerrain : hitWorld;
}
if (isHit)
{
#if UNITY_EDITOR
UnityEditor.Undo.RecordObject(children[i], "Snap");
#endif
children[i].transform.position = hit.point;
children[i].transform.up = Vector3.up;
if (AlignToSurface)
{
children[i].transform.up = hit.normal;
}
}
}
}
}
}
#endif

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 4a6e0af9dd7f8404fabcf9e165316dc3
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,15 @@
#if GRIFFIN
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
namespace Pinwheel.Griffin
{
public struct GOverlapTestResult
{
public GStylizedTerrain Terrain;
public bool IsOverlapped;
public bool[] IsChunkOverlapped;
}
}
#endif

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 22b0803b41a425d43954a5e6140880d8
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,10 @@
#if GRIFFIN
using System;
namespace Pinwheel.Griffin
{
public class GProgressCancelledException : Exception
{
}
}
#endif

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 5e5e02e76e76583468abad853b4677ab
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,36 @@
#if GRIFFIN
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
namespace Pinwheel.Griffin
{
public struct GPrototypeInstanceInfo
{
public int prototypeIndex;
public Vector3 position;
public Quaternion rotation;
public Vector3 scale;
public GGrassInstance ToGrassInstance()
{
GGrassInstance g = new GGrassInstance();
g.prototypeIndex = prototypeIndex;
g.position = position;
g.rotation = rotation;
g.scale = scale;
return g;
}
public GTreeInstance ToTreeInstance()
{
GTreeInstance t = new GTreeInstance();
t.prototypeIndex = prototypeIndex;
t.position = position;
t.rotation = rotation;
t.scale = scale;
return t;
}
}
}
#endif

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: f96dd29f1f47d734fa9604450092e5f5
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,46 @@
#if GRIFFIN
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using Unity.Mathematics;
namespace Pinwheel.Griffin
{
public struct GQuad2D
{
public float2 p0, p1, p2, p3;
public GQuad2D(float2 p0, float2 p1, float2 p2, float2 p3)
{
this.p0 = p0;
this.p1 = p1;
this.p2 = p2;
this.p3 = p3;
}
public bool Contains(float2 point)
{
Vector2 d0, d1;
float c0, c1, c2, c3;
d0 = p1 - p0;
d1 = point - p0;
c0 = GMath.Float2Cross(d0, d1);
d0 = p2 - p1;
d1 = point - p1;
c1 = GMath.Float2Cross(d0, d1);
d0 = p3 - p2;
d1 = point - p2;
c2 = GMath.Float2Cross(d0, d1);
d0 = p0 - p3;
d1 = point - p3;
c3 = GMath.Float2Cross(d0, d1);
return c0 > 0 && c1 > 0 && c2 > 0 && c3 > 0;
}
}
}
#endif

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 448b67aa5db7fa8499fe89e782747404
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,9 @@
#if GRIFFIN
namespace Pinwheel.Griffin
{
public enum GRenderPipelineType
{
Builtin, Universal, Unsupported
}
}
#endif

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 1e85497977b38544a8f43dc41ada02fc
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,9 @@
#if GRIFFIN
namespace Pinwheel.Griffin
{
public enum GSnapMode
{
Terrain, World
}
}
#endif

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: d4191ebd7e4285b4393c61b0dc02520f
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,9 @@
#if GRIFFIN
namespace Pinwheel.Griffin
{
public enum GSplatsModel
{
Splats4, Splats4Normals4, Splats8
}
}
#endif

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: bcea112d77e9bd840bca93808e1695cd
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,14 @@
#if GRIFFIN
using UnityEngine;
namespace Pinwheel.Griffin
{
/// <summary>
/// Dummy class to detect if terrain tools are added to the scene
/// </summary>
[AddComponentMenu("")]
public class GTerrainTools : MonoBehaviour
{
}
}
#endif

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 90c4fd16064f8b54582f074762555f4d
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,28 @@
#if GRIFFIN
using UnityEngine;
namespace Pinwheel.Griffin
{
//[CreateAssetMenu(menuName = "Griffin/Text Asset")]
public class GTextAsset : ScriptableObject
{
[SerializeField]
private string text;
public string Text
{
get
{
return text;
}
set
{
text = value;
}
}
public void Reset()
{
}
}
}
#endif

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 7ff9f750a290ac74599355288dcaa417
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,17 @@
#if GRIFFIN
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
namespace Pinwheel.Griffin
{
[System.Flags]
public enum GTextureChannel
{
R = 1,
G = 2,
B = 4,
A = 8
}
}
#endif

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: fb5584e4789e08c418e5bb84e0713f23
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,52 @@
#if GRIFFIN
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using Unity.Collections;
namespace Pinwheel.Griffin
{
public struct GTextureNativeDataDescriptor<T> where T : struct
{
[ReadOnly]
public NativeArray<T> data;
public int width;
public int height;
private bool isValid;
public bool IsValid
{
get
{
return isValid;
}
}
public GTextureNativeDataDescriptor(Texture2D tex)
{
if (tex != null)
{
data = tex.GetRawTextureData<T>();
width = tex.width;
height = tex.height;
isValid = true;
}
else
{
data = new NativeArray<T>(1, Allocator.Persistent);
width = 0;
height = 0;
isValid = false;
}
}
public void Dispose()
{
if (!isValid)
{
GNativeArrayUtilities.Dispose(data);
}
}
}
}
#endif

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 2c37df5ad7d13124bad41d428108a9c2
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,9 @@
#if GRIFFIN
namespace Pinwheel.Griffin
{
public enum GTexturingModel
{
GradientLookup, ColorMap, Splat, VertexColor
}
}
#endif

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 210a13564010c984492b49737074b00a
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,869 @@
#if GRIFFIN
using System.Collections.Generic;
using UnityEngine;
#if UNITY_EDITOR
using UnityEditor;
#endif
using Unity.Collections;
using Unity.Mathematics;
namespace Pinwheel.Griffin
{
/// <summary>
/// Utility class for helper function
/// </summary>
public static class GUtilities
{
public static float DELTA_TIME = 0.0167f;
private static Mesh quadMesh;
public static Mesh QuadMesh
{
get
{
if (quadMesh == null)
{
quadMesh = GUtilities.GetPrimitiveMesh(PrimitiveType.Quad);
}
return quadMesh;
}
}
public static string ListElementsToString<T>(this IEnumerable<T> list, string separator)
{
IEnumerator<T> i = list.GetEnumerator();
System.Text.StringBuilder s = new System.Text.StringBuilder();
if (i.MoveNext())
s.Append(i.Current.ToString());
while (i.MoveNext())
s.Append(separator).Append(i.Current.ToString());
return s.ToString();
}
public static T[][] CreateJaggedArray<T>(int dimension1, int dimension2)
{
T[][] jaggedArray = new T[dimension1][];
for (int i = 0; i < dimension1; ++i)
{
jaggedArray[i] = new T[dimension2];
}
return jaggedArray;
}
public static T[] To1dArray<T>(T[][] jaggedArray)
{
List<T> result = new List<T>();
for (int z = 0; z < jaggedArray.Length; ++z)
{
for (int x = 0; x < jaggedArray[z].Length; ++x)
{
result.Add(jaggedArray[z][x]);
}
}
return result.ToArray();
}
public static T[] To1dArray<T>(T[,] grid)
{
int height = grid.GetLength(0);
int width = grid.GetLength(1);
T[] result = new T[height * width];
for (int z = 0; z < height; ++z)
{
for (int x = 0; x < width; ++x)
{
result[To1DIndex(x, z, width)] = grid[z, x];
}
}
return result;
}
public static void Fill<T>(NativeArray<T> array, T value) where T : struct
{
int length = array.Length;
for (int i = 0; i < length; ++i)
{
array[i] = value;
}
}
public static void Fill<T>(T[] array, T value)
{
for (int i = 0; i < array.Length; ++i)
{
array[i] = value;
}
}
public static void CopyTo<T>(T[] src, T[] des)
{
int limit = Mathf.Min(src.Length, des.Length);
for (int i = 0; i < limit; ++i)
{
des[i] = src[i];
}
}
public static int Sum(int[,] array)
{
int sum = 0;
int length = array.GetLength(0);
int width = array.GetLength(1);
for (int z = 0; z < length; ++z)
{
for (int x = 0; x < width; ++x)
{
sum += array[z, x];
}
}
return sum;
}
public static int To1DIndex(int x, int z, int width)
{
return z * width + x;
}
public static bool IsInRange(float number, float minValue, float maxValue)
{
return number >= minValue && number <= maxValue;
}
public static bool IsInRangeExclusive(float number, float minValue, float maxValue)
{
return number > minValue && number < maxValue;
}
public static float GetFraction(float value, float floor, float ceil)
{
return (value - floor) / (ceil - floor);
}
public static void ClearChildren(Transform t)
{
int childCount = t.childCount;
for (int i = childCount - 1; i >= 0; --i)
{
#if UNITY_EDITOR
if (!UnityEditor.EditorApplication.isPlaying)
{
GameObject.DestroyImmediate(t.GetChild(i).gameObject);
}
else
{
GameObject.Destroy(t.GetChild(i).gameObject);
}
#else
GameObject.Destroy(t.GetChild(i).gameObject);
#endif
}
}
public static Gradient CreateFullWhiteGradient()
{
Gradient g = new Gradient();
GradientColorKey color = new GradientColorKey(Color.white, 1);
GradientAlphaKey alpha = new GradientAlphaKey(1, 1);
g.SetKeys(new GradientColorKey[] { color }, new GradientAlphaKey[] { alpha });
return g;
}
public static Gradient CreateFullTransparentGradient()
{
Gradient g = new Gradient();
GradientColorKey color = new GradientColorKey(Color.white, 1);
GradientAlphaKey alpha = new GradientAlphaKey(0, 1);
g.SetKeys(new GradientColorKey[] { color }, new GradientAlphaKey[] { alpha });
return g;
}
public static void CalculateBarycentricCoord(Vector2 p, Vector2 p1, Vector2 p2, Vector2 p3, ref Vector3 bary)
{
Vector2 v0 = p2 - p1;
Vector2 v1 = p3 - p1;
Vector2 v2 = p - p1;
float d00 = Vector2.Dot(v0, v0);
float d01 = Vector2.Dot(v0, v1);
float d11 = Vector2.Dot(v1, v1);
float d20 = Vector2.Dot(v2, v0);
float d21 = Vector2.Dot(v2, v1);
float inverseDenom = 1 / (d00 * d11 - d01 * d01);
bary.y = (d11 * d20 - d01 * d21) * inverseDenom;
bary.z = (d00 * d21 - d01 * d20) * inverseDenom;
bary.x = 1.0f - bary.y - bary.z;
}
public static void ExpandTrisUvCoord(Texture2D tex, Vector2[] trisUv)
{
Vector2 texelSize = tex.texelSize;
Vector2 center = (trisUv[0] + trisUv[1] + trisUv[2]) / 3;
trisUv[0] += (trisUv[0] - center).normalized * texelSize.magnitude;
trisUv[0].x = Mathf.Clamp01(trisUv[0].x);
trisUv[0].y = Mathf.Clamp01(trisUv[0].y);
trisUv[1] += (trisUv[1] - center).normalized * texelSize.magnitude;
trisUv[1].x = Mathf.Clamp01(trisUv[1].x);
trisUv[1].y = Mathf.Clamp01(trisUv[1].y);
trisUv[2] += (trisUv[2] - center).normalized * texelSize.magnitude;
trisUv[2].x = Mathf.Clamp01(trisUv[2].x);
trisUv[2].y = Mathf.Clamp01(trisUv[2].y);
}
public static bool ContainIdenticalElements<T>(T[] arr1, T[] arr2)
{
if (arr1 == null && arr2 == null)
return true;
if (arr1 == null && arr2 != null)
return false;
if (arr1 != null && arr2 == null)
return false;
if (arr1.Length != arr2.Length)
return false;
for (int i = 0; i < arr1.Length; ++i)
{
if (!arr1[i].Equals(arr2[i]))
return false;
}
return true;
}
public static float GetNearestMultiple(float number, float multipleOf)
{
int multiplier = 0;
while (multipleOf * multiplier < number)
{
multiplier += 1;
}
float floor = multipleOf * (multiplier - 1);
float ceil = multipleOf * multiplier;
float f0 = number - floor;
float f1 = ceil - number;
if (f0 < f1)
return floor;
else
return ceil;
}
public static Transform GetChildrenWithName(Transform parent, string name)
{
Transform t = parent.Find(name);
if (t == null)
{
GameObject g = new GameObject(name);
g.transform.parent = parent;
ResetTransform(g.transform, parent);
t = g.transform;
}
return t;
}
public static void ResetTransform(Transform t, Transform parent)
{
t.parent = parent;
t.localPosition = Vector3.zero;
t.localRotation = Quaternion.identity;
t.localScale = Vector3.one;
}
public static void DestroyGameobject(GameObject g)
{
#if UNITY_EDITOR
if (UnityEditor.EditorApplication.isPlaying)
GameObject.Destroy(g);
else
GameObject.DestroyImmediate(g);
#else
GameObject.Destroy(g);
#endif
}
public static void DestroyGameObjectWithUndo(GameObject g)
{
#if UNITY_EDITOR
Undo.DestroyObjectImmediate(g);
#else
DestroyGameobject(g);
#endif
}
public static void DestroyObject(Object o)
{
#if UNITY_EDITOR
if (UnityEditor.EditorApplication.isPlaying)
Object.Destroy(o);
else
Object.DestroyImmediate(o, true);
#else
GameObject.Destroy(o);
#endif
}
public static string Repeat(char src, int count)
{
System.Text.StringBuilder sb = new System.Text.StringBuilder();
sb.Append(src, count);
return sb.ToString();
}
public static void MarkCurrentSceneDirty()
{
#if UNITY_EDITOR
if (!UnityEditor.EditorApplication.isPlaying)
UnityEditor.SceneManagement.EditorSceneManager.MarkSceneDirty(UnityEditor.SceneManagement.EditorSceneManager.GetActiveScene());
#endif
}
public static GameObject[] GetChildrenGameObjects(Transform parent)
{
GameObject[] children = new GameObject[parent.childCount];
for (int i = 0; i < parent.childCount; ++i)
{
children[i] = parent.GetChild(i).gameObject;
}
return children;
}
public static Transform[] GetChildrenTransforms(Transform parent)
{
Transform[] children = new Transform[parent.childCount];
for (int i = 0; i < parent.childCount; ++i)
{
children[i] = parent.GetChild(i);
}
return children;
}
/// <summary>
/// https://en.wikipedia.org/wiki/Rodrigues%27_rotation_formula
/// </summary>
/// <param name="vector"></param>
/// <param name="normal"></param>
/// <param name="angleDegree"></param>
/// <returns></returns>
public static Vector3 RotateVectorAroundNormal(Vector3 vector, Vector3 normal, float angleDegree)
{
float sin = Mathf.Sin(angleDegree * Mathf.Deg2Rad);
float cos = Mathf.Cos(angleDegree * Mathf.Deg2Rad);
Vector3 rotatedVector =
vector * cos +
Vector3.Cross(normal, vector) * sin +
normal * Vector3.Dot(normal, vector) * (1 - cos);
return rotatedVector;
}
public static Mesh GetPrimitiveMesh(PrimitiveType type)
{
GameObject g = GameObject.CreatePrimitive(type);
Mesh m = g.GetComponent<MeshFilter>().sharedMesh;
DestroyGameobject(g);
return m;
}
public static void ShuffleList<T>(List<T> list)
{
int length = list.Count;
for (int i = 0; i < length - 1; ++i)
{
int j = UnityEngine.Random.Range(0, length);
T tmp = list[i];
list[i] = list[j];
list[j] = tmp;
}
}
public static int[] GetShuffleIndicesArray(int length)
{
int[] indices = GetIndicesArray(length);
for (int i = 0; i < length - 1; ++i)
{
int j = UnityEngine.Random.Range(0, length);
int tmp = indices[i];
indices[i] = indices[j];
indices[j] = tmp;
}
return indices;
}
public static int[] GetIndicesArray(int length)
{
int[] indices = new int[length];
for (int i = 0; i < length; ++i)
{
indices[i] = i;
}
return indices;
}
public static void ResetArray<T>(ref T[] array, int count, T defaultValue)
{
if (array != null && array.Length == count)
{
GUtilities.Fill(array, defaultValue);
}
else
{
array = new T[count];
}
}
public static bool EnsureArrayLength<T>(ref T[] array, int count)
{
if (array == null || array.Length != count)
{
array = new T[count];
return false;
}
return true;
}
public static float GetValueBilinear(float[] data, int width, int height, Vector2 uv)
{
float value = 0;
Vector2 pixelCoord = new Vector2(
Mathf.Lerp(0, width - 1, uv.x),
Mathf.Lerp(0, height - 1, uv.y));
//apply a bilinear filter
int xFloor = Mathf.FloorToInt(pixelCoord.x);
int xCeil = Mathf.CeilToInt(pixelCoord.x);
int yFloor = Mathf.FloorToInt(pixelCoord.y);
int yCeil = Mathf.CeilToInt(pixelCoord.y);
float f00 = data[GUtilities.To1DIndex(xFloor, yFloor, width)];
float f01 = data[GUtilities.To1DIndex(xFloor, yCeil, width)];
float f10 = data[GUtilities.To1DIndex(xCeil, yFloor, width)];
float f11 = data[GUtilities.To1DIndex(xCeil, yCeil, width)];
Vector2 unitCoord = new Vector2(
pixelCoord.x - xFloor,
pixelCoord.y - yFloor);
value =
f00 * (1 - unitCoord.x) * (1 - unitCoord.y) +
f01 * (1 - unitCoord.x) * unitCoord.y +
f10 * unitCoord.x * (1 - unitCoord.y) +
f11 * unitCoord.x * unitCoord.y;
return value;
}
public static Color GetColorBilinear(Color[] textureData, int width, int height, Vector2 uv)
{
Color color = Color.clear;
Vector2 pixelCoord = new Vector2(
Mathf.Lerp(0, width - 1, uv.x),
Mathf.Lerp(0, height - 1, uv.y));
//apply a bilinear filter
int xFloor = Mathf.FloorToInt(pixelCoord.x);
int xCeil = Mathf.CeilToInt(pixelCoord.x);
int yFloor = Mathf.FloorToInt(pixelCoord.y);
int yCeil = Mathf.CeilToInt(pixelCoord.y);
Color f00 = textureData[GUtilities.To1DIndex(xFloor, yFloor, width)];
Color f01 = textureData[GUtilities.To1DIndex(xFloor, yCeil, width)];
Color f10 = textureData[GUtilities.To1DIndex(xCeil, yFloor, width)];
Color f11 = textureData[GUtilities.To1DIndex(xCeil, yCeil, width)];
Vector2 unitCoord = new Vector2(
pixelCoord.x - xFloor,
pixelCoord.y - yFloor);
color =
f00 * (1 - unitCoord.x) * (1 - unitCoord.y) +
f01 * (1 - unitCoord.x) * unitCoord.y +
f10 * unitCoord.x * (1 - unitCoord.y) +
f11 * unitCoord.x * unitCoord.y;
return color;
}
public static GameObject CreatePreviewGameObject(Mesh m, Material mat, Vector3 position)
{
GameObject g = new GameObject("GO");
g.transform.position = position;
g.transform.rotation = Quaternion.identity;
g.transform.localScale = Vector3.one;
MeshFilter mf = g.AddComponent<MeshFilter>();
mf.sharedMesh = m;
MeshRenderer mr = g.AddComponent<MeshRenderer>();
mr.shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.Off;
mr.receiveShadows = false;
mr.sharedMaterial = mat;
return g;
}
public static Camera CreatePreviewCamera(GameObject target, float distance, float padding)
{
GameObject g = new GameObject("CAM");
g.transform.rotation = Quaternion.identity;
g.transform.localScale = Vector3.one;
Camera cam = g.AddComponent<Camera>();
cam.orthographic = true;
cam.clearFlags = CameraClearFlags.Nothing;
cam.aspect = 1;
MeshRenderer mr = target.GetComponent<MeshRenderer>();
Bounds bounds = mr.bounds;
cam.transform.position = bounds.center + new Vector3(-1, 0.5f, -1) * distance;
cam.transform.LookAt(bounds.center);
cam.orthographicSize = Mathf.Max(bounds.size.x, bounds.size.y, bounds.size.z) / 2 + padding;
return cam;
}
public static void EnsureDirectoryExists(string dir)
{
if (!System.IO.Directory.Exists(dir))
{
System.IO.Directory.CreateDirectory(dir);
}
}
public static void SetStaticRecursively(GameObject g, bool isStatic)
{
#if UNITY_EDITOR
g.isStatic = isStatic;
GameObject[] children = GetChildrenGameObjects(g.transform);
for (int i = 0; i < children.Length; ++i)
{
SetStaticRecursively(children[i], isStatic);
}
#endif
}
public static void EnsureLengthSufficient<T>(List<T> list, int preferredLength) where T : Object
{
if (list == null)
list = new List<T>();
while (list.Count < preferredLength)
{
list.Add(null);
}
}
public static void EnsureLengthSufficient(List<string> list, int preferredLength)
{
if (list == null)
list = new List<string>();
while (list.Count < preferredLength)
{
list.Add(string.Empty);
}
}
public static void EnsureLengthSufficient(List<bool> list, int preferredLength)
{
if (list == null)
list = new List<bool>();
while (list.Count < preferredLength)
{
list.Add(false);
}
}
public static string Ellipsis(string s, int length)
{
if (s.Length < length)
return s;
string s0 = s.Substring(0, length);
return s0 + "...";
}
public static bool IsRectContainPointExclusive(Rect r, Vector2 p)
{
return
p.x > r.min.x &&
p.x < r.max.x &&
p.y > r.min.y &&
p.y < r.max.y;
}
public static Color GetColor(Color baseColor, float alpha)
{
return new Color(baseColor.r, baseColor.g, baseColor.b, alpha);
}
public static Rect GetRectContainsPoints(params Vector2[] points)
{
float xMin = float.MaxValue;
float xMax = float.MinValue;
float yMin = float.MaxValue;
float yMax = float.MinValue;
for (int i = 0; i < points.Length; ++i)
{
xMin = points[i].x < xMin ? points[i].x : xMin;
xMax = points[i].x > xMax ? points[i].x : xMax;
yMin = points[i].y < yMin ? points[i].y : yMin;
yMax = points[i].y > yMax ? points[i].y : yMax;
}
return Rect.MinMaxRect(xMin, yMin, xMax, yMax);
}
public static Rect GetRectContainsPoints(params Vector3[] points)
{
float xMin = float.MaxValue;
float xMax = float.MinValue;
float zMin = float.MaxValue;
float zMax = float.MinValue;
for (int i = 0; i < points.Length; ++i)
{
xMin = points[i].x < xMin ? points[i].x : xMin;
xMax = points[i].x > xMax ? points[i].x : xMax;
zMin = points[i].z < zMin ? points[i].z : zMin;
zMax = points[i].z > zMax ? points[i].z : zMax;
}
return Rect.MinMaxRect(xMin, zMin, xMax, zMax);
}
public static float InverseLerpUnclamped(float a, float b, float value)
{
if (a != b)
{
return (value - a) / (b - a);
}
return 0f;
}
public static Vector2 PointToNormalizedUnclampled(Rect r, Vector2 point)
{
return new Vector2(InverseLerpUnclamped(r.x, r.xMax, point.x), InverseLerpUnclamped(r.y, r.yMax, point.y));
}
public static Rect GetUvRect(Vector2 v0, Vector2 v1, Vector2 v2)
{
return Rect.MinMaxRect(
Mathf.Min(v0.x, v1.x, v2.x),
Mathf.Min(v0.y, v1.y, v2.y),
Mathf.Max(v0.x, v1.x, v2.x),
Mathf.Max(v0.y, v1.y, v2.y));
}
public static Gradient Clone(Gradient src)
{
if (src == null)
return null;
Gradient des = new Gradient();
des.SetKeys(src.colorKeys, src.alphaKeys);
return des;
}
public static AnimationCurve Clone(AnimationCurve src)
{
if (src == null)
return null;
AnimationCurve des = new AnimationCurve();
Keyframe[] keys = src.keys;
for (int i = 0; i < keys.Length; ++i)
{
des.AddKey(keys[i]);
}
des.preWrapMode = src.preWrapMode;
des.postWrapMode = src.postWrapMode;
return des;
}
public static bool IsPointInsideQuadXZ(Vector3 point, Vector3[] quad)
{
Vector3 bary = Vector3.zero;
CalculateBarycentricCoord(
new Vector2(point.x, point.z),
new Vector2(quad[0].x, quad[0].z),
new Vector2(quad[1].x, quad[1].z),
new Vector2(quad[2].x, quad[2].z),
ref bary);
if (bary.x >= 0 && bary.y >= 0 && bary.z >= 0)
return true;
CalculateBarycentricCoord(
new Vector2(point.x, point.z),
new Vector2(quad[0].x, quad[0].z),
new Vector2(quad[2].x, quad[2].z),
new Vector2(quad[3].x, quad[3].z),
ref bary);
if (bary.x >= 0 && bary.y >= 0 && bary.z >= 0)
return true;
return false;
}
public static void DestroyMeshArray(Mesh[] meshes)
{
for (int i = 0; i < meshes.Length; ++i)
{
if (meshes[i] != null)
{
Object.DestroyImmediate(meshes[i], true);
}
}
}
public static Vector2 FlipY(Vector2 v)
{
return new Vector2(v.x, 1 - v.y);
}
/// <summary>
/// https://en.wikipedia.org/wiki/Delaunay_triangulation#Algorithms
/// </summary>
/// <param name="v0"></param>
/// <param name="v1"></param>
/// <param name="v2"></param>
/// <param name="p"></param>
/// <returns></returns>
public static bool IsPointInCircumcircle(Vector2 v0, Vector2 v1, Vector2 v2, Vector2 p)
{
Matrix4x4 mat = new Matrix4x4();
mat.SetRow(0, new Vector4(v0.x, v0.y, v0.x * v0.x + v0.y * v0.y, 1));
mat.SetRow(1, new Vector4(v2.x, v2.y, v2.x * v2.x + v2.y * v2.y, 1)); //a,b,c counterclockwise
mat.SetRow(2, new Vector4(v1.x, v1.y, v1.x * v1.x + v1.y * v1.y, 1));
mat.SetRow(3, new Vector4(p.x, p.y, p.x * p.x + p.y * p.y, 1));
return mat.determinant > 0;
}
public static bool IsPointInCircumcircleXZ(Vector3 v0, Vector3 v1, Vector3 v2, Vector3 p)
{
Matrix4x4 mat = new Matrix4x4();
mat.SetRow(0, new Vector4(v0.x, v0.z, v0.x * v0.x + v0.z * v0.z, 1));
mat.SetRow(1, new Vector4(v2.x, v2.z, v2.x * v2.x + v2.z * v2.z, 1)); //a,b,c counterclockwise
mat.SetRow(2, new Vector4(v1.x, v1.z, v1.x * v1.x + v1.z * v1.z, 1));
mat.SetRow(3, new Vector4(p.x, p.z, p.x * p.x + p.z * p.z, 1));
return mat.determinant > 0;
}
public static bool AreSetEqual(ushort[] setA, ushort[] setB)
{
HashSet<ushort> a = new HashSet<ushort>(setA);
HashSet<ushort> b = new HashSet<ushort>(setB);
return a.SetEquals(b);
}
//public static void Distinct<T>(this List<T> list)
//{
// list.Distinct();
//}
public static void AddIfNotContains<T>(this IList<T> list, IEnumerable<T> items)
{
IEnumerator<T> iter = items.GetEnumerator();
while (iter.MoveNext())
{
T current = iter.Current;
if (!list.Contains(current))
{
list.Add(current);
}
}
}
public static void AddIfNotContains<T>(this IList<T> list, T item)
{
if (!list.Contains(item))
{
list.Add(item);
}
}
public static Vector3 ToX0Y(this Vector2 v)
{
return new Vector3(v.x, 0, v.y);
}
public static Vector3 Mul(this Vector3 v0, Vector3 v1)
{
return new Vector3(v0.x * v1.x, v0.y * v1.y, v0.z * v1.z);
}
public static Rect MergeRects(IEnumerable<Rect> rects)
{
float minX = float.MaxValue;
float maxX = float.MinValue;
float minY = float.MaxValue;
float maxY = float.MinValue;
IEnumerator<Rect> i = rects.GetEnumerator();
while (i.MoveNext())
{
Rect r = i.Current;
minX = Mathf.Min(minX, r.xMin);
minY = Mathf.Min(minY, r.yMin);
maxX = Mathf.Max(maxX, r.xMax);
maxY = Mathf.Max(maxY, r.yMax);
}
float width = maxX - minX;
float height = maxY - minY;
return new Rect(minX, minY, width, height);
}
public static bool IsSceneViewOrGameCamera(Camera cam)
{
return cam.cameraType == CameraType.SceneView || cam.cameraType == CameraType.Game;
}
public static bool IsPrefabCamera(Camera cam)
{
#if UNITY_EDITOR
UnityEditor.SceneManagement.PrefabStage prefabStage = UnityEditor.SceneManagement.PrefabStageUtility.GetCurrentPrefabStage();
if (prefabStage != null)
{
if (prefabStage.scene == cam.scene)
return true;
}
#endif
return false;
}
public static bool TestOverlap(Rect r, IEnumerable<Rect> other)
{
IEnumerator<Rect> i = other.GetEnumerator();
while (i.MoveNext())
{
if (r.Overlaps(i.Current))
{
return true;
}
}
return false;
}
public static float Vector2Cross(Vector2 lhs, Vector2 rhs)
{
return lhs.y * rhs.x - lhs.x * rhs.y;
}
public static List<GStylizedTerrain> ExtractTerrainsFromOverlapTest(List<GOverlapTestResult> sweepTests)
{
List<GStylizedTerrain> terrains = new List<GStylizedTerrain>();
foreach (GOverlapTestResult st in sweepTests)
{
if (st.IsOverlapped)
{
terrains.Add(st.Terrain);
}
}
return terrains;
}
public static void Swap<T>(List<T> list, int firstIndex, int secondIndex)
{
T temp = list[firstIndex];
list[firstIndex] = list[secondIndex];
list[secondIndex] = temp;
}
}
}
#endif

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: a29a808106281554aafcda59815b3131
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,58 @@
#if GRIFFIN
namespace Pinwheel.Griffin
{
/// <summary>
/// Utility class contains product info
/// </summary>
public static class GVersionInfo
{
public static float Number
{
get
{
return 2021.1f;
}
}
public static string Code
{
get
{
return "2021.1.5";
}
}
public static string ProductName
{
get
{
return "Polaris - Low Poly Terrain Engine";
}
}
public static string ProductNameAndVersion
{
get
{
return string.Format("{0} {1}", ProductName, Code);
}
}
public static string ProductNameShort
{
get
{
return "Polaris";
}
}
public static string ProductNameAndVersionShort
{
get
{
return string.Format("{0} {1}", ProductNameShort, Code);
}
}
}
}
#endif

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 976fd8605c9c40442bb71ddd6d12e570
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,125 @@
#if GRIFFIN
using System.Collections.Generic;
using UnityEngine;
namespace Pinwheel.Griffin
{
[ExecuteInEditMode]
public class GWindZone : MonoBehaviour
{
private static HashSet<GWindZone> activeWindZoneSet;
private static HashSet<GWindZone> ActiveWindZoneSet
{
get
{
if (activeWindZoneSet == null)
activeWindZoneSet = new HashSet<GWindZone>();
return activeWindZoneSet;
}
}
public static IEnumerable<GWindZone> ActiveWindZones
{
get
{
return ActiveWindZoneSet;
}
}
[SerializeField]
private float directionX;
public float DirectionX
{
get
{
return directionX;
}
set
{
directionX = value;
}
}
[SerializeField]
private float directionZ;
public float DirectionZ
{
get
{
return directionZ;
}
set
{
directionZ = value;
}
}
[SerializeField]
private float speed;
public float Speed
{
get
{
return speed;
}
set
{
speed = value;
}
}
[SerializeField]
private float spread;
public float Spread
{
get
{
return spread;
}
set
{
spread = value;
}
}
private void Reset()
{
directionX = 1;
directionZ = 1;
speed = 4;
spread = 8;
}
private void OnEnable()
{
ActiveWindZoneSet.Add(this);
}
private void OnDisable()
{
ActiveWindZoneSet.Remove(this);
}
public Vector4 GetWindParams()
{
Vector2 dir = new Vector2(DirectionX, DirectionZ).normalized;
Vector4 param = new Vector4(dir.x, dir.y, speed, spread);
return param;
}
public void SyncTransform()
{
transform.rotation = Quaternion.identity;
transform.forward = new Vector3(DirectionX, 0, DirectionZ).normalized;
}
public void SyncDirection()
{
Matrix4x4 matrix = Matrix4x4.Rotate(transform.rotation);
Vector3 dir = matrix.MultiplyVector(Vector3.forward);
DirectionX = dir.x;
DirectionZ = dir.z;
}
}
}
#endif

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 5f45d81229cedc24ba508bace3cd2fcb
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: