Node's geometry (from DAE file) is nil only on production builds

201 views Asked by At

I have a 3D model that ALWAYS works fine on real device and simulator when compiled from Xcode even if setting as Release and with any optimization setting but when uploaded to TestFlight it's missing some materials.

After debugging (with TF builds because there's no way to reproduce locally) I found out that two of the nodes I'm using (the ones that look bad) have no geometry (they do have geometry locally).

Code I'm using:

self.scene = SCNScene(named: "model.scnassets/Body.dae")
self.scene?.rootNode.rotation = SCNVector4(1, 0, 0, 45.degreesToRadians)
let baseNode = self.scene?.rootNode.childNode(withName: "Body", recursively: true)
let bodyImageMaterial = SCNMaterial()
bodyImageMaterial.isDoubleSided = false
bodyImageMaterial.diffuse.contents = UIImage(named: "Body_Background")
baseNode?.geometry?.materials = [bodyImageMaterial]

baseNode?.geometry return nil on production, that's the part I can't figure out and thus the material is not applied. Also I wanna clarify that the geometry works as expected but it's using the default material since nothing is applied.

3

There are 3 answers

0
Andy Jazz On

Try to access a node’s children in the scene graph hierarchy via:

var childNodes: [SCNNode] { get }

In real code it looks like this:

let material = SCNMaterial()
material.diffuse.contents = UIColor.red

let ship = scene.rootNode.childNode(withName: "ship", recursively: true)!        
ship.childNodes[0].geometry?.materials = [material]

Sometimes it might be deeper in hierarchy:

someNode.childNodes[0].childNodes[0].geometry?.materials = [material]
0
Dante Puglisi On

I finally got it working by converting the .dae files into a .scn. Not sure what happens here since I have other .dae that work as expected.

0
Wiza On

Same issue here and I finally found a solution :

Instead of :

node.boundingBox

Use :

node.presentation.boundingBox