1

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.

Andy Jazz
  • 49,178
  • 17
  • 136
  • 220
Dante Puglisi
  • 648
  • 7
  • 24

3 Answers3

0

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]
Andy Jazz
  • 49,178
  • 17
  • 136
  • 220
0

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.

Dante Puglisi
  • 648
  • 7
  • 24
0

Same issue here and I finally found a solution :

Instead of :

node.boundingBox

Use :

node.presentation.boundingBox
Wiza
  • 1
  • 1