I want to test the SCNNode whether overlap to other exist SCNNode. Therefore, I try to use
contactTestBetween
. But, I got crash. I cannot provide more crash information because I encounter "iPhone has denied the launch request" and must turn off debug executable.var node: SCNNode!
var node2: SCNNode!
@objc func handleTap(_ gesture: UITapGestureRecognizer) {
if(node == nil){
let center = gesture.location(in: gesture.view)
let boxCenter = CGPoint(x: center.x, y: center.y)
let arHitTestResult: [ARHitTestResult] = drawer.cameraView.hitTest(boxCenter, types: [.estimatedHorizontalPlane, .featurePoint])
if let result = arHitTestResult.first{
let transform: matrix_float4x4 = result.worldTransform
node = SCNNode()
let box = SCNBox(width: 0.3, height: 0.3, length: 0.3, chamferRadius: 0)
box.firstMaterial?.diffuse.contents = TLDarknet.labels_tl_color[0]
node.geometry = box
node.position = SCNVector3Make(transform.columns.3.x, transform.columns.3.y, transform.columns.3.z)
node.physicsBody = SCNPhysicsBody(type: .kinematic, shape: SCNPhysicsShape(geometry: box, options: nil))
node.physicsBody!.categoryBitMask = 2
node.physicsBody!.contactTestBitMask = 2
node.physicsBody!.collisionBitMask = 2
self.cameraView.scene.rootNode.addChildNode(node)
let pointer = SCNScene(named: "art.scnassets/pointer.dae")
let t1 = pointer!.rootNode.childNodes[2]
t1.scale = SCNVector3(0.3, 0.3, 0.3)
node2 = SCNNode()
let box2 = SCNBox(width: CGFloat(t1.boundingBox.max.x - t1.boundingBox.min.x), height: CGFloat(t1.boundingBox.max.y - t1.boundingBox.min.y), length: CGFloat(t1.boundingBox.max.z - t1.boundingBox.min.z), chamferRadius: 0)
box2.firstMaterial?.diffuse.contents = TLDarknet.labels_tl_color[1]
node2.addChildNode(t1)
node2.position = SCNVector3Make(transform.columns.3.x, transform.columns.3.y, transform.columns.3.z)
node2.physicsBody = SCNPhysicsBody(type: .kinematic, shape: SCNPhysicsShape(geometry: box2, options: nil))
node2.physicsBody!.categoryBitMask = 2
node2.physicsBody!.contactTestBitMask = 2
node2.physicsBody!.collisionBitMask = 2
self.cameraView.scene.rootNode.addChildNode(node2)
}
}else{
let center = gesture.location(in: gesture.view)
let boxCenter = CGPoint(x: center.x, y: center.y)
let arHitTestResult: [ARHitTestResult] = drawer.cameraView.hitTest(boxCenter, types: [.estimatedHorizontalPlane, .featurePoint])
if let result = arHitTestResult.first{
let transform: matrix_float4x4 = result.worldTransform
let pointer = SCNScene(named: "art.scnassets/pointer.dae")
let t1 = pointer!.rootNode.childNodes[2]
t1.scale = SCNVector3(0.3, 0.3, 0.3)
node2 = SCNNode()
let box2 = SCNBox(width: CGFloat(t1.boundingBox.max.x - t1.boundingBox.min.x), height: CGFloat(t1.boundingBox.max.y - t1.boundingBox.min.y), length: CGFloat(t1.boundingBox.max.z - t1.boundingBox.min.z), chamferRadius: 0)
box2.firstMaterial?.diffuse.contents = TLDarknet.labels_tl_color[1]
node2.addChildNode(t1)
node2.position = SCNVector3Make(transform.columns.3.x, transform.columns.3.y, transform.columns.3.z)
node2.physicsBody = SCNPhysicsBody(type: .kinematic, shape: SCNPhysicsShape(geometry: box2, options: nil))
node2.physicsBody!.categoryBitMask = 2
node2.physicsBody!.contactTestBitMask = 2
node2.physicsBody!.collisionBitMask = 2
self.cameraView.scene.rootNode.addChildNode(node2)
}
print("ok? ", self.cameraView.scene.physicsWorld.contactTestBetween(node.physicsBody!, node2.physicsBody!, options: nil))
}
}