1. 首页
  2. three.js

three.js拉伸几何体失败,出现“计算半径为NaN”

three.jsn大家好,n我是个彻头彻尾的傻瓜,可能在我能走路之前就想跑,但我一直在读@Looee的在线书,并且有点自信n我正试图从文件中的坐标在我的场景中创建框(我不会让你们厌烦为什么…。n我正在使用fetch api读取文件。n我的问题是,如果我使用从文件中读取坐标,我得到n3.BufferGeometry.computeBoundingSphere():计算半径为NaN。“position”属性可能有NaN值。错误。n但是在“fetch”之外使用相同的坐标手动创建长方体可以很好地创建长方体。n它似乎与坐标中的负数有关,因为如果我将文件编辑为只有正坐标,则创建长方体时不会出错(读取)这是我创建框的代码-场景设置的其余部分来自@looee的书,所以我没有包括…:ncreateMeshes() {fetch(\”./boxcoords.txt\”, = JSON.parse(text);for (const bay of json.Bays) = new ExtrudeBufferGeometry(boxShape, = new>nIt probably doesn\”t help that I\”m pretty new to javascript too but I\”d be grateful if someone could point out what I\”m doing wrong.nI\”ve attached the booxcoords text file with a single entry (ignore that it\”s called bay)BoxCoords.txt (216 Bytes)nThanks in advance for any assistance. Solved by prisoner849 in post #7 This works: https://jsfiddle.net/prisoner849/poqbhdjr/ Using of parseFloat() for coordinates helps. boxPoints.push(new THREE.Vector2(parseFloat(coord.x), parseFloat(coord.y)));nSorry guys I clearly don\”t know how to properly post a code snippet!nSelect the code.nUsefromnEDIT:n… now you got it nErm… I didn\”t do anything.nI came back to the page to reply to you and it looked fine. I thought you\”d fixed it for me!nI\”ve got a feeling I\”m going to cause problems… nI can\”t fix it, maybe just a moderator?nSometimes parts of the code are automatically recognized and formatted – artificial intelligence !?nAbout your problem.nI get that message a lot. Then, for example, I have divided by zero somewhere or have taken the square root of a negative number.nCheck all intermediate results with console.log for NaN. hofk:nSometimes parts of the code are automatically recognized and formatted – artificial intelligence !?nNope, I\”ve edited the post^^.nIt seems not possible to triangulate your input data. I get the same error already with ShapeBufferGeometry:https://jsfiddle.net/e20qr7oc/14这项工作:https://jsfiddle.net/prisoner849/poqbhdjr/37使用parseFloat()作为坐标有帮助。nboxPoints.push(new THREE.Vector2(parseFloat(coord.x), parseFloat(coord.y)));n很好。谢谢你的帮助n Extrude geometry fails with “Computed radius is NaN”n

three.js拉伸几何体失败,出现“计算半径为NaN” 为WP2原创文章,链接:https://www.wp2.cn/three-js/three-js%e6%8b%89%e4%bc%b8%e5%87%a0%e4%bd%95%e4%bd%93%e5%a4%b1%e8%b4%a5%ef%bc%8c%e5%87%ba%e7%8e%b0%e8%ae%a1%e7%ae%97%e5%8d%8a%e5%be%84%e4%b8%banan/