- Index
- » Usage and Applications
- » OpenModelica Usage and Applications
- » Dynamic color change
Dynamic color change
Dynamic color change
Hello all,
I have been working for some time with the multibody library and its animations and this works great. Thanks for all the time people have put in here. I can now simulate exoskeletons and have them moving, showing everyone what is going on.
Of course, with the animations working, I would make it even more clear. For this I would like to change values of the visualization objects dynamically. In the documentation it is written that this is possible, when 'appropriate expressions in the input fields' are given. I cannot get this to work, and hope I do something stupid so that it is easily corrected.
The minimal example below should give an arrow changing from red to green. However, the arrow is always red. In the results I do see that the values of the fa.color change as specified. I hope somebody can give a pointer to the correct solution?
Thanks in advance
Bas
-------------------------------------------------------------------------------------------------
model tst
inner ModelicaServices.Modelica3D.Controller m3d_control;
inner Modelica.Mechanics.MultiBody.World world;
Integer clr[3];
Modelica.Mechanics.MultiBody.Visualizers.FixedArrow fa(color = clr);
equation
connect(world.frame_b, fa.frame_a);
clr = if time < 0.5 then {250, 0, 0} else {0, 250, 0};
end tst;
- bjdekruif
- 18 Posts
Re: Dynamic color change
Hmm, I don't know if we have support for that. I need to check a bit in the Modelica3D library. I'll let you know as soon as possible.
- adrpo
- 885 Posts
Re: Dynamic color change
Adrian, weren't there some thermal demo for Modelica3D that changed the colour based on some measurements? Or am I thinking of something else?
- sjoelund.se
- 1700 Posts
Re: Dynamic color change
Yes. There were. I'm looking into this presentation:
http://www.modprod.liu.se/modprod2012/1 … lica3D.pdf
And it seems there is something like:
Code:
Modelica3D.SetMaterialColor(fluidMaterialVis3D[i].id, rVis3D, gVis3D, bVis3D, update3d.frame);
which means that you specifically need to signal a color change via a Modelica3D function call inside the when equation, you cannot just change the clr variable.
The trouble is I don't know yet how to adapt this to the model given above by Bas.
I'll play with it a bit and hopefully I'll find out how to do it
- adrpo
- 885 Posts
Re: Dynamic color change
It seems that our Modelica3D doesn't have a Modelica3D.SetMaterialColor function but it does have some other functions.
- adrpo
- 885 Posts
Re: Dynamic color change
Hi, I could change the color using this:
Code:
model tst
inner ModelicaServices.Modelica3D.Controller m3d_control;
inner Modelica.Mechanics.MultiBody.World world;
Integer clr[3];
Modelica.Mechanics.MultiBody.Visualizers.FixedArrow fa(color = clr);
equation
connect(world.frame_b, fa.frame_a);
clr = if time < 0.5 then {250, 0, 0} else {0, 250, 0};
ModelicaServices.Modelica3D.setAmbientColor(m3d_control.conn, m3d_control.context, fa.arrowHead.mat, fa.arrowHead.color[1] / 255.0, fa.arrowHead.color[2] / 255.0, fa.arrowHead.color[3] / 255.0, 1.0, time);
ModelicaServices.Modelica3D.setSpecularColor(m3d_control.conn, m3d_control.context, fa.arrowHead.mat, 0.00392156862745098 * fa.arrowHead.specularCoefficient * fa.arrowHead.color[1], fa.arrowHead.specularCoefficient * fa.arrowHead.color[2] / 255.0, fa.arrowHead.specularCoefficient * fa.arrowHead.color[3] / 255.0, 1.0, time);
ModelicaServices.Modelica3D.applyMaterial(m3d_control.conn, m3d_control.context, fa.arrowHead.id, fa.arrowHead.mat);
end tst;
Hopefully you can do what you want with this.
- adrpo
- 885 Posts
Re: Dynamic color change
Hello Adrian,
Thanks for your help (again). This does the trick. Now I can show when I lock a joint visually.
I was hoping for a solution that could be used to change all the properties of a visualization component (eg width, etc) but I can try to discover this based on the signal arrow model..
Bas
- bjdekruif
- 18 Posts
- Index
- » Usage and Applications
- » OpenModelica Usage and Applications
- » Dynamic color change