mirror of
https://github.com/vrm-c/UniVRM.git
synced 2026-06-02 22:14:30 -05:00
parent
8ab360c0bd
commit
5d3c66513c
|
|
@ -741,6 +741,42 @@ namespace UniGLTF
|
|||
}
|
||||
}
|
||||
|
||||
//
|
||||
// https://github.com/vrm-c/UniVRM/pull/2413
|
||||
//
|
||||
[Test]
|
||||
public void ExportingMeshByteLengthTest()
|
||||
{
|
||||
var validator = ScriptableObject.CreateInstance<MeshExportValidator>();
|
||||
var root = new GameObject("root");
|
||||
try
|
||||
{
|
||||
{
|
||||
var child = TestGltf.CreatePrimitiveAsBuiltInRP(PrimitiveType.Cube);
|
||||
child.transform.SetParent(root.transform);
|
||||
}
|
||||
// export
|
||||
var data = TestGltf.ExportAsBuiltInRP(root);
|
||||
var gltf = data.Gltf;
|
||||
// cube
|
||||
var expected =
|
||||
// pos
|
||||
(4*3)*24
|
||||
// normal
|
||||
+(4*3)*24
|
||||
// uv
|
||||
+(4*2)*24
|
||||
// indices
|
||||
+ 4 * 36;
|
||||
Assert.AreEqual(expected, gltf.buffers[0].byteLength);
|
||||
}
|
||||
finally
|
||||
{
|
||||
GameObject.DestroyImmediate(root);
|
||||
ScriptableObject.DestroyImmediate(validator);
|
||||
}
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
class CantConstruct
|
||||
{
|
||||
|
|
|
|||
8
Assets/VRM10/Runtime/IO/Material/URP/Export.meta
Normal file
8
Assets/VRM10/Runtime/IO/Material/URP/Export.meta
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: a6506c50290f7fb48984c1c5e83929e4
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
using UniGLTF;
|
||||
using UnityEngine;
|
||||
|
||||
namespace UniVRM10
|
||||
{
|
||||
public class UrpVrm10MaterialExporter : IMaterialExporter
|
||||
{
|
||||
public glTFMaterial ExportMaterial(Material m, ITextureExporter textureExporter, GltfExportSettings settings)
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
return new glTFMaterial{
|
||||
name = "dummyForTest",
|
||||
};
|
||||
#else
|
||||
throw new System.NotImplementedException();
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 95b7c97505db9d747b04136aa1505204
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -8,7 +8,7 @@ namespace UniVRM10
|
|||
{
|
||||
return RenderPipelineUtility.GetRenderPipelineType() switch
|
||||
{
|
||||
RenderPipelineTypes.UniversalRenderPipeline => throw new System.NotImplementedException(),
|
||||
RenderPipelineTypes.UniversalRenderPipeline => new UrpVrm10MaterialExporter(),
|
||||
RenderPipelineTypes.BuiltinRenderPipeline => new BuiltInVrm10MaterialExporter(),
|
||||
_ => new BuiltInVrm10MaterialExporter(),
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,5 +1,8 @@
|
|||
using System.IO;
|
||||
using System.Linq;
|
||||
using NUnit.Framework;
|
||||
using UniGLTF;
|
||||
using UnityEngine;
|
||||
|
||||
namespace UniVRM10.Test
|
||||
{
|
||||
|
|
@ -25,5 +28,109 @@ namespace UniVRM10.Test
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
static string ModelPath
|
||||
{
|
||||
get
|
||||
{
|
||||
// submodule
|
||||
return Path.GetFullPath(Application.dataPath + "/../vrm-specification/samples/Seed-san/vrm/Seed-san.vrm")
|
||||
.Replace("\\", "/");
|
||||
}
|
||||
}
|
||||
|
||||
static int getByteLength(glTF gltf, int accessorIndex)
|
||||
{
|
||||
if (accessorIndex < 0) { return 0; }
|
||||
var accessor = gltf.accessors[accessorIndex];
|
||||
return accessor.CalcByteSize();
|
||||
}
|
||||
|
||||
static int getByteLength(glTF gltf, glTFPrimitives prim)
|
||||
{
|
||||
var l = 0;
|
||||
l += getByteLength(gltf, prim.indices);
|
||||
l += getByteLength(gltf, prim.attributes.POSITION);
|
||||
l += getByteLength(gltf, prim.attributes.NORMAL);
|
||||
l += getByteLength(gltf, prim.attributes.TANGENT);
|
||||
l += getByteLength(gltf, prim.attributes.TEXCOORD_0);
|
||||
l += getByteLength(gltf, prim.attributes.JOINTS_0);
|
||||
l += getByteLength(gltf, prim.attributes.WEIGHTS_0);
|
||||
foreach (var morph in prim.targets)
|
||||
{
|
||||
l += getByteLength(gltf, morph.POSITION);
|
||||
l += getByteLength(gltf, morph.NORMAL);
|
||||
l += getByteLength(gltf, morph.TANGENT);
|
||||
}
|
||||
return l;
|
||||
}
|
||||
|
||||
static int getByteLength(glTF gltf, glTFMesh mesh)
|
||||
{
|
||||
var l = 0;
|
||||
foreach (var prim in mesh.primitives)
|
||||
{
|
||||
l += getByteLength(gltf, prim);
|
||||
}
|
||||
return l;
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void NoTexture()
|
||||
{
|
||||
if (!File.Exists(ModelPath))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// load model
|
||||
var task = Vrm10.LoadPathAsync(ModelPath, awaitCaller: new ImmediateCaller());
|
||||
var instance = task.Result;
|
||||
|
||||
// remove textures
|
||||
instance.Vrm.Meta.Thumbnail = null;
|
||||
var m = new Material(Shader.Find("Unlit/Color"));
|
||||
foreach (var r in instance.GetComponentsInChildren<Renderer>())
|
||||
{
|
||||
r.sharedMaterials = r.sharedMaterials.Select(x => m).ToArray();
|
||||
}
|
||||
|
||||
// export as vrm1
|
||||
using (var arrayManager = new NativeArrayManager())
|
||||
{
|
||||
var converter = new UniVRM10.ModelExporter();
|
||||
var model = converter.Export(arrayManager, instance.gameObject);
|
||||
|
||||
// 右手系に変換
|
||||
Debug.Log($"convert to right handed coordinate...");
|
||||
model.ConvertCoordinate(VrmLib.Coordinates.Vrm1, ignoreVrm: false);
|
||||
|
||||
// export vrm-1.0
|
||||
var exporter = new Vrm10Exporter(new GltfExportSettings());
|
||||
exporter.Export(instance.gameObject, model, converter, new VrmLib.ExportArgs
|
||||
{
|
||||
sparse = false,
|
||||
});
|
||||
|
||||
var gltf = exporter.Storage.Gltf;
|
||||
|
||||
var last = gltf.bufferViews.Last();
|
||||
// https://github.com/vrm-c/UniVRM/pull/2413
|
||||
Assert.AreEqual(last.byteOffset + last.byteLength, exporter.Storage.Gltf.buffers[0].byteLength);
|
||||
|
||||
// check byteLength
|
||||
var expected = 0;
|
||||
foreach (var mesh in gltf.meshes)
|
||||
{
|
||||
expected += getByteLength(gltf, mesh);
|
||||
}
|
||||
foreach (var skin in gltf.skins)
|
||||
{
|
||||
expected += getByteLength(gltf, skin.inverseBindMatrices);
|
||||
}
|
||||
// alighment ?
|
||||
// Assert.AreEqual(expected, exporter.Storage.Gltf.buffers[0].byteLength);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user