1

我是 Cocos3D 的新手,我有两个关于 3D 模型部分的问题。

据我了解,一个 .POD 文件由几个部分组成。在我的示例中,我有一辆 3D 汽车,它具有以下部件: - 车轮 - 轮胎 - 类(等),并且这些部件具有子网格。当我使用 PVRShaman 打开 pod 文件时,我看到了这一点。

现在我的问题:

  1. 我可以访问这些部分吗?例如,我想改变轮子的颜色。我可以以编程方式执行此操作吗?

  2. 当我点击一个部分时,我想知道我点击了哪个部分。例如,我想点击轮子,并且我知道轮子已被选中。我怎样才能做到这一点?

非常感谢!

更新:在第二个提案之后,我的方法如下所示:

-(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); 
}
4

2 回答 2

1

是的,这绝对是可能的。

假设你有一个带有车门、轮胎、方向盘等的汽车的 POD 文件。
如果你想在 cocos3d 中访问汽车的轮胎,你需要轮胎节点的名称,这应该已经在你的3d 编辑器(maya、blender 等)。

假设您使用了 Maya,并且您已将所有四个轮胎节点名称设置为:
L_back_tireL_front_tireR_back_tireR_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  
于 2013-09-15T11:19:03.913 回答
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 项目中得到了这个。

推荐你CC3DemoMashUpScene.m从 Cocos3dDemoMashUp 打开,去看看方法-(void) markTouchPoint: (CGPoint) touchPoint on: (CC3Node*) aNode
它位于文件的底部。

于 2013-09-15T15:10:11.593 回答