Working with units
How units are expressed
Units are expressed as a multiple of millimeters. For example, an inch unit will be expressed as 25.4, a meter unit as 1000, and a millimeter unit as 1.
You can get the unit value by calling the Model::getNodeUnitMultiplier() method on the model object.
You can also use Util::formatWithUnit() to convert your measurement value to a formatted string.
Here’s an example using the command line in a browser console, with “hwv” representing the Communicator.WebViewer object:
> hwv.getModel().getNodeUnitMultiplier()
> 25.4
> Communicator.MeasureUtils.formatWithUnit(128, hwv.getModel().getNodeUnitMultiplier())
> "128.00inch"
Building a scene with mixed units
Suppose we’ve defined a cube using inches. If we load this model into the WebViewer and measure it, we get the following results:
The length of the edge of the cube is 3.35 inches (85 millimeters)
Now we restart and load a scene in millimeters.
We then load the cube into this existing scene:
The cube, which is defined in inches, will then be measured in millimeters because it gets imported in millimeters. In this case, Communicator will automatically scale the imported object to make it fit to the existing scene unit.
In some cases you might not want the object to automatically scale to fit the unit of the existing scene. This can be turned off by calling the setEnableAutomaticUnitScaling method of the Model
object:
In this case, the cube won’t be rescaled to fit millimeter units and will be a lot smaller relative to the other object in the scene: