Merge pull request #1649 from Santarh/uvExpressionFix

Ignore duplicated UV expression in migration.
This commit is contained in:
ousttrue 2022-05-18 18:35:32 +09:00 committed by GitHub
commit d15bb4cb07
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 48 additions and 47 deletions

View File

@ -231,21 +231,9 @@ namespace UniVRM10
{ {
{"Standard", new string[]{ {"Standard", new string[]{
"_MainTex_ST", "_MainTex_ST",
"_BumpMap_ST",
"_EmissionMap_ST",
"_MetallicGlossMap_ST",
"_ParallaxMap_ST",
}}, }},
{"VRM10/MToon10", new string[]{ {"VRM10/MToon10", new string[]{
"_MainTex_ST", "_MainTex_ST",
"_ShadeTexture_ST",
"_BumpMap_ST",
"_EmissionMap_ST",
"_OutlineWidthTexture_ST",
"_ReceiveShadowTexture_ST",
"_RimTexture_ST",
"_ShadingGradeTexture_ST",
"_UvAnimMaskTexture_ST",
}}, }},
}; };
static string[] DefaultProps = { "_MainTex_ST" }; static string[] DefaultProps = { "_MainTex_ST" };

View File

@ -34,7 +34,7 @@ namespace UniVRM10
} }
/// <summary> /// <summary>
/// ///
/// </summary> /// </summary>
/// <param name="data"></param> /// <param name="data"></param>
/// <param name="vrm1Data"></param> /// <param name="vrm1Data"></param>
@ -80,21 +80,21 @@ namespace UniVRM10
{ {
// migration 失敗 // migration 失敗
vrm1Data = default; vrm1Data = default;
migration = new MigrationData(ex.Message, oldMeta); migration = new MigrationData(ex.ToString(), oldMeta);
return null; return null;
} }
catch (Exception ex) catch (Exception ex)
{ {
// その他のエラー // その他のエラー
vrm1Data = default; vrm1Data = default;
migration = new MigrationData(ex.Message, oldMeta); migration = new MigrationData(ex.ToString(), oldMeta);
return null; return null;
} }
byte[] debugCopy = null; byte[] debugCopy = null;
if (VRMShaders.Symbols.VRM_DEVELOP) if (VRMShaders.Symbols.VRM_DEVELOP)
{ {
// load 時の右手左手座標変換でバッファが破壊的変更されるので、コピーを作っている // load 時の右手左手座標変換でバッファが破壊的変更されるので、コピーを作っている
debugCopy = migrated.Select(x => x).ToArray(); debugCopy = migrated.Select(x => x).ToArray();
} }

View File

@ -10,7 +10,7 @@ namespace UniVRM10
{ {
/// <summary> /// <summary>
/// preset 名の文字列から ExpressionPreset を確定させる。 /// preset 名の文字列から ExpressionPreset を確定させる。
/// ///
/// 0.x の特殊な挙動として、 /// 0.x の特殊な挙動として、
/// preset名が "unknown" の場合に、 /// preset名が "unknown" の場合に、
/// "name" を preset 名として解釈を試みる。 /// "name" を preset 名として解釈を試みる。
@ -82,7 +82,7 @@ namespace UniVRM10
} }
bind.Node = nodeIndex; bind.Node = nodeIndex;
bind.Index = morphTargetIndex; bind.Index = morphTargetIndex;
// https://github.com/vrm-c/vrm-specification/issues/209 // https://github.com/vrm-c/vrm-specification/issues/209
bind.Weight = weight * 0.01f; bind.Weight = weight * 0.01f;
yield return bind; yield return bind;
@ -95,7 +95,7 @@ namespace UniVRM10
public const string OUTLINE_COLOR_PROPERTY = "_OutlineColor"; public const string OUTLINE_COLOR_PROPERTY = "_OutlineColor";
public const string SHADE_COLOR_PROPERTY = "_ShadeColor"; public const string SHADE_COLOR_PROPERTY = "_ShadeColor";
static UniGLTF.Extensions.VRMC_vrm.MaterialColorType ToMaterialType(string src) static UniGLTF.Extensions.VRMC_vrm.MaterialColorType? ToMaterialColorType(string src)
{ {
switch (src) switch (src)
{ {
@ -115,17 +115,17 @@ namespace UniVRM10
return UniGLTF.Extensions.VRMC_vrm.MaterialColorType.outlineColor; return UniGLTF.Extensions.VRMC_vrm.MaterialColorType.outlineColor;
} }
throw new NotImplementedException(); return default;
} }
/// <summary> /// <summary>
/// MaterialValue の仕様変更 /// MaterialValue の仕様変更
/// ///
/// * MaterialColorBind /// * MaterialColorBind
/// * TextureTransformBind /// * TextureTransformBind
/// ///
/// の2種類になった。 /// の2種類になった。
/// ///
/// </summary> /// </summary>
/// <param name="gltf"></param> /// <param name="gltf"></param>
/// <param name="json"></param> /// <param name="json"></param>
@ -151,57 +151,70 @@ namespace UniVRM10
} }
var propertyName = x["propertyName"].GetString(); var propertyName = x["propertyName"].GetString();
var targetValue = x["targetValue"].ArrayItems().Select(y => y.GetSingle()).ToArray(); var targetValue = x["targetValue"].ArrayItems().Select(y => y.GetSingle()).ToArray();
if (propertyName.EndsWith("_ST")) if (propertyName == "_MainTex_ST")
{ {
// VRM-0 は無変換 // VRM-0 は無変換
var (scale, offset) = UniGLTF.TextureTransform.VerticalFlipScaleOffset( var (scale, offset) = UniGLTF.TextureTransform.VerticalFlipScaleOffset(
new UnityEngine.Vector2(targetValue[0], targetValue[1]), new UnityEngine.Vector2(targetValue[0], targetValue[1]),
new UnityEngine.Vector2(targetValue[2], targetValue[3])); new UnityEngine.Vector2(targetValue[2], targetValue[3]));
expression.TextureTransformBinds.Add(new UniGLTF.Extensions.VRMC_vrm.TextureTransformBind if (!expression.TextureTransformBinds.Exists(bind => bind.Material == materialIndex))
{ {
Material = materialIndex, expression.TextureTransformBinds.Add(new UniGLTF.Extensions.VRMC_vrm.TextureTransformBind
Scale = new float[] { scale.x, scale.y }, {
Offset = new float[] { offset.x, offset.y } Material = materialIndex,
}); Scale = new float[] {scale.x, scale.y},
Offset = new float[] {offset.x, offset.y}
});
}
} }
else if (propertyName.EndsWith("_ST_S")) else if (propertyName == "_MainTex_ST_S")
{ {
// VRM-0 は無変換 // VRM-0 は無変換
var (scale, offset) = UniGLTF.TextureTransform.VerticalFlipScaleOffset( var (scale, offset) = UniGLTF.TextureTransform.VerticalFlipScaleOffset(
new UnityEngine.Vector2(targetValue[0], 1), new UnityEngine.Vector2(targetValue[0], 1),
new UnityEngine.Vector2(targetValue[2], 0)); new UnityEngine.Vector2(targetValue[2], 0));
expression.TextureTransformBinds.Add(new UniGLTF.Extensions.VRMC_vrm.TextureTransformBind if (!expression.TextureTransformBinds.Exists(bind => bind.Material == materialIndex))
{ {
Material = materialIndex, expression.TextureTransformBinds.Add(new UniGLTF.Extensions.VRMC_vrm.TextureTransformBind
Scale = new float[] { scale.x, scale.y }, {
Offset = new float[] { offset.x, offset.y } Material = materialIndex,
}); Scale = new float[] {scale.x, scale.y},
Offset = new float[] {offset.x, offset.y}
});
}
} }
else if (propertyName.EndsWith("_ST_T")) else if (propertyName == "_MainTex_ST_T")
{ {
// VRM-0 は無変換 // VRM-0 は無変換
var (scale, offset) = UniGLTF.TextureTransform.VerticalFlipScaleOffset( var (scale, offset) = UniGLTF.TextureTransform.VerticalFlipScaleOffset(
new UnityEngine.Vector2(1, targetValue[1]), new UnityEngine.Vector2(1, targetValue[1]),
new UnityEngine.Vector2(0, targetValue[3])); new UnityEngine.Vector2(0, targetValue[3]));
expression.TextureTransformBinds.Add(new UniGLTF.Extensions.VRMC_vrm.TextureTransformBind if (!expression.TextureTransformBinds.Exists(bind => bind.Material == materialIndex))
{ {
Material = materialIndex, expression.TextureTransformBinds.Add(new UniGLTF.Extensions.VRMC_vrm.TextureTransformBind
Scale = new float[] { scale.x, scale.y }, {
Offset = new float[] { offset.x, offset.y } Material = materialIndex,
}); Scale = new float[] {scale.x, scale.y},
Offset = new float[] {offset.x, offset.y}
});
}
} }
else else
{ {
// color var materialColorType = ToMaterialColorType(propertyName);
expression.MaterialColorBinds.Add(new UniGLTF.Extensions.VRMC_vrm.MaterialColorBind if (materialColorType.HasValue)
{ {
Material = materialIndex, // color
Type = ToMaterialType(propertyName), expression.MaterialColorBinds.Add(new UniGLTF.Extensions.VRMC_vrm.MaterialColorBind
TargetValue = targetValue, {
}); Material = materialIndex,
Type = materialColorType.Value,
TargetValue = targetValue,
});
}
} }
} }
} }