1

I want to place an obj-3D-Model with ARKit and SceneKit.

That's the model I'm using: https://free3d.com/3d-model/chest-50529.html

I'm using the following code:

private func createChestFromScene(_ position: SCNVector3) -> SCNNode? {
    guard let url = Bundle.main.url(forResource: "art.scnassets/Models/chest", withExtension: "obj") else {
        NSLog("Could not find door scene")
        return nil
    }
    guard let node = SCNReferenceNode(url: url) else { return nil }

    node.load()

    // Position scene
    node.position = position

    return node
}

However, I get the following error: OBJ file has no faces.

Why? - Thanks.

Pascal
  • 2,590
  • 3
  • 21
  • 46
  • I don't have an answer for you yet, but I just ran into the same problem. I stripped down the obj file in text editor to contain only the faces and vertices and it still give the same error. While others load fine. I will do some tests with smaller models to see if I can track down the issue. I've noticed including 3D assets as DAE files works much better (obj imports in model io have additional issues) so if you can convert the file that would be an easy way to avoid the problem. – Xartec Jan 20 '18 at 19:53

1 Answers1

1

The problem lies in the encoding of the obj file. In particular, the problem is the carriage return difference.

In a Terminal session, run the following command: file testcube.obj (where test cube is your model name)

The result for files that will cause the error you mentioned is: testcube.obj: ASCII text, with CR line terminators

After removing the CR line terminators the result of the file command is: testcube.obj: ASCII text

The latter opens correctly in XCode and Scenekit and Model IO.

I simply copied a empty new line and replaced the CR with a new line manually but see the following answer on how you can use mac2unix command instead: https://stackoverflow.com/a/14080318/7426374

Xartec
  • 2,369
  • 11
  • 22