public void UniGLTFSimpleSceneTest() { var go = CreateSimpelScene(); var context = new ImporterContext(); try { // export var gltf = new glTF(); using (var exporter = new gltfExporter(gltf)) { exporter.Prepare(go); exporter.Export(); // import context.ParseJson <glTF>(gltf.ToJson(), new SimpleStorage(new ArraySegment <byte>())); Debug.LogFormat("{0}", context.Json); gltfImporter.Import <glTF>(context); AssertAreEqual(go.transform, context.Root.transform); } } finally { //Debug.LogFormat("Destory, {0}", go.name); GameObject.DestroyImmediate(go); context.Destroy(true); } }
GameObject Load(string path) { var bytes = File.ReadAllBytes(path); Debug.LogFormat("[OnClick] {0}", path); var context = new ImporterContext(); var ext = Path.GetExtension(path).ToLower(); switch (ext) { case ".gltf": context.ParseJson(Encoding.UTF8.GetString(bytes), new FileSystemStorage(Path.GetDirectoryName(path))); break; case ".zip": { var zipArchive = UniGLTF.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); context.ParseJson(json, zipArchive); } break; case ".glb": context.ParseGlb(bytes); break; default: throw new NotImplementedException(); } gltfImporter.Load(context); context.Root.name = Path.GetFileNameWithoutExtension(path); context.ShowMeshes(); return(context.Root); }