[swift4] How to put dae file which downloaded from Internet, on scenekit
How to put dae file which downloaded from Internet, on scenekit, is below
目次
Convert dae file by xcode command
Need to convert dae file by xcode before put into scenekit.
so before uploading to your server, You have to convert dae file by below command on console.
Open console, move to dae file folder, convert your folder which dae file located
/Applications/Xcode.app/Contents/Developer/usr/bin/copySceneKitAssets ./ -o ./optimized
Once complete to convert, make sure that “./optimized” which pointed on command are created.
and in this folder, converted dae file should be created.
Reference :
BTW, on above reference site, described to create “product–1.scnassets” folder.
but no need specifically “product–1.scnassets” folder.
Can convert any name folder. no need “scnassets” name on your folder.
Then, can’t download .dae file directly. you should compress dae file to zip file.
after download zip file, un-zip zip file to dae file
[swift4] How to install SSZipArchive for un-zip file downloaded
Put dae file on scenekit
how to put dae file on scenekit is below.
“filepath” is URL which dae file located on device.
Need to add “file://” on top of filepath.
let sceneSource: SCNSceneSource = SCNSceneSource(url: NSURL(string: "file://"+filepath)! as URL, options: nil)! //List identifier List print(sceneSource.identifiersOfEntries(withClass: SCNNode.self)) let node = sceneSource.entryWithIdentifier("identifier", withClass: SCNNode.self) as! SCNNode scene.rootNode.addChildNode(node)
Or
let scene = SCNScene(named: "file://"+filepath) let node = scene!.rootNode.childNodes[0] scene.rootNode.addChildNode(node)
Or
let node:SCNReferenceNode = SCNReferenceNode(url: NSURL(string: "file://"+filepath)! as URL)! node.load() scene.rootNode.addChildNode(node)
Pingback: [swift4] How to paste texture on dae node on scenekit | BlueBear I/O
Pingback: [xcode] Adjust the scale of dae file downloaded from Internet. | BlueBear I/O