Updated UniGLTF

This commit is contained in:
ousttrue 2018-08-07 18:40:48 +09:00
parent 4f8b5d0095
commit ad4af4ac79
3 changed files with 21 additions and 9 deletions

View File

@ -181,7 +181,7 @@ namespace VRM
MaterialName = x.materialName,
ValueName = x.propertyName,
TargetValue = value,
BaseValue = context.Materials.First(y => y.name == x.materialName).GetColor(x.propertyName),
BaseValue = context.GetMaterials().First(y => y.name == x.materialName).GetColor(x.propertyName),
};
})
.ToArray();
@ -297,15 +297,24 @@ namespace VRM
static IEnumerator LoadMaterials(VRMImporterContext context)
{
Func<int, TextureItem> getTexture = x =>
{
if (x < 0 || x >= context.Textures.Count)
{
return null;
}
return context.Textures[x];
};
if (context.GLTF.materials == null || !context.GLTF.materials.Any())
{
context.Materials.Add(context.MaterialImporter.CreateMaterial(context, 0));
context.AddMaterial(context.MaterialImporter.CreateMaterial(0, null, getTexture));
}
else
{
for (int i = 0; i < context.GLTF.materials.Count; ++i)
{
context.Materials.Add(context.MaterialImporter.CreateMaterial(context, i));
context.AddMaterial(context.MaterialImporter.CreateMaterial(i, context.GLTF.materials[i], getTexture));
yield return null;
}
}

View File

@ -2,7 +2,7 @@
using UniGLTF;
using UnityEngine;
using System.Linq;
using System;
namespace VRM
{
@ -47,7 +47,7 @@ namespace VRM
"VRM/MToon",
};
public override Material CreateMaterial(ImporterContext ctx, int i)
public override Material CreateMaterial(int i, glTFMaterial src, Func<int, TextureItem> getTexture)
{
var item = m_materials[i];
var shaderName = item.shader;
@ -60,12 +60,12 @@ namespace VRM
if (VRM_SHADER_NAMES.Contains(shaderName))
{
Debug.LogErrorFormat("shader {0} not found. set Assets/VRM/Shaders/VRMShaders to Edit - project setting - Graphics - preloaded shaders", shaderName);
return base.CreateMaterial(ctx, i);
return base.CreateMaterial(i, src, getTexture);
}
else
{
Debug.LogWarningFormat("unknown shader {0}.", shaderName);
return base.CreateMaterial(ctx, i);
return base.CreateMaterial(i, src, getTexture);
}
}
@ -97,7 +97,10 @@ namespace VRM
}
foreach (var kv in item.textureProperties)
{
material.SetTexture(kv.Key, ctx.Textures[kv.Value].Texture);
var texture = getTexture(kv.Value);
if (texture != null) {
material.SetTexture(kv.Key, texture.Texture);
}
}
foreach (var kv in item.keywordMap)
{

@ -1 +1 @@
Subproject commit c1e5f0828a7404476406cb99fccd8bf2cc1b2990
Subproject commit 3bc3985f4dc04d3d0808a0957675365385893cac