Created
July 24, 2021 15:31
-
-
Save TachibanaKaoru/5b0c9e6e4538476f579d21abdc98503a to your computer and use it in GitHub Desktop.
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 | |
import PlaygroundSupport | |
var arView = ARSCNView(frame: CGRect(x: 0, y: 0, width: 300, height: 300)) | |
arView.autoenablesDefaultLighting = true | |
let scene = SCNScene() | |
arView.scene = scene | |
let configuration = ARWorldTrackingConfiguration() | |
arView.session.run(configuration) | |
PlaygroundPage.current.liveView = arView | |
// cone nodeの作成 | |
let cone = SCNCone(topRadius: 0.0, bottomRadius: 0.03, height: 0.1) | |
let coneNode = SCNNode(geometry: cone) | |
coneNode.position = SCNVector3(0.0, 0.02, -0.25) | |
cone.firstMaterial?.diffuse.contents = UIColor.systemTeal | |
cone.firstMaterial?.specular.contents = UIColor.white | |
coneNode.rotation = SCNVector4(x: 0.0, y: 0.0, z: 1.0, w: 0.0) | |
var conePivot = SCNMatrix4MakeTranslation(0.0, 0.02, 0.0) | |
coneNode.pivot = conePivot | |
scene.rootNode.addChildNode(coneNode) | |
// capsule nodeの作成 | |
let capsule = SCNCapsule(capRadius: 0.03, height: 0.08) | |
let capsuleNode = SCNNode(geometry: capsule) | |
capsule.firstMaterial?.diffuse.contents = UIColor.systemPink | |
capsule.firstMaterial?.specular.contents = UIColor.white | |
capsuleNode.rotation = SCNVector4(x:1.0, y:0.8, z:0.0, w:0.0) | |
capsuleNode.position = SCNVector3(0.0, 0.05, -0.3) | |
scene.rootNode.addChildNode(capsuleNode) | |
// cone node のアニメーションの設定 | |
var spinAnimation = CABasicAnimation(keyPath: "rotation.w") | |
spinAnimation.repeatCount = HUGE | |
spinAnimation.toValue = Double.pi * 2.0 | |
spinAnimation.duration = 4.0 | |
spinAnimation.autoreverses = true | |
coneNode.addAnimation(spinAnimation, forKey: "spin animation") | |
// capsule node のアニメーションの設定 | |
var moveAnimation = CABasicAnimation(keyPath: "position.y") | |
moveAnimation.repeatCount = HUGE | |
moveAnimation.toValue = 0.2 | |
moveAnimation.duration = 1.0 | |
moveAnimation.autoreverses = true | |
capsuleNode.addAnimation(moveAnimation, forKey: "move animation") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment