我是Cocos3D的新手,我有两个关于3D模型部分的问题。
据我所知,.POD文件包含几个部分。在我的例子中,我有一辆3D汽车,它有零件: - 轮胎 - 轮胎 - 类(等),这些零件有子网。当我用PVRShaman打开pod文件时,我看到了这一点。
现在我的问题:
我可以访问这些部分吗?例如。我想改变车轮的颜色。我可以通过编程方式执行此操作吗?
当我点击某个部分时,我想知道,我在哪个部分轻拍。例如。我想点击方向盘,我知道,车轮已被选中。我怎么能这样做?
非常感谢!
更新:在第二个提案之后,我的方法如下所示:
-(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);
}
答案 0 :(得分:1)
是的,这绝对是可能的。
假设您有一个带有门,轮胎,方向盘等的汽车的POD文件
如果你想在cocos3d中访问汽车的轮胎,你需要轮胎节点的名称,这应该在你的3D编辑器(maya,搅拌机等)中设置。
假设您使用了maya并且已将所有四个轮胎节点名称设置为:
L_back_tire
,L_front_tire
,R_back_tire
,R_front_tire
。
然后你会这样做
//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
答案 1 :(得分:0)
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;`
localNode
将是最接近触摸的节点。
我是从cocos3d DemoMashUp项目得到的。
我建议您从Cocos3dDemoMashUp打开CC3DemoMashUpScene.m
并查看方法-(void) markTouchPoint: (CGPoint) touchPoint on: (CC3Node*) aNode
。
它位于文件的底部。