three.js加载3D模型疯狂报错Cannot read property 'elements' of undefined

Uncaught TypeError: Cannot read property ‘elements’ of undefined
就是这个疯狂的报错导致很多元素都没有加载进来噢!!

原因:
由于来自npm的“three-mtl-loader”使用旧的THREE版本并且其TextureLoader在加载后不会添加矩阵参数,因此生成此警告消息
Uncaught TypeError: Cannot read property ‘elements’ of undefined
“Uncaught TypeError:无法读取未定义的属性’元素’”。(哭泣!!我的obj文件没问题呀)

解决方法:
解决方案是要求维护者更新模块的package.json。

临时解决方案(划重点!!!):
node_modules/.1.0.2@three-mtl-loader目录
运行npm install three @ latest --save来更新它。

https://github.com/mrdoob/three.js/issues/12644

参考答案:@eastpiger commented on Dec 12, 2017
Hi @maurocolella , I figured out my problem and it might work for you.

This warning message “Uncaught TypeError: Cannot read property ‘elements’ of undefined” is produced because of the “three-mtl-loader” from npm uses a old THREE version and its TextureLoader won’t add matrix parameter after loading.

The solution is ask the maintainer of this package update it’s package.json. Temporary solution is enter node_modules/.1.0.2@three-mtl-loader and run npm install three@latest --save to update it.

你可能感兴趣的:(js)