private static Material ExportThenImport(Material src) { // // export // GameObject cube = GameObject.CreatePrimitive(PrimitiveType.Cube); var renderer = cube.GetComponent <Renderer>(); renderer.sharedMaterial = src; var gltf = new glTF(); var exporter = new VCIExporter(gltf); exporter.Prepare(cube); exporter.Export(); var bytes = gltf.ToGlbBytes(); // // importer // var importer = new VCIImporter(); importer.ParseGlb(bytes); importer.Load(); var dst = importer.GetMaterial(0); return(dst); }
private static Material ExportThenImport(Material src) { // // export // var gltf = new glTF(); var exporter = new VCIExporter(gltf); exporter.Materials = new System.Collections.Generic.List <Material> { src }; exporter.Export(); var bytes = gltf.ToGlbBytes(); // // importer // var importer = new VCIImporter(); importer.ParseGlb(bytes); importer.Load(); var dst = importer.GetMaterial(0); return(dst); }
public static void ExportObject() { #if UNITY_STANDALONE_WIN && UNITY_EDITOR EditorApplication.isPlaying = false; if (!Validate()) { return; } try { // save dialog var root = Selection.activeObject as GameObject; var path = VCI.FileDialogForWindows.SaveDialog("Save " + VCIVersion.EXTENSION, root.name + VCIVersion.EXTENSION); //var path = EditorUtility.SaveFilePanel( // "Save " + VCIVersion.EXTENSION, // null, // root.name + VCIVersion.EXTENSION, // VCIVersion.EXTENSION.Substring(1)); if (string.IsNullOrEmpty(path)) { return; } // export var gltf = new glTF(); using (var exporter = new VCIExporter(gltf)) { exporter.Prepare(root); exporter.Export(); } var bytes = gltf.ToGlbBytes(); File.WriteAllBytes(path, bytes); if (path.StartsWithUnityAssetPath()) { AssetDatabase.ImportAsset(path.ToUnityRelativePath()); AssetDatabase.Refresh(); } // Show the file in the explorer. if (VCIConfig.IsOpenDirectoryAfterExport && Application.platform == RuntimePlatform.WindowsEditor) { System.Diagnostics.Process.Start("explorer.exe", " /e,/select," + path.Replace("/", "\\")); } } finally { GUIUtility.ExitGUI(); } #else Debug.LogError("this function works only on Windows"); #endif }
public static void ExportObject() { var errorMessage = ""; if (!Validate(out errorMessage)) { Debug.LogAssertion(errorMessage); EditorUtility.DisplayDialog("Error", errorMessage, "OK"); return; } // save dialog var root = Selection.activeObject as GameObject; var path = EditorUtility.SaveFilePanel( "Save " + VCIVersion.EXTENSION, null, root.name + VCIVersion.EXTENSION, VCIVersion.EXTENSION.Substring(1)); if (string.IsNullOrEmpty(path)) { return; } // export var gltf = new glTF(); using (var exporter = new VCIExporter(gltf)) { exporter.Prepare(root); exporter.Export(); } var bytes = gltf.ToGlbBytes(); File.WriteAllBytes(path, bytes); if (path.StartsWithUnityAssetPath()) { AssetDatabase.ImportAsset(path.ToUnityRelativePath()); AssetDatabase.Refresh(); } // Show the file in the explorer. if (Application.platform == RuntimePlatform.WindowsEditor) { System.Diagnostics.Process.Start("explorer.exe", " /e,/select," + path.Replace("/", "\\")); } }