Reputation: 11052
I need to wrap the 3d object (scene
) with an image. Something like this:
I am using the following code:
let imageMaterial = SCNMaterial()
let image = UIImage(named: "temp_flow_image")
imageMaterial.diffuse.contents = image
let objectScene = SCNScene(named: "art.scnassets/frame.scn")
let objectNode: SCNNode = objectScene!.rootNode.childNode(withName: "frame", recursively: true)!
objectNode.geometry?.firstMaterial?.diffuse.contents = imageMaterial
objectNode.position = SCNVector3(0,0,-4)
let scene = SCNScene() // Main scene of the app
self.sceneView.scene = objectScene!
The whole process would be like this:
Load the 3d
object as a SCNNode
and wrap the image around it programmatically. I can see the 3d object but not the image over it. What I am doing wrong here? Can't we edit the geometry part of scene
pragmatically?
I can wrap the image around SCNBox
or any other predefined shape in arkit
but not with the external 3d
object
Upvotes: 0
Views: 279
Reputation: 11052
Following code is working :
self.sceneView.scene.rootNode.enumerateChildNodes { (node, _) in
if(node.name == "box") {
parentNode = node
let geometry = parentNode.geometry
geometry?.firstMaterial?.diffuse.contents = imageToDisplay
parentNode.position = SCNVector3Make(0, 0, -2.9)
let boxShape:SCNPhysicsShape = SCNPhysicsShape(geometry: geometry!, options: nil)
parentNode.physicsBody = SCNPhysicsBody(type: .static, shape: boxShape)
parentNode.physicsBody?.restitution = 1
}
}
sceneView.scene.rootNode.addChildNode(parentNode)
I created scene box
in Xcode
Upvotes: 1