如何在纹理映射过程后合并两个 .obj 文件? [英] How to merge two .obj files after texture mapping process?

查看:67
本文介绍了如何在纹理映射过程后合并两个 .obj 文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 3D 网格上应用纹理后,会生成三个文件(包括 .obj、.mtl 和 atlas 文件).我已经在 2 个对象上映射了纹理,现在我想将这些对象合并在一起,但我不知道如何合并它们的文件.有什么方法(不是非免费工具)?

After applying texture on 3D mesh, three files (including a .obj, .mtl and an atlas file) are generated. I have mapped textures on 2 objects and now I want to merge these objects together, but I do not know how to merge their files. Is there any method(not non free tool)?

推荐答案

单对象波前 obj 文件的 naive 文件合并相对容易:

The naive file merging for single object wavefront obj files is relatively easy:

  1. 将第一个文件读入内存

记住每个表的条目数

将第二个文件追加到内存中(人脸除外)

将第二个文件的人脸追加到内存中

这是唯一需要稍微改变的东西.所有索引都来自1,因此您需要将前一个文件中每个表的大小添加到其中.例如,如果第一个 obj 有 10 行以 v 开头,这意味着在附加第二个 obj 后,将开始从 11 开始引用它的点.所以取每个顶点索引并添加大小.

This is the only stuff that need to change a bit. All the indexes are from 1 so you need to add the size of each table from previous file to it. For example if first obj got 10 lines starting with v that means after appending the second obj will start referencing its points from 11 instead. so take each vertex index and add the size to it.

同样适用于您获得的任何信息,例如法线、纹理坐标或其他任何信息.

The same goes for any info you got like normals, texture coords or what ever.

将整个内容保存为单个 obj 文件

抱歉,我不使用材料扩展名,所以我不知道格式,也不知道 mtl 文件中是否也需要进行任何更改(但我不这么认为).

Sorry I do not use the material extensions so I do not know the format and if any changes are needed inside mtl file too (but I do not think so).

如果您还想更新网格(移除不可见的相交部分),那么您需要使用一些几何方法(不是微不足道的问题).

If you want to have also the mesh updated (removing the invisible intersected part) then you need to use some geometry approach (not trivial problem).

只是为了确定这里的小例子...

Just to be sure here small example...

文件 1:

v -1.0 -1.0 -1.0 
v +1.0 -1.0 -1.0 
v +1.0 +1.0 -1.0 
v -1.0 +1.0 -1.0 
v -1.0 -1.0 +1.0 
v +1.0 -1.0 +1.0 
v +1.0 +1.0 +1.0 
v -1.0 +1.0 +1.0 

f 1 2 3 4 
f 5 6 7 8 
f 1 2 6 5 
f 2 3 7 6 
f 3 4 8 7 
f 4 1 5 8 

文件 2:

v -1.0 -1.0 +1.0 
v +1.0 -1.0 +1.0 
v +1.0 +1.0 +1.0 
v -1.0 +1.0 +1.0 
v -2.0 -2.0 +2.0 
v +2.0 -2.0 +2.0 
v +2.0 +2.0 +2.0 
v -2.0 +2.0 +2.0 

f 1 2 3 4 
f 5 6 7 8 
f 1 2 6 5 
f 2 3 7 6 
f 3 4 8 7 
f 4 1 5 8 

合并:

v -1.0 -1.0 -1.0 
v +1.0 -1.0 -1.0 
v +1.0 +1.0 -1.0 
v -1.0 +1.0 -1.0 
v -1.0 -1.0 +1.0 
v +1.0 -1.0 +1.0 
v +1.0 +1.0 +1.0 
v -1.0 +1.0 +1.0 

v -1.0 -1.0 +1.0 
v +1.0 -1.0 +1.0 
v +1.0 +1.0 +1.0 
v -1.0 +1.0 +1.0 
v -2.0 -2.0 +2.0 
v +2.0 -2.0 +2.0 
v +2.0 +2.0 +2.0 
v -2.0 +2.0 +2.0 

f 1 2 3 4 
f 5 6 7 8 
f 1 2 6 5 
f 2 3 7 6 
f 3 4 8 7 
f 4 1 5 8 

f  9 10 11 12 
f 13 14 15 16 
f  9 10 14 13 
f 10 11 15 14 
f 11 12 16 15 
f 12  9 13 16

File18 个顶点,所以 f 中来自 File2 的每个顶点索引都增加了 8.我手动完成了整个示例(包括 File1,2),所以希望我没有犯一些愚蠢的错误,但预览还可以,所以看起来并非如此.

File1 has 8 vertexes so each vertex index in f from File2 is increased by 8. I did the whole example manually (including File1,2) so hope I did not make some silly mistake but the previews are OK so looks like not the case.

如果你想消除重复的条目(为了空间和速度),那么你需要为每个表重新索引表并使用它而不是仅仅添加......

If you want to eliminate duplicate entries (for space and speed) then you need to have reindexing table for each table and use it instead of just adding...

这篇关于如何在纹理映射过程后合并两个 .obj 文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆