ios - Get material by name in SceneKit -


i have imported collada .dae file scenekit. can see in scene editor/inspector there list of entities , materials named materials. have no clue how ask these programatically.

i can ask material name geometry object if know 1 node , geometry uses it, so:

myscene.rootnode.childnodes[68].geometry?.materialwithname("carpaint") 

but these reusable materials used on many sub geometries, there should global index somewhere(?)

i have expected like

myscene.materialwithname("carpaint") 

what ended doing create extension scnnode , scnscene give me index materials:

import scenekit  extension scnscene {     func buildmaterialindex() -> dictionary<string, scnmaterial> {         return self.rootnode.buildmaterialindex()     } }  extension scnnode {     func ispartof(node: scnnode) -> bool {         return (node === self) || (parentnode?.ispartof(node) ?? false)     }      private class _dictbox {         var dict = dictionary<string, scnmaterial>()     }     private func _populatematerialindex(dictbox: _dictbox, node: scnnode) {         if let g = node.geometry {             m in g.materials {                 if let n = m.name {                     dictbox.dict[n] = m                 }             }         }         n in node.childnodes {             _populatematerialindex(dictbox, node: n)         }     }     func buildmaterialindex() -> dictionary<string, scnmaterial> {         let dictbox = _dictbox()         _populatematerialindex(dictbox, node: self)         return dictbox.dict     } } 

Comments

Popular posts from this blog

Spring Boot + JPA + Hibernate: Unable to locate persister -

go - Golang: panic: runtime error: invalid memory address or nil pointer dereference using bufio.Scanner -

c - double free or corruption (fasttop) -