Merge pull request #1008 from ousttrue/fix/vrm10_mtoon_export

glb ローダーで読めるように修正
This commit is contained in:
ousttrue 2021-06-07 18:49:47 +09:00 committed by GitHub
commit 86e098cb43
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -25,40 +25,47 @@ namespace UniVRM10
// convert MToon intermediate value from UnityEngine.Material
var def = MToon.Utils.GetMToonParametersFromMaterial(src);
// gltfMaterial
dst = new glTFMaterial
// base material
dst = glTF_KHR_materials_unlit.CreateDefault();
dst.name = src.name;
// Rendering
dst.doubleSided = def.Rendering.CullMode == CullMode.Off;
dst.alphaMode = ExportAlphaMode(def.Rendering.RenderMode);
dst.alphaCutoff = Mathf.Max(def.Color.CutoutThresholdValue, 0);
// Lighting
dst.pbrMetallicRoughness = new glTFPbrMetallicRoughness
{
name = src.name,
// Rendering
doubleSided = def.Rendering.CullMode == CullMode.Off,
alphaMode = ExportAlphaMode(def.Rendering.RenderMode),
alphaCutoff = Mathf.Max(def.Color.CutoutThresholdValue, 0),
// Lighting
pbrMetallicRoughness = new glTFPbrMetallicRoughness
baseColorFactor = def.Color.LitColor.ToFloat4(ColorSpace.sRGB, ColorSpace.Linear),
baseColorTexture = new glTFMaterialBaseColorTextureInfo
{
baseColorFactor = def.Color.LitColor.ToFloat4(ColorSpace.sRGB, ColorSpace.Linear),
baseColorTexture = new glTFMaterialBaseColorTextureInfo
{
index = textureExporter.ExportAsSRgb(def.Color.LitMultiplyTexture),
},
},
normalTexture = new glTFMaterialNormalTextureInfo
{
index = textureExporter.ExportAsNormal(def.Lighting.Normal.NormalTexture),
scale = def.Lighting.Normal.NormalScaleValue,
},
// Emission
emissiveFactor = def.Emission.EmissionColor.ToFloat3(ColorSpace.Linear, ColorSpace.Linear),
emissiveTexture = new glTFMaterialEmissiveTextureInfo
{
index = textureExporter.ExportAsSRgb(def.Emission.EmissionMultiplyTexture),
index = textureExporter.ExportAsSRgb(def.Color.LitMultiplyTexture),
},
};
// Normal
var normalTextureIndex = textureExporter.ExportAsNormal(def.Lighting.Normal.NormalTexture);
if (normalTextureIndex != -1)
{
dst.normalTexture = new glTFMaterialNormalTextureInfo
{
index = normalTextureIndex,
scale = def.Lighting.Normal.NormalScaleValue,
};
}
// Emission
dst.emissiveFactor = def.Emission.EmissionColor.ToFloat3(ColorSpace.Linear, ColorSpace.Linear);
var emissiveTextureIndex = textureExporter.ExportAsSRgb(def.Emission.EmissionMultiplyTexture);
if (emissiveTextureIndex != -1)
{
dst.emissiveTexture = new glTFMaterialEmissiveTextureInfo
{
index = emissiveTextureIndex,
};
}
const float centimeterToMeter = 0.01f;
const float invertY = -1f;
@ -207,6 +214,10 @@ namespace UniVRM10
private static void ExportTextureTransform(glTFTextureInfo textureInfo, Vector2 unityScale, Vector2 unityOffset)
{
if (textureInfo == null)
{
return;
}
var scale = unityScale;
var offset = new Vector2(unityOffset.x, 1.0f - unityOffset.y - unityScale.y);