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?
Create a scnassets folder first (not required but useful)
Create a folder on your desktop and give it an extension of ".scnassets"
Put your collada(.dae) file along with any textures you will be using in it.
Drag the folder into your project and save as copy like usual.
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
Click on your collada(.dae) file inside your project in xcode.
You should see your scene and on its left side a list of cameras, lights, materials, and such. This is your scene tree.
Open the materials tab and click on one of your materials.
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.
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...
Get the url of your scene(.dae) like so...
let url = NSBundle.mainBundle().URLForResource("YourFolder.scnassets/yourScene", withExtension "dae")
Now lets put that url to use...
let source = SCNSceneSource(URL: url, options: nil)
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
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()
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.
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.
3 things I had to do to make it work.
Make sure images are packed in the .blend file (this is an option in UV editor)
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.
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)
来源:https://stackoverflow.com/questions/25031774/including-textures-when-exporting-from-blender-to-collada-dae-format-for-use-in