Reputation: 61
I am trying to create an SCNNode in scene kit based on a 2D jpg image. This image is to be placed in another 3D SCNNode. I have tried using .background.contents on my scene but this is not what i'm looking for. Any idea of how i can do that? Thanks!
This is my code:
@IBOutlet weak var sceneView: ARSCNView!
in the viewDidLoad method:
let scene = SCNScene()
sceneView.scene = scene
in viewWillAppear:
let ship = SpaceShip()
ship.loadModal()
ship.position = SCNVector3(0, 0, Double(-1.5))
sceneView.scene.rootNode.addChildNode(ship)
this is the class Spaceship:
class SpaceShip: SCNNode {
func loadModal(){
let virtualObjectScene = SCNScene(named: "ship.scn")!
let wrapperNode = SCNNode()
for child in virtualObjectScene.rootNode.childNodes{
wrapperNode.addChildNode(child)
}
self.addChildNode(wrapperNode)
}
}
Upvotes: 3
Views: 4430
Reputation: 31
It work for me
let node = SCNNode(geometry: SCNSphere(radius: 0.01))
node.geometry?.materials.first?.diffuse.contents = color
node.physicsBody? = .static()
node.name = name
node.physicsBody?.categoryBitMask = MaskNum.barrier.rawValue
node.geometry?.materials.first?.diffuse.contents = UIImage(named: "Circle")
node.position = SCNVector3(0.0, 0.0, -5.0)
sceneView.pointOfView?.addChildNode(node)
Upvotes: 1
Reputation: 148
You can do it from the inspector. On any 3d object just go to the material properties and then change the diffuse property to an image, simple as that
Upvotes: 2