This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension Array where Iterator.Element == CGFloat { | |
var average: CGFloat? { | |
guard !isEmpty else { | |
return nil | |
} | |
var ret = self.reduce(CGFloat(0)) { (cur, next) -> CGFloat in | |
var cur = cur | |
cur += next | |
return cur |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension SCNNode { | |
func setUniformScale(_ scale: Float) { | |
self.scale = SCNVector3Make(scale, scale, scale) | |
} | |
func renderOnTop() { | |
self.renderingOrder = 2 | |
if let geom = self.geometry { | |
for material in geom.materials { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension SCNVector3 { | |
init(_ vec: vector_float3) { | |
self.x = vec.x | |
self.y = vec.y | |
self.z = vec.z | |
} | |
/** | |
* Returns the length (magnitude) of the vector described by the SCNVector3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension SCNMaterial { | |
static func material(withDiffuse diffuse: Any?, respondsToLighting: Bool = true) -> SCNMaterial { | |
let material = SCNMaterial() | |
material.diffuse.contents = diffuse | |
material.isDoubleSided = true | |
if respondsToLighting { | |
material.locksAmbientWithDiffuse = true | |
} else { | |
material.ambient.contents = UIColor.black |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension CGPoint { | |
init(_ size: CGSize) { | |
self.x = size.width | |
self.y = size.height | |
} | |
init(_ vector: SCNVector3) { | |
self.x = CGFloat(vector.x) | |
self.y = CGFloat(vector.y) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension CGSize { | |
init(_ point: CGPoint) { | |
self.width = point.x | |
self.height = point.y | |
} | |
func friendlyString() -> String { | |
return "(\(String(format: "%.2f", width)), \(String(format: "%.2f", height)))" | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension CGRect { | |
var mid: CGPoint { | |
return CGPoint(x: midX, y: midY) | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import ARKit | |
extension ARSCNView { | |
func setup() { | |
antialiasingMode = .multisampling4X | |
automaticallyUpdatesLighting = false | |
preferredFramesPerSecond = 60 | |
contentScaleFactor = 1.3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import SceneKit | |
public class LineNode: SCNNode { | |
// Properties | |
var startPoint: SCNVector3! | |
var endPoint: SCNVector3! | |
var radius: CGFloat! | |
var color: UIColor! | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
OlderNewer