Invisible model after pycollada -> dae2egg -> pview

Hi all!

I’m currently working on my graduation project and am in need of a 3D game engine that works well with Python. After trying OpenSceneGraph’s Python bindings (which were cumbersome to compile and setup) I was happy to find Panda3D.

For my project I need to display a bunch of geometries saved in Collada. I use pycollada to generate the .dae files and feed those to dae2egg. The problem is that I can’t get the .egg’s to display in Panda3D either through code or through pview. This is the collada file for a simple untextured cube:

<COLLADA xmlns="http://www.collada.org/2005/11/COLLADASchema" version="1.4.1">
  <asset>
    <created>2011-12-13T16:31:21.890130</created>
    <modified>2011-12-13T16:31:21.890136</modified>
    <up_axis>Y_UP</up_axis>
  </asset>
  <library_effects>
    <effect name="effect0" id="effect0">
      <profile_COMMON>
        <technique sid="common">
          <phong>
            <emission>
              <color>0.0 0.0 0.0 1.0</color>
            </emission>
            <ambient>
              <color>0.0 0.0 0.0 1.0</color>
            </ambient>
            <diffuse>
              <color>1 0 0 1.0</color>
            </diffuse>
            <specular>
              <color>0 1 0 1.0</color>
            </specular>
            <shininess>
              <float>0.0</float>
            </shininess>
            <reflective>
              <color>0.0 0.0 0.0 1.0</color>
            </reflective>
            <reflectivity>
              <float>0.0</float>
            </reflectivity>
            <transparent>
              <color>0.0 0.0 0.0 1.0</color>
            </transparent>
            <transparency>
              <float>0.0</float>
            </transparency>
          </phong>
        </technique>
        <extra>
          <technique profile="GOOGLEEARTH">
            <double_sided>0</double_sided>
          </technique>
        </extra>
      </profile_COMMON>
    </effect>
  </library_effects>
  <library_geometries>
    <geometry id="geometry0" name="mycube">
      <mesh>
        <source id="cubenormals-array">
          <float_array count="72" id="cubenormals-array-array">0 0 1 0 0 1 0 0 1 0 0 1 0 1 0 0 1 0 0 1 0 0 1 0 0 -1 0 0 -1 0 0 -1 0 0 -1 0 -1 0 0 -1 0 0 -1 0 0 -1 0 0 1 0 0 1 0 0 1 0 0 1 0 0 0 0 -1 0 0 -1 0 0 -1 0 0 -1</float_array>
          <technique_common>
            <accessor count="24" source="#cubenormals-array-array" stride="3">
              <param type="float" name="X"/>
              <param type="float" name="Y"/>
              <param type="float" name="Z"/>
            </accessor>
          </technique_common>
        </source>
        <source id="cubeverts-array">
          <float_array count="24" id="cubeverts-array-array">-50 50 50 50 50 50 -50 -50 50 50 -50 50 -50 50 -50 50 50 -50 -50 -50 -50 50 -50 -50</float_array>
          <technique_common>
            <accessor count="8" source="#cubeverts-array-array" stride="3">
              <param type="float" name="X"/>
              <param type="float" name="Y"/>
              <param type="float" name="Z"/>
            </accessor>
          </technique_common>
        </source>
        <vertices id="cubeverts-array-vertices">
          <input source="#cubeverts-array" semantic="POSITION"/>
        </vertices>
        <triangles count="12" material="materialref">
          <input source="#cubenormals-array" semantic="NORMAL" offset="1"/>
          <input source="#cubeverts-array-vertices" semantic="VERTEX" offset="0"/>
          <p>0 0 2 1 3 2 0 0 3 2 1 3 0 4 1 5 5 6 0 4 5 6 4 7 6 8 7 9 3 10 6 8 3 10 2 11 0 12 4 13 6 14 0 12 6 14 2 15 3 16 7 17 5 18 3 16 5 18 1 19 5 20 7 21 6 22 5 20 6 22 4 23</p>
        </triangles>
      </mesh>
    </geometry>
  </library_geometries>
  <library_materials>
    <material name="mymaterial" id="material0">
      <instance_effect url="#effect0"/>
    </material>
  </library_materials>
  <library_visual_scenes>
    <visual_scene id="myscene">
      <node name="node0" id="node0">
        <instance_geometry url="#geometry0">
          <bind_material>
            <technique_common>
              <instance_material symbol="materialref" target="#material0"/>
            </technique_common>
          </bind_material>
        </instance_geometry>
      </node>
    </visual_scene>
  </library_visual_scenes>
  <scene>
    <instance_visual_scene url="#myscene"/>
  </scene>
</COLLADA>

Feeding this into dae2egg produces this egg

<CoordinateSystem> { Y-Up }

<Comment> {
  "dae2egg test.dae"
}
<Material> materialref {
  <Scalar> diffr { 1 }
  <Scalar> diffg { 0 }
  <Scalar> diffb { 0 }
  <Scalar> ambr { 0 }
  <Scalar> ambg { 0 }
  <Scalar> ambb { 0 }
  <Scalar> emitr { 0 }
  <Scalar> emitg { 0 }
  <Scalar> emitb { 0 }
  <Scalar> specr { 0 }
  <Scalar> specg { 1 }
  <Scalar> specb { 0 }
  <Scalar> shininess { 0 }
}
<Group> node0 {
  <Group> geometry0 {
    <Scalar> blend { add }
    <Scalar> blendop-a { zero }
    <Scalar> blendop-b { one }
    <Scalar> blendr { 0 }
    <Scalar> blendg { 0 }
    <Scalar> blendb { 0 }
    <Scalar> blenda { 0 }
    <VertexPool> geometry0 {
      <Vertex> 0 {
        -50 50 50
        <Normal> { 0 0 1 }
      }
      <Vertex> 1 {
        -50 -50 50
        <Normal> { 0 0 1 }
      }
      <Vertex> 2 {
        50 -50 50
        <Normal> { 0 0 1 }
      }
      <Vertex> 3 {
        -50 50 50
        <Normal> { 0 0 1 }
      }
      <Vertex> 4 {
        50 -50 50
        <Normal> { 0 0 1 }
      }
      <Vertex> 5 {
        50 50 50
        <Normal> { 0 0 1 }
      }
      <Vertex> 6 {
        -50 50 50
        <Normal> { 0 1 0 }
      }
      <Vertex> 7 {
        50 50 50
        <Normal> { 0 1 0 }
      }
      <Vertex> 8 {
        50 50 -50
        <Normal> { 0 1 0 }
      }
      <Vertex> 9 {
        -50 50 50
        <Normal> { 0 1 0 }
      }
      <Vertex> 10 {
        50 50 -50
        <Normal> { 0 1 0 }
      }
      <Vertex> 11 {
        -50 50 -50
        <Normal> { 0 1 0 }
      }
      <Vertex> 12 {
        -50 -50 -50
        <Normal> { 0 -1 0 }
      }
      <Vertex> 13 {
        50 -50 -50
        <Normal> { 0 -1 0 }
      }
      <Vertex> 14 {
        50 -50 50
        <Normal> { 0 -1 0 }
      }
      <Vertex> 15 {
        -50 -50 -50
        <Normal> { 0 -1 0 }
      }
      <Vertex> 16 {
        50 -50 50
        <Normal> { 0 -1 0 }
      }
      <Vertex> 17 {
        -50 -50 50
        <Normal> { 0 -1 0 }
      }
      <Vertex> 18 {
        -50 50 50
        <Normal> { -1 0 0 }
      }
      <Vertex> 19 {
        -50 50 -50
        <Normal> { -1 0 0 }
      }
      <Vertex> 20 {
        -50 -50 -50
        <Normal> { -1 0 0 }
      }
      <Vertex> 21 {
        -50 50 50
        <Normal> { -1 0 0 }
      }
      <Vertex> 22 {
        -50 -50 -50
        <Normal> { -1 0 0 }
      }
      <Vertex> 23 {
        -50 -50 50
        <Normal> { -1 0 0 }
      }
      <Vertex> 24 {
        50 -50 50
        <Normal> { 1 0 0 }
      }
      <Vertex> 25 {
        50 -50 -50
        <Normal> { 1 0 0 }
      }
      <Vertex> 26 {
        50 50 -50
        <Normal> { 1 0 0 }
      }
      <Vertex> 27 {
        50 -50 50
        <Normal> { 1 0 0 }
      }
      <Vertex> 28 {
        50 50 -50
        <Normal> { 1 0 0 }
      }
      <Vertex> 29 {
        50 50 50
        <Normal> { 1 0 0 }
      }
      <Vertex> 30 {
        50 50 -50
        <Normal> { 0 0 -1 }
      }
      <Vertex> 31 {
        50 -50 -50
        <Normal> { 0 0 -1 }
      }
      <Vertex> 32 {
        -50 -50 -50
        <Normal> { 0 0 -1 }
      }
      <Vertex> 33 {
        50 50 -50
        <Normal> { 0 0 -1 }
      }
      <Vertex> 34 {
        -50 -50 -50
        <Normal> { 0 0 -1 }
      }
      <Vertex> 35 {
        -50 50 -50
        <Normal> { 0 0 -1 }
      }
    }
    <Polygon> {
      <MRef> { materialref }
      <VertexRef> { 0 1 2 <Ref> { geometry0 } }
    }
    <Polygon> {
      <MRef> { materialref }
      <VertexRef> { 3 4 5 <Ref> { geometry0 } }
    }
    <Polygon> {
      <MRef> { materialref }
      <VertexRef> { 6 7 8 <Ref> { geometry0 } }
    }
    <Polygon> {
      <MRef> { materialref }
      <VertexRef> { 9 10 11 <Ref> { geometry0 } }
    }
    <Polygon> {
      <MRef> { materialref }
      <VertexRef> { 12 13 14 <Ref> { geometry0 } }
    }
    <Polygon> {
      <MRef> { materialref }
      <VertexRef> { 15 16 17 <Ref> { geometry0 } }
    }
    <Polygon> {
      <MRef> { materialref }
      <VertexRef> { 18 19 20 <Ref> { geometry0 } }
    }
    <Polygon> {
      <MRef> { materialref }
      <VertexRef> { 21 22 23 <Ref> { geometry0 } }
    }
    <Polygon> {
      <MRef> { materialref }
      <VertexRef> { 24 25 26 <Ref> { geometry0 } }
    }
    <Polygon> {
      <MRef> { materialref }
      <VertexRef> { 27 28 29 <Ref> { geometry0 } }
    }
    <Polygon> {
      <MRef> { materialref }
      <VertexRef> { 30 31 32 <Ref> { geometry0 } }
    }
    <Polygon> {
      <MRef> { materialref }
      <VertexRef> { 33 34 35 <Ref> { geometry0 } }
    }
  }
}
<Table> {
}

which, when loaded in pview, does not show up. I’ve tried turning on the lights, showing the wireframe, centering the object, displaying the bbox, etc. but nothing seems to work.

I also tried to tweak the model into view with the GUI by calling the .place() function on the model, but to no avail.

Any thoughts on what might be going wrong? Is there a minimum amount of information needed in an .egg file in order to get it to render?

Thanks in advance,

Simeon

Hi, welcome to the forums!

In your collada document, I’m seeing:

            <transparent> 
              <color>0.0 0.0 0.0 1.0</color> 
            </transparent> 
            <transparency> 
              <float>0.0</float> 
            </transparency> 

From the collada 1.4.1 spec: (about )

• A_ONE (the default): Takes the transparency information from the color’s alpha channel, where the value 1.0 is opaque.

So your tool is exporting your models transparent. Changing the transparency to 1.0 should fix it.

It’s actually a bug I’ve seen before in older versions of Sketchup, I think. I didn’t know pycollada also suffered from this bug. It’s probably a good idea to file a bug report with them, if they didn’t already fix the problem.

Alternatively, as a temporary workaround, you can just remove this section from the Egg file:

    <Scalar> blend { add } 
    <Scalar> blendop-a { zero } 
    <Scalar> blendop-b { one } 
    <Scalar> blendr { 0 } 
    <Scalar> blendg { 0 } 
    <Scalar> blendb { 0 } 
    <Scalar> blenda { 0 } 

This will just disable the transparency-related information from the model altogether.

Hey thanks for the quick reply! You are totally correct, changing the value to 1.0 solved the problem. I’ll report it to the pycollada crew.

Something else: my cube is rendering quite okay except for some ‘popping’ of faces when I rotate the model, see image below.

Initially everything looks fine but once I rotate the model past a certain angle,the faces turn black as if they are backfaces when they clearly aren’t. Image below shows how the cube looks like prior to the ‘popping’ of the faces.

My guess is that something weird is going on with the normals (since I calculate them myself), but they look fine when I converting the model to Wavefront (.obj) and import it in Blender (and turn the normals on). The cube displays fine in OpenSceneGraph, but I see the same ‘popping’ when I load my project data. Note that this effect occurs only for some faces (both in case of the cube and my project data), not all. For instance, rotating the object to the right (i.e. such that the bottom left faces get in the same position as the bottom right faces in the first image) doesn’t cause ‘popping’.

Any thoughts? It’s a minor issue but it’s a bit weird especially for such a simple geometry.

I’m not knowledgeable on how the normals are used in the rendering pipeline (I do understand the mathematical implications and why normals are there, etc.) to be able to tell where this effect comes from. A reference to a good text/book/tutorial will be helpful.

Cheers,

Simeon

The green color is entirely due to a specular highlight (the material color is actually red), and the nature of specular highlights is that they’re not visible from certain angles. But because it’s just a cube with perfectly flat faces, it looks like “popping” instead of a shiny spot.

It would probably make more sense if you applied this material to a sphere or a teapot or something else with curves. But still, it’s a very weird material.

David