This project illustrates the use of a 3D environment (BABYLONjs) in TwinCAT HMI.
The framework project wraps the BABYLON environment in a configurable control, allowing users to import and render their own 3D models (supported formats).
Scaling, position, and rotation properties for each model can be bound to dynamic values (symbols) to provide real-time animation. The HMI project's symbol update rate is used to interpolate frames and smooth these animations.
There are two projects / solutions:
- TcHmi3dDynamics: The framework project / control, and associated types
- 3dDynamics_Test: Test project with models to show implementation
- Add a reference to the TcHmi3dDynamics framework project (or package)
- Drop a
Dynamic Scenecontrol onto your page - Add models to the
Mesh Listproperty of the control - Apply any static or dynamic translations (position, rotation, scaling)
- Enable the
Animationproperty for real-time animations - Create parent/child hierarchy between models via the
Parentproperty- Simply reference the parent mesh name
- Make sure the referenced parent mesh before any children
- Enable the
- Configure the
Scene Optionsproperties to dial in the camera / aux options
The test project includes 7 STL model files that make up a 6-axis robot arm. The models are added to the mesh list, with scaling, position, and rotation translations applied so everything is appropriately aligned. Internal symbols tied to the slider controls are used for the rotations so that the motion of each joint can be animated.
Note: STL models do not carry coordinate system information, which is why the rotations seem to be applied to the wrong axes (e.g. the first joint should rotate about the Z axis in right-hand rule, but the rotation is applied to the Y axis because the model and world coord systems are not the same). If you import a model with an appropriately defined coordinate system, everything should align correctly. You can always invert the model's system by negating the X or Z scaling.
