I'm confused with nodes...

I have few questions about nodes.

  1. When you create node, eg. x = NodePath(‘something’), what does (‘something’) do?

  2. are SpotLight(’’), PointLight(’’) nodes?

  3. What does " node() " do? (eg. base.cam.node())

  4. What’s the difference between these two?

[1]
thing = NodePath(‘something’)
thing.reparentTo(render)

[2]
thing = NodePath(‘something’)
thing = render.attachNewNode(‘something’)

  1. Is render is the final node?

Most of things explains here: panda3d.org/manual/index.php/Cheat_Sheets

First of all NodePath and Node is a different things

  1. You create a Node Path with empty Node. By name ‘something’ you can find your Node Path later.
  2. Yes it’s nodes, to convert it to the NodePath you should attach it to the scene.
  3. This metod return Node of the given Node Path. The Node Path is container, which provide general interface to control (position, rotation, e.t.c.) different types of nodes. If you wish to get control over specific properties (for example lens parameters), then you should get node.

[1] You make unattached Node Path and attach it to the scene
[2] You make unattached Nodepath, and then you make another Node Path, already attached to the scene. I.e. second line of second example is equivalent of first example.
5. Render is the root Node Path of the 3D scene, however it’s just a part of show base and you can make your own scene root if you wish.

ninth explained it pretty well, but to clarify a bit more:

  1. NodePath(“abc”) is equivalent to NodePath(PandaNode(“abc”)), ie. you create an empty PandaNode and then create a NodePath pointing to it.

  2. A PointLight is a specific type of PandaNode. PointLight is a class that inherits from PandaNode.

  3. You are creating two separate PandaNodes - in the first example, you create a PandaNode called “something” and attach it to render. In the second example, you create a PandaNode called “something”, discard it, and then create another PandaNode called “something” and attach that to “render”.

I’ll add more from the practical side :wink:

  1. When you create node, eg. x = NodePath(‘something’), what does (‘something’) do?
    It doesn’t do much, it’s basically the name of the newly created PandaNode (wrapped into a NodePath).
    It’s useful if you want to search the scene graph using .find(), but you should always give some name because doing x = NodePath() gives you a NodePath pointing to well …nothing at all. x = NodePath(‘something’) gives you an empty bucket, x = NodePath() gives you no bucket (and before you ask,no there are no buckets in p3d, just trying to make it graphical).

  2. are SpotLight(’’), PointLight(’’) nodes?
    Yes and No. Lights are PandaNodes (they inherit from PandaNode) but are not NodePaths.
    You may want to look here:
    panda3d.org/reference/1.8.1/ … daNode.php
    and here:
    panda3d.org/reference/1.8.1/ … dePath.php
    To compare what you can do with a PandaNode and what you can do with a NodePath.

  3. What does " node() " do? (eg. base.cam.node())
    The thing about NodePaths is that you can wrap a PandaNode (or anything that inherits from it) into a NodePath, so you get a PandaNode inside a NodePath and .node() allows you to access th methods of the PandaNode inside.

  4. What’s the difference between these two?
    The code:

thing = render.attachNewNode('something')

is a short way to write:

 
thing = NodePath('something')
thing.reparentTo(render)