-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
26 changed files
with
1,096 additions
and
174 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
using System; | ||
using UnityEditor; | ||
using UnityEditor.PackageManager; | ||
using UnityEditor.PackageManager.Requests; | ||
using UnityEngine; | ||
|
||
public static class PackageVersion | ||
{ | ||
private static ListRequest _request; | ||
private static int _progressId; | ||
|
||
/// <summary> | ||
/// Package check will start on Editor start | ||
/// </summary> | ||
[InitializeOnLoadMethod] | ||
public static void GetPackageList() | ||
{ | ||
// List packages installed for the project | ||
_request = Client.List(); | ||
_progressId = Progress.Start("Package version check"); | ||
//Injection update loop | ||
EditorApplication.update += VersionCheck; | ||
} | ||
|
||
/// <summary> | ||
/// Make sure the collection version conforms to the specification | ||
/// </summary> | ||
/// <exception cref="ArgumentOutOfRangeException">Error in Status</exception> | ||
private static void VersionCheck() | ||
{ | ||
switch (_request.Status) | ||
{ | ||
case StatusCode.Success: | ||
{ | ||
Progress.Report(_progressId, 2, 3, "Checking the version"); | ||
//version detection operation | ||
foreach (var info in _request.Result) | ||
if (info.name == "com.unity.collections") | ||
Debug.Log(info.version); | ||
|
||
Progress.Report(_progressId, 3, 3); | ||
break; | ||
} | ||
case StatusCode.Failure: | ||
{ | ||
Debug.LogWarning(_request.Error.message); | ||
break; | ||
} | ||
case StatusCode.InProgress: | ||
{ | ||
Progress.Report(_progressId, 1, 3, "Waiting package list"); | ||
return; | ||
} | ||
default: | ||
throw new ArgumentOutOfRangeException(); | ||
} | ||
|
||
Progress.Remove(_progressId); | ||
EditorApplication.update -= VersionCheck; | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
using Unity.Collections; | ||
using Unity.Jobs; | ||
using UnityEngine; | ||
|
||
internal struct BakeNormalJob : IJobParallelFor | ||
{ | ||
[ReadOnly] private NativeArray<Vector3> _normals; | ||
[ReadOnly] private NativeArray<Vector4> _tangents; | ||
[ReadOnly] private NativeArray<Vector3> _vertex; | ||
[ReadOnly] private NativeParallelMultiHashMap<Vector3, Vector3> _result; | ||
[ReadOnly] private readonly bool _existColors; | ||
private NativeArray<Color> _colors; | ||
|
||
public BakeNormalJob(NativeArray<Vector3> vertex, NativeArray<Vector3> normals, NativeArray<Vector4> tangents, | ||
NativeParallelMultiHashMap<Vector3, Vector3> result, bool existColors, NativeArray<Color> colors) | ||
{ | ||
_normals = normals; | ||
_tangents = tangents; | ||
_vertex = vertex; | ||
_result = result; | ||
_existColors = existColors; | ||
_colors = colors; | ||
} | ||
|
||
void IJobParallelFor.Execute(int index) | ||
{ | ||
var smoothedNormals = Vector3.zero; | ||
var vertex = _vertex[index]; | ||
|
||
foreach (var values in _result.GetValuesForKey(vertex)) smoothedNormals += values; | ||
|
||
smoothedNormals = smoothedNormals.normalized; | ||
|
||
var biNormal = (Vector3.Cross(_normals[index], _tangents[index]) * _tangents[index].w).normalized; | ||
|
||
var tbn = new Matrix4x4( | ||
_tangents[index], | ||
biNormal, | ||
_normals[index], | ||
Vector4.zero); | ||
tbn = tbn.transpose; | ||
|
||
//Calculate the normal vector in model space | ||
var bakedNormal = tbn.MultiplyVector(smoothedNormals).normalized; | ||
|
||
//Remapping [-1,1] to [0,1] | ||
var color = new Color | ||
{ | ||
r = bakedNormal.x * 0.5f + 0.5f, | ||
g = bakedNormal.y * 0.5f + 0.5f, | ||
b = bakedNormal.z * 0.5f + 0.5f, | ||
/* | ||
* Choose a color channel | ||
* b = _existColors ? m_Colors[index].b : 1, | ||
*/ | ||
a = _existColors ? _colors[index].a : 1 | ||
}; | ||
_colors[index] = color; | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
using Unity.Collections; | ||
using Unity.Jobs; | ||
using UnityEngine; | ||
|
||
internal struct CollectNormalJob : IJobParallelFor | ||
{ | ||
// Mark read-only to improve performance | ||
[ReadOnly] private NativeArray<Vector3> _normals, _vertex; | ||
|
||
private NativeParallelMultiHashMap<Vector3, Vector3>.ParallelWriter _result; | ||
|
||
public CollectNormalJob(NativeArray<Vector3> normals, NativeArray<Vector3> vertex, | ||
NativeParallelMultiHashMap<Vector3, Vector3>.ParallelWriter result) | ||
{ | ||
_normals = normals; | ||
_vertex = vertex; | ||
_result = result; | ||
} | ||
|
||
void IJobParallelFor.Execute(int index) | ||
{ | ||
_result.Add(_vertex[index], _normals[index]); | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
Oops, something went wrong.