stla / PolygonSoup

Make a consistent mesh from a polygon soup.
5 stars 1 forks source link

wrong vertex index count in writing .obj files #1

Open batuff opened 1 year ago

batuff commented 1 year ago

Dear developers,

when using the function writeMeshFile() to write a .obj file (Wavefront file), the vertex indexing start from zero, while it should start from 1 (https://en.wikipedia.org/wiki/Wavefront_.obj_file).

This wrong indexing prevent the file to be imported correctly in 3D visualization/modeling tools such as Blender.

example code:

rm(list=ls())
library(PolygonSoup)

my.mesh <- list()
my.mesh$vertices <-rbind(c(1,1,0),c(1,-1,0),c(-1,-1,0),c(-1,1,0))
my.mesh$faces <- matrix(c(1,2,3,4), ncol=4)
writeMeshFile(mesh = my.mesh, filename = 'my_mesh.obj')

resulting in output file (my_mesh.obj):

# file written from a CGAL tool in Wavefront obj format
# 4 vertices
# 0 halfedges
# 1 facets

# 4 vertices
# ------------------------------------------

v 1 1 0
v 1 -1 0
v -1 -1 0
v -1 1 0

# 1 facets
# ------------------------------------------

f  0 1 2 3

# End of Wavefront obj format #

that cannot be used, since facets are defined with vertex index starting from zero (f 0 1 2 3 while it should be f 1 2 3 4).

stla commented 1 year ago

Hello,

Ok, thanks for the report. This package is a bit abandoned in favor of cgalMeshes. Did you try with cgalMeshes?

batuff commented 1 year ago

Thanks for the answer. I didn't know about cgalMeshes. I will try it.

stla commented 1 year ago

Sorry there's only off and ply available in this package.