子类化 SCNNode [英] Subclassing SCNNode

查看:45
本文介绍了子类化 SCNNode的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am importing a simple dae file. I want some of the nodes to be a subclass of SCNNode - MySCNNode.

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

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

Tried casting to (MySCNNode *) too.
But this is not working. "node" is still an SCNNode. Why?

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

I need to add a few properties and methods to SCNNode. So I subclassed SCNNode. I want the nodes from the scene(imported from a dae) to have the properties and behaviour. The nodes from the scene is always SCNNode. I want it to be of class MySCNNode.

推荐答案

我知道需要一个子类.我明白为什么它是非典型的.就我而言,我正在制作 RTS 并创建它的任务编辑器",因此我可以拍摄 1 个场景,其中填充了在 Blender 中创建的各种对象,并在编辑器中构建自定义场景.所以我需要知道瓷砖什么时候可以建造,可以通过(以及在哪个级别)等.这可能并不完美,但它应该可以工作:

I understand needing a subclass. And I understand why it's atypical. In my case I'm making a RTS and am creating it's "Mission editor" so I can take 1 scene filled with the various objects created in blender and build custom scenes in the editor. So I need to know when tiles are buildable, passable (and on which level), etc. This may not be perfect but it should work:

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

}

这篇关于子类化 SCNNode的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆