0 Replies - 276 Views - Last Post: 27 April 2019 - 02:31 PM Rate Topic: -----

#1 sashachca   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 27-April 19

How do I use an NSImage as material of an SCNGeometry shape correctly?

Posted 27 April 2019 - 02:31 PM

I got a task in the university to add a picture as texture to the SCNGeometry Octahedron. It's my first project in Swift.

There are lot's of advices for the UIKit with UIImage class, but I'm using AppKit for macos and NSImage class. And none of the options I found in the web haven't worked for me yet. Probably I misunderstand something fundamental. Well, firstly I dragndroped a picture named "sims.jpg" to my project folder and to art.scnassets folder. And also added them with File → Add files to "art.scnassets" and general folder. And did nothing with Assets.xcassets.

This is the full code: pastebin.com/vw4CUYRm. Function called createOctahedron() is where I would like to add material to the shape. I haven't left there any of my tryings. So here they are:

№1
let imageMaterial = SCNMaterial()
let image = NSImage(named: NSImage.Name("sims"))
imageMaterial.diffuse.contents = image
geometry.materials = [imageMaterial, imageMaterial, imageMaterial, imageMaterial, imageMaterial, imageMaterial, imageMaterial, imageMaterial] 

№2
node.geometry?.firstMaterial?.diffuse.contents = NSImage.Name("sims") 

Please help me make it done. So far Xcode outputs just a rotating octahedron with no additional texture, no errors either

Is This A Good Question/Topic? 0
  • +

Page 1 of 1