我有使用SceneView的Creat Cubes,我想消除Tap操作的多维数据集。怎么能实现呢?
这是我创建Cube的代码
SCNBox *Box = [SCNBox boxWithWidth:2.0 height:2.0 length:2.0
chamferRadius:Radius];
Box.firstMaterial.diffuse.contents = [UIColor whiteColor];
SCNNode *cubeNode = [SCNNode nodeWithGeometry:Box];
[ArrBoxNode addObject:cubeNode];
self.sceneView.backgroundColor = [UIColor redColor];
self.view.backgroundColor = [UIColor grayColor];
cubeNode.position = SCNVector3Make(4,0,0);
[scene.rootNode addChildNode:cubeNode];
self.sceneView.scene = scene;
[self.sceneView sizeToFit];
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [touches anyObject];
CGPoint touchPoint = [touch locationInView:self.sceneView];
SCNHitTestResult *hitTestResult = [[self.sceneView
hitTest:touchPoint options:nil] firstObject];
SCNNode *hitNode = hitTestResult.node;
for (SCNNode *node in ArrBoxNode) {
[node removeFromParentNode];
}
}
但我无法从Tap操作中删除Node。你能帮助我,并给出更好的建议,谢谢...... :)
答案 0 :(得分:1)
您需要使用[hitNode removeFromParentNode];
<强>代码强>
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [touches anyObject];
CGPoint touchPoint = [touch locationInView:self.sceneView];
SCNHitTestResult *hitTestResult = [[self.sceneView hitTest:touchPoint options:nil] firstObject];
SCNNode *hitNode = hitTestResult.node;
[hitNode removeFromParentNode];
}