Skip to main content

Transformation

In this section, we explain how you can apply transformations to 3D objects and how you can use expressions to implement geometric constraints between nodes in a GLTF model. Transformations on 3D objects can be used to visualize the state of an object depending on IoT parameters. For example, you can show the location of an elevator in a building or the position of the arm of a robot in a factory.

Solids

This example shows how IoT parameters stored in topics can be used to translate and rotate objects in a small crane, or cherry picker. The body of the crane is constructed from a block and a raised cylinder near the edge as shown below. The two objects are shrink-wrapped into a new body using the Hull operation.

The crane object includes a part Arm that can be rotated in two directions and that can be extended so that the grey inner shaft moves out of the yellow outer shaft. The Basket is included as a part in the Extension.

Topics

The example shows how you can control the angle and extension of the arm. First, we create a topic to link to the GLTF file, a topic to set the angle of the arm, and a topic to set the extension.

crane.T01.geometry = Crane.gltf
crane.T01.angle = 0
crane.T01.extension = 0

Next, we create two topics to control the extension of the arm. The first topic links to the node that controls the extension. The second topic sets a constraint on the maximum extension to 3 units, by using the JavaScript Math.min() function.

crane.T01.extension.node = Extension
crane.T01.extension.translation.y = Math.min(3, crane.T01.extension)

For the rotation of the arm we link the rotation in z-direction to the angle topic of the crane. Note that if the arm rotates in one direction, the basket should rotate in the opposite direction to ensure it stays horizontal.

crane.T01.arm.node = Arm
crane.T01.arm.rotation.z = crane.T01.angle
crane.T01.basket.node = Basket
crane.T01.basket.rotation.z = -crane.T01.angle

You can now control the crane by setting the value of the extension and angle topics.

Model

Create a new model and include the topic for the crane. If you click on the crane a list of topics is displayed. To change the value of the topics click on the edit icon, set the values, and click update.

Explanation

A GLTF model has an internal hierarchy, a so-called tree of nodes. When applying a translation or rotation to a node all child nodes are translated or rotated as well. For example, when a translation is applied to the whole model is moved. When a rotation is applied to the arm, the extension and basket are also rotated because they are part of the arm.