10.4. Addition: Shifting the Whole Tip

In the example above, the change in length will be translated into an overall change with the center of rotation as overall center. However, it might be preferable to keep the tip in place and change the length of the shaft into the other direction.

Basically, this is the same problem as in the length calculation we made in the Python script. However, instead of calculating it in the macro scripting, we can also use a module for the calculation.

For this, the following modules need to be added:

The SoCalculator module offers input and output of floating values and vectors.

Figure 10.18. Feeding the SoCalculator Module

Feeding the SoCalculator Module

Some important points:

For calculating the translation from the input values of cone and shaft height, use the SoCalculator module and set up parameter connections

  1. Connect SoCylinder.height to SoCalculator.a

  2. Connect SoCone.height to SoCalculator.b

  3. Enter the calculation: oa = - (0.5*a+0.5*b) (a negative sign needs to be added; otherwise, the end of the applicator is fixed and the tip side grows).

To apply the new translation, we need another SoComposeVec3f module. It allows for converting the float value y into a vector translation in y direction. For this, it needs to receive the output of SoCalculator and deliver the input for the SoTranslation module.

  1. Connect SoCalculator.oa to SoComposeVec3f1.y

  2. Connect SoComposeVec3f1.vector to SoTranslation.translation

[Tip]Tip

You can find the names of the connected parameters by right-clicking the parameter connections. For an overview of all parameter connections in a network, use the Parameter Connections Inspector View.

The resulting macro network looks as follows:

Figure 10.19. Improved Applicator Macro Module

Improved Applicator Macro Module

When to choose calculating values in scripts and when via modules? This is not an easy question.

In the end, it comes down to your current network and your design decisions which way to choose. Or you might combine them, like we did in our ApplicatorMacro network.

What else could you do now? You could, for example, make sure that the shaft length cannot be shorter than the tip length (which looks strange in the Open Inventor scene). You could also make the colors parametrizable, or add new features for the applicator.

This is the end of this example.

[Tip]Tip

This example is delivered with MeVisLab (.def file in $(InstallDir)Packages/MeVisLab/Examples/Modules/GettingStarted/ApplicatorMacroExample, source files in $(InstallDir)Packages/MeVisLab/Examples/Sources/GettingStarted/ApplicatorMacroExample). The module can be added via quick search.