3

I am newbie in ARKit and do small project add object to plane.

I am follow step in Apple demo project: Handling 3D Interaction and UI Controls in Augmented Reality.

If I load scn model (or dae, obj) and place in plane use add anchor it work perfect.

But when I change use USDZ model(download from Apple) to load and place it alway above my head. I change use add child node and set position but not working, same result as add anchor.

    // Test add usdz object
    guard let url = Bundle.main.url(forResource: "wheelbarrow", withExtension: "usdz"),
        let object = VirtualObject(url: url) else {
            print("Error usdz file")
            return
    }

    // Add Child Node not working
    //        let object = obj.clone()
    //        object.load()
    //        object.position = focusSquare.position
    //        sceneView.scene.rootNode.addChildNode(object)

    self.virtualObjectLoader.loadVirtualObject(object, loadedHandler: { [weak self] loadedObject in
        do {
            print("Load Virtual Object:\(object.referenceURL.absoluteString)")
            let scene = try SCNScene(url: object.referenceURL, options: nil)
            self?.sceneView.prepare([scene], completionHandler: { _ in
                DispatchQueue.main.async {
                    self?.placeVirtualObject(loadedObject)
                    loadedObject.isHidden = false
                }
            })
        } catch {
            print("Error: \(error)")
            fatalError("Failed to load SCNScene from object.referenceURL")
        }
    })
Andy Jazz
  • 49,178
  • 17
  • 136
  • 220
Quyet Nguyen
  • 118
  • 8

1 Answers1

1

By default the scale of WheelBarrow.usdz file is huge.

enter image description here

You need to scale down a model to a value of 0.025 (for all three axis):

wheelBarrowNode.scale = SCNVector3(x: 0.025, y: 0.025, z: 0.025)

enter image description here

Hope this helps.

Andy Jazz
  • 49,178
  • 17
  • 136
  • 220
  • Thanks. I have a question more? scn vs usdz is better, should use usdz in scene or it better in quick look. Yesterday I read doc and sample ARKit 3.0 and scn still used in sample Apple: Handling 3D Interaction and UI Controls in Augmented Reality – Quyet Nguyen Jun 06 '19 at 04:43
  • 1
    `usdz` is a file format for 3D geometry and corresponding textures by Pixar. SceneKit also supports `dae`, `abc`, and `obj` file formats. `SCN` is a SceneKit's scene file where all the geometry of your app should be. – Andy Jazz Jun 06 '19 at 05:26
  • 1
    and this – https://stackoverflow.com/questions/48119378/which-format-file-for-3d-model-scenekit-arkit-better-to-use/55879013#55879013 – Andy Jazz Jun 06 '19 at 05:40