I would like to copy a SCNNode multiple times, have different materials for each node and different positions. However keeping the same scale. So, if I change the scale for the node I copy, all copied nodes should change.
In the code below, when I run changeScale(), the copied node scale does not change.
Is there a way I can change the scale of all copied Nodes or size of geometry together. Without enumerating or changing them individually
let mainNode = SCNNode()
let mainGeo = SCNPlane(width: CGFloat(4), height: CGFloat(4))
mainNode.geometry = mainGeo
for var i = 1; i <= 10; i += 1 {
let thisNode = mainNode.copy() as! SCNNode
thisNode.position = SCNVector3Make( Float(rx), Float(ry), Float(rz) )
thisNode.geometry = thisNode.geometry!.copy() as? SCNGeometry
thisNode.geometry?.firstMaterial = thisNode.geometry?.firstMaterial!.copy() as? SCNMaterial
if i == 0 {
thisNode.geometry?.firstMaterial?.diffuse.contents = UIColor.blueColor()
} else {
thisNode.geometry?.firstMaterial?.diffuse.contents = UIColor.redColor()
}
scene.rootNode.addChildNode(thisNode)
}
func changeScale() {
mainNode.scale = SCNVector3Make(7, 7, 7)
}