If you had different images, you would build another SCNMaterial object from each like this:
let material_L = SCNMaterial() material_L.diffuse.contents = UIImage(named: "CapL")
Here, CapL refers to the .png file that was saved in the Assets.xcassets folder of the project. After creating 6 such objects, you pass them to boxNode as follows:
boxGeometry.materials = [material_L, material_green_r, material_K, material_purple_r, material_g, material_j]
Note that "boxGeometry" will be better called "box" or "cube". In addition, it would be nice to do this work in a new class in your project, built as follows:
class BoxScene: SCNScene {
Which you would then call using modern Swift in your viewController viewDidLoad, for example:
let scnView = self.view as! SCNView scnView.scene = BoxScene()
(for this, let the operator work, go to Main.storyboard β View Controller Scene β View Controller β View β Identity icon Then, in the user class, change it from UIView to SCNView. Otherwise, you will receive an error message such as:
Unable to pass value of type "UIView" to "SCNView"
source share