Replacing render node

In developing my editor I’ve come to a point where it might be useful to replace the scene graph root, aka “render” with another node.

Currently each scene created by the editor has its own root node. This stops unwanted behaviour like being able to pick your own manipulators or saving them out to file, as the scene is only interested in what is below its own root.

For the most part this approach works well, but now I’m getting into interesting territory where the user can drop scripts onto objects. In order for a developer to maintain their coding style it would be necessary for base.camera and base.render to point to their game nodes and not those the editor uses.

Keeping base.cam would be easy enough; just create another camera for the editor to use. The only way I can think of to get this to work for base.render is to attach a new node to render then force this back into builtins so any subsequent call to “render” will give this new node.

Can this be done or am I only asking for trouble if I go poking around like this?

“render” is just an arbitrary node, so sure, you can swap it around with your own nodes. You can simply set base.render and builtin.render to a different value; I don’t think that would cause any harm. It may affect some cases where objects may have already been created for a different instance of “render”, such as the SceneGraphAnalyzerMeter; look at the ShowBase.py source code and search for “render” to see which functionality is affected in what way.

Alternatively, you could also simply load different “render” and “base” objects into the initial scope of the script environment, one that is specific to that scene. It might be cleaner that way.

That makes sense. I like the idea of simply switching out the references to render in the scopes that require it, but I’m not sure how I would go about doing this.

I suppose I can do it simple enough for “render” as you could just redeclare it in another scope. Replacing “base.render” locally seems a lot harder - would I have to subclass base locally and change it out there? That wouldn’t change any other instance of “base” in the program?

You can just set “base” to be a variable at the global scope in your script environment, different from the one in builtin.

I see. Thinking about this issue again, is it possible to create another (parallel) scene graph root? What is it about the render node which makes it render?

AFAIK, render is nothing more than the node rendered by the main camera, being the base.camNode, which displays to the main window, being base.win. That’s about it. The name makes it sound special, but really it isn’t.

In my editor, I have 3 additional “root nodes”, being nodes that each have a camera rendering them and a window displaying image from that camera, and none of them is attached to render (or anything else, they have no parent). Thus, I have 3 completely separate scene graphs. I use the render node to render the perspective view, and the 3 additional ones (with ortho cameras) for the orthographic views.

In fact, you do actually have a parallel scene graph in every Panda application. It’s the render2d node, which has its own orthographic camera and renders to base.win, on top of render.

Thanks guys, helpful as always :slight_smile:

For anyone else interested, I did some more searching of threads and found this: [url]Make a new scene graph.] which gives a pretty good recipe.

I might try a different approach after all and just parent “render” to another node and use that as the root for all the editor nodes. That way I can keep my cameras and manipulators separate and still get things like mouse picking to traverse both graphs.