(Three.js) 使用加载器加载 stl 文件后如何从 STL 文件中获取索引?

发布于 2025-01-11 17:36:14 字数 787 浏览 1 评论 0原文

我有一个问题, 我想从 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

情仇皆在手 2025-01-18 17:36:14

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文