SCNNode를 설정하는 데 사용 된 구형 지오메트리 (SCNSphere)의 반지름을 어떻게 반환합니까? 부모 노드와 관련하여 일부 자식 노드를 이동하는 방법에서 반지름을 사용하고 싶습니다. 반경이 결과 노드에서 알 수없는 것처럼 보이기 때문에 아래 코드는 실패합니다. 노드를 메서드에 전달하지 않으면 어떻게됩니까?SCNNode를 생성하는 데 사용되는 SCNSphere의 반경을 얻습니다.
또한 내 배열 인덱스는 Int가 범위가 아님을 나타내지 못합니다.
내가 radius
와 this
import UIKit
import SceneKit
class PrimitivesScene: SCNScene {
override init() {
super.init()
self.addSpheres();
}
func addSpheres() {
let sphereGeometry = SCNSphere(radius: 1.0)
sphereGeometry.firstMaterial?.diffuse.contents = UIColor.redColor()
let sphereNode = SCNNode(geometry: sphereGeometry)
self.rootNode.addChildNode(sphereNode)
let secondSphereGeometry = SCNSphere(radius: 0.5)
secondSphereGeometry.firstMaterial?.diffuse.contents = UIColor.greenColor()
let secondSphereNode = SCNNode(geometry: secondSphereGeometry)
secondSphereNode.position = SCNVector3(x: 0, y: 1.25, z: 0.0)
self.rootNode.addChildNode(secondSphereNode)
self.attachChildrenWithAngle(sphereNode, children:[secondSphereNode, sphereNode], angle:20)
}
func attachChildrenWithAngle(parent: SCNNode, children:[SCNNode], angle:Int) {
let parentRadius = parent.geometry.radius //This fails cause geometry does not know radius.
for var index = 0; index < 3; ++index{
children[index].position=SCNVector3(x:Float(index),y:parentRadius+children[index].radius/2, z:0);// fails saying int is not convertible to range.
}
}
required init(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}
예! 기존 노드의 반경을 변경하는데도 사용할 수 있습니다. 감사. – bpedit