4
votes

I have a subclass "ExSCNNode" of SCNNode to add more properties and behavior to the SCNNode.

class ExSCNNode : SCNNode {
...
}

I than build a scene with a ExSCNNode.

let testnode = ExSCNNode()

When hittesting the scene:

// check what nodes are tapped
let p = gestureRecognize.location(in: scnView)
let hitResults = scnView.hitTest(p, options: [:])

// check that we clicked on at least one object
if hitResults.count > 0 {

for hit in hitResults {
let hitnode = hit.node
...

hitnode is a SCNNode not a ExSCNNode. But I want to get the ExSCNNode to access the advance functionality.

How do I get access to the subclass instead of the SCNNode class ?

1
You need to create it as an ExSCNNode. You have not included the code where it is created.Gary Makin
I create a scene of ExSCNodes. Just one in the example above addedBernd

1 Answers

5
votes

Just cast the object to your subclass:

// check what nodes are tapped
let p = gestureRecognize.location(in: scnView)
let hitResults = scnView.hitTest(p, options: [:])

for hit in hitResults {
    if let hitnode = hit.node as? ExSCNNode {

        …
    }