/// <summary>
        /// Creates the AssetLoaderOptions instance, configures the Web Request, and downloads the Model.
        /// </summary>
        /// <remarks>
        /// You can create the AssetLoaderOptions by right clicking on the Assets Explorer and selecting "TriLib->Create->AssetLoaderOptions->Pre-Built AssetLoaderOptions".
        /// </remarks>
        private void Start()
        {
            var assetLoaderOptions = AssetLoader.CreateDefaultLoaderOptions();
            var webRequest         = AssetDownloader.CreateWebRequest("https://ricardoreis.net/trilib/demos/sample/TriLibSampleModel.zip");

            AssetDownloader.LoadModelFromUri(webRequest, OnLoad, OnMaterialsLoad, OnProgress, OnError, null, assetLoaderOptions);
        }
Exemplo n.º 2
0
    ///<summary>
    /// Replace the box GameObject by the given fbx model
    ///</summary>
    ///<param name="_object">The Object to update</param>
    ///<param name="_modelPath">The path of the 3D model to load with TriLib</param>
    public async Task ReplaceBox(GameObject _object, string _modelPath)
    {
        isLocked = true;

        Uri filePath = new Uri($"{GameManager.gm.configLoader.GetCacheDir()}/{_object.name}.fbx");

        await DownloadFile(_modelPath, filePath.AbsolutePath);

        AssetLoaderOptions assetLoaderOptions = AssetLoader.CreateDefaultLoaderOptions();

        // BoxCollider added later
        assetLoaderOptions.GenerateColliders = false;
        assetLoaderOptions.ConvexColliders   = false;
        assetLoaderOptions.AlphaMaterialMode = TriLibCore.General.AlphaMaterialMode.None;

        if (File.Exists(filePath.AbsolutePath))
        {
            Debug.Log($"From file: {filePath.AbsolutePath}");
            AssetLoader.LoadModelFromFile(filePath.AbsolutePath, OnLoad, OnMaterialsLoad, OnProgress, OnError,
                                          _object, assetLoaderOptions);
        }
        else
        {
            Debug.Log($"From url: {_modelPath}");
            UnityWebRequest webRequest = AssetDownloader.CreateWebRequest(_modelPath);
            AssetDownloader.LoadModelFromUri(webRequest, OnLoad, OnMaterialsLoad, OnProgress, OnError,
                                             _object, assetLoaderOptions, null, "fbx");
        }
        while (isLocked)
        {
            await Task.Delay(10);
        }
    }
Exemplo n.º 3
0
        /// <summary>Loads a model from a URL.</summary>
        protected void LoadModelFromURL(UnityWebRequest request, string fileExtension, GameObject wrapperGameObject = null, object customData = null, Action <AssetLoaderContext> onMaterialsLoad = null)
        {
            HideModelUrlDialog();
            SetLoading(true);
            OnBeginLoadModel(true);
            fileExtension = fileExtension.ToLowerInvariant();
            var isZipFile = fileExtension == "zip" || fileExtension == ".zip";

            AssetDownloader.LoadModelFromUri(request, OnLoad, onMaterialsLoad ?? OnMaterialsLoad, OnProgress, OnError, wrapperGameObject, AssetLoaderOptions, customData, isZipFile ? null : fileExtension, isZipFile);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Loads the part with the given index from the given area.
        /// </summary>
        /// <param name="partName">The area name to load (hair, eyes, nose or mouth).</param>
        /// <param name="partIndex">The area part index.</param>
        private void LoadPart(string partName, int partIndex)
        {
            var wrapper = GameObject.Find($"{partName}Wrapper");

            if (wrapper == null)
            {
                return;
            }
            var request = AssetDownloader.CreateWebRequest($"{BaseURI}{partName}{partIndex}.zip");

            AssetDownloader.LoadModelFromUri(request, OnLoad, OnMaterialsLoad, OnProgress, OnError, wrapper, AssetLoaderOptions, partIndex, null, true);
        }