Merge branch 'master' into mtoon10showcase

This commit is contained in:
amamagi
2025-04-03 12:01:19 +09:00
154 changed files with 41635 additions and 2830 deletions

View File

@@ -45,7 +45,7 @@ MonoBehaviour:
value: 65472
diffusion:
overrideState: 1
value: 7
value: 6.4
anamorphicRatio:
overrideState: 0
value: 0

View File

@@ -21,18 +21,20 @@ namespace UniGLTF.SpringBoneJobs
{
private FastSpringBoneCombinedBuffer _combinedBuffer;
public FastSpringBoneCombinedBuffer Combined => _combinedBuffer;
private readonly LinkedList<FastSpringBoneBuffer> _buffers = new LinkedList<FastSpringBoneBuffer>();
private Queue<(bool isAdd, FastSpringBoneBuffer buffer)> _request = new();
private readonly List<FastSpringBoneBuffer> _buffers = new();
struct Request
{
public FastSpringBoneBuffer Remove;
public FastSpringBoneBuffer Add;
}
private Queue<Request> _request = new();
public bool HasBuffer => _buffers.Count > 0 && _combinedBuffer != null;
public void Register(FastSpringBoneBuffer buffer)
public void Register(FastSpringBoneBuffer add, FastSpringBoneBuffer remove)
{
_request.Enqueue((true, buffer));
}
public void Unregister(FastSpringBoneBuffer buffer)
{
_request.Enqueue((false, buffer));
_request.Enqueue(new Request { Remove = remove, Add = add });
}
/// <summary>
@@ -52,11 +54,6 @@ namespace UniGLTF.SpringBoneJobs
var logicsIndex = 0;
foreach (var buffer in _buffers)
{
if (_request.Any(x => !x.isAdd && x.buffer == buffer))
{
// 削除するので skip
continue;
}
buffer.BackupCurrentTails(combined.CurrentTails, combined.NextTails, logicsIndex);
logicsIndex += buffer.Logics.Length;
}
@@ -65,15 +62,20 @@ namespace UniGLTF.SpringBoneJobs
// buffer 増減
while (_request.Count > 0)
{
var (isAdd, buffer) = _request.Dequeue();
if (isAdd)
var req = _request.Dequeue();
if (req.Remove != null && req.Add != null)
{
// 速度 0 にす
_buffers.AddLast(buffer);
// 順番が変わらないように入れ替え
var index = _buffers.IndexOf(req.Remove);
_buffers[index] = req.Add;
}
else
else if (req.Add != null)
{
_buffers.Remove(buffer);
_buffers.Add(req.Add);
}
else if (req.Remove != null)
{
_buffers.Remove(req.Remove);
}
}

View File

@@ -78,11 +78,14 @@ namespace UniGLTF.SpringBoneJobs
_batchedBufferLogicSizes = batchedBufferLogicSizes;
}
/// <summary>
/// Job向けに、Lidt[FastSpringBoneBuffer] をひとつの FastSpringBoneCombinedBuffer に統合する
/// </summary>
internal static JobHandle Create(JobHandle handle,
LinkedList<FastSpringBoneBuffer> _buffers, out FastSpringBoneCombinedBuffer combined)
IReadOnlyList<FastSpringBoneBuffer> buffers, out FastSpringBoneCombinedBuffer combined)
{
Profiler.BeginSample("FastSpringBone.ReconstructBuffers.CopyToBatchedBuffers");
var batchedBuffers = _buffers.ToArray();
var batchedBuffers = buffers.ToArray();
var batchedBufferLogicSizes = batchedBuffers.Select(buffer => buffer.Logics.Length).ToArray();
Profiler.EndSample();
@@ -92,7 +95,7 @@ namespace UniGLTF.SpringBoneJobs
var collidersCount = 0;
var logicsCount = 0;
var transformsCount = 0;
foreach (var buffer in _buffers)
foreach (var buffer in buffers)
{
springsCount += buffer.Springs.Length;
collidersCount += buffer.Colliders.Length;
@@ -103,7 +106,7 @@ namespace UniGLTF.SpringBoneJobs
// バッファの構築
Profiler.BeginSample("FastSpringBone.ReconstructBuffers.CreateBuffers");
combined = new FastSpringBoneCombinedBuffer(logicsCount, springsCount, _buffers.Count,
combined = new FastSpringBoneCombinedBuffer(logicsCount, springsCount, buffers.Count,
collidersCount, transformsCount, batchedBuffers, batchedBufferLogicSizes);
Profiler.EndSample();
@@ -300,6 +303,9 @@ namespace UniGLTF.SpringBoneJobs
public void Execute(int springIndex)
{
var spring = Springs[springIndex];
var center = spring.centerTransformIndex >= 0
? Transforms[spring.transformIndexOffset + spring.centerTransformIndex]
: (BlittableTransform?)null;
for (int jointIndex = spring.logicSpan.startIndex; jointIndex < spring.logicSpan.EndIndex; ++jointIndex)
{
if (float.IsNaN(CurrentTails[jointIndex].x))
@@ -317,9 +323,10 @@ namespace UniGLTF.SpringBoneJobs
}
var tail = Transforms[tailIndex];
CurrentTails[jointIndex] = tail.position;
PrevTails[jointIndex] = tail.position;
NextTails[jointIndex] = tail.position;
var tailPos = center.HasValue ? center.Value.worldToLocalMatrix.MultiplyPoint3x4(tail.position) : tail.position;
CurrentTails[jointIndex] = tailPos;
PrevTails[jointIndex] = tailPos;
NextTails[jointIndex] = tailPos;
}
}
}

View File

@@ -310,9 +310,6 @@ namespace UniGLTF
{
var node = data.GLTF.nodes[channel.target.node];
var mesh = data.GLTF.meshes[node.mesh];
var primitive = mesh.primitives.FirstOrDefault();
var targets = primitive.targets;
if (!gltf_mesh_extras_targetNames.TryGet(mesh, out List<string> targetNames))
{
throw new UniGLTFNotSupportedException("glTF BlendShape Animation. targetNames invalid.");

View File

@@ -3,16 +3,23 @@
/// <summary>
/// 指定の index の glTFMaterial から Import できる Material の生成情報を生成する。
/// glTFMaterial と Unity Material は 1:1 対応する。
///
/// IMaterialDescriptorGenerator の使われ方は MaterialFactory.LoadAsync を参照
/// </summary>
public interface IMaterialDescriptorGenerator
{
/// <summary>
/// Generate the MaterialDescriptor generated from the index i.
/// <code>
/// glTFMaterial src = data.GLTF.materials[i];
/// return new MaterialDescriptor();
/// </code>
/// </summary>
MaterialDescriptor Get(GltfData data, int i);
/// <summary>
/// Generate the MaterialDescriptor for the non-specified glTF material.
/// Generate the fallback MaterialDescriptor for the non-specified glTF material.
/// <see href="https://registry.khronos.org/glTF/specs/2.0/glTF-2.0.html#default-material"/>
/// </summary>
MaterialDescriptor GetGltfDefault(string materialName = null);
}

View File

@@ -5,18 +5,82 @@ using UnityEngine;
namespace UniGLTF
{
/// <summary>
/// Material information generated by IMaterialDescriptorGenerator
/// In recent versions, it is easy to manipulate Materials directly using Actions.
///
/// Actions の使用例は UniGLTF.UrpGltfMaterialDescriptorGenerator を参照
/// </summary>
public sealed class MaterialDescriptor
{
public delegate Task MaterialGenerateAsyncFunc(Material m, GetTextureAsyncFunc getTexture, IAwaitCaller awaitCaller);
/// <summary>
/// <code>
/// material.name = matDesc.SubAssetKey.Name;
/// </code>
/// </summary>
public readonly string Name;
/// <summary>
/// <code>
/// material = new Material(matDesc.Shader);
/// </code>
/// </summary>
public readonly Shader Shader;
/// <summary>
/// <code>
/// material.renderQueue = matDesc.RenderQueue.Value;
/// </code>
/// </summary>
public readonly int? RenderQueue;
public readonly IReadOnlyDictionary<string, TextureDescriptor> TextureSlots;
/// <summary>
/// <code>
/// foreach (var kv in matDesc.FloatValues)
/// {
/// material.SetFloat(kv.Key, kv.Value);
/// }
/// </code>
/// </summary>
public readonly IReadOnlyDictionary<string, float> FloatValues;
/// <summary>
/// <code>
/// foreach (var kv in matDesc.Colors)
/// {
/// material.SetColor(kv.Key, kv.Value);
/// }
/// </code>
/// </summary>
public readonly IReadOnlyDictionary<string, Color> Colors;
/// <summary>
/// <code>
/// foreach (var kv in matDesc.Vectors)
/// {
/// material.SetVector(kv.Key, kv.Value);
/// }
/// </code>
/// </summary>
public readonly IReadOnlyDictionary<string, Vector4> Vectors;
/// <summary>
/// Process and construct the argument Material
/// <code>
/// material.SetTexture(prop, texture);
/// material.SetColor(prop, color);
/// </code>
/// </summary>
public readonly IReadOnlyList<Action<Material>> Actions;
/// <summary>
/// New api. for new code, this is a convenience.
/// MaterialGenerateAsyncFunc has full access to material and can get all textures.
/// </summary>
public readonly IReadOnlyList<MaterialGenerateAsyncFunc> AsyncActions;
public SubAssetKey SubAssetKey => new SubAssetKey(SubAssetKey.MaterialType, Name);
@@ -42,5 +106,21 @@ namespace UniGLTF
Actions = actions;
AsyncActions = asyncActions ?? new List<MaterialGenerateAsyncFunc>();
}
public MaterialDescriptor(
string name,
Shader shader,
IReadOnlyList<MaterialGenerateAsyncFunc> asyncActions)
{
Name = name;
Shader = shader;
RenderQueue = default;
TextureSlots = new Dictionary<string, TextureDescriptor>();
FloatValues = new Dictionary<string, float>();
Colors = new Dictionary<string, Color>();
Vectors = new Dictionary<string, Vector4>();
Actions = new List<Action<Material>>();
AsyncActions = asyncActions;
}
}
}

View File

@@ -78,6 +78,10 @@ namespace UniGLTF
{
return false;
}
if (Mesh.triangles.Length == 0)
{
return false;
}
if (Materials == null)
{
return false;

View File

@@ -69,8 +69,9 @@ namespace UniGLTF
public NativeArray<T> CreateNativeArray<T>(ArraySegment<T> data) where T : struct
{
var array = CreateNativeArray<T>(data.Count);
for (int i = 0; i < data.Count; i++)
array[i] = data.Array[data.Offset + i];
var toSpan = array.AsSpan();
var fromSpan = data.AsSpan();
fromSpan.CopyTo(toSpan);
return array;
}

View File

@@ -9,6 +9,18 @@ namespace UniGLTF
/// </summary>
public sealed class UnitySupportedImageTypeDeserializer : ITextureDeserializer
{
/// <summary>
/// `true` を指定すると、テクスチャを Non-Readable なものとしてデシリアライズする。
/// </summary>
/// <remarks>
/// `UnityEngine.ImageConversion.LoadImage` の第二引数 `markNonReadable` に相当。
/// デフォルト値は `false`。
/// テクスチャ編集を行わないアプリケーションプログラム等では、
/// この値を `true` にすることでメモリ使用量の削減を期待できる。
/// このフラグの効用については `UnityEngine.Texture2D.Apply` に記述がある。
/// </remarks>
public bool MarkNonReadable { get; set; } = false;
public async Task<Texture2D> LoadTextureAsync(DeserializingTextureInfo textureInfo, IAwaitCaller awaitCaller)
{
if (textureInfo.ImageData == null) return null;
@@ -16,7 +28,7 @@ namespace UniGLTF
try
{
var texture = new Texture2D(2, 2, TextureFormat.ARGB32, textureInfo.UseMipmap, textureInfo.ColorSpace == ColorSpace.Linear);
texture.LoadImage(textureInfo.ImageData);
texture.LoadImage(textureInfo.ImageData, MarkNonReadable);
await awaitCaller.NextFrame();
texture.wrapModeU = textureInfo.WrapModeU;

View File

@@ -273,6 +273,12 @@ namespace UniGLTF
? MeshExporter_DividedVertexBuffer.Export(_data, unityMesh, Materials, m_settings.InverseAxis.Create(), m_settings)
: MeshExporter_SharedVertexBuffer.Export(_data, unityMesh, Materials, m_settings.InverseAxis.Create(), m_settings)
;
if (gltfMesh.primitives == null || gltfMesh.primitives.Count == 0)
{
Debug.LogError($"gltfMesh.primitives is empty: {unityMesh.Mesh.name}");
}
_gltf.meshes.Add(gltfMesh);
Meshes.Add(unityMesh.Mesh);
if (!MeshBlendShapeIndexMap.ContainsKey(unityMesh.Mesh))

View File

@@ -5,7 +5,7 @@ namespace UniGLTF
{
public const int MAJOR = 0;
public const int MINOR = 128;
public const int PATCH = 1;
public const string VERSION = "0.128.1";
public const int PATCH = 3;
public const string VERSION = "0.128.3";
}
}

View File

@@ -5,7 +5,7 @@ namespace UniGLTF
{
public const int MAJOR = 2;
public const int MINOR = 64;
public const int PATCH = 1;
public const string VERSION = "2.64.1";
public const int PATCH = 3;
public const string VERSION = "2.64.3";
}
}

View File

@@ -129,7 +129,7 @@ namespace UniHumanoid
public Avatar CreateAvatar(Transform root)
{
// force unique name
ForceUniqueName.Process(root);
ForceTransformUniqueName.Validate(root);
return AvatarBuilder.BuildHumanAvatar(root.gameObject, ToHumanDescription(root));
}

View File

@@ -65,6 +65,15 @@ namespace UniHumanoid
}
HumanPoseHandler m_handler;
public void Dispose()
{
if (m_handler != null)
{
m_handler.Dispose();
m_handler = null;
}
}
public void OnEnable()
{
if (TryGetComponent<Animator>(out var animator))
@@ -75,12 +84,18 @@ namespace UniHumanoid
Setup();
}
void OnDisable()
{
Dispose();
}
public void Setup()
{
if (Avatar == null)
{
return;
}
Dispose();
m_handler = new HumanPoseHandler(Avatar, transform);
}

View File

@@ -9,7 +9,7 @@ namespace UniHumanoid
{
public static Avatar LoadHumanoidAvatar(Transform root, IEnumerable<(Transform, HumanBodyBones)> boneMap)
{
ForceUniqueName.Process(root);
UniGLTF.Utils.ForceTransformUniqueName.Process(root);
var description = new HumanDescription
{

View File

@@ -1,18 +1,35 @@
using System;
using System.Collections.Generic;
using UniGLTF;
using UnityEngine;
namespace UniHumanoid
namespace UniGLTF.Utils
{
class ForceUniqueName
public class ForceTransformUniqueName
{
HashSet<string> m_uniqueNameSet = new HashSet<string>();
int m_counter = 1;
public static bool Validate(Transform root)
{
HashSet<string> uniqueNameSet = new HashSet<string>();
var transforms = root.GetComponentsInChildren<Transform>();
foreach (var t in transforms)
{
if (uniqueNameSet.Contains(t.name))
{
UniGLTFLogger.Warning($"duplicate name: {t.name}");
}
else
{
uniqueNameSet.Add(t.name);
}
}
return uniqueNameSet.Count == transforms.Length;
}
public static void Process(Transform root)
{
var uniqueName = new ForceUniqueName();
var uniqueName = new ForceTransformUniqueName();
var transforms = root.GetComponentsInChildren<Transform>();
foreach (var t in transforms)
{

View File

@@ -1,6 +1,6 @@
{
"name": "com.vrmc.gltf",
"version": "0.128.1",
"version": "0.128.3",
"displayName": "UniGLTF",
"description": "GLTF importer and exporter",
"unity": "2021.3",

View File

@@ -7,24 +7,24 @@ using System;
namespace VRM
{
/// <summary>
/// VersionDialog
///
/// v0.81.0: com.vrmc.unigltf to com.vrmc.gltf and same version with univrm.
///
/// Major = 2
/// Minor = VRMVersion.MINOR - 64
/// Patch = VRMVersion.PATCH
///
/// </summary>
public class VRMVersionMenu : EditorWindow
{
/// <summary>
/// VersionDialog
///
/// v0.81.0: com.vrmc.unigltf to com.vrmc.gltf and same version with univrm.
///
/// Major = 2
/// Minor = VRMVersion.MINOR - 64
/// Patch = VRMVersion.PATCH
///
/// UNIGLTF
/// </summary>
public class VRMVersionMenu : EditorWindow
{
/// <summary>
/// UNIGLTF
/// </summary>
static string UniGltfVersionPath = "Assets/UniGLTF/Runtime/UniGLTF/UniGLTFVersion.cs";
static string UniGltfVersionPath = "Assets/UniGLTF/Runtime/UniGLTF/UniGLTFVersion.cs";
const string UniGltfVersionTemplate = @"
const string UniGltfVersionTemplate = @"
namespace UniGLTF
{{
public static partial class UniGLTFVersion
@@ -37,11 +37,11 @@ namespace UniGLTF
}}
";
/// <summary>
/// VRM
/// </summary>
const string VrmVersionPath = "Assets/UniGLTF/Runtime/UniGLTF/PackageVersion.cs";
const string VrmVersionTemplate = @"
/// <summary>
/// VRM
/// </summary>
const string VrmVersionPath = "Assets/UniGLTF/Runtime/UniGLTF/PackageVersion.cs";
const string VrmVersionTemplate = @"
namespace UniGLTF
{{
public static partial class PackageVersion
@@ -54,20 +54,20 @@ namespace UniGLTF
}}
";
struct UpmPackage
{
public readonly string Path;
public readonly string Template;
struct UpmPackage
{
public readonly string Path;
public readonly string Template;
public UpmPackage(string path, string template)
{
Path = path;
Template = template;
}
}
public UpmPackage(string path, string template)
{
Path = path;
Template = template;
}
}
UpmPackage[] Packages = new UpmPackage[]
{
UpmPackage[] Packages = new UpmPackage[]
{
new UpmPackage("Assets/VRM/package.json",
@"{{
""name"": ""com.vrmc.univrm"",
@@ -142,14 +142,19 @@ namespace UniGLTF
""displayName"": ""VRM10FirstPersonSample"",
""description"": ""First Person layer sample with multi camera"",
""path"": ""Samples~/VRM10FirstPersonSample""
}},
{{
""displayName"": ""ClothSample"",
""description"": ""Experimental cloth implementation"",
""path"": ""Samples~/ClothSample""
}}
]
}}
"),
};
};
UpmPackage UniGLTFPackage = new UpmPackage("Assets/UniGLTF/package.json",
UpmPackage UniGLTFPackage = new UpmPackage("Assets/UniGLTF/package.json",
@"{{
""name"": ""com.vrmc.gltf"",
""version"": ""{0}"",
@@ -174,137 +179,137 @@ namespace UniGLTF
]
}}");
[SerializeField]
string m_vrmVersion;
[SerializeField]
string m_vrmVersion;
(int, int, int) m_uniGltfVersion
(int, int, int) m_uniGltfVersion
{
get
{
if (TryGetVersion(m_vrmVersion, out (int, int, int) vrmVersion))
{
get
{
if (TryGetVersion(m_vrmVersion, out (int, int, int) vrmVersion))
{
return (2, vrmVersion.Item2 - 64, vrmVersion.Item3);
}
else
{
return (0, 0, 0);
}
}
return (2, vrmVersion.Item2 - 64, vrmVersion.Item3);
}
static bool TryGetVersion(string src, out (int, int, int) version)
else
{
try
{
if (string.IsNullOrEmpty(src))
{
version = default;
return false;
}
var splitted = src.Split('.');
if (splitted.Length != 3)
{
version = default;
return false;
}
version = (
int.Parse(splitted[0]),
int.Parse(splitted[1]),
int.Parse(splitted[2])
);
return true;
}
catch (Exception)
{
version = default;
return false;
}
}
/// <summary>
/// バージョン管理ダイアログ
/// </summary>
void OnGUI()
{
GUILayout.Label("VRM");
GUILayout.Label($"Current version: {PackageVersion.VERSION}");
m_vrmVersion = EditorGUILayout.TextField("Major.Minor.Patch", m_vrmVersion);
GUILayout.Space(30);
GUILayout.Label("UniGLTF");
GUILayout.Label($"Current version: {UniGLTFVersion.VERSION}");
{
var enabled = GUI.enabled;
GUI.enabled = false;
EditorGUILayout.TextField("Major.Minor.Patch", $"{m_uniGltfVersion}");
GUI.enabled = enabled;
}
GUILayout.Space(30);
if (GUILayout.Button("Apply"))
{
if (TryGetVersion(m_vrmVersion, out (int, int, int) vrmVersion))
{
UpdateVrmVersion(vrmVersion);
UpdateUniGLTFVersion(m_uniGltfVersion, vrmVersion);
AssetDatabase.Refresh();
UniGLTFLogger.Log($"{m_uniGltfVersion}, {vrmVersion}");
}
else
{
UniGLTFLogger.Warning($"InvalidFormat: {m_vrmVersion}");
}
// COPY
VRMSampleCopy.Execute();
}
if (GUILayout.Button("Close"))
{
Close();
}
}
void UpdateUniGLTFVersion((int, int, int) uniGltf, (int, int, int) vrm)
{
var utf8 = new UTF8Encoding(false);
File.WriteAllText(UniGltfVersionPath, string.Format(UniGltfVersionTemplate,
uniGltf.Item1,
uniGltf.Item2,
uniGltf.Item3), utf8);
File.WriteAllText(UniGLTFPackage.Path, string.Format(UniGLTFPackage.Template,
$"{vrm.Item1}.{vrm.Item2}.{vrm.Item3}",
$"{vrm.Item1}.{vrm.Item2}.{vrm.Item3}"
), utf8);
}
void UpdateVrmVersion((int, int, int) vrm)
{
// generate
var utf8 = new UTF8Encoding(false);
File.WriteAllText(VrmVersionPath, string.Format(VrmVersionTemplate,
vrm.Item1,
vrm.Item2,
vrm.Item3), utf8);
// UPM
foreach (var upm in Packages)
{
File.WriteAllText(upm.Path, string.Format(upm.Template,
$"{vrm.Item1}.{vrm.Item2}.{vrm.Item3}",
$"{vrm.Item1}.{vrm.Item2}.{vrm.Item3}"
), utf8);
}
}
public static void ShowVersionDialog()
{
var window = ScriptableObject.CreateInstance<VRMVersionMenu>();
window.m_vrmVersion = PackageVersion.VERSION;
// window.m_uniGltfVersion = UniGLTFVersion.VERSION;
window.ShowUtility();
return (0, 0, 0);
}
}
}
static bool TryGetVersion(string src, out (int, int, int) version)
{
try
{
if (string.IsNullOrEmpty(src))
{
version = default;
return false;
}
var splitted = src.Split('.');
if (splitted.Length != 3)
{
version = default;
return false;
}
version = (
int.Parse(splitted[0]),
int.Parse(splitted[1]),
int.Parse(splitted[2])
);
return true;
}
catch (Exception)
{
version = default;
return false;
}
}
/// <summary>
/// バージョン管理ダイアログ
/// </summary>
void OnGUI()
{
GUILayout.Label("VRM");
GUILayout.Label($"Current version: {PackageVersion.VERSION}");
m_vrmVersion = EditorGUILayout.TextField("Major.Minor.Patch", m_vrmVersion);
GUILayout.Space(30);
GUILayout.Label("UniGLTF");
GUILayout.Label($"Current version: {UniGLTFVersion.VERSION}");
{
var enabled = GUI.enabled;
GUI.enabled = false;
EditorGUILayout.TextField("Major.Minor.Patch", $"{m_uniGltfVersion}");
GUI.enabled = enabled;
}
GUILayout.Space(30);
if (GUILayout.Button("Apply"))
{
if (TryGetVersion(m_vrmVersion, out (int, int, int) vrmVersion))
{
UpdateVrmVersion(vrmVersion);
UpdateUniGLTFVersion(m_uniGltfVersion, vrmVersion);
AssetDatabase.Refresh();
UniGLTFLogger.Log($"{m_uniGltfVersion}, {vrmVersion}");
}
else
{
UniGLTFLogger.Warning($"InvalidFormat: {m_vrmVersion}");
}
// COPY
VRMSampleCopy.Execute();
}
if (GUILayout.Button("Close"))
{
Close();
}
}
void UpdateUniGLTFVersion((int, int, int) uniGltf, (int, int, int) vrm)
{
var utf8 = new UTF8Encoding(false);
File.WriteAllText(UniGltfVersionPath, string.Format(UniGltfVersionTemplate,
uniGltf.Item1,
uniGltf.Item2,
uniGltf.Item3), utf8);
File.WriteAllText(UniGLTFPackage.Path, string.Format(UniGLTFPackage.Template,
$"{vrm.Item1}.{vrm.Item2}.{vrm.Item3}",
$"{vrm.Item1}.{vrm.Item2}.{vrm.Item3}"
), utf8);
}
void UpdateVrmVersion((int, int, int) vrm)
{
// generate
var utf8 = new UTF8Encoding(false);
File.WriteAllText(VrmVersionPath, string.Format(VrmVersionTemplate,
vrm.Item1,
vrm.Item2,
vrm.Item3), utf8);
// UPM
foreach (var upm in Packages)
{
File.WriteAllText(upm.Path, string.Format(upm.Template,
$"{vrm.Item1}.{vrm.Item2}.{vrm.Item3}",
$"{vrm.Item1}.{vrm.Item2}.{vrm.Item3}"
), utf8);
}
}
public static void ShowVersionDialog()
{
var window = ScriptableObject.CreateInstance<VRMVersionMenu>();
window.m_vrmVersion = PackageVersion.VERSION;
// window.m_uniGltfVersion = UniGLTFVersion.VERSION;
window.ShowUtility();
}
}
}

View File

@@ -120,11 +120,11 @@ float4 frag_forward(v2f i) : SV_TARGET
// const
const float PI_2 = 6.28318530718;
const float EPS_COL = 0.00001;
const half EPSILON_FP16 = 0.0009765625;
// uv
float2 mainUv = TRANSFORM_TEX(i.uv0, _MainTex);
// uv anim
float uvAnim = tex2D(_UvAnimMaskTexture, mainUv).r * _Time.y;
// translate uv in bottom-left origin coordinates.
@@ -133,25 +133,25 @@ float4 frag_forward(v2f i) : SV_TARGET
float rotateRad = _UvAnimRotation * PI_2 * uvAnim;
const float2 rotatePivot = float2(0.5, 0.5);
mainUv = mul(float2x2(cos(rotateRad), -sin(rotateRad), sin(rotateRad), cos(rotateRad)), mainUv - rotatePivot) + rotatePivot;
// main tex
half4 mainTex = tex2D(_MainTex, mainUv);
// alpha
half alpha = 1;
#ifdef _ALPHATEST_ON
alpha = _Color.a * mainTex.a;
alpha = (alpha - _Cutoff) / max(fwidth(alpha), EPS_COL) + 0.5; // Alpha to Coverage
alpha = (alpha - _Cutoff) / max(fwidth(alpha), EPSILON_FP16) + 0.5; // Alpha to Coverage
clip(alpha - _Cutoff);
alpha = 1.0; // Discarded, otherwise it should be assumed to have full opacity
#endif
#ifdef _ALPHABLEND_ON
alpha = _Color.a * mainTex.a;
#if !_ALPHATEST_ON && SHADER_API_D3D11 // Only enable this on D3D11, where I tested it
clip(alpha - 0.0001); // Slightly improves rendering with layered transparency
#ifdef SHADER_API_D3D11 // Only enable this on D3D11, where I tested it
clip(alpha - EPSILON_FP16); // Slightly improves rendering with layered transparency
#endif
#endif
// normal
#ifdef _NORMALMAP
half3 tangentNormal = UnpackScaleNormal(tex2D(_BumpMap, mainUv), _BumpScale);
@@ -177,7 +177,7 @@ float4 frag_forward(v2f i) : SV_TARGET
#else
half lightAttenuation = shadowAttenuation * lerp(1, shadowAttenuation, _ReceiveShadowRate * tex2D(_ReceiveShadowTexture, mainUv).r);
#endif
// Decide albedo color rate from Direct Light
half shadingGrade = 1.0 - _ShadingGradeRate * (1.0 - tex2D(_ShadingGradeTexture, mainUv).r);
half lightIntensity = dotNL; // [-1, +1]
@@ -188,8 +188,8 @@ float4 frag_forward(v2f i) : SV_TARGET
// tooned. mapping from [minIntensityThreshold, maxIntensityThreshold] to [0, 1]
half maxIntensityThreshold = lerp(1, _ShadeShift, _ShadeToony);
half minIntensityThreshold = _ShadeShift;
lightIntensity = saturate((lightIntensity - minIntensityThreshold) / max(EPS_COL, (maxIntensityThreshold - minIntensityThreshold)));
lightIntensity = saturate((lightIntensity - minIntensityThreshold) / max(EPSILON_FP16, (maxIntensityThreshold - minIntensityThreshold)));
// Albedo color
half4 shade = _ShadeColor * tex2D(_ShadeTexture, mainUv);
half4 lit = _Color * mainTex;
@@ -197,7 +197,7 @@ float4 frag_forward(v2f i) : SV_TARGET
// Direct Light
half3 lighting = lightColor;
lighting = lerp(lighting, max(EPS_COL, max(lighting.x, max(lighting.y, lighting.z))), _LightColorAttenuation); // color atten
lighting = lerp(lighting, max(EPSILON_FP16, max(lighting.x, max(lighting.y, lighting.z))), _LightColorAttenuation); // color atten
#ifdef MTOON_FORWARD_ADD
#ifdef _ALPHABLEND_ON
lighting *= step(0, dotNL); // darken if transparent. Because Unity's transparent material can't receive shadowAttenuation.
@@ -215,9 +215,9 @@ float4 frag_forward(v2f i) : SV_TARGET
#else
half3 toonedGI = 0.5 * (ShadeSH9(half4(0, 1, 0, 1)) + ShadeSH9(half4(0, -1, 0, 1)));
half3 indirectLighting = lerp(toonedGI, ShadeSH9(half4(worldNormal, 1)), _IndirectLightIntensity);
indirectLighting = lerp(indirectLighting, max(EPS_COL, max(indirectLighting.x, max(indirectLighting.y, indirectLighting.z))), _LightColorAttenuation); // color atten
indirectLighting = lerp(indirectLighting, max(EPSILON_FP16, max(indirectLighting.x, max(indirectLighting.y, indirectLighting.z))), _LightColorAttenuation); // color atten
col += indirectLighting * lit;
col = min(col, lit); // comment out if you want to PBR absolutely.
#endif
@@ -230,7 +230,7 @@ float4 frag_forward(v2f i) : SV_TARGET
half3 mixedRimLighting = lighting + indirectLighting;
#endif
half3 rimLighting = lerp(staticRimLighting, mixedRimLighting, _RimLightingMix);
half3 rim = pow(saturate(1.0 - dot(worldNormal, worldView) + _RimLift), max(_RimFresnelPower, EPS_COL)) * _RimColor.rgb * tex2D(_RimTexture, mainUv).rgb;
half3 rim = pow(saturate(1.0 - dot(worldNormal, worldView) + _RimLift), max(_RimFresnelPower, EPSILON_FP16)) * _RimColor.rgb * tex2D(_RimTexture, mainUv).rgb;
col += lerp(rim * rimLighting, half3(0, 0, 0), i.isOutline);
// additive matcap

View File

@@ -57,7 +57,7 @@ namespace VRM
return;
}
m_service.BufferCombiner.Unregister(m_buffer);
m_service.BufferCombiner.Register(add: null, remove: m_buffer);
m_buffer.Dispose();
m_buffer = null;
}
@@ -67,7 +67,7 @@ namespace VRM
Debug.Assert(m_buffer == null);
var buffer = await SpringBoneJobs.FastSpringBoneReplacer.MakeBufferAsync(m_vrm, awaitCaller);
m_buffer = buffer;
SpringBoneJobs.FastSpringBoneService.Instance.BufferCombiner.Register(buffer);
SpringBoneJobs.FastSpringBoneService.Instance.BufferCombiner.Register(add: buffer, remove: null);
}

View File

@@ -1,6 +1,6 @@
{
"name": "com.vrmc.univrm",
"version": "0.128.1",
"version": "0.128.3",
"displayName": "VRM",
"description": "VRM importer",
"unity": "2021.3",
@@ -14,7 +14,7 @@
"name": "VRM Consortium"
},
"dependencies": {
"com.vrmc.gltf": "0.128.1",
"com.vrmc.gltf": "0.128.3",
"com.unity.ugui": "1.0.0"
},
"samples": [

View File

@@ -59,12 +59,12 @@ namespace UniVRM10
m_showJointSettings = EditorGUILayout.Foldout(m_showJointSettings, "Joint Settings");
if (m_showJointSettings)
{
LimitBreakSlider(m_stiffnessForceProp, 0.0f, 4.0f, 0.0f, Mathf.Infinity);
LimitBreakSlider(m_gravityPowerProp, 0.0f, 2.0f, 0.0f, Mathf.Infinity);
Vrm10EditorUtility.LimitBreakSlider(m_stiffnessForceProp, 0.0f, 4.0f, 0.0f, Mathf.Infinity);
Vrm10EditorUtility.LimitBreakSlider(m_gravityPowerProp, 0.0f, 2.0f, 0.0f, Mathf.Infinity);
EditorGUILayout.PropertyField(m_gravityDirProp);
EditorGUILayout.PropertyField(m_dragForceProp);
EditorGUILayout.Space();
LimitBreakSlider(m_jointRadiusProp, 0.0f, 0.5f, 0.0f, Mathf.Infinity);
Vrm10EditorUtility.LimitBreakSlider(m_jointRadiusProp, 0.0f, 0.5f, 0.0f, Mathf.Infinity);
}
if (serializedObject.ApplyModifiedProperties())
@@ -143,53 +143,6 @@ namespace UniVRM10
return jointIndex == (spring.Joints.Count - 1);
}
/// <summary>
/// スライダーと数値入力で限界値の違う、所謂「限界突破スライダー」を作成する
/// `EditorGUILayout.PropertyField` の代替として利用する
/// </summary>
private static void LimitBreakSlider(SerializedProperty property, float sliderLeft, float sliderRight, float numberLeft, float numberRight)
{
var label = new GUIContent(property.displayName);
var currentValue = property.floatValue;
var rect = EditorGUILayout.GetControlRect();
EditorGUI.BeginProperty(rect, label, property);
rect = EditorGUI.PrefixLabel(rect, label);
// slider
{
EditorGUI.BeginChangeCheck();
var sliderRect = rect;
sliderRect.width -= 55.0f;
rect.xMin += rect.width - 50.0f;
var clampedvalue = Mathf.Clamp(currentValue, sliderLeft, sliderRight);
var sliderValue = GUI.HorizontalSlider(sliderRect, clampedvalue, sliderLeft, sliderRight);
if (EditorGUI.EndChangeCheck())
{
property.floatValue = sliderValue;
}
}
// number
{
EditorGUI.BeginChangeCheck();
var numberValue = Mathf.Clamp(EditorGUI.FloatField(rect, currentValue), numberLeft, numberRight);
if (EditorGUI.EndChangeCheck())
{
property.floatValue = numberValue;
}
}
EditorGUI.EndProperty();
}
void OnSceneGUI()
{
if (m_root == null)

View File

@@ -22,7 +22,7 @@ namespace UniVRM10
// for SerializedProperty
SerializedPropertyEditor m_expression;
SerializedPropertyEditor m_meta;
SerializedPropertyEditor m_lookAt;
VRM10ObjectLookAtEditor m_lookAt;
SerializedPropertyEditor m_firstPerson;
SerializedProperty m_prefab;
@@ -36,7 +36,7 @@ namespace UniVRM10
m_expression = SerializedPropertyEditor.Create(serializedObject, nameof(m_target.Expression));
m_meta = VRM10MetaEditor.Create(serializedObject);
m_lookAt = SerializedPropertyEditor.Create(serializedObject, nameof(m_target.LookAt));
m_lookAt = new(serializedObject);
m_firstPerson = SerializedPropertyEditor.Create(serializedObject, nameof(m_target.FirstPerson));
m_prefab = serializedObject.FindProperty("m_prefab");

View File

@@ -0,0 +1,87 @@
using UniGLTF.Extensions.VRMC_vrm;
using UnityEditor;
namespace UniVRM10
{
public class VRM10ObjectLookAtEditor
{
private readonly SerializedObject _serializedObject;
private readonly SerializedProperty _OffsetFromHead;
private readonly SerializedProperty _LookAtType;
class CurveMapEditor
{
private readonly SerializedProperty _CurveXRangeDegree;
private readonly SerializedProperty _CurveYRangeDegree;
private readonly string _name;
public CurveMapEditor(SerializedObject serializedObject, string name)
{
_CurveXRangeDegree = serializedObject.FindProperty($"LookAt.{name}.CurveXRangeDegree");
_CurveYRangeDegree = serializedObject.FindProperty($"LookAt.{name}.CurveYRangeDegree");
_name = name;
}
public void OnInspectorGUI(float yMax)
{
EditorGUILayout.LabelField(_name);
EditorGUI.indentLevel++;
Vrm10EditorUtility.LimitBreakSlider(_CurveXRangeDegree, 0, 90.0f, 0, 90.0f);
Vrm10EditorUtility.LimitBreakSlider(_CurveYRangeDegree, 0, yMax, 0, 90.0f);
EditorGUI.indentLevel--;
EditorGUILayout.Space();
}
}
private readonly CurveMapEditor _HorizontalOuter;
private readonly CurveMapEditor _HorizontalInner;
private readonly CurveMapEditor _VerticalDown;
private readonly CurveMapEditor _VerticalUp;
public VRM10ObjectLookAtEditor(SerializedObject serializedObject)
{
_serializedObject = serializedObject;
_OffsetFromHead = serializedObject.FindProperty("LookAt.OffsetFromHead");
_LookAtType = serializedObject.FindProperty("LookAt.LookAtType");
_HorizontalOuter = new(serializedObject, "HorizontalOuter");
_HorizontalInner = new(serializedObject, "HorizontalInner");
_VerticalDown = new(serializedObject, "VerticalDown");
_VerticalUp = new(serializedObject, "VerticalUp");
}
public void OnInspectorGUI()
{
EditorGUILayout.PropertyField(_OffsetFromHead);
EditorGUILayout.PropertyField(_LookAtType);
EditorGUILayout.Space();
switch ((LookAtType)_LookAtType.enumValueIndex)
{
case LookAtType.bone:
{
EditorGUILayout.HelpBox("Degree Input (0-90) => EyeBone Degree(0-90)", MessageType.Info);
_HorizontalOuter.OnInspectorGUI(90);
_HorizontalInner.OnInspectorGUI(90);
_VerticalDown.OnInspectorGUI(90);
_VerticalUp.OnInspectorGUI(90);
}
break;
case LookAtType.expression:
{
EditorGUILayout.HelpBox("Degree Input (0-90) => Expression Weight(0-1.0)", MessageType.Info);
_HorizontalOuter.OnInspectorGUI(1);
_HorizontalInner.OnInspectorGUI(1);
_VerticalDown.OnInspectorGUI(1);
_VerticalUp.OnInspectorGUI(1);
}
break;
default:
break;
}
_serializedObject.ApplyModifiedProperties();
}
}
}

View File

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

View File

@@ -0,0 +1,55 @@
using UnityEditor;
using UnityEngine;
namespace UniVRM10
{
public static class Vrm10EditorUtility
{
/// <summary>
/// スライダーと数値入力で限界値の違う、所謂「限界突破スライダー」を作成する
/// `EditorGUILayout.PropertyField` の代替として利用する
/// </summary>
public static void LimitBreakSlider(SerializedProperty property, float sliderLeft, float sliderRight, float numberLeft, float numberRight)
{
var label = new GUIContent(property.displayName);
var currentValue = property.floatValue;
var rect = EditorGUILayout.GetControlRect();
EditorGUI.BeginProperty(rect, label, property);
rect = EditorGUI.PrefixLabel(rect, label);
// slider
{
EditorGUI.BeginChangeCheck();
var sliderRect = rect;
sliderRect.width -= 55.0f;
rect.xMin += rect.width - 50.0f;
var clampedvalue = Mathf.Clamp(currentValue, sliderLeft, sliderRight);
var sliderValue = GUI.HorizontalSlider(sliderRect, clampedvalue, sliderLeft, sliderRight);
if (EditorGUI.EndChangeCheck())
{
property.floatValue = sliderValue;
}
}
// number
{
EditorGUI.BeginChangeCheck();
var numberValue = Mathf.Clamp(EditorGUI.FloatField(rect, currentValue), numberLeft, numberRight);
if (EditorGUI.EndChangeCheck())
{
property.floatValue = numberValue;
}
}
EditorGUI.EndProperty();
}
}
}

View File

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

View File

@@ -24,8 +24,11 @@ namespace UniVRM10
LookAt,
SpringBone,
}
static Tab s_selected = default;
static bool s_foldRuntimeLookAt = false;
Vrm10Instance m_instance;
private Dictionary<string, Material> m_materials = new();
SerializedProperty m_script;
SerializedProperty m_vrmObject;
@@ -40,6 +43,14 @@ namespace UniVRM10
void OnEnable()
{
m_instance = (Vrm10Instance)target;
m_materials.Clear();
foreach (var r in m_instance.GetComponentsInChildren<Renderer>())
{
foreach (var m in r.sharedMaterials)
{
m_materials.TryAdd(m.name, m);
}
}
m_script = serializedObject.FindProperty("m_Script");
m_vrmObject = serializedObject.FindProperty(nameof(m_instance.Vrm));
@@ -226,7 +237,7 @@ namespace UniVRM10
root.Add(s);
}
var tabs = new EnumField("select UI", default(Tab));
var tabs = new EnumField("select UI", s_selected);
root.Add(tabs);
var body = new VisualElement();
@@ -239,7 +250,7 @@ namespace UniVRM10
foreach (var (tab, content) in contents)
{
// content.visible = tab == Tab.VrmInstance;
content.style.display = tab == Tab.VrmInstance
content.style.display = tab == s_selected
? DisplayStyle.Flex
: DisplayStyle.None
;
@@ -249,11 +260,11 @@ namespace UniVRM10
tabs.RegisterValueChangedCallback(e =>
{
var selected = (Tab)e.newValue;
s_selected = (Tab)e.newValue;
foreach (var (tab, content) in contents)
{
// content.visible = tab == selected;
content.style.display = tab == selected
content.style.display = tab == s_selected
? DisplayStyle.Flex
: DisplayStyle.None
;
@@ -275,13 +286,114 @@ namespace UniVRM10
serializedObject.ApplyModifiedProperties();
}
void showuv(ExpressionPreset preset)
{
EditorGUI.indentLevel++;
try
{
var (_, clip) = m_instance.Vrm.Expression.Clips.FirstOrDefault(x => x.Preset == preset);
if (clip != null)
{
foreach (var b in clip.MaterialUVBindings)
{
if (m_materials.TryGetValue(b.MaterialName, out var m))
{
EditorGUILayout.TextField(b.MaterialName, $"{b.Offset},${b.Scaling} => {m.mainTextureOffset},{m.mainTextureScale}");
}
else
{
EditorGUILayout.TextField(b.MaterialName, "not found");
}
}
}
}
finally
{
EditorGUI.indentLevel--;
}
}
void GUILookAt()
{
if (!target)
{
return;
}
serializedObject.Update();
EditorGUILayout.PropertyField(m_drawLookatGizmo);
EditorGUILayout.PropertyField(m_lookatTarget);
EditorGUILayout.PropertyField(m_lookatTargetType);
serializedObject.ApplyModifiedProperties();
// lookat info
{
EditorGUILayout.Space();
s_foldRuntimeLookAt = EditorGUILayout.Foldout(s_foldRuntimeLookAt, "RuntimeInfo");
if (s_foldRuntimeLookAt)
{
var enabled = GUI.enabled;
GUI.enabled = false;
EditorGUILayout.Slider("yaw(-180 ~ +180)", m_instance.Runtime.LookAt.Yaw, -180, 180);
EditorGUILayout.Slider("pitch(-90 ~ +90)", m_instance.Runtime.LookAt.Pitch, -90, 90);
if (m_instance.Runtime.LookAt.EyeDirectionApplicable is LookAtEyeDirectionApplicableToBone)
{
EditorGUILayout.LabelField("BoneTYpe");
}
else if (m_instance.Runtime.LookAt.EyeDirectionApplicable is LookAtEyeDirectionApplicableToExpression)
{
EditorGUILayout.LabelField("ExpressionType");
var w = m_instance.Runtime.Expression.ActualWeights;
// left
if (w.TryGetValue(ExpressionKey.LookLeft, out var left))
{
EditorGUILayout.Slider("left", left, 0, 1);
showuv(ExpressionPreset.lookLeft);
}
else
{
EditorGUILayout.TextField("left");
}
// right
if (w.TryGetValue(ExpressionKey.LookRight, out var right))
{
EditorGUILayout.Slider("right", right, 0, 1);
showuv(ExpressionPreset.lookRight);
}
else
{
EditorGUILayout.TextField("right");
}
// up
if (w.TryGetValue(ExpressionKey.LookUp, out var up))
{
EditorGUILayout.Slider("up", up, 0, 1);
showuv(ExpressionPreset.lookUp);
}
else
{
EditorGUILayout.TextField("up");
}
// down
if (w.TryGetValue(ExpressionKey.LookDown, out var down))
{
EditorGUILayout.Slider("down", down, 0, 1);
showuv(ExpressionPreset.lookDown);
}
else
{
EditorGUILayout.TextField("down");
}
}
else
{
EditorGUILayout.LabelField($"UnknownTYpe: {m_instance.Runtime.LookAt.EyeDirectionApplicable}");
}
GUI.enabled = enabled;
Repaint();
}
}
}
VisualElement GUISpringBone()

View File

@@ -6,13 +6,27 @@ namespace VRM10.MToon10
{
public sealed class MToonOutlineRenderFeature : ScriptableRendererFeature
{
#if UNITY_6000_0_OR_NEWER
private RenderObjectsPass _opaquePass;
private RenderObjectsPass _transparentPass;
#else
private MToonOutlineRenderPass _opaquePass;
private MToonOutlineRenderPass _transparentPass;
#endif
public override void Create()
{
#if UNITY_6000_0_OR_NEWER
var profilerTagName = nameof(MToonOutlineRenderFeature);
var shaderTags = new[] {"MToonOutline"};
var layerMask = -1;
var cameraSettings = new RenderObjects.CustomCameraSettings();
_opaquePass = new RenderObjectsPass(profilerTagName, RenderPassEvent.AfterRenderingOpaques, shaderTags, RenderQueueType.Opaque, layerMask, cameraSettings);
_transparentPass = new RenderObjectsPass(profilerTagName, RenderPassEvent.BeforeRenderingTransparents, shaderTags, RenderQueueType.Transparent, layerMask, cameraSettings);
#else
_opaquePass = new MToonOutlineRenderPass(RenderPassEvent.AfterRenderingOpaques, RenderQueueRange.opaque);
_transparentPass = new MToonOutlineRenderPass(RenderPassEvent.BeforeRenderingTransparents, RenderQueueRange.transparent);
#endif
}
public override void AddRenderPasses(ScriptableRenderer renderer, ref RenderingData renderingData)

View File

@@ -1,4 +1,4 @@
#if MTOON_URP
#if MTOON_URP && !UNITY_6000_0_OR_NEWER
using UnityEngine.Rendering;
using UnityEngine.Rendering.Universal;
@@ -17,9 +17,6 @@ namespace VRM10.MToon10
this.renderPassEvent = renderPassEvent;
}
#if UNITY_6000_0_OR_NEWER
[System.Obsolete]
#endif
public override void Execute(ScriptableRenderContext context, ref RenderingData renderingData)
{
var cmd = CommandBufferPool.Get();

View File

@@ -29,7 +29,7 @@ Shader "VRM10/MToon10"
_EmissionMap ("emissiveTexture", 2D) = "white" {} // Unity specified name
// Rim Lighting
_MatcapColor ("mtoon.matcapFactor", Color) = (1, 1, 1, 1)
_MatcapColor ("mtoon.matcapFactor", Color) = (0, 0, 0, 1) // 仕様のデフォルト値は白だが、過去の仕様違反 UniVRM 実装アプリケーションのために黒とする。 https://github.com/vrm-c/UniVRM/pull/2594
_MatcapTex ("mtoon.matcapTexture", 2D) = "black" {}
_RimColor ("mtoon.parametricRimColorFactor", Color) = (0, 0, 0, 1)
_RimFresnelPower ("mtoon.parametricRimFresnelPowerFactor", Range(0, 100)) = 5.0

View File

@@ -17,7 +17,7 @@ inline half GetMToonGeometry_Alpha(half4 litColor)
else if (MToon_IsAlphaBlendOn())
{
const half alpha = litColor.a;
clip(alpha - EPS_COL);
clip(alpha - EPSILON_FP16); // https://github.com/vrm-c/UniVRM/pull/2598
return alpha;
}
else

View File

@@ -123,7 +123,7 @@ inline half3 GetMToonLighting_Rim_Matcap(const MToonInput input)
inline half3 GetMToonLighting_Rim(const UnityLighting unityLight, const MToonInput input, const half shadow)
{
const half3 parametricRimFactor = pow(saturate(1.0 - dot(input.normalWS, input.viewDirWS) + _RimLift), max(_RimFresnelPower, EPS_COL)) * _RimColor.rgb;
const half3 parametricRimFactor = pow(saturate(1.0 - dot(input.normalWS, input.viewDirWS) + _RimLift), max(_RimFresnelPower, EPSILON_FP16)) * _RimColor.rgb;
const half3 matcapFactor = GetMToonLighting_Rim_Matcap(input);
const half3 directLightingFactor = unityLight.directLightColor * shadow;

View File

@@ -29,7 +29,7 @@ Shader "VRM10/Universal Render Pipeline/MToon10"
_EmissionMap ("emissiveTexture", 2D) = "white" {} // Unity specified name
// Rim Lighting
_MatcapColor ("mtoon.matcapFactor", Color) = (1, 1, 1, 1)
_MatcapColor ("mtoon.matcapFactor", Color) = (0, 0, 0, 1) // 仕様のデフォルト値は白だが、過去の仕様違反 UniVRM 実装アプリケーションのために黒とする。 https://github.com/vrm-c/UniVRM/pull/2594
_MatcapTex ("mtoon.matcapTexture", 2D) = "black" {}
_RimColor ("mtoon.parametricRimColorFactor", Color) = (0, 0, 0, 1)
_RimFresnelPower ("mtoon.parametricRimFresnelPowerFactor", Range(0, 100)) = 5.0

View File

@@ -9,7 +9,8 @@
// define
static const float PI_2 = 6.28318530718;
static const float EPS_COL = 0.00001;
// 2^-10 (min positive value of 16-bit floating point)
static const half EPSILON_FP16 = 0.0009765625;
inline half mtoon_linearstep(const half start, const half end, const half t)
{

View File

@@ -61,6 +61,11 @@ namespace UniVRM10
return;
}
if (clip.IsBinary)
{
value = value > 0.5f ? 1 : 0;
}
m_morphTargetBindingMerger.AccumulateValue(key, value);
m_materialValueBindingMerger.AccumulateValue(clip, value);
}

View File

@@ -115,7 +115,7 @@ namespace UniVRM10
{
foreach (var kv in m_materialMap)
{
kv.Value.RestoreInitialValues();
kv.Value.Clear();
}
}
#endregion

View File

@@ -71,14 +71,6 @@ namespace UniVRM10
set;
}
public void RestoreInitialValues()
{
foreach (var prop in PropMap)
{
Material.SetColor(prop.Value.Name, prop.Value.DefaultValues);
}
}
public static readonly string COLOR_PROPERTY = MToon10Prop.BaseColorFactor.ToUnityShaderLabName();
public static readonly string EMISSION_COLOR_PROPERTY = MToon10Prop.EmissiveFactor.ToUnityShaderLabName();
public static readonly string RIM_COLOR_PROPERTY = MToon10Prop.ParametricRimColorFactor.ToUnityShaderLabName();

View File

@@ -7,10 +7,20 @@ namespace UniVRM10
[Serializable]
public class CurveMapper
{
[Range(20.0f, 90.0f)]
/// <summary>
/// v0.128.3 VRM10ObjectLookAtEditor
///
/// DegreeINput 0-90
/// </summary>
public float CurveXRangeDegree;
[Range(0, 90.0f)]
/// <summary>
/// v0.128.3 VRM10ObjectLookAtEditor
///
/// EyeBoneDegree 0-90
/// or
/// ExpressionWeight 0-1.0
/// </summary>
public float CurveYRangeDegree;
public CurveMapper(float xRange, float yRange)

View File

@@ -12,7 +12,7 @@ namespace UniVRM10
/// <param name="Yaw"></param>
/// <param name="m"></param>
/// <param name="target"></param>
/// <returns></returns>
/// <returns>yaw, pitch degree</returns>
public static (float Yaw, float Pitch) CalcYawPitch(this Matrix4x4 m, Vector3 target)
{
var localPosition = m.inverse.MultiplyPoint(target);
@@ -67,6 +67,10 @@ namespace UniVRM10
/// pitch: 上が+
/// という仕様。vrm-0.x から据え置き
/// </summary>
/// <param name="m"></param>
/// <param name="target"></param>
/// <param name="yaw">Degree</param>
/// <param name="pitch">eegree</param>
public static void CalcYawPitch(this Matrix4x4 m, Vector3 target, out float yaw, out float pitch)
{
var z = Vector3.Dot(target, m.GetColumn(2));

View File

@@ -215,6 +215,11 @@ namespace UniVRM10
}
private void OnDestroy()
{
DisposeRuntime();
}
public void DisposeRuntime()
{
if (m_runtime != null)
{

View File

@@ -55,7 +55,7 @@ namespace UniVRM10
{
if (m_fastSpringBoneBuffer != null)
{
m_fastSpringBoneService.BufferCombiner.Unregister(m_fastSpringBoneBuffer);
m_fastSpringBoneService.BufferCombiner.Register(add: null, remove: m_fastSpringBoneBuffer);
m_fastSpringBoneBuffer.Dispose();
}
}
@@ -87,16 +87,10 @@ namespace UniVRM10
}
m_building = true;
// 登録削除
if (m_fastSpringBoneBuffer != null)
{
m_fastSpringBoneService.BufferCombiner.Unregister(m_fastSpringBoneBuffer);
}
var fastSpringBoneBuffer = await FastSpringBoneBufferFactory.ConstructSpringBoneAsync(awaitCaller, m_instance, m_fastSpringBoneBuffer);
m_fastSpringBoneBuffer = await FastSpringBoneBufferFactory.ConstructSpringBoneAsync(awaitCaller, m_instance, m_fastSpringBoneBuffer);
// 登録
m_fastSpringBoneService.BufferCombiner.Register(m_fastSpringBoneBuffer);
m_fastSpringBoneService.BufferCombiner.Register(add: fastSpringBoneBuffer, remove: m_fastSpringBoneBuffer);
m_fastSpringBoneBuffer = fastSpringBoneBuffer;
m_building = false;
return true;

View File

@@ -54,7 +54,7 @@ namespace UniVRM10
public void Dispose()
{
m_bufferCombiner.Unregister(m_fastSpringBoneBuffer);
m_bufferCombiner.Register(add: null, remove: m_fastSpringBoneBuffer);
m_fastSpringBoneBuffer.Dispose();
m_fastSpringBoneScheduler.Dispose();
@@ -88,16 +88,9 @@ namespace UniVRM10
}
m_building = true;
// 登録削除
if (m_fastSpringBoneBuffer != null)
{
m_bufferCombiner.Unregister(m_fastSpringBoneBuffer);
}
m_fastSpringBoneBuffer = await FastSpringBoneBufferFactory.ConstructSpringBoneAsync(awaitCaller, m_instance, m_fastSpringBoneBuffer);
// 登録
m_bufferCombiner.Register(m_fastSpringBoneBuffer);
var fastSpringBoneBuffer = await FastSpringBoneBufferFactory.ConstructSpringBoneAsync(awaitCaller, m_instance, m_fastSpringBoneBuffer);
m_bufferCombiner.Register(add: fastSpringBoneBuffer, remove: m_fastSpringBoneBuffer);
m_fastSpringBoneBuffer = fastSpringBoneBuffer;
m_building = false;
return true;

View File

@@ -72,6 +72,7 @@ namespace UniVRM10
public void Dispose()
{
Expression.Dispose();
ControlRig?.Dispose();
SpringBone.Dispose();
}

View File

@@ -1,9 +1,10 @@
using System;
using System.Collections.Generic;
using System.Linq;
namespace UniVRM10
{
public sealed class Vrm10RuntimeExpression
public sealed class Vrm10RuntimeExpression : IDisposable
{
public static IExpressionValidatorFactory ExpressionValidatorFactory = new DefaultExpressionValidator.Factory();
@@ -22,12 +23,8 @@ namespace UniVRM10
public float LookAtOverrideRate { get; private set; }
public float MouthOverrideRate { get; private set; }
int m_debugCount;
internal Vrm10RuntimeExpression(Vrm10Instance target, ILookAtEyeDirectionApplicable eyeDirectionApplicable)
{
Restore();
_merger = new ExpressionMerger(target.Vrm.Expression, target.transform);
_keys = target.Vrm.Expression.Clips
.Select(x => target.Vrm.Expression.CreateKey(x.Clip))
@@ -52,7 +49,7 @@ namespace UniVRM10
_eyeDirectionApplicable = eyeDirectionApplicable;
}
internal void Restore()
public void Dispose()
{
_merger?.RestoreMaterialInitialValues();
_merger = null;

View File

@@ -92,6 +92,8 @@ namespace UniVRM10
LookAtInput = new LookAtInput { YawPitch = new LookAtEyeDirection(yaw, pitch) };
}
/// <param name="lookAtWorldPosition"></param>
/// <returns>Degree</returns>
public (float Yaw, float Pitch) CalculateYawPitchFromLookAtPosition(Vector3 lookAtWorldPosition)
{
var localPosition = LookAtOriginTransform.worldToLocalMatrix.MultiplyPoint(lookAtWorldPosition);

View File

@@ -36,7 +36,7 @@ namespace UniVRM10
null,
Vrm10MToonTextureImporter.EnumerateAllTextures(data, m, mtoon).ToDictionary(tuple => tuple.key, tuple => tuple.Item2.Item2),
TryGetAllFloats(m, mtoon).ToDictionary(tuple => tuple.key, tuple => tuple.value),
TryGetAllColors(m, mtoon).ToDictionary(tuple => tuple.key, tuple => tuple.value),
TryGetAllColors(data, m, mtoon).ToDictionary(tuple => tuple.key, tuple => tuple.value),
TryGetAllFloatArrays(m, mtoon).ToDictionary(tuple => tuple.key, tuple => tuple.value),
new Action<Material>[]
{
@@ -50,7 +50,7 @@ namespace UniVRM10
return true;
}
public static IEnumerable<(string key, Color value)> TryGetAllColors(glTFMaterial material, VRMC_materials_mtoon mToon)
public static IEnumerable<(string key, Color value)> TryGetAllColors(GltfData data, glTFMaterial material, VRMC_materials_mtoon mToon)
{
const ColorSpace gltfColorSpace = ColorSpace.Linear;
@@ -72,10 +72,13 @@ namespace UniVRM10
// Emission
// Emissive factor should be stored in Linear space
var emissionColor = material?.emissiveFactor?.ToColor3(gltfColorSpace, ColorSpace.Linear);
if (emissionColor.HasValue)
if (material != null)
{
yield return (MToon10Prop.EmissiveFactor.ToUnityShaderLabName(), emissionColor.Value);
var emissionColor = GltfMaterialImportUtils.ImportLinearEmissiveFactor(data, material);
if (emissionColor.HasValue)
{
yield return (MToon10Prop.EmissiveFactor.ToUnityShaderLabName(), emissionColor.Value);
}
}
// Matcap

View File

@@ -31,7 +31,7 @@ namespace UniVRM10
null,
Vrm10MToonTextureImporter.EnumerateAllTextures(data, m, mtoon).ToDictionary(tuple => tuple.key, tuple => tuple.Item2.Item2),
BuiltInVrm10MToonMaterialImporter.TryGetAllFloats(m, mtoon).ToDictionary(tuple => tuple.key, tuple => tuple.value),
BuiltInVrm10MToonMaterialImporter.TryGetAllColors(m, mtoon).ToDictionary(tuple => tuple.key, tuple => tuple.value),
BuiltInVrm10MToonMaterialImporter.TryGetAllColors(data, m, mtoon).ToDictionary(tuple => tuple.key, tuple => tuple.value),
BuiltInVrm10MToonMaterialImporter.TryGetAllFloatArrays(m, mtoon).ToDictionary(tuple => tuple.key, tuple => tuple.value),
new Action<Material>[]
{

View File

@@ -118,7 +118,7 @@ namespace UniVRM10
}
}
private static bool TryGetShadeMultiplyTexture(GltfData data, VRMC_materials_mtoon mToon, out SubAssetKey key, out TextureDescriptor desc)
public static bool TryGetShadeMultiplyTexture(GltfData data, VRMC_materials_mtoon mToon, out SubAssetKey key, out TextureDescriptor desc)
{
return TryGetSRGBTexture(data, new Vrm10TextureInfo(mToon.ShadeMultiplyTexture), out key, out desc);
}

View File

@@ -0,0 +1,63 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!114 &11400000
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: d7fd9488000d3734a9e00ee676215985, type: 3}
m_Name: PostProcess Profile
m_EditorClassIdentifier:
components:
- {fileID: 4092932147052232957}
--- !u!114 &4092932147052232957
MonoBehaviour:
m_ObjectHideFlags: 3
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 0b2db86121404754db890f4c8dfe81b2, type: 3}
m_Name: Bloom
m_EditorClassIdentifier:
active: 1
skipIterations:
m_OverrideState: 0
m_Value: 1
threshold:
m_OverrideState: 1
m_Value: 1
intensity:
m_OverrideState: 1
m_Value: 1
scatter:
m_OverrideState: 0
m_Value: 0.7
clamp:
m_OverrideState: 0
m_Value: 65472
tint:
m_OverrideState: 0
m_Value: {r: 1, g: 1, b: 1, a: 1}
highQualityFiltering:
m_OverrideState: 0
m_Value: 0
downscale:
m_OverrideState: 0
m_Value: 0
maxIterations:
m_OverrideState: 0
m_Value: 6
dirtTexture:
m_OverrideState: 0
m_Value: {fileID: 0}
dimension: 1
dirtIntensity:
m_OverrideState: 0
m_Value: 0

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 74977177c881c8a449d9f981e53acc0c
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 11400000
userData:
assetBundleName:
assetBundleVariant:

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,10 @@
fileFormatVersion: 2
guid: 6b60fe85d745eda4281e3278fcb0657c
ScriptedImporter:
internalIDToNameTable: []
externalObjects: {}
serializedVersion: 2
userData:
assetBundleName:
assetBundleVariant:
script: {fileID: 11500000, guid: 625f186215c104763be7675aa2d941aa, type: 3}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,10 @@
fileFormatVersion: 2
guid: fd08e80eb7e04e849b8a6d534e48efea
ScriptedImporter:
internalIDToNameTable: []
externalObjects: {}
serializedVersion: 2
userData:
assetBundleName:
assetBundleVariant:
script: {fileID: 11500000, guid: 625f186215c104763be7675aa2d941aa, type: 3}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,10 @@
fileFormatVersion: 2
guid: 45c6d2335bae988419dbc2ec65c33dae
ScriptedImporter:
internalIDToNameTable: []
externalObjects: {}
serializedVersion: 2
userData:
assetBundleName:
assetBundleVariant:
script: {fileID: 11500000, guid: 60072b568d64c40a485e0fc55012dc9f, type: 3}

View File

@@ -1,975 +0,0 @@
{
"m_SGVersion": 3,
"m_Type": "UnityEditor.ShaderGraph.GraphData",
"m_ObjectId": "77181a4b19324ebdb175da71cf4f6186",
"m_Properties": [
{
"m_Id": "92f5ab11614c4ec1b4d632f73041ba65"
}
],
"m_Keywords": [],
"m_Dropdowns": [],
"m_CategoryData": [
{
"m_Id": "0778abfa54c94f9abfd0482e1de4d602"
}
],
"m_Nodes": [
{
"m_Id": "f56f676a56e04566a12f41980b760358"
},
{
"m_Id": "307a94d3f1ca45a39f6170433e3c81c6"
},
{
"m_Id": "7b57df1b4e444208bd41b7b749f485d0"
},
{
"m_Id": "80fce1dbcef04945aa9b988609dbe324"
},
{
"m_Id": "6f683c2eb23a4baf8dc028500640b75a"
},
{
"m_Id": "6098dc7f36d84b83b8421cc0e56ed1a0"
},
{
"m_Id": "53f1bc01113946bc946f0808f16df02b"
},
{
"m_Id": "0f64718141f34878916463ec72c9d2d8"
},
{
"m_Id": "58ee8fea72cc4a649f9a1198b12d621b"
},
{
"m_Id": "6637a91f035a40e798e76f70bed17d7e"
},
{
"m_Id": "305a571d629e4b258d80c3ad877cb596"
}
],
"m_GroupDatas": [],
"m_StickyNoteDatas": [],
"m_Edges": [
{
"m_OutputSlot": {
"m_Node": {
"m_Id": "305a571d629e4b258d80c3ad877cb596"
},
"m_SlotId": 0
},
"m_InputSlot": {
"m_Node": {
"m_Id": "6637a91f035a40e798e76f70bed17d7e"
},
"m_SlotId": 1
}
},
{
"m_OutputSlot": {
"m_Node": {
"m_Id": "6637a91f035a40e798e76f70bed17d7e"
},
"m_SlotId": 0
},
"m_InputSlot": {
"m_Node": {
"m_Id": "80fce1dbcef04945aa9b988609dbe324"
},
"m_SlotId": 0
}
}
],
"m_VertexContext": {
"m_Position": {
"x": 0.0,
"y": 0.0
},
"m_Blocks": [
{
"m_Id": "f56f676a56e04566a12f41980b760358"
},
{
"m_Id": "307a94d3f1ca45a39f6170433e3c81c6"
},
{
"m_Id": "7b57df1b4e444208bd41b7b749f485d0"
}
]
},
"m_FragmentContext": {
"m_Position": {
"x": 0.0,
"y": 200.0
},
"m_Blocks": [
{
"m_Id": "80fce1dbcef04945aa9b988609dbe324"
},
{
"m_Id": "6f683c2eb23a4baf8dc028500640b75a"
},
{
"m_Id": "6098dc7f36d84b83b8421cc0e56ed1a0"
},
{
"m_Id": "53f1bc01113946bc946f0808f16df02b"
},
{
"m_Id": "0f64718141f34878916463ec72c9d2d8"
},
{
"m_Id": "58ee8fea72cc4a649f9a1198b12d621b"
}
]
},
"m_PreviewData": {
"serializedMesh": {
"m_SerializedMesh": "{\"mesh\":{\"instanceID\":0}}",
"m_Guid": ""
},
"preventRotation": false
},
"m_Path": "Shader Graphs",
"m_GraphPrecision": 1,
"m_PreviewMode": 2,
"m_OutputNode": {
"m_Id": ""
},
"m_SubDatas": [],
"m_ActiveTargets": [
{
"m_Id": "15cb78699c8c4194ad103421699dbd17"
}
]
}
{
"m_SGVersion": 0,
"m_Type": "UnityEditor.ShaderGraph.Vector4MaterialSlot",
"m_ObjectId": "02acc5a4d1de49f087b1a9268cf423ed",
"m_Id": 0,
"m_DisplayName": "RGBA",
"m_SlotType": 1,
"m_Hidden": false,
"m_ShaderOutputName": "RGBA",
"m_StageCapability": 2,
"m_Value": {
"x": 0.0,
"y": 0.0,
"z": 0.0,
"w": 0.0
},
"m_DefaultValue": {
"x": 0.0,
"y": 0.0,
"z": 0.0,
"w": 0.0
},
"m_Labels": []
}
{
"m_SGVersion": 0,
"m_Type": "UnityEditor.ShaderGraph.CategoryData",
"m_ObjectId": "0778abfa54c94f9abfd0482e1de4d602",
"m_Name": "",
"m_ChildObjectList": [
{
"m_Id": "92f5ab11614c4ec1b4d632f73041ba65"
}
]
}
{
"m_SGVersion": 0,
"m_Type": "UnityEditor.ShaderGraph.BlockNode",
"m_ObjectId": "0f64718141f34878916463ec72c9d2d8",
"m_Group": {
"m_Id": ""
},
"m_Name": "SurfaceDescription.Emission",
"m_DrawState": {
"m_Expanded": true,
"m_Position": {
"serializedVersion": "2",
"x": 0.0,
"y": 0.0,
"width": 0.0,
"height": 0.0
}
},
"m_Slots": [
{
"m_Id": "a8a3476bbfe8465fbf208d8592d231a3"
}
],
"synonyms": [],
"m_Precision": 0,
"m_PreviewExpanded": true,
"m_DismissedVersion": 0,
"m_PreviewMode": 0,
"m_CustomColors": {
"m_SerializableColors": []
},
"m_SerializedDescriptor": "SurfaceDescription.Emission"
}
{
"m_SGVersion": 1,
"m_Type": "UnityEditor.Rendering.Universal.ShaderGraph.UniversalTarget",
"m_ObjectId": "15cb78699c8c4194ad103421699dbd17",
"m_Datas": [],
"m_ActiveSubTarget": {
"m_Id": "352f1953e12a45019330c49643812248"
},
"m_AllowMaterialOverride": false,
"m_SurfaceType": 0,
"m_ZTestMode": 4,
"m_ZWriteControl": 0,
"m_AlphaMode": 0,
"m_RenderFace": 2,
"m_AlphaClip": false,
"m_CastShadows": true,
"m_ReceiveShadows": true,
"m_SupportsLODCrossFade": false,
"m_CustomEditorGUI": "",
"m_SupportVFX": false
}
{
"m_SGVersion": 0,
"m_Type": "UnityEditor.ShaderGraph.Vector1MaterialSlot",
"m_ObjectId": "1773542df3cf4760b4bc7081934f54ca",
"m_Id": 0,
"m_DisplayName": "Smoothness",
"m_SlotType": 0,
"m_Hidden": false,
"m_ShaderOutputName": "Smoothness",
"m_StageCapability": 2,
"m_Value": 0.5,
"m_DefaultValue": 0.5,
"m_Labels": []
}
{
"m_SGVersion": 0,
"m_Type": "UnityEditor.ShaderGraph.Vector1MaterialSlot",
"m_ObjectId": "1b504994184f46fb86fd313496af2752",
"m_Id": 0,
"m_DisplayName": "Ambient Occlusion",
"m_SlotType": 0,
"m_Hidden": false,
"m_ShaderOutputName": "Occlusion",
"m_StageCapability": 2,
"m_Value": 1.0,
"m_DefaultValue": 1.0,
"m_Labels": []
}
{
"m_SGVersion": 0,
"m_Type": "UnityEditor.ShaderGraph.TangentMaterialSlot",
"m_ObjectId": "1c1aa306b109406fae4e7ad7412fdb14",
"m_Id": 0,
"m_DisplayName": "Tangent",
"m_SlotType": 0,
"m_Hidden": false,
"m_ShaderOutputName": "Tangent",
"m_StageCapability": 1,
"m_Value": {
"x": 0.0,
"y": 0.0,
"z": 0.0
},
"m_DefaultValue": {
"x": 0.0,
"y": 0.0,
"z": 0.0
},
"m_Labels": [],
"m_Space": 0
}
{
"m_SGVersion": 0,
"m_Type": "UnityEditor.ShaderGraph.NormalMaterialSlot",
"m_ObjectId": "204b111e465b44809369f1d3e5a90370",
"m_Id": 0,
"m_DisplayName": "Normal (Tangent Space)",
"m_SlotType": 0,
"m_Hidden": false,
"m_ShaderOutputName": "NormalTS",
"m_StageCapability": 2,
"m_Value": {
"x": 0.0,
"y": 0.0,
"z": 0.0
},
"m_DefaultValue": {
"x": 0.0,
"y": 0.0,
"z": 0.0
},
"m_Labels": [],
"m_Space": 3
}
{
"m_SGVersion": 0,
"m_Type": "UnityEditor.ShaderGraph.SamplerStateMaterialSlot",
"m_ObjectId": "2b57ee1b447443b39131b7d7ca5656c4",
"m_Id": 3,
"m_DisplayName": "Sampler",
"m_SlotType": 0,
"m_Hidden": false,
"m_ShaderOutputName": "Sampler",
"m_StageCapability": 3,
"m_BareResource": false
}
{
"m_SGVersion": 0,
"m_Type": "UnityEditor.ShaderGraph.PropertyNode",
"m_ObjectId": "305a571d629e4b258d80c3ad877cb596",
"m_Group": {
"m_Id": ""
},
"m_Name": "Property",
"m_DrawState": {
"m_Expanded": true,
"m_Position": {
"serializedVersion": "2",
"x": -482.6666564941406,
"y": 233.3333282470703,
"width": 140.0,
"height": 35.99998474121094
}
},
"m_Slots": [
{
"m_Id": "46fb52b8b307424ab27250d54f2c27f9"
}
],
"synonyms": [],
"m_Precision": 0,
"m_PreviewExpanded": true,
"m_DismissedVersion": 0,
"m_PreviewMode": 0,
"m_CustomColors": {
"m_SerializableColors": []
},
"m_Property": {
"m_Id": "92f5ab11614c4ec1b4d632f73041ba65"
}
}
{
"m_SGVersion": 0,
"m_Type": "UnityEditor.ShaderGraph.BlockNode",
"m_ObjectId": "307a94d3f1ca45a39f6170433e3c81c6",
"m_Group": {
"m_Id": ""
},
"m_Name": "VertexDescription.Normal",
"m_DrawState": {
"m_Expanded": true,
"m_Position": {
"serializedVersion": "2",
"x": 0.0,
"y": 0.0,
"width": 0.0,
"height": 0.0
}
},
"m_Slots": [
{
"m_Id": "e1de0ca351fd43ff866485e33328e300"
}
],
"synonyms": [],
"m_Precision": 0,
"m_PreviewExpanded": true,
"m_DismissedVersion": 0,
"m_PreviewMode": 0,
"m_CustomColors": {
"m_SerializableColors": []
},
"m_SerializedDescriptor": "VertexDescription.Normal"
}
{
"m_SGVersion": 2,
"m_Type": "UnityEditor.Rendering.Universal.ShaderGraph.UniversalLitSubTarget",
"m_ObjectId": "352f1953e12a45019330c49643812248",
"m_WorkflowMode": 1,
"m_NormalDropOffSpace": 0,
"m_ClearCoat": false,
"m_BlendModePreserveSpecular": true
}
{
"m_SGVersion": 0,
"m_Type": "UnityEditor.ShaderGraph.Vector1MaterialSlot",
"m_ObjectId": "408c7be450e8421abf78f79621f38a90",
"m_Id": 6,
"m_DisplayName": "B",
"m_SlotType": 1,
"m_Hidden": false,
"m_ShaderOutputName": "B",
"m_StageCapability": 2,
"m_Value": 0.0,
"m_DefaultValue": 0.0,
"m_Labels": []
}
{
"m_SGVersion": 0,
"m_Type": "UnityEditor.ShaderGraph.Texture2DMaterialSlot",
"m_ObjectId": "46fb52b8b307424ab27250d54f2c27f9",
"m_Id": 0,
"m_DisplayName": "BaseMap",
"m_SlotType": 1,
"m_Hidden": false,
"m_ShaderOutputName": "Out",
"m_StageCapability": 3,
"m_BareResource": false
}
{
"m_SGVersion": 0,
"m_Type": "UnityEditor.ShaderGraph.UVMaterialSlot",
"m_ObjectId": "4c1d0e69fdc7482b9e9587c61e9aee52",
"m_Id": 2,
"m_DisplayName": "UV",
"m_SlotType": 0,
"m_Hidden": false,
"m_ShaderOutputName": "UV",
"m_StageCapability": 3,
"m_Value": {
"x": 0.0,
"y": 0.0
},
"m_DefaultValue": {
"x": 0.0,
"y": 0.0
},
"m_Labels": [],
"m_Channel": 0
}
{
"m_SGVersion": 0,
"m_Type": "UnityEditor.ShaderGraph.BlockNode",
"m_ObjectId": "53f1bc01113946bc946f0808f16df02b",
"m_Group": {
"m_Id": ""
},
"m_Name": "SurfaceDescription.Smoothness",
"m_DrawState": {
"m_Expanded": true,
"m_Position": {
"serializedVersion": "2",
"x": 0.0,
"y": 0.0,
"width": 0.0,
"height": 0.0
}
},
"m_Slots": [
{
"m_Id": "1773542df3cf4760b4bc7081934f54ca"
}
],
"synonyms": [],
"m_Precision": 0,
"m_PreviewExpanded": true,
"m_DismissedVersion": 0,
"m_PreviewMode": 0,
"m_CustomColors": {
"m_SerializableColors": []
},
"m_SerializedDescriptor": "SurfaceDescription.Smoothness"
}
{
"m_SGVersion": 0,
"m_Type": "UnityEditor.ShaderGraph.BlockNode",
"m_ObjectId": "58ee8fea72cc4a649f9a1198b12d621b",
"m_Group": {
"m_Id": ""
},
"m_Name": "SurfaceDescription.Occlusion",
"m_DrawState": {
"m_Expanded": true,
"m_Position": {
"serializedVersion": "2",
"x": 0.0,
"y": 0.0,
"width": 0.0,
"height": 0.0
}
},
"m_Slots": [
{
"m_Id": "1b504994184f46fb86fd313496af2752"
}
],
"synonyms": [],
"m_Precision": 0,
"m_PreviewExpanded": true,
"m_DismissedVersion": 0,
"m_PreviewMode": 0,
"m_CustomColors": {
"m_SerializableColors": []
},
"m_SerializedDescriptor": "SurfaceDescription.Occlusion"
}
{
"m_SGVersion": 0,
"m_Type": "UnityEditor.ShaderGraph.BlockNode",
"m_ObjectId": "6098dc7f36d84b83b8421cc0e56ed1a0",
"m_Group": {
"m_Id": ""
},
"m_Name": "SurfaceDescription.Metallic",
"m_DrawState": {
"m_Expanded": true,
"m_Position": {
"serializedVersion": "2",
"x": 0.0,
"y": 0.0,
"width": 0.0,
"height": 0.0
}
},
"m_Slots": [
{
"m_Id": "cd2a46a6fe0746ae965dc193ce0757eb"
}
],
"synonyms": [],
"m_Precision": 0,
"m_PreviewExpanded": true,
"m_DismissedVersion": 0,
"m_PreviewMode": 0,
"m_CustomColors": {
"m_SerializableColors": []
},
"m_SerializedDescriptor": "SurfaceDescription.Metallic"
}
{
"m_SGVersion": 0,
"m_Type": "UnityEditor.ShaderGraph.PositionMaterialSlot",
"m_ObjectId": "619a91e5d75d4a629f14de895dbebb39",
"m_Id": 0,
"m_DisplayName": "Position",
"m_SlotType": 0,
"m_Hidden": false,
"m_ShaderOutputName": "Position",
"m_StageCapability": 1,
"m_Value": {
"x": 0.0,
"y": 0.0,
"z": 0.0
},
"m_DefaultValue": {
"x": 0.0,
"y": 0.0,
"z": 0.0
},
"m_Labels": [],
"m_Space": 0
}
{
"m_SGVersion": 0,
"m_Type": "UnityEditor.ShaderGraph.SampleTexture2DNode",
"m_ObjectId": "6637a91f035a40e798e76f70bed17d7e",
"m_Group": {
"m_Id": ""
},
"m_Name": "Sample Texture 2D",
"m_DrawState": {
"m_Expanded": true,
"m_Position": {
"serializedVersion": "2",
"x": -322.0,
"y": 200.0,
"width": 209.3333282470703,
"height": 438.6666259765625
}
},
"m_Slots": [
{
"m_Id": "02acc5a4d1de49f087b1a9268cf423ed"
},
{
"m_Id": "8057542115c941488ee696e0d023e9d8"
},
{
"m_Id": "c47fe1183b3b44d1ad66a998fde085f5"
},
{
"m_Id": "408c7be450e8421abf78f79621f38a90"
},
{
"m_Id": "70bb30a82355421ca010103090de0f4a"
},
{
"m_Id": "7aa32b9c5fc74c8088ac31ed5fc87f50"
},
{
"m_Id": "4c1d0e69fdc7482b9e9587c61e9aee52"
},
{
"m_Id": "2b57ee1b447443b39131b7d7ca5656c4"
}
],
"synonyms": [
"tex2d"
],
"m_Precision": 0,
"m_PreviewExpanded": true,
"m_DismissedVersion": 0,
"m_PreviewMode": 0,
"m_CustomColors": {
"m_SerializableColors": []
},
"m_TextureType": 0,
"m_NormalMapSpace": 0,
"m_EnableGlobalMipBias": true,
"m_MipSamplingMode": 0
}
{
"m_SGVersion": 0,
"m_Type": "UnityEditor.ShaderGraph.BlockNode",
"m_ObjectId": "6f683c2eb23a4baf8dc028500640b75a",
"m_Group": {
"m_Id": ""
},
"m_Name": "SurfaceDescription.NormalTS",
"m_DrawState": {
"m_Expanded": true,
"m_Position": {
"serializedVersion": "2",
"x": 0.0,
"y": 0.0,
"width": 0.0,
"height": 0.0
}
},
"m_Slots": [
{
"m_Id": "204b111e465b44809369f1d3e5a90370"
}
],
"synonyms": [],
"m_Precision": 0,
"m_PreviewExpanded": true,
"m_DismissedVersion": 0,
"m_PreviewMode": 0,
"m_CustomColors": {
"m_SerializableColors": []
},
"m_SerializedDescriptor": "SurfaceDescription.NormalTS"
}
{
"m_SGVersion": 0,
"m_Type": "UnityEditor.ShaderGraph.Vector1MaterialSlot",
"m_ObjectId": "70bb30a82355421ca010103090de0f4a",
"m_Id": 7,
"m_DisplayName": "A",
"m_SlotType": 1,
"m_Hidden": false,
"m_ShaderOutputName": "A",
"m_StageCapability": 2,
"m_Value": 0.0,
"m_DefaultValue": 0.0,
"m_Labels": []
}
{
"m_SGVersion": 0,
"m_Type": "UnityEditor.ShaderGraph.ColorRGBMaterialSlot",
"m_ObjectId": "7454a78d02bb4f79b6ff0f81f6b795a0",
"m_Id": 0,
"m_DisplayName": "Base Color",
"m_SlotType": 0,
"m_Hidden": false,
"m_ShaderOutputName": "BaseColor",
"m_StageCapability": 2,
"m_Value": {
"x": 0.5,
"y": 0.5,
"z": 0.5
},
"m_DefaultValue": {
"x": 0.0,
"y": 0.0,
"z": 0.0
},
"m_Labels": [],
"m_ColorMode": 0,
"m_DefaultColor": {
"r": 0.5,
"g": 0.5,
"b": 0.5,
"a": 1.0
}
}
{
"m_SGVersion": 0,
"m_Type": "UnityEditor.ShaderGraph.Texture2DInputMaterialSlot",
"m_ObjectId": "7aa32b9c5fc74c8088ac31ed5fc87f50",
"m_Id": 1,
"m_DisplayName": "Texture",
"m_SlotType": 0,
"m_Hidden": false,
"m_ShaderOutputName": "Texture",
"m_StageCapability": 3,
"m_BareResource": false,
"m_Texture": {
"m_SerializedTexture": "",
"m_Guid": ""
},
"m_DefaultType": 0
}
{
"m_SGVersion": 0,
"m_Type": "UnityEditor.ShaderGraph.BlockNode",
"m_ObjectId": "7b57df1b4e444208bd41b7b749f485d0",
"m_Group": {
"m_Id": ""
},
"m_Name": "VertexDescription.Tangent",
"m_DrawState": {
"m_Expanded": true,
"m_Position": {
"serializedVersion": "2",
"x": 0.0,
"y": 0.0,
"width": 0.0,
"height": 0.0
}
},
"m_Slots": [
{
"m_Id": "1c1aa306b109406fae4e7ad7412fdb14"
}
],
"synonyms": [],
"m_Precision": 0,
"m_PreviewExpanded": true,
"m_DismissedVersion": 0,
"m_PreviewMode": 0,
"m_CustomColors": {
"m_SerializableColors": []
},
"m_SerializedDescriptor": "VertexDescription.Tangent"
}
{
"m_SGVersion": 0,
"m_Type": "UnityEditor.ShaderGraph.Vector1MaterialSlot",
"m_ObjectId": "8057542115c941488ee696e0d023e9d8",
"m_Id": 4,
"m_DisplayName": "R",
"m_SlotType": 1,
"m_Hidden": false,
"m_ShaderOutputName": "R",
"m_StageCapability": 2,
"m_Value": 0.0,
"m_DefaultValue": 0.0,
"m_Labels": []
}
{
"m_SGVersion": 0,
"m_Type": "UnityEditor.ShaderGraph.BlockNode",
"m_ObjectId": "80fce1dbcef04945aa9b988609dbe324",
"m_Group": {
"m_Id": ""
},
"m_Name": "SurfaceDescription.BaseColor",
"m_DrawState": {
"m_Expanded": true,
"m_Position": {
"serializedVersion": "2",
"x": 0.0,
"y": 0.0,
"width": 0.0,
"height": 0.0
}
},
"m_Slots": [
{
"m_Id": "7454a78d02bb4f79b6ff0f81f6b795a0"
}
],
"synonyms": [],
"m_Precision": 0,
"m_PreviewExpanded": true,
"m_DismissedVersion": 0,
"m_PreviewMode": 0,
"m_CustomColors": {
"m_SerializableColors": []
},
"m_SerializedDescriptor": "SurfaceDescription.BaseColor"
}
{
"m_SGVersion": 0,
"m_Type": "UnityEditor.ShaderGraph.Internal.Texture2DShaderProperty",
"m_ObjectId": "92f5ab11614c4ec1b4d632f73041ba65",
"m_Guid": {
"m_GuidSerialized": "df5eef53-f7a6-40ef-8fca-1fd91f86d83f"
},
"m_Name": "BaseMap",
"m_DefaultRefNameVersion": 1,
"m_RefNameGeneratedByDisplayName": "BaseMap",
"m_DefaultReferenceName": "_BaseMap",
"m_OverrideReferenceName": "",
"m_GeneratePropertyBlock": true,
"m_UseCustomSlotLabel": false,
"m_CustomSlotLabel": "",
"m_DismissedVersion": 0,
"m_Precision": 0,
"overrideHLSLDeclaration": false,
"hlslDeclarationOverride": 0,
"m_Hidden": false,
"m_Value": {
"m_SerializedTexture": "",
"m_Guid": ""
},
"isMainTexture": true,
"useTilingAndOffset": true,
"m_Modifiable": true,
"m_DefaultType": 0
}
{
"m_SGVersion": 0,
"m_Type": "UnityEditor.ShaderGraph.ColorRGBMaterialSlot",
"m_ObjectId": "a8a3476bbfe8465fbf208d8592d231a3",
"m_Id": 0,
"m_DisplayName": "Emission",
"m_SlotType": 0,
"m_Hidden": false,
"m_ShaderOutputName": "Emission",
"m_StageCapability": 2,
"m_Value": {
"x": 0.0,
"y": 0.0,
"z": 0.0
},
"m_DefaultValue": {
"x": 0.0,
"y": 0.0,
"z": 0.0
},
"m_Labels": [],
"m_ColorMode": 1,
"m_DefaultColor": {
"r": 0.0,
"g": 0.0,
"b": 0.0,
"a": 1.0
}
}
{
"m_SGVersion": 0,
"m_Type": "UnityEditor.ShaderGraph.Vector1MaterialSlot",
"m_ObjectId": "c47fe1183b3b44d1ad66a998fde085f5",
"m_Id": 5,
"m_DisplayName": "G",
"m_SlotType": 1,
"m_Hidden": false,
"m_ShaderOutputName": "G",
"m_StageCapability": 2,
"m_Value": 0.0,
"m_DefaultValue": 0.0,
"m_Labels": []
}
{
"m_SGVersion": 0,
"m_Type": "UnityEditor.ShaderGraph.Vector1MaterialSlot",
"m_ObjectId": "cd2a46a6fe0746ae965dc193ce0757eb",
"m_Id": 0,
"m_DisplayName": "Metallic",
"m_SlotType": 0,
"m_Hidden": false,
"m_ShaderOutputName": "Metallic",
"m_StageCapability": 2,
"m_Value": 0.0,
"m_DefaultValue": 0.0,
"m_Labels": []
}
{
"m_SGVersion": 0,
"m_Type": "UnityEditor.ShaderGraph.NormalMaterialSlot",
"m_ObjectId": "e1de0ca351fd43ff866485e33328e300",
"m_Id": 0,
"m_DisplayName": "Normal",
"m_SlotType": 0,
"m_Hidden": false,
"m_ShaderOutputName": "Normal",
"m_StageCapability": 1,
"m_Value": {
"x": 0.0,
"y": 0.0,
"z": 0.0
},
"m_DefaultValue": {
"x": 0.0,
"y": 0.0,
"z": 0.0
},
"m_Labels": [],
"m_Space": 0
}
{
"m_SGVersion": 0,
"m_Type": "UnityEditor.ShaderGraph.BlockNode",
"m_ObjectId": "f56f676a56e04566a12f41980b760358",
"m_Group": {
"m_Id": ""
},
"m_Name": "VertexDescription.Position",
"m_DrawState": {
"m_Expanded": true,
"m_Position": {
"serializedVersion": "2",
"x": 0.0,
"y": 0.0,
"width": 0.0,
"height": 0.0
}
},
"m_Slots": [
{
"m_Id": "619a91e5d75d4a629f14de895dbebb39"
}
],
"synonyms": [],
"m_Precision": 0,
"m_PreviewExpanded": true,
"m_DismissedVersion": 0,
"m_PreviewMode": 0,
"m_CustomColors": {
"m_SerializableColors": []
},
"m_SerializedDescriptor": "VertexDescription.Position"
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,10 @@
fileFormatVersion: 2
guid: 868190a58757d6242bb3ca456402f82f
ScriptedImporter:
internalIDToNameTable: []
externalObjects: {}
serializedVersion: 2
userData:
assetBundleName:
assetBundleVariant:
script: {fileID: 11500000, guid: 625f186215c104763be7675aa2d941aa, type: 3}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,10 @@
fileFormatVersion: 2
guid: 2fe3270edce96f4438a6dcc501a8c5cd
ScriptedImporter:
internalIDToNameTable: []
externalObjects: {}
serializedVersion: 2
userData:
assetBundleName:
assetBundleVariant:
script: {fileID: 11500000, guid: 60072b568d64c40a485e0fc55012dc9f, type: 3}

Binary file not shown.

After

Width:  |  Height:  |  Size: 68 B

View File

@@ -0,0 +1,127 @@
fileFormatVersion: 2
guid: d8c7685da35f7994799534cbc1acce4a
TextureImporter:
internalIDToNameTable: []
externalObjects: {}
serializedVersion: 13
mipmaps:
mipMapMode: 0
enableMipMap: 1
sRGBTexture: 1
linearTexture: 0
fadeOut: 0
borderMipMap: 0
mipMapsPreserveCoverage: 0
alphaTestReferenceValue: 0.5
mipMapFadeDistanceStart: 1
mipMapFadeDistanceEnd: 3
bumpmap:
convertToNormalMap: 0
externalNormalMap: 0
heightScale: 0.25
normalMapFilter: 0
flipGreenChannel: 0
isReadable: 0
streamingMipmaps: 0
streamingMipmapsPriority: 0
vTOnly: 0
ignoreMipmapLimit: 0
grayScaleToAlpha: 0
generateCubemap: 6
cubemapConvolution: 0
seamlessCubemap: 0
textureFormat: 1
maxTextureSize: 2048
textureSettings:
serializedVersion: 2
filterMode: 1
aniso: 1
mipBias: 0
wrapU: 0
wrapV: 0
wrapW: 0
nPOTScale: 1
lightmap: 0
compressionQuality: 50
spriteMode: 0
spriteExtrude: 1
spriteMeshType: 1
alignment: 0
spritePivot: {x: 0.5, y: 0.5}
spritePixelsToUnits: 100
spriteBorder: {x: 0, y: 0, z: 0, w: 0}
spriteGenerateFallbackPhysicsShape: 1
alphaUsage: 1
alphaIsTransparency: 0
spriteTessellationDetail: -1
textureType: 0
textureShape: 1
singleChannelComponent: 0
flipbookRows: 1
flipbookColumns: 1
maxTextureSizeSet: 0
compressionQualitySet: 0
textureFormatSet: 0
ignorePngGamma: 0
applyGammaDecoding: 0
swizzle: 50462976
cookieLightType: 0
platformSettings:
- serializedVersion: 3
buildTarget: DefaultTexturePlatform
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
ignorePlatformSupport: 0
androidETC2FallbackOverride: 0
forceMaximumCompressionQuality_BC6H_BC7: 0
- serializedVersion: 3
buildTarget: Standalone
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
ignorePlatformSupport: 0
androidETC2FallbackOverride: 0
forceMaximumCompressionQuality_BC6H_BC7: 0
- serializedVersion: 3
buildTarget: WebGL
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
ignorePlatformSupport: 0
androidETC2FallbackOverride: 0
forceMaximumCompressionQuality_BC6H_BC7: 0
spriteSheet:
serializedVersion: 2
sprites: []
outline: []
physicsShape: []
bones: []
spriteID:
internalID: 0
vertices: []
indices:
edges: []
weights: []
secondaryTextures: []
nameFileIdTable: {}
mipmapLimitGroupName:
pSDRemoveMatte: 0
userData:
assetBundleName:
assetBundleVariant:

Binary file not shown.

After

Width:  |  Height:  |  Size: 79 B

View File

@@ -0,0 +1,127 @@
fileFormatVersion: 2
guid: 909670d47b2f55d4a991788acca59d7e
TextureImporter:
internalIDToNameTable: []
externalObjects: {}
serializedVersion: 13
mipmaps:
mipMapMode: 0
enableMipMap: 1
sRGBTexture: 1
linearTexture: 0
fadeOut: 0
borderMipMap: 0
mipMapsPreserveCoverage: 0
alphaTestReferenceValue: 0.5
mipMapFadeDistanceStart: 1
mipMapFadeDistanceEnd: 3
bumpmap:
convertToNormalMap: 0
externalNormalMap: 0
heightScale: 0.25
normalMapFilter: 0
flipGreenChannel: 0
isReadable: 0
streamingMipmaps: 0
streamingMipmapsPriority: 0
vTOnly: 0
ignoreMipmapLimit: 0
grayScaleToAlpha: 0
generateCubemap: 6
cubemapConvolution: 0
seamlessCubemap: 0
textureFormat: 1
maxTextureSize: 2048
textureSettings:
serializedVersion: 2
filterMode: 1
aniso: 1
mipBias: 0
wrapU: 0
wrapV: 0
wrapW: 0
nPOTScale: 1
lightmap: 0
compressionQuality: 50
spriteMode: 0
spriteExtrude: 1
spriteMeshType: 1
alignment: 0
spritePivot: {x: 0.5, y: 0.5}
spritePixelsToUnits: 100
spriteBorder: {x: 0, y: 0, z: 0, w: 0}
spriteGenerateFallbackPhysicsShape: 1
alphaUsage: 1
alphaIsTransparency: 0
spriteTessellationDetail: -1
textureType: 0
textureShape: 1
singleChannelComponent: 0
flipbookRows: 1
flipbookColumns: 1
maxTextureSizeSet: 0
compressionQualitySet: 0
textureFormatSet: 0
ignorePngGamma: 0
applyGammaDecoding: 0
swizzle: 50462976
cookieLightType: 0
platformSettings:
- serializedVersion: 3
buildTarget: DefaultTexturePlatform
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
ignorePlatformSupport: 0
androidETC2FallbackOverride: 0
forceMaximumCompressionQuality_BC6H_BC7: 0
- serializedVersion: 3
buildTarget: Standalone
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
ignorePlatformSupport: 0
androidETC2FallbackOverride: 0
forceMaximumCompressionQuality_BC6H_BC7: 0
- serializedVersion: 3
buildTarget: WebGL
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
ignorePlatformSupport: 0
androidETC2FallbackOverride: 0
forceMaximumCompressionQuality_BC6H_BC7: 0
spriteSheet:
serializedVersion: 2
sprites: []
outline: []
physicsShape: []
bones: []
spriteID:
internalID: 0
vertices: []
indices:
edges: []
weights: []
secondaryTextures: []
nameFileIdTable: {}
mipmapLimitGroupName:
pSDRemoveMatte: 0
userData:
assetBundleName:
assetBundleVariant:

Binary file not shown.

After

Width:  |  Height:  |  Size: 79 B

View File

@@ -0,0 +1,127 @@
fileFormatVersion: 2
guid: 51ce5cf2de6d788449c2fdd4b8488a92
TextureImporter:
internalIDToNameTable: []
externalObjects: {}
serializedVersion: 13
mipmaps:
mipMapMode: 0
enableMipMap: 1
sRGBTexture: 1
linearTexture: 0
fadeOut: 0
borderMipMap: 0
mipMapsPreserveCoverage: 0
alphaTestReferenceValue: 0.5
mipMapFadeDistanceStart: 1
mipMapFadeDistanceEnd: 3
bumpmap:
convertToNormalMap: 0
externalNormalMap: 0
heightScale: 0.25
normalMapFilter: 0
flipGreenChannel: 0
isReadable: 0
streamingMipmaps: 0
streamingMipmapsPriority: 0
vTOnly: 0
ignoreMipmapLimit: 0
grayScaleToAlpha: 0
generateCubemap: 6
cubemapConvolution: 0
seamlessCubemap: 0
textureFormat: 1
maxTextureSize: 2048
textureSettings:
serializedVersion: 2
filterMode: 1
aniso: 1
mipBias: 0
wrapU: 0
wrapV: 0
wrapW: 0
nPOTScale: 1
lightmap: 0
compressionQuality: 50
spriteMode: 0
spriteExtrude: 1
spriteMeshType: 1
alignment: 0
spritePivot: {x: 0.5, y: 0.5}
spritePixelsToUnits: 100
spriteBorder: {x: 0, y: 0, z: 0, w: 0}
spriteGenerateFallbackPhysicsShape: 1
alphaUsage: 1
alphaIsTransparency: 0
spriteTessellationDetail: -1
textureType: 0
textureShape: 1
singleChannelComponent: 0
flipbookRows: 1
flipbookColumns: 1
maxTextureSizeSet: 0
compressionQualitySet: 0
textureFormatSet: 0
ignorePngGamma: 0
applyGammaDecoding: 0
swizzle: 50462976
cookieLightType: 0
platformSettings:
- serializedVersion: 3
buildTarget: DefaultTexturePlatform
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
ignorePlatformSupport: 0
androidETC2FallbackOverride: 0
forceMaximumCompressionQuality_BC6H_BC7: 0
- serializedVersion: 3
buildTarget: Standalone
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
ignorePlatformSupport: 0
androidETC2FallbackOverride: 0
forceMaximumCompressionQuality_BC6H_BC7: 0
- serializedVersion: 3
buildTarget: WebGL
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
ignorePlatformSupport: 0
androidETC2FallbackOverride: 0
forceMaximumCompressionQuality_BC6H_BC7: 0
spriteSheet:
serializedVersion: 2
sprites: []
outline: []
physicsShape: []
bones: []
spriteID:
internalID: 0
vertices: []
indices:
edges: []
weights: []
secondaryTextures: []
nameFileIdTable: {}
mipmapLimitGroupName:
pSDRemoveMatte: 0
userData:
assetBundleName:
assetBundleVariant:

Binary file not shown.

After

Width:  |  Height:  |  Size: 79 B

View File

@@ -0,0 +1,127 @@
fileFormatVersion: 2
guid: 3ab316f1cf207684abb754d9a2731c66
TextureImporter:
internalIDToNameTable: []
externalObjects: {}
serializedVersion: 13
mipmaps:
mipMapMode: 0
enableMipMap: 1
sRGBTexture: 1
linearTexture: 0
fadeOut: 0
borderMipMap: 0
mipMapsPreserveCoverage: 0
alphaTestReferenceValue: 0.5
mipMapFadeDistanceStart: 1
mipMapFadeDistanceEnd: 3
bumpmap:
convertToNormalMap: 0
externalNormalMap: 0
heightScale: 0.25
normalMapFilter: 0
flipGreenChannel: 0
isReadable: 0
streamingMipmaps: 0
streamingMipmapsPriority: 0
vTOnly: 0
ignoreMipmapLimit: 0
grayScaleToAlpha: 0
generateCubemap: 6
cubemapConvolution: 0
seamlessCubemap: 0
textureFormat: 1
maxTextureSize: 2048
textureSettings:
serializedVersion: 2
filterMode: 1
aniso: 1
mipBias: 0
wrapU: 0
wrapV: 0
wrapW: 0
nPOTScale: 1
lightmap: 0
compressionQuality: 50
spriteMode: 0
spriteExtrude: 1
spriteMeshType: 1
alignment: 0
spritePivot: {x: 0.5, y: 0.5}
spritePixelsToUnits: 100
spriteBorder: {x: 0, y: 0, z: 0, w: 0}
spriteGenerateFallbackPhysicsShape: 1
alphaUsage: 1
alphaIsTransparency: 0
spriteTessellationDetail: -1
textureType: 0
textureShape: 1
singleChannelComponent: 0
flipbookRows: 1
flipbookColumns: 1
maxTextureSizeSet: 0
compressionQualitySet: 0
textureFormatSet: 0
ignorePngGamma: 0
applyGammaDecoding: 0
swizzle: 50462976
cookieLightType: 0
platformSettings:
- serializedVersion: 3
buildTarget: DefaultTexturePlatform
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
ignorePlatformSupport: 0
androidETC2FallbackOverride: 0
forceMaximumCompressionQuality_BC6H_BC7: 0
- serializedVersion: 3
buildTarget: Standalone
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
ignorePlatformSupport: 0
androidETC2FallbackOverride: 0
forceMaximumCompressionQuality_BC6H_BC7: 0
- serializedVersion: 3
buildTarget: WebGL
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
ignorePlatformSupport: 0
androidETC2FallbackOverride: 0
forceMaximumCompressionQuality_BC6H_BC7: 0
spriteSheet:
serializedVersion: 2
sprites: []
outline: []
physicsShape: []
bones: []
spriteID:
internalID: 0
vertices: []
indices:
edges: []
weights: []
secondaryTextures: []
nameFileIdTable: {}
mipmapLimitGroupName:
pSDRemoveMatte: 0
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,6 @@
#?RADIANCE
SOFTWARE=GEGL
FORMAT=32-bit_rle_rgbe
-Y 2 +X 2
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>

View File

@@ -0,0 +1,127 @@
fileFormatVersion: 2
guid: 09e6225be3a2a43489e11a41cb198377
TextureImporter:
internalIDToNameTable: []
externalObjects: {}
serializedVersion: 13
mipmaps:
mipMapMode: 0
enableMipMap: 1
sRGBTexture: 1
linearTexture: 0
fadeOut: 0
borderMipMap: 0
mipMapsPreserveCoverage: 0
alphaTestReferenceValue: 0.5
mipMapFadeDistanceStart: 1
mipMapFadeDistanceEnd: 3
bumpmap:
convertToNormalMap: 0
externalNormalMap: 0
heightScale: 0.25
normalMapFilter: 0
flipGreenChannel: 0
isReadable: 0
streamingMipmaps: 0
streamingMipmapsPriority: 0
vTOnly: 0
ignoreMipmapLimit: 0
grayScaleToAlpha: 0
generateCubemap: 6
cubemapConvolution: 0
seamlessCubemap: 0
textureFormat: 1
maxTextureSize: 2048
textureSettings:
serializedVersion: 2
filterMode: 1
aniso: 1
mipBias: 0
wrapU: 0
wrapV: 0
wrapW: 0
nPOTScale: 1
lightmap: 0
compressionQuality: 50
spriteMode: 0
spriteExtrude: 1
spriteMeshType: 1
alignment: 0
spritePivot: {x: 0.5, y: 0.5}
spritePixelsToUnits: 100
spriteBorder: {x: 0, y: 0, z: 0, w: 0}
spriteGenerateFallbackPhysicsShape: 1
alphaUsage: 1
alphaIsTransparency: 0
spriteTessellationDetail: -1
textureType: 0
textureShape: 1
singleChannelComponent: 0
flipbookRows: 1
flipbookColumns: 1
maxTextureSizeSet: 0
compressionQualitySet: 0
textureFormatSet: 0
ignorePngGamma: 0
applyGammaDecoding: 0
swizzle: 50462976
cookieLightType: 0
platformSettings:
- serializedVersion: 3
buildTarget: DefaultTexturePlatform
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
ignorePlatformSupport: 0
androidETC2FallbackOverride: 0
forceMaximumCompressionQuality_BC6H_BC7: 0
- serializedVersion: 3
buildTarget: Standalone
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
ignorePlatformSupport: 0
androidETC2FallbackOverride: 0
forceMaximumCompressionQuality_BC6H_BC7: 0
- serializedVersion: 3
buildTarget: WebGL
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
ignorePlatformSupport: 0
androidETC2FallbackOverride: 0
forceMaximumCompressionQuality_BC6H_BC7: 0
spriteSheet:
serializedVersion: 2
sprites: []
outline: []
physicsShape: []
bones: []
spriteID:
internalID: 0
vertices: []
indices:
edges: []
weights: []
secondaryTextures: []
nameFileIdTable: {}
mipmapLimitGroupName:
pSDRemoveMatte: 0
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: da380cc015227a946a8a8ccd61811b82
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,9 @@
using UniGLTF;
namespace UniVRM10.VRM10Viewer
{
public interface IMaterialImporter
{
bool TryCreateParam(GltfData data, int i, out MaterialDescriptor matDesc);
}
}

View File

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

View File

@@ -0,0 +1,88 @@
using System.Collections.Generic;
using UniGLTF;
namespace UniVRM10.VRM10Viewer
{
/// <summary>
/// Importersに格納したを順番に試行して成功したらそれを採用する。
/// mtoon, unlit, pbr の順に試行することを想定。
/// </summary>
public sealed class OrderedMaterialDescriptorGenerator : IMaterialDescriptorGenerator
{
public readonly List<IMaterialImporter> Importers = new();
public delegate MaterialDescriptor MakeDefaultMaterialDescriptor(string materialName);
private readonly MakeDefaultMaterialDescriptor _makeDefault;
/// <summary>
/// 順に TryCreateParam を実行して最初に成功したら終わる。
/// 全て失敗したら UrpGltfDefaultMaterialImporter を実行する。
/// 通常 vrm-1.0, unlit, pbr の順に試行する。
/// </summary>
/// <param name="importers"></param>
public OrderedMaterialDescriptorGenerator(MakeDefaultMaterialDescriptor makeDefault, params IMaterialImporter[] importers)
{
_makeDefault = makeDefault;
Importers.AddRange(importers);
}
public static OrderedMaterialDescriptorGenerator CreateCustomGenerator(
IMaterialImporter customPbr,
IMaterialImporter customMToonImporter = null)
{
var generator = new OrderedMaterialDescriptorGenerator((new UrpGltfDefaultMaterialImporter()).CreateParam);
// 最初にMToonの分岐
// generator.Importers は前から順に処理します
if (customMToonImporter != null)
{
// TinyMToon(WebGL 向け) を使う例
generator.Importers.Add(customMToonImporter);
}
else
{
// VRM10/Universal Render Pipeline/MToon10 を使う例
generator.Importers.Add(new UrpMToonMaterialImporter());
}
// 次に unlit の分岐
generator.Importers.Add(new UnlitMaterialImporter());
// 次に pbr の分岐
if (customPbr != null)
{
// TinyPbr を使う例
generator.Importers.Add(customPbr);
}
else
{
// Universal Render Pipeline/Lit を使う例
// AlwaysIncludedShaders に登録すると、Variant が多すぎてビルドが終わらない問題があります。
generator.Importers.Add(new UrpPbrMaterialImporter());
}
return generator;
}
public MaterialDescriptor Get(GltfData data, int i)
{
foreach (var importer in Importers)
{
if (importer.TryCreateParam(data, i, out var param))
{
return param;
}
}
// NOTE: Fallback to default material
if (Symbols.VRM_DEVELOP)
{
UniGLTFLogger.Warning($"material: {i} out of range. fallback");
}
return GetGltfDefault(GltfMaterialImportUtils.ImportMaterialName(i, null));
}
public MaterialDescriptor GetGltfDefault(string materialName = null) => _makeDefault(materialName);
}
}

View File

@@ -0,0 +1,139 @@
using System.Dynamic;
using UnityEngine;
namespace UniVRM10.VRM10Viewer
{
public class TinyMToonMaterialContext
{
//
// When using shadergraph, you need to expose the following properties.
//
/// <summary>
/// Color = White
/// </summary>
private static readonly int BaseColorProp = Shader.PropertyToID("_BaseColor");
/// <summary>
/// Texture2D = white
/// When using shadergraph, require "Set as Main Texture"
/// </summary>
private static readonly int BaseMapProp = Shader.PropertyToID("_BaseMap");
private static readonly int ShadingColorFactorProp = Shader.PropertyToID("_ShadingColor");
private static readonly int ShadingMapProp = Shader.PropertyToID("_ShadingMap");
private static readonly int ShadingToonyFactorProp = Shader.PropertyToID("_ShadingToonyFactor");
private static readonly int ShadingShiftFactorProp = Shader.PropertyToID("_ShadingShiftFactor");
/// <summary>
/// float = 1.0
/// </summary>
private static readonly int BumpScaleProp = Shader.PropertyToID("_BumpScale");
/// <summary>
/// Texture2D = [0, 0, 1.0]
/// </summary>
private static readonly int BumpMapProp = Shader.PropertyToID("_BumpMap");
/// <summary>
/// Color = black
/// </summary>
private static readonly int EmissionColorProp = Shader.PropertyToID("_EmissionColor");
/// <summary>
/// Texture2D = black
/// </summary>
private static readonly int EmissionMapProp = Shader.PropertyToID("_EmissionMap");
/// <summary>
/// boolean keyword
/// </summary>
private static readonly int CutoffEnabledProp = Shader.PropertyToID("_CutoffEnabled");
/// <summary>
/// float = 0.5
/// </summary>
private static readonly int CutoffProp = Shader.PropertyToID("_Cutoff");
public readonly Material Material;
public TinyMToonMaterialContext(Material material)
{
Material = material;
}
public Color BaseColorSrgb
{
get => Material.GetColor(BaseColorProp);
set => Material.SetColor(BaseColorProp, value);
}
public Texture BaseTexture
{
get => Material.GetTexture(BaseMapProp);
set => Material.SetTexture(BaseMapProp, value);
}
public Vector2 BaseTextureOffset
{
get => Material.GetTextureOffset(BaseMapProp);
set => Material.SetTextureOffset(BaseMapProp, value);
}
public Vector2 BaseTextureScale
{
get => Material.GetTextureScale(BaseMapProp);
set => Material.SetTextureScale(BaseMapProp, value);
}
public Color ShadingColorFactorSrgb
{
get => Material.GetColor(ShadingColorFactorProp);
set => Material.SetColor(ShadingColorFactorProp, value);
}
public Texture ShadingTexture
{
get => Material.GetTexture(ShadingMapProp);
set => Material.SetTexture(ShadingMapProp, value);
}
public float ShadingToonyFactor
{
get => Material.GetFloat(ShadingToonyFactorProp);
set => Material.SetFloat(ShadingToonyFactorProp, value);
}
public float ShadingShiftFactor
{
get => Material.GetFloat(ShadingShiftFactorProp);
set => Material.SetFloat(ShadingShiftFactorProp, value);
}
public float BumpScale
{
get => Material.GetFloat(BumpScaleProp);
set => Material.SetFloat(BumpScaleProp, value);
}
public Texture BumpMap
{
get => Material.GetTexture(BumpMapProp);
set
{
Material.SetTexture(BumpMapProp, value);
}
}
public Color EmissionColorLinear
{
get => Material.GetColor(EmissionColorProp);
set => Material.SetColor(EmissionColorProp, value);
}
public Texture EmissionTexture
{
get => Material.GetTexture(EmissionMapProp);
set => Material.SetTexture(EmissionMapProp, value);
}
public bool CutoffEnabled
{
get => Material.GetInt(CutoffEnabledProp) != 0;
set => Material.SetInt(CutoffEnabledProp, value ? 1 : 0);
}
public float Cutoff
{
get => Material.GetFloat(CutoffProp);
set => Material.SetFloat(CutoffProp, value);
}
}
}

View File

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

View File

@@ -0,0 +1,120 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using UniGLTF;
using UniGLTF.Extensions.VRMC_materials_mtoon;
using UnityEngine;
namespace UniVRM10.VRM10Viewer
{
public class TinyMToonrMaterialImporter : IMaterialImporter
{
private Material m_opaque;
private Material m_alphablend;
public TinyMToonrMaterialImporter(Material opaque, Material alphablend)
{
m_opaque = opaque;
m_alphablend = alphablend;
}
bool IMaterialImporter.TryCreateParam(GltfData data, int i, out MaterialDescriptor matDesc)
{
if (i < 0 || i >= data.GLTF.materials.Count)
{
matDesc = default;
return false;
}
var src = data.GLTF.materials[i];
if (!UniGLTF.Extensions.VRMC_materials_mtoon.GltfDeserializer.TryGet(src.extensions, out var mtoon))
{
// Fallback to glTF, when MToon extension does not exist.
matDesc = default;
return false;
}
matDesc = new MaterialDescriptor(
GltfMaterialImportUtils.ImportMaterialName(i, src),
src.alphaMode == "BLEND" ? m_alphablend.shader : m_opaque.shader,
new[] { (MaterialDescriptor.MaterialGenerateAsyncFunc)AsyncAction }
);
return true;
Task AsyncAction(Material x, GetTextureAsyncFunc y, IAwaitCaller z) => GenerateMaterialAsync(data, src, mtoon, x, y, z);
}
public static async Task GenerateMaterialAsync(GltfData data, glTFMaterial src, VRMC_materials_mtoon mtoon, Material dst, GetTextureAsyncFunc getTextureAsync, IAwaitCaller awaitCaller)
{
var context = new TinyMToonMaterialContext(dst);
ImportSurfaceSettings(src, context);
await ImportBaseShadeColorAsync(data, src, mtoon, context, getTextureAsync, awaitCaller);
await ImportNormalAsync(data, src, context, getTextureAsync, awaitCaller);
// await ImportEmissionAsync(data, src, context, getTextureAsync, awaitCaller);
// context.Validate();
}
public static void ImportSurfaceSettings(glTFMaterial src, TinyMToonMaterialContext context)
{
// context.SurfaceType = src.alphaMode switch
// {
// "OPAQUE" => UrpLitSurfaceType.Opaque,
// "MASK" => UrpLitSurfaceType.Transparent,
// "BLEND" => UrpLitSurfaceType.Transparent,
// _ => UrpLitSurfaceType.Opaque,
// };
// context.BlendMode = context.SurfaceType switch
// {
// UrpLitSurfaceType.Transparent => UrpLitBlendMode.Alpha,
// _ => UrpLitBlendMode.Alpha,
// };
context.CutoffEnabled = src.alphaMode == "MASK";
context.Cutoff = src.alphaCutoff;
// context.CullMode = src.doubleSided ? CullMode.Off : CullMode.Back;
}
public static async Task ImportBaseShadeColorAsync(GltfData data, glTFMaterial src, VRMC_materials_mtoon mtoon, TinyMToonMaterialContext context, GetTextureAsyncFunc getTextureAsync, IAwaitCaller awaitCaller)
{
var baseColorFactor = GltfMaterialImportUtils.ImportLinearBaseColorFactor(data, src);
if (baseColorFactor.HasValue)
{
context.BaseColorSrgb = baseColorFactor.Value.gamma;
}
if (src is { pbrMetallicRoughness: { baseColorTexture: { index: >= 0 } } })
{
if (GltfPbrTextureImporter.TryBaseColorTexture(data, src, out _, out var desc))
{
context.BaseTexture = await getTextureAsync(desc, awaitCaller);
context.BaseTextureOffset = desc.Offset;
context.BaseTextureScale = desc.Scale;
}
}
context.ShadingToonyFactor = mtoon.ShadingToonyFactor.GetValueOrDefault();
context.ShadingShiftFactor = mtoon.ShadingToonyFactor.GetValueOrDefault();
var shadeColor = mtoon.ShadeColorFactor?.ToColor3(UniGLTF.ColorSpace.Linear, UniGLTF.ColorSpace.sRGB);
context.ShadingColorFactorSrgb = shadeColor.GetValueOrDefault(Color.white);
if (mtoon is { ShadeMultiplyTexture: { Index: >= 0 } })
{
if (Vrm10MToonTextureImporter.TryGetShadeMultiplyTexture(data, mtoon, out var _, out var desc))
{
context.ShadingTexture = await getTextureAsync(desc, awaitCaller);
}
}
}
private static async Task ImportNormalAsync(GltfData data, glTFMaterial src, TinyMToonMaterialContext context, GetTextureAsyncFunc getTextureAsync, IAwaitCaller awaitCaller)
{
if (src.normalTexture is { index: >= 0 })
{
if (GltfPbrTextureImporter.TryNormalTexture(data, src, out _, out var desc))
{
context.BumpMap = await getTextureAsync(desc, awaitCaller);
context.BumpScale = src.normalTexture.scale;
}
}
}
}
}

View File

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

View File

@@ -0,0 +1,154 @@
using UnityEngine;
namespace UniVRM10.VRM10Viewer
{
public class TinyPbrMaterialContext
{
//
// When using shadergraph, you need to expose the following properties.
//
/// <summary>
/// Color = White
/// </summary>
private static readonly int BaseColorProp = Shader.PropertyToID("_BaseColor");
/// <summary>
/// Texture2D = white
/// When using shadergraph, require "Set as Main Texture"
/// </summary>
private static readonly int BaseMapProp = Shader.PropertyToID("_BaseMap");
/// <summary>
/// float = 1.0
/// </summary>
private static readonly int OcclusionStrengthProp = Shader.PropertyToID("_OcclusionStrength");
/// <summary>
/// Texture2D.Red = 1.0.
/// </summary>
private static readonly int OcclusionMapProp = Shader.PropertyToID("_OcclusionMap");
private static readonly int RoughnessProp = Shader.PropertyToID("_Roughness");
private static readonly int MetallicProp = Shader.PropertyToID("_Metallic");
/// <summary>
/// Texture2D.Green = 1.0. The roughness
/// Texture2D.Blue = 1.0. The metalness
/// </summary>
private static readonly int MetallicRoughnessMapProp = Shader.PropertyToID("_MetallicRoughnessMap");
/// <summary>
/// float = 1.0
/// </summary>
private static readonly int BumpScaleProp = Shader.PropertyToID("_BumpScale");
/// <summary>
/// Texture2D = [0, 0, 1.0]
/// </summary>
private static readonly int BumpMapProp = Shader.PropertyToID("_BumpMap");
/// <summary>
/// Color = black
/// </summary>
private static readonly int EmissionColorProp = Shader.PropertyToID("_EmissionColor");
/// <summary>
/// Texture2D = black
/// </summary>
private static readonly int EmissionMapProp = Shader.PropertyToID("_EmissionMap");
/// <summary>
/// boolean keyword
/// </summary>
private static readonly int CutoffEnabledProp = Shader.PropertyToID("_CutoffEnabled");
/// <summary>
/// float = 0.5
/// </summary>
private static readonly int CutoffProp = Shader.PropertyToID("_Cutoff");
public readonly Material Material;
public TinyPbrMaterialContext(Material material)
{
Material = material;
}
public Color BaseColorSrgb
{
get => Material.GetColor(BaseColorProp);
set => Material.SetColor(BaseColorProp, value);
}
public Texture BaseTexture
{
get => Material.GetTexture(BaseMapProp);
set => Material.SetTexture(BaseMapProp, value);
}
public Vector2 BaseTextureOffset
{
get => Material.GetTextureOffset(BaseMapProp);
set => Material.SetTextureOffset(BaseMapProp, value);
}
public Vector2 BaseTextureScale
{
get => Material.GetTextureScale(BaseMapProp);
set => Material.SetTextureScale(BaseMapProp, value);
}
public float OcclusionStrength
{
get => Material.GetFloat(OcclusionStrengthProp);
set => Material.SetFloat(OcclusionStrengthProp, value);
}
public Texture OcclusionTexture
{
get => Material.GetTexture(OcclusionMapProp);
set
{
Material.SetTexture(OcclusionMapProp, value);
}
}
public float Roughness
{
get => Material.GetFloat(RoughnessProp);
set => Material.SetFloat(RoughnessProp, value);
}
public float Metallic
{
get => Material.GetFloat(MetallicProp);
set => Material.SetFloat(MetallicProp, value);
}
public Texture MetallicRoughnessMap
{
get => Material.GetTexture(MetallicRoughnessMapProp);
set => Material.SetTexture(MetallicRoughnessMapProp, value);
}
public float BumpScale
{
get => Material.GetFloat(BumpScaleProp);
set => Material.SetFloat(BumpScaleProp, value);
}
public Texture BumpMap
{
get => Material.GetTexture(BumpMapProp);
set
{
Material.SetTexture(BumpMapProp, value);
}
}
public Color EmissionColorLinear
{
get => Material.GetColor(EmissionColorProp);
set => Material.SetColor(EmissionColorProp, value);
}
public Texture EmissionTexture
{
get => Material.GetTexture(EmissionMapProp);
set => Material.SetTexture(EmissionMapProp, value);
}
public bool CutoffEnabled
{
get => Material.GetInt(CutoffEnabledProp) != 0;
set => Material.SetInt(CutoffEnabledProp, value ? 1 : 0);
}
public float Cutoff
{
get => Material.GetFloat(CutoffProp);
set => Material.SetFloat(CutoffProp, value);
}
}
}

View File

@@ -0,0 +1,157 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using UniGLTF;
using UnityEngine;
namespace UniVRM10.VRM10Viewer
{
public class TinyPbrMaterialImporter : IMaterialImporter
{
// public const string ALPHABLEND_SHADER_NAME = "Shader Graphs/TinyPbrAlphaBlend";
// public const string OPAQUE_SHADER_NAME = "Shader Graphs/TinyPbrOpaque";
Material m_opaque;
Material m_alphablend;
public TinyPbrMaterialImporter(Material opaque, Material alphablend)
{
m_opaque = opaque;
m_alphablend = alphablend;
}
bool IMaterialImporter.TryCreateParam(GltfData data, int i, out MaterialDescriptor matDesc)
{
if (i < 0 || i >= data.GLTF.materials.Count)
{
matDesc = default;
return false;
}
var src = data.GLTF.materials[i];
matDesc = new MaterialDescriptor(
GltfMaterialImportUtils.ImportMaterialName(i, src),
src.alphaMode == "BLEND" ? m_alphablend.shader : m_opaque.shader,
new[] { (MaterialDescriptor.MaterialGenerateAsyncFunc)AsyncAction }
);
return true;
Task AsyncAction(Material x, GetTextureAsyncFunc y, IAwaitCaller z) => GenerateMaterialAsync(data, src, x, y, z);
}
public static async Task GenerateMaterialAsync(GltfData data, glTFMaterial src, Material dst, GetTextureAsyncFunc getTextureAsync, IAwaitCaller awaitCaller)
{
var context = new TinyPbrMaterialContext(dst);
ImportSurfaceSettings(src, context);
await ImportBaseColorAsync(data, src, context, getTextureAsync, awaitCaller);
await ImportMetallicRoughnessAsync(data, src, context, getTextureAsync, awaitCaller);
await ImportOcclusionAsync(data, src, context, getTextureAsync, awaitCaller);
await ImportNormalAsync(data, src, context, getTextureAsync, awaitCaller);
await ImportEmissionAsync(data, src, context, getTextureAsync, awaitCaller);
// context.Validate();
}
public static void ImportSurfaceSettings(glTFMaterial src, TinyPbrMaterialContext context)
{
// context.SurfaceType = src.alphaMode switch
// {
// "OPAQUE" => UrpLitSurfaceType.Opaque,
// "MASK" => UrpLitSurfaceType.Transparent,
// "BLEND" => UrpLitSurfaceType.Transparent,
// _ => UrpLitSurfaceType.Opaque,
// };
// context.BlendMode = context.SurfaceType switch
// {
// UrpLitSurfaceType.Transparent => UrpLitBlendMode.Alpha,
// _ => UrpLitBlendMode.Alpha,
// };
context.CutoffEnabled = src.alphaMode == "MASK";
context.Cutoff = src.alphaCutoff;
// context.CullMode = src.doubleSided ? CullMode.Off : CullMode.Back;
}
public static async Task ImportBaseColorAsync(GltfData data, glTFMaterial src, TinyPbrMaterialContext context, GetTextureAsyncFunc getTextureAsync, IAwaitCaller awaitCaller)
{
var baseColorFactor = GltfMaterialImportUtils.ImportLinearBaseColorFactor(data, src);
if (baseColorFactor.HasValue)
{
context.BaseColorSrgb = baseColorFactor.Value.gamma;
}
if (src is { pbrMetallicRoughness: { baseColorTexture: { index: >= 0 } } })
{
if (GltfPbrTextureImporter.TryBaseColorTexture(data, src, out _, out var desc))
{
context.BaseTexture = await getTextureAsync(desc, awaitCaller);
context.BaseTextureOffset = desc.Offset;
context.BaseTextureScale = desc.Scale;
}
}
}
public static async Task ImportMetallicRoughnessAsync(GltfData data, glTFMaterial src, TinyPbrMaterialContext context, GetTextureAsyncFunc getTextureAsync, IAwaitCaller awaitCaller)
{
if (src.pbrMetallicRoughness != null)
{
context.Metallic = src.pbrMetallicRoughness.metallicFactor;
context.Roughness = src.pbrMetallicRoughness.roughnessFactor;
}
if (src is { pbrMetallicRoughness: { metallicRoughnessTexture: { index: >= 0 } } })
{
var (offset, scale) = GltfTextureImporter.GetTextureOffsetAndScale(src.pbrMetallicRoughness.metallicRoughnessTexture);
if (GltfTextureImporter.TryCreateLinear(data, src.pbrMetallicRoughness.metallicRoughnessTexture.index, offset, scale, out var _, out var desc))
{
context.MetallicRoughnessMap = await getTextureAsync(desc, awaitCaller);
}
}
}
public static async Task ImportOcclusionAsync(GltfData data, glTFMaterial src, TinyPbrMaterialContext context, GetTextureAsyncFunc getTextureAsync, IAwaitCaller awaitCaller)
{
if (src.occlusionTexture != null)
{
context.OcclusionStrength = src.occlusionTexture.strength;
}
if (src is { occlusionTexture: { index: >= 0 } })
{
var (offset, scale) = GltfTextureImporter.GetTextureOffsetAndScale(src.occlusionTexture);
if (GltfTextureImporter.TryCreateLinear(data, src.occlusionTexture.index, offset, scale, out var _, out var desc))
{
context.OcclusionTexture = await getTextureAsync(desc, awaitCaller);
}
}
}
private static async Task ImportNormalAsync(GltfData data, glTFMaterial src, TinyPbrMaterialContext context, GetTextureAsyncFunc getTextureAsync, IAwaitCaller awaitCaller)
{
if (src.normalTexture is { index: >= 0 })
{
if (GltfPbrTextureImporter.TryNormalTexture(data, src, out _, out var desc))
{
context.BumpMap = await getTextureAsync(desc, awaitCaller);
context.BumpScale = src.normalTexture.scale;
}
}
}
private static async Task ImportEmissionAsync(GltfData data, glTFMaterial src, TinyPbrMaterialContext context, GetTextureAsyncFunc getTextureAsync, IAwaitCaller awaitCaller)
{
var emissiveFactor = GltfMaterialImportUtils.ImportLinearEmissiveFactor(data, src);
if (emissiveFactor.HasValue)
{
context.EmissionColorLinear = emissiveFactor.Value;
}
if (src is { emissiveTexture: { index: >= 0 } })
{
if (GltfPbrTextureImporter.TryEmissiveTexture(data, src, out _, out var desc))
{
context.EmissionTexture = await getTextureAsync(desc, awaitCaller);
}
}
}
}
}

View File

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

View File

@@ -0,0 +1,12 @@
using UniGLTF;
namespace UniVRM10.VRM10Viewer
{
class UnlitMaterialImporter : IMaterialImporter
{
bool IMaterialImporter.TryCreateParam(GltfData data, int i, out MaterialDescriptor matDesc)
{
return BuiltInGltfUnlitMaterialImporter.TryCreateParam(data, i, out matDesc);
}
}
}

View File

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

View File

@@ -0,0 +1,19 @@
using UniGLTF;
namespace UniVRM10.VRM10Viewer
{
/// <summary>
/// VRM10/Universal Render Pipeline/MToon10
/// </summary>
public class UrpMToonMaterialImporter : IMaterialImporter
{
public bool TryCreateParam(GltfData data, int i, out MaterialDescriptor matDesc)
{
if (UrpVrm10MToonMaterialImporter.TryCreateParam(data, i, out matDesc))
{
return true;
}
return false;
}
}
}

View File

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

View File

@@ -0,0 +1,18 @@
using UniGLTF;
namespace UniVRM10.VRM10Viewer
{
public class UrpPbrMaterialImporter : IMaterialImporter
{
public UrpGltfPbrMaterialImporter PbrMaterialImporter { get; } = new();
public bool TryCreateParam(GltfData data, int i, out MaterialDescriptor matDesc)
{
if (PbrMaterialImporter.TryCreateParam(data, i, out matDesc))
{
return true;
}
return false;
}
}
}

View File

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

View File

@@ -1,33 +0,0 @@
using UnityEngine;
namespace UniVRM10.VRM10Viewer
{
public class TinyPbrContext
{
private static readonly int BaseMap = Shader.PropertyToID("_BaseMap");
public readonly Material Material;
public Texture BaseTexture
{
get => Material.GetTexture(BaseMap);
set => Material.SetTexture(BaseMap, value);
}
public Vector2 BaseTextureOffset
{
get => Material.GetTextureOffset(BaseMap);
set => Material.SetTextureOffset(BaseMap, value);
}
public Vector2 BaseTextureScale
{
get => Material.GetTextureScale(BaseMap);
set => Material.SetTextureScale(BaseMap, value);
}
public TinyPbrContext(Material material)
{
Material = material;
}
}
}

View File

@@ -1,84 +0,0 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using UniGLTF;
using UnityEngine;
namespace UniVRM10.VRM10Viewer
{
/// <summary>
/// GLTF の MaterialImporter
/// </summary>
public sealed class TinyPbrDescriptorGenerator : IMaterialDescriptorGenerator
{
public UrpGltfPbrMaterialImporter PbrMaterialImporter { get; } = new();
public UrpGltfDefaultMaterialImporter DefaultMaterialImporter { get; } = new();
public Material Material { get; set; }
public TinyPbrDescriptorGenerator(Material material)
{
Material = material;
}
public MaterialDescriptor Get(GltfData data, int i)
{
// TODO: VRM
// UNLIT
MaterialDescriptor param;
// if (BuiltInGltfUnlitMaterialImporter.TryCreateParam(data, i, out param)) return param;
if (TryCreateParam(data, i, out param)) return param;
// NOTE: Fallback to default material
if (Symbols.VRM_DEVELOP)
{
UniGLTFLogger.Warning($"material: {i} out of range. fallback");
}
return GetGltfDefault(GltfMaterialImportUtils.ImportMaterialName(i, null));
}
public MaterialDescriptor GetGltfDefault(string materialName = null) => DefaultMaterialImporter.CreateParam(materialName);
public bool TryCreateParam(GltfData data, int i, out MaterialDescriptor matDesc)
{
if (i < 0 || i >= data.GLTF.materials.Count)
{
matDesc = default;
return false;
}
var src = data.GLTF.materials[i];
matDesc = new MaterialDescriptor(
GltfMaterialImportUtils.ImportMaterialName(i, src),
Material.shader,
null,
new Dictionary<string, TextureDescriptor>(),
new Dictionary<string, float>(),
new Dictionary<string, Color>(),
new Dictionary<string, Vector4>(),
new List<Action<Material>>(),
new[] { (MaterialDescriptor.MaterialGenerateAsyncFunc)AsyncAction }
);
return true;
Task AsyncAction(Material x, GetTextureAsyncFunc y, IAwaitCaller z) => GenerateMaterialAsync(data, src, x, y, z);
}
public static async Task GenerateMaterialAsync(GltfData data, glTFMaterial src, Material dst, GetTextureAsyncFunc getTextureAsync, IAwaitCaller awaitCaller)
{
var context = new TinyPbrContext(dst);
if (src is { pbrMetallicRoughness: { baseColorTexture: { index: >= 0 } } })
{
if (GltfPbrTextureImporter.TryBaseColorTexture(data, src, out _, out var desc))
{
context.BaseTexture = await getTextureAsync(desc, awaitCaller);
context.BaseTextureOffset = desc.Offset;
context.BaseTextureScale = desc.Scale;
}
}
}
}
}

View File

@@ -10,7 +10,7 @@ namespace UniVRM10.VRM10Viewer
Vrm10Instance m_vrm;
public Vrm10Instance Instance => m_vrm;
public Vrm10RuntimeControlRig ControlRig => m_vrm.Runtime.ControlRig;
public Vrm10Runtime Runtime => m_vrm.Runtime;
public Vrm10Runtime Runtime => m_vrm?.Runtime;
public Loaded(RuntimeGltfInstance instance)
{

View File

@@ -24,13 +24,16 @@ namespace UniVRM10.VRM10Viewer
while (true)
{
angle += m_angularVelocity * Time.deltaTime * Mathf.Deg2Rad;
if (this.enabled)
{
angle += m_angularVelocity * Time.deltaTime * Mathf.Deg2Rad;
var x = Mathf.Cos(angle) * m_radius;
var z = Mathf.Sin(angle) * m_radius;
var y = m_y + m_height * Mathf.Cos(angle / 3);
var x = Mathf.Cos(angle) * m_radius;
var z = Mathf.Sin(angle) * m_radius;
var y = m_y + m_height * Mathf.Cos(angle / 3);
transform.localPosition = new Vector3(x, y, z);
transform.localPosition = new Vector3(x, y, z);
}
yield return null;
}

View File

@@ -4717,7 +4717,7 @@ Transform:
m_GameObject: {fileID: 322182884}
serializedVersion: 2
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalPosition: {x: 0, y: -0.001, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
@@ -4931,6 +4931,7 @@ RectTransform:
- {fileID: 1767706907}
- {fileID: 1621794411}
- {fileID: 731212245}
- {fileID: 358762027}
- {fileID: 2009818432}
- {fileID: 103723704}
- {fileID: 602093298}
@@ -5130,6 +5131,92 @@ MonoBehaviour:
m_PersistentCalls:
m_Calls: []
m_IsOn: 0
--- !u!1 &358762026
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 358762027}
- component: {fileID: 358762028}
m_Layer: 5
m_Name: UseCustomMToorMaterial
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!224 &358762027
RectTransform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 358762026}
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children:
- {fileID: 2090176800}
- {fileID: 1405688945}
m_Father: {fileID: 339774397}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 0, y: 0}
m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: 0, y: 20}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!114 &358762028
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 358762026}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 9085046f02f69544eb97fd06b6048fe2, type: 3}
m_Name:
m_EditorClassIdentifier:
m_Navigation:
m_Mode: 3
m_WrapAround: 0
m_SelectOnUp: {fileID: 0}
m_SelectOnDown: {fileID: 0}
m_SelectOnLeft: {fileID: 0}
m_SelectOnRight: {fileID: 0}
m_Transition: 1
m_Colors:
m_NormalColor: {r: 1, g: 1, b: 1, a: 1}
m_HighlightedColor: {r: 0.9607843, g: 0.9607843, b: 0.9607843, a: 1}
m_PressedColor: {r: 0.78431374, g: 0.78431374, b: 0.78431374, a: 1}
m_SelectedColor: {r: 0.9607843, g: 0.9607843, b: 0.9607843, a: 1}
m_DisabledColor: {r: 0.78431374, g: 0.78431374, b: 0.78431374, a: 0.5019608}
m_ColorMultiplier: 1
m_FadeDuration: 0.1
m_SpriteState:
m_HighlightedSprite: {fileID: 0}
m_PressedSprite: {fileID: 0}
m_SelectedSprite: {fileID: 0}
m_DisabledSprite: {fileID: 0}
m_AnimationTriggers:
m_NormalTrigger: Normal
m_HighlightedTrigger: Highlighted
m_PressedTrigger: Pressed
m_SelectedTrigger: Highlighted
m_DisabledTrigger: Disabled
m_Interactable: 1
m_TargetGraphic: {fileID: 2090176801}
toggleTransition: 1
graphic: {fileID: 379278027}
m_Group: {fileID: 0}
onValueChanged:
m_PersistentCalls:
m_Calls: []
m_IsOn: 0
--- !u!1 &364098868
GameObject:
m_ObjectHideFlags: 0
@@ -5464,6 +5551,81 @@ CanvasRenderer:
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 377012217}
m_CullTransparentMesh: 1
--- !u!1 &379278025
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 379278026}
- component: {fileID: 379278028}
- component: {fileID: 379278027}
m_Layer: 5
m_Name: Checkmark
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!224 &379278026
RectTransform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 379278025}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 2090176800}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0.5, y: 0.5}
m_AnchorMax: {x: 0.5, y: 0.5}
m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: 20, y: 20}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!114 &379278027
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 379278025}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: fe87c0e1cc204ed48ad3b37840f39efc, type: 3}
m_Name:
m_EditorClassIdentifier:
m_Material: {fileID: 0}
m_Color: {r: 1, g: 1, b: 1, a: 1}
m_RaycastTarget: 1
m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0}
m_Maskable: 1
m_OnCullStateChanged:
m_PersistentCalls:
m_Calls: []
m_Sprite: {fileID: 10901, guid: 0000000000000000f000000000000000, type: 0}
m_Type: 0
m_PreserveAspect: 0
m_FillCenter: 1
m_FillMethod: 4
m_FillAmount: 1
m_FillClockwise: 1
m_FillOrigin: 0
m_UseSpriteMesh: 0
m_PixelsPerUnitMultiplier: 1
--- !u!222 &379278028
CanvasRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 379278025}
m_CullTransparentMesh: 0
--- !u!1 &381534432
GameObject:
m_ObjectHideFlags: 0
@@ -5651,7 +5813,9 @@ MonoBehaviour:
m_HorizontalOverflow: 0
m_VerticalOverflow: 0
m_LineSpacing: 1
m_Text: Use CustomMaterial
m_Text: 'Use CustomPbrMaterial
'
--- !u!222 &390989033
CanvasRenderer:
m_ObjectHideFlags: 0
@@ -12326,7 +12490,7 @@ GameObject:
- component: {fileID: 731212245}
- component: {fileID: 731212246}
m_Layer: 5
m_Name: UseCustomMaterial
m_Name: UseCustomPbrMaterial
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
@@ -23821,6 +23985,87 @@ RectTransform:
m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: 0, y: 28}
m_Pivot: {x: 0.5, y: 1}
--- !u!1 &1405688944
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 1405688945}
- component: {fileID: 1405688947}
- component: {fileID: 1405688946}
m_Layer: 5
m_Name: Label
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!224 &1405688945
RectTransform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1405688944}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 358762027}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 1, y: 1}
m_AnchoredPosition: {x: 9, y: -0.5}
m_SizeDelta: {x: -28, y: -3}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!114 &1405688946
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1405688944}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 5f7201a12d95ffc409449d95f23cf332, type: 3}
m_Name:
m_EditorClassIdentifier:
m_Material: {fileID: 0}
m_Color: {r: 0.19607843, g: 0.19607843, b: 0.19607843, a: 1}
m_RaycastTarget: 1
m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0}
m_Maskable: 1
m_OnCullStateChanged:
m_PersistentCalls:
m_Calls: []
m_FontData:
m_Font: {fileID: 10102, guid: 0000000000000000e000000000000000, type: 0}
m_FontSize: 14
m_FontStyle: 0
m_BestFit: 0
m_MinSize: 10
m_MaxSize: 40
m_Alignment: 0
m_AlignByGeometry: 0
m_RichText: 1
m_HorizontalOverflow: 0
m_VerticalOverflow: 0
m_LineSpacing: 1
m_Text: 'Use CustomMToonMaterial
'
--- !u!222 &1405688947
CanvasRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1405688944}
m_CullTransparentMesh: 0
--- !u!1 &1406385458
GameObject:
m_ObjectHideFlags: 0
@@ -30638,9 +30883,16 @@ MonoBehaviour:
Root: {fileID: 124675793}
m_version: {fileID: 1268276256}
m_faceCamera: {fileID: 1150163685}
m_customMaterial: {fileID: -876546973899608171, guid: ac58f8c11a130e04ba883a82ae4b78e4,
m_pbrOpaqueMaterial: {fileID: -876546973899608171, guid: ac58f8c11a130e04ba883a82ae4b78e4,
type: 3}
m_useCustomMaterial: {fileID: 731212246}
m_pbrAlphaBlendMaterial: {fileID: -876546973899608171, guid: 868190a58757d6242bb3ca456402f82f,
type: 3}
m_mtoonMaterialOpaque: {fileID: -876546973899608171, guid: fd08e80eb7e04e849b8a6d534e48efea,
type: 3}
m_mtoonMaterialAlphaBlend: {fileID: -876546973899608171, guid: 6b60fe85d745eda4281e3278fcb0657c,
type: 3}
m_useCustomPbrMaterial: {fileID: 731212246}
m_useCustomMToonMaterial: {fileID: 358762028}
m_openModel: {fileID: 2009818433}
m_openMotion: {fileID: 168425996}
m_pastePose: {fileID: 1307084564}
@@ -35727,6 +35979,82 @@ CanvasRenderer:
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2085434813}
m_CullTransparentMesh: 1
--- !u!1 &2090176799
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 2090176800}
- component: {fileID: 2090176802}
- component: {fileID: 2090176801}
m_Layer: 5
m_Name: Background
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!224 &2090176800
RectTransform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2090176799}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children:
- {fileID: 379278026}
m_Father: {fileID: 358762027}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 1}
m_AnchorMax: {x: 0, y: 1}
m_AnchoredPosition: {x: 10, y: -10}
m_SizeDelta: {x: 20, y: 20}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!114 &2090176801
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2090176799}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: fe87c0e1cc204ed48ad3b37840f39efc, type: 3}
m_Name:
m_EditorClassIdentifier:
m_Material: {fileID: 0}
m_Color: {r: 1, g: 1, b: 1, a: 1}
m_RaycastTarget: 1
m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0}
m_Maskable: 1
m_OnCullStateChanged:
m_PersistentCalls:
m_Calls: []
m_Sprite: {fileID: 10905, guid: 0000000000000000f000000000000000, type: 0}
m_Type: 1
m_PreserveAspect: 0
m_FillCenter: 1
m_FillMethod: 4
m_FillAmount: 1
m_FillClockwise: 1
m_FillOrigin: 0
m_UseSpriteMesh: 0
m_PixelsPerUnitMultiplier: 1
--- !u!222 &2090176802
CanvasRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2090176799}
m_CullTransparentMesh: 0
--- !u!1 &2092455692
GameObject:
m_ObjectHideFlags: 0

View File

@@ -9,6 +9,7 @@ using System.Threading.Tasks;
using UniGLTF;
using UniGLTF.SpringBoneJobs.Blittables;
using UnityEngine;
using UnityEngine.Rendering;
using UnityEngine.UI;
namespace UniVRM10.VRM10Viewer
@@ -24,11 +25,19 @@ namespace UniVRM10.VRM10Viewer
[Header("Material")]
[SerializeField]
Material m_customMaterial = default;
Material m_pbrOpaqueMaterial = default;
[SerializeField]
Material m_pbrAlphaBlendMaterial = default;
[SerializeField]
Material m_mtoonMaterialOpaque = default;
[SerializeField]
Material m_mtoonMaterialAlphaBlend = default;
[Header("UI")]
[SerializeField]
Toggle m_useCustomMaterial = default;
Toggle m_useCustomPbrMaterial = default;
[SerializeField]
Toggle m_useCustomMToonMaterial = default;
[SerializeField]
Button m_openModel = default;
@@ -372,7 +381,8 @@ namespace UniVRM10.VRM10Viewer
{
var map = new ObjectMap(gameObject);
Root = map.Objects["Root"];
m_useCustomMaterial = map.Get<Toggle>("CustomMaterial");
m_useCustomPbrMaterial = map.Get<Toggle>("CustomPbrMaterial");
m_useCustomMToonMaterial = map.Get<Toggle>("CustomMToonMaterial");
m_openModel = map.Get<Button>("OpenModel");
m_openMotion = map.Get<Button>("OpenMotion");
m_pastePose = map.Get<Button>("PastePose");
@@ -479,8 +489,23 @@ namespace UniVRM10.VRM10Viewer
VRM10Blinker m_autoBlink;
VRM10AIUEO m_autoLipsync;
private TinyMToonrMaterialImporter m_mtoonImporter;
private TinyPbrMaterialImporter m_pbrImporter;
private void Start()
{
if (m_mtoonMaterialOpaque != null && m_mtoonMaterialAlphaBlend != null)
{
m_mtoonImporter = new(m_mtoonMaterialOpaque, m_mtoonMaterialAlphaBlend);
}
if (m_pbrOpaqueMaterial != null && m_pbrAlphaBlendMaterial != null)
{
m_pbrImporter = new(m_pbrOpaqueMaterial, m_pbrAlphaBlendMaterial);
}
// URP かつ WebGL で有効にする
m_useCustomMToonMaterial.isOn = Application.platform == RuntimePlatform.WebGLPlayer && GraphicsSettings.renderPipelineAsset != null;
m_autoEmotion = gameObject.AddComponent<VRM10AutoExpression>();
m_autoBlink = gameObject.AddComponent<VRM10Blinker>();
m_autoLipsync = gameObject.AddComponent<VRM10AIUEO>();
@@ -497,15 +522,16 @@ namespace UniVRM10.VRM10Viewer
if (m_motion != null)
{
Motion = BvhMotion.LoadBvhFromText(m_motion.text);
if (m_useCustomMaterial.isOn)
if (GraphicsSettings.renderPipelineAsset != null
&& m_pbrAlphaBlendMaterial != null)
{
Motion.SetBoxManMaterial(Instantiate(m_customMaterial));
Motion.SetBoxManMaterial(Instantiate(m_pbrOpaqueMaterial));
}
}
if (ArgumentChecker.TryGetFirstLoadable(out var cmd))
{
var _ = LoadModel(cmd);
var _ = LoadModelPath(cmd);
}
m_texts.Start();
@@ -558,96 +584,97 @@ namespace UniVRM10.VRM10Viewer
StopSpringBoneWriteback = m_springbonePause.isOn,
SupportsScalingAtRuntime = m_springboneScaling.isOn,
});
}
m_happy.ApplyRuntime(m_loaded.Instance.Vrm.Expression.Happy);
m_angry.ApplyRuntime(m_loaded.Instance.Vrm.Expression.Angry);
m_sad.ApplyRuntime(m_loaded.Instance.Vrm.Expression.Sad);
m_relaxed.ApplyRuntime(m_loaded.Instance.Vrm.Expression.Relaxed);
m_surprised.ApplyRuntime(m_loaded.Instance.Vrm.Expression.Surprised);
m_lipAa.ApplyRuntime(m_loaded.Instance.Vrm.Expression.Aa);
m_lipIh.ApplyRuntime(m_loaded.Instance.Vrm.Expression.Ih);
m_lipOu.ApplyRuntime(m_loaded.Instance.Vrm.Expression.Ou);
m_lipEe.ApplyRuntime(m_loaded.Instance.Vrm.Expression.Ee);
m_lipOh.ApplyRuntime(m_loaded.Instance.Vrm.Expression.Oh);
m_blink.ApplyRuntime(m_loaded.Instance.Vrm.Expression.Blink);
if (m_enableAutoExpression.isOn)
{
vrm.Runtime.Expression.SetWeight(ExpressionKey.Happy, m_autoEmotion.Happy);
vrm.Runtime.Expression.SetWeight(ExpressionKey.Angry, m_autoEmotion.Angry);
vrm.Runtime.Expression.SetWeight(ExpressionKey.Sad, m_autoEmotion.Sad);
vrm.Runtime.Expression.SetWeight(ExpressionKey.Relaxed, m_autoEmotion.Relaxed);
vrm.Runtime.Expression.SetWeight(ExpressionKey.Surprised, m_autoEmotion.Surprised);
m_happy.m_expression.SetValueWithoutNotify(m_autoEmotion.Happy);
m_angry.m_expression.SetValueWithoutNotify(m_autoEmotion.Angry);
m_sad.m_expression.SetValueWithoutNotify(m_autoEmotion.Sad);
m_relaxed.m_expression.SetValueWithoutNotify(m_autoEmotion.Relaxed);
m_surprised.m_expression.SetValueWithoutNotify(m_autoEmotion.Surprised);
}
else
{
vrm.Runtime.Expression.SetWeight(ExpressionKey.Happy, m_happy.m_expression.value);
vrm.Runtime.Expression.SetWeight(ExpressionKey.Angry, m_angry.m_expression.value);
vrm.Runtime.Expression.SetWeight(ExpressionKey.Sad, m_sad.m_expression.value);
vrm.Runtime.Expression.SetWeight(ExpressionKey.Relaxed, m_relaxed.m_expression.value);
vrm.Runtime.Expression.SetWeight(ExpressionKey.Surprised, m_surprised.m_expression.value);
}
m_happy.ApplyRuntime(m_loaded.Instance.Vrm.Expression.Happy);
m_angry.ApplyRuntime(m_loaded.Instance.Vrm.Expression.Angry);
m_sad.ApplyRuntime(m_loaded.Instance.Vrm.Expression.Sad);
m_relaxed.ApplyRuntime(m_loaded.Instance.Vrm.Expression.Relaxed);
m_surprised.ApplyRuntime(m_loaded.Instance.Vrm.Expression.Surprised);
m_lipAa.ApplyRuntime(m_loaded.Instance.Vrm.Expression.Aa);
m_lipIh.ApplyRuntime(m_loaded.Instance.Vrm.Expression.Ih);
m_lipOu.ApplyRuntime(m_loaded.Instance.Vrm.Expression.Ou);
m_lipEe.ApplyRuntime(m_loaded.Instance.Vrm.Expression.Ee);
m_lipOh.ApplyRuntime(m_loaded.Instance.Vrm.Expression.Oh);
m_blink.ApplyRuntime(m_loaded.Instance.Vrm.Expression.Blink);
if (m_enableLipSync.isOn)
{
vrm.Runtime.Expression.SetWeight(ExpressionKey.Aa, m_autoLipsync.Aa);
vrm.Runtime.Expression.SetWeight(ExpressionKey.Ih, m_autoLipsync.Ih);
vrm.Runtime.Expression.SetWeight(ExpressionKey.Ou, m_autoLipsync.Ou);
vrm.Runtime.Expression.SetWeight(ExpressionKey.Ee, m_autoLipsync.Ee);
vrm.Runtime.Expression.SetWeight(ExpressionKey.Oh, m_autoLipsync.Oh);
m_lipAa.m_expression.SetValueWithoutNotify(m_autoLipsync.Aa);
m_lipIh.m_expression.SetValueWithoutNotify(m_autoLipsync.Ih);
m_lipOu.m_expression.SetValueWithoutNotify(m_autoLipsync.Ou);
m_lipEe.m_expression.SetValueWithoutNotify(m_autoLipsync.Ee);
m_lipOh.m_expression.SetValueWithoutNotify(m_autoLipsync.Oh);
}
else
{
vrm.Runtime.Expression.SetWeight(ExpressionKey.Aa, m_lipAa.m_expression.value);
vrm.Runtime.Expression.SetWeight(ExpressionKey.Ih, m_lipIh.m_expression.value);
vrm.Runtime.Expression.SetWeight(ExpressionKey.Ou, m_lipOu.m_expression.value);
vrm.Runtime.Expression.SetWeight(ExpressionKey.Ee, m_lipEe.m_expression.value);
vrm.Runtime.Expression.SetWeight(ExpressionKey.Oh, m_lipOh.m_expression.value);
}
if (m_enableAutoExpression.isOn)
{
vrm.Runtime.Expression.SetWeight(ExpressionKey.Happy, m_autoEmotion.Happy);
vrm.Runtime.Expression.SetWeight(ExpressionKey.Angry, m_autoEmotion.Angry);
vrm.Runtime.Expression.SetWeight(ExpressionKey.Sad, m_autoEmotion.Sad);
vrm.Runtime.Expression.SetWeight(ExpressionKey.Relaxed, m_autoEmotion.Relaxed);
vrm.Runtime.Expression.SetWeight(ExpressionKey.Surprised, m_autoEmotion.Surprised);
m_happy.m_expression.SetValueWithoutNotify(m_autoEmotion.Happy);
m_angry.m_expression.SetValueWithoutNotify(m_autoEmotion.Angry);
m_sad.m_expression.SetValueWithoutNotify(m_autoEmotion.Sad);
m_relaxed.m_expression.SetValueWithoutNotify(m_autoEmotion.Relaxed);
m_surprised.m_expression.SetValueWithoutNotify(m_autoEmotion.Surprised);
}
else
{
vrm.Runtime.Expression.SetWeight(ExpressionKey.Happy, m_happy.m_expression.value);
vrm.Runtime.Expression.SetWeight(ExpressionKey.Angry, m_angry.m_expression.value);
vrm.Runtime.Expression.SetWeight(ExpressionKey.Sad, m_sad.m_expression.value);
vrm.Runtime.Expression.SetWeight(ExpressionKey.Relaxed, m_relaxed.m_expression.value);
vrm.Runtime.Expression.SetWeight(ExpressionKey.Surprised, m_surprised.m_expression.value);
}
if (m_enableAutoBlink.isOn)
{
vrm.Runtime.Expression.SetWeight(ExpressionKey.Blink, m_autoBlink.BlinkValue);
m_blink.m_expression.SetValueWithoutNotify(m_autoBlink.BlinkValue);
}
else
{
vrm.Runtime.Expression.SetWeight(ExpressionKey.Blink, m_blink.m_expression.value);
}
if (m_enableLipSync.isOn)
{
vrm.Runtime.Expression.SetWeight(ExpressionKey.Aa, m_autoLipsync.Aa);
vrm.Runtime.Expression.SetWeight(ExpressionKey.Ih, m_autoLipsync.Ih);
vrm.Runtime.Expression.SetWeight(ExpressionKey.Ou, m_autoLipsync.Ou);
vrm.Runtime.Expression.SetWeight(ExpressionKey.Ee, m_autoLipsync.Ee);
vrm.Runtime.Expression.SetWeight(ExpressionKey.Oh, m_autoLipsync.Oh);
m_lipAa.m_expression.SetValueWithoutNotify(m_autoLipsync.Aa);
m_lipIh.m_expression.SetValueWithoutNotify(m_autoLipsync.Ih);
m_lipOu.m_expression.SetValueWithoutNotify(m_autoLipsync.Ou);
m_lipEe.m_expression.SetValueWithoutNotify(m_autoLipsync.Ee);
m_lipOh.m_expression.SetValueWithoutNotify(m_autoLipsync.Oh);
}
else
{
vrm.Runtime.Expression.SetWeight(ExpressionKey.Aa, m_lipAa.m_expression.value);
vrm.Runtime.Expression.SetWeight(ExpressionKey.Ih, m_lipIh.m_expression.value);
vrm.Runtime.Expression.SetWeight(ExpressionKey.Ou, m_lipOu.m_expression.value);
vrm.Runtime.Expression.SetWeight(ExpressionKey.Ee, m_lipEe.m_expression.value);
vrm.Runtime.Expression.SetWeight(ExpressionKey.Oh, m_lipOh.m_expression.value);
}
if (m_useLookAtTarget.isOn)
{
var (yaw, pitch) = vrm.Runtime.LookAt.CalculateYawPitchFromLookAtPosition(m_lookAtTarget.transform.position);
vrm.Runtime.LookAt.SetYawPitchManually(yaw, pitch);
m_yaw.value = yaw;
m_pitch.value = pitch;
}
else
{
vrm.Runtime.LookAt.SetYawPitchManually(m_yaw.value, m_pitch.value);
}
if (m_enableAutoBlink.isOn)
{
vrm.Runtime.Expression.SetWeight(ExpressionKey.Blink, m_autoBlink.BlinkValue);
m_blink.m_expression.SetValueWithoutNotify(m_autoBlink.BlinkValue);
}
else
{
vrm.Runtime.Expression.SetWeight(ExpressionKey.Blink, m_blink.m_expression.value);
}
if (vrm.TryGetBoneTransform(HumanBodyBones.Head, out var head))
{
var initLocarlRotation = vrm.DefaultTransformStates[head].LocalRotation;
var r = head.rotation * Quaternion.Inverse(initLocarlRotation);
var pos = head.position
+ (r * Vector3.forward * 0.7f)
+ (r * Vector3.up * 0.07f)
;
m_faceCamera.position = pos;
m_faceCamera.rotation = r;
if (m_useLookAtTarget.isOn)
{
var (yaw, pitch) = vrm.Runtime.LookAt.CalculateYawPitchFromLookAtPosition(m_lookAtTarget.transform.position);
vrm.Runtime.LookAt.SetYawPitchManually(yaw, pitch);
m_yaw.value = yaw;
m_pitch.value = pitch;
}
else
{
vrm.Runtime.LookAt.SetYawPitchManually(m_yaw.value, m_pitch.value);
}
if (vrm.TryGetBoneTransform(HumanBodyBones.Head, out var head))
{
var initLocarlRotation = vrm.DefaultTransformStates[head].LocalRotation;
var r = head.rotation * Quaternion.Inverse(initLocarlRotation);
var pos = head.position
+ (r * Vector3.forward * 0.7f)
+ (r * Vector3.up * 0.07f)
;
m_faceCamera.position = pos;
m_faceCamera.rotation = r;
}
}
}
}
@@ -657,10 +684,10 @@ namespace UniVRM10.VRM10Viewer
string FileDialog()
{
#if UNITY_EDITOR
return UnityEditor.EditorUtility.OpenFilePanel("Open VRM", "", "vrm");
#if UNITY_EDITOR
return UnityEditor.EditorUtility.OpenFilePanel("Open VRM", "", "vrm,glb,gltf,zip");
#elif UNITY_STANDALONE_WIN
return VRM10FileDialogForWindows.FileDialog("open VRM", "vrm");
return VRM10FileDialogForWindows.FileDialog("open VRM", "vrm", "glb", "gltf", "zip");
#elif UNITY_WEBGL
// Open WebGL_VRM10_VRM10Viewer_FileDialog
// see: Assets/UniGLTF/Runtime/Utils/Plugins/OpenFile.jslib
@@ -675,19 +702,7 @@ namespace UniVRM10.VRM10Viewer
void OnOpenModelClicked()
{
var path = FileDialog();
if (string.IsNullOrEmpty(path))
{
return;
}
var ext = Path.GetExtension(path).ToLower();
if (ext != ".vrm")
{
UniGLTFLogger.Warning($"{path} is not vrm");
return;
}
_ = LoadModel(path);
_ = LoadModelPath(path);
}
/// <summary>
@@ -704,15 +719,15 @@ namespace UniVRM10.VRM10Viewer
{
var www = new WWW(url);
yield return www;
var _ = LoadModel("WebGL.vrm", www.bytes);
var _ = LoadModelBytes("WebGL.vrm", www.bytes);
}
async void OnOpenMotionClicked()
{
#if UNITY_STANDALONE_WIN
#if UNITY_EDITOR
var path = UnityEditor.EditorUtility.OpenFilePanel("Open Motion", "", "bvh,gltf,glb,vrma");
#elif UNITY_STANDALONE_WIN
var path = VRM10FileDialogForWindows.FileDialog("open Motion", "bvh", "gltf", "glb", "vrma");
#elif UNITY_EDITOR
var path = UnityEditor.EditorUtility.OpenFilePanel("Open Motion", "", "bvh");
#else
var path = Application.dataPath + "/default.bvh";
#endif
@@ -780,39 +795,33 @@ namespace UniVRM10.VRM10Viewer
}
}
static IMaterialDescriptorGenerator GetVrmMaterialDescriptorGenerator(bool useUrp)
{
if (useUrp)
{
return new UrpVrm10MaterialDescriptorGenerator();
}
else
{
return new BuiltInVrm10MaterialDescriptorGenerator();
}
}
IMaterialDescriptorGenerator GetMaterialDescriptorGenerator()
{
if (m_useCustomMaterial.isOn)
{
return new TinyPbrDescriptorGenerator(m_customMaterial);
}
else
var useCustomPbr = m_useCustomPbrMaterial.isOn && m_pbrImporter != null;
var useCustomMToon = m_useCustomMToonMaterial.isOn && m_mtoonImporter != null;
if (!useCustomPbr && !useCustomMToon)
{
// カスタムしない。デフォルトのローダーを使う
return default;
}
return OrderedMaterialDescriptorGenerator.CreateCustomGenerator(
useCustomPbr ? m_pbrImporter : null,
useCustomMToon ? m_mtoonImporter : null);
}
IAwaitCaller GetIAwaitCaller()
{
if (m_useAsync.isOn)
{
#if UNITY_WEBGL
return new RuntimeOnlyNoThreadAwaitCaller();
#else
return new RuntimeOnlyAwaitCaller();
#endif
if (Application.platform == RuntimePlatform.WebGLPlayer)
{
return new RuntimeOnlyNoThreadAwaitCaller();
}
else
{
return new RuntimeOnlyAwaitCaller();
}
}
else
{
@@ -820,13 +829,13 @@ namespace UniVRM10.VRM10Viewer
}
}
async Task LoadModel(string path)
async Task LoadModelPath(string path)
{
var bytes = await File.ReadAllBytesAsync(path);
await LoadModel(path, bytes);
await LoadModelBytes(path, bytes);
}
async Task LoadModel(string path, byte[] bytes)
async Task LoadModelBytes(string path, byte[] bytes)
{
// cleanup
m_loaded?.Dispose();
@@ -837,6 +846,9 @@ namespace UniVRM10.VRM10Viewer
try
{
//
// try VRM
//
UniGLTFLogger.Log($"{path}");
var vrm10Instance = await Vrm10.LoadBytesAsync(bytes,
canLoadVrm0X: true,
@@ -876,16 +888,34 @@ namespace UniVRM10.VRM10Viewer
m_lipOh.OnLoad(m_loaded.Instance.Vrm.Expression.Oh);
m_blink.OnLoad(m_loaded.Instance.Vrm.Expression.Blink);
}
catch (Exception ex)
catch (Exception)
{
if (ex is OperationCanceledException)
try
{
UniGLTFLogger.Warning($"Canceled to Load: {path}");
//
// fallback gltf
//
var instance = await GltfUtility.LoadBytesAsync(path, bytes,
awaitCaller: GetIAwaitCaller(),
materialGenerator: GetMaterialDescriptorGenerator()
);
instance.ShowMeshes();
instance.EnableUpdateWhenOffscreen();
m_loaded = new Loaded(instance);
m_showBoxMan.isOn = false;
}
else
catch (Exception ex)
{
UniGLTFLogger.Error($"Failed to Load: {path}");
UniGLTFLogger.Exception(ex);
if (ex is OperationCanceledException)
{
UniGLTFLogger.Warning($"Canceled to Load: {path}");
}
else
{
UniGLTFLogger.Error($"Failed to Load: {path}");
UniGLTFLogger.Exception(ex);
}
}
}
}

Some files were not shown because too many files have changed in this diff Show More