子类化 SCNNode

Subclassing SCNNode

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

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

也尝试投射到 (MySCNNode *)。
但这是行不通的。 "node" 仍然是一个 SCNNode。为什么?

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

我知道需要一个子类。我明白为什么它是非典型的。在我的例子中,我正在制作一个 RTS 并创建它 "Mission editor" 所以我可以用 1 个场景填充在搅拌机中创建的各种对象并在编辑器中构建自定义场景。所以我需要知道瓷砖什么时候可以建造、可以通过(以及在哪个级别)等。 这可能不完美,但应该可以:

+(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;

}