Subclassing SCNNode

删除回忆录丶 提交于 2020-01-21 15:21:15

问题


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 

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

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.


回答1:


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;

}



来源:https://stackoverflow.com/questions/29616913/subclassing-scnnode

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!