Repository navigation
New function "supportsGLB" - #4842
MartinOtter wants to merge 4 commits into
Conversation
The function returns true, if the tool can visualize meshes in GLB format with model Shape
sjoelund
left a comment
There was a problem hiding this comment.
Since the use-case would be to support both formats, could we have 1 example in Modelica/ModelicaTest that uses the GLB format if it's anyway supposed to be supported? So tool vendors could verify that this is working as expected.
I am also wondering if this function should perhaps be more flexible. Like:
function supportedMeshFormats
output String result[:] = {"stl", "glb"};
end supportedMeshFormats;|
Currently MSL has dxf-files for the robot, and
I do know that Dymola support dxf, stl, and wrl (for wrml); and similarly for related apps on 3D Experience Platform (in addition to the couplings to actual CAD-models). I don't know if any tool supports 3ds (which was used by Autodesk the last millennium, not related to www.3ds.com). I'll check internally about this format. |
The minimum would be to convert existing assets. But we should also check with tool vendors.
Alternatively: function supportedMeshFormats
input String format annotation(choices(choice="stl",choice="dxf",choice="glb"));
output Boolean supported;
end supportedMeshFormats; |
I made pull request #4844 that adds such a test. The default is to show the shape in STL format (should work in any tool). After a function is added that allows to inquire whether GLB format is supported, the GLB format of the mesh is shown. Note, this pull request could be just accepted already now and then later adapted once there is agreement on the inquiry function. |
Yes, this is good, maybe with slightly different name and providing a default implementation that should work in every tool: function supportsMeshFormat "Return true, if the provided mesh format is supported"
input String format = "stl" annotation(choices(choice="stl", choice="glb"));
output Boolean result = format == "stl";
end supportsMeshFormat; |
|
|
To me this is still confusing: the current documentation says that dxf is the format that is most likely to be supported, and the r3robot only has dxf-files. For some reason "dxf" was removed from the choices, and "stl" made the default support one. I don't know what other tools support, but I think we need to check that first. |
Maybe better to state this in a comment and keep the function clean (tool-independent). Next proposal: 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;A user would typically want to use it in the following way: Visualizers.FixedShape mesh(shapeType="MyPackage/Resources/meshes/mymesh."+(if supportsMeshFormat("glb") then "glb" else "stl").This is quite tedious. A user could provide a helper function to move this in a function: function selectMeshFile
input String fileName;
input String ext="glb";
output String fileName + "." + (if supportsMeshFormat(ext) then ext else "stl").
end selectMeshFile;
Visualizers.FixedShape mesh(shapeType=selectMeshFile("MyPackage/Resources/meshes/mymesh"));If you agree, I will update the pull request |
|
Yes, using a support function (outside of ModelicaServices) would be the way I envisioned it. |
I would assume a more generic solution like (or possibly without defaults) function selectMeshFile
input String fileName;
input String extensions[:]={"glb","stl"};
output String resName;
algorithm
for ext in extensions loop
if supportsMeshFormat(ext) then
resName:=fileName+"."+ext;
return;
end if;
end for;
assert(false, "No supported format");
end selectMeshFile;
Visualizers.FixedShape mesh(shapeType=selectMeshFile("MyPackage/Resources/meshes/mymesh")); |
Yes, this is a better solution - but outside of ModelicaServices - This could be included in Multibody. I will update this pull request (to add supportsMeshFormat in ModelicaServices and selectMeshFile in Multibody and use selectMeshFile in the pull request for a test model (probably, I move the test model into this pull request here)) |
…lica.Mechanics.MultiBody.Visualizers.Advanced/selectMeshFile and the test model ModelicaTest.MultiBody.Visualizers.Mesh with two mesh files Resources/Data/Meshes/GlassHurricane_yUP.glb and .stl
|
Added // In Modelica.Mechanics.MultiBody.Visualizers.Advanced.selectMeshFile // A test model with two meshes as ModelicaTest.MultiBody.Visualizers.Meshes |
| 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"); |
There was a problem hiding this comment.
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?
The function returns true, if the tool can visualize meshes in GLB format with model Shape. The default implementation is to return false (so adding this function is backwards compatible).
Background:
The only mesh format supported by all Modelica-tools seems to be the STL format - which looks bad and is extremely limited. In order to improve Modelica packages that utilize 3D-meshes in a Modelica compliant way, it is proposed that such libraries (such as the coming Model3D library - the planned successor of MSL multibody) provide meshes in STL and in GLB format and when using them in examples decide with this function, which extension to use for the file name given to model Shape.
There are many mesh formats. Here it is explained why GLB should be used (especially for an open source activity). Copied from this link:
GLB is the binary version of glTF (GL Transmission Format), an open standard created and maintained by the Khronos Group, the same industry consortium behind OpenGL, Vulkan, and WebGL. glTF was designed from the ground up with one specific goal in mind: to be the “JPEG of 3D,” a format that transmits and loads 3D scenes and models as efficiently as possible, without any conversion or fuss.
The many software supporting GLB includes Blender and threejs