mirror of
https://github.com/vrm-c/UniVRM.git
synced 2026-04-25 07:28:51 -05:00
Merge branch 'master' of https://github.com/vrm-c/UniVRM into fixExporterInterface
This commit is contained in:
commit
2a01ef551b
|
|
@ -141,6 +141,9 @@ namespace VRM
|
|||
loaded.TransferOwnership(SaveAsAsset);
|
||||
var root = loaded.Root;
|
||||
|
||||
// Remove RuntimeGltfInstance component before saving as a prefab.
|
||||
UnityObjectDestoyer.DestroyRuntimeOrEditor(loaded);
|
||||
|
||||
// Create or update Main Asset
|
||||
if (m_prefabPath.IsFileExists)
|
||||
{
|
||||
|
|
@ -155,7 +158,7 @@ namespace VRM
|
|||
}
|
||||
|
||||
// destroy GameObject on scene
|
||||
GameObject.DestroyImmediate(root);
|
||||
UnityObjectDestoyer.DestroyRuntimeOrEditor(root);
|
||||
|
||||
foreach (var x in m_paths)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -8,7 +8,8 @@ namespace VRM
|
|||
{
|
||||
public static class VRMUnlitTransparentZWriteMaterialImporter
|
||||
{
|
||||
public const string ShaderName = "VRM/UnlitTransparentZWrite";
|
||||
public const string UnlitTransparentZWriteShaderName = "VRM/UnlitTransparentZWrite";
|
||||
public const string UnlitTransparentZWriteMainTexturePropName = "_MainTex";
|
||||
|
||||
public static bool TryCreateParam(GltfData data, glTF_VRM_extensions vrm, int materialIdx, out MaterialDescriptor matDesc)
|
||||
{
|
||||
|
|
@ -24,9 +25,8 @@ namespace VRM
|
|||
}
|
||||
|
||||
var vrmMaterial = vrm.materialProperties[materialIdx];
|
||||
if (vrmMaterial.shader != ShaderName)
|
||||
if (vrmMaterial.shader != UnlitTransparentZWriteShaderName)
|
||||
{
|
||||
// fallback to gltf
|
||||
matDesc = default;
|
||||
return false;
|
||||
}
|
||||
|
|
@ -34,50 +34,121 @@ namespace VRM
|
|||
// use material.name, because material name may renamed in GltfParser.
|
||||
var name = data.GLTF.materials[materialIdx].name;
|
||||
|
||||
//
|
||||
// import as MToon
|
||||
//
|
||||
matDesc = new MaterialDescriptor(name, MToon.Utils.ShaderName);
|
||||
|
||||
matDesc.RenderQueue = MToon.Utils.GetRenderQueueRequirement(RenderMode.TransparentWithZWrite).DefaultValue;
|
||||
|
||||
// NOTE: Unlit のフォールバックなので、 Lit/Shade 色は黒とし、Emissive Factor に設定する.
|
||||
// また、元のシェーダのうちユーザが設定できるプロパティは Texture のみ.
|
||||
matDesc.Colors[MToon.Utils.PropColor] = Color.black;
|
||||
matDesc.Colors[MToon.Utils.PropShadeColor] = Color.black;
|
||||
matDesc.Colors[MToon.Utils.PropEmissionColor] = Color.white;
|
||||
|
||||
if (vrmMaterial.textureProperties.ContainsKey(MToon.Utils.PropMainTex))
|
||||
if (vrmMaterial.textureProperties.ContainsKey(UnlitTransparentZWriteMainTexturePropName))
|
||||
{
|
||||
if (VRMMToonTextureImporter.TryGetTextureFromMaterialProperty(data, vrmMaterial, MToon.Utils.PropMainTex, out var texture))
|
||||
if (VRMMToonTextureImporter.TryGetTextureFromMaterialProperty(data, vrmMaterial, UnlitTransparentZWriteMainTexturePropName, out var texture))
|
||||
{
|
||||
matDesc.TextureSlots.Add(MToon.Utils.PropEmissionMap, texture.Item2);
|
||||
matDesc.TextureSlots.Add(MToon.Utils.PropMainTex, texture.Item2);
|
||||
}
|
||||
}
|
||||
|
||||
matDesc.Actions.Add(unityMaterial =>
|
||||
{
|
||||
// NOTE: ZWrite などの属性は util に設定させる.
|
||||
var parameter = MToon.Utils.GetMToonParametersFromMaterial(unityMaterial);
|
||||
parameter.Rendering.CullMode = CullMode.Back;
|
||||
parameter.Rendering.RenderMode = RenderMode.TransparentWithZWrite;
|
||||
parameter.Rendering.RenderQueueOffsetNumber = 0;
|
||||
MToon.Utils.SetMToonParametersToMaterial(unityMaterial, parameter);
|
||||
});
|
||||
|
||||
if (vrmMaterial.shader == MToon.Utils.ShaderName)
|
||||
{
|
||||
// TODO: Material拡張にMToonの項目が追加されたら旧バージョンのshaderPropから変換をかける
|
||||
// インポート時にUniVRMに含まれるMToonのバージョンに上書きする
|
||||
matDesc.FloatValues[MToon.Utils.PropVersion] = MToon.Utils.VersionNumber;
|
||||
}
|
||||
|
||||
matDesc.Actions.Add(m =>
|
||||
{
|
||||
m.SetFloat(MToon.Utils.PropBlendMode, (float)MToon.RenderMode.TransparentWithZWrite);
|
||||
MToon.Utils.ValidateProperties(m, true);
|
||||
var mainTexture = (Texture2D) unityMaterial.GetTexture(MToon.Utils.PropMainTex);
|
||||
|
||||
// NOTE: Unlit のフォールバックなので
|
||||
// Lit/Shade 色は黒として、Alpha のために Lit にテクスチャを設定する.
|
||||
// Emissive 色は白として、テクスチャを設定する.
|
||||
// また、元のシェーダのうちユーザが設定できるプロパティは Texture のみ.
|
||||
MToon.Utils.SetMToonParametersToMaterial(unityMaterial, new MToonDefinition
|
||||
{
|
||||
Meta = new MetaDefinition
|
||||
{
|
||||
Implementation = MToon.Utils.Implementation,
|
||||
VersionNumber = MToon.Utils.VersionNumber,
|
||||
},
|
||||
Rendering = new RenderingDefinition
|
||||
{
|
||||
// NOTE: Transparent ZWrite
|
||||
RenderMode = RenderMode.TransparentWithZWrite,
|
||||
CullMode = CullMode.Back,
|
||||
RenderQueueOffsetNumber = 0,
|
||||
},
|
||||
Color = new ColorDefinition
|
||||
{
|
||||
// NOTE: Unlit なので、RGB 値は黒とする。
|
||||
// NOTE: Alpha は使うので、テクスチャを設定する.
|
||||
LitColor = new Color(0, 0, 0, 1),
|
||||
LitMultiplyTexture = mainTexture,
|
||||
ShadeColor = new Color(0, 0, 0, 1),
|
||||
ShadeMultiplyTexture = default,
|
||||
CutoutThresholdValue = 0.5f,
|
||||
},
|
||||
Lighting = new LightingDefinition
|
||||
{
|
||||
LitAndShadeMixing = new LitAndShadeMixingDefinition
|
||||
{
|
||||
// NOTE: default value
|
||||
ShadingShiftValue = 0,
|
||||
ShadingToonyValue = 1,
|
||||
ShadowReceiveMultiplierValue = 1,
|
||||
ShadowReceiveMultiplierMultiplyTexture = default,
|
||||
LitAndShadeMixingMultiplierValue = 1,
|
||||
LitAndShadeMixingMultiplierMultiplyTexture = default,
|
||||
},
|
||||
LightingInfluence = new LightingInfluenceDefinition
|
||||
{
|
||||
// NOTE: default value
|
||||
LightColorAttenuationValue = 0,
|
||||
GiIntensityValue = 0.1f,
|
||||
},
|
||||
Normal = new NormalDefinition
|
||||
{
|
||||
// NOTE: default value
|
||||
NormalTexture = default,
|
||||
NormalScaleValue = 1,
|
||||
},
|
||||
},
|
||||
Emission = new EmissionDefinition
|
||||
{
|
||||
// NOTE: Unlit なので Emission にテクスチャを設定する.
|
||||
EmissionColor = Color.white,
|
||||
EmissionMultiplyTexture = mainTexture,
|
||||
},
|
||||
MatCap = new MatCapDefinition
|
||||
{
|
||||
// NOTE: default value
|
||||
AdditiveTexture = default,
|
||||
},
|
||||
Rim = new RimDefinition
|
||||
{
|
||||
// NOTE: default value
|
||||
RimColor = Color.black,
|
||||
RimMultiplyTexture = default,
|
||||
RimLightingMixValue = 1,
|
||||
RimLiftValue = 0,
|
||||
RimFresnelPowerValue = 1,
|
||||
},
|
||||
Outline = new OutlineDefinition
|
||||
{
|
||||
// NOTE: default value
|
||||
OutlineWidthMode = OutlineWidthMode.None,
|
||||
OutlineWidthValue = 0,
|
||||
OutlineWidthMultiplyTexture = default,
|
||||
OutlineScaledMaxDistanceValue = 1,
|
||||
OutlineColorMode = OutlineColorMode.FixedColor,
|
||||
OutlineColor = Color.black,
|
||||
OutlineLightingMixValue = 1,
|
||||
},
|
||||
TextureOption = new TextureUvCoordsDefinition
|
||||
{
|
||||
// NOTE: default value
|
||||
MainTextureLeftBottomOriginScale = new Vector2(1, 1),
|
||||
MainTextureLeftBottomOriginOffset = new Vector2(0, 0),
|
||||
UvAnimationMaskTexture = default,
|
||||
UvAnimationScrollXSpeedValue = 0,
|
||||
UvAnimationScrollYSpeedValue = 0,
|
||||
UvAnimationRotationSpeedValue = 0,
|
||||
},
|
||||
});
|
||||
|
||||
// NOTE: MToon として正しくはないが、やむをえず renderQueue を元の値で復帰する.
|
||||
unityMaterial.renderQueue = vrmMaterial.renderQueue;
|
||||
});
|
||||
|
||||
Debug.LogWarning($"fallback: {UnlitTransparentZWriteShaderName} => {MToon.Utils.ShaderName}");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
using System;
|
||||
using Unity.Collections;
|
||||
using Unity.Jobs;
|
||||
using UnityEngine;
|
||||
|
|
@ -106,7 +107,7 @@ namespace UniVRM10.FastSpringBones.System
|
|||
if (parentTransform.HasValue)
|
||||
{
|
||||
var parentLocalToWorldMatrix = parentTransform.Value.localToWorldMatrix;
|
||||
headTransform.localRotation = (Quaternion.Inverse(parentTransform.Value.rotation) * headTransform.rotation).normalized;
|
||||
headTransform.localRotation = Normalize(Quaternion.Inverse(parentTransform.Value.rotation) * headTransform.rotation);
|
||||
headTransform.localToWorldMatrix =
|
||||
parentLocalToWorldMatrix *
|
||||
Matrix4x4.TRS(
|
||||
|
|
@ -134,6 +135,15 @@ namespace UniVRM10.FastSpringBones.System
|
|||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// BurstではMathfがエラーを吐くため、内部でMathfを呼ばないNormalizeを自前実装
|
||||
/// </summary>
|
||||
private static Quaternion Normalize(Quaternion q)
|
||||
{
|
||||
var num = (float)Math.Sqrt(Quaternion.Dot(q, q));
|
||||
return num < float.Epsilon ? Quaternion.identity : new Quaternion(q.x / num, q.y / num, q.z / num, q.w / num);
|
||||
}
|
||||
|
||||
private static void ResolveCapsuleCollision(
|
||||
Vector3 worldTail,
|
||||
Vector3 worldPosition,
|
||||
|
|
|
|||
|
|
@ -17,13 +17,12 @@ namespace VRMShaders
|
|||
m_externalMap = externalMaterialMap;
|
||||
}
|
||||
|
||||
// TODO: UniVRM 0.x の方に処理を移したい
|
||||
static Dictionary<string, string> s_fallbackShaders = new Dictionary<string, string>
|
||||
{
|
||||
{"VRM/UnlitTexture", "Unlit/Texture"},
|
||||
{"VRM/UnlitTransparent", "Unlit/Transparent"},
|
||||
{"VRM/UnlitCutout", "Unlit/Transparent Cutout"},
|
||||
// 互換性は無いがとりあえず、
|
||||
{"VRM/UnlitTransparentZWrite", "VRM/MToon"},
|
||||
{"UniGLTF/StandardVColor", UniGLTF.UniUnlit.UniUnlitUtil.ShaderName},
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user