簡體   English   中英

在SceneKit中縮放SCNNode

[英]Scale SCNNode in 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)檢查過這個。 它始終是相同的,並在屏幕上顯示相同。

我錯過了什么嗎? 文檔暗示設置比例應該影響節點的幾何形狀,因此是不同的大小。

謝謝。 J.

我只是在操場上測試過,它對我來說很有效。 也許您的相機正在放大以補償較小的盒子?

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)到小於球體。 這是在縮放之后:

在此輸入圖像描述

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM