我正在导入一个简单的dae文件。我希望其中一些节点是SCNNode - MySCNNode的子类。
MySCNNode *node = [scnView.scene.rootNode childNodeWithName:@"Box1" recursively:YES];
//additional initialization goes here 尝试转换到(MySCNNode *)。
但这不管用。“节点”仍然是一个SCNNode。为什么?
我需要向SCNNode添加一些属性和方法。所以我把SCNNode子类化了。我希望场景中的节点(从dae导入)具有属性和行为。场景中的节点总是SCNNode。我希望它是MySCNNode级的。
发布于 2015-05-15 19:41:06
我知道需要一个子类。我明白为什么这是不典型的。在我的例子中,我正在创建一个RTS并创建它的“任务编辑器”,这样我就可以在搅拌器中获取一个充满各种对象的场景,并在编辑器中构建自定义场景。所以我需要知道什么时候瓷砖是可建造的,可通过的(以及在哪一层),等等。这可能不是完美的,但它应该能工作:
+(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
复制相似问题