/// <summary> /// メタが不要な場合のローダー /// </summary> void LoadVRMClicked_without_meta() { #if UNITY_STANDALONE_WIN var path = FileDialogForWindows.FileDialog("open VRM", ".vrm"); #else var path = Application.dataPath + "/default.vrm"; #endif if (string.IsNullOrEmpty(path)) { return; } #if true var bytes = File.ReadAllBytes(path); // なんらかの方法でByte列を得た var context = new VRMImporterContext(); // GLB形式でJSONを取得しParseします context.ParseGlb(bytes); if (m_loadAsync) { // ローカルファイルシステムからロードします LoadAsync(context); } else { context.Load(); OnLoaded(context); } #else // ParseしたJSONをシーンオブジェクトに変換していく if (m_loadAsync) { // ローカルファイルシステムからロードします VRMImporter.LoadVrmAsync(path, OnLoaded); } else { var root = VRMImporter.LoadFromPath(path); OnLoaded(root); } #endif }
static void ImportMenu() { var path = EditorUtility.OpenFilePanel("open vrm", "", "vrm"); if (string.IsNullOrEmpty(path)) { return; } var ext = Path.GetExtension(path).ToLower(); if (ext != ".vrm") { return; } if (path.StartsWithUnityAssetPath()) { Debug.LogWarning("vrm in AssetFolder is imported automatically"); Selection.activeObject = AssetDatabase.LoadAssetAtPath <GameObject>(path.Replace(".vrm", ".prefab").ToUnityRelativePath()); return; } var root = VRMImporter.LoadFromPath(path); if (!EditorApplication.isPlaying) { // save root as Asset var prefabPath = EditorUtility.SaveFilePanel("save vrm prefab", "Assets", Path.GetFileNameWithoutExtension(path) + ".prefab", "prefab" ); if (!string.IsNullOrEmpty(prefabPath)) { VRMAssetWriter.SaveAsPrefab(root, prefabPath); var prefab = AssetDatabase.LoadAssetAtPath <GameObject>(prefabPath.ToUnityRelativePath()); Selection.activeObject = prefab; } } }
void OnOpenClicked() { var path = FileDialogForWindows.FileDialog("open vrm", "vrm"); if (string.IsNullOrEmpty(path)) { return; } Debug.LogFormat("{0}", path); var go = VRMImporter.LoadFromPath(path); if (go == null) { return; } SetModel(go); }
static void ImportMenu() { var path = EditorUtility.OpenFilePanel("open vrm", "", "vrm"); if (string.IsNullOrEmpty(path)) { return; } if (Application.isPlaying) { // load into scene Selection.activeGameObject = VRMImporter.LoadFromPath(path); } 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 Import(path, UnityPath.FromUnityPath(assetPath)); } }
static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAssets, string[] movedAssets, string[] movedFromAssetPaths) { foreach (string path in importedAssets) { var ext = Path.GetExtension(path).ToLower(); if (ext == ".vrm") { var context = new VRMImporterContext(path); try { VRMImporter.LoadFromPath(context); /* * var prefabPath = String.Format("{0}/{1}.prefab", * Path.GetDirectoryName(path), * Path.GetFileNameWithoutExtension(path)); * * VRMAssetWriter.SaveAsPrefab(context.Root, prefabPath); * * var prefab = AssetDatabase.LoadAssetAtPath<GameObject>(prefabPath.ToUnityRelativePath()); * Selection.activeObject = prefab; */ context.SaveAsAsset(); context.Destroy(false); } catch (Exception ex) { Debug.LogError(ex); if (context != null) { context.Destroy(true); } } } } }