2

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.

Andy Jazz
  • 49,178
  • 17
  • 136
  • 220

2 Answers2

2

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):

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

For additional reading use Apple Documentation:

Andy Jazz
  • 49,178
  • 17
  • 136
  • 220
0

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.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Sia
  • 63
  • 1
  • 9
  • I am not sure if you can put the URL directly in SCNReferenceNode, What I understood from my research is, you should save the file locally, get the URL of it and show. – Sia Jan 23 '20 at 13:53
  • thank you Can you please share your sample code I am tried but its not loading my files.If your not sharing the code just send you url that contains .dae file and textures – Gangireddy Rami Reddy Jan 23 '20 at 15:19
  • What do you get, do you get an error? Which part of the code do you need? well, you don't need to include the textures in your URL. Collada has the information itself. Make sure the step2 is done correctly without any error. Are you sure about it? if yes, save the zip on the "Documents" folder, unzip it there. go to the unzipped folder and pick the .dae file. At the end the modelUrl should look like: file:///var/mobile/Containers/Data/Application/7DVBACE2-9584-412A-AB38-661CE60BE98C/Documents/modelunzip/YYY_2019339_Internetworld/YYY_2019339_Internetworld.dae – Sia Jan 23 '20 at 18:11