在SceneKit中缩放SCNNode

时间:2015-12-18 23:39:07

标签: ios swift scenekit

我有以下SCNNode

let box = SCNBox(width: 10.0, height: 10.0, length: 10.0, chamferRadius: 0)
let boxNode = SCNNode(geometry: box)
boxNode.position = SCNVector3(x: 0, y: 0, z: 0)

如果我申请:

boxNode.scale = SCNVector3(x: 0.5, y: 0.5, z: 0.5)

它似乎对盒子的大小没有影响。我已使用boxNode.getBoundingBoxMin(&v1, max: &v2)进行了检查。它总是一样,在屏幕上显示相同。

我错过了什么吗?文档暗示设置比例应该影响节点的几何形状,因此是不同的大小。

感谢。 学家

1 个答案:

答案 0 :(得分:8)

我刚在操场上测试过,它对我来说非常适合。也许您的相机正在放大以补偿较小的盒子?

import SceneKit
import SpriteKit
import XCPlayground

let sceneView = SCNView(frame: CGRect(x: 0, y: 0, width: 800, height: 600))

XCPlaygroundPage.currentPage.liveView = sceneView

var scene = SCNScene()
sceneView.scene = scene
sceneView.backgroundColor = SKColor.greenColor()
sceneView.debugOptions = .ShowWireframe

// default lighting
sceneView.autoenablesDefaultLighting = true

// a camera
var cameraNode = SCNNode()
cameraNode.camera = SCNCamera()
cameraNode.position = SCNVector3(x: 15, y: 15, z: 30)
scene.rootNode.addChildNode(cameraNode)

let box = SCNBox(width: 10.0, height: 10.0, length: 10.0, chamferRadius: 0)
let boxNode = SCNNode(geometry: box)
boxNode.position = SCNVector3(x: 0, y: 0, z: 0)
scene.rootNode.addChildNode(boxNode)
let centerConstraint = SCNLookAtConstraint(target: boxNode)
cameraNode.constraints = [centerConstraint]

let sphere = SCNSphere(radius: 4)
let sphereNode = SCNNode(geometry: sphere)
sphereNode.position = SCNVector3(x:15, y:0, z:0)
scene.rootNode.addChildNode(sphereNode)

//boxNode.scale = SCNVector3(x: 0.5, y: 0.5, z: 0.5)

取消对最后一行的注释,你会看到盒子(10 x 10 x 10)开关从大于球体(直径8)到小于球体。这是在缩放之后:

enter image description here