I am new to SceneKit and created an object I added an image as texture to object but it is showing on both the side front and back .what I want is to display another image behind it .is that possible to add two texture for an object?
let scene = SCNScene()
var planet : SCNGeometry
let tempScene = SCNScene(named: "FrameOBJ.obj")
planet = tempScene!.rootNode.childNodes[0].geometry!
let material = SCNMaterial()
let url = URL(string: "www.imageasf.com/123.png")
let data = try? Data(contentsOf: url!) //make sure your image in this url does exist, otherwise unwrap in a if let check / try-catch
let image = UIImage(data: data!)
material.diffuse.contents = image
material.diffuse.wrapT = SCNWrapMode.mirror
material.diffuse.wrapS = SCNWrapMode.mirror
material.isDoubleSided = true
planet.materials = [material]
let planetNode = SCNNode(geometry: planet)
scene.rootNode.addChildNode(planetNode)
sceneView.cameraControlConfiguration.allowsTranslation = true
sceneView.allowsCameraControl = true
sceneView.scene = scene
I have done it by adding Material array .
let tempScene = SCNScene(named: "untitled.obj")
planet = tempScene!.rootNode.childNodes[0].geometry!
var image = UIImage()
let url = URL(string: "https://www.images123.jpg")!
//make sure your image in this url does exist, otherwise unwrap in a if let check / try-catch
var node = SCNNode()
do {
let data = try Data(contentsOf: url)
image = UIImage(data: data)!
node = SCNNode(geometry: SCNBox(width: 0.05, height: 1, length:1, chamferRadius: 0.5))
node.geometry?.firstMaterial?.diffuse.contents = image
// do something with data
// if the call fails, the catch block is executed
} catch {
print(error.localizedDescription)
}
let allMaterial = SCNMaterial()
allMaterial.diffuse.contents = UIImage(named: "woods.png")
let smallMaterial1 = SCNMaterial()
smallMaterial1.diffuse.contents = image
node.scale = SCNVector3(0.5,0.5,0.5)
node.geometry?.materials = [smallMaterial1,allMaterial,smallMaterial1,smallMaterial1,smallMaterial1,smallMaterial1];
scene.rootNode.addChildNode(node)
print(node.scale)
print(scene.rootNode.scale)
sceneView.cameraControlConfiguration.allowsTranslation = true
sceneView.allowsCameraControl = true
sceneView.scene = scene