From 0c794440557fe9b0625233d94be51d8f5d7a8078 Mon Sep 17 00:00:00 2001 From: Andy Baker Date: Tue, 3 Dec 2024 13:01:47 +0000 Subject: [PATCH] Fixes for upload/publish when not all file formats are created --- .../AssetsServiceClient.cs | 56 ++++++++++++------- 1 file changed, 37 insertions(+), 19 deletions(-) diff --git a/Assets/Scripts/api_clients/assets_service_client/AssetsServiceClient.cs b/Assets/Scripts/api_clients/assets_service_client/AssetsServiceClient.cs index ebb79463..dff6a1b1 100644 --- a/Assets/Scripts/api_clients/assets_service_client/AssetsServiceClient.cs +++ b/Assets/Scripts/api_clients/assets_service_client/AssetsServiceClient.cs @@ -64,19 +64,29 @@ public void Setup(AssetsServiceClient assetsServiceClient, string assetId, HashS public void BackgroundWork() { - saveData.GLTFfiles.root.multipartBytes = assetsServiceClient.MultiPartContent(saveData.GLTFfiles.root.fileName, - saveData.GLTFfiles.root.mimeType, saveData.GLTFfiles.root.bytes); - foreach (FormatDataFile file in saveData.GLTFfiles.resources) + if (saveData.GLTFfiles != null) { - file.multipartBytes = assetsServiceClient.MultiPartContent(file.fileName, file.mimeType, file.bytes); + saveData.GLTFfiles.root.multipartBytes = assetsServiceClient.MultiPartContent(saveData.GLTFfiles.root.fileName, + saveData.GLTFfiles.root.mimeType, saveData.GLTFfiles.root.bytes); + foreach (FormatDataFile file in saveData.GLTFfiles.resources) + { + file.multipartBytes = assetsServiceClient.MultiPartContent(file.fileName, file.mimeType, file.bytes); + } + } + if (saveData.objFile != null) + { + objMultiPartBytes = assetsServiceClient.MultiPartContent(ExportUtils.OBJ_FILENAME, "text/plain", saveData.objFile); + triangulatedObjMultiPartBytes = assetsServiceClient.MultiPartContent(ExportUtils.TRIANGULATED_OBJ_FILENAME, + "text/plain", saveData.triangulatedObjFile); + mtlMultiPartBytes = assetsServiceClient.MultiPartContent(ExportUtils.MTL_FILENAME, "text/plain", saveData.mtlFile); + } + if (saveData.fbxFile != null) + { + fbxMultiPartBytes = assetsServiceClient.MultiPartContent(ExportUtils.FBX_FILENAME, "application/octet-stream", + saveData.fbxFile); } - objMultiPartBytes = assetsServiceClient.MultiPartContent(ExportUtils.OBJ_FILENAME, "text/plain", saveData.objFile); - triangulatedObjMultiPartBytes = assetsServiceClient.MultiPartContent(ExportUtils.TRIANGULATED_OBJ_FILENAME, - "text/plain", saveData.triangulatedObjFile); - mtlMultiPartBytes = assetsServiceClient.MultiPartContent(ExportUtils.MTL_FILENAME, "text/plain", saveData.mtlFile); - fbxMultiPartBytes = assetsServiceClient.MultiPartContent(ExportUtils.FBX_FILENAME, "application/octet-stream", - saveData.fbxFile); + // Blocks format MUST be present blocksMultiPartBytes = assetsServiceClient.MultiPartContent(ExportUtils.BLOCKS_FILENAME, "application/octet-stream", saveData.blocksFile); thumbnailMultiPartBytes = assetsServiceClient.MultiPartContent(ExportUtils.THUMBNAIL_FILENAME, "image/png", @@ -674,16 +684,24 @@ private IEnumerator UploadResources(byte[] objFile, byte[] triangulatedObjFile, byte[] mtlFile, FormatSaveData gltfData, byte[] fbxFile, byte[] blocksFile, byte[] thumbnailFile, bool saveSelected) { - yield return StartCoroutine(AddResource(ExportUtils.OBJ_FILENAME, "text/plain", objFile, "obj")); - yield return StartCoroutine(AddResource(ExportUtils.TRIANGULATED_OBJ_FILENAME, "text/plain", triangulatedObjFile, "triangulated-obj")); - yield return StartCoroutine(AddResource(ExportUtils.MTL_FILENAME, "text/plain", mtlFile, "mtl")); - yield return StartCoroutine(AddResource(ExportUtils.FBX_FILENAME, "application/octet-stream", fbxFile, "fbx")); - yield return StartCoroutine(AddResource(gltfData.root.fileName, gltfData.root.mimeType, gltfData.root.multipartBytes, gltfData.root.tag)); - - for (int i = 0; i < gltfData.resources.Count; i++) + if (objFile != null) { - FormatDataFile file = gltfData.resources[i]; - yield return StartCoroutine(AddResource(file.fileName, file.mimeType, file.multipartBytes, file.tag + i)); + yield return StartCoroutine(AddResource(ExportUtils.OBJ_FILENAME, "text/plain", objFile, "obj")); + yield return StartCoroutine(AddResource(ExportUtils.TRIANGULATED_OBJ_FILENAME, "text/plain", triangulatedObjFile, "triangulated-obj")); + yield return StartCoroutine(AddResource(ExportUtils.MTL_FILENAME, "text/plain", mtlFile, "mtl")); + } + if (fbxFile != null) + { + yield return StartCoroutine(AddResource(ExportUtils.FBX_FILENAME, "application/octet-stream", fbxFile, "fbx")); + } + if (gltfData != null) + { + yield return StartCoroutine(AddResource(gltfData.root.fileName, gltfData.root.mimeType, gltfData.root.multipartBytes, gltfData.root.tag)); + for (int i = 0; i < gltfData.resources.Count; i++) + { + FormatDataFile file = gltfData.resources[i]; + yield return StartCoroutine(AddResource(file.fileName, file.mimeType, file.multipartBytes, file.tag + i)); + } } yield return StartCoroutine(AddResource(ExportUtils.BLOCKS_FILENAME, "application/octet-stream", blocksFile, "blocks"));