scene.add(object) 创建一个“Uncaught TypeError: Cannot read property ‘length’”未定义的”
在我的 javascript 控制台(在 Chrome 中)中,使用我尝试使用基本加载器添加的 collada 对象时出现该错误。它具体来自它的“scene.add( object )”块。其他一切似乎都工作得很好。加载对象的代码如下所示。
var ltable;
var furnLoad = new THREE.ColladaLoader();
function addlt(){
furnLoad.load('../Models/Furniture/foldingLongTable.dae', function(collada){
ltable = collada.scene;
ltable.scale.x=ltable.scale.y=ltable.scale.z=1;
ltable.updateMatrix();
ltable.position.x=ltable.position.z=ltable.position.y=0;
});
scene.add( ltable );
}
该函数在页面初始化期间调用,否则可以正常工作。该页面可以在此处找到(没有此表的版本具有相同的 URL除了结尾处是 4 而不是 3),并且特定对象 此处。
克服此错误的推荐方法是什么?
Getting that error in my javascript console(in Chrome) with a collada object I'm attempting to add with a basic loader. It's specifically coming from the "scene.add( object )" chunk of it. Everything else seems to work just fine. The code for loading the object is as follows
var ltable;
var furnLoad = new THREE.ColladaLoader();
function addlt(){
furnLoad.load('../Models/Furniture/foldingLongTable.dae', function(collada){
ltable = collada.scene;
ltable.scale.x=ltable.scale.y=ltable.scale.z=1;
ltable.updateMatrix();
ltable.position.x=ltable.position.z=ltable.position.y=0;
});
scene.add( ltable );
}
This function is called during the init of a page that, otherwise, works just fine. That page can be found here(version without this table has the same URL except for a 4 instead of a 3 at the end), and the specific object here.
What would be the recommended way to get past this error?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
解决了。 Collada 加载器只是讨厌成为任何功能的一部分,并且在其中时无法工作。因此,解决方法是将它们放在函数之外,并且它们可以正常工作。
RESOLVED. Collada loaders just hate being part of any function and won't work when in them. So the fix is to have them outside of functions and they work just fine.
此问题的答案是由于
scene.add()
的位置位于回调函数之外。它是在回调触发之前被调用的,因此会出现未定义的错误。The answer to this issue is due to the location of the
scene.add()
being outside of the callback function. It is being called before the callback fires, hence the undefined error.