Parse obj file and weld UV Verts

40 Views Asked by At

I have some issues with obj files exported from a software. For some reason the uv on export is split into individual faces and I need to weld the faces back together if the verts overlap.

As a example this is the faulty verts (simple plane with 4 polygons)

`` 
#
# object Plane001
#

v  -29.2301 0.0000 -6.0921
v  -29.2301 0.0000 26.7190
v  -8.7203 0.0000 26.7190
v  -8.7203 0.0000 -6.0921
v  11.7895 0.0000 26.7190
v  11.7895 0.0000 -6.0921
v  -29.2301 0.0000 -38.9033
v  -8.7203 0.0000 -38.9033
v  11.7895 0.0000 -38.9033
# 9 vertices

vn 0.0000 1.0000 -0.0000
# 1 vertex normals                  
# 9 texture coords

o Plane001
g Plane001
usemtl wire_028089177
s 1
vt 0.499838 0.000412
vt 0.999350 0.000412
vt 0.999350 0.499924
vt 0.499838 0.499924
f  1/1/1 2/2/1 3/3/1 4/4/1

vt 0.499838 0.499924
vt 0.999350 0.499924
vt 0.999350 0.999436
vt 0.499838 0.999436
f  4/5/1 3/6/1 5/7/1 6/8/1

vt 0.000326 0.000412
vt 0.499838 0.000412
vt 0.499838 0.499924
vt 0.000326 0.499924
f  7/9/1 1/10/1 4/11/1 8/12/1

vt 0.000326 0.499924
vt 0.499838 0.499924
vt 0.499838 0.999436
vt 0.000326 0.999436
f  8/13/1 4/14/1 6/15/1 9/16/1

# 4 polygons`

Correctly outputed, where the coordinates are not split.

#
# object Plane001
#

v  -29.2301 0.0000 -6.0921
v  -29.2301 0.0000 26.7190
v  -8.7203 0.0000 26.7190
v  -8.7203 0.0000 -6.0921
v  11.7895 0.0000 26.7190
v  11.7895 0.0000 -6.0921
v  -29.2301 0.0000 -38.9033
v  -8.7203 0.0000 -38.9033
v  11.7895 0.0000 -38.9033
# 9 vertices

vn -0.0000 1.0000 -0.0000
# 1 vertex normals

vt 0.499838 0.000412
vt 0.999350 0.000412
vt 0.999350 0.499924
vt 0.499838 0.499924
vt 0.999350 0.999436
vt 0.499838 0.999436
vt 0.000326 0.000412
vt 0.000326 0.499924
vt 0.000326 0.999436
# 9 texture coords

o Plane001
g Plane001
usemtl wire_028089177
s 1
f 1/1/1 2/2/1 3/3/1 4/4/1
f 4/4/1 3/3/1 5/5/1 6/6/1
f 7/7/1 1/1/1 4/4/1 8/8/1
f 8/8/1 4/4/1 6/6/1 9/9/1
# 4 polygons

What im looking for is a way to parse a obj file as text and weld the overlapping tverts(vt) together with python and save as a new obj file. In some cases there might be stacked elements (identical geometry) on top of each other due to uv space optimization so I need to care fore this as well.

0

There are 0 best solutions below