1. 首页
  2. three.js

three.js为什么材料是未定义的3.OBJLoader?

three.jsn你好,n我不明白为什么Javascript显示错误:n类型错误:物体材料在>n中未定义,我想它是数组,但不是。你能帮我吗?n整个函数体:n(有趣的是,纹理正在加载到对象上,它通常看起来很好)nfunction loadObj(objPath, mtlPath) = = = = true;console.log( \”Object loaded.\” );},function( xhr ){console.log( ( Math.round( xhr.loaded / xhr.total, 2 ) * 100 ) + \”% loaded\” );},function( error ){console.log( \”error:\” + error.message );});});return loader;n由OBJLoader返回的对象类型为THREE.Group,没有属性material。将此对象视为容器,而不是将OBJ文件中定义的多个对象(网格、线或点)分组。所以在这个地方执行>是无效的。Mugen87:n所以在这个地方执行>是无效的n那么如何才能获得我加载的这个对象并访问材质、纹理等呢。?n谢谢,nA.n嗯,您在第一篇文章中已经有了必要的代码。只需像这样遍历容器对象:nobject.traverse( function( child ) {if ( child instanceof THREE.Mesh )> Mugen87:nUm, you already have the necessary code in your first post. Just traverse through the container object like so:nThank you, but I mean I want to invoke:nOn the end of the function, to be sure that it is updated. How can I achieve this? Without invoke .traverse() again… Which is not fast function, I suppose.nAnd I completely not understand this. Please, let\”s see the documentation:nhttps://threejs.org/docs/#api/en/core/Object3D.traverse 3).traverse ( callback : Function ) : nullncallback – A function with as first argument an object3D object.nExecutes the callback on this object and all descendants.n.traverse() is an Object3D method, yes? Like in docs. So why:nfirst argument an object3D object.nit has same type (Object3D) as argument and in this method I can:nExecutes the callback on this object and all descendants.nI can have acces to .material?nIf in the first argument it is Object3D, so why can\”t I do it on this object \”above\” traverse.nWhat is wrong with my reasoning? (Exluding lack of experience.) arrowman:nOn the end of the function, to be sure that it is updated. How can I achieve this?nYou have to do put this line of code inside the if语句更新纹理后。不是在onLoad()回调结束时。像这样尝试:nif ( child instanceof THREE.Mesh> Mugen87:nYou have to do put this line of code inside the if更新纹理后的语句。不是在onLoad()回调结束时,然后在load()回调结束时更新材料映射?n这是一个非常开始的项目,我想我会在以后处理这个对象。两个星期以来,我不想搜索为什么某些东西没有更新。n文档中有关于它如何工作的描述吗?n或者它正在等待循环结束(新的渲染函数调用),在我为needsUpdate属性指定“true”值的地方没有任何区别?对?n Why material is undefined in THREE.OBJLoader?n

three.js为什么材料是未定义的3.OBJLoader? 为WP2原创文章,链接:https://www.wp2.cn/three-js/three-js%e4%b8%ba%e4%bb%80%e4%b9%88%e6%9d%90%e6%96%99%e6%98%af%e6%9c%aa%e5%ae%9a%e4%b9%89%e7%9a%843-objloader%ef%bc%9f/