3

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)
    }
}
mei02
  • 61
  • 1
  • 4

2 Answers2

2

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

enter image description here

Joseph Hajjar
  • 138
  • 2
  • 12
1

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)
docbohanh
  • 31
  • 2
  • In iOS 11.2 there is a image rendering problem with this solution (imge is shown as black and red colors only), have you faced like this problem? – ondermerol Feb 08 '18 at 08:54