You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在R中将STL文件转换为mesh3d对象以适配Arothron库?

将STL文件转换为mesh3d对象用于Arothron的endomaker函数

方法一:直接转换(推荐)

如果你用rgl包的readSTL读取STL文件,返回的数据可以直接通过as.mesh3d()转成mesh3d对象:

library(rgl)
library(Arothron)

# 读取STL文件(二进制格式,ASCII格式需加ascii=TRUE)
stl_data <- readSTL("your_file_path.stl")

# 转换为mesh3d
mesh_obj <- as.mesh3d(stl_data)

# 确认类型
class(mesh_obj) # 应返回 "mesh3d" "shape3d"

方法二:手动构建mesh3d

如果直接转换有问题,可手动提取顶点和面数据来构建:

library(rgl)
library(Arothron)

stl_data <- readSTL("your_file_path.stl")

# 提取顶点矩阵:每行对应一个顶点的x/y/z坐标
vertices <- t(stl_data$vb[1:3, ])

# 提取面索引:每行对应一个面的三个顶点索引
faces <- t(stl_data$it)

# 构建mesh3d对象
mesh_obj <- mesh3d(vertices = vertices, indices = faces)

验证并使用endomaker

转换完成后,直接将mesh3d对象传入函数即可:

# 替换...为endomaker所需的其他参数
endomaker_result <- endomaker(mesh = mesh_obj, ...)
  • 注意:若STL是ASCII格式,调用readSTL时需指定ascii = TRUE
  • 检查顶点和面数据是否存在缺失,避免索引错误

内容的提问来源于stack exchange,提问作者J A

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.21 02:00:11