GeomNode loaded from disk has no modelroot

Not sure if this is a real issue or my brain farted.

I’m creating some procedural geometry then saving to disk by wrapping the resulting GeomNode in a NodePath then calling .writeBamFile(). So far, so good. I get a .bam file on disk.

Loading that .bam file using loader.loadModel returns a NodePath which is of no surpise, however the underlying .node() returns a GeomNode, not a ModelRoot node as I would have expected. As per the docs: A node of this type is created automatically at the root of each model file that is loaded. I expected the loader to return me a model root, with the geomnode parented immediately below it.

Is this something I’m misunderstanding here? Thanks in advance!!

That seems to only apply when loading non-.bam file formats.

So when you create a .bam file using write_bam_file, you do need to parent your nodes to a ModelRoot node manually and call write_bam_file on that one.

Hope this helps. :slight_smile:

1 Like

Thanks @Epihaius. One of the ways I detect a loaded mode in my editor project is with the model root node type, and I make use of the get_fullpath method to see where the model is on disk. Seems a shame that this doesn’t work reliably across all formats.

You can also set that path manually on the ModelRoot when you write the .bam file:

full_path = "c/my_projects/editor/models/my_model.bam"
model_root_node = ModelRoot("my_model")
model_root_node.fullpath = full_path
model_root = NodePath(model_root_node)
# parent geomnodes to model_root here
model_root.write_bam_file(full_path)

I can imagine that being a bit misleading, like if I copy the model to a new directory and load from there then the written path would be inaccurate.

Oh wait, after some testing with changing location of a self-created .bam file, it looks like Panda does set the fullpath property correctly based on the file’s current location when loading it, overwriting the value set when the .bam file was written.

So you only need to provide a ModelRoot and it should work. :slight_smile:

1 Like