I am working on an app the creates a 3d mesh of users face. I am successful in generating data of a users face.
I want to programatically save this data in .dae format so that i could export my .dae file, edit that in 3d softwares like blender, and than further import it in my iphone and display that file in sceneview.
Long story short i want programatically save the data in .dae format. I am not able to find anything on internet about this.
If there could be another approach then please tell me.
SceneKit doesn’t natively read or write DAE format in iOS. (SceneKit reads/writes DAE only in macOS. When you ship a DAE in your app’s bundle resources, Xcode converts it to an iOS-optimized format at build time.)
Your best bet for exporting a mesh to common file formats from iOS is Model I/O. That framework supports several formats, but not DAE. If you’re just looking to output the ARFaceGeometry
mesh generated by ARKit, you don’t really need a format more complicated than OBJ, and Model I/O does that.
The gist:
Create an MDLMesh
from your vertex/index data. That’ll require MDLMeshBuffer
s for the vertex and texture coordinate data, and MDLSubmesh
es for the triangle index data. Or, if you already have the mesh in SceneKit, convert it with MDLMesh(scnGeometry:)
.
Create an empty MDLAsset
, and add your mesh to it as a child object.
Export the asset to a file. The filename extension of the URL you provide for writing the asset to determines the file format for export, so use a “.obj” filename if you want to write an OBJ file.
you can try the code below:
let scene2 = sceneView.scene
let documentsPath = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first!
let timeInterval = Date().timeIntervalSince1970 * 1000
let filename = String(format: "test_%d.dae", timeInterval)
let exportUrl = documentsPath.appendingPathComponent(filename)
scene2.write(to: exportUrl, options: nil, delegate: nil, progressHandler: nil);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With