Skip to content

Instantly share code, notes, and snippets.

@levantAJ
Last active October 20, 2021 15:01
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save levantAJ/0cbd0ea39901628c172de52f8880784f to your computer and use it in GitHub Desktop.
Save levantAJ/0cbd0ea39901628c172de52f8880784f to your computer and use it in GitHub Desktop.
Create SCNNode from USDZ file
class USDZNode: SCNReferenceNode {
init?(
name: String,
position: SCNVector3? = nil,
scale: SCNVector3? = nil,
pivot: SCNMatrix4? = nil
) {
guard let usdzURL: URL = Bundle.main.url(forResource: name, withExtension: "usdz") else { return nil }
super.init(url: usdzURL)
if let scale: SCNVector3 = scale {
self.scale = scale
}
if let position: SCNVector3 = position {
self.position = position
}
if let pivot: SCNMatrix4 = pivot {
self.pivot = pivot // the billboard look's direction
}
self.load()
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment