2
votes

I have a scene.scn file which contains a car.dae model. Here is the image:

enter image description here

I have the following code to load the scene.

override func viewDidLoad() {
        super.viewDidLoad()

        // Set the view's delegate
        sceneView.delegate = self

        // Show statistics such as fps and timing information
        sceneView.showsStatistics = true

        // Create a new scene

        let scene = SCNScene(named: "art.scnassets/scene.scn")!

        // Set the scene to the view
        sceneView.scene = scene
    }

I do not see the car being loading in the scene. Any ideas?

3
How big is the car? If you're looking in the Xcode scene editor where you took your screenshot, there should be bounding box info in the inspector. Also, you probably want to reorient your model so that Y is up.rickster
I can get the car to be displayed. I removed the camera and now it works! The other problem is that the car moves with the user movement. I want the car to be fixed at one location so I can move around and look at the car in different angles.john doe
I have the same issue. I think it has something to do with my model because other scn files work.Castles
I fixed it. The problem was the size. I adjusted the scale of the model and made is much small and then it started to work properly.john doe

3 Answers

5
votes

The following workflow produces repeatable results for me when exporting a 3D model from SketchUp Make 2017 (I use the Simple Template - Meters for drawing) to Xcode 9.0:

  1. In Xcode, create a SceneKit asset catalog: Create an assets catalog and change the extension to .scnassets before saving.

  2. In Xcode, in the asset catalog Settings, ensure that Always use the Y-up axis is not checked. This setting is buggy; while it works during runtime, it isn't taken into account by the Scene Editor.

  3. In SketchUp, export the model using Export 3D Model... and select the file format COLLADA File (*.dae). Export it to the .scnassets folder of the asset catalog (or a subfolder thereof).

    Hint: If you export somewhere else, use the Finder to copy or move the files. Don't drag-and-drop the exported model to Xcode, as it would only create a reference to the model and you would lose the textures on the way, as they are referenced in the .dae file by a relative path.

  4. In Xcode, create a SceneKit Scene File: First, select the project and create a New file with the template SceneKit Scene File there; Save it in the .scnassets folder; Then delete the file (Remove reference) from your project, so that it is referenced only in the .scnassets folder.

    Hint: You can't create a .scn file directly in the asset catalog, as the New file feature creates an empty file that the Scene Editor won't recognize, even if you rename it with the .scn extension.

  5. Embed the .dae file in the scene and fix the axes:

    a. Open the .scn file.

    b. Drag-and-drop the .dae file to the scene. This creates a reference to the model. Ensure that the reference to the model is selected.

    c. In the Node Inspector, under Transforms, select the Editing space: Local.

    d. Set the local Position to x: 0, y: 0, z: 0 (or whatever position is needed).

    e. Set the local Euler angles to x: -90, y: 0, z: 0. Now, the object is oriented as expected, e.g. its front is displayed when the point of view Front is selected in the toolbar at the bottom of the scene editor.

    f. Set the local Scale to x: 0.0254, y: 0.0254, z: 0.0254. I assume that the .dae file import expects sizes in inches.

    g. Still in the Node Inspector, under Transforms, select the Editing space: World. Check the size of the Bounding Box. I assume that meters are used as measurement unit here. Save the changes.

1
votes

There's a flag in Xcode's scnassets inspector to set which axis is "up". In SceneKit, Y is up. IIRC SketchUp uses Z up by default.

0
votes

Tip: I found for all the collada (dae) models created by SketchUp you need to adjust the Euler x-axis to -90 in the scene editor In order to get the model the right way up when you load it.