eddieplaschke
eddieplaschke

Reputation: 11

Hot to use material I created in one scn object in another one?

I got an object I edited in SceneKit and created a material for it. Now I want to use the same material for another scn Object. I am just using the SceneKit for editing the objects.

Tried to put them in the same xcode project but it is still not possible to choose the material.

Not working with code, only the graphical user interface.

No error messages, just not possible to share the material for me.

Upvotes: 1

Views: 138

Answers (1)

Andy Jazz
Andy Jazz

Reputation: 58143

You're able to do that using the following code:

let material = SCNMaterial()
material.diffuse.contents = UIImage(named: "art.scnassets/diffuse.jpg")
material.emission.contents = UIColor.orange
material.normal.contents = UIImage(named: "art.scnassets/normals.png")
    
let sphereNode = SCNNode()
sphereNode.geometry = SCNSphere(radius: 1)
sphereNode.geometry?.firstMaterial = material
scene.rootNode.addChildNode(sphereNode)
    
let planeNode = SCNNode()
planeNode.geometry = SCNPlane(width: 3, height: 3)
planeNode.geometry?.firstMaterial = material
scene.rootNode.addChildNode(planeNode)

Upvotes: 0

Related Questions