Egg "Transform" node cancelled by loader

Hi guys,

Not sure if this is the right board to ask this, but i noticed something rather weird happening when loading models that are in .egg format in Panda using either loader.loadModel or ModelPool.loadModel

-> if the model has a tranform node (eg. { {…} } {…} ) then all of the vertices imported will be altered by the inverse transform (eg. the coordinates are multiplied by the inverse matrix of the transform) and those are then stored as vertex values in the GeomNode (if you look at them with a GeomVertexReader that is); This makes sense somewhat, BUT, the Transform matrix itself is also kept in the model tree, specifically in the GeomNode or its parent PandaNode (under the ModelRoot node, when a single ModelRoot contains multiple GeomNodes that are all affected by the same Tranform).

Therefore, when rendering, the Tranform is applied to the vertices of the model loaded and simply cancels away, since the vertices had been pre-multiplied by the inverse matrix at import time. Basically then, the Transform node in the egg file has no effect at all during play. You can test that very easily by creating a very simple egg file, a cube model for instance, and adding a TransformNode to it, not unlike the following:

<Transform> { 
  <Matrix4> {
 2.0 0.0 0.0 0.0
 0.0 2.0 0.0 0.0
 0.0 0.0 2.0 0.0
 0.0 0.0 4.0 1.0
 }
}

which scales the model by 2 and moves it upwards 4 units

So, my question is, why does that happen? The only thing i could find in the doc that might explain it was briefly mentionning a conversion from world coordinates to (something-i-can’t-remember) coordinates when importing :S
If the transform was meant to be ignored, why not simply call model.clearTranform() during the import and leave the vertices as is?
Or let the transform be applied? but why of all things keep both the Tranform and use the inverse to alter models anyway?
Am i missing something? I know this is my first post on the forums, but i’ve been using Panda for more than a year now and i’ve never been so confused before…

anyway, thanks for reading all this, sorry if it gets mystifying at times
btw, i can provide the egg files i used for testing and a simple script that prints the vertices/matrices if someone wants to see for themselves
thanks again :slight_smile:

Hey, welcome to the forums.

I think the .egg format specifies vertices in global coordinates, rather than local - you can use an tag to specify a coordinate system for the vertices within it. I’m not 100% sure though, it’s been a long time since I messed with the .egg stuff.

do you know if there are some LoaderOptions flags i can set to force the loader to use the local coordinates instead of the global/transformed ones when loading the models?
i have way too many egg files to try adding an tag in each and everyone of them (although i could try writing a shell script, but that still feels a bit wrong :confused:

I’m not sure what you’re asking. Egg files store vertices in global coordinates; that is the definition of the tag in an egg file.

However, the Panda scene graph (and most other scene graph models) store vertices in local coordinates. Thus, when you load an egg file, and then examine the vertices in the resulting GeomVertexData, they have been translated from global coordinates to local coordinates. This is the effect you are describing in the OP.

So, normally this should not cause a problem, because that is the correct behavior for rendering models that are represented in egg files. What is the precise nature of the problem you are experiencing? Are you storing explicit tables of numbers in your egg files that you want to read, unmodified? If so, you could use the EggData interfaces to read the original egg file data, without going through the loadModel() interface.

David

ok, sorry to revive this thread weeks later, but i’m a really terrible procrastinator (and i’ve been pretty busy at work), but i thought an example would be the best way of explaining what i meant in the op:

http://thecorsaircove.com/panda/transformExample.zip

the script transform.py simply creates 3 unit cubes, which have the following characteristics: the first one is a plain unit cube model (cube.egg), so it appears as a such when loaded in Panda; the second one has a node (cubeT.egg), yet appears exactly identical to the first one when loaded in the environment; the third one, is the same model as the second one, but the tranform is stripped from the PandaNode after it is loaded, and this one’s coordinates appear to have undergone the opposite tranform to the one described in the model file (or at least, that’s how i see it…)

i’ve fixed my problem anyway, but i’m still curious as to what is going on with the tranforms when the models are loaded. sorry for picking on such small details though, it’s just that it has been bugging me for a while now

This is a difficult concept to grasp, so bear with me while I try again. :slight_smile:

An egg file stores vertices in global coordinates. Not local coordinates, like almost every model file format. Global coordinates.

Global coordinates means that the vertex values that appear in the egg file specify the position at which these vertices will be found relative to the global coordinate frame.

<Transform> entries change only the local coordinate frame. They do not change the global coordinate frame, of course. Thus, putting a <Transform> entry in an egg file, without changing the numerical values of the vertex values, means that the vertices will still appear at the same position in the global coordinate frame as they would have been without the <Transform> entry.

See? Since the vertices are defined in global coordinates, the only way to make the vertices (and therefore the cube) appear in another position is to actually change the vertex values. Changing the <Transform> entry only changes the local transform, not the vertices’ global position, and therefore not the cube’s apparent position either.

What does it mean to change the local transform? It means that when the vertex values are converted to local coordinate values for populating the vertex data of the renderable obejct, the vertices are inverse-transformed by the local transform, then the local transform is applied to the parent node. This means that if you do nothing to the transform on the node, the cube’s vertices (and therefore the cube) appear in the same position as if there had been no transform at all, exactly as required by the egg syntax. If, however, you remove the transform on the node, then you have undone half of the equation, and all you see remaining is the inverse transform on the vertices–so the cube appears to have moved in the opposite direction.

Does that make sense? It all comes down to what the numerical values of the vertices mean in the egg file.

David

Hi, sorry to hop on to your topic but I was hoping dwr would be able to answer how the vertices work in dae. It seems to be the only way to save models in Mac for me and they don’t seem to work like egg.

Thanks a lot David! That really helped make sense out of what was going on :smiley:

@asimes: i have never used dae models before so i doubt i could help, but out of curiosity, what do you mean by “how do the vertices work”?

I had only used egg files in the past but I was using computers at my school to make the files and can’t do that now. The only kind of file I know how to make that Panda3D will take for models is a dae file.

In Maya the model looks just like what I wanted. (6 cubes that form one large cube) but when I run the sketch in the terminal by loading the dae it places only 2 of the cubes in the correct locations and the other 4 somewhere else higher up.

Can’t figure out why it is doing that

It must be either a bug in the Maya -> dae conversion, or in the dae -> egg conversion.

I don’t have personal experience with either of these steps, but rdb has developed the dae2egg converter. He might be able to help you diagnose the problem.

David

Can you e-mail me the dae file? I’ll be able to see if the problem is in the maya2dae conversion or in the dae2egg conversion.

I don’t have the dae file anymore unfortunately and now I cannot remember how I made a dae file in the first place, it doesn’t seem to be an export option.

I also cannot seem to find how to make one online without reference to external exporters. Is there a way for Macs to make a file in Maya that Panda would accept?