我在通过对象加载器加载 Threejs 模型时遇到问题,我添加了最新的 ThreeJs 库版本以获得更多功能,例如创建文本,使用对象加载器......这是我的代码:
loadThreeJs() {
const loader = new THREEE.ObjectLoader();
loader.load('./assets/MVP-TW-CCTV TOWER.json', (obj) => {
console.log(obj)
var object3DInside = obj.children[0].children[0];
console.log(object3DInside)
setTimeout(() => {this.addScene(object3DInside)},1000)
}, (xhr) => {
console.log((xhr.loaded / xhr.total * 100) + '% loaded');
});
}
addScene(obj:any)
{
this.viewer.impl.createOverlayScene('load-scene');
this.viewer.impl.addOverlay('load-scene', obj );
this.viewer.impl.invalidate(true);
}
其中三个是我从外部加载的 Threejs 库。obj
是场景所以我得到object3D的孩子,但它总是返回object not an instance of THREE.Object3D.
我记录的结果和类型是object3D,它应该是正确的,但它不是吗?
It looks like you're using another version of three.js and referencing it globally, which is not delivered by Forge Viewer itself, and it will conflict with Forge Viewer one. As Petr mentioned here (upgrade three js version in autodesk forge viewer), Forge Viewer uses self-maintained three.js r71 removed most of the built-in three.js functions.
如果您想使用 Forge Viewer 的three.js 库中缺少的功能,我建议您使用一些现代开发工具,例如捆绑器(Webpack 是最受欢迎的工具)。您可以利用 ES6 模块并仅将严格需要的依赖项导入您的应用程序。该threejs-全ES6包可以导入three.js所配备到您的应用程序独立,所以在这种情况下,我们可以导入THREEE.ObjectLoader,
和所有其他需要的依赖将包的实现得到照顾。
在此处查看 Forge 社区博客:https : //forge.autodesk.com/blog/how-add-newest-threejs-features-forge-viewer
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句