mirror of
https://github.com/vrm-c/UniVRM.git
synced 2026-06-02 22:14:30 -05:00
try の範囲を狭める
This commit is contained in:
parent
3dcc802285
commit
bd4df41789
|
|
@ -1,6 +1,8 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UniGLTF;
|
||||
using UniJSON;
|
||||
using UnityEngine;
|
||||
|
||||
namespace UniVRM10
|
||||
{
|
||||
|
|
@ -10,7 +12,32 @@ namespace UniVRM10
|
|||
/// </summary>
|
||||
public static class MigrationLegacyUnlitMaterial
|
||||
{
|
||||
public static glTFMaterial Migrate(JsonNode vrm0XMaterial, string materialName)
|
||||
public static bool Migrate(glTF gltf, IReadOnlyList<JsonNode> vrm0XMaterials)
|
||||
{
|
||||
var anyMigrated = false;
|
||||
|
||||
for (var materialIdx = 0; materialIdx < gltf.materials.Count; ++materialIdx)
|
||||
{
|
||||
try
|
||||
{
|
||||
var newMaterial = Migrate(vrm0XMaterials[materialIdx], gltf.materials[materialIdx].name);
|
||||
if (newMaterial != null)
|
||||
{
|
||||
// NOTE: マイグレーション対象だった場合、上書きする.
|
||||
gltf.materials[materialIdx] = newMaterial;
|
||||
anyMigrated = true;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Debug.LogException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
return anyMigrated;
|
||||
}
|
||||
|
||||
private static glTFMaterial Migrate(JsonNode vrm0XMaterial, string materialName)
|
||||
{
|
||||
var unlitMaterial = new glTFMaterial
|
||||
{
|
||||
|
|
|
|||
|
|
@ -14,51 +14,20 @@ namespace UniVRM10
|
|||
public static void Migrate(glTF gltf, JsonNode vrm0)
|
||||
{
|
||||
var needsDisablingVertexColor = false;
|
||||
var vrm0XMaterialList = vrm0[MaterialPropertiesKey].ArrayItems().ToArray();
|
||||
|
||||
for (var materialIdx = 0; materialIdx < gltf.materials.Count; ++materialIdx)
|
||||
// 2. VRM 拡張のうち、古い Unlit 情報からの取得を試みる.
|
||||
if (MigrationLegacyUnlitMaterial.Migrate(gltf, vrm0XMaterialList))
|
||||
{
|
||||
try
|
||||
{
|
||||
var vrm0XMaterial = vrm0[MaterialPropertiesKey][materialIdx];
|
||||
var shaderName = MigrationMaterialUtil.GetShaderName(vrm0XMaterial);
|
||||
|
||||
// 1. material 拡張を使わない場合.
|
||||
// NOTE: この ShaderName の場合、「この拡張に記載されている情報は無視する」ということを示す.
|
||||
if (shaderName == DontUseExtensionShaderName)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
// 2. VRM 拡張のうち、古い Unlit 情報からの取得を試みる.
|
||||
var unlitMaterial = MigrationLegacyUnlitMaterial.Migrate(vrm0XMaterial, gltf.materials[materialIdx].name);
|
||||
if (unlitMaterial != null)
|
||||
{
|
||||
gltf.materials[materialIdx] = unlitMaterial;
|
||||
// NOTE: 古い Unlit である場合、頂点カラー情報を破棄する.
|
||||
needsDisablingVertexColor = true;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Debug.LogException(ex);
|
||||
}
|
||||
// NOTE: 古い Unlit である場合、頂点カラー情報を破棄する.
|
||||
needsDisablingVertexColor = true;
|
||||
}
|
||||
|
||||
try
|
||||
// 3. VRM 拡張のうち、UnlitTransparentZWrite 情報からの取得を試みる.
|
||||
if (MigrationUnlitTransparentZWriteMaterial.Migrate(gltf, vrm0XMaterialList))
|
||||
{
|
||||
var vrm0XMaterialList = vrm0[MaterialPropertiesKey].ArrayItems().ToArray();
|
||||
|
||||
// 3. VRM 拡張のうち、UnlitTransparentZWrite 情報からの取得を試みる.
|
||||
if (MigrationUnlitTransparentZWriteMaterial.Migrate(gltf, vrm0XMaterialList))
|
||||
{
|
||||
// NOTE: 古い Unlit である場合、頂点カラー情報を破棄する.
|
||||
needsDisablingVertexColor = true;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Debug.LogException(ex);
|
||||
// NOTE: 古い Unlit である場合、頂点カラー情報を破棄する.
|
||||
needsDisablingVertexColor = true;
|
||||
}
|
||||
|
||||
try
|
||||
|
|
|
|||
|
|
@ -22,7 +22,31 @@ namespace UniVRM10
|
|||
public static bool Migrate(glTF gltf, IReadOnlyList<JsonNode> vrm0XMaterials)
|
||||
{
|
||||
var anyMigrated = false;
|
||||
var mapper = GetRenderQueueMapper(vrm0XMaterials);
|
||||
|
||||
for (var materialIdx = 0; materialIdx < gltf.materials.Count; ++materialIdx)
|
||||
{
|
||||
try
|
||||
{
|
||||
var newMaterial = Migrate(vrm0XMaterials[materialIdx], gltf.materials[materialIdx].name, mapper);
|
||||
if (newMaterial != null)
|
||||
{
|
||||
// NOTE: UnlitTransparentZWrite の場合は、名前を引き継いで、glTFMaterial を上書きする.
|
||||
gltf.materials[materialIdx] = newMaterial;
|
||||
anyMigrated = true;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Debug.LogException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
return anyMigrated;
|
||||
}
|
||||
|
||||
private static Dictionary<int, int> GetRenderQueueMapper(IReadOnlyList<JsonNode> vrm0XMaterials)
|
||||
{
|
||||
try
|
||||
{
|
||||
var renderQueueSet = new SortedSet<int>();
|
||||
|
|
@ -40,23 +64,13 @@ namespace UniVRM10
|
|||
currentQueueOffset = Mathf.Min(currentQueueOffset + 1, MaxRenderQueueOffset);
|
||||
}
|
||||
|
||||
for (var materialIdx = 0; materialIdx < gltf.materials.Count; ++materialIdx)
|
||||
{
|
||||
var newMaterial = Migrate(vrm0XMaterials[materialIdx], gltf.materials[materialIdx].name, mapper);
|
||||
if (newMaterial != null)
|
||||
{
|
||||
// NOTE: UnlitTransparentZWrite の場合は、名前を引き継いで、glTFMaterial を上書きする.
|
||||
gltf.materials[materialIdx] = newMaterial;
|
||||
anyMigrated = true;
|
||||
}
|
||||
}
|
||||
return mapper;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Debug.LogException(ex);
|
||||
return new Dictionary<int, int>();
|
||||
}
|
||||
|
||||
return anyMigrated;
|
||||
}
|
||||
|
||||
private static glTFMaterial Migrate(JsonNode vrm0XMaterial, string materialName, Dictionary<int, int> renderQueueMapper)
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user