14
votes

I am able to export meshes created in Blender for use in SceneKit by using the COLLADA/.dae format - however no textures show up on iOS device.

Also, Preview on OS X won't open any COLLADA file exported from Blender - yet the sidebar preview does show the mesh. What are the options needed at export to make this work?

3
I think you need to tell us more about how you are exporting these textures. Also, if preview can't even open the textures, then this sounds more like a issue with Blender than an issue with Scene Kit.David Rönnqvist
I have been looking around for a tutorial or explanation on how to export from Blender to SceneKit but haven't really found anything. This text is interesting, but old: iphonedevelopment.blogspot.jp/2012/08/… So far I have just tried to export from Blender to COLLADA, changing some of the export options regarding COLLADA - at first it didn't export the one texture file I was playing with but got it to do that later - it puts it in the same folder. However I just get the results as in my question.Jonny
The template "ship" if you start a scenekit game in Xcode is defined in "ship.dae", opening up the xml file reveals that Apple used "SceneKit Collada Exporter v1.0" to export it - that looks like a tool of their own. Makes you wonder from what tool/format they exported in the first place, maybe it's 3dsmax, Maya or something. Collada version is 1.4.1, same as Blender. I'll go ahead and look at what is different...Jonny
One more note: Apple's ship.dae has Y up, Blender has Z up. Maybe it breaks things.Jonny

3 Answers

25
votes

Create a scnassets folder first (not required but useful)

  1. Create a folder on your desktop and give it an extension of ".scnassets"

  2. Put your collada(.dae) file along with any textures you will be using in it.

  3. Drag the folder into your project and save as copy like usual.

  4. Click on your scnassets folder and you will see a checked box (if not check it) for converting to a "y" up axis.

Assigning textures to your scene model

  1. Click on your collada(.dae) file inside your project in xcode.

  2. You should see your scene and on its left side a list of cameras, lights, materials, and such. This is your scene tree.

  3. Open the materials tab and click on one of your materials.

  4. On the right hand side in the inspection window click on the blue ball shaped icon(Material inspector) to view the diffuse, specularity, and such of that one material.

  5. Click on the diffuse tab and when it opens you should have an option of colors and your textures within your project. Select the texture you used on your model within 3d program. As long as you UV unwrapped them properly in your 3D program, they should apply instantly within your scene view.

What if I want to change my material after loading my scene? Glad you asked!

To do this we must use entryWithIdentifier method of SCNSceneSource class. I am going to use swift here because it is awesome! Here we go...

  1. Get the url of your scene(.dae) like so...

    let url = NSBundle.mainBundle().URLForResource("YourFolder.scnassets/yourScene", withExtension "dae")
    
  2. Now lets put that url to use...

    let source = SCNSceneSource(URL: url, options: nil)
    
  3. Click on your .dae and under Scene Graph is list of items one of which is your geometry. It will have a tee kettle just to the right of it signifying so. We are going to use its name here. Let say your geometry's name is Geo. Use it like so...

    let yourGeometry = source.entryWithIdentifier("Geo", withClass: SCNGeometry.self) as SCNGeometry
    
  4. Now we have a source attatched to a SCNNode called yourGeomerty. Lets create a new material with a UIColor like so...

    let newMaterial = SCNMaterial()
    newMaterial.diffuse.contents = UIColor.redColor()
    
  5. Finally we will switch out the old material with the newMaterial like so...

    yourGeometry.geometry.replaceMaterialAtIndex(0, withMaterial: newMaterial)
    

Play around with it and other indexes if you have more than one material. You can also use the UIImage class to use another texture instead of a color.

TIP If you want to add to or delete something from your scnassets folder, navigate to your project folder to do so and not xcode. This took me a while to figure out so thought I would save everyone the trouble.

4
votes

Collada files don't embed textures, they only have references to them. Make sure that your textures are reachable from the collada file when you open it in Preview and make sure to include the textures in the app bundle when building an app.

4
votes

3 things I had to do to make it work.

  1. Make sure images are packed in the .blend file (this is an option in UV editor)

  2. when you export, the file will not automatically include the uv's or the materials. there is a checkbox to include the UV's and Materials in the DAE. I missed this as well when doing it.

  3. This one you only need if your putting in a playground. The dae isn't quite applized, but i was able to use their scntool in the developer tools to export a dae that is. here is a sample command line that i used.

./scntool --convert ~/Documents/Art/BlenderArt/tableandappleUV.dae --format c3d --output ~/Documents/Table5.dae

notice the c3d format. use that and your playground can now also recognize the dae. (One other note: if you want to used the dae in the playground you need to put in resources folder of the playground)