I'm using Cocos3D.
There i've a list of different CC3Node
s. I want to put an image next to each of it.
My problem is: how to create a new CC3Node
and add it as a Child.
Asked
Active
Viewed 603 times
3

Hamed Rajabi Varamini
- 3,439
- 3
- 24
- 38

Adrian
- 524
- 5
- 21
1 Answers
2
You need to doing something like this:
CC3PlaneNode *imageNode = [CC3PlaneNode nodeWithName:@"One Plane Node on 3D Object"];
[imageNode populateAsCenteredRectangleWithSize: CGSizeMake(200.0, 200.0)
andTessellation:ccg(40, 40) withTexture: [CC3Texture textureFromFile:@"Your Image Address"] invertTexture: YES];
imageNode.material.specularColor = kCCC4FLightGray;
imageNode.shouldCullBackFaces = NO;
[imageNode retainVertexLocations];
[self addChild:imageNode];
And for doing this for each Node:
CC3PlaneNode *newImageNode = [imageNode copyWithName:@"New Node Name"];
...
[self addChild:newImageNode];
At the end of it, if you want to add these node each node as a child do:
[previousNode addChild:newNode];
instead of:
[self addChild:newNode];
I hope it works for you!

Hamed Rajabi Varamini
- 3,439
- 3
- 24
- 38
-
I tried it - but i can't see any node.. Maybe I'm making an error? http://pastebin.com/XZvYTdNJ – Adrian Nov 03 '11 at 18:57
-
If you can see your objects but can't see these images, maybe you need to change my objects position! Else, perhaps you did't set camera and lights correctly! – Hamed Rajabi Varamini Nov 05 '11 at 05:32
-
i'm setting the camera like this: CC3Camera* cam = [CC3Camera nodeWithName: @"Camera"]; cam.location = cc3v( 0.0, 0.0, 6.0 ); [self addChild: cam]; is there an error? i'm sorry for the formatting - don't know how to change that. and the lamp like this: CC3Light* lamp = [CC3Light nodeWithName: @"Lamp"]; lamp.location = cc3v( -2.0, 0.0, 0.0 ); lamp.isDirectionalOnly = NO; [cam addChild: lamp]; sorry for the formatting. i don't know how to change that. – Adrian Nov 05 '11 at 12:41
-
You can use back tick for formatting your code. Can you see your objects before adding new images to world? – Hamed Rajabi Varamini Nov 05 '11 at 13:37
-
i can see one object. this picture is in the middle of my "parent" node. – Adrian Nov 05 '11 at 14:52
-
I suggest you set the camera location to `cc3v(0,0,20)`. I think you are so close to objects. Also, I suggest you work on the HelloWorld demo and try to change that to your world, it works very well! – Hamed Rajabi Varamini Nov 05 '11 at 15:43
-
it seems like getting the wrong location of the subnodes. e.g. -17,4,-3. my main model is at 0,0,0. and it's not possible to add the image as child to the subnodes - only if i add it as a child of the main POD, it's visible.. – Adrian Nov 07 '11 at 18:17
-
Of course not! When you add a new child to node, Cocos3d set the center of child on the center of its parent. I think it is better for you to see this [code](https://sites.google.com/site/rajabivaramini/mycode/JustTest3DWorld.m?attredirects=0) which I wrote for you. It is just updated HelloWorld Demo. You can replace it into the HelloWorld Demo and run it. – Hamed Rajabi Varamini Nov 08 '11 at 05:43
-
this works fine - thank you very much! i'll try to integrate it in my application! – Adrian Nov 08 '11 at 15:18