mirror of
https://github.com/vrm-c/UniVRM.git
synced 2026-08-23 11:05:29 -05:00
use gltfImage.uri as textureExternalObject in gltf import
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using UnityEditor;
|
||||
using UnityEditor.Experimental.AssetImporters;
|
||||
using UnityEngine;
|
||||
|
||||
@@ -27,6 +28,33 @@ namespace UniGLTF
|
||||
AddSubAssets(context, loaded);
|
||||
}
|
||||
|
||||
static IEnumerable<(string, UnityEngine.Object)> EnumerateExists(GltfParser parser, UnityPath dir)
|
||||
{
|
||||
foreach (var texParam in parser.EnumerateTextures())
|
||||
{
|
||||
switch (texParam.TextureType)
|
||||
{
|
||||
case GetTextureParam.METALLIC_GLOSS_PROP:
|
||||
case GetTextureParam.OCCLUSION_PROP:
|
||||
break;
|
||||
|
||||
default:
|
||||
{
|
||||
var gltfTexture = parser.GLTF.textures.First(y => y.name == texParam.Name);
|
||||
var gltfImage = parser.GLTF.images[gltfTexture.source];
|
||||
if (!string.IsNullOrEmpty(gltfImage.uri))
|
||||
{
|
||||
var child = dir.Child(gltfImage.uri);
|
||||
var asset = AssetDatabase.LoadAssetAtPath<Texture2D>(child.Value);
|
||||
// Debug.Log($"exists: {child}: {asset}");
|
||||
yield return (asset.name, asset);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Parse して、UnityObject 化する。
|
||||
///
|
||||
@@ -47,7 +75,8 @@ namespace UniGLTF
|
||||
//
|
||||
// Import(create unity objects)
|
||||
//
|
||||
var context = new ImporterContext(parser, null, externalObjectMap);
|
||||
var context = new ImporterContext(parser, null, externalObjectMap.Concat(
|
||||
EnumerateExists(parser, UnityPath.FromUnityPath(assetPath).Parent)));
|
||||
context.InvertAxis = reverseAxis;
|
||||
context.Load();
|
||||
context.ShowMeshes();
|
||||
|
||||
@@ -229,10 +229,16 @@ namespace UniGLTF
|
||||
for (int i = 0; i < GLTF.textures.Count; ++i)
|
||||
{
|
||||
var gltfTexture = GLTF.textures[i];
|
||||
var gltfImage = GLTF.images[gltfTexture.source];
|
||||
if (!string.IsNullOrEmpty(gltfImage.uri))
|
||||
{
|
||||
gltfTexture.name = Path.GetFileNameWithoutExtension(gltfImage.uri);
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(gltfTexture.name))
|
||||
{
|
||||
// use image name
|
||||
gltfTexture.name = GLTF.images[gltfTexture.source].name;
|
||||
gltfTexture.name = gltfImage.name;
|
||||
}
|
||||
if (string.IsNullOrEmpty(gltfTexture.name))
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user