Search code examples
swiftpngaugmented-realityscenekitarkit

ARKit – How to convert a PNG file into a OBJ file?


I am currently studying ARKit and I wish to display a 2d image in 3D environment. The image I want to display is a .png file.

Is there a way to convert this into an .obj file?


Solution

  • There's no way to convert a 2D .png raster file into 3D .obj geometry file. These formats are different like green apple and small button...

    Although, the simplest way to see your image in ARKit's or SceneKit's 3D environment is to assign it on a 3D plane as a texture. Here's how you can do it:

    @IBOutlet var sceneView: ARSCNView!
    
    sceneView.scene = SCNScene()
    
    let config = ARWorldTrackingConfiguration()
    sceneView.session.run(config)
    
    let node = SCNNode()
    node.geometry = SCNPlane(width: 1.0, height: 1.0)
    node.geometry?.firstMaterial?.isDoubleSided = true
    node.geometry?.firstMaterial?.diffuse.contents = UIImage(named: "dir/image.png")
    sceneView.scene.rootNode.addChildNode(node)