Duplicating procedural geometry

Hi to all,

I have generated a procedural model and would like to create multiple copies of it. I know one can do this:

par_nom='prototype'
par_np=render.find(par_nom)
p_h_nom="Piece_ph"
p_h=render.attachNewNode(p_h_nom)
par_np.copyTo(p_h)

That does add a node to the ‘dummy’ nodepath that is similar to the node of the original model. The problem is that this makes the duplicate model the parent of the original model, which I do not want. What I need is a new completely free duplicate that has no relations at all to its original model. How can this be done?

Thanks in advance.

I’m not sure what you mean. copyTo does a deep copy, meaning that not only the node, but all its children will be copied.

Hi there,

well, what I mean is that I don’t want the nodepath with the copied node to be the parent of the nodepath with the original node. When I do this:

nodepath_of_copied_node.ls()

I get a child which is the nodepath with the original node. I just thought about and realized a work-around that would work for me given what I’m building; but I was asking whether there was a way to prevent the establishment of this parent-child relationship, or if there is another way to create duplicate procedural geometry.

I don’t know whether it will work, and I don’t know whether it’s safe, but you could try a deep copy via Python’s “copy” module. If it works, that method should provide a new NodePath that can be reparented as you please.

copy.deepcopy(np) just uses copyTo under the hood. In fact, it returns np.copyTo(NodePath()), which copies the node graph but doesn’t reparent the copy to anything.

yeah, the copy isn’t re-parented in this case. What’s happening is that the copy’s original, i.e. the thing from which it is duplicated is added as its child. So that if I do:

for child in copy.getChildren():
   print child.getName()

I get the name of the copy’s original. This is what I don’t want, I mean, I need it to be independent of its original, so that the copy does not have the original as its child. Perhaps it’s a bug in my own code as the part that does this is nested deeply in other parts, so I’ll have a look at it. Either way, I realized that I could just filter out the name of the copy’s original from the child-list and that would solve everything.

Note that just because two nodes have the same name, they aren’t necessarily the same node. Names don’t have to be unique in Panda’s scene graph.