0

I'm trying to bind the position of a node - in this case, my pointOfView node - to a text field on macOS (but I guess it would be the same on iOS)

I can bind (via .bind or Storyboard) e.g. scnView.pointOfView.camera.fieldOfView. But I can't bind scnView.pointOfView.position.x

I can, however, bind scnView.pointOfView.position. But that doesn't seem useful for the text field.

Details

Here's what I get with

field.bind(.value, to: self, withKeyPath: "scnView.pointOfView.position.x", options: nil)

2019-01-11 11:54:13.987696+0100 Scenekit Test Template[45791:1781975] Failed to set (contentViewController) user defined inspected property on (NSWindow): [ valueForUndefinedKey:]: this class is not key value coding-compliant for the key x.

And here's binding just the .position

enter image description here

Morten J
  • 814
  • 10
  • 21

1 Answers1

0

You can always use value transformer to get specific component of a compound value. Something like this:

field.bind(.value, to: self, withKeyPath: "scnView.pointOfView.position",
    options: [.valueTransformer: PositionXValueTransformer()])

Where ValueTransformer might look like this:

class PositionXValueTransformer: ValueTransformer {
    override class func transformedValueClass() -> AnyClass {
        return NSString.self
    }

    override class func allowsReverseTransformation() -> Bool {
        return false
    }

    override func transformedValue(_ value: Any?) -> Any? {
        guard let position = value as? SCNVector3 else {
            return ""
        }

        return "\(position.x)"
    }
}
Konstantin Oznobihin
  • 5,234
  • 24
  • 31