mirror of
https://github.com/vrm-c/UniVRM.git
synced 2026-08-28 13:54:45 -05:00
Merge pull request #2401 from Santarh/animNullShader
[VRMA] Fixed an issue where a shader could not be found at app
This commit is contained in:
@@ -10,11 +10,9 @@ namespace UniGLTF
|
||||
public class MaterialFactory : IResponsibilityForDestroyObjects
|
||||
{
|
||||
private readonly IReadOnlyDictionary<SubAssetKey, Material> m_externalMap;
|
||||
|
||||
/// <summary>
|
||||
/// デフォルトマテリアルの MaterialDescriptor は IMaterialDescriptorGenerator の実装によって異なるので外から渡す
|
||||
/// </summary>
|
||||
private readonly SubAssetKey m_defaultMaterialKey = new SubAssetKey(typeof(Material), "__UNIGLTF__DEFAULT__MATERIAL__");
|
||||
private readonly MaterialDescriptor m_defaultMaterialParams;
|
||||
private readonly List<MaterialLoadInfo> m_materials = new List<MaterialLoadInfo>();
|
||||
|
||||
/// <summary>
|
||||
/// gltfPritmitive.material が無い場合のデフォルトマテリアル
|
||||
@@ -23,6 +21,9 @@ namespace UniGLTF
|
||||
/// </summary>
|
||||
private Material m_defaultMaterial;
|
||||
|
||||
public IReadOnlyList<MaterialLoadInfo> Materials => m_materials;
|
||||
|
||||
|
||||
public MaterialFactory(IReadOnlyDictionary<SubAssetKey, Material> externalMaterialMap, MaterialDescriptor defaultMaterialParams)
|
||||
{
|
||||
m_externalMap = externalMaterialMap;
|
||||
@@ -45,18 +46,6 @@ namespace UniGLTF
|
||||
}
|
||||
}
|
||||
|
||||
List<MaterialLoadInfo> m_materials = new List<MaterialLoadInfo>();
|
||||
public IReadOnlyList<MaterialLoadInfo> Materials => m_materials;
|
||||
void Remove(Material material)
|
||||
{
|
||||
var index = m_materials.FindIndex(x => x.Asset == material);
|
||||
if (index >= 0)
|
||||
{
|
||||
m_materials.RemoveAt(index);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
foreach (var x in m_materials)
|
||||
@@ -67,6 +56,11 @@ namespace UniGLTF
|
||||
UnityObjectDestroyer.DestroyRuntimeOrEditor(x.Asset);
|
||||
}
|
||||
}
|
||||
|
||||
if (m_defaultMaterial != null)
|
||||
{
|
||||
UnityObjectDestroyer.DestroyRuntimeOrEditor(m_defaultMaterial);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -90,6 +84,12 @@ namespace UniGLTF
|
||||
m_materials.Remove(x);
|
||||
}
|
||||
}
|
||||
|
||||
if (m_defaultMaterial != null)
|
||||
{
|
||||
take(m_defaultMaterialKey, m_defaultMaterial);
|
||||
m_defaultMaterial = null;
|
||||
}
|
||||
}
|
||||
|
||||
public Material GetMaterial(int index)
|
||||
@@ -101,6 +101,12 @@ namespace UniGLTF
|
||||
|
||||
public async Task<Material> GetDefaultMaterialAsync(IAwaitCaller awaitCaller)
|
||||
{
|
||||
if (m_externalMap.ContainsKey(m_defaultMaterialKey))
|
||||
{
|
||||
m_defaultMaterial = m_externalMap[m_defaultMaterialKey];
|
||||
return m_externalMap[m_defaultMaterialKey];
|
||||
}
|
||||
|
||||
if (m_defaultMaterial == null)
|
||||
{
|
||||
m_defaultMaterial = await LoadAsync(m_defaultMaterialParams, (_, _) => null, awaitCaller);
|
||||
@@ -136,7 +142,8 @@ namespace UniGLTF
|
||||
if (texture != null)
|
||||
{
|
||||
material.SetTexture(kv.Key, texture);
|
||||
SetTextureOffsetAndScale(material, kv.Key, kv.Value.Offset, kv.Value.Scale);
|
||||
material.SetTextureOffset(kv.Key, kv.Value.Offset);
|
||||
material.SetTextureScale(kv.Key, kv.Value.Scale);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -174,11 +181,5 @@ namespace UniGLTF
|
||||
|
||||
return material;
|
||||
}
|
||||
|
||||
public static void SetTextureOffsetAndScale(Material material, string propertyName, Vector2 offset, Vector2 scale)
|
||||
{
|
||||
material.SetTextureOffset(propertyName, offset);
|
||||
material.SetTextureScale(propertyName, scale);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -171,7 +171,7 @@ namespace UniVRM10
|
||||
public float custom_98;
|
||||
public float custom_99;
|
||||
|
||||
public void Initialize(IEnumerable<ExpressionKey> keys)
|
||||
public void Initialize(IEnumerable<ExpressionKey> keys, Material material)
|
||||
{
|
||||
var humanoid = gameObject.AddComponent<Humanoid>();
|
||||
if (humanoid.AssignBonesFromAnimator())
|
||||
@@ -183,7 +183,6 @@ namespace UniVRM10
|
||||
// create SkinnedMesh for bone visualize
|
||||
var animator = this.GetComponentOrThrow<Animator>();
|
||||
BoxMan = SkeletonMeshUtility.CreateRenderer(animator);
|
||||
var material = new Material(Shader.Find("Standard"));
|
||||
BoxMan.sharedMaterial = material;
|
||||
var mesh = BoxMan.sharedMesh;
|
||||
mesh.name = "box-man";
|
||||
|
||||
@@ -244,6 +244,9 @@ namespace UniVRM10
|
||||
}
|
||||
Data.GLTF.scenes[0].nodes = Data.GLTF.scenes[0].nodes.Take(1).ToArray();
|
||||
|
||||
// 可視化メッシュ用マテリアル。base.LoadAsync を呼ぶ前に生成する。
|
||||
var defaultMaterial = await MaterialFactory.GetDefaultMaterialAsync(awaitCaller);
|
||||
|
||||
// Humanoid Animation が Gltf アニメーションとしてロードされる
|
||||
var instance = await base.LoadAsync(awaitCaller, measureTime);
|
||||
|
||||
@@ -285,7 +288,7 @@ namespace UniVRM10
|
||||
|
||||
// VRMA-animation solver
|
||||
var animationInstance = instance.gameObject.AddComponent<Vrm10AnimationInstance>();
|
||||
animationInstance.Initialize(expressions.Select(x => x.Key));
|
||||
animationInstance.Initialize(expressions.Select(x => x.Key), defaultMaterial);
|
||||
|
||||
return instance;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user