Ghost vertices generated by obj2egg? BUGGY!

Hi, I just experienced a weird behaviour of obj2egg, ie from an original file (basic test) with 8 vertices I end up with an egg file listing 19 vertices !
(This seems to be due to the f v/vt/vn lines in obj files)

For me it’s annoying since I’m postprocessing some eggfile and wasn’t expecting extra ghost or duplicated vertices…

Other than that maybe it’s ok and taken into account by Panda3D egg loader? I’m wondering.

So apparently:

(1) whenever a vt (uv) line exists and is not used by any face a ghost vertex is generated, and positionned at 0,0,0

(2) if a vertex is used in faces with a different (uv) associated (see f v/vt/vn definition) then a new vertex is generated, see for instance

Let me try illustrate it through the following example.

Provided a obj file defining 8 vertices (v), 8 normal (vn), 12 uv (vt), 6 faces (f) as follows

o weird
g test
v 0.0 10.0 31.0
v 0.0 20.0 21.0
v 1.0 11.0 32.0
v 1.0 21.0 22.0
v 5.0 12.0 33.0
v 5.0 22.0 23.0
v 8.0 13.0 34.0
v 8.0 23.0 24.0
vn -0.18 -0.61 0.76
vn -0.18 -0.65 0.72
vn -0.25 -0.60 0.75
vn 0.13 -0.85 0.50
vn 0.20 -0.84 0.48
vn 0.17 -0.82 0.53
vn -0.40 -0.69 0.59
vn -0.46 -0.74 0.48
vt 0.42 0.29
vt 0.43 0.27
vt 0.43 0.29
vt 0.28 0.32
vt 0.28 0.30
vt 0.30 0.30
vt 0.28 0.71
vt 0.26 0.72
vt 0.26 0.71
vt 0.39 0.33
vt 0.40 0.34
vt 0.39 0.34
f 1/1/1 2/2/2 3/3/3
f 4/4/4 5/5/5 6/6/6
f 7/7/7 8/8/8 9/9/9
f 5/7/5 6/8/6 7/9/7
f 7/10/7 2/11/2 3/12/3
f 1/4/1 5/5/5 6/6/6

And as a result

<CoordinateSystem> { Z-Up }

<Comment> {
  "obj2egg test_neut.obj test_neut.egg"
}
<VertexPool> vpool {
  <Vertex> 1 {
    0 10 31
    <UV> { 0.42 0.29 }
    <Normal> { -0.181633 -0.615534 0.766895 }
  }
  <Vertex> 2 {
    0 20 21
    <UV> { 0.43 0.27 }
    <Normal> { -0.182452 -0.658855 0.729809 }
  }
  <Vertex> 3 {
    1 11 32
    <UV> { 0.43 0.29 }
    <Normal> { -0.251896 -0.604551 0.755689 }
  }
  <Vertex> 4 {
    1 21 22
    <UV> { 0.28 0.32 }
    <Normal> { 0.130695 -0.854541 0.502671 }
  }
  <Vertex> 5 {
    5 12 33
    <UV> { 0.28 0.3 }
    <Normal> { 0.202444 -0.850265 0.485866 }
  }
  <Vertex> 6 {
    5 22 23
    <UV> { 0.3 0.3 }
    <Normal> { 0.171534 -0.827397 0.534781 }
  }
  <Vertex> 7 {
    8 13 34
    <UV> { 0.28 0.71 }
    <Normal> { -0.403198 -0.695516 0.594717 }
  }
  <Vertex> 8 {
    8 23 24
    <UV> { 0.26 0.72 }
    <Normal> { -0.462411 -0.743878 0.482516 }
  }
  <Vertex> 9 {
    0 0 0
    <UV> { 0.26 0.71 }
  }
  <Vertex> 10 {
    0 0 0
    <UV> { 0.39 0.33 }
  }
  <Vertex> 11 {
    0 0 0
    <UV> { 0.4 0.34 }
  }
  <Vertex> 12 {
    0 0 0
    <UV> { 0.39 0.34 }
  }
  <Vertex> 13 {
    5 12 33
    <UV> { 0.28 0.71 }
    <Normal> { 0.202444 -0.850265 0.485866 }
  }
  <Vertex> 14 {
    5 22 23
    <UV> { 0.26 0.72 }
    <Normal> { 0.171534 -0.827397 0.534781 }
  }
  <Vertex> 15 {
    8 13 34
    <UV> { 0.26 0.71 }
    <Normal> { -0.403198 -0.695516 0.594717 }
  }
  <Vertex> 16 {
    8 13 34
    <UV> { 0.39 0.33 }
    <Normal> { -0.403198 -0.695516 0.594717 }
  }
  <Vertex> 17 {
    0 20 21
    <UV> { 0.4 0.34 }
    <Normal> { -0.182452 -0.658855 0.729809 }
  }
  <Vertex> 18 {
    1 11 32
    <UV> { 0.39 0.34 }
    <Normal> { -0.251896 -0.604551 0.755689 }
  }
  <Vertex> 19 {
    0 10 31
    <UV> { 0.28 0.32 }
    <Normal> { -0.181633 -0.615534 0.766895 }
  }
}
<Group> root {
  <Group> test {
    <Polygon> {
      <VertexRef> { 1 2 3 <Ref> { vpool } }
    }
    <Polygon> {
      <VertexRef> { 4 5 6 <Ref> { vpool } }
    }
    <Polygon> {
      <VertexRef> { 7 8 9 <Ref> { vpool } }
    }
    <Polygon> {
      <VertexRef> { 13 14 15 <Ref> { vpool } }
    }
    <Polygon> {
      <VertexRef> { 16 17 18 <Ref> { vpool } }
    }
    <Polygon> {
      <VertexRef> { 19 5 6 <Ref> { vpool } }
    }
  }
}

I’ve seen and even reported this as a bug on the tracker, but it turns out it’s ok for egg files to have unneeded verts, the loader fixes that (just as ‘egg-trans -c’).

bugs.launchpad.net/panda3d/+bug/950906

Well, as one says “this is not a bug, this is a feature !!” :wink:

Having said so, this creates undesirable side effects:

(a) some eggfile are getting very large with this extra dummy vertices…

(b) more seriously, trying to postprocess eggfile vertices is a headacke since additional or duplicated vertices are bringing confusion.

consider for instance a obj file with 2 faces, 4 vertices where faces are defined as:

f 1/1/1 2/2/2 3/3/3
f 1/2/1 2/3/1 4/3/2

after obj2egg convertion, trying to add a specific property to each original vertex (for various purpose see for instance [Dynamic Composite Mesh - Real time blendshaping)) is really a pain in the neck !!

PS. ok, I’ll try to use egg-trans -c after obj2egg, just hoping that the vertices numbering is back to the original… I cross my fingers

After some more investigation, it really appears that
obj2egg followed by egg-trans -c
doesn’t respect the total number of original vertices

For instance from an initial obj file with 1470 vertices, I end up having 2993 vertices after obj2egg conversion, and eventually 1503 vertices after egg-trans -c cleanup. :open_mouth:

No need to mention the vertex numbering is lost…this definitively is creating headacke, and should be considered as a bug!