Beispiel #1
0
        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);
        }
Beispiel #2
0
        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
        }
Beispiel #3
0
        public static byte[] ExportVci(GameObject root)
        {
            // export
            var gltf = new glTF();

            using (var exporter = new VCIExporter(gltf))
            {
                exporter.Prepare(root);
                exporter.Export(default);
Beispiel #4
0
        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("/", "\\"));
            }
        }
Beispiel #5
0
        private static Material ExportThenImport(Material src)
        {
            //
            // export
            //
            GameObject cube = GameObject.CreatePrimitive(PrimitiveType.Cube);
            GameObject root = new GameObject("root");

            cube.transform.SetParent(root.transform);
            var vciObject = root.AddComponent <VCIObject>();

            vciObject.Meta.author = "AUTHOR";
            vciObject.Meta.title  = "TITLE";
            var renderer = cube.GetComponent <Renderer>();

            renderer.sharedMaterial = src;
            var gltf     = new glTF();
            var exporter = new VCIExporter(gltf);

            exporter.Prepare(root);
            exporter.Export(default);