SCNBox
renders the textures correctly, but SCNCylinder
seems to mirror the base and top textures. The following code reproduces the issue (just set the image
variable to the name of the image you're using, in this case an image with the number 2 in it):
class GameViewController: NSViewController {
let image = "art.scnassets/image.heic"
override func viewDidLoad() {
super.viewDidLoad()
let scene = SCNScene(named: "art.scnassets/ship.scn")!
let cameraNode = SCNNode()
cameraNode.camera = SCNCamera()
scene.rootNode.addChildNode(cameraNode)
cameraNode.position = SCNVector3(x: 0, y: 3, z: 3)
let scnView = self.view as! SCNView
scnView.scene = scene
let node = SCNNode(geometry: SCNCylinder(radius: 0.5, height: 1))
node.geometry!.materials = [SCNMaterial(), SCNMaterial(), SCNMaterial()]
node.geometry!.materials[1].diffuse.contents = image
node.geometry!.materials[2].diffuse.contents = image
node.position.x = -1
node.runAction(.repeatForever(.rotate(by: 1, around: SCNVector3(x: 1, y: 0, z: 0), duration: 1)))
scene.rootNode.addChildNode(node)
let node2 = SCNNode(geometry: SCNBox(width: 1, height: 1, length: 1, chamferRadius: 0))
node2.geometry!.materials = [SCNMaterial(), SCNMaterial(), SCNMaterial(), SCNMaterial(), SCNMaterial(), SCNMaterial()]
node2.geometry!.materials[4].diffuse.contents = image
node2.geometry!.materials[5].diffuse.contents = image
node2.position.x = 1
node2.runAction(.repeatForever(.rotate(by: 1, around: SCNVector3(x: 1, y: 0, z: 0), duration: 1)))
scene.rootNode.addChildNode(node2)
cameraNode.look(at: SCNVector3(x: 0, y: 0, z: 0))
}
}