windows下搭建stp&iges转换成gltf格式环境

前言

传统建模领域,有各种各样的格式文件,相对于three.js来说不一定友好,后者推荐的是gltf格式文件,笔者人为即json+obj资源文件的格式,优点是更小,层次更分明,所以在这个需求基础上,一旦涉及到模型上云,这个转化工具必不可少,而传统行业中,建模工具在windows使用的频次更高,所以,开始吧

准备环境

目前能找到的解决方案
pythonocc ----> stl
gltf-pipeline --> gltf

  1. AnaConda 安装,python3.7 链接
  2. 安装nvm-windows,进行版本管理,这里需要node 12.0.0版本nvm.exe install 12.0.0 nvm.exe use 12.0.0
  3. 安装pythonocc,conda create -n pythonocct -c dlr-sc -c pythonocc pythonocc-core=7.4.0rc1 或者根据github中的 conda install -c conda-forge pythonocc-core=7.4.0,对应的demo 项目地址 demo,校验下是否执行成功cd examples;python core_helloworld.py; 执行之前 pip install pyqt5
  4. https://github.com/MyMiniFactory/stl2gltf
  5. python stl2gltf.py out.stl out.glb -b(压缩后感觉文件有点问题)

转换方法

import os
from OCC.Extend.DataExchange import read_iges_file,read_step_file,write_stl_file

input_file = 'temp2.igs'
output_file = 'out2.stl'
if not os.path.exists(input_file):
    print('Input file need exists')
    exit()

shapes=read_iges_file(input_file)
write_stl_file(shapes, output_file, 'binary', 0.03, 0.5)

import os
from OCC.Extend.DataExchange import read_iges_file,read_step_file,write_stl_file

input_file = 'temp2.stp'
output_file = 'out.stl'
if not os.path.exists(input_file):
    print('Input file need exists')
    exit()

shapes=read_step_file(input_file)
write_stl_file(shapes, output_file, 'binary', 0.03, 0.5)

结尾感言

这个项目是之前接的一个私活,基本上全网找了下没有很合适的躺平办法,包括occ等所谓开源最终也是被人卡着脖子不了了之,最终选择了破解cadexchanger,实现命令行调用,惭愧惭愧

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值