/// <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);
        }
Пример #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);
        }
    }
Пример #3
0
        /// <summary>
        /// Shows the URL selector for loading a model from network.
        /// </summary>
        public void LoadModelFromURLWithDialogValues()
        {
            if (string.IsNullOrWhiteSpace(_modelUrl.text))
            {
                return;
            }
            var request       = AssetDownloader.CreateWebRequest(_modelUrl.text);
            var fileExtension = FileUtils.GetFileExtension(request.uri.Segments[request.uri.Segments.Length - 1], false);

            LoadModelFromURL(request, fileExtension);
        }
Пример #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);
        }