how to access nodes...

i’m adding models to root of the graph and then i would like to access each model within a for loop, but there since to be a problem. when i try to do move it (with setX() method) it doesnt move the models, instead it moves all of the models, so i think i’m movin the node with models and not the model. please help…

here is my code:

quadsHolder = []
def setQuads():
	for i in range(100):
		tempQuadNode = loader.loadModel("primitives/cube.egg")
		tempQuadNode.reparentTo(render)
		tempQuadNode.setPos(random.uniform(3,-3), random.uniform(3,-3), random.uniform(2,-2))
		tempQuadNode.setHpr(random.randint(0, 360), random.randint(0, 360), random.randint(0, 360))
		tempQuadNode.setTwoSided(True)
		tempQuadNode.flattenLight()		
		quadsHolder.append(tempQuadNode)


def moveQuad():
	for item in render.getChildren():
		if item.getX() < 3:
			item.setX(item.getX()+0.1)
		else:
			item.setX(-3)
			
			
def moveTask(task):
	moveQuad()
	return task.again


taskMgr.doMoving(0.2, moveTask, 'moveTask')

vedran

One of the children of render is the camera. When you move the camera, it looks like you’re moving everything else.

Instead of iterating through the children of render, you should iterate through your quadsHolder.

David

won’t work that way… i get the same resoult.

when i print the item from the loop in moveQuad() function i get this:

render/cube.egg
so i think that i’m not referencig the right thing when i’m appending my items in quadsHolder array.

what i’m i doing wrong?

txn,
vedran

ok, here is the method that can handle my idea:

next problem, how (where) to define color od the node?
this is not working (snipt from previous code example):

mainHolderNode = render.attachNewNode("mainHolder")

tempModelNode = mainHolderNode.attachNewNode("modelHolder")
		tempModelNode.setPos(random.uniform(3,-3), random.uniform(3,-3), random.uniform(2,-2))
		tempModelNode.setHpr(random.randint(0, 360), random.randint(0, 360), random.randint(0, 360))
		tempModelNode.setColor(random.uniform(0, 1), random.uniform(0, 1), random.uniform(0, 1), 1, 0);
		
		tempModel = loader.loadModel("primitives/cube.egg")
		tempModel.setTwoSided(True)
		tempModel.flattenLight()
		tempModel.instanceTo(tempModelNode)

Try passing 1 as the last parameter to tempModelNode.setColor(). The last parameter is the override value, and 0 means not to override any color that is set on a lower node. 1 will override.

David

not working…

i’ve moved this topic here:
discourse.panda3d.org/viewtopic.php?t=7126