I am trying to set the background contents of a scene to a skybox effect using about array of 6 images.
I have created the array of images in the correct order, I know I need to then use
+ (instancetype) materialPropertyWithContents:(id)contents
However I'm struggling to work out how and where exactly I use that class method to return the property containing the cube map.
SCNScene's "background" property is of the SCNMaterialProperty class. So you can directly set it's contents to an array of 6 images to setup your skybox (see SCNScene.h).
aScene.background.contents = @[@"Right.png", @"Left.png", @"Top.png", @"Bottom.png", @"Back.png", @"Front.png"];
Make sure your 6 images are square and with the same dimensions.
Swift 5.0 / iOS 14
Some changes in newer Swift versions:
// Be aware, that the order of the images is relevant, not the names, and
// "Front" means the background at the most negativ value of z-dimension
// (exactly where the default camera looks at)
background.contents = [UIImage(named: "Right"),
UIImage(named: "Left"),
UIImage(named: "Top"),
UIImage(named: "Bottom"),
UIImage(named: "Front"),
UIImage(named: "Back")]
// alternatively
background.contents = [UIImage(named: "east"),
UIImage(named: "west"),
UIImage(named: "sky"),
UIImage(named: "floor"),
UIImage(named: "north"),
UIImage(named: "south")]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With