mirror of
https://github.com/vrm-c/UniVRM.git
synced 2026-04-24 23:18:04 -05:00
Implements Parser variants.
This commit is contained in:
parent
e5ca1346a5
commit
a1c40eeda0
|
|
@ -27,8 +27,7 @@ namespace UniGLTF
|
|||
base.OnEnable();
|
||||
|
||||
m_importer = target as GlbScriptedImporter;
|
||||
m_data = new IGltfData();
|
||||
m_data.ParsePath(m_importer.assetPath);
|
||||
m_data = new GlbFileParser(m_importer.assetPath).Parse();
|
||||
|
||||
var materialGenerator = new GltfMaterialDescriptorGenerator();
|
||||
var materialKeys = m_data.GLTF.materials.Select((_, i) => materialGenerator.Get(m_data, i).SubAssetKey);
|
||||
|
|
|
|||
|
|
@ -27,8 +27,7 @@ namespace UniGLTF
|
|||
base.OnEnable();
|
||||
|
||||
m_importer = target as GltfScriptedImporter;
|
||||
m_data = new IGltfData();
|
||||
m_data.ParsePath(m_importer.assetPath);
|
||||
m_data = new GltfFileWithResourceFilesParser(m_importer.assetPath).Parse();
|
||||
|
||||
var materialGenerator = new GltfMaterialDescriptorGenerator();
|
||||
var materialKeys = m_data.GLTF.materials.Select((_, i) => materialGenerator.Get(m_data, i).SubAssetKey);
|
||||
|
|
|
|||
|
|
@ -27,8 +27,8 @@ namespace UniGLTF
|
|||
//
|
||||
// Parse(parse glb, parser gltf json)
|
||||
//
|
||||
var parser = new IGltfData();
|
||||
parser.ParsePath(scriptedImporter.assetPath);
|
||||
var data = new AmbiguousGltfFileParser(scriptedImporter.assetPath).Parse();
|
||||
|
||||
|
||||
//
|
||||
// Import(create unity objects)
|
||||
|
|
@ -39,7 +39,7 @@ namespace UniGLTF
|
|||
.Where(x => x.Value != null)
|
||||
.ToDictionary(kv => new SubAssetKey(kv.Value.GetType(), kv.Key.name), kv => kv.Value);
|
||||
|
||||
using (var loader = new ImporterContext(parser, extractedObjects))
|
||||
using (var loader = new ImporterContext(data, extractedObjects))
|
||||
{
|
||||
// Configure TextureImporter to Extracted Textures.
|
||||
foreach (var textureInfo in loader.TextureDescriptorGenerator.Get().GetEnumerable())
|
||||
|
|
|
|||
|
|
@ -3,379 +3,64 @@ using System.Collections.Generic;
|
|||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using UniJSON;
|
||||
using UnityEngine;
|
||||
|
||||
namespace UniGLTF
|
||||
{
|
||||
public class IGltfData
|
||||
public sealed class IGltfData
|
||||
{
|
||||
/// <summary>
|
||||
/// Source file path.
|
||||
/// Maybe empty if source file was on memory.
|
||||
/// </summary>
|
||||
public string TargetPath { get; }
|
||||
|
||||
/// <summary>
|
||||
/// JSON source
|
||||
/// </summary>
|
||||
public String Json;
|
||||
|
||||
public string Json { get; }
|
||||
|
||||
/// <summary>
|
||||
/// GLTF parsed from JSON
|
||||
/// </summary>
|
||||
public glTF GLTF;
|
||||
|
||||
public glTF GLTF { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Chunk Data.
|
||||
/// Maybe empty if source file was not glb format.
|
||||
/// </summary>
|
||||
public IReadOnlyList<GlbChunk> Chunks { get; }
|
||||
|
||||
/// <summary>
|
||||
/// URI access
|
||||
/// </summary>
|
||||
public IStorage Storage;
|
||||
|
||||
public MigrationFlags MigrationFlags = new MigrationFlags();
|
||||
|
||||
#region Parse
|
||||
public void ParsePath(string path)
|
||||
{
|
||||
Parse(path, File.ReadAllBytes(path));
|
||||
}
|
||||
|
||||
string m_targetPath;
|
||||
public string TargetPath
|
||||
{
|
||||
get => m_targetPath;
|
||||
set
|
||||
{
|
||||
m_targetPath = Path.GetFullPath(value);
|
||||
}
|
||||
}
|
||||
|
||||
public IStorage Storage { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Parse gltf json or Parse json chunk of glb
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="path"></param>
|
||||
/// <param name="bytes"></param>
|
||||
public virtual void Parse(string path, Byte[] bytes)
|
||||
{
|
||||
TargetPath = path;
|
||||
var ext = Path.GetExtension(path).ToLower();
|
||||
switch (ext)
|
||||
{
|
||||
case ".gltf":
|
||||
ParseJson(Encoding.UTF8.GetString(bytes), new FileSystemStorage(Path.GetDirectoryName(path)));
|
||||
break;
|
||||
|
||||
case ".zip":
|
||||
{
|
||||
var zipArchive = Zip.ZipArchiveStorage.Parse(bytes);
|
||||
var gltf = zipArchive.Entries.FirstOrDefault(x => x.FileName.ToLower().EndsWith(".gltf"));
|
||||
if (gltf == null)
|
||||
{
|
||||
throw new Exception("no gltf in archive");
|
||||
}
|
||||
var jsonBytes = zipArchive.Extract(gltf);
|
||||
var json = Encoding.UTF8.GetString(jsonBytes);
|
||||
ParseJson(json, zipArchive);
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
ParseGlb(bytes);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="bytes"></param>
|
||||
public void ParseGlb(Byte[] bytes)
|
||||
{
|
||||
var chunks = glbImporter.ParseGlbChunks(bytes);
|
||||
|
||||
if (chunks.Count < 2)
|
||||
{
|
||||
throw new Exception("unknown chunk count: " + chunks.Count);
|
||||
}
|
||||
|
||||
if (chunks[0].ChunkType != GlbChunkType.JSON)
|
||||
{
|
||||
throw new Exception("chunk 0 is not JSON");
|
||||
}
|
||||
|
||||
if (chunks[1].ChunkType != GlbChunkType.BIN)
|
||||
{
|
||||
throw new Exception("chunk 1 is not BIN");
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
var jsonBytes = chunks[0].Bytes;
|
||||
ParseJson(Encoding.UTF8.GetString(jsonBytes.Array, jsonBytes.Offset, jsonBytes.Count),
|
||||
new SimpleStorage(chunks[1].Bytes));
|
||||
|
||||
ParseExternalChunks(bytes, chunks);
|
||||
}
|
||||
catch (StackOverflowException ex)
|
||||
{
|
||||
throw new Exception("[UniVRM Import Error] json parsing failed, nesting is too deep.\n" + ex);
|
||||
}
|
||||
catch
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
protected virtual void ParseExternalChunks(byte[] bytes, IReadOnlyList<GlbChunk> chunks)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public virtual void ParseJson(string json, IStorage storage)
|
||||
public MigrationFlags MigrationFlags { get; }
|
||||
|
||||
public IGltfData(string targetPath, string json, glTF gltf, IReadOnlyList<GlbChunk> chunks, IStorage storage, MigrationFlags migrationFlags)
|
||||
{
|
||||
TargetPath = targetPath;
|
||||
Json = json;
|
||||
GLTF = gltf;
|
||||
Chunks = chunks;
|
||||
Storage = storage;
|
||||
GLTF = GltfDeserializer.Deserialize(json.ParseAsJson());
|
||||
if (GLTF.asset.version != "2.0")
|
||||
{
|
||||
throw new UniGLTFException("unknown gltf version {0}", GLTF.asset.version);
|
||||
}
|
||||
|
||||
// Version Compatibility
|
||||
RestoreOlderVersionValues();
|
||||
|
||||
FixMeshNameUnique();
|
||||
foreach (var image in GLTF.images)
|
||||
{
|
||||
image.uri = PrepareUri(image.uri);
|
||||
}
|
||||
FixTextureNameUnique();
|
||||
FixMaterialNameUnique();
|
||||
FixNodeName();
|
||||
FixAnimationNameUnique();
|
||||
|
||||
// parepare byte buffer
|
||||
//GLTF.baseDir = System.IO.Path.GetDirectoryName(Path);
|
||||
foreach (var buffer in GLTF.buffers)
|
||||
{
|
||||
buffer.OpenStorage(storage);
|
||||
}
|
||||
MigrationFlags = migrationFlags;
|
||||
}
|
||||
|
||||
void FixMeshNameUnique()
|
||||
public static IGltfData CreateFromGltfData(glTF gltf)
|
||||
{
|
||||
var used = new HashSet<string>();
|
||||
foreach (var mesh in GLTF.meshes)
|
||||
{
|
||||
if (string.IsNullOrEmpty(mesh.name))
|
||||
{
|
||||
// empty
|
||||
mesh.name = "mesh_" + Guid.NewGuid().ToString("N");
|
||||
// Debug.LogWarning($"mesh.name: => {mesh.name}");
|
||||
used.Add(mesh.name);
|
||||
}
|
||||
else
|
||||
{
|
||||
var lower = mesh.name.ToLower();
|
||||
if (used.Contains(lower))
|
||||
{
|
||||
// rename
|
||||
var uname = lower + "_" + Guid.NewGuid().ToString("N");
|
||||
// Debug.LogWarning($"mesh.name: {lower} => {uname}");
|
||||
mesh.name = uname;
|
||||
lower = uname;
|
||||
}
|
||||
used.Add(lower);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void RenameImageFromTexture(int i)
|
||||
{
|
||||
foreach (var texture in GLTF.textures)
|
||||
{
|
||||
if (texture.source == i)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(texture.name))
|
||||
{
|
||||
GLTF.images[i].name = texture.name;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// image.uri を前理
|
||||
/// </summary>
|
||||
/// <param name="uri"></param>
|
||||
/// <returns></returns>
|
||||
public static string PrepareUri(string uri)
|
||||
{
|
||||
if (string.IsNullOrEmpty(uri))
|
||||
{
|
||||
return uri;
|
||||
}
|
||||
|
||||
if (uri.StartsWith("./"))
|
||||
{
|
||||
// skip
|
||||
uri = uri.Substring(2);
|
||||
}
|
||||
|
||||
// %20 to ' ' etc...
|
||||
var unescape = Uri.UnescapeDataString(uri);
|
||||
return unescape;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// gltfTexture.name を Unity Asset 名として運用する。
|
||||
/// ユニークである必要がある。
|
||||
/// </summary>
|
||||
void FixTextureNameUnique()
|
||||
{
|
||||
var used = new HashSet<string>();
|
||||
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) && !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))
|
||||
{
|
||||
// no name
|
||||
var newName = $"texture_{i}";
|
||||
if (!used.Add(newName))
|
||||
{
|
||||
newName = "texture_" + Guid.NewGuid().ToString("N");
|
||||
if (!used.Add(newName))
|
||||
{
|
||||
throw new Exception();
|
||||
}
|
||||
}
|
||||
gltfTexture.name = newName;
|
||||
}
|
||||
else
|
||||
{
|
||||
var lower = gltfTexture.name.ToLower();
|
||||
if (!used.Add(lower))
|
||||
{
|
||||
// rename
|
||||
var uname = lower + "_" + Guid.NewGuid().ToString("N");
|
||||
// Debug.LogWarning($"texture.name: {lower} => {uname}");
|
||||
gltfTexture.name = uname;
|
||||
if (!used.Add(uname))
|
||||
{
|
||||
throw new Exception();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void FixMaterialNameUnique()
|
||||
{
|
||||
var used = new HashSet<string>();
|
||||
for (int i = 0; i < GLTF.materials.Count; ++i)
|
||||
{
|
||||
var material = GLTF.materials[i];
|
||||
var originalName = material.name;
|
||||
int j = 2;
|
||||
|
||||
if (string.IsNullOrEmpty(material.name))
|
||||
{
|
||||
material.name = $"material_{i}";
|
||||
}
|
||||
|
||||
while (true)
|
||||
{
|
||||
if (used.Add(material.name))
|
||||
{
|
||||
#if VRM_DEVELOP
|
||||
// Debug.Log($"Material: {material.name}");
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
material.name = string.Format("{0}({1})", originalName, j++);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// rename empty name to $"{index}"
|
||||
/// </summary>
|
||||
void FixNodeName()
|
||||
{
|
||||
for (var i = 0; i < GLTF.nodes.Count; ++i)
|
||||
{
|
||||
var node = GLTF.nodes[i];
|
||||
if (string.IsNullOrWhiteSpace(node.name))
|
||||
{
|
||||
node.name = $"{i}";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void FixAnimationNameUnique()
|
||||
{
|
||||
var used = new HashSet<string>();
|
||||
for (int i = 0; i < GLTF.animations.Count; ++i)
|
||||
{
|
||||
var animation = GLTF.animations[i];
|
||||
var originalName = animation.name;
|
||||
int j = 2;
|
||||
|
||||
if (string.IsNullOrEmpty(animation.name))
|
||||
{
|
||||
animation.name = $"animation_{i}";
|
||||
}
|
||||
|
||||
while (true)
|
||||
{
|
||||
if (used.Add(animation.name))
|
||||
{
|
||||
#if VRM_DEVELOP
|
||||
// Debug.Log($"Material: {material.name}");
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
animation.name = string.Format("{0}({1})", originalName, j++);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void RestoreOlderVersionValues()
|
||||
{
|
||||
var parsed = UniJSON.JsonParser.Parse(Json);
|
||||
for (int i = 0; i < GLTF.images.Count; ++i)
|
||||
{
|
||||
if (string.IsNullOrEmpty(GLTF.images[i].name))
|
||||
{
|
||||
try
|
||||
{
|
||||
var extraName = parsed["images"][i]["extra"]["name"].Value.GetString();
|
||||
if (!string.IsNullOrEmpty(extraName))
|
||||
{
|
||||
//Debug.LogFormat("restore texturename: {0}", extraName);
|
||||
GLTF.images[i].name = extraName;
|
||||
}
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
// do nothing
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
public static void AppendImageExtension(glTFImage texture, string extension)
|
||||
{
|
||||
if (!texture.name.EndsWith(extension))
|
||||
{
|
||||
texture.name = texture.name + extension;
|
||||
}
|
||||
return new IGltfData(
|
||||
string.Empty,
|
||||
string.Empty,
|
||||
gltf,
|
||||
new List<GlbChunk>(),
|
||||
new SimpleStorage(new ArraySegment<byte>()),
|
||||
new MigrationFlags()
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
3
Assets/UniGLTF/Runtime/UniGLTF/IO/Parser.meta
Normal file
3
Assets/UniGLTF/Runtime/UniGLTF/IO/Parser.meta
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 7355a12dd8fc4e0287077f7e57d185ef
|
||||
timeCreated: 1624801467
|
||||
|
|
@ -0,0 +1,34 @@
|
|||
using System.IO;
|
||||
|
||||
namespace UniGLTF
|
||||
{
|
||||
/// <summary>
|
||||
/// Ambiguous file parser.
|
||||
/// Determine parsing method from the file extension.
|
||||
/// </summary>
|
||||
public sealed class AmbiguousGltfFileParser
|
||||
{
|
||||
private readonly string _path;
|
||||
|
||||
public AmbiguousGltfFileParser(string path)
|
||||
{
|
||||
_path = path;
|
||||
}
|
||||
|
||||
public IGltfData Parse()
|
||||
{
|
||||
var ext = Path.GetExtension(_path).ToLower();
|
||||
switch (ext)
|
||||
{
|
||||
case ".gltf":
|
||||
return new GltfFileWithResourceFilesParser(_path).Parse();
|
||||
|
||||
case ".zip":
|
||||
return new ZipArchivedGltfFileParser(_path).Parse();
|
||||
|
||||
default:
|
||||
return new GlbFileParser(_path).Parse();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 3a36dcb5732b467598919c0ed66f0c5a
|
||||
timeCreated: 1624802689
|
||||
20
Assets/UniGLTF/Runtime/UniGLTF/IO/Parser/GlbFileParser.cs
Normal file
20
Assets/UniGLTF/Runtime/UniGLTF/IO/Parser/GlbFileParser.cs
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
using System.IO;
|
||||
|
||||
namespace UniGLTF
|
||||
{
|
||||
public sealed class GlbFileParser
|
||||
{
|
||||
private readonly string _path;
|
||||
|
||||
public GlbFileParser(string glbFilePath)
|
||||
{
|
||||
_path = glbFilePath;
|
||||
}
|
||||
|
||||
public IGltfData Parse()
|
||||
{
|
||||
var data = File.ReadAllBytes(_path);
|
||||
return new GlbLowLevelParser(_path, data).Parse();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 5ba8d14b45824a97a4e63c2ced2c4bb4
|
||||
timeCreated: 1624798248
|
||||
319
Assets/UniGLTF/Runtime/UniGLTF/IO/Parser/GlbLowLevelParser.cs
Normal file
319
Assets/UniGLTF/Runtime/UniGLTF/IO/Parser/GlbLowLevelParser.cs
Normal file
|
|
@ -0,0 +1,319 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using UniJSON;
|
||||
|
||||
namespace UniGLTF
|
||||
{
|
||||
public sealed class GlbLowLevelParser
|
||||
{
|
||||
private readonly string _path;
|
||||
private readonly byte[] _binary;
|
||||
|
||||
public GlbLowLevelParser(string path, byte[] specifiedBinary)
|
||||
{
|
||||
_path = path;
|
||||
_binary = specifiedBinary;
|
||||
}
|
||||
|
||||
public IGltfData Parse()
|
||||
{
|
||||
try
|
||||
{
|
||||
var chunks = ParseGlbChunks(_binary);
|
||||
var jsonBytes = chunks[0].Bytes;
|
||||
return ParseGltf(
|
||||
_path,
|
||||
Encoding.UTF8.GetString(jsonBytes.Array, jsonBytes.Offset, jsonBytes.Count),
|
||||
chunks,
|
||||
new SimpleStorage(chunks[1].Bytes),
|
||||
new MigrationFlags()
|
||||
);
|
||||
}
|
||||
catch (StackOverflowException ex)
|
||||
{
|
||||
throw new Exception("[UniVRM Import Error] json parsing failed, nesting is too deep.\n" + ex);
|
||||
}
|
||||
catch
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public static List<GlbChunk> ParseGlbChunks(byte[] data)
|
||||
{
|
||||
var chunks = glbImporter.ParseGlbChunks(data);
|
||||
|
||||
if (chunks.Count < 2)
|
||||
{
|
||||
throw new Exception("unknown chunk count: " + chunks.Count);
|
||||
}
|
||||
|
||||
if (chunks[0].ChunkType != GlbChunkType.JSON)
|
||||
{
|
||||
throw new Exception("chunk 0 is not JSON");
|
||||
}
|
||||
|
||||
if (chunks[1].ChunkType != GlbChunkType.BIN)
|
||||
{
|
||||
throw new Exception("chunk 1 is not BIN");
|
||||
}
|
||||
|
||||
return chunks;
|
||||
}
|
||||
|
||||
public static IGltfData ParseGltf(string path, string json, IReadOnlyList<GlbChunk> chunks, IStorage storage, MigrationFlags migrationFlags)
|
||||
{
|
||||
var GLTF = GltfDeserializer.Deserialize(json.ParseAsJson());
|
||||
if (GLTF.asset.version != "2.0")
|
||||
{
|
||||
throw new UniGLTFException("unknown gltf version {0}", GLTF.asset.version);
|
||||
}
|
||||
|
||||
// Version Compatibility
|
||||
RestoreOlderVersionValues(json, GLTF);
|
||||
|
||||
FixMeshNameUnique(GLTF);
|
||||
foreach (var image in GLTF.images)
|
||||
{
|
||||
image.uri = PrepareUri(image.uri);
|
||||
}
|
||||
FixTextureNameUnique(GLTF);
|
||||
FixMaterialNameUnique(GLTF);
|
||||
FixNodeName(GLTF);
|
||||
FixAnimationNameUnique(GLTF);
|
||||
|
||||
// parepare byte buffer
|
||||
//GLTF.baseDir = System.IO.Path.GetDirectoryName(Path);
|
||||
foreach (var buffer in GLTF.buffers)
|
||||
{
|
||||
buffer.OpenStorage(storage);
|
||||
}
|
||||
|
||||
return new IGltfData(path, json, GLTF, chunks, storage, migrationFlags);
|
||||
}
|
||||
|
||||
private static void FixMeshNameUnique(glTF GLTF)
|
||||
{
|
||||
var used = new HashSet<string>();
|
||||
foreach (var mesh in GLTF.meshes)
|
||||
{
|
||||
if (string.IsNullOrEmpty(mesh.name))
|
||||
{
|
||||
// empty
|
||||
mesh.name = "mesh_" + Guid.NewGuid().ToString("N");
|
||||
// Debug.LogWarning($"mesh.name: => {mesh.name}");
|
||||
used.Add(mesh.name);
|
||||
}
|
||||
else
|
||||
{
|
||||
var lower = mesh.name.ToLower();
|
||||
if (used.Contains(lower))
|
||||
{
|
||||
// rename
|
||||
var uname = lower + "_" + Guid.NewGuid().ToString("N");
|
||||
// Debug.LogWarning($"mesh.name: {lower} => {uname}");
|
||||
mesh.name = uname;
|
||||
lower = uname;
|
||||
}
|
||||
used.Add(lower);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void RenameImageFromTexture(glTF GLTF, int i)
|
||||
{
|
||||
foreach (var texture in GLTF.textures)
|
||||
{
|
||||
if (texture.source == i)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(texture.name))
|
||||
{
|
||||
GLTF.images[i].name = texture.name;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// image.uri を前理
|
||||
/// </summary>
|
||||
/// <param name="uri"></param>
|
||||
/// <returns></returns>
|
||||
public static string PrepareUri(string uri)
|
||||
{
|
||||
if (string.IsNullOrEmpty(uri))
|
||||
{
|
||||
return uri;
|
||||
}
|
||||
|
||||
if (uri.StartsWith("./"))
|
||||
{
|
||||
// skip
|
||||
uri = uri.Substring(2);
|
||||
}
|
||||
|
||||
// %20 to ' ' etc...
|
||||
var unescape = Uri.UnescapeDataString(uri);
|
||||
return unescape;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// gltfTexture.name を Unity Asset 名として運用する。
|
||||
/// ユニークである必要がある。
|
||||
/// </summary>
|
||||
private static void FixTextureNameUnique(glTF GLTF)
|
||||
{
|
||||
var used = new HashSet<string>();
|
||||
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) && !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))
|
||||
{
|
||||
// no name
|
||||
var newName = $"texture_{i}";
|
||||
if (!used.Add(newName))
|
||||
{
|
||||
newName = "texture_" + Guid.NewGuid().ToString("N");
|
||||
if (!used.Add(newName))
|
||||
{
|
||||
throw new Exception();
|
||||
}
|
||||
}
|
||||
gltfTexture.name = newName;
|
||||
}
|
||||
else
|
||||
{
|
||||
var lower = gltfTexture.name.ToLower();
|
||||
if (!used.Add(lower))
|
||||
{
|
||||
// rename
|
||||
var uname = lower + "_" + Guid.NewGuid().ToString("N");
|
||||
// Debug.LogWarning($"texture.name: {lower} => {uname}");
|
||||
gltfTexture.name = uname;
|
||||
if (!used.Add(uname))
|
||||
{
|
||||
throw new Exception();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void FixMaterialNameUnique(glTF GLTF)
|
||||
{
|
||||
var used = new HashSet<string>();
|
||||
for (int i = 0; i < GLTF.materials.Count; ++i)
|
||||
{
|
||||
var material = GLTF.materials[i];
|
||||
var originalName = material.name;
|
||||
int j = 2;
|
||||
|
||||
if (string.IsNullOrEmpty(material.name))
|
||||
{
|
||||
material.name = $"material_{i}";
|
||||
}
|
||||
|
||||
while (true)
|
||||
{
|
||||
if (used.Add(material.name))
|
||||
{
|
||||
#if VRM_DEVELOP
|
||||
// Debug.Log($"Material: {material.name}");
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
material.name = string.Format("{0}({1})", originalName, j++);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// rename empty name to $"{index}"
|
||||
/// </summary>
|
||||
private static void FixNodeName(glTF GLTF)
|
||||
{
|
||||
for (var i = 0; i < GLTF.nodes.Count; ++i)
|
||||
{
|
||||
var node = GLTF.nodes[i];
|
||||
if (string.IsNullOrWhiteSpace(node.name))
|
||||
{
|
||||
node.name = $"{i}";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void FixAnimationNameUnique(glTF GLTF)
|
||||
{
|
||||
var used = new HashSet<string>();
|
||||
for (int i = 0; i < GLTF.animations.Count; ++i)
|
||||
{
|
||||
var animation = GLTF.animations[i];
|
||||
var originalName = animation.name;
|
||||
int j = 2;
|
||||
|
||||
if (string.IsNullOrEmpty(animation.name))
|
||||
{
|
||||
animation.name = $"animation_{i}";
|
||||
}
|
||||
|
||||
while (true)
|
||||
{
|
||||
if (used.Add(animation.name))
|
||||
{
|
||||
#if VRM_DEVELOP
|
||||
// Debug.Log($"Material: {material.name}");
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
animation.name = string.Format("{0}({1})", originalName, j++);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void RestoreOlderVersionValues(string Json, glTF GLTF)
|
||||
{
|
||||
var parsed = UniJSON.JsonParser.Parse(Json);
|
||||
for (int i = 0; i < GLTF.images.Count; ++i)
|
||||
{
|
||||
if (string.IsNullOrEmpty(GLTF.images[i].name))
|
||||
{
|
||||
try
|
||||
{
|
||||
var extraName = parsed["images"][i]["extra"]["name"].Value.GetString();
|
||||
if (!string.IsNullOrEmpty(extraName))
|
||||
{
|
||||
//Debug.LogFormat("restore texturename: {0}", extraName);
|
||||
GLTF.images[i].name = extraName;
|
||||
}
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
// do nothing
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void AppendImageExtension(glTFImage texture, string extension)
|
||||
{
|
||||
if (!texture.name.EndsWith(extension))
|
||||
{
|
||||
texture.name = texture.name + extension;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 880cb82ec6f8498fbae6a5579484e171
|
||||
timeCreated: 1624804947
|
||||
|
|
@ -0,0 +1,40 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
|
||||
namespace UniGLTF
|
||||
{
|
||||
/// <summary>
|
||||
/// .GLTF file with resources in same directory parser.
|
||||
/// </summary>
|
||||
public sealed class GltfFileWithResourceFilesParser
|
||||
{
|
||||
private readonly string _gltfFilePath;
|
||||
private readonly string _gltfRootPath;
|
||||
|
||||
public GltfFileWithResourceFilesParser(string gltfFilePath)
|
||||
{
|
||||
if (!File.Exists(gltfFilePath))
|
||||
{
|
||||
throw new ArgumentException($"no file: {gltfFilePath}");
|
||||
}
|
||||
|
||||
_gltfFilePath = gltfFilePath;
|
||||
_gltfRootPath = Path.GetDirectoryName(gltfFilePath);
|
||||
}
|
||||
|
||||
public IGltfData Parse()
|
||||
{
|
||||
var binary = File.ReadAllBytes(_gltfFilePath);
|
||||
|
||||
return GlbLowLevelParser.ParseGltf(
|
||||
_gltfFilePath,
|
||||
Encoding.UTF8.GetString(binary),
|
||||
new List<GlbChunk>(), // .gltf file has no chunks.
|
||||
new FileSystemStorage(_gltfRootPath), // .gltf file has resource path at file system.
|
||||
new MigrationFlags()
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: f8d3a8226f2d49b78529a62fa26aa386
|
||||
timeCreated: 1624802034
|
||||
|
|
@ -0,0 +1,32 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace UniGLTF
|
||||
{
|
||||
/// <summary>
|
||||
/// For unit tests.
|
||||
/// JSON string with storage parser.
|
||||
/// </summary>
|
||||
public sealed class JsonWithStorageParser
|
||||
{
|
||||
private readonly string _json;
|
||||
private readonly IStorage _storage;
|
||||
|
||||
public JsonWithStorageParser(string json, IStorage storage = null)
|
||||
{
|
||||
_json = json;
|
||||
_storage = storage ?? new SimpleStorage(new ArraySegment<byte>());
|
||||
}
|
||||
|
||||
public IGltfData Parse()
|
||||
{
|
||||
return GlbLowLevelParser.ParseGltf(
|
||||
string.Empty,
|
||||
_json,
|
||||
new List<GlbChunk>(),
|
||||
_storage,
|
||||
new MigrationFlags()
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: c103da8b4a2b4050be09e7bfce2769fd
|
||||
timeCreated: 1624803637
|
||||
|
|
@ -0,0 +1,47 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace UniGLTF
|
||||
{
|
||||
/// <summary>
|
||||
/// Zip archived .GLTF file parser.
|
||||
/// </summary>
|
||||
public sealed class ZipArchivedGltfFileParser
|
||||
{
|
||||
private readonly string _zippedFilePath;
|
||||
|
||||
public ZipArchivedGltfFileParser(string zippedFilePath)
|
||||
{
|
||||
if (!File.Exists(zippedFilePath))
|
||||
{
|
||||
throw new ArgumentException($"no file: {zippedFilePath}");
|
||||
}
|
||||
|
||||
_zippedFilePath = zippedFilePath;
|
||||
}
|
||||
|
||||
public IGltfData Parse()
|
||||
{
|
||||
var binary = File.ReadAllBytes(_zippedFilePath);
|
||||
|
||||
var zipArchive = Zip.ZipArchiveStorage.Parse(binary);
|
||||
var gltf = zipArchive.Entries.FirstOrDefault(x => x.FileName.ToLower().EndsWith(".gltf"));
|
||||
if (gltf == null)
|
||||
{
|
||||
throw new Exception("no gltf in archive");
|
||||
}
|
||||
var jsonBytes = zipArchive.Extract(gltf);
|
||||
var json = Encoding.UTF8.GetString(jsonBytes);
|
||||
return GlbLowLevelParser.ParseGltf(
|
||||
_zippedFilePath,
|
||||
json,
|
||||
new List<GlbChunk>(),
|
||||
zipArchive,
|
||||
new MigrationFlags()
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 78c9576bb53142eea2fef19b8ba16fa8
|
||||
timeCreated: 1624802489
|
||||
|
|
@ -78,10 +78,10 @@ namespace UniGLTF
|
|||
|
||||
static void RuntimeLoadExport(FileInfo gltf, int subStrStart)
|
||||
{
|
||||
var parser = new IGltfData();
|
||||
IGltfData data = null;
|
||||
try
|
||||
{
|
||||
parser.ParsePath(gltf.FullName);
|
||||
data = new AmbiguousGltfFileParser(gltf.FullName).Parse();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
|
@ -89,7 +89,7 @@ namespace UniGLTF
|
|||
Debug.LogException(ex);
|
||||
}
|
||||
|
||||
using (var loader = new ImporterContext(parser))
|
||||
using (var loader = new ImporterContext(data))
|
||||
{
|
||||
try
|
||||
{
|
||||
|
|
@ -124,10 +124,10 @@ namespace UniGLTF
|
|||
/// <param name="root"></param>
|
||||
static void EditorLoad(FileInfo gltf, int subStrStart)
|
||||
{
|
||||
var parser = new IGltfData();
|
||||
IGltfData data = null;
|
||||
try
|
||||
{
|
||||
parser.ParsePath(gltf.FullName);
|
||||
data = new AmbiguousGltfFileParser(gltf.FullName).Parse();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
|
@ -136,7 +136,7 @@ namespace UniGLTF
|
|||
}
|
||||
|
||||
// should unique
|
||||
var gltfTextures = new GltfTextureDescriptorGenerator(parser).Get().GetEnumerable()
|
||||
var gltfTextures = new GltfTextureDescriptorGenerator(data).Get().GetEnumerable()
|
||||
.Select(x => x.SubAssetKey)
|
||||
.ToArray();
|
||||
var distinct = gltfTextures.Distinct().ToArray();
|
||||
|
|
@ -205,10 +205,9 @@ namespace UniGLTF
|
|||
|
||||
{
|
||||
var path = Path.Combine(root.FullName, "DamagedHelmet/glTF-Binary/DamagedHelmet.glb");
|
||||
var parser = new IGltfData();
|
||||
parser.ParsePath(path);
|
||||
var data = new AmbiguousGltfFileParser(path).Parse();
|
||||
|
||||
var matDesc = new GltfMaterialDescriptorGenerator().Get(parser, 0);
|
||||
var matDesc = new GltfMaterialDescriptorGenerator().Get(data, 0);
|
||||
Assert.AreEqual("Standard", matDesc.ShaderName);
|
||||
Assert.AreEqual(5, matDesc.TextureSlots.Count);
|
||||
var (key, value) = matDesc.EnumerateSubAssetKeyValue().First();
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
using System.Collections.Generic;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using NUnit.Framework;
|
||||
|
||||
|
|
@ -203,40 +204,40 @@ namespace UniGLTF
|
|||
public void TextureEnumerationTest()
|
||||
{
|
||||
{
|
||||
var parser = new IGltfData
|
||||
{
|
||||
GLTF = TwoTexture(),
|
||||
};
|
||||
var items = new GltfTextureDescriptorGenerator(parser).Get().GetEnumerable().ToArray();
|
||||
var data = CreateGltfData(TwoTexture());
|
||||
var items = new GltfTextureDescriptorGenerator(data).Get().GetEnumerable().ToArray();
|
||||
Assert.AreEqual(2, items.Length);
|
||||
}
|
||||
|
||||
{
|
||||
var parser = new IGltfData
|
||||
{
|
||||
GLTF = TwoTextureOneUri(),
|
||||
};
|
||||
var items = new GltfTextureDescriptorGenerator(parser).Get().GetEnumerable().ToArray();
|
||||
var data = CreateGltfData(TwoTextureOneUri());
|
||||
var items = new GltfTextureDescriptorGenerator(data).Get().GetEnumerable().ToArray();
|
||||
Assert.AreEqual(1, items.Length);
|
||||
}
|
||||
|
||||
{
|
||||
var parser = new IGltfData
|
||||
{
|
||||
GLTF = TwoTextureOneImage(),
|
||||
};
|
||||
var items = new GltfTextureDescriptorGenerator(parser).Get().GetEnumerable().ToArray();
|
||||
var data = CreateGltfData(TwoTextureOneImage());
|
||||
var items = new GltfTextureDescriptorGenerator(data).Get().GetEnumerable().ToArray();
|
||||
Assert.AreEqual(1, items.Length);
|
||||
}
|
||||
|
||||
{
|
||||
var parser = new IGltfData
|
||||
{
|
||||
GLTF = CombineMetallicSmoothOcclusion(),
|
||||
};
|
||||
var items = new GltfTextureDescriptorGenerator(parser).Get().GetEnumerable().ToArray();
|
||||
var data = CreateGltfData(CombineMetallicSmoothOcclusion());
|
||||
var items = new GltfTextureDescriptorGenerator(data).Get().GetEnumerable().ToArray();
|
||||
Assert.AreEqual(1, items.Length);
|
||||
}
|
||||
}
|
||||
|
||||
private IGltfData CreateGltfData(glTF gltf)
|
||||
{
|
||||
return new IGltfData(
|
||||
string.Empty,
|
||||
string.Empty,
|
||||
gltf,
|
||||
new List<GlbChunk>(),
|
||||
new SimpleStorage(new ArraySegment<byte>()),
|
||||
new MigrationFlags()
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -89,11 +89,10 @@ namespace UniGLTF
|
|||
}
|
||||
|
||||
// parse
|
||||
var parser = new IGltfData();
|
||||
parser.ParsePath(path.FullName);
|
||||
var data = new GlbFileParser(path.FullName).Parse();
|
||||
|
||||
// load
|
||||
using (var context = new ImporterContext(parser))
|
||||
using (var context = new ImporterContext(data))
|
||||
{
|
||||
var instance = context.Load();
|
||||
var textureMap = instance.RuntimeResources
|
||||
|
|
@ -103,7 +102,7 @@ namespace UniGLTF
|
|||
;
|
||||
|
||||
// extractor
|
||||
var extractor = new TextureExtractor(parser, UnityPath.FromUnityPath(""), textureMap);
|
||||
var extractor = new TextureExtractor(data, UnityPath.FromUnityPath(""), textureMap);
|
||||
var m = context.TextureDescriptorGenerator.Get().GetEnumerable()
|
||||
.FirstOrDefault(x => x.SubAssetKey.Name == "texture_1.standard");
|
||||
|
||||
|
|
|
|||
|
|
@ -115,11 +115,10 @@ namespace UniGLTF
|
|||
}
|
||||
|
||||
// parse
|
||||
var parser = new IGltfData();
|
||||
parser.ParseJson(json, new SimpleStorage(new ArraySegment<byte>()));
|
||||
var data = new JsonWithStorageParser(json).Parse();
|
||||
|
||||
// import
|
||||
using (var context = new ImporterContext(parser))
|
||||
using (var context = new ImporterContext(data))
|
||||
using (var loaded = context.Load())
|
||||
{
|
||||
AssertAreEqual(go.transform, loaded.transform);
|
||||
|
|
@ -553,10 +552,10 @@ namespace UniGLTF
|
|||
|
||||
// import
|
||||
{
|
||||
var parser = new IGltfData();
|
||||
parser.ParseJson(json, new SimpleStorage(new ArraySegment<byte>(new byte[1024 * 1024])));
|
||||
var storage = new SimpleStorage(new ArraySegment<byte>(new byte[1024 * 1024]));
|
||||
var data = new JsonWithStorageParser(json, storage).Parse();
|
||||
|
||||
using (var context = new ImporterContext(parser))
|
||||
using (var context = new ImporterContext(data))
|
||||
using (var loaded = context.Load())
|
||||
{
|
||||
var importedRed = loaded.transform.GetChild(0);
|
||||
|
|
@ -573,10 +572,11 @@ namespace UniGLTF
|
|||
|
||||
// import new version
|
||||
{
|
||||
var parser = new IGltfData();
|
||||
parser.ParseJson(json, new SimpleStorage(new ArraySegment<byte>(new byte[1024 * 1024])));
|
||||
var storage = new SimpleStorage(new ArraySegment<byte>(new byte[1024 * 1024]));
|
||||
var data = new JsonWithStorageParser(json, storage).Parse();
|
||||
|
||||
//Debug.LogFormat("{0}", context.Json);
|
||||
using (var context = new ImporterContext(parser))
|
||||
using (var context = new ImporterContext(data))
|
||||
using (var loaded = context.Load())
|
||||
{
|
||||
var importedRed = loaded.transform.GetChild(0);
|
||||
|
|
@ -626,10 +626,10 @@ namespace UniGLTF
|
|||
|
||||
// import
|
||||
{
|
||||
var parser = new IGltfData();
|
||||
parser.ParseJson(json, new SimpleStorage(new ArraySegment<byte>(new byte[1024 * 1024])));
|
||||
|
||||
using (var context = new ImporterContext(parser))
|
||||
var storage = new SimpleStorage(new ArraySegment<byte>(new byte[1024 * 1024]));
|
||||
var data = new JsonWithStorageParser(json, storage).Parse();
|
||||
|
||||
using (var context = new ImporterContext(data))
|
||||
using (var loaded = context.Load())
|
||||
{
|
||||
Assert.AreEqual(1, loaded.transform.GetChildren().Count());
|
||||
|
|
@ -691,10 +691,10 @@ namespace UniGLTF
|
|||
|
||||
// import
|
||||
{
|
||||
var parser = new IGltfData();
|
||||
parser.ParseJson(json, new SimpleStorage(new ArraySegment<byte>(new byte[1024 * 1024])));
|
||||
var storage = new SimpleStorage(new ArraySegment<byte>(new byte[1024 * 1024]));
|
||||
var data = new JsonWithStorageParser(json, storage).Parse();
|
||||
|
||||
using (var context = new ImporterContext(parser))
|
||||
using (var context = new ImporterContext(data))
|
||||
using (var loaded = context.Load())
|
||||
{
|
||||
Assert.AreEqual(2, loaded.transform.GetChildren().Count());
|
||||
|
|
|
|||
|
|
@ -43,10 +43,9 @@ namespace VRM.Samples
|
|||
public void ImportExportTest()
|
||||
{
|
||||
var path = AliciaPath;
|
||||
var parser = new IGltfData();
|
||||
parser.ParseGlb(File.ReadAllBytes(path));
|
||||
var data = new GlbFileParser(path).Parse();
|
||||
|
||||
using (var context = new VRMImporterContext(parser))
|
||||
using (var context = new VRMImporterContext(data))
|
||||
using (var loaded = context.Load())
|
||||
{
|
||||
loaded.ShowMeshes();
|
||||
|
|
@ -67,16 +66,16 @@ namespace VRM.Samples
|
|||
mesh = smr.sharedMesh;
|
||||
}
|
||||
|
||||
var gltfMesh = parser.GLTF.meshes.Find(x => x.name == mesh.name);
|
||||
var gltfMesh = data.GLTF.meshes.Find(x => x.name == mesh.name);
|
||||
Assert.AreEqual(gltfMesh.name, mesh.name);
|
||||
|
||||
// materials
|
||||
foreach (var material in renderer.sharedMaterials)
|
||||
{
|
||||
var gltfMaterial = parser.GLTF.materials.Find(x => x.name == material.name);
|
||||
var gltfMaterial = data.GLTF.materials.Find(x => x.name == material.name);
|
||||
Assert.AreEqual(gltfMaterial.name, material.name);
|
||||
|
||||
var materialIndex = parser.GLTF.materials.IndexOf(gltfMaterial);
|
||||
var materialIndex = data.GLTF.materials.IndexOf(gltfMaterial);
|
||||
var vrmMaterial = context.VRM.materialProperties[materialIndex];
|
||||
// Debug.Log($"shaderName: '{vrmMaterial.shader}'");
|
||||
if (vrmMaterial.shader == "VRM/MToon")
|
||||
|
|
@ -192,10 +191,9 @@ namespace VRM.Samples
|
|||
public void MeshCopyTest()
|
||||
{
|
||||
var path = AliciaPath;
|
||||
var parser = new IGltfData();
|
||||
parser.ParseGlb(File.ReadAllBytes(path));
|
||||
var data = new GlbFileParser(path).Parse();
|
||||
|
||||
using (var context = new VRMImporterContext(parser))
|
||||
using (var context = new VRMImporterContext(data))
|
||||
using (var loaded = context.Load())
|
||||
{
|
||||
loaded.ShowMeshes();
|
||||
|
|
@ -214,10 +212,9 @@ namespace VRM.Samples
|
|||
{
|
||||
// Aliciaを古いデシリアライザでロードする
|
||||
var path = AliciaPath;
|
||||
var parser = new IGltfData();
|
||||
parser.ParseGlb(File.ReadAllBytes(path));
|
||||
var data = new GlbFileParser(path).Parse();
|
||||
|
||||
using (var context = new VRMImporterContext(parser))
|
||||
using (var context = new VRMImporterContext(data))
|
||||
{
|
||||
var oldJson = context.GLTF.ToJson().ParseAsJson().ToString(" ");
|
||||
|
||||
|
|
|
|||
|
|
@ -44,14 +44,11 @@ namespace VRM.Samples
|
|||
return;
|
||||
}
|
||||
|
||||
var bytes = File.ReadAllBytes(path);
|
||||
// なんらかの方法でByte列を得た
|
||||
|
||||
// GLB形式でJSONを取得しParseします
|
||||
var parser = new IGltfData();
|
||||
parser.ParseGlb(bytes);
|
||||
var data = new GlbFileParser(path).Parse();
|
||||
// var data = new GlbBinaryParser(anyBinary).Parse();
|
||||
|
||||
using (var context = new VRMImporterContext(parser))
|
||||
using (var context = new VRMImporterContext(data))
|
||||
{
|
||||
|
||||
// metaを取得(todo: thumbnailテクスチャのロード)
|
||||
|
|
|
|||
|
|
@ -83,14 +83,11 @@ namespace VRM.Samples
|
|||
return;
|
||||
}
|
||||
|
||||
var bytes = File.ReadAllBytes(path);
|
||||
// なんらかの方法でByte列を得た
|
||||
|
||||
// GLB形式でJSONを取得しParseします
|
||||
var parser = new IGltfData();
|
||||
parser.Parse(path, bytes);
|
||||
var data = new GlbFileParser(path).Parse();
|
||||
// var data = new GlbBinaryParser(anyBinary).Parse();
|
||||
|
||||
using (var context = new VRMImporterContext(parser))
|
||||
using (var context = new VRMImporterContext(data))
|
||||
{
|
||||
// metaを取得(todo: thumbnailテクスチャのロード)
|
||||
var meta = await context.ReadMetaAsync();
|
||||
|
|
@ -128,14 +125,11 @@ namespace VRM.Samples
|
|||
return;
|
||||
}
|
||||
|
||||
var bytes = File.ReadAllBytes(path);
|
||||
// なんらかの方法でByte列を得た
|
||||
|
||||
// GLB形式でJSONを取得しParseします
|
||||
var parser = new IGltfData();
|
||||
parser.ParseGlb(bytes);
|
||||
var data = new GlbFileParser(path).Parse();
|
||||
// var data = new GlbBinaryParser(anyBinary).Parse();
|
||||
|
||||
var context = new VRMImporterContext(parser);
|
||||
var context = new VRMImporterContext(data);
|
||||
var loaded = default(RuntimeGltfInstance);
|
||||
if (m_loadAsync)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -310,12 +310,9 @@ namespace VRM.Samples
|
|||
{
|
||||
case ".vrm":
|
||||
{
|
||||
var file = File.ReadAllBytes(path);
|
||||
var data = new GlbFileParser(path).Parse();
|
||||
|
||||
var parser = new IGltfData();
|
||||
parser.ParseGlb(file);
|
||||
|
||||
using (var context = new VRMImporterContext(parser))
|
||||
using (var context = new VRMImporterContext(data))
|
||||
{
|
||||
await m_texts.UpdateMetaAsync(context);
|
||||
var loaded = await context.LoadAsync();
|
||||
|
|
@ -328,11 +325,9 @@ namespace VRM.Samples
|
|||
|
||||
case ".glb":
|
||||
{
|
||||
var file = File.ReadAllBytes(path);
|
||||
var parser = new IGltfData();
|
||||
parser.ParseGlb(file);
|
||||
var data = new GlbFileParser(path).Parse();
|
||||
|
||||
var context = new UniGLTF.ImporterContext(parser);
|
||||
var context = new UniGLTF.ImporterContext(data);
|
||||
var loaded = context.Load();
|
||||
loaded.EnableUpdateWhenOffscreen();
|
||||
loaded.ShowMeshes();
|
||||
|
|
@ -341,12 +336,21 @@ namespace VRM.Samples
|
|||
}
|
||||
|
||||
case ".gltf":
|
||||
{
|
||||
var data = new GltfFileWithResourceFilesParser(path).Parse();
|
||||
|
||||
var context = new UniGLTF.ImporterContext(data);
|
||||
var loaded = context.Load();
|
||||
loaded.EnableUpdateWhenOffscreen();
|
||||
loaded.ShowMeshes();
|
||||
SetModel(loaded.gameObject);
|
||||
break;
|
||||
}
|
||||
case ".zip":
|
||||
{
|
||||
var parser = new IGltfData();
|
||||
parser.ParsePath(path);
|
||||
var data = new ZipArchivedGltfFileParser(path).Parse();
|
||||
|
||||
var context = new UniGLTF.ImporterContext(parser);
|
||||
var context = new UniGLTF.ImporterContext(data);
|
||||
var loaded = context.Load();
|
||||
loaded.EnableUpdateWhenOffscreen();
|
||||
loaded.ShowMeshes();
|
||||
|
|
|
|||
|
|
@ -45,10 +45,9 @@ namespace VRM
|
|||
static void ImportRuntime(string path)
|
||||
{
|
||||
// load into scene
|
||||
var parser = new IGltfData();
|
||||
parser.ParsePath(path);
|
||||
var data = new GlbFileParser(path).Parse();
|
||||
|
||||
using (var context = new VRMImporterContext(parser))
|
||||
using (var context = new VRMImporterContext(data))
|
||||
{
|
||||
var loaded = context.Load();
|
||||
loaded.EnableUpdateWhenOffscreen();
|
||||
|
|
@ -67,8 +66,7 @@ namespace VRM
|
|||
|
||||
// import as asset
|
||||
// var prefabPath = UnityPath.FromUnityPath(prefabPath);
|
||||
var parser = new IGltfData();
|
||||
parser.ParseGlb(File.ReadAllBytes(path));
|
||||
var data = new GlbFileParser(path).Parse();
|
||||
|
||||
Action<IEnumerable<UnityPath>> onCompleted = texturePaths =>
|
||||
{
|
||||
|
|
@ -80,7 +78,7 @@ namespace VRM
|
|||
.Where(x => x != null)
|
||||
.ToDictionary(x => new SubAssetKey(x), x => x as Object);
|
||||
|
||||
using (var context = new VRMImporterContext(parser, map))
|
||||
using (var context = new VRMImporterContext(data, map))
|
||||
{
|
||||
var editor = new VRMEditorImporterContext(context, prefabPath);
|
||||
foreach (var textureInfo in editor.TextureDescriptorGenerator.Get().GetEnumerable())
|
||||
|
|
@ -92,7 +90,7 @@ namespace VRM
|
|||
}
|
||||
};
|
||||
|
||||
using (var context = new VRMImporterContext(parser))
|
||||
using (var context = new VRMImporterContext(data))
|
||||
{
|
||||
var editor = new VRMEditorImporterContext(context, prefabPath);
|
||||
editor.ConvertAndExtractImages(onCompleted);
|
||||
|
|
|
|||
|
|
@ -45,8 +45,7 @@ namespace VRM
|
|||
throw new Exception();
|
||||
}
|
||||
|
||||
var parser = new IGltfData();
|
||||
parser.ParseGlb(File.ReadAllBytes(vrmPath.FullPath));
|
||||
var data = new GlbFileParser(vrmPath.FullPath).Parse();
|
||||
|
||||
var prefabPath = vrmPath.Parent.Child(vrmPath.FileNameWithoutExtension + ".prefab");
|
||||
|
||||
|
|
@ -56,7 +55,7 @@ namespace VRM
|
|||
.Select(x => x.LoadAsset<Texture>())
|
||||
.ToDictionary(x => new SubAssetKey(x), x => x as UnityEngine.Object);
|
||||
|
||||
using (var context = new VRMImporterContext(parser, map))
|
||||
using (var context = new VRMImporterContext(data, map))
|
||||
{
|
||||
var editor = new VRMEditorImporterContext(context, prefabPath);
|
||||
foreach (var textureInfo in context.TextureDescriptorGenerator.Get().GetEnumerable())
|
||||
|
|
@ -69,7 +68,7 @@ namespace VRM
|
|||
};
|
||||
|
||||
// extract texture images
|
||||
using (var context = new VRMImporterContext(parser))
|
||||
using (var context = new VRMImporterContext(data))
|
||||
{
|
||||
var editor = new VRMEditorImporterContext(context, prefabPath);
|
||||
editor.ConvertAndExtractImages(onCompleted);
|
||||
|
|
|
|||
|
|
@ -46,13 +46,12 @@ namespace VRM
|
|||
return;
|
||||
}
|
||||
|
||||
var parser = new IGltfData();
|
||||
parser.ParsePath(path);
|
||||
var data = new GlbFileParser(path).Parse();
|
||||
|
||||
var importer = new VRMImporterContext(data, null);
|
||||
|
||||
var importer = new VRMImporterContext(parser, null);
|
||||
|
||||
Assert.AreEqual(73, parser.GLTF.materials.Count);
|
||||
Assert.True(VRMMToonMaterialImporter.TryCreateParam(parser, importer.VRM, 0, out MaterialDescriptor matDesc));
|
||||
Assert.AreEqual(73, data.GLTF.materials.Count);
|
||||
Assert.True(VRMMToonMaterialImporter.TryCreateParam(data, importer.VRM, 0, out MaterialDescriptor matDesc));
|
||||
}
|
||||
|
||||
static string AliciaPath
|
||||
|
|
@ -67,10 +66,10 @@ namespace VRM
|
|||
[Test]
|
||||
public void MaterialImporterTest()
|
||||
{
|
||||
var parser = new IGltfData();
|
||||
parser.ParsePath(AliciaPath);
|
||||
var vrmImporter = new VRMImporterContext(parser, null);
|
||||
var materialParam = new VRMMaterialDescriptorGenerator(vrmImporter.VRM).Get(parser, 0);
|
||||
var path = AliciaPath;
|
||||
var data = new GlbFileParser(path).Parse();
|
||||
var vrmImporter = new VRMImporterContext(data, null);
|
||||
var materialParam = new VRMMaterialDescriptorGenerator(vrmImporter.VRM).Get(data, 0);
|
||||
Assert.AreEqual("VRM/MToon", materialParam.ShaderName);
|
||||
Assert.AreEqual("Alicia_body", materialParam.TextureSlots["_MainTex"].UnityObjectName);
|
||||
|
||||
|
|
|
|||
|
|
@ -51,16 +51,16 @@ namespace VRM
|
|||
|
||||
static GameObject Load(FileInfo gltf, DirectoryInfo root, byte[] bytes = null)
|
||||
{
|
||||
var parser = new IGltfData();
|
||||
IGltfData data = null;
|
||||
try
|
||||
{
|
||||
if (bytes != null)
|
||||
{
|
||||
parser.Parse(gltf.FullName, bytes);
|
||||
data = new GlbLowLevelParser(gltf.FullName, bytes).Parse();
|
||||
}
|
||||
else
|
||||
{
|
||||
parser.ParsePath(gltf.FullName);
|
||||
data = new GlbFileParser(gltf.FullName).Parse();
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
|
@ -72,7 +72,7 @@ namespace VRM
|
|||
|
||||
try
|
||||
{
|
||||
using (var importer = new VRMImporterContext(parser))
|
||||
using (var importer = new VRMImporterContext(data))
|
||||
{
|
||||
return importer.Load().gameObject;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,10 +20,9 @@ namespace VRM
|
|||
[Test]
|
||||
public void VRMLookAtTest()
|
||||
{
|
||||
var parser = new IGltfData();
|
||||
parser.ParsePath(AliciaPath);
|
||||
var data = new GlbFileParser(AliciaPath).Parse();
|
||||
byte[] bytes = default;
|
||||
using (var loader = new VRMImporterContext(parser))
|
||||
using (var loader = new VRMImporterContext(data))
|
||||
using (var loaded = loader.Load())
|
||||
{
|
||||
loaded.ShowMeshes();
|
||||
|
|
@ -38,9 +37,8 @@ namespace VRM
|
|||
});
|
||||
}
|
||||
|
||||
var parser2 = new IGltfData();
|
||||
parser2.Parse(AliciaPath, bytes);
|
||||
using (var loader2 = new VRMImporterContext(parser2))
|
||||
var data2 = new GlbLowLevelParser(AliciaPath, bytes).Parse();
|
||||
using (var loader2 = new VRMImporterContext(data2))
|
||||
{
|
||||
Assert.AreEqual(LookAtType.BlendShape, loader2.VRM.firstPerson.lookAtType);
|
||||
}
|
||||
|
|
@ -49,11 +47,10 @@ namespace VRM
|
|||
[Test]
|
||||
public void VRMLookAtCurveMapWithFreezeTest()
|
||||
{
|
||||
var parser = new IGltfData();
|
||||
parser.ParsePath(AliciaPath);
|
||||
var data = new GlbFileParser(AliciaPath).Parse();
|
||||
byte[] bytes = default;
|
||||
CurveMapper horizontalInner = default;
|
||||
using (var loader = new VRMImporterContext(parser))
|
||||
using (var loader = new VRMImporterContext(data))
|
||||
using (var loaded = loader.Load())
|
||||
{
|
||||
loaded.ShowMeshes();
|
||||
|
|
@ -68,9 +65,8 @@ namespace VRM
|
|||
});
|
||||
}
|
||||
|
||||
var parser2 = new IGltfData();
|
||||
parser2.Parse(AliciaPath, bytes);
|
||||
using (var loader = new VRMImporterContext(parser2))
|
||||
var data2 = new GlbLowLevelParser(AliciaPath, bytes).Parse();
|
||||
using (var loader = new VRMImporterContext(data2))
|
||||
using (var loaded = loader.Load())
|
||||
{
|
||||
loaded.ShowMeshes();
|
||||
|
|
@ -84,11 +80,10 @@ namespace VRM
|
|||
[Test]
|
||||
public void VRMLookAtCurveMapTest()
|
||||
{
|
||||
var parser = new IGltfData();
|
||||
parser.ParsePath(AliciaPath);
|
||||
var data = new GlbFileParser(AliciaPath).Parse();
|
||||
byte[] bytes = default;
|
||||
CurveMapper horizontalInner = default;
|
||||
using (var loader = new VRMImporterContext(parser))
|
||||
using (var loader = new VRMImporterContext(data))
|
||||
using (var loaded = loader.Load())
|
||||
{
|
||||
loaded.ShowMeshes();
|
||||
|
|
@ -103,9 +98,8 @@ namespace VRM
|
|||
});
|
||||
}
|
||||
|
||||
var parser2 = new IGltfData();
|
||||
parser2.Parse(AliciaPath, bytes);
|
||||
using (var loader = new VRMImporterContext(parser2))
|
||||
var data2 = new GlbLowLevelParser(AliciaPath, bytes).Parse();
|
||||
using (var loader = new VRMImporterContext(data2))
|
||||
using (var loaded = loader.Load())
|
||||
{
|
||||
loaded.ShowMeshes();
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
using System.Collections.Generic;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using NUnit.Framework;
|
||||
using UniGLTF;
|
||||
|
|
@ -16,42 +17,49 @@ namespace VRM
|
|||
public void TextureEnumerationTest()
|
||||
{
|
||||
{
|
||||
var parser = new IGltfData
|
||||
{
|
||||
GLTF = new glTF
|
||||
var data = IGltfData.CreateFromGltfData(
|
||||
new glTF
|
||||
{
|
||||
images = new List<glTFImage>
|
||||
{
|
||||
new glTFImage{
|
||||
new glTFImage
|
||||
{
|
||||
mimeType = "image/png",
|
||||
}
|
||||
},
|
||||
textures = new List<glTFTexture>
|
||||
{
|
||||
new glTFTexture{
|
||||
new glTFTexture
|
||||
{
|
||||
name = "texture0",
|
||||
source = 0,
|
||||
}
|
||||
},
|
||||
materials = new List<glTFMaterial>
|
||||
{
|
||||
new glTFMaterial{
|
||||
pbrMetallicRoughness = new glTFPbrMetallicRoughness{
|
||||
baseColorTexture = new glTFMaterialBaseColorTextureInfo{
|
||||
new glTFMaterial
|
||||
{
|
||||
pbrMetallicRoughness = new glTFPbrMetallicRoughness
|
||||
{
|
||||
baseColorTexture = new glTFMaterialBaseColorTextureInfo
|
||||
{
|
||||
index = 0,
|
||||
}
|
||||
}
|
||||
},
|
||||
new glTFMaterial{
|
||||
pbrMetallicRoughness = new glTFPbrMetallicRoughness{
|
||||
baseColorTexture = new glTFMaterialBaseColorTextureInfo{
|
||||
new glTFMaterial
|
||||
{
|
||||
pbrMetallicRoughness = new glTFPbrMetallicRoughness
|
||||
{
|
||||
baseColorTexture = new glTFMaterialBaseColorTextureInfo
|
||||
{
|
||||
index = 0,
|
||||
}
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
};
|
||||
);
|
||||
var vrm = new glTF_VRM_extensions
|
||||
{
|
||||
materialProperties = new List<glTF_VRM_Material>
|
||||
|
|
@ -72,7 +80,7 @@ namespace VRM
|
|||
},
|
||||
}
|
||||
};
|
||||
var items = new VrmTextureDescriptorGenerator(parser, vrm).Get().GetEnumerable().ToArray();
|
||||
var items = new VrmTextureDescriptorGenerator(data, vrm).Get().GetEnumerable().ToArray();
|
||||
Assert.AreEqual(1, items.Length);
|
||||
}
|
||||
}
|
||||
|
|
@ -80,35 +88,39 @@ namespace VRM
|
|||
[Test]
|
||||
public void TextureEnumerationInUnknownShader()
|
||||
{
|
||||
var parser = new IGltfData
|
||||
{
|
||||
GLTF = new glTF
|
||||
var data = IGltfData.CreateFromGltfData(
|
||||
new glTF
|
||||
{
|
||||
images = new List<glTFImage>
|
||||
{
|
||||
new glTFImage
|
||||
{
|
||||
new glTFImage{
|
||||
mimeType = "image/png",
|
||||
}
|
||||
},
|
||||
textures = new List<glTFTexture>
|
||||
{
|
||||
new glTFTexture{
|
||||
name = "texture0",
|
||||
source = 0,
|
||||
}
|
||||
},
|
||||
materials = new List<glTFMaterial>
|
||||
{
|
||||
new glTFMaterial{
|
||||
pbrMetallicRoughness = new glTFPbrMetallicRoughness{
|
||||
baseColorTexture = new glTFMaterialBaseColorTextureInfo{
|
||||
index = 0,
|
||||
}
|
||||
}
|
||||
},
|
||||
mimeType = "image/png",
|
||||
}
|
||||
},
|
||||
textures = new List<glTFTexture>
|
||||
{
|
||||
new glTFTexture
|
||||
{
|
||||
name = "texture0",
|
||||
source = 0,
|
||||
}
|
||||
},
|
||||
materials = new List<glTFMaterial>
|
||||
{
|
||||
new glTFMaterial
|
||||
{
|
||||
pbrMetallicRoughness = new glTFPbrMetallicRoughness
|
||||
{
|
||||
baseColorTexture = new glTFMaterialBaseColorTextureInfo
|
||||
{
|
||||
index = 0,
|
||||
}
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
};
|
||||
);
|
||||
var vrm = new glTF_VRM_extensions
|
||||
{
|
||||
materialProperties = new List<glTF_VRM_Material>
|
||||
|
|
@ -125,10 +137,10 @@ namespace VRM
|
|||
};
|
||||
|
||||
// 2系統ある?
|
||||
Assert.IsTrue(VRMMToonMaterialImporter.TryCreateParam(parser, vrm, 0, out VRMShaders.MaterialDescriptor matDesc));
|
||||
Assert.IsTrue(VRMMToonMaterialImporter.TryCreateParam(data, vrm, 0, out VRMShaders.MaterialDescriptor matDesc));
|
||||
Assert.AreEqual(1, matDesc.TextureSlots.Count);
|
||||
|
||||
var items = new VrmTextureDescriptorGenerator(parser, vrm).Get().GetEnumerable().ToArray();
|
||||
var items = new VrmTextureDescriptorGenerator(data, vrm).Get().GetEnumerable().ToArray();
|
||||
Assert.AreEqual(1, items.Length);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,10 +21,9 @@ namespace VRM
|
|||
|
||||
static GameObject Load(byte[] bytes, string path)
|
||||
{
|
||||
var parser = new IGltfData();
|
||||
parser.Parse(path, bytes);
|
||||
var data = new GlbLowLevelParser(path, bytes).Parse();
|
||||
|
||||
using (var loader = new VRMImporterContext(parser))
|
||||
using (var loader = new VRMImporterContext(data))
|
||||
{
|
||||
var loaded = loader.Load();
|
||||
loaded.ShowMeshes();
|
||||
|
|
|
|||
|
|
@ -325,11 +325,9 @@ namespace UniVRM10.Samples
|
|||
|
||||
case ".glb":
|
||||
{
|
||||
var file = File.ReadAllBytes(path);
|
||||
var parser = new IGltfData();
|
||||
parser.ParseGlb(file);
|
||||
var data = new GlbFileParser(path).Parse();
|
||||
|
||||
using (var loader = new UniGLTF.ImporterContext(parser))
|
||||
using (var loader = new UniGLTF.ImporterContext(data))
|
||||
{
|
||||
var loaded = loader.Load();
|
||||
loaded.ShowMeshes();
|
||||
|
|
@ -340,12 +338,23 @@ namespace UniVRM10.Samples
|
|||
}
|
||||
|
||||
case ".gltf":
|
||||
{
|
||||
var data = new GltfFileWithResourceFilesParser(path).Parse();
|
||||
|
||||
using (var loader = new UniGLTF.ImporterContext(data))
|
||||
{
|
||||
var loaded = loader.Load();
|
||||
loaded.ShowMeshes();
|
||||
loaded.EnableUpdateWhenOffscreen();
|
||||
SetModel(loaded.gameObject);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case ".zip":
|
||||
{
|
||||
var parser = new IGltfData();
|
||||
parser.ParsePath(path);
|
||||
var data = new ZipArchivedGltfFileParser(path).Parse();
|
||||
|
||||
using (var loader = new UniGLTF.ImporterContext(parser))
|
||||
using (var loader = new UniGLTF.ImporterContext(data))
|
||||
{
|
||||
var loaded = loader.Load();
|
||||
loaded.ShowMeshes();
|
||||
|
|
|
|||
|
|
@ -47,12 +47,11 @@ namespace UniVRM10
|
|||
// Parse(parse glb, parser gltf json)
|
||||
//
|
||||
{
|
||||
var parser = new IGltfData();
|
||||
parser.Parse(path, bytes);
|
||||
if (UniGLTF.Extensions.VRMC_vrm.GltfDeserializer.TryGet(parser.GLTF.extensions, out UniGLTF.Extensions.VRMC_vrm.VRMC_vrm vrm))
|
||||
var data = new GlbLowLevelParser(path, bytes).Parse();
|
||||
if (UniGLTF.Extensions.VRMC_vrm.GltfDeserializer.TryGet(data.GLTF.extensions, out UniGLTF.Extensions.VRMC_vrm.VRMC_vrm vrm))
|
||||
{
|
||||
// success
|
||||
result = new Result(parser, vrm, Vrm10FileType.Vrm1, "vrm1: loaded");
|
||||
result = new Result(data, vrm, Vrm10FileType.Vrm1, "vrm1: loaded");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
@ -103,12 +102,11 @@ namespace UniVRM10
|
|||
}
|
||||
|
||||
{
|
||||
var parser = new IGltfData();
|
||||
parser.Parse(path, migrated);
|
||||
if (UniGLTF.Extensions.VRMC_vrm.GltfDeserializer.TryGet(parser.GLTF.extensions, out VRMC_vrm vrm))
|
||||
var data = new GlbLowLevelParser(path, migrated).Parse();
|
||||
if (UniGLTF.Extensions.VRMC_vrm.GltfDeserializer.TryGet(data.GLTF.extensions, out VRMC_vrm vrm))
|
||||
{
|
||||
// success
|
||||
result = new Result(parser, vrm, Vrm10FileType.Vrm0, "vrm0: migrated");
|
||||
result = new Result(data, vrm, Vrm10FileType.Vrm0, "vrm0: migrated");
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -26,13 +26,17 @@ namespace UniVRM10
|
|||
/// </summary>
|
||||
public Vrm10Storage()
|
||||
{
|
||||
m_data = new UniGLTF.IGltfData
|
||||
{
|
||||
GLTF = new UniGLTF.glTF()
|
||||
m_data = new IGltfData(
|
||||
string.Empty,
|
||||
string.Empty,
|
||||
new glTF
|
||||
{
|
||||
extensionsUsed = new List<string>(),
|
||||
}
|
||||
};
|
||||
},
|
||||
new List<GlbChunk>(),
|
||||
new SimpleStorage(new ArraySegment<byte>()),
|
||||
new MigrationFlags()
|
||||
);
|
||||
Buffers = new List<UniGLTF.IBytesBuffer>()
|
||||
{
|
||||
new UniGLTF.ArrayByteBuffer()
|
||||
|
|
|
|||
|
|
@ -13,10 +13,9 @@ namespace UniVRM10.Test
|
|||
{
|
||||
var bytes = MigrationVrm.Migrate(File.ReadAllBytes(path));
|
||||
|
||||
var parser = new IGltfData();
|
||||
parser.Parse("migrated", bytes);
|
||||
var data = new GlbLowLevelParser(path, bytes).Parse();
|
||||
|
||||
var model = ModelReader.Read(parser);
|
||||
var model = ModelReader.Read(data);
|
||||
return model;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -22,10 +22,9 @@ namespace UniVRM10
|
|||
public void MaterialImporterTest()
|
||||
{
|
||||
var migratedBytes = MigrationVrm.Migrate(File.ReadAllBytes(AliciaPath));
|
||||
var parser = new IGltfData();
|
||||
parser.Parse(AliciaPath, migratedBytes);
|
||||
var data = new GlbLowLevelParser(AliciaPath, migratedBytes).Parse();
|
||||
|
||||
var matDesc = new Vrm10MaterialDescriptorGenerator().Get(parser, 0);
|
||||
var matDesc = new Vrm10MaterialDescriptorGenerator().Get(data, 0);
|
||||
Assert.AreEqual("Alicia_body", matDesc.Name);
|
||||
Assert.AreEqual("Hidden/VRM10/vrmc_materials_mtoon", matDesc.ShaderName);
|
||||
Assert.AreEqual("Alicia_body", matDesc.TextureSlots["_MainTex"].UnityObjectName);
|
||||
|
|
|
|||
|
|
@ -202,9 +202,8 @@ namespace UniVRM10
|
|||
try
|
||||
{
|
||||
var migrated = MigrationVrm.Migrate(bytes);
|
||||
var parser = new IGltfData();
|
||||
parser.Parse(gltf.FullName, migrated);
|
||||
UniGLTF.Extensions.VRMC_vrm.GltfDeserializer.TryGet(parser.GLTF.extensions, out UniGLTF.Extensions.VRMC_vrm.VRMC_vrm vrm);
|
||||
var data = new GlbLowLevelParser(gltf.FullName, migrated).Parse();
|
||||
UniGLTF.Extensions.VRMC_vrm.GltfDeserializer.TryGet(data.GLTF.extensions, out UniGLTF.Extensions.VRMC_vrm.VRMC_vrm vrm);
|
||||
Assert.NotNull(vrm);
|
||||
}
|
||||
catch (UnNormalizedException)
|
||||
|
|
@ -224,10 +223,9 @@ namespace UniVRM10
|
|||
// vrm0 のオリジナルの値
|
||||
//
|
||||
var VALUE = new Vector3(-0.0359970331f, -0.0188314915f, 0.00566166639f);
|
||||
var parser0 = new IGltfData();
|
||||
var bytes0 = File.ReadAllBytes(AliciaPath);
|
||||
parser0.Parse(AliciaPath, bytes0);
|
||||
var json0 = parser0.Json.ParseAsJson();
|
||||
var data0 = new GlbLowLevelParser(AliciaPath, bytes0).Parse();
|
||||
var json0 = data0.Json.ParseAsJson();
|
||||
var groupIndex = json0["extensions"]["VRM"]["secondaryAnimation"]["boneGroups"][0]["colliderGroups"][0].GetInt32();
|
||||
var x = json0["extensions"]["VRM"]["secondaryAnimation"]["colliderGroups"][groupIndex]["colliders"][0]["offset"]["x"].GetSingle();
|
||||
var y = json0["extensions"]["VRM"]["secondaryAnimation"]["colliderGroups"][groupIndex]["colliders"][0]["offset"]["y"].GetSingle();
|
||||
|
|
@ -240,9 +238,8 @@ namespace UniVRM10
|
|||
// vrm1 に migrate
|
||||
//
|
||||
var bytes1 = MigrationVrm.Migrate(bytes0);
|
||||
var parser1 = new IGltfData();
|
||||
parser1.Parse(AliciaPath, bytes1);
|
||||
Assert.True(UniGLTF.Extensions.VRMC_springBone.GltfDeserializer.TryGet(parser1.GLTF.extensions, out UniGLTF.Extensions.VRMC_springBone.VRMC_springBone springBone));
|
||||
var data1 = new GlbLowLevelParser(AliciaPath, bytes1).Parse();
|
||||
Assert.True(UniGLTF.Extensions.VRMC_springBone.GltfDeserializer.TryGet(data1.GLTF.extensions, out UniGLTF.Extensions.VRMC_springBone.VRMC_springBone springBone));
|
||||
var spring = springBone.Springs[0];
|
||||
// var colliderNodeIndex = spring.ColliderGroups[0];
|
||||
// x軸だけが反転する
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user