Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What unit is used by the Scene Editor in Xcode?

Tags:

xcode

scenekit

The Scene Editor in Xcode displays sizes but no unit. Is it a size in inches or a size in meters?

For instance, when I select a node, e.g. a box, when I inspect its properties in the Node Inspector and I check its size in the "Transforms" section next to "Bounding Box", no unit is shown.

Bounding Box in the Scene Editor in Xcode

The unit doesn't seem to be related to the system measurement units that are set in the "Language & Region" preference pane (in the "Advanced..." popover) because the numbers don't change in the Node Inspector when I switch the measurement units between "metric" and "US".

like image 845
Pierre F Avatar asked Jan 29 '23 11:01

Pierre F


2 Answers

The sizes are expressed in meters. See the SceneKit documentation:

All values in SceneKit’s physics simulation use the International System of Units (SI): The unit of mass is the kilogram; the units of force, impulse, and torque are the newton, newton-second, and newton-meter; and the unit of distance for node positions and sizes is the meter.

like image 105
Pierre F Avatar answered Feb 01 '23 01:02

Pierre F


The answer you got from Apple is sort of correct, but also incomplete.

In a 3D scene graph model such as SceneKit, the unit of length doesn’t really matter for most purposes. It can be entirely arbitrary, with the choice and use of units having no effect on visual results so long as your units are used consistently. For example, the following scenes all look exactly the same:

  • A 1.0 meter wide cube, 3.0 meters away from the camera
  • A 0.1 meter wide cube, 0.3 meters away from the camera
  • A 0.91 meter wide cube, 2.73 meters away from the camera
  • A 1.0 foot wide cube, 3.0 feet away from the camera
  • A 6.28 frobnitz wide cube, 18.84 frobnitz away from the camera (How do you convert frobnitz to meters? Doesn’t matter!)

And on top of all that, every node in the scene graph can apply a scale to its children. So you can have a cube whose width is set to 1.0 units, and a camera set 3.0 units away, and have both of those as children of a node whose scale is 0.91... in that case, even if there are other things elsewhere in the scene where “1.0 unit” means one meter, the cube and the camera don’t agree on what “1.0 unit” means. (For them, it’s a US yard.) Thus, most of the length-based properties in SceneKit (and Xcode’s scene edition UI) don’t label their units, because their units are relative to the (possibly arbitrary) scale of their parent node.

There are a couple of places where the meaning of scene-space units starts to matter:

  1. If you start using physics simulation. When mass, force, energy, and friction start getting involved, the relationship between units of length and units of those other quantities becomes important. The rest of the physics engine (mass, force, impulse) uses SI units (kilograms, newtons, newton seconds), so to keep things simple we just assume that length (and by extension, area, volume, and velocity) does, too.

  2. If you need to render your scene so that the results appear to line up with another 3D space, as in AR or VR. When used with ARKit, SceneKit lengths/distances are in meters, so that the rendered image appears to inhabit the real world as measured by ARKit.

So, yes — the answer you got from Apple is correct... in the broadest set of use cases, it’s best to assume that the unlabeled units of SceneKit space are meters, and design accordingly. But it’s important to know why, and when that assumption applies and when it’s just an arbitrary assumption.

like image 37
rickster Avatar answered Feb 01 '23 01:02

rickster