mirror of
https://github.com/vrm-c/UniVRM.git
synced 2026-08-22 10:34:54 -05:00
glTFTexture.source type to int?
This commit is contained in:
@@ -475,9 +475,9 @@ public static void Serialize_gltf_textures_ITEM(JsonFormatter f, glTFTexture val
|
||||
f.Value(value.sampler);
|
||||
}
|
||||
|
||||
if(value.source>=0){
|
||||
if(value.source.HasValue){
|
||||
f.Key("source");
|
||||
f.Value(value.source);
|
||||
f.Value(value.source.Value);
|
||||
}
|
||||
|
||||
if(value.extensions!=null){
|
||||
|
||||
@@ -58,8 +58,7 @@ namespace UniGLTF
|
||||
[JsonSchema(Minimum = 0)]
|
||||
public int sampler;
|
||||
|
||||
[JsonSchema(Minimum = 0)]
|
||||
public int source;
|
||||
public int? source;
|
||||
|
||||
// empty schemas
|
||||
public glTFExtension extensions;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using UnityEngine;
|
||||
using VRMShaders;
|
||||
using ColorSpace = VRMShaders.ColorSpace;
|
||||
@@ -70,13 +71,19 @@ namespace UniGLTF
|
||||
var vectors = new Dictionary<string, Vector4>();
|
||||
var actions = new List<Action<Material>>();
|
||||
|
||||
var standardTexDesc = default(TextureDescriptor);
|
||||
TextureDescriptor? standardTexDesc = default;
|
||||
if (src.pbrMetallicRoughness != null || src.occlusionTexture != null)
|
||||
{
|
||||
if (src.pbrMetallicRoughness.metallicRoughnessTexture != null || src.occlusionTexture != null)
|
||||
{
|
||||
SubAssetKey key;
|
||||
(key, standardTexDesc) = GltfPbrTextureImporter.StandardTexture(data, src);
|
||||
if (GltfPbrTextureImporter.TryStandardTexture(data, src, out var value))
|
||||
{
|
||||
if (string.IsNullOrEmpty(value.Item2.UnityObjectName))
|
||||
{
|
||||
throw new ArgumentNullException();
|
||||
}
|
||||
standardTexDesc = value.Item2;
|
||||
}
|
||||
}
|
||||
|
||||
if (src.pbrMetallicRoughness.baseColorFactor != null &&
|
||||
@@ -90,15 +97,22 @@ namespace UniGLTF
|
||||
if (src.pbrMetallicRoughness.baseColorTexture != null &&
|
||||
src.pbrMetallicRoughness.baseColorTexture.index != -1)
|
||||
{
|
||||
var (key, textureParam) = GltfPbrTextureImporter.BaseColorTexture(data, src);
|
||||
textureSlots.Add("_MainTex", textureParam);
|
||||
if (GltfPbrTextureImporter.TryBaseColorTexture(data, src, out var value))
|
||||
{
|
||||
if (string.IsNullOrEmpty(value.Item2.UnityObjectName))
|
||||
{
|
||||
throw new ArgumentNullException();
|
||||
}
|
||||
textureSlots.Add("_MainTex", value.Item2);
|
||||
}
|
||||
}
|
||||
|
||||
if (src.pbrMetallicRoughness.metallicRoughnessTexture != null &&
|
||||
src.pbrMetallicRoughness.metallicRoughnessTexture.index != -1)
|
||||
src.pbrMetallicRoughness.metallicRoughnessTexture.index != -1 &&
|
||||
standardTexDesc.HasValue)
|
||||
{
|
||||
actions.Add(material => material.EnableKeyword("_METALLICGLOSSMAP"));
|
||||
textureSlots.Add("_MetallicGlossMap", standardTexDesc);
|
||||
textureSlots.Add("_MetallicGlossMap", standardTexDesc.Value);
|
||||
// Set 1.0f as hard-coded. See: https://github.com/dwango/UniVRM/issues/212.
|
||||
floatValues.Add("_Metallic", 1.0f);
|
||||
floatValues.Add("_GlossMapScale", 1.0f);
|
||||
@@ -113,14 +127,20 @@ namespace UniGLTF
|
||||
if (src.normalTexture != null && src.normalTexture.index != -1)
|
||||
{
|
||||
actions.Add(material => material.EnableKeyword("_NORMALMAP"));
|
||||
var (_, textureParam) = GltfPbrTextureImporter.NormalTexture(data, src);
|
||||
textureSlots.Add("_BumpMap", textureParam);
|
||||
floatValues.Add("_BumpScale", src.normalTexture.scale);
|
||||
if (GltfPbrTextureImporter.TryNormalTexture(data, src, out var value))
|
||||
{
|
||||
if (string.IsNullOrEmpty(value.Item2.UnityObjectName))
|
||||
{
|
||||
throw new ArgumentNullException();
|
||||
}
|
||||
textureSlots.Add("_BumpMap", value.Item2);
|
||||
floatValues.Add("_BumpScale", src.normalTexture.scale);
|
||||
}
|
||||
}
|
||||
|
||||
if (src.occlusionTexture != null && src.occlusionTexture.index != -1)
|
||||
if (src.occlusionTexture != null && src.occlusionTexture.index != -1 && standardTexDesc.HasValue)
|
||||
{
|
||||
textureSlots.Add("_OcclusionMap", standardTexDesc);
|
||||
textureSlots.Add("_OcclusionMap", standardTexDesc.Value);
|
||||
floatValues.Add("_OcclusionStrength", src.occlusionTexture.strength);
|
||||
}
|
||||
|
||||
@@ -152,8 +172,14 @@ namespace UniGLTF
|
||||
|
||||
if (src.emissiveTexture != null && src.emissiveTexture.index != -1)
|
||||
{
|
||||
var (key, textureParam) = GltfPbrTextureImporter.EmissiveTexture(data, src);
|
||||
textureSlots.Add("_EmissionMap", textureParam);
|
||||
if (GltfPbrTextureImporter.TryEmissiveTexture(data, src, out var value))
|
||||
{
|
||||
if (string.IsNullOrEmpty(value.Item2.UnityObjectName))
|
||||
{
|
||||
throw new ArgumentNullException();
|
||||
}
|
||||
textureSlots.Add("_EmissionMap", value.Item2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -42,11 +42,11 @@ namespace UniGLTF
|
||||
// texture
|
||||
if (src.pbrMetallicRoughness.baseColorTexture != null)
|
||||
{
|
||||
var (offset, scale) =
|
||||
GltfTextureImporter.GetTextureOffsetAndScale(src.pbrMetallicRoughness.baseColorTexture);
|
||||
var (key, textureParam) = GltfTextureImporter.CreateSrgb(data,
|
||||
src.pbrMetallicRoughness.baseColorTexture.index, offset, scale);
|
||||
textureSlots.Add("_MainTex", textureParam);
|
||||
var (offset, scale) = GltfTextureImporter.GetTextureOffsetAndScale(src.pbrMetallicRoughness.baseColorTexture);
|
||||
if (GltfTextureImporter.TryCreateSrgb(data, src.pbrMetallicRoughness.baseColorTexture.index, offset, scale, out var value))
|
||||
{
|
||||
textureSlots.Add("_MainTex", value.Item2);
|
||||
}
|
||||
}
|
||||
|
||||
matDesc = new MaterialDescriptor(
|
||||
|
||||
@@ -42,13 +42,19 @@ namespace UniGLTF
|
||||
var actions = new List<Action<Material>>();
|
||||
var src = data.GLTF.materials[i];
|
||||
|
||||
var standardTexDesc = default(TextureDescriptor);
|
||||
TextureDescriptor? standardTexDesc = default;
|
||||
if (src.pbrMetallicRoughness != null || src.occlusionTexture != null)
|
||||
{
|
||||
if (src.pbrMetallicRoughness.metallicRoughnessTexture != null || src.occlusionTexture != null)
|
||||
{
|
||||
SubAssetKey key;
|
||||
(key, standardTexDesc) = GltfPbrTextureImporter.StandardTexture(data, src);
|
||||
if (GltfPbrTextureImporter.TryStandardTexture(data, src, out var value))
|
||||
{
|
||||
if (string.IsNullOrEmpty(value.Item2.UnityObjectName))
|
||||
{
|
||||
throw new ArgumentNullException();
|
||||
}
|
||||
standardTexDesc = value.Item2;
|
||||
}
|
||||
}
|
||||
|
||||
if (src.pbrMetallicRoughness.baseColorFactor != null && src.pbrMetallicRoughness.baseColorFactor.Length == 4)
|
||||
@@ -61,15 +67,17 @@ namespace UniGLTF
|
||||
|
||||
if (src.pbrMetallicRoughness.baseColorTexture != null && src.pbrMetallicRoughness.baseColorTexture.index != -1)
|
||||
{
|
||||
var (key, textureParam) = GltfPbrTextureImporter.BaseColorTexture(data, src);
|
||||
// from _MainTex !
|
||||
textureSlots.Add("_BaseMap", textureParam);
|
||||
if (GltfPbrTextureImporter.TryBaseColorTexture(data, src, out var value))
|
||||
{
|
||||
// from _MainTex !
|
||||
textureSlots.Add("_BaseMap", value.Item2);
|
||||
}
|
||||
}
|
||||
|
||||
if (src.pbrMetallicRoughness.metallicRoughnessTexture != null && src.pbrMetallicRoughness.metallicRoughnessTexture.index != -1)
|
||||
if (src.pbrMetallicRoughness.metallicRoughnessTexture != null && src.pbrMetallicRoughness.metallicRoughnessTexture.index != -1 && standardTexDesc.HasValue)
|
||||
{
|
||||
actions.Add(material => material.EnableKeyword("_METALLICGLOSSMAP"));
|
||||
textureSlots.Add("_MetallicGlossMap", standardTexDesc);
|
||||
textureSlots.Add("_MetallicGlossMap", standardTexDesc.Value);
|
||||
// Set 1.0f as hard-coded. See: https://github.com/dwango/UniVRM/issues/212.
|
||||
floatValues.Add("_Metallic", 1.0f);
|
||||
floatValues.Add("_GlossMapScale", 1.0f);
|
||||
@@ -87,14 +95,17 @@ namespace UniGLTF
|
||||
if (src.normalTexture != null && src.normalTexture.index != -1)
|
||||
{
|
||||
actions.Add(material => material.EnableKeyword("_NORMALMAP"));
|
||||
var (key, textureParam) = GltfPbrTextureImporter.NormalTexture(data, src);
|
||||
textureSlots.Add("_BumpMap", textureParam);
|
||||
floatValues.Add("_BumpScale", src.normalTexture.scale);
|
||||
if (GltfPbrTextureImporter.TryNormalTexture(data, src, out var value))
|
||||
{
|
||||
var (key, textureParam) = value;
|
||||
textureSlots.Add("_BumpMap", textureParam);
|
||||
floatValues.Add("_BumpScale", src.normalTexture.scale);
|
||||
}
|
||||
}
|
||||
|
||||
if (src.occlusionTexture != null && src.occlusionTexture.index != -1)
|
||||
if (src.occlusionTexture != null && src.occlusionTexture.index != -1 && standardTexDesc.HasValue)
|
||||
{
|
||||
textureSlots.Add("_OcclusionMap", standardTexDesc);
|
||||
textureSlots.Add("_OcclusionMap", standardTexDesc.Value);
|
||||
floatValues.Add("_OcclusionStrength", src.occlusionTexture.strength);
|
||||
}
|
||||
|
||||
@@ -125,8 +136,10 @@ namespace UniGLTF
|
||||
|
||||
if (src.emissiveTexture != null && src.emissiveTexture.index != -1)
|
||||
{
|
||||
var (key, textureParam) = GltfPbrTextureImporter.EmissiveTexture(data, src);
|
||||
textureSlots.Add("_EmissionMap", textureParam);
|
||||
if (GltfPbrTextureImporter.TryEmissiveTexture(data, src, out var value))
|
||||
{
|
||||
textureSlots.Add("_EmissionMap", value.Item2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -172,16 +172,19 @@ namespace UniGLTF
|
||||
for (var textureIdx = 0; textureIdx < GLTF.textures.Count; ++textureIdx)
|
||||
{
|
||||
var gltfTexture = GLTF.textures[textureIdx];
|
||||
var gltfImage = GLTF.images[gltfTexture.source];
|
||||
if (!string.IsNullOrEmpty(gltfImage.uri) && !gltfImage.uri.StartsWith("data:"))
|
||||
if (gltfTexture.source.HasValidIndex())
|
||||
{
|
||||
// from image uri
|
||||
gltfTexture.name = Path.GetFileNameWithoutExtension(gltfImage.uri);
|
||||
}
|
||||
if (string.IsNullOrEmpty(gltfTexture.name))
|
||||
{
|
||||
// use image name
|
||||
gltfTexture.name = gltfImage.name;
|
||||
var gltfImage = GLTF.images[gltfTexture.source.Value];
|
||||
if (!string.IsNullOrEmpty(gltfImage.uri) && !gltfImage.uri.StartsWith("data:"))
|
||||
{
|
||||
// from image uri
|
||||
gltfTexture.name = Path.GetFileNameWithoutExtension(gltfImage.uri);
|
||||
}
|
||||
if (string.IsNullOrEmpty(gltfTexture.name))
|
||||
{
|
||||
// use image name
|
||||
gltfTexture.name = gltfImage.name;
|
||||
}
|
||||
}
|
||||
if (string.IsNullOrEmpty(gltfTexture.name))
|
||||
{
|
||||
|
||||
@@ -15,7 +15,10 @@ namespace UniGLTF
|
||||
// base color
|
||||
if (m.pbrMetallicRoughness?.baseColorTexture != null)
|
||||
{
|
||||
yield return BaseColorTexture(data, m);
|
||||
if (TryBaseColorTexture(data, m, out var value))
|
||||
{
|
||||
yield return value;
|
||||
}
|
||||
}
|
||||
|
||||
// metallic roughness
|
||||
@@ -28,13 +31,19 @@ namespace UniGLTF
|
||||
// emission
|
||||
if (m.emissiveTexture != null)
|
||||
{
|
||||
yield return EmissiveTexture(data, m);
|
||||
if (TryEmissiveTexture(data, m, out var value))
|
||||
{
|
||||
yield return value;
|
||||
}
|
||||
}
|
||||
|
||||
// normal
|
||||
if (m.normalTexture != null)
|
||||
{
|
||||
yield return NormalTexture(data, m);
|
||||
if (TryNormalTexture(data, m, out var value))
|
||||
{
|
||||
yield return value;
|
||||
}
|
||||
}
|
||||
|
||||
// occlusion
|
||||
@@ -47,17 +56,20 @@ namespace UniGLTF
|
||||
// metallicSmooth and occlusion
|
||||
if (metallicRoughnessTexture.HasValue || occlusionTexture.HasValue)
|
||||
{
|
||||
yield return StandardTexture(data, m);
|
||||
if (TryStandardTexture(data, m, out var value))
|
||||
{
|
||||
yield return value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static (SubAssetKey, TextureDescriptor) BaseColorTexture(GltfData data, glTFMaterial src)
|
||||
public static bool TryBaseColorTexture(GltfData data, glTFMaterial src, out (SubAssetKey, TextureDescriptor) value)
|
||||
{
|
||||
var (offset, scale) = GltfTextureImporter.GetTextureOffsetAndScale(src.pbrMetallicRoughness.baseColorTexture);
|
||||
return GltfTextureImporter.CreateSrgb(data, src.pbrMetallicRoughness.baseColorTexture.index, offset, scale);
|
||||
return GltfTextureImporter.TryCreateSrgb(data, src.pbrMetallicRoughness.baseColorTexture.index, offset, scale, out value);
|
||||
}
|
||||
|
||||
public static (SubAssetKey, TextureDescriptor) StandardTexture(GltfData data, glTFMaterial src)
|
||||
public static bool TryStandardTexture(GltfData data, glTFMaterial src, out (SubAssetKey, TextureDescriptor) value)
|
||||
{
|
||||
var metallicFactor = 1.0f;
|
||||
var roughnessFactor = 1.0f;
|
||||
@@ -67,25 +79,24 @@ namespace UniGLTF
|
||||
roughnessFactor = src.pbrMetallicRoughness.roughnessFactor;
|
||||
}
|
||||
var (offset, scale) = GltfTextureImporter.GetTextureOffsetAndScale(src.pbrMetallicRoughness.metallicRoughnessTexture);
|
||||
return GltfTextureImporter.CreateStandard(data,
|
||||
return GltfTextureImporter.TryCreateStandard(data,
|
||||
src.pbrMetallicRoughness?.metallicRoughnessTexture?.index,
|
||||
src.occlusionTexture?.index,
|
||||
offset, scale,
|
||||
metallicFactor,
|
||||
roughnessFactor);
|
||||
roughnessFactor, out value);
|
||||
}
|
||||
|
||||
public static (SubAssetKey, TextureDescriptor) NormalTexture(GltfData data, glTFMaterial src)
|
||||
public static bool TryNormalTexture(GltfData data, glTFMaterial src, out (SubAssetKey, TextureDescriptor) value)
|
||||
{
|
||||
var (offset, scale) = GltfTextureImporter.GetTextureOffsetAndScale(src.normalTexture);
|
||||
return GltfTextureImporter.CreateNormal(data, src.normalTexture.index, offset, scale);
|
||||
return GltfTextureImporter.TryCreateNormal(data, src.normalTexture.index, offset, scale, out value);
|
||||
}
|
||||
|
||||
public static (SubAssetKey, TextureDescriptor) EmissiveTexture(GltfData data, glTFMaterial src)
|
||||
public static bool TryEmissiveTexture(GltfData data, glTFMaterial src, out (SubAssetKey, TextureDescriptor) value)
|
||||
{
|
||||
var (offset, scale) = GltfTextureImporter.GetTextureOffsetAndScale(src.emissiveTexture);
|
||||
return GltfTextureImporter.CreateSrgb(data, src.emissiveTexture.index, offset, scale);
|
||||
return GltfTextureImporter.TryCreateSrgb(data, src.emissiveTexture.index, offset, scale, out value);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,10 +35,16 @@ namespace UniGLTF
|
||||
return (texDesc.SubAssetKey, texDesc);
|
||||
}
|
||||
|
||||
public static (SubAssetKey, TextureDescriptor) CreateSrgb(GltfData data, int textureIndex, Vector2 offset, Vector2 scale)
|
||||
public static bool TryCreateSrgb(GltfData data, int textureIndex, Vector2 offset, Vector2 scale, out (SubAssetKey, TextureDescriptor) value)
|
||||
{
|
||||
var gltfTexture = data.GLTF.textures[textureIndex];
|
||||
var gltfImage = data.GLTF.images[gltfTexture.source];
|
||||
if (!gltfTexture.source.HasValidIndex())
|
||||
{
|
||||
value = default;
|
||||
return false;
|
||||
}
|
||||
|
||||
var gltfImage = data.GLTF.images[gltfTexture.source.Value];
|
||||
var name = TextureImportName.GetUnityObjectName(TextureImportTypes.sRGB, gltfTexture.name, gltfImage.uri);
|
||||
var sampler = TextureSamplerUtil.CreateSampler(data.GLTF, textureIndex);
|
||||
var param = new TextureDescriptor(
|
||||
@@ -50,13 +56,20 @@ namespace UniGLTF
|
||||
default,
|
||||
() => Task.FromResult(GetImageBytesFromTextureIndex(data, textureIndex)),
|
||||
default, default, default, default, default);
|
||||
return (param.SubAssetKey, param);
|
||||
value = (param.SubAssetKey, param);
|
||||
return true;
|
||||
}
|
||||
|
||||
public static (SubAssetKey, TextureDescriptor) CreateLinear(GltfData data, int textureIndex, Vector2 offset, Vector2 scale)
|
||||
public static bool TryCreateLinear(GltfData data, int textureIndex, Vector2 offset, Vector2 scale, out (SubAssetKey, TextureDescriptor) value)
|
||||
{
|
||||
var gltfTexture = data.GLTF.textures[textureIndex];
|
||||
var gltfImage = data.GLTF.images[gltfTexture.source];
|
||||
if (!gltfTexture.source.HasValidIndex())
|
||||
{
|
||||
value = default;
|
||||
return false;
|
||||
}
|
||||
|
||||
var gltfImage = data.GLTF.images[gltfTexture.source.Value];
|
||||
var name = TextureImportName.GetUnityObjectName(TextureImportTypes.Linear, gltfTexture.name, gltfImage.uri);
|
||||
var sampler = TextureSamplerUtil.CreateSampler(data.GLTF, textureIndex);
|
||||
var param = new TextureDescriptor(
|
||||
@@ -69,13 +82,20 @@ namespace UniGLTF
|
||||
default,
|
||||
() => Task.FromResult(GetImageBytesFromTextureIndex(data, textureIndex)),
|
||||
default, default, default, default, default);
|
||||
return (param.SubAssetKey, param);
|
||||
value = (param.SubAssetKey, param);
|
||||
return true;
|
||||
}
|
||||
|
||||
public static (SubAssetKey, TextureDescriptor) CreateNormal(GltfData data, int textureIndex, Vector2 offset, Vector2 scale)
|
||||
public static bool TryCreateNormal(GltfData data, int textureIndex, Vector2 offset, Vector2 scale, out (SubAssetKey, TextureDescriptor) value)
|
||||
{
|
||||
var gltfTexture = data.GLTF.textures[textureIndex];
|
||||
var gltfImage = data.GLTF.images[gltfTexture.source];
|
||||
if (!gltfTexture.source.HasValidIndex())
|
||||
{
|
||||
value = default;
|
||||
return false;
|
||||
}
|
||||
|
||||
var gltfImage = data.GLTF.images[gltfTexture.source.Value];
|
||||
var name = TextureImportName.GetUnityObjectName(TextureImportTypes.NormalMap, gltfTexture.name, gltfImage.uri);
|
||||
var sampler = TextureSamplerUtil.CreateSampler(data.GLTF, textureIndex);
|
||||
var param = new TextureDescriptor(
|
||||
@@ -88,10 +108,11 @@ namespace UniGLTF
|
||||
default,
|
||||
() => Task.FromResult(GetImageBytesFromTextureIndex(data, textureIndex)),
|
||||
default, default, default, default, default);
|
||||
return (param.SubAssetKey, param);
|
||||
value = (param.SubAssetKey, param);
|
||||
return true;
|
||||
}
|
||||
|
||||
public static (SubAssetKey, TextureDescriptor) CreateStandard(GltfData data, int? metallicRoughnessTextureIndex, int? occlusionTextureIndex, Vector2 offset, Vector2 scale, float metallicFactor, float roughnessFactor)
|
||||
public static bool TryCreateStandard(GltfData data, int? metallicRoughnessTextureIndex, int? occlusionTextureIndex, Vector2 offset, Vector2 scale, float metallicFactor, float roughnessFactor, out (SubAssetKey, TextureDescriptor) value)
|
||||
{
|
||||
string name = default;
|
||||
|
||||
@@ -100,21 +121,33 @@ namespace UniGLTF
|
||||
if (metallicRoughnessTextureIndex.HasValue)
|
||||
{
|
||||
var gltfTexture = data.GLTF.textures[metallicRoughnessTextureIndex.Value];
|
||||
name = TextureImportName.GetUnityObjectName(TextureImportTypes.StandardMap, gltfTexture.name, data.GLTF.images[gltfTexture.source].uri);
|
||||
sampler = TextureSamplerUtil.CreateSampler(data.GLTF, metallicRoughnessTextureIndex.Value);
|
||||
getMetallicRoughnessAsync = () => Task.FromResult(GetImageBytesFromTextureIndex(data, metallicRoughnessTextureIndex.Value));
|
||||
if (gltfTexture.source.HasValidIndex())
|
||||
{
|
||||
name = TextureImportName.GetUnityObjectName(TextureImportTypes.StandardMap, gltfTexture.name, data.GLTF.images[gltfTexture.source.Value].uri);
|
||||
sampler = TextureSamplerUtil.CreateSampler(data.GLTF, metallicRoughnessTextureIndex.Value);
|
||||
getMetallicRoughnessAsync = () => Task.FromResult(GetImageBytesFromTextureIndex(data, metallicRoughnessTextureIndex.Value));
|
||||
}
|
||||
}
|
||||
|
||||
GetTextureBytesAsync getOcclusionAsync = default;
|
||||
if (occlusionTextureIndex.HasValue)
|
||||
{
|
||||
var gltfTexture = data.GLTF.textures[occlusionTextureIndex.Value];
|
||||
if (string.IsNullOrEmpty(name))
|
||||
if (gltfTexture.source.HasValidIndex())
|
||||
{
|
||||
name = TextureImportName.GetUnityObjectName(TextureImportTypes.StandardMap, gltfTexture.name, data.GLTF.images[gltfTexture.source].uri);
|
||||
if (string.IsNullOrEmpty(name))
|
||||
{
|
||||
name = TextureImportName.GetUnityObjectName(TextureImportTypes.StandardMap, gltfTexture.name, data.GLTF.images[gltfTexture.source.Value].uri);
|
||||
}
|
||||
sampler = TextureSamplerUtil.CreateSampler(data.GLTF, occlusionTextureIndex.Value);
|
||||
getOcclusionAsync = () => Task.FromResult(GetImageBytesFromTextureIndex(data, occlusionTextureIndex.Value));
|
||||
}
|
||||
sampler = TextureSamplerUtil.CreateSampler(data.GLTF, occlusionTextureIndex.Value);
|
||||
getOcclusionAsync = () => Task.FromResult(GetImageBytesFromTextureIndex(data, occlusionTextureIndex.Value));
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(name))
|
||||
{
|
||||
value = default;
|
||||
return false;
|
||||
}
|
||||
|
||||
var texDesc = new TextureDescriptor(
|
||||
@@ -128,7 +161,13 @@ namespace UniGLTF
|
||||
getMetallicRoughnessAsync,
|
||||
getOcclusionAsync,
|
||||
default, default, default, default);
|
||||
return (texDesc.SubAssetKey, texDesc);
|
||||
value = (texDesc.SubAssetKey, texDesc);
|
||||
if (string.IsNullOrEmpty(value.Item2.UnityObjectName))
|
||||
{
|
||||
throw new ArgumentNullException();
|
||||
}
|
||||
Debug.Log("${name}");
|
||||
return true;
|
||||
}
|
||||
|
||||
public static (Vector2, Vector2) GetTextureOffsetAndScale(glTFTextureInfo textureInfo)
|
||||
|
||||
@@ -301,8 +301,11 @@ namespace VRM
|
||||
meta.Title = gltfMeta.title;
|
||||
if (gltfMeta.texture >= 0)
|
||||
{
|
||||
var (key, param) = GltfTextureImporter.CreateSrgb(Data, gltfMeta.texture, Vector2.zero, Vector2.one);
|
||||
meta.Thumbnail = await TextureFactory.GetTextureAsync(param, awaitCaller) as Texture2D;
|
||||
if (GltfTextureImporter.TryCreateSrgb(Data, gltfMeta.texture, Vector2.zero, Vector2.one, out var value))
|
||||
{
|
||||
var (key, param) = value;
|
||||
meta.Thumbnail = await TextureFactory.GetTextureAsync(param, awaitCaller) as Texture2D;
|
||||
}
|
||||
}
|
||||
meta.AllowedUser = gltfMeta.allowedUser;
|
||||
meta.ViolentUssage = gltfMeta.violentUssage;
|
||||
|
||||
@@ -33,13 +33,10 @@ namespace VRM
|
||||
switch (textureKey)
|
||||
{
|
||||
case MToon.Utils.PropBumpMap:
|
||||
texture = GltfTextureImporter.CreateNormal(data, textureIdx, offset, scale);
|
||||
break;
|
||||
return GltfTextureImporter.TryCreateNormal(data, textureIdx, offset, scale, out texture);
|
||||
default:
|
||||
texture = GltfTextureImporter.CreateSrgb(data, textureIdx, offset, scale);
|
||||
break;
|
||||
return GltfTextureImporter.TryCreateSrgb(data, textureIdx, offset, scale, out texture);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
texture = default;
|
||||
|
||||
@@ -69,8 +69,7 @@ namespace VRM
|
||||
{
|
||||
if (vrm.meta.texture > -1)
|
||||
{
|
||||
texture = GltfTextureImporter.CreateSrgb(data, vrm.meta.texture, Vector2.zero, Vector2.one);
|
||||
return true;
|
||||
return GltfTextureImporter.TryCreateSrgb(data, vrm.meta.texture, Vector2.zero, Vector2.one, out texture);
|
||||
}
|
||||
|
||||
texture = default;
|
||||
|
||||
@@ -62,8 +62,7 @@ namespace UniVRM10
|
||||
{
|
||||
try
|
||||
{
|
||||
pair = GltfPbrTextureImporter.BaseColorTexture(data, src);
|
||||
return true;
|
||||
return GltfPbrTextureImporter.TryBaseColorTexture(data, src, out pair);
|
||||
}
|
||||
catch (NullReferenceException)
|
||||
{
|
||||
@@ -81,8 +80,7 @@ namespace UniVRM10
|
||||
{
|
||||
try
|
||||
{
|
||||
pair = GltfPbrTextureImporter.EmissiveTexture(data, src);
|
||||
return true;
|
||||
return GltfPbrTextureImporter.TryEmissiveTexture(data, src, out pair);
|
||||
}
|
||||
catch (NullReferenceException)
|
||||
{
|
||||
@@ -101,8 +99,7 @@ namespace UniVRM10
|
||||
{
|
||||
try
|
||||
{
|
||||
pair = GltfPbrTextureImporter.NormalTexture(data, src);
|
||||
return true;
|
||||
return GltfPbrTextureImporter.TryNormalTexture(data, src, out pair);
|
||||
}
|
||||
catch (NullReferenceException)
|
||||
{
|
||||
@@ -151,8 +148,7 @@ namespace UniVRM10
|
||||
try
|
||||
{
|
||||
var (offset, scale) = GetTextureOffsetAndScale(info);
|
||||
pair = GltfTextureImporter.CreateSrgb(data, info.index, offset, scale);
|
||||
return true;
|
||||
return GltfTextureImporter.TryCreateSrgb(data, info.index, offset, scale, out pair);
|
||||
}
|
||||
catch (NullReferenceException)
|
||||
{
|
||||
@@ -170,8 +166,7 @@ namespace UniVRM10
|
||||
try
|
||||
{
|
||||
var (offset, scale) = GetTextureOffsetAndScale(info);
|
||||
pair = GltfTextureImporter.CreateLinear(data, info.index, offset, scale);
|
||||
return true;
|
||||
return GltfTextureImporter.TryCreateLinear(data, info.index, offset, scale, out pair);
|
||||
}
|
||||
catch (NullReferenceException)
|
||||
{
|
||||
|
||||
@@ -55,9 +55,14 @@ namespace VRMShaders
|
||||
|
||||
public SubAssetKey(Type type, string name)
|
||||
{
|
||||
if (type == null || string.IsNullOrEmpty(name))
|
||||
if (type == null)
|
||||
{
|
||||
throw new System.ArgumentNullException();
|
||||
throw new System.ArgumentNullException("type");
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(name))
|
||||
{
|
||||
throw new System.ArgumentNullException("name");
|
||||
}
|
||||
|
||||
if (!type.IsSubclassOf(typeof(UnityEngine.Object)))
|
||||
|
||||
@@ -52,6 +52,10 @@ namespace VRMShaders
|
||||
GetTextureBytesAsync i4,
|
||||
GetTextureBytesAsync i5)
|
||||
{
|
||||
if (string.IsNullOrEmpty(name))
|
||||
{
|
||||
throw new ArgumentNullException("name");
|
||||
}
|
||||
UnityObjectName = name;
|
||||
Offset = offset;
|
||||
Scale = scale;
|
||||
|
||||
Reference in New Issue
Block a user