Initial commit

This commit is contained in:
msk
2022-01-22 20:13:49 -08:00
parent f9d23e5bcf
commit 687473573d
878 changed files with 70957 additions and 0 deletions
@@ -0,0 +1,190 @@
// Alloy Physical Shader Framework
// Copyright 2013-2017 RUST LLC.
// http://www.alloy.rustltd.com/
using UnityEngine;
using UnityEditor;
#if H3VR_IMPORTED
[CustomEditor(typeof(AlloyAreaLight))]
[CanEditMultipleObjects]
public class AlloyAreaLightEditor : Editor {
public override void OnInspectorGUI() {
serializedObject.Update();
var hasSpecularHightlight = serializedObject.FindProperty("m_hasSpecularHightlight");
var maxRange = float.MaxValue;
var isSpecularAreaLight = false;
var isPointLight = false;
// Light Type.
foreach (AlloyAreaLight area in targets) {
var light = area.GetComponent<Light>();
if (light.type == LightType.Directional) {
maxRange = 1.0f;
}
else {
maxRange = Mathf.Min(light.range, maxRange);
}
isPointLight = light.type == LightType.Point;
if (isPointLight
|| light.type == LightType.Spot
|| light.type == LightType.Directional) {
isSpecularAreaLight = true;
}
}
// Specular Highlight.
if (isSpecularAreaLight) {
hasSpecularHightlight.boolValue = EditorGUILayout.Toggle("Specular Highlight", hasSpecularHightlight.boolValue);
isSpecularAreaLight = isSpecularAreaLight && hasSpecularHightlight.boolValue;
}
// Radius.
if (isSpecularAreaLight) {
EditorGUILayout.Slider(serializedObject.FindProperty("m_radius"), 0.0f, maxRange);
} else {
var radius = serializedObject.FindProperty("m_radius");
if (radius.floatValue != 0.0f) {
GUI.changed = true;
radius.floatValue = 0.0f;
}
}
// Length.
if (isSpecularAreaLight && isPointLight) {
EditorGUILayout.Slider(serializedObject.FindProperty("m_length"), 0.0f, maxRange * 2.0f);
} else {
var length = serializedObject.FindProperty("m_length");
if (length.floatValue != 0.0f) {
GUI.changed = true;
length.floatValue = 0.0f;
}
}
serializedObject.ApplyModifiedProperties();
if (GUI.changed) {
foreach (AlloyAreaLight area in targets) {
area.UpdateBinding();
}
}
}
internal static void DrawTwoShadedWireDisc(Vector3 position, Vector3 axis, float radius) {
Color color1 = Handles.color;
Color color2 = color1;
color1.a *= 0.2f;
Handles.color = color1;
Handles.DrawWireDisc(position, axis, radius);
Handles.color = color2;
}
internal static void DrawTwoShadedWireDisc(Vector3 position, Vector3 axis, Vector3 from, float degrees, float radius) {
Handles.DrawWireArc(position, axis, from, degrees, radius);
Color cur = Handles.color;
Color set = cur;
set.a *= 0.2f;
Handles.color = set;
Handles.DrawWireArc(position, axis, from, degrees - 360f, radius);
Handles.color = cur;
}
static Vector3[] s_directionArray = {
Vector3.right,
Vector3.up,
Vector3.forward,
-Vector3.right,
-Vector3.up,
-Vector3.forward
};
static void DoRadiusHandle(Vector3 position, float radius, float length) {
Vector3 dif = position - Camera.current.transform.position;
float sqrMagnitude = dif.sqrMagnitude;
float radiusSqr = radius * radius;
float radiusDiv = radiusSqr * radiusSqr / sqrMagnitude;
//float ratio = radiusDiv / radiusSqr;
float total = Mathf.Sqrt(radiusSqr - radiusDiv);
Handles.DrawWireDisc(position - radiusSqr * dif / sqrMagnitude, dif, total);
for (int j = 0; j < 3; j++) {
float angle = Vector3.Angle(dif, s_directionArray[j]);
angle = 90f - Mathf.Min(angle, 180f - angle);
float tanAngle = Mathf.Tan(angle * Mathf.Deg2Rad);
float viewSize = Mathf.Sqrt(radiusDiv + tanAngle * tanAngle * radiusDiv) / radius;
if (viewSize < 1f) {
float finalArcAngle = Mathf.Asin(viewSize) * Mathf.Rad2Deg;
Vector3 vector2 = Vector3.Cross(s_directionArray[j], dif).normalized;
vector2 = Quaternion.AngleAxis(finalArcAngle, s_directionArray[j]) * vector2;
DrawTwoShadedWireDisc(position, s_directionArray[j], vector2, (90f - finalArcAngle) * 2f, radius);
}
else {
DrawTwoShadedWireDisc(position, s_directionArray[j], radius);
}
}
}
float DrawCapsuleGizmo(Transform transform, float radius, float length) {
var fwd = Vector3.forward * radius;
var side = Vector3.up * radius;
var halfLength = 0.5f * length;
// Exclude light transform scale, and pre-rotate capsule to follow the Y-axis.
Handles.matrix = Matrix4x4.TRS(transform.position, transform.rotation, Vector3.one)
* Matrix4x4.TRS(Vector3.zero, Quaternion.Euler(0.0f, 0.0f, 90.0f), Vector3.one);
Handles.DrawWireArc(-halfLength * Vector3.right, Vector3.forward, Vector3.up, 180.0f, radius);
Handles.DrawWireArc(-halfLength * Vector3.right, Vector3.up, -Vector3.forward, 180.0f, radius);
Handles.DrawWireArc(halfLength * Vector3.right, Vector3.forward, -Vector3.up, 180.0f, radius);
Handles.DrawWireArc(halfLength * Vector3.right, Vector3.up, Vector3.forward, 180.0f, radius);
Handles.DrawWireDisc(-halfLength * Vector3.right, Vector3.right, radius);
Handles.DrawWireDisc(halfLength * Vector3.right, Vector3.right, radius);
Handles.DrawLine(-halfLength * Vector3.right + fwd, halfLength * Vector3.right + fwd);
Handles.DrawLine(-halfLength * Vector3.right - fwd, halfLength * Vector3.right - fwd);
Handles.DrawLine(-halfLength * Vector3.right + side, halfLength * Vector3.right + side);
Handles.DrawLine(-halfLength * Vector3.right - side, halfLength * Vector3.right - side);
if (!Event.current.alt && !Event.current.shift) {
radius = Handles.RadiusHandle(Quaternion.identity, -halfLength * Vector3.right, radius, true);
radius = Handles.RadiusHandle(Quaternion.identity, halfLength * Vector3.right, radius, true);
}
Handles.matrix = Matrix4x4.identity;
return radius;
}
void OnSceneGUI() {
var area = target as AlloyAreaLight;
var light = area.GetComponent<Light>();
if (light.type == LightType.Point
|| light.type == LightType.Spot) {
area.Radius = DrawCapsuleGizmo(area.transform, area.Radius, area.Length);
}
//DoRadiusHandle(area.transform.position, area.Size, 1.0f);
if (GUI.changed) {
Undo.RecordObject(area, "Adjust area light");
}
}
}
#endif
@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 895b6d1a02c68594f89e4586bdfff530
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
@@ -0,0 +1,51 @@
// Alloy Physical Shader Framework
// Copyright 2013-2017 RUST LLC.
// http://www.alloy.rustltd.com/
using UnityEditor;
using UnityEngine;
public static class AlloyLightCreator {
#if H3VR_IMPORTED
const string c_lightMenuPath = "GameObject/Light/";
const string c_undoMessage = "Created ";
const string c_directionalLight = "Alloy Directional Light";
const string c_pointLight = "Alloy Point Light";
const string c_spotLight = "Alloy Spotlight";
[MenuItem(c_lightMenuPath + c_directionalLight)]
static void CreateDirectionalLight() {
BuildLight(c_directionalLight, LightType.Directional);
}
[MenuItem(c_lightMenuPath + c_pointLight)]
static void CreateSphereAreaLight() {
BuildLight(c_pointLight, LightType.Point);
}
[MenuItem(c_lightMenuPath + c_spotLight)]
static void CreateSpotSphereAreaLight() {
BuildLight(c_spotLight, LightType.Spot);
}
static void BuildLight(string name, LightType type) {
var go = new GameObject();
var lastSceneView = SceneView.lastActiveSceneView;
Undo.RegisterCreatedObjectUndo(go, c_undoMessage + name);
go.name = name;
var light = go.AddComponent<Light>();
light.type = type;
go.AddComponent<AlloyAreaLight>();
if (lastSceneView != null)
go.transform.position = lastSceneView.pivot;
else
go.transform.position = Vector3.zero;
Selection.activeGameObject = go;
}
#endif
}
@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: f5d3ae613b034fe4599db89f5c75351a
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
@@ -0,0 +1,67 @@
// Alloy Physical Shader Framework
// Copyright 2013-2017 RUST LLC.
// http://www.alloy.rustltd.com/
using System;
using System.Linq;
using System.Reflection;
using MeatKit;
using UnityEditor;
using UnityEngine;
[CustomEditor(typeof(Light))]
[CanEditMultipleObjects]
public class AlloyLightEditor : Editor {
#if H3VR_IMPORTED
Editor m_editor;
Action m_onSceneGUIReflected;
Type GetTypeGlobal(string typeName) {
return AppDomain.CurrentDomain.GetAssemblies().SelectMany(a => a.GetTypesSafe()).FirstOrDefault(t => t.Name == typeName);
}
void OnEnable() {
m_editor = CreateEditor(targets, GetTypeGlobal("LightEditor"));
Undo.undoRedoPerformed += RebindAreaLights;
RebindAreaLights();
m_onSceneGUIReflected = (Action)Delegate.CreateDelegate(typeof(Action), m_editor, "OnSceneGUI", false, true);
}
void OnSceneGUI() {
m_onSceneGUIReflected();
}
void OnDisable() {
Undo.undoRedoPerformed -= RebindAreaLights;
//Calls on destroy on light editor
DestroyImmediate(m_editor);
}
public override void OnInspectorGUI() {
m_editor.OnInspectorGUI();
bool anyMissing = targets.Any(l => ((Light)l).GetComponent<Light>().type != LightType.Area
&& ((Light)l).GetComponent<AlloyAreaLight>() == null);
if (anyMissing) {
if (GUILayout.Button("Convert to Alloy area light", EditorStyles.toolbarButton)) {
foreach (Light light in targets) {
Undo.AddComponent<AlloyAreaLight>(light.gameObject);
}
}
}
if (GUI.changed) {
RebindAreaLights();
}
}
void RebindAreaLights() {
var lights = targets.Select(l => ((Light)l).GetComponent<AlloyAreaLight>()).Where(a => a != null);
foreach (AlloyAreaLight ar in lights) {
ar.UpdateBinding();
}
}
#endif
}
@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: f83832185bd1caa4d9aab41ddfbc423d
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName: