나는 그것을 만드는 방법을 찾았습니다. 내 큰 실수였다 :
은 어떻게 든 (A lightNode
에 대한 조치가 호출 될 때 그냥, 아무 효과가 없습니다)
내가 SCNAction.move(to...)
를 통해 이동하려는 lightNode에 액세스 할 작동하지 않습니다. 대답은 종 방향 움직임 대신 회전을 사용하는 것입니다.
답은 lightNode 대신 제약 Node를 액세스하고있었습니다. 이 코드에서 cubeNode는 보이지 않는 centerPoint
으로 바뀝니다 (lightNode
이 보이는 제한 노드로). 그림자의 캔버스를 만들기 위해 boxNode
이 추가되었습니다. lightNode
은 centerPoint
에 추가해야하며 장면에는 추가하면 안됩니다.
변경된 viewDidLoad
-method가 있습니다. 이것을 확인하려면 Xcode를 열고 SceneKit 게임으로 새 프로젝트를 시작한 다음 viewDidLoad
을 다음 코드로 바꿉니다.
override func viewDidLoad() {
super.viewDidLoad()
// create a new scene
let scene = SCNScene(named: "art.scnassets/ship.scn")!
// create and add a camera to the scene
let cameraNode = SCNNode()
cameraNode.camera = SCNCamera()
scene.rootNode.addChildNode(cameraNode)
// place the camera
cameraNode.position = SCNVector3(x: 0, y: 0, z: 15)
// create and add a light to the scene
let centerPoint = SCNNode.init()
centerPoint.position = SCNVector3Make(0, 0, 0)
scene.rootNode.addChildNode(centerPoint)
let light = SCNLight()
light.type = SCNLight.LightType.spot
light.spotInnerAngle = 30
light.spotOuterAngle = 80
light.castsShadow = true
light.color = UIColor.init(colorLiteralRed: 0.95, green: 0.8, blue: 0.8, alpha: 1)
light.zFar = 200
let lightNode = SCNNode()
lightNode.light = light
lightNode.position = SCNVector3Make(20, 100, 50)
let constraint = SCNLookAtConstraint(target: centerPoint)
constraint.isGimbalLockEnabled = true
lightNode.constraints = [constraint]
centerPoint.addChildNode(lightNode)
let ambientLight = SCNLight.init()
ambientLight.type = SCNLight.LightType.ambient
ambientLight.color = UIColor.darkGray
scene.rootNode.light = ambientLight
// retrieve the ship node
let material = SCNMaterial.init()
material.diffuse.contents = UIColor.yellow
material.lightingModel = SCNMaterial.LightingModel.phong
material.locksAmbientWithDiffuse = true
let boxNode = SCNNode.init(geometry: SCNBox.init(width: 10, height: 0.1, length: 10, chamferRadius: 0))
boxNode.geometry?.firstMaterial = material
boxNode.position = SCNVector3Make(0, -2, 0)
scene.rootNode.addChildNode(boxNode)
// animate spot light rotation
centerPoint.runAction(SCNAction.repeatForever(SCNAction.rotateBy(x: CGFloat(M_PI), y: 0, z: CGFloat(M_PI), duration: 5)))
// animate color light change
let lightColorChange: CABasicAnimation = CABasicAnimation.init(keyPath: "color")
lightColorChange.fromValue = UIColor.init(colorLiteralRed: 0.95, green: 0.8, blue: 0.8, alpha: 1)
lightColorChange.toValue = UIColor.init(colorLiteralRed: 0, green: 0, blue: 0.4, alpha: 1)
lightColorChange.duration = 5.0
lightColorChange.autoreverses = true
lightColorChange.repeatCount = Float.infinity
light.addAnimation(lightColorChange, forKey: "changeLight")
// retrieve the SCNView
let scnView = self.view as! SCNView
// set the scene to the view
scnView.scene = scene
// allows the user to manipulate the camera
scnView.allowsCameraControl = true
// show statistics such as fps and timing information
scnView.showsStatistics = true
// configure the view
scnView.backgroundColor = UIColor.black
// add a tap gesture recognizer
let tapGesture = UITapGestureRecognizer(target: self, action: #selector(handleTap(_:)))
scnView.addGestureRecognizer(tapGesture)
}
빛의 변화도 있습니다. CABasicAnimation을 사용하면 시간이 지남에 따라 light.color
속성을 변경할 수 있습니다. 모든 색상 단계가있는 완벽한 일출과 같지 않지만 애니메이션을 더욱 복잡하게 만드는 방법이 있습니다. ("wenderlich 복잡한 로딩 애니메이션을 만드는 방법"을 찾으려면
그림자 색을 변경하는 방법을 찾지 못했습니다. 야간에는 흰색 그림자를 주며 낮에는 검은 색 그림자가있는 좋은 효과가 될 수 있습니다 light.shadowColor
아직 도움이되지 않았습니다. 누군가가 아이디어를 가지고 있다면 매우 높이 평가됩니다. 매우 편리합니다.
태양이 떠오르는 모습을 사진처럼 보여주세요. –
여기에 나는 Scenekit으로 만들고 싶은 그림자 이동 효과를 보여주는 비디오를 발견했다 : https://www.youtube.com/watch?v=305b3X_FDZM –
보기 후에 YouTube 동영상을 보았을 때 나는 대답보다 더 많은 질문을 가지고있다.자, 비디오에서 큐브로 어떤 부분을 만들고 싶은지 잘 모르겠습니다. 또한 "lightNode에 대한 작업 -> 아무 일도 일어나지 않습니다"라고 말하면 코드 줄을 표시하지 않으므로 아무 말도하지 않아도됩니다. 추가 정보가 없으면이 주제가 닫히도록 제안합니다. –