Skip to content

Instantly share code, notes, and snippets.

@eugenebokhan
Created March 2, 2018 12:06
Show Gist options
  • Save eugenebokhan/d38973c27b4aec105b553718f5e7f1b0 to your computer and use it in GitHub Desktop.
Save eugenebokhan/d38973c27b4aec105b553718f5e7f1b0 to your computer and use it in GitHub Desktop.
Axes Node in SceneKit
import SceneKit
func createAxesNode(quiverLength: CGFloat, quiverThickness: CGFloat) -> SCNNode {
let quiverThickness = (quiverLength / 50.0) * quiverThickness
let chamferRadius = quiverThickness / 2.0
let xQuiverBox = SCNBox(width: quiverLength, height: quiverThickness, length: quiverThickness, chamferRadius: chamferRadius)
xQuiverBox.materials = [SCNMaterial.material(withDiffuse: UIColor.red, respondsToLighting: false)]
let xQuiverNode = SCNNode(geometry: xQuiverBox)
xQuiverNode.position = SCNVector3Make(Float(quiverLength / 2.0), 0.0, 0.0)
let yQuiverBox = SCNBox(width: quiverThickness, height: quiverLength, length: quiverThickness, chamferRadius: chamferRadius)
yQuiverBox.materials = [SCNMaterial.material(withDiffuse: UIColor.green, respondsToLighting: false)]
let yQuiverNode = SCNNode(geometry: yQuiverBox)
yQuiverNode.position = SCNVector3Make(0.0, Float(quiverLength / 2.0), 0.0)
let zQuiverBox = SCNBox(width: quiverThickness, height: quiverThickness, length: quiverLength, chamferRadius: chamferRadius)
zQuiverBox.materials = [SCNMaterial.material(withDiffuse: UIColor.blue, respondsToLighting: false)]
let zQuiverNode = SCNNode(geometry: zQuiverBox)
zQuiverNode.position = SCNVector3Make(0.0, 0.0, Float(quiverLength / 2.0))
let quiverNode = SCNNode()
quiverNode.addChildNode(xQuiverNode)
quiverNode.addChildNode(yQuiverNode)
quiverNode.addChildNode(zQuiverNode)
quiverNode.name = "Axes"
return quiverNode
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment