obj convert to stl(java)

FileFormat

obj 格式规范:
stl 格式规范:https://docs.fileformat.com/cad/stl/

Main

  1. 导入 aspose,Aspose.3D for Java API是为创建、编辑、操作和保存3D格式而构建的。它使Java应用程序能够与3D文档连接,而无需在计算机上安装任何软件包。
<repositories>
    <repository>
        <id>AsposeJavaAPI</id>
        <name>Aspose Java API</name>
        <url>https://repository.aspose.com/repo/</url>
    </repository>
</repositories>

<dependencies>
	<dependency>
        <groupId>com.aspose</groupId>
        <artifactId>aspose-3d</artifactId>
        <version>22.9</version>
    </dependency>
</dependencies>        
  1. 实现 obj 转换为 stl
Scene s1 = new Scene();
// 导入obj
s1.open("1.obj");
// 导入stl
s1.save("1.stl");
  1. 计算 stl 的面法线
    • aspose 20.7 以上版本新增导入时重新计算法线的选项
StlLoadOptions stlLoadOptions = new StlLoadOptions();
// 20.7 以上版本新增导入时重新计算法线的选项
stlLoadOptions.setRecalculateNormal(true);
s1.open("1.stl", stlLoadOptions);
s1.save("1.stl");

Others

WithOut Files

MemoryStream res_stream = new MemoryStream();
MemoryStream res = new MemoryStream();

// 导入obj
Scene s1 = new Scene();
s1.open(new MemoryStream(Files.readAllBytes(Path.of("1.obj"))));

// 导出 stl 到 stream,并将锚点归0,方便下次导入
StlSaveOptions stlSaveOptions = new StlSaveOptions();
stlSaveOptions.setEncoding(StandardCharsets.UTF_8);
s1.save(res_stream, stlSaveOptions);
res_stream.seek(0,0);

// 导入 stl 并计算法线
StlLoadOptions stlLoadOptions = new StlLoadOptions();
stlLoadOptions.setEncoding(StandardCharsets.UTF_8);
stlLoadOptions.setRecalculateNormal(true);
s1.open(res_stream, stlLoadOptions);

// 导出 stl
s1.save(res, stlSaveOptions);
String resString = new String(res.getBuffer(),0, res.getSize());
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值