public static void SetValue <T>(this ListTreeNode <JsonValue> node, string key, T value) { var f = new JsonFormatter(); f.Serialize(value); var p = Utf8String.From(key); var bytes = f.GetStoreBytes(); node.SetValue(p, bytes); }
public static void SetValue <T>(this JsonNode node, string key, T value, Action <JsonFormatter, T> serialize) { var f = new JsonFormatter(); serialize(f, value); var p = Utf8String.From(key); var bytes = f.GetStoreBytes(); node.SetValue(p, bytes); }
public void RegisterInterface(Type methods, object self) { if (!methods.IsInterface) { throw new Exception(); } foreach (var mi in methods.GetMethods()) { var call = CreateCall(mi, self); m_map.Add(Utf8String.From(mi.Name), call); } }
public void GlTFToJsonTest() { var gltf = new glTF(); using (var exporter = new gltfExporter(gltf)) { exporter.Prepare(CreateSimpleScene()); exporter.Export(); } var expected = gltf.ToJson().ParseAsJson(); expected.AddKey(Utf8String.From("meshes")); expected.AddValue(default(ArraySegment <byte>), ValueNodeType.Array); expected["meshes"].AddValue(default(ArraySegment <byte>), ValueNodeType.Object); var mesh = expected["meshes"][0]; mesh.AddKey(Utf8String.From("name")); mesh.AddValue(Utf8String.From(JsonString.Quote("test")).Bytes, ValueNodeType.String); mesh.AddKey(Utf8String.From("primitives")); mesh.AddValue(default(ArraySegment <byte>), ValueNodeType.Array); mesh["primitives"].AddValue(default(ArraySegment <byte>), ValueNodeType.Object); var primitive = mesh["primitives"][0]; primitive.AddKey(Utf8String.From("mode")); primitive.AddValue(Utf8String.From("0").Bytes, ValueNodeType.Integer); primitive.AddKey(Utf8String.From("indices")); primitive.AddValue(Utf8String.From("0").Bytes, ValueNodeType.Integer); primitive.AddKey(Utf8String.From("material")); primitive.AddValue(Utf8String.From("0").Bytes, ValueNodeType.Integer); primitive.AddKey(Utf8String.From("attributes")); primitive.AddValue(default(ArraySegment <byte>), ValueNodeType.Object); primitive["attributes"].AddKey(Utf8String.From("POSITION")); primitive["attributes"].AddValue(Utf8String.From("0").Bytes, ValueNodeType.Integer); primitive.AddKey(Utf8String.From("targets")); primitive.AddValue(default(ArraySegment <byte>), ValueNodeType.Array); primitive["targets"].AddValue(default(ArraySegment <byte>), ValueNodeType.Object); primitive["targets"][0].AddKey(Utf8String.From("POSITION")); primitive["targets"][0].AddValue(Utf8String.From("1").Bytes, ValueNodeType.Integer); primitive["targets"].AddValue(default(ArraySegment <byte>), ValueNodeType.Object); primitive["targets"][1].AddKey(Utf8String.From("POSITION")); primitive["targets"][1].AddValue(Utf8String.From("2").Bytes, ValueNodeType.Integer); primitive["targets"][1].AddKey(Utf8String.From("TANGENT")); primitive["targets"][1].AddValue(Utf8String.From("0").Bytes, ValueNodeType.Integer); gltf.meshes.Add(new glTFMesh("test") { primitives = new List <glTFPrimitives> { new glTFPrimitives { indices = 0, attributes = new glTFAttributes { POSITION = 0, TANGENT = -1 // should be removed }, targets = new List <gltfMorphTarget> { new gltfMorphTarget { POSITION = 1, TANGENT = -1 // should be removed }, new gltfMorphTarget { POSITION = 2, TANGENT = 0 } } } } }); var actual = gltf.ToJson().ParseAsJson(); Assert.AreEqual(expected, actual); }
public void ImportExportTest() { var path = AliciaPath; var parser = new GltfParser(); parser.ParseGlb(File.ReadAllBytes(path)); using (var context = new VRMImporterContext(parser)) { context.Load(); context.ShowMeshes(); context.EnableUpdateWhenOffscreen(); var importedJson = JsonParser.Parse(context.Json); importedJson.SetValue("/extensions/VRM/exporterVersion", VRMVersion.VRM_VERSION, (f, x) => f.Value(x)); importedJson.SetValue("/asset/generator", UniGLTF.UniGLTFVersion.UNIGLTF_VERSION, (f, x) => f.Value(x)); importedJson.SetValue("/scene", 0, (f, x) => f.Value(x)); importedJson.SetValue("/materials/*/doubleSided", false, (f, x) => f.Value(x)); //importJson.SetValue("/materials/*/pbrMetallicRoughness/roughnessFactor", 0); //importJson.SetValue("/materials/*/pbrMetallicRoughness/baseColorFactor", new float[] { 1, 1, 1, 1 }); importedJson.SetValue("/accessors/*/normalized", false, (f, x) => f.Value(x)); importedJson.RemoveValue(Utf8String.From("/nodes/*/extras")); /* * importJson.SetValue("/bufferViews/12/byteStride", 4); * importJson.SetValue("/bufferViews/13/byteStride", 4); * importJson.SetValue("/bufferViews/14/byteStride", 4); * importJson.SetValue("/bufferViews/15/byteStride", 4); * importJson.SetValue("/bufferViews/22/byteStride", 4); * importJson.SetValue("/bufferViews/29/byteStride", 4); * importJson.SetValue("/bufferViews/45/byteStride", 4); * importJson.SetValue("/bufferViews/46/byteStride", 4); * importJson.SetValue("/bufferViews/47/byteStride", 4); * importJson.SetValue("/bufferViews/201/byteStride", 4); * importJson.SetValue("/bufferViews/202/byteStride", 4); * importJson.SetValue("/bufferViews/203/byteStride", 4); * importJson.SetValue("/bufferViews/204/byteStride", 4); * importJson.SetValue("/bufferViews/211/byteStride", 4); * importJson.SetValue("/bufferViews/212/byteStride", 4); * importJson.SetValue("/bufferViews/213/byteStride", 4); * importJson.SetValue("/bufferViews/214/byteStride", 4); * importJson.SetValue("/bufferViews/215/byteStride", 4); * importJson.SetValue("/bufferViews/243/byteStride", 4); * importJson.SetValue("/bufferViews/247/byteStride", 64); * importJson.SetValue("/bufferViews/248/byteStride", 64); * importJson.SetValue("/bufferViews/249/byteStride", 64); * importJson.SetValue("/bufferViews/250/byteStride", 64); * importJson.SetValue("/bufferViews/251/byteStride", 64); * importJson.SetValue("/bufferViews/252/byteStride", 64); * importJson.SetValue("/bufferViews/253/byteStride", 64); */ importedJson.RemoveValue(Utf8String.From("/bufferViews/*/byteStride")); var vrm = VRMExporter.Export(UniGLTF.MeshExportSettings.Default, context.Root); // TODO: Check contents in JSON /*var exportJson = */ JsonParser.Parse(vrm.ToJson()); // TODO: Check contents in JSON /*var newExportedJson = */ // JsonParser.Parse(JsonSchema.FromType<glTF>().Serialize(vrm)); /* * foreach (var kv in importJson.Diff(exportJson)) * { * Debug.Log(kv); * } * * Assert.AreEqual(importJson, exportJson); */ } }
public void ImportExportTest() { var path = AliciaPath; var data = new GlbFileParser(path).Parse(); using (var context = new VRMImporterContext(new VRMData(data))) using (var loaded = context.Load()) { loaded.ShowMeshes(); loaded.EnableUpdateWhenOffscreen(); // mesh { foreach (var renderer in loaded.GetComponentsInChildren <Renderer>()) { Mesh mesh = default; if (renderer is MeshRenderer) { var f = renderer.GetComponent <MeshFilter>(); mesh = f.sharedMesh; } else if (renderer is SkinnedMeshRenderer smr) { mesh = smr.sharedMesh; } 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 = data.GLTF.materials.Find(x => x.name == material.name); Assert.AreEqual(gltfMaterial.name, material.name); var materialIndex = data.GLTF.materials.IndexOf(gltfMaterial); var vrmMaterial = context.VRM.materialProperties[materialIndex]; // Debug.Log($"shaderName: '{vrmMaterial.shader}'"); if (vrmMaterial.shader == "VRM/MToon") { // MToon // Debug.Log($"{material.name} is MToon"); foreach (var kv in vrmMaterial.textureProperties) { var texture = material.GetTexture(kv.Key); // Debug.Log($"{kv.Key}: {texture}"); Assert.NotNull(texture); } } else if (glTF_KHR_materials_unlit.IsEnable(gltfMaterial)) { // Unlit // Debug.Log($"{material.name} is unlit"); throw new NotImplementedException(); } else { // PBR // Debug.Log($"{material.name} is PBR"); throw new NotImplementedException(); } } } } // meta { var meta = loaded.GetComponent <VRMMeta>(); } // humanoid { var animator = loaded.GetComponent <Animator>(); } // blendshape { var blendshapeProxy = loaded.GetComponent <VRMBlendShapeProxy>(); for (int i = 0; i < context.VRM.blendShapeMaster.blendShapeGroups.Count; ++i) { var gltfBlendShapeClip = context.VRM.blendShapeMaster.blendShapeGroups[i]; var unityBlendShapeClip = blendshapeProxy.BlendShapeAvatar.Clips[i]; Assert.AreEqual(Enum.Parse(typeof(BlendShapePreset), gltfBlendShapeClip.presetName, true), unityBlendShapeClip.Preset); } } var importedJson = JsonParser.Parse(context.Json); importedJson.SetValue("/extensions/VRM/exporterVersion", VRMVersion.VRM_VERSION, (f, x) => f.Value(x)); importedJson.SetValue("/asset/generator", UniGLTF.UniGLTFVersion.UNIGLTF_VERSION, (f, x) => f.Value(x)); importedJson.SetValue("/scene", 0, (f, x) => f.Value(x)); importedJson.SetValue("/materials/*/doubleSided", false, (f, x) => f.Value(x)); //importJson.SetValue("/materials/*/pbrMetallicRoughness/roughnessFactor", 0); //importJson.SetValue("/materials/*/pbrMetallicRoughness/baseColorFactor", new float[] { 1, 1, 1, 1 }); importedJson.SetValue("/accessors/*/normalized", false, (f, x) => f.Value(x)); importedJson.RemoveValue(Utf8String.From("/nodes/*/extras")); /* * importJson.SetValue("/bufferViews/12/byteStride", 4); * importJson.SetValue("/bufferViews/13/byteStride", 4); * importJson.SetValue("/bufferViews/14/byteStride", 4); * importJson.SetValue("/bufferViews/15/byteStride", 4); * importJson.SetValue("/bufferViews/22/byteStride", 4); * importJson.SetValue("/bufferViews/29/byteStride", 4); * importJson.SetValue("/bufferViews/45/byteStride", 4); * importJson.SetValue("/bufferViews/46/byteStride", 4); * importJson.SetValue("/bufferViews/47/byteStride", 4); * importJson.SetValue("/bufferViews/201/byteStride", 4); * importJson.SetValue("/bufferViews/202/byteStride", 4); * importJson.SetValue("/bufferViews/203/byteStride", 4); * importJson.SetValue("/bufferViews/204/byteStride", 4); * importJson.SetValue("/bufferViews/211/byteStride", 4); * importJson.SetValue("/bufferViews/212/byteStride", 4); * importJson.SetValue("/bufferViews/213/byteStride", 4); * importJson.SetValue("/bufferViews/214/byteStride", 4); * importJson.SetValue("/bufferViews/215/byteStride", 4); * importJson.SetValue("/bufferViews/243/byteStride", 4); * importJson.SetValue("/bufferViews/247/byteStride", 64); * importJson.SetValue("/bufferViews/248/byteStride", 64); * importJson.SetValue("/bufferViews/249/byteStride", 64); * importJson.SetValue("/bufferViews/250/byteStride", 64); * importJson.SetValue("/bufferViews/251/byteStride", 64); * importJson.SetValue("/bufferViews/252/byteStride", 64); * importJson.SetValue("/bufferViews/253/byteStride", 64); */ importedJson.RemoveValue(Utf8String.From("/bufferViews/*/byteStride")); var vrm = VRMExporter.Export(new GltfExportSettings(), loaded.gameObject, new EditorTextureSerializer()); // TODO: Check contents in JSON /*var exportJson = */ JsonParser.Parse(vrm.GLTF.ToJson()); // TODO: Check contents in JSON /*var newExportedJson = */ // JsonParser.Parse(JsonSchema.FromType<glTF>().Serialize(vrm)); /* * foreach (var kv in importJson.Diff(exportJson)) * { * Debug.Log(kv); * } * * Assert.AreEqual(importJson, exportJson); */ } }
public static void Notify <A0, A1, A2, A3, A4, A5>(this IRpc rpc, string method, A0 a0, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5) { rpc.Notify(Utf8String.From(method), a0, a1, a2, a3, a4, a5); }
public static void Notify <A0, A1, A2, A3>(this IRpc rpc, string method, A0 a0, A1 a1, A2 a2, A3 a3) { rpc.Notify(Utf8String.From(method), a0, a1, a2, a3); }
public static void Notify <A0, A1>(this IRpc rpc, string method, A0 a0, A1 a1) { rpc.Notify(Utf8String.From(method), a0, a1); }
public static void Notify(this IRpc rpc, string method) { rpc.Notify(Utf8String.From(method)); }
public static void Request <A0, A1, A2, A3, A4>(this IRpc rpc, string method, A0 a0, A1 a1, A2 a2, A3 a3, A4 a4) { rpc.Request(Utf8String.From(method), a0, a1, a2, a3, a4); }
public static void Request <A0, A1, A2>(this IRpc rpc, string method, A0 a0, A1 a1, A2 a2) { rpc.Request(Utf8String.From(method), a0, a1, a2); }
public static void Request <A0>(this IRpc rpc, string method, A0 a0) { rpc.Request(Utf8String.From(method), a0); }
public static void Request(this IRpc rpc, string method) { rpc.Request(Utf8String.From(method)); }
public void ImportExportTest() { var path = UniGLTF.UnityPath.FromUnityPath("Models/Alicia_vrm-0.40/AliciaSolid_vrm-0.40.vrm"); var context = new VRMImporterContext(); context.ParseGlb(File.ReadAllBytes(path.FullPath)); context.Load(); context.ShowMeshes(); context.EnableUpdateWhenOffscreen(); using (new ActionDisposer(() => { GameObject.DestroyImmediate(context.Root); })) { var importJson = JsonParser.Parse(context.Json); importJson.SetValue("/extensions/VRM/exporterVersion", VRMVersion.VRM_VERSION); importJson.SetValue("/asset/generator", UniGLTF.UniGLTFVersion.UNIGLTF_VERSION); importJson.SetValue("/scene", 0); importJson.SetValue("/materials/*/doubleSided", false); //importJson.SetValue("/materials/*/pbrMetallicRoughness/roughnessFactor", 0); //importJson.SetValue("/materials/*/pbrMetallicRoughness/baseColorFactor", new float[] { 1, 1, 1, 1 }); importJson.SetValue("/accessors/*/normalized", false); importJson.RemoveValue(Utf8String.From("/nodes/*/extras")); /* * importJson.SetValue("/bufferViews/12/byteStride", 4); * importJson.SetValue("/bufferViews/13/byteStride", 4); * importJson.SetValue("/bufferViews/14/byteStride", 4); * importJson.SetValue("/bufferViews/15/byteStride", 4); * importJson.SetValue("/bufferViews/22/byteStride", 4); * importJson.SetValue("/bufferViews/29/byteStride", 4); * importJson.SetValue("/bufferViews/45/byteStride", 4); * importJson.SetValue("/bufferViews/46/byteStride", 4); * importJson.SetValue("/bufferViews/47/byteStride", 4); * importJson.SetValue("/bufferViews/201/byteStride", 4); * importJson.SetValue("/bufferViews/202/byteStride", 4); * importJson.SetValue("/bufferViews/203/byteStride", 4); * importJson.SetValue("/bufferViews/204/byteStride", 4); * importJson.SetValue("/bufferViews/211/byteStride", 4); * importJson.SetValue("/bufferViews/212/byteStride", 4); * importJson.SetValue("/bufferViews/213/byteStride", 4); * importJson.SetValue("/bufferViews/214/byteStride", 4); * importJson.SetValue("/bufferViews/215/byteStride", 4); * importJson.SetValue("/bufferViews/243/byteStride", 4); * importJson.SetValue("/bufferViews/247/byteStride", 64); * importJson.SetValue("/bufferViews/248/byteStride", 64); * importJson.SetValue("/bufferViews/249/byteStride", 64); * importJson.SetValue("/bufferViews/250/byteStride", 64); * importJson.SetValue("/bufferViews/251/byteStride", 64); * importJson.SetValue("/bufferViews/252/byteStride", 64); * importJson.SetValue("/bufferViews/253/byteStride", 64); */ importJson.RemoveValue(Utf8String.From("/bufferViews/*/byteStride")); var vrm = VRMExporter.Export(context.Root); var exportJson = JsonParser.Parse(vrm.ToJson()); /* * foreach (var kv in importJson.Diff(exportJson)) * { * Debug.Log(kv); * } * * Assert.AreEqual(importJson, exportJson); */ } }