Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Scale SCNNode in SceneKit

I have the following 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)

If I apply:

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

it appears to have no effect on the size of the box. I've checked this with boxNode.getBoundingBoxMin(&v1, max: &v2). It's always the same and appears the same on-screen.

Am I missing something? The docs imply that setting the scale should affect the node's geometry and thus be a different size.

Thanks. J.

like image 454
Jason Leach Avatar asked Dec 18 '15 23:12

Jason Leach


People also ask

What is SceneKit in IOS?

SceneKit is a high-level 3D graphics framework that helps you create 3D animated scenes and effects in your apps.

What is node in ARKit?

In my previous blog post I discussed how to overlay an image on the camera output in an ARKit app. Objects that you overlay on the camera output are called nodes. By default, nodes don't have a shape. Instead, you give them a geometry (shape) and apply materials to the geometry to provide a visual appearance.


1 Answers

I just tested in a playground and it worked perfectly for me. Perhaps your camera is zooming in to compensate for the smaller box?

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)

Uncomment the last line and you'll see the box (10 x 10 x 10) switch switch from being larger than the sphere (diameter of 8) to being smaller than the sphere. Here it is after the scaling:

enter image description here

like image 104
Hal Mueller Avatar answered Sep 30 '22 19:09

Hal Mueller