How to load SCN or glTF model at runtime in ARKit app?

情到浓时终转凉″ 提交于 2020-02-23 04:00:43

问题


What is the best way to load a 3d model from a URL inside of iOS at runtime. I have tried this .scn and .gtlf models importer.

I am using this framework https://github.com/prolificinteractive/SamMitiAR-iOS I load the model like this:

let virtualObjectGLTFNode = SamMitiVirtualObject(gltfUrl: URL(string: 
   "https://raw.githubusercontent.com/KhronosGroup/glTF-Sample- 
    Models/master/2.0/Duck/glTF-Embedded/Duck.gltf")!, allowedAlignments: 
   [.horizontal])
virtualObjectGLTFNode.name = "Duck"

virtualObjectGLTFNode.setAnimationForVirtualObjectRemoving { (node, completed) in
    SceneKitAnimator.animateWithDuration(duration: 0.35 / 2, 
                                   timingFunction: .easeIn, 
                                       animations: {
        let transform = SCNMatrix4MakeScale(0.01, 0.01, 0.01)
        node.contentNode?.transform = transform
        }, completion: completed)
    }
return virtualObjectGLTFNode

like above i am loading different url from remote server please guide me How can i load 3d models from remote server.In which format i want take url.Please send any link have that scn files from remote server Thanks adavance.


回答1:


Seems that a url loader feature doesn't work in SamMitiAR framework. It says Work in Progress under Placing and Removing Virtual Objects section.

To know how dynamically load a model into ARKit app (when a model isn't accessible at compile-time), read this article (sorry, there's an Objective-C code):

  • Dynamically load Collada files in SceneKit at runtime

If you want to find out how to use different approaches when working with url, please read the following SO posts:

  • ARKit - How to load .scn and texture file from server URL

  • How to load a model and textures from a remote server using ARKit?

  • Swift Load A 3d Asset from URL Xcode

For additional reading use Apple Documentation:

  • SCNSceneSource - An object that manages the data-reading tasks...



回答2:


I can explain what I have done which is working now. I think we also have tried .gltf and .scn and did not get anything so we reached to the conclusion like this:

  1. Get a folder including Collada file(.dae) and all of the textures.

  2. As @AndyFedo mentioned as well, we have been through the steps of this solution. When you do not have the file at run time locally then you should go through this step.

  3. After converting the raw Collada folder to the desired one explained in that page with the help of copySceneKitAssets, I have zipped the new folder and put it on the server

  4. Then call the api, save the zip folder on the device, unzip the folder and search for the file with .dae file and get the path to this file. I named it modelUrl.

  5. let virtualObject = SamMitiVirtualObject(referenceNode: SCNReferenceNode.init(url:modelUrl as URL)! , allowedAlignments: [.horizontal])

That should work.



来源:https://stackoverflow.com/questions/59860657/how-to-load-scn-or-gltf-model-at-runtime-in-arkit-app

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!