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

Dynamically load Collada files in SceneKit at runtime

BTW, on above reference site, described to create “product1.scnassets” folder.

but no need specifically “product1.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)

2 thoughts on “[swift4] How to put dae file which downloaded from Internet, on scenekit

コメントを残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です