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

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

问题描述

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

解决方案

单一对象wavefront obj文件的naive文件合并相对容易:


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



    记住每个表的条目数

  2. p> 将第二个文件的面添加到内存中



    这是唯一需要更改位的内容。所有索引都来自 1 ,因此您需要将每个表的大小从之前的文件添加到它。例如,如果第一个obj有从 v 开始的10行,意味着在追加第二个obj后,将从 11开始引用它的点改为。所以取每个顶点索引并添加它的大小。



    对于任何你喜欢的法线,纹理坐标或任何信息,同样如此。

    li>
  3. 将整个内容另存为单个obj文件



$ b b

对不起,我不使用材料扩展,所以我不知道格式,如果任何更改需要在mtl文件(但我不这么认为)。



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





  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

File2:

  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

File1 code>顶点,因此 File2 中的 f 中的每个顶点索引增加 8 。我做了整个例子手动(包括File1,2),所以希望我没有犯一些愚蠢的错误,但预览是好的,所以看起来不是这样。





如果你想要消除重复的条目(空间和速度),那么你需要为每个表使用reindexing表,只是添加...


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)?

解决方案

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

  1. read first files into memory

    remember the number of entries of each table

  2. append the second file into memory (except faces)

  3. append faces of the second file into memory

    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.

  4. save the whole thing as single obj file

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...

File1:

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 

File2:

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 

Merged:

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

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天全站免登陆