(Three.js) 使用加载器加载 stl 文件后如何从 STL 文件中获取索引?
我有一个问题, 我想从 Three.js 的 STLLoader 中获取 stl 文件的顶点和索引。 我可以获取顶点,但是无法获取索引...
我尝试过,
console.log(STLgeometry)
但索引属性为空...
是否有机会获取索引..?
我尝试了 for 循环,
//arr = devided vertices array in 3 elements
// ex) arr =[[x1,y1,z1],[x2,y2,z2]...,]
//but there are same elements ex) [[x1,y1,z1],..,[x1,y1,z1]]
// so i remove same elements and that called "node" array
//if node's element and arr's elment is same, take that index and push it to "indices" array.
//but it takes so much time..... if vertices array is too big.
for (let i = 0; i < arr.length; i++) {
for (let j = 0; j < node.length; j++) {
if (String(arr[i]) === String(node[j])) {
indices.push(j);
}
}
}
我真的需要你的帮助。
i have a question,
i want to get vertices and indices from stl file from STLLoader of Three.js.
i can get vertices but, i can't get indices...
i tried
console.log(STLgeometry)
but the index attribute is null....
is there any chance to get indices..?
and i tried for loop
//arr = devided vertices array in 3 elements
// ex) arr =[[x1,y1,z1],[x2,y2,z2]...,]
//but there are same elements ex) [[x1,y1,z1],..,[x1,y1,z1]]
// so i remove same elements and that called "node" array
//if node's element and arr's elment is same, take that index and push it to "indices" array.
//but it takes so much time..... if vertices array is too big.
for (let i = 0; i < arr.length; i++) {
for (let j = 0; j < node.length; j++) {
if (String(arr[i]) === String(node[j])) {
indices.push(j);
}
}
}
i really need your help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
STL 没有顶点索引的概念。这意味着 STL 文件中的三角形不共享顶点。因此,
THREE.STLLoader
返回一个非索引几何图形。尝试使用实用函数 BufferGeometryUtils.mergeVertices()。它将通过合并相等的顶点数据返回一个新的索引几何体。
STL has no concept of vertex indices. Meaning the triangles in an STL file do not share vertices. Hence,
THREE.STLLoader
returns an non-indexed geometry.Try to use the utility function BufferGeometryUtils.mergeVertices(). It will return a new indexed geometry by merging equal vertex data.