Reputation: 4166
I have a .scn
file in a folder in the Documents
folder in the iPhone. I've been trying to use SCNSceneSource
to turn the .scn
file as a SCNNode
//fileDestFolderURL is the folder that holds the .scn file
let sceneSource = SCNSceneSource(url: fileDestFolderURL, options: [:])
let scene = sceneSource?.scene(options: [:])
print(scene) //prints nil
print(scene?.rootNode) //prints nil
However, I keep getting nil
:(
My ultimate goal is to take the SCNNode
and add it to an ARSCNView
.
If anyone could provide their input it would be greatly appreciated!
Upvotes: 2
Views: 1213
Reputation: 13462
You should use SCNScene.init(url:options:)
instead of SCNSceneSource
(which is mostly meant for Collada files).
Upvotes: 3
Reputation: 1142
I'm using Objective-C to accomplish what you're asking. Here is some translated code that might help you. Here is an example with a Chair .scn model. I've noticed htat it is better to have the .scn file in the Models.scnassets folder
class Chair {
func loadModel() {
let virtualObjectScene = SCNScene(named:"Models.scnassets/chair/chair.scn"")
let wrapperNode = SCNNode()
for child: SCNNode in virtualObjectScene?.rootNode?.childNodes {
wrapperNode.addChildNode(child)
}
addChildNode(wrapperNode)
}
}
What I do is instantiate an object of this Chair class and then call loadModel on this object. After that I can just add it as a child node to the scene's root node and it appears in the scene.
Upvotes: -1