Question

I'm new in Cocos3D and I have two questions concerning the parts of the 3D model.

As I understood, a .POD file consits of several parts. In my example, I have a 3D Car, which has the parts: - wheel - tire - class (etc.) and these parts have submeshes. I see this, when I open the pod file with PVRShaman.

Now my questions:

  1. Is it possible for me to have access to these parts? E.g. I want to change the color of the wheel. Can I do this programmatically?

  2. When I tap on a part, I want to know, on which part I have tapped. E.g. I want to tap on the wheel, and I know, that the wheel was selected. How can I do this?

Thank you very much!

Update: after the second proposal, my method looks like this:

-(void) nodeSelected: (CC3Node*) aNode byTouchEvent: (uint) touchType at: (CGPoint) touchPoint {
     NSLog(@"Node selected: %@", aNode.name);
     CC3Ray touchRay = [camera unprojectPoint: touchPoint];
     CC3NodePuncturingVisitor* puncturedNodes = [self nodesIntersectedByGlobalRay: touchRay];

     // The reported touched node may be a parent. We want to find the descendant node that
     // was actually pierced by the touch ray, so that we can attached a descriptor to it.
     CC3Node* localNode = puncturedNodes.closestPuncturedNode;

     NSLog(@"Node local: %@", localNode.name); 
}
Was it helpful?

Solution

Yes this is definitely possible.

Lets say you have a POD file of a car with doors, tires, steering wheel, etc.
If you want to access the tire of the car in cocos3d, you will need the name of the tire node, this should have been set in your 3d editor (maya, blender, etc).

Lets say you used maya and that you have set all four tire nodes names to:
L_back_tire, L_front_tire, R_back_tire, R_front_tire.

Then you would do this

//load car and all the child nodes of the car 
CC3PODResourceNode *car = [CC3PODResourceNode nodeFromFile:@"Car.pod"];
[self addChild:car];

//the car and all its child node (tires,doors,etc.) have been loaded into the scene
//so this is how you would fetch the left tire
CC3Node *leftTire = [car getNodeNamed:@"L_back_tire"];

//do more stuff with that tire her  

OTHER TIPS

CC3Ray touchRay = [self.activeCamera unprojectPoint: touchPoint];
CC3NodePuncturingVisitor* puncturedNodes = [self nodesIntersectedByGlobalRay: touchRay];

// The reported touched node may be a parent. We want to find the descendant node that
// was actually pierced by the touch ray, so that we can attached a descriptor to it.
CC3Node* localNode = puncturedNodes.closestPuncturedNode;`

The localNode will be the node that was closest to the touch.

I got this from the cocos3d DemoMashUp project.

I recommend you open up CC3DemoMashUpScene.m from the Cocos3dDemoMashUp and go look at the method -(void) markTouchPoint: (CGPoint) touchPoint on: (CC3Node*) aNode.
It's at the bottom of the file.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top