2

I have an object broken into many small parts. I could maintain a global list of vertices and figure out which belong to each small part, but it would be easier in my use case if I could index relatively.

IE, I specify that part 0 has 8 vertices, and face 0 of part 0 uses vertex 0, 3, 4 of that part.

Is there a way to do this in Wavefront OBJ files? It's a little unclear how Groups and Objects work.

For example, is the following legal?

o myObj1
v 3159.000000 203.000000 1959.000000 1.000000
v 3161.000000 203.000000 1959.000000 1.000000
v 3161.000000 203.000000 1961.000000 1.000000
v 3159.000000 203.000000 1961.000000 1.000000
v 3159.000000 205.000000 1959.000000 1.000000
v 3161.000000 205.000000 1959.000000 1.000000
v 3161.000000 205.000000 1961.000000 1.000000
v 3159.000000 205.000000 1961.000000 1.000000
f 1 4 5
f 4 5 8
f 2 3 6
f 3 6 7
f 1 2 3
f 1 3 4
f 5 6 7
f 5 7 8
f 1 2 5
f 2 5 6
f 4 3 8
f 3 8 7
o myObj2
v 3159.000000 203.000000 1961.000000 1.000000
v 3161.000000 203.000000 1961.000000 1.000000
v 3161.000000 203.000000 1963.000000 1.000000
v 3159.000000 203.000000 1963.000000 1.000000
v 3159.000000 205.000000 1961.000000 1.000000
v 3161.000000 205.000000 1961.000000 1.000000
v 3161.000000 205.000000 1963.000000 1.000000
v 3159.000000 205.000000 1963.000000 1.000000
f 1 4 5
f 4 5 8
f 2 3 6
f 3 6 7
f 1 2 3
f 1 3 4
f 5 6 7
f 5 7 8
f 1 2 5
f 2 5 6
f 4 3 8
f 3 8 7

And so on. (Assuming coordinates is the coordinates, of course)

EDIT: Wikipedia states:

OBJ files, due to their list structure, are able to reference vertices, normals, etc. either by their absolute position (1 represents the first defined vertex, N representing the Nth defined vertex), or by their relative position (-1 represents the latest defined vertex). However, not all software supports the latter approach, and conversely some software inherently writes only the latter form (due to the convenience of appending elements without needing to recalculate vertex offsets, etc.), leading to occasional incompatibilities.

So this...should work? It's unclear what the format would look like however. In any case, it fails to work properly in 3D Viewer.

Tyler Shellberg
  • 1,086
  • 11
  • 28

2 Answers2

0

A little late to the party :)

You could use the relative vertex position as stated in the wikipedia quote; it accesses the latest (not the last) defined vertex. If you replace both face lists by this:

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

It shows both cubes in 3D Viewer. So even though OBJ doesn't associate them with the object or group, they can be accessed "locally".

You could also choose to write the vertices per object in reverse, so the first vertex (written last) can be referred to as -1, the second as -2, etc.

C.Evenhuis
  • 25,996
  • 2
  • 58
  • 72
0

Vertex numbering is contiguous throughout a single OBJ file, regardless of any kinds of grouping used. This translates to positive vertex numbering being absolute and not relative in any way, and negative vertex numbering being relative to the last defined vertex (but still including all defined vertices).

Ie. vertex definitions don't have grouping.

Points ("p" tag) can (probably?) have grouping, but are meant to be rendered as actual points, not part of a face.

tl;dr the closest you can get to what you were attempting is negative indices, but whether it loads correctly would depend on the program loading it

Laike Endaril
  • 781
  • 5
  • 4