子类化SCNNode

时间:2015-04-13 23:50:29

标签: scenekit

我正在导入一个简单的dae文件。我希望一些节点成为SCNNode的子类 - MySCNNode。

 MySCNNode *node = [scnView.scene.rootNode childNodeWithName:@"Box1" recursively:YES];
 //additional initialization goes here 

尝试投射到(MySCNNode *) 但这不起作用。 “node”仍然是SCNNode。为什么呢?

我需要为SCNNode添加一些属性和方法。所以我将SCNNode子类化。我希望场景中的节点(从dae导入)具有属性和行为。场景中的节点始终是SCNNode。我希望它是MySCNNode类。

1 个答案:

答案 0 :(得分:3)

我明白需要一个子类。我理解为什么它不典型。在我的情况下,我正在创建一个RTS并且正在创建它"任务编辑"所以我可以在1个场景中填充在blender中创建的各种对象,并在编辑器中构建自定义场景。所以我需要知道什么时候瓷砖是可以建造的,可以通行的(以及在哪个层面上)等等。 这可能不完美,但应该有效:

+(instancetype)mySCNNodeWithNode:(SCNNode*)node{

SCNVector3 min,max;
[node getBoundingBoxMin:&min max:&max];
MySCNNode *newNode = [MySCNNode node];
newNode.position = node.position;
newNode.rotation = node.rotation;
newNode.transform = node.transform;
[node setBoundingBoxMin:&min max:&max];
newNode.geometry = [node.geometry copy];
SCNMaterial * material = [node.geometry.firstMaterial copy];
newNode.geometry.firstMaterial = material;

return newNode;

}