Uncaught TypeError: THREE.MTLLoader is not a constructor 2.0

自闭症网瘾萝莉.ら 提交于 2019-12-06 11:28:15

The Three.js docs are misleading. Even though the MTLLoader is in the main documentation, it's actually not part of Three.js's core library. It's included in the examples/ folder of Three.js.

If you're using ES6 module syntax, you have two options.

Option 1: NPM

Usually people publish things like this to NPM because the creators of Threejs don't use modern JS development practices. In this case, there is a three-mtl-loader npm package package.

npm install --save three-mtl-loader

and then

import MTLLoader from 'three-mtl-loader';

Option 2: Copy MTLLoader from Three's source.

You can copy the MTLLoader.js file into your project, but it's not good practice to copy third party libraries into your local project if you're using modern ES6 modules.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!