How to use SCNFloor properties with Swift and Scenekit?

I cannot figure out how to access the properties of the SCeneFit SCNFloor class using Swift, in objective-c they do it like this:

SCNNode*floor = [SCNNode node];
floor.geometry = [SCNFloor floor];
((SCNFloor*)floor.geometry).reflectionFalloffEnd = 10;

This creates the floor, how can I get a "reflectionFalloffEnd"?

let levelFloor = SCNNode()
levelFloor.geometry = SCNFloor()

thank

EDIT Thanks for the quick answers that it works now.

+4
source share
2 answers

If you are in ObjC or Swift so that the compiler is pleased with you using the properties or methods SCNFloorfor the link, this link must be of type SCNFloor.

You can do this by casting:

// ObjC
((SCNFloor*)floor.geometry).reflectionFalloffEnd = 10;

// Swift
(levelFloor.geometry as SCNFloor).reflectionFalloffEnd = 10

, . ( , , ):

let floor = SCNFloor()
floor.reflectionFalloffEnd = 10
floor.reflectivity = 0.5
let floorNode = SCNNode(geometry: floor)
floorNode.position = SCNVector3(x: 0, y: -10.0, z: 0)
scene.rootNode.addChildNode(floorNode)
+7

(levelFloor.geometry as SCNFloor).reflectionFalloffEnd = 10 , Swift - !

- , as :), :

let levelFloor = SCNNode()
let levelFloorGeometry = SCNFloor()
levelFloor.geometry = levelFloorGeometry

levelFloorGeometry.reflectionFalloffEnd = 10
// and so on as this property of your SCNNode geometry needs to change throughout your app
+2

Source: https://habr.com/ru/post/1545746/


All Articles