2017-11-21 4 views
0

私はSceneKitの使用に初心者で、私のノードは私の画面には大きすぎます(半径を変更しても下のコードと写真を参照してください)。私のSCNNodesは、指定された半径に対して一定のサイズです

コード:https://pastebin.com/GGikSTyY

let scene = SCNScene() 
sceneView.autoenablesDefaultLighting = true 
sceneView.allowsCameraControl = true 
// If I set size to 2, 5, 120 the answer is the same. 
let hydrogenAtom = SCNSphere(radius: 0.2) 
hydrogenAtom.firstMaterial!.diffuse.contents = UIColor.lightGray 
hydrogenAtom.firstMaterial!.specular.contents = UIColor.red 
let atomsNode = SCNNode() 
let carbonNode = SCNNode(geometry: hydrogenAtom) 
carbonNode.position = SCNVector3Make(-6, 0, 0) 
atomsNode.addChildNode(carbonNode) 
scene.rootNode.addChildNode(atomsNode) 
sceneView.scene = scene 

とのviewDidLoad内のコードのこの作品があります:(私は設定何でも半径用)

override func viewDidLoad() { 
     super.viewDidLoad() 

     sceneView.frame = self.viewMain.bounds 
     sceneView.backgroundColor = UIColor.clear 
     self.viewMain.addSubview(sceneView) 
} 

画像:enter image description here

ありがとう!

答えて

1

カメラを作成していないからです。ノードを中心にして同じサイズに見えるデフォルトのノードを取得するだけです。あなたは球の位置を変更することにも明らかな効果はないことに気付くでしょう。

あなたはこのようにカメラを作成することができます。

let cameraNode = SCNNode() 
cameraNode.camera = SCNCamera() 
scene.rootNode.addChildNode(cameraNode) 
cameraNode.position = SCNVector3(x: 0, y: 0, z: 15) 
関連する問題