Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set contents of scenekit background to cube map

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.

like image 526
user3765506 Avatar asked Jun 22 '14 21:06

user3765506


2 Answers

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.

like image 109
Toyos Avatar answered Sep 18 '22 01:09

Toyos


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")]
like image 27
LukeSideWalker Avatar answered Sep 19 '22 01:09

LukeSideWalker