static void ImportMenu() { var path = EditorUtility.OpenFilePanel("open vrm", "", "vrm"); if (string.IsNullOrEmpty(path)) { return; } if (Application.isPlaying) { // load into scene var parser = new GltfParser(); parser.ParsePath(path); var context = new VRMImporterContext(parser); context.Load(); context.ShowMeshes(); context.EnableUpdateWhenOffscreen(); Selection.activeGameObject = context.Root; } else { if (path.StartsWithUnityAssetPath()) { Debug.LogWarningFormat("disallow import from folder under the Assets"); return; } var assetPath = EditorUtility.SaveFilePanel("save prefab", "Assets", Path.GetFileNameWithoutExtension(path), "prefab"); if (string.IsNullOrEmpty(path)) { return; } if (!assetPath.StartsWithUnityAssetPath()) { Debug.LogWarningFormat("out of asset path: {0}", assetPath); return; } // import as asset var prefabPath = UnityPath.FromUnityPath(assetPath); var parser = new GltfParser(); parser.ParseGlb(File.ReadAllBytes(path)); var context = new VRMImporterContext(parser); var editor = new VRMEditorImporterContext(context); editor.ExtractImages(prefabPath); EditorApplication.delayCall += () => { // // after textures imported // context.Load(); editor.SaveAsAsset(prefabPath); editor.Dispose(); }; } }
static void ImportMenu() { var path = EditorUtility.OpenFilePanel("open vrm", "", "vrm"); if (string.IsNullOrEmpty(path)) { return; } if (Application.isPlaying) { // load into scene var parser = new GltfParser(); parser.ParsePath(path); using (var context = new VRMImporterContext(parser)) { context.Load(); context.EnableUpdateWhenOffscreen(); context.ShowMeshes(); context.DisposeOnGameObjectDestroyed(); Selection.activeGameObject = context.Root; } } else { if (path.StartsWithUnityAssetPath()) { Debug.LogWarningFormat("disallow import from folder under the Assets"); return; } var assetPath = EditorUtility.SaveFilePanel("save prefab", "Assets", Path.GetFileNameWithoutExtension(path), "prefab"); if (string.IsNullOrEmpty(path)) { return; } if (!assetPath.StartsWithUnityAssetPath()) { Debug.LogWarningFormat("out of asset path: {0}", assetPath); return; } // import as asset var prefabPath = UnityPath.FromUnityPath(assetPath); var parser = new GltfParser(); parser.ParseGlb(File.ReadAllBytes(path)); Action <IEnumerable <string> > onCompleted = texturePaths => { // // after textures imported // var map = texturePaths.Select(x => { var texture = AssetDatabase.LoadAssetAtPath(x, typeof(Texture2D)); return(texture.name, texture); }).ToArray();
public static GameObject LoadFromBytes(Byte[] bytes) { var context = new VRMImporterContext(); context.ParseGlb(bytes); context.Load(); context.ShowMeshes(); context.EnableUpdateWhenOffscreen(); return(context.Root); }
public static GameObject LoadFromPath(string path) { var context = new VRMImporterContext(); context.Parse(path, File.ReadAllBytes(path)); context.Load(); context.ShowMeshes(); context.EnableUpdateWhenOffscreen(); return(context.Root); }
static void ImportRuntime(string path) { // load into scene var parser = new GltfParser(); parser.ParsePath(path); using (var context = new VRMImporterContext(parser)) { context.Load(); context.EnableUpdateWhenOffscreen(); context.ShowMeshes(); context.DisposeOnGameObjectDestroyed(); Selection.activeGameObject = context.Root; } }
public void MeshCoyTest() { 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(); foreach (var mesh in context.Meshes) { var src = mesh.Mesh; var dst = src.Copy(true); MeshTests.MeshEquals(src, dst); } }
void LoadModel(string path) { if (!File.Exists(path)) { return; } Debug.LogFormat("{0}", path); var ext = Path.GetExtension(path).ToLower(); switch (ext) { case ".vrm": { var context = new VRMImporterContext(); var file = File.ReadAllBytes(path); context.ParseGlb(file); m_texts.UpdateMeta(context); context.Load(); context.ShowMeshes(); context.EnableUpdateWhenOffscreen(); context.ShowMeshes(); SetModel(context.Root); break; } case ".glb": { var context = new UniGLTF.ImporterContext(); var file = File.ReadAllBytes(path); context.ParseGlb(file); context.Load(); context.ShowMeshes(); context.EnableUpdateWhenOffscreen(); context.ShowMeshes(); SetModel(context.Root); break; } default: Debug.LogWarningFormat("unknown file type: {0}", path); break; } }
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("/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("/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); */ } }
public static void LoadFromBytes(VRMImporterContext context) { context.Load(); context.ShowMeshes(); context.EnableUpdateWhenOffscreen(); }