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 byte[] ExportVci(GameObject root) { // export var gltf = new glTF(); using (var exporter = new VCIExporter(gltf)) { exporter.Prepare(root); exporter.Export(default);
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("/", "\\")); } }
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);
private void ExportSceneLighting(VCIExporter exporter, glTF gltf) { var lightmapTextureExporter = new LightmapTextureExporter(TextureExporter, gltf); var existsLightmappedMesh = false; for (var i = 0; i < exporter.Nodes.Count; i++) { var node = exporter.Nodes[i]; var gltfNode = gltf.nodes[i]; var renderer = node.GetComponent <MeshRenderer>(); if (renderer != null) { var useLightmapExtension = false; #if UNITY_EDITOR var contributeGi = UnityEditor.GameObjectUtility.GetStaticEditorFlags(node.gameObject) .HasFlag(UnityEditor.StaticEditorFlags.ContributeGI); var receiveLightmap = renderer.receiveGI == ReceiveGI.Lightmaps; var isLightmapExistsInScene = LightmapSettings.lightmaps != null && LightmapSettings.lightmaps.Length > 0; useLightmapExtension = contributeGi && receiveLightmap && isLightmapExistsInScene; #endif if (useLightmapExtension) { var originalRenderer = _originalNodes[i].GetComponent <MeshRenderer>(); var lightmapUnityIndex = originalRenderer.lightmapIndex; if (lightmapUnityIndex < 0 || lightmapUnityIndex >= LightmapSettings.lightmaps.Length) { continue; } var lightmapGltfIndex = lightmapTextureExporter.GetOrAddColorTexture(lightmapUnityIndex); if (lightmapGltfIndex >= 0) { var so = originalRenderer.lightmapScaleOffset; var scale = new Vector2(so.x, so.y); var offset = new Vector2(so.z, so.w); offset.y = (offset.y + scale.y - 1) * -1.0f; var VCAST_vci_lightmap = new glTF_VCAST_vci_lightmap { lightmap = new glTF_VCAST_vci_Lightmap { texture = new glTFLightmapTextureInfo { index = lightmapGltfIndex }, offset = new[] { offset.x, offset.y }, scale = new[] { scale.x, scale.y }, }, }; var f = new UniJSON.JsonFormatter(); glTF_VCAST_vci_lightmap_Serializer.Serialize(f, VCAST_vci_lightmap); glTFExtensionExport.GetOrCreate(ref gltfNode.extensions).Add(glTF_VCAST_vci_lightmap.ExtensionName, f.GetStore().Bytes); existsLightmappedMesh = true; } } } } var enableLocationLightingExtension = existsLightmappedMesh; if (enableLocationLightingExtension) { var cubemapExporter = new CubemapTextureExporter(TextureExporter, glTF); var skyboxExporter = new SkyboxExporter(cubemapExporter); var lightProbeExporter = new LightProbeExporter(); var VCAST_vci_location_lighting = new glTF_VCAST_vci_location_lighting { locationLighting = new glTF_VCAST_vci_LocationLighting { lightmapCompressionMode = glTF_VCAST_vci_LocationLighting.ConvertLightmapCompressionMode(lightmapTextureExporter .CompressionType), lightmapDirectionalMode = glTF_VCAST_vci_LocationLighting.ConvertLightmapDirectionalMode(lightmapTextureExporter .DirectionalType), lightmapTextures = lightmapTextureExporter.RegisteredColorTextureIndexArray .Select(x => new glTFLightmapTextureInfo { index = x }) .ToArray(), skyboxCubemap = skyboxExporter.Export(1024), lightProbes = lightProbeExporter.Export(), }, }; var f = new UniJSON.JsonFormatter(); glTF_VCAST_vci_location_lighting_Serializer.Serialize(f, VCAST_vci_location_lighting); glTFExtensionExport.GetOrCreate(ref gltf.extensions).Add(glTF_VCAST_vci_location_lighting.ExtensionName, f.GetStore().Bytes); } for (var i = 0; i < exporter.Nodes.Count; i++) { var node = exporter.Nodes[i]; var gltfNode = gltf.nodes[i]; var reflectionProbe = _originalNodes[i].GetComponent <ReflectionProbe>(); if (reflectionProbe == null) { continue; } var exportReflectionProbeExtension = false; var isModeActive = reflectionProbe.mode == ReflectionProbeMode.Baked; var texture = reflectionProbe.bakedTexture; var isTextureExists = texture != null && texture.dimension == TextureDimension.Cube; exportReflectionProbeExtension = !Application.isPlaying && isModeActive && isTextureExists; if (!exportReflectionProbeExtension) { continue; } var reflectionProbeCubemapExporter = new CubemapTextureExporter(TextureExporter, glTF); var offset = reflectionProbe.center; var size = reflectionProbe.size; var VCAST_vci_reflectionProbe = new glTF_VCAST_vci_reflectionProbe { reflectionProbe = new glTF_VCAST_vci_ReflectionProbe { boxOffset = new[] { -offset.x, offset.y, offset.z }, // invert X-axis boxSize = new[] { size.x, size.y, size.z }, intensity = reflectionProbe.intensity, useBoxProjection = reflectionProbe.boxProjection, cubemap = reflectionProbeCubemapExporter.Export(texture, reflectionProbe.resolution, includeMipmaps: true), }, }; var f = new UniJSON.JsonFormatter(); glTF_VCAST_vci_reflectionProbe_Serializer.Serialize(f, VCAST_vci_reflectionProbe); glTFExtensionExport.GetOrCreate(ref gltfNode.extensions).Add(glTF_VCAST_vci_reflectionProbe.ExtensionName, f.GetStore().Bytes); } }