STEP 转 GLB 教程 — CAD 到 Web 3D 流水线

STEP 转 GLB 是你需要的 Web 3D 流水线
STEP 文件描述精确的数学曲面 — CAD 完美,浏览器灾难。GLB(二进制 glTF 2.0)是事实上的 Web 3D 标准 — 小、快、被 three.js、Babylon.js、model-viewer、Sketchfab 和所有现代浏览器原生支持。STEP 转 GLB 意味着把 B-rep 曲面细分成三角形,连同材质和元数据打包到一个二进制 blob 里。做对了,50 MB 的 STEP 变成 200 ms 加载完的 2 MB GLB。做错了,要么是分面化的烂摊子(太粗),要么是 100 MB 的怪物(太细)。本指南讲 2026 年真正能用的三条转换路径 — OCCT WASM 浏览器内、FreeCAD 脚本导出、Fusion 360 — 加上要紧的细分参数。
细分实际做的是什么
STEP 几何是连续的:圆柱是一个数学方程。GLB 几何是离散的:圆柱是 N 个三角形近似那个方程。细分就是从一个到另一个的转换,由弦偏差(三角形边离真实曲面能偏多远)和角偏差(相邻三角形法线之间的最大角度)参数化。容差越紧,三角形越多,曲面近似越好。OpenCASCADE BRepMesh_IncrementalMesh 算法是开源标准 — FreeCAD、KiCad 的 STEP 导出器、大多数浏览器端 STEP 加载器都用它。如果 STEP 文件包含颜色元数据,材质分配可以传过来(AP214 通过 PRESENTATION_LAYER_ASSIGNMENT 支持每面颜色);AP203 STEP 文件经常丢颜色信息。
每条转换路径处理的事
- OCCT WASM 浏览器内 — occt-import-js 把 OpenCASCADE Technology 编译成 WebAssembly,在客户端跑完整 STEP 加载器、客户端细分、导出 glTF/GLB。~13 MB WASM 负载,现代笔记本上 50 MB STEP 处理时间 ~5 秒。
- FreeCAD 脚本导出 — 打开 .step,跑 Mesh.export(['__doc__.RootObjects'], 'out.glb')。FreeCAD 内部用同一套 OpenCASCADE 网格化,可脚本化批量转换零件库。
- Fusion 360 — File > Export > GLTF (glb)。单零件一键搞定;装配体按层级导出,每个组件作为单独节点。保留每实体外观,GLB 里材质颜色不丢。
- Linear deflection — 弦偏差参数(机械零件典型 0.1mm,珠宝/牙科 0.01mm)。值越小三角形越多。大多数工具默认值对任何可见曲线都是错的粗糙值。
- Angular deflection — 限制相邻三角形法线之间的角度(典型 0.5 弧度 ≈ 28°)。对圆形特征关键 — 1.0 rad 时圆柱看起来像八边形,0.2 rad 才平滑。
- Draco 压缩 — 可选 GLB 压缩,进一步减小体积(通常 5-10 倍)。代价:查看端要 Draco 解码器,three.js GLTFLoader 通过 DRACOLoader 支持,model-viewer 原生支持。
五步把 STEP 转成 GLB
- Open pcbviewer.app — 把 STEP 文件拖到 MakerSuite 3D 的 3D 查看器,确认能干净解析。MakerSuite 渲染得出来,底层 OCCT WASM 加载器导 GLB 也干净。
- 挑细分容差。给视觉 Web 预览(model-viewer、Sketchfab、AR):0.1mm 弦 / 0.5 rad 角度够用。给技术检查(放大验证几何):0.01mm 弦 / 0.2 rad。值越小三角形多 5-10 倍。
- 在 MakerSuite 里点 Export,选 GLB。工具用默认参数跑 OCCT 细分,下载一个 .glb 文件。批量转换或自定义参数,用 FreeCAD 的 Python 控制台跑 Mesh.export()。
- 在 three.js 或 model-viewer 里加载 GLB 验证。检查圆柱上有没有可见的分面(角度容差太松)、丢面(导入时 STEP 修复失败)、错误颜色(没颜色元数据的 AP203 STEP 默认灰色)。
- 需要的话优化 GLB — gltfpack(来自 glTF-Transform)压缩材质、量化坐标、加 meshopt 或 Draco,通常体积减半。带宽受限的查看器嵌入有用。
验证 GLB 跟原始 STEP 视觉一致 — 把两个都拖进 MakerSuite 3D 切换查看,在发查看器嵌入之前抓出细分伪影。
免费试用 MakerSuite 3D为什么 STEP 转 GLB 是 Web 3D 的瓶颈
每个带 '查看 3D' 按钮的产品页、每个 iOS Safari 上的 AR 预览、每个作品集里的 Sketchfab 嵌入都依赖这次转换。浏览器引擎不解析 STEP — WebGL 或 WebGPU 里没有原生 B-rep 加载器。Web 3D 生态在 2016 年统一到 glTF/GLB,CAD 工具花了过去十年追赶。今天转换是已解决问题(OCCT WASM 行、FreeCAD 行、Fusion 360 行),但细分参数没标准化。粗糙默认值把产品搞得像塑料分面化;精细默认值把文件大小炸了。给你的用例挑对容差才是真本事,视觉验证是不可妥协的。
STEP 转 GLB 出现的地方
- 产品配置器 — 电商网站让顾客买之前转一转机械零件 3D 模型
- iOS AR 预览 — model-viewer 给 iOS Safari 用 USDZ、给 Android Chrome 用 GLB,都从同一个 STEP 源生成
- 文档嵌入 — 技术写作展示装配视图在浏览器里,GLB 通过 <model-viewer> 嵌入 HTML
- Three.js 场景 — 工程仿真可视化要 CAD 几何当场景网格,GLB 是加载器友好的格式
- Sketchfab 作品集 — 设计师发作品给客户在浏览器里看,Sketchfab 要求 glTF/GLB 上传
在浏览器里转换,不上传
STEP 文件是 CAD 源文件 — 含尺寸、公差、设计意图。上传到服务器端转换器就把工程 IP 送出本机。MakerSuite 3D 的 STEP 转 GLB 完全在浏览器里通过 OCCT WASM 跑 — 跟 FreeCAD 同样的算法,只是编译给 Web。STEP 文件本地解析、本地细分,GLB 直接下载。不走服务器、不缓存、不让第三方碰你的几何。
常见问题
What's the difference between glTF and GLB?
Same data, different packaging. glTF 2.0 (JSON + separate .bin buffers + texture files) is human-readable and good for development. GLB packs everything into a single binary blob, which is faster to load and easier to ship to a CDN. For web embeds, GLB is almost always the right choice — single HTTP request, no broken texture references. The Khronos Group standardized both in glTF 2.0 (2017), and every modern web 3D library (three.js, Babylon.js, model-viewer, react-three-fiber) supports both interchangeably.
Why does my converted GLB look faceted on cylinders?
Tessellation tolerance was too loose. Most STEP→GLB converters default to a chord deviation of 0.5mm and angular deviation of 1.0 radians (about 57°), which makes cylinders look like octagons or hexagons. Tighten to 0.1mm chord / 0.3 rad angular for visible curves. The tradeoff is triangle count — going from 0.5mm to 0.1mm typically multiplies triangle count by 5-10×. For web embeds where bandwidth matters, a balanced 0.2mm chord / 0.5 rad angular is usually the sweet spot.
Do colors and materials transfer in STEP to GLB conversion?
Sometimes. STEP AP214 supports per-face colors via PRESENTATION_LAYER_ASSIGNMENT, which OCCT can read and pass through to glTF materials. STEP AP203 doesn't support colors at all, so the GLB defaults to a single gray material. If your STEP file came from SolidWorks or Fusion 360, it's almost certainly AP214 with colors. If it came from older tools or was exported from KiCad/Eagle, it's often AP203 without colors. Check by opening the STEP in a viewer that shows materials — if you see colors there, the GLB will have them too.
How big can a STEP file be before browser conversion fails?
OCCT WASM (occt-import-js) handles STEP files up to roughly 100 MB on a modern laptop without issue. Above that, browser memory limits start mattering — Chrome/Edge cap WASM heap around 4 GB but realistic processing tops out at ~500 MB STEP. For larger CAD assemblies, batch-process locally with FreeCAD's Python API or Fusion 360 CLI. The browser path is best for single parts and small assemblies; large multi-part assemblies are better handled offline and the resulting GLB shipped to the browser as a static asset.
Should I use Draco compression on the GLB?
Usually yes for web delivery. Draco geometry compression typically shrinks GLB files 5-10× (a 2 MB GLB becomes 200-400 KB). Three.js GLTFLoader supports Draco via DRACOLoader; @google/model-viewer supports it natively. Cost: a small CPU hit on decode (typically <100 ms) and a Draco decoder library that adds ~150 KB to your bundle. Worth it for any GLB over 500 KB or any GLB shipped to mobile clients. gltf-transform compresses existing GLBs in one command: gltf-transform draco in.glb out.glb.
相关文章
拖入 STEP 文件 — 浏览器里转 GLB,零上传
打开 3D 查看器