I try to use Cocos3D
and I need to show several 3D objects placed on the sphere in front of the camera. So, here is my code:
@interface cocos3d_testScene : CC3Scene {
CC3ResourceNode* rezNode;
CC3ResourceNode* resNode;
}
- (void) onOpen {
...
rezNode = [CC3PODResourceNode nodeFromFile: @"arrow.pod"];
rezNode.scale = CC3VectorMake(0.03, 0.03, 0.03);
rezNode.rotation = CC3VectorMake(90, 90, 0);
[self addChild: rezNode];
rezNode.location = CC3VectorMake(0, 0, -1.9);
resNode = [CC3PODResourceNode nodeFromFile: @"arrow.pod"];
resNode.scale = CC3VectorMake(0.03, 0.03, 0.03);
resNode.rotation = CC3VectorMake(90, 0, 0);
[self addChild:resNode];
resNode.location = CC3VectorMake(0, 0, -1.9);
...
}
So I can't see the second arrow on my scene. How can I solve this?
In Cocos3D, resources are cached. Loading the same POD resource twice, as you are doing, will result in both CC3PODResourceNode
attempting to use the same content. Since any node can only have a single parent, the second loading has the effect of moving the descendants of the first CC3PODResourceNode
instance to the second instance, leaving the first CC3PODResourceNode
instance with no descendants.
Instead of attempting to load multiple copies of the same resource file, simply copy the nodes you want to duplicate. Copying a node performs a deep copy, copying all descendant nodes as well. To preserve memory, mesh vertex content, which is static and can be quite large, is not copied, and two or more nodes can share the same mesh content.
For your example, the following should get you what you want:
resNode = [rezNode copy];
resNode.rotation = CC3VectorMake(90, 0, 0);
[self addChild: resNode];
Since the scale
and location
properties of both nodes are the same, the copy will take care of setting them in the second instance.