解决threejs加载gltf文件报错 No DRACOLoader

2023-12-08 17:04

本文主要是介绍解决threejs加载gltf文件报错 No DRACOLoader,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

解决threejs加载gltf文件报错 No DRACOLoader

错误描述

Error: THREE.GLTFLoader: No DRACOLoader instance provided.at new GLTFDracoMeshCompressionExtension (GLTFLoader.js:1669:10)at GLTFLoader.parse (GLTFLoader.js:321:37)at Object.eval [as onLoad] (GLTFLoader.js:159:11)at eval (three.module.js:41910:38)

解决, 使用 DRACOLoader 加载

  • 封装 DRACOLoader 加载器 dracoLoader.js
import { GLTFLoader } from 'three/examples/jsm/loaders/GLTFLoader.js';
import { DRACOLoader } from 'three/examples/jsm/loaders/DRACOLoader';
import { MessageBox, Message } from 'element-ui';
import Vue from 'vue';let loading;
// 加载gtlf文件
export function dracoLoader(path) {loading = Vue.prototype.$loading({lock: true,text: 'Loading',spinner: 'el-icon-loading',background: 'rgba(0, 0, 0, 0.7)',});return new Promise((resolve) => {const loader = new GLTFLoader(new LoadingManager()); const dracoLoader = new DRACOLoader(); ///*设置dracoLoader路径https://www.gstatic.com/draco/versioned/decoders/[version]/https://www.gstatic.com/draco/versioned/decoders/1.5.6/版本号来自 ★ 非常重要 https://github.com/google/draco/tree/master*/dracoLoader.setDecoderPath('https://www.gstatic.com/draco/versioned/decoders/1.5.6/'); dracoLoader.setDecoderConfig({ type: 'js' }); //使用js方式解压dracoLoader.preload(); //初始化_initDecoder 解码器loader.setDRACOLoader(dracoLoader); //gltfloader使用dracoLoaderloader.load(path,(gltf) => {resolve(gltf);setTimeout(() => {loading.close();}, 500);},() => {},(err) => {console.log(err);Message({message: `加载失败: ${err.message}`,type: 'error',duration: 3000,});setTimeout(() => {loading.close();}, 500);});});
}
  • 使用
import { dracoLoader } from './dracoLoader.js';dracoLoader('/three/model/man.glb').then((res) => {console.log(res.scene)this.scene.add(res.scene);}).catch((err) => {console.log(err);});

这篇关于解决threejs加载gltf文件报错 No DRACOLoader的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/470652

相关文章

Oracle登录时忘记用户名或密码该如何解决

《Oracle登录时忘记用户名或密码该如何解决》:本文主要介绍如何在Oracle12c中忘记用户名和密码时找回或重置用户账户信息,文中通过代码介绍的非常详细,对同样遇到这个问题的同学具有一定的参... 目录一、忘记账户:二、忘记密码:三、详细情况情况 1:1.1. 登录到数据库1.2. 查看当前用户信息1.

springboot3.4和mybatis plus的版本问题的解决

《springboot3.4和mybatisplus的版本问题的解决》本文主要介绍了springboot3.4和mybatisplus的版本问题的解决,主要由于SpringBoot3.4与MyBat... 报错1:spring-boot-starter/3.4.0/spring-boot-starter-

解决java.lang.NullPointerException问题(空指针异常)

《解决java.lang.NullPointerException问题(空指针异常)》本文详细介绍了Java中的NullPointerException异常及其常见原因,包括对象引用为null、数组元... 目录Java.lang.NullPointerException(空指针异常)NullPointer

Android开发中gradle下载缓慢的问题级解决方法

《Android开发中gradle下载缓慢的问题级解决方法》本文介绍了解决Android开发中Gradle下载缓慢问题的几种方法,本文给大家介绍的非常详细,感兴趣的朋友跟随小编一起看看吧... 目录一、网络环境优化二、Gradle版本与配置优化三、其他优化措施针对android开发中Gradle下载缓慢的问

python安装whl包并解决依赖关系的实现

《python安装whl包并解决依赖关系的实现》本文主要介绍了python安装whl包并解决依赖关系的实现,文中通过图文示例介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面... 目录一、什么是whl文件?二、我们为什么需要使用whl文件来安装python库?三、我们应该去哪儿下

MySQL安装时initializing database失败的问题解决

《MySQL安装时initializingdatabase失败的问题解决》本文主要介绍了MySQL安装时initializingdatabase失败的问题解决,文中通过图文介绍的非常详细,对大家的学... 目录问题页面:解决方法:问题页面:解决方法:1.勾选红框中的选项:2.将下图红框中全部改为英

spring-boot-starter-thymeleaf加载外部html文件方式

《spring-boot-starter-thymeleaf加载外部html文件方式》本文介绍了在SpringMVC中使用Thymeleaf模板引擎加载外部HTML文件的方法,以及在SpringBoo... 目录1.Thymeleaf介绍2.springboot使用thymeleaf2.1.引入spring

IDEA编译报错“java: 常量字符串过长”的原因及解决方法

《IDEA编译报错“java:常量字符串过长”的原因及解决方法》今天在开发过程中,由于尝试将一个文件的Base64字符串设置为常量,结果导致IDEA编译的时候出现了如下报错java:常量字符串过长,... 目录一、问题描述二、问题原因2.1 理论角度2.2 源码角度三、解决方案解决方案①:StringBui

mybatis和mybatis-plus设置值为null不起作用问题及解决

《mybatis和mybatis-plus设置值为null不起作用问题及解决》Mybatis-Plus的FieldStrategy主要用于控制新增、更新和查询时对空值的处理策略,通过配置不同的策略类型... 目录MyBATis-plusFieldStrategy作用FieldStrategy类型每种策略的作

Python Jupyter Notebook导包报错问题及解决

《PythonJupyterNotebook导包报错问题及解决》在conda环境中安装包后,JupyterNotebook导入时出现ImportError,可能是由于包版本不对应或版本太高,解决方... 目录问题解决方法重新安装Jupyter NoteBook 更改Kernel总结问题在conda上安装了