unity 使用TriLib插件动态读取外部模型

最近在做动态加载读取外部模型的功能使用了triLib插件,废话不多说直接干货。
第一步下载导入插件,直接分享主打白嫖共享,不搞花里胡哨的。
链接:https://pan.baidu.com/s/1DK474wSrIZ0R6i0EBh5V8A
提取码:tado
导入后第一步新建一个管理渲染管线的文件
在这里插入图片描述
第二步建立一个渲染管线的文件,放入上一个创建的文件中在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
配置完成后新建一个文件夹需要把文件和贴图放在同一文件夹内
在这里插入图片描述
注意添加后缀名称,在这里插入图片描述

然后抄一下demo代码 有兴趣的可以去研究demo 我是为了快速实现就不细讲了

using System.Collections;
using System.Collections.Generic;
using TriLibCore;
using UnityEngine;
using System.IO;


public class GetLoadFbx : MonoBehaviour
{
 

    //文件路径要加载的模型的绝对路径,不能为空
    string modelFilename;
    [Header("模型贴图必须在同级目录,会自动读取原始模型的使用贴图")]
    //文件名称
    public string name;
    public SetUV GetSetUV;//这个可以忽略
    public AssetLoaderOptions options;//这个就是你创建管理渲染的物体
    void Start()
    {
        GetSetUV=GetComponent<SetUV>();
        modelFilename = Application.dataPath + "/GetModel/Model/SAST5000/";
        LoadNameModel(name);
    }

    void LoadNameModel(string name)
    {
       modelFilename += name;
       AssetLoader.LoadModelFromFile(modelFilename, OnLoad, OnMaterialsLoad, OnProgress, OnError, null, options);     
    }

    /// <summary>
    /// Called when any error occurs.
    /// </summary>
    /// <param name="obj">The contextualized error, containing the original exception and the context passed to the method where the error was thrown.</param>
    private void OnError(IContextualizedError obj)
    {
        Debug.LogError($"An error occurred while loading your Model: {obj.GetInnerException()}"); //加载模型时发生错误
    }

    /// <summary>
    /// Called when the Model loading progress changes.
    /// </summary>
    /// <param name="assetLoaderContext">The context used to load the Model.</param>
    /// <param name="progress">The loading progress.</param>
    private void OnProgress(AssetLoaderContext assetLoaderContext, float progress)
    {
        Debug.Log($"Loading Model. Progress: {progress:P}");
    }

    /// <summary>
    /// Called when the Model (including Textures and Materials) has been fully loaded.
    /// </summary>
    /// <remarks>The loaded GameObject is available on the assetLoaderContext.RootGameObject field.</remarks>
    /// <param name="assetLoaderContext">The context used to load the Model.</param>材料加载。模型完全加载
    private void OnMaterialsLoad(AssetLoaderContext assetLoaderContext)
    {

    }

    /// <summary>
    /// Called when the Model Meshes and hierarchy are loaded.
    /// </summary>
    /// <remarks>The loaded GameObject is available on the assetLoaderContext.RootGameObject field.</remarks>
    /// <param name="assetLoaderContext">The context used to load the Model.</param>模型加载。装材料
    private void OnLoad(AssetLoaderContext assetLoaderContext)
    {
        Debug.Log("Model loaded. Loading materials.");
    }

    void Update() 
    {
    }
  
}

  • 2
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
Unity Trilib2插件是一个用于Unity引擎的三维模型导入和管理工具。它可以帮助开发者在Unity中导入、处理和管理各种三维模型资源。最新版Unity Trilib2插件的主要特点和更新如下: 1. 支持多种模型格式:Unity Trilib2可以导入和处理常见的三维模型格式,包括OBJ、FBX、3DS等。这使得开发者可以方便地导入各种不同格式、来源的三维模型文件。 2. 快速而稳定的导入功能:最新版的Unity Trilib2插件在导入模型时具有更高的性能和稳定性。它可以有效地处理大型模型或高复杂度的场景,同时减少导入时的崩溃和错误情况。 3. 自定义导入设置:Unity Trilib2插件提供了丰富的导入设置选项,允许开发者根据项目需求进行细致的调整。例如,可以选择导入的材质类型、贴图压缩方式、动画导入方式等。 4. 高效的模型数据管理:Unity Trilib2插件可以将导入的模型数据进行组织和管理,使得开发者可以更轻松地在项目中使用。例如,可以在Unity编辑器中预览、修改和配置模型的各种属性和效果。 5. 多种平台的兼容性:最新版的Unity Trilib2插件可以与主流的平台和设备兼容,包括PC、移动设备、虚拟现实设备等。这为开发者提供了更广泛的使用场景和目标用户。 总之,最新版的Unity Trilib2插件通过提供更高的性能、稳定性和灵活性,为开发者在Unity中导入、处理和管理三维模型提供了更好的工具和体验。无论是开发大型项目还是小型应用程序,Unity Trilib2插件都能为开发者提供高效、便捷的三维模型操作功能。
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值