From 81b0783035dceb8b4bd4b3698a066b90281ddf93 Mon Sep 17 00:00:00 2001 From: Juan Ignacio Molteni Date: Thu, 7 Mar 2024 15:55:09 -0300 Subject: [PATCH] Added export by files --- .../Editor/ExportLODAssetBundles.cs | 57 ++++++++++++++++++- consumer-server/src/logic/run-conversion.ts | 2 +- 2 files changed, 57 insertions(+), 2 deletions(-) diff --git a/asset-bundle-converter/Assets/AssetBundleConverter/LODsConverter/Editor/ExportLODAssetBundles.cs b/asset-bundle-converter/Assets/AssetBundleConverter/LODsConverter/Editor/ExportLODAssetBundles.cs index fc6df1d7..524ba82b 100644 --- a/asset-bundle-converter/Assets/AssetBundleConverter/LODsConverter/Editor/ExportLODAssetBundles.cs +++ b/asset-bundle-converter/Assets/AssetBundleConverter/LODsConverter/Editor/ExportLODAssetBundles.cs @@ -9,9 +9,11 @@ using Amazon.S3; using Amazon.S3.Model; using AssetBundleConverter.LODsConverter.Utils; +using Cysharp.Threading.Tasks; using DCL.ABConverter; using DCL.Shaders; using UnityEngine.Experimental.Rendering; +using UnityEngine.Networking; using UnityEngine.Rendering; using Object = UnityEngine.Object; using Random = UnityEngine.Random; @@ -23,7 +25,60 @@ public class ExportLODAssetBundles : MonoBehaviour private static readonly string outputPath = Path.Combine(Application.dataPath, "../AssetBundles/"); private static readonly string tempPath = Path.Combine(Application.dataPath, "temp"); - [MenuItem("Assets/Export AMAZON Asset Bundles")] + public static async void ExportURLLODsToAssetBundles() + { + string[] commandLineArgs = Environment.GetCommandLineArgs(); + + string lodsURL = ""; + string customOutputDirectory = ""; + + if (Utils.ParseOption(commandLineArgs, Config.LODS_URL, 1, out string[] lodsURLArg)) + lodsURL = lodsURLArg[0].ToLower(); + + if (Utils.ParseOption(commandLineArgs, Config.CLI_SET_CUSTOM_OUTPUT_ROOT_PATH, 1, out string[] outputDirectoryArg)) + customOutputDirectory = outputDirectoryArg[0].ToLower(); + else + customOutputDirectory = outputPath; + + string[] downloadedFiles = await DownloadRawLOD(lodsURL); + ExportFilesToAssetBundles(downloadedFiles, customOutputDirectory); + } + + private static async Task DownloadRawLOD(string lodsURL) + { + Directory.CreateDirectory(tempPath); + string[] filesToDownload = lodsURL.Split(","); + string[] downloadedPaths = new string[filesToDownload.Length]; + for (int index = 0; index < filesToDownload.Length; index++) + { + string url = filesToDownload[index]; + using (var webRequest = UnityWebRequest.Get(url)) + { + string fileName = Path.GetFileName(url); + // Modify this path according to your needs + string savePath = Path.Combine(tempPath, fileName); + + // Await the completion of the download + await webRequest.SendWebRequest(); + + if (webRequest.result == UnityWebRequest.Result.Success) + { + // Success, save the downloaded file + File.WriteAllBytes(savePath, webRequest.downloadHandler.data); + Debug.Log($"File downloaded and saved to {savePath}"); + downloadedPaths[index] = savePath; + } + else + { + Debug.LogError($"Error downloading {url}: {webRequest.error}"); + return null; + } + } + } + + return downloadedPaths; + } + public static async void ExportS3LODsToAssetBundles() { string[] commandLineArgs = Environment.GetCommandLineArgs(); diff --git a/consumer-server/src/logic/run-conversion.ts b/consumer-server/src/logic/run-conversion.ts index f87dc916..fd164494 100644 --- a/consumer-server/src/logic/run-conversion.ts +++ b/consumer-server/src/logic/run-conversion.ts @@ -57,7 +57,7 @@ export async function runLodsConversion(logger: ILoggerComponent.ILogger, compon const childArguments: string[] = [ '-projectPath', options.projectPath, '-batchmode', - '-executeMethod', 'DCL.ABConverter.LODClient.ExportS3LODsToAssetBundles', + '-executeMethod', 'DCL.ABConverter.LODClient.ExportURLLODsToAssetBundles', '-sceneCid', options.entityId, '-logFile', options.logFile, '-lods', options.lods.join(','),