Skip to content

Commit

Permalink
Experimental support for uploading newglb to Icosa
Browse files Browse the repository at this point in the history
  • Loading branch information
andybak committed Feb 1, 2025
1 parent 4d86561 commit d7c015f
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 19 deletions.
38 changes: 20 additions & 18 deletions Assets/Scripts/Export/Export.cs
Original file line number Diff line number Diff line change
Expand Up @@ -293,27 +293,10 @@ public static void ExportScene()

if (App.PlatformConfig.EnableExportGlb && IsExportEnabled("newglb"))
{
// 'New' GLTF export using UnityGLTF
string extension = "glb";
using (var unused = new AutoTimer("glb export"))
{
OverlayManager.m_Instance.UpdateProgress(0.7f);
var settings = App.Config.m_UnityGLTFSettings;
var context = new ExportContext(settings);

// Beware the two meanings of "layer" in the following code - Unity layers and Open Brush layers

var layerCanvases = App.Scene.LayerCanvases.Select(x => x.transform).ToList();
var layerMask = LayerMask.GetMask("MainCanvas");
if (App.UserConfig.Export.ExportEnvironment)
{
layerCanvases.Add(App.Instance.m_EnvironmentTransform);
layerMask |= LayerMask.GetMask("Environment");
}
context.ExportLayers = layerMask;
var unityGltfexporter = new GLTFSceneExporter(layerCanvases.ToArray(), context);

unityGltfexporter.SaveGLB(Path.Combine(parent, $"newglb"), $"{basename}.{extension}");
ExportNewGlb(Path.Combine(parent, $"newglb"), basename, App.UserConfig.Export.ExportEnvironment);
}
progress.CompleteWork("newglb");
}
Expand All @@ -329,5 +312,24 @@ public static void ExportScene()
File.WriteAllText(readmeFilename, kExportReadmeBody);
}
}

public static void ExportNewGlb(string destinationPath, string fileBaseName, bool exportEnvironment)
{
// 'New' GLTF style export. Exports to GLB format using UnityGLTF
var settings = App.Config.m_UnityGLTFSettings;
var context = new ExportContext(settings);

// Beware the two meanings of "layer" in the following code - Unity layers and Open Brush layers
var layerCanvases = App.Scene.LayerCanvases.Select(x => x.transform).ToList();
var layerMask = LayerMask.GetMask("MainCanvas");
if (exportEnvironment)
{
layerCanvases.Add(App.Instance.m_EnvironmentTransform);
layerMask |= LayerMask.GetMask("Environment");
}
context.ExportLayers = layerMask;
var unityGltfexporter = new GLTFSceneExporter(layerCanvases.ToArray(), context);
unityGltfexporter.SaveGLB(destinationPath, $"{fileBaseName}.glb");
}
}
} // namespace TiltBrush
13 changes: 12 additions & 1 deletion Assets/Scripts/Sharing/VrAssetService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -702,7 +702,18 @@ private async Task CreateZipFileAsync(

// Collect files into a .zip file, including the .tilt file and thumbnail
string zipName = Path.Combine(tempUploadDir, "archive.zip");
var filesToZip = exportResults.exportedFiles.ToList().Append(tempTiltPath).Append(tempThumbnailPath);

var filesToZip = exportResults.exportedFiles.ToList()
.Append(tempTiltPath)
.Append(tempThumbnailPath);

if (App.UserConfig?.Sharing.GenerateNewGlb ?? false)
{
string newGlbPath = Path.Combine(tempUploadDir, $"{uploadName}.glb");
Export.ExportNewGlb(tempUploadDir, uploadName, true);
filesToZip = filesToZip.Append(newGlbPath);
}

await CreateZipFileAsync(zipName, tempUploadDir, filesToZip.ToArray(), token);

var service = new IcosaService(App.Instance.IcosaToken);
Expand Down
1 change: 1 addition & 0 deletions Assets/Scripts/UserConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,7 @@ public struct SharingConfig
{
public string IcosaApiRoot;
public string IcosaHomePage;
[FormerlySerializedAs("ExportNewGlb")] public bool GenerateNewGlb;
}
public SharingConfig Sharing;

Expand Down

0 comments on commit d7c015f

Please sign in to comment.