Creating objects "on the fly"

Hi everyone !

I’d like to know if there is a way of creating objects on the fly. I have method which computes the object vertex position and an other one which computes the faces of the object. I could create an egg file (although all my attempts to create a model with a egg, even a really simple model have failed - I think I did not get how it works) but I have a lot of objects, and writing into a file then loading them seems a bit slow.

What I would like to do is to create the object directly from my program. Is this possible ?

Yes, it is possible. There is a full section of the manual dedicated to this topic: “Procedurally Generating 3D Models”.

Or you can use the egg library and then directly load a NodePath from the egg data without writing the data to a file by using loadEggData( eggData ).


Thanks, I’m going to take a look at it.

I tried this after reading the manual, but nothing shows up on screen. Any idea ?

It works fine for me. You just have to reposition the camera a bit to see it. Drag with the right mouse a bit upwards to zoom out, then drag the middle mouse button around to rotate. You will see two perfect red triangles.

Yes, it works for me too.

This is your first triangle, visible only from “above”:

   \   |
    \  |
     \ |
  3    0

And this your second, visible only from “below”:

  |   / 
  |  /  
  | /   
  3    0

But I assume you wanted to do something like this:

  |\   |
  | \  |
  |  \ |
  |   \|

You have to create the triangle indices in counter-clockwise order, like this:




yep, addition :
your node is behind your camera
if it’s still hard to see, use nodePath.showBounds()

Sorry guys. I didn’t even thought that the camera position might be the problem. I must have been tired last friday…

Thanks anyway !