Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ Shape
Surface
PipeWithScalarField
SurfaceCharacteristics
selectMeshFile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
within Modelica.Mechanics.MultiBody.Visualizers.Advanced;
function selectMeshFile
"Return the file name of a mesh with an extension that is supported by the tool"
input String fileNameBase "Base part of a mesh file name (e.g. modelica://ModelicaTest/Resources/Data/Meshes/GlassHurricane_yUP)";
input String extensions[:]={"glb","stl"} "Formats provided for the mesh";
output String fileName "File name of the mesh, using the first extension supported by the tool";
algorithm
for ext in extensions loop
if ModelicaServices.Animation.supportsMeshFormat(ext) then
fileName := fileNameBase + "." + ext;
return;
end if;
end for;
Modelica.Utilities.Streams.print("... Mesh \"" + fileNameBase + "\" is not visualized because\nthe tool does not support one of the provided mesh formats");

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Warning: Pure function 'selectMeshFile' contains a call to impure function 'Modelica.Utilities.Streams.print'.
Error: Output parameter fileName was not assigned a value

I guess an assertion would be better. The fileName being unassigned is not optional if the function is supposed to work when visualization is disabled. But in those cases, you would not expect a warning, right?

end selectMeshFile;
8 changes: 7 additions & 1 deletion ModelicaServices/package.mo
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ The interface of this model is defined at
model Vector "Animation of a moveable vector-quantity (the length is not fixed in meters)"
extends Modelica.Utilities.Internal.PartialModelicaServices.Animation.PartialVector;

annotation (Documentation(info="<html>
annotation (Documentation(info="<html>
<p>
The interface of this model is documented at
<a href=\"modelica://Modelica.Mechanics.MultiBody.Visualizers.Advanced.Vector\">Modelica.Mechanics.MultiBody.Visualizers.Advanced.Vector</a>.<br>
Expand All @@ -156,6 +156,12 @@ The interface of this model is defined at

</html>"));
end Vector;

function supportsMeshFormat "Return true, if the provided mesh format is supported"
input String format "Extension of the mesh file name that shall be used, e.g., \"stl\", \"dxf\", \"glb\"";
output Boolean result = false "Return true, if the format is supported by the tool";
end supportsMeshFormat;

end Animation;

package ExternalReferences "Library of functions to access external resources"
Expand Down
21 changes: 21 additions & 0 deletions ModelicaTest/MultiBody.mo
Original file line number Diff line number Diff line change
Expand Up @@ -10587,6 +10587,27 @@ This test model was proposed in ticket <a href=\"https://github.com/modelica/Mod
thickness=0.5));
annotation (experiment(StopTime=1));
end Planes;

model Meshes "Test and show meshes from file"
extends Modelica.Icons.Example;
import Modelica.Mechanics.MultiBody.Visualizers.Advanced.*;

inner MultiBody.World world(animateWorld=true, animateGravity=false)
annotation (Placement(transformation(extent={{-60,0},
{-40,20}})));
MultiBody.Visualizers.FixedShape fixedShape(
shapeType=selectMeshFile("modelica://ModelicaTest/Resources/Data/Meshes/GlassHurricane_yUP.stl"),
length=1,
width=1,
height=1)
annotation (Placement(transformation(extent={{-20,0},{0,20}})));
equation
connect(world.frame_b, fixedShape.frame_a) annotation (Line(
points={{-40,10},{-20,10}},
color={95,95,95},
thickness=0.5));
annotation (experiment(StopTime=1));
end Meshes;
end Visualizers;

package InitializationConversion "Test conversion of the initialization"
Expand Down
Binary file not shown.
Loading
Loading