Import/exportSeveral type of data and formats can be imported to, or exported from CoppeliaSim: New importers/exports can easily be created via an add-on, or via a plugin. Importing/exporting mesh dataThe mesh import/export functionality is handled via the Assimp plugin for CoppeliaSim. More formats can be supported if the Assimp library (and Assimp plugin) are recompiled with the required flags. The plugin's functionality is exposed to CoppeliaSim's GUI and can be reached at [Menu bar --> File --> Import --> Meshes...] or [Menu bar --> File --> Export --> Selected shapes...]. If after the import operation you can't see any shapes in the scene, but the scene hierarchy indicates the presence of newly added shapes, then most probably your shapes are either too big or too small to be seen. You can then proceed to a scaling operation. Additionally, you can subdivide imported meshes via [Menu Bar --> Edit --> Shape grouping/merging --> divide]. Make sure that imported meshes do not contain too many triangles (for a robot, typically between 10'000-20'000 triangles in total), otherwise CoppeliaSim could be slowed down. You can decimate an imported mesh via [Menu bar --> Edit --> Decimate shape(s)...] Heightfields in CoppeliaSim are also meshes, and can be imported via [Menu bar --> File --> Import --> Heightfield...]. Supported formats are image formats (the color or grey tone components represent elevations), or csv or txt formats (comma-separated values (y rows with x values)). See also the API functions related to mesh import/export. Importing/exporting URDF filesOne can access the URDF importer/exporter functionality via the following two add-ons: [Menu bar --> Modules --> Importers --> URDF importer...] and [Menu bar --> Modules --> Exporters --> URDF exporter...] See also the API functions related to URDF import/export. Exporting a simulation as GLTFA scene or simulation can be exported via the GLTF format. The result will be a still scene or an animated scene. The functionality is available via two distinct add-ons: [Menu bar --> Modules --> Exporters --> GLTF exporter...] and [Menu bar --> Modules --> Exporters --> GLTF animation exporter...]. See also the API functions related to GLTF export. Importing/exporting imagesImages can be imported/exported with sim.loadImage and sim.saveImage. See also sim.getScaledImage, sim.transformImage, sim.transformBuffer and the OpenCV plugin API reference. Importing/exporting text/binary dataFollowing example illustrates how to log a joint angle to a file, as text data:
function sysCall_init()
jointHandle=sim.getObject('/Joint')
file=io.open('jointAngles.txt','w+')
file:write('Joint angles for each simulation step:\n\n')
end
function sysCall_sensing()
local v=180*sim.getJointPosition(jointHandle)/math.pi
file:write(string.format('time: %.3f [s]',sim.getSimulationTime()+sim.getSimulationTimeStep()))
file:write(string.format(', joint angle: %.1f [deg]\n',v))
end
function sysCall_cleanup()
file:close()
end
Following example illustrates how to read a file, line by line:
for line in io.lines('textFile.txt') do
print(line)
end
Importing miscellaneous dataThe floor plan importer add-on, available via [Menu bar --> Modules --> Importers --> Floor plan importer...], can create shapes from a floor plan image, by mapping each pixel value to either a wall, a door or a window. A floor-plan image looks like this: [Example of a floor-plan image] Note that above image is zoomed in, and actual lines are 1px thick. Different gray levels are used to indicate different classes. In this example, 0 is used for walls, 82 for window holes, and 187 for door holes. These values can be configured (see below) and anything outside the given ranges will be ignored, so it is possible to use a floor plan that contains more annotations, but only extract wall/door/window lines if given in a specific gray value. Various other formats derived from or related to images can also be imported. For a complete list of supported formats, use simUI.supportedImageFormats. Following example illustrates the PGM format: P2 18 6 3 0 0 0 0 0 0 0 0 0 0 0 0 2 2 2 2 0 0 0 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 0 0 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 0 0 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 0 0 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 0 0 0 1 1 1 1 0 0 0 0 0 0 2 2 2 2 0 0 After selecting the menu entry, an image file must be selected, then a few import options can be specified: Importing LDR / MPD modelsThe LDraw importer add-on is available via [Menu bar --> Modules --> Importers --> LDraw importer...]. Make sure the LDraw parts library is installed. The simExtLDraw plugin uses the ldrawloader from Christoph Kubisch. See also the API functions related to LDR / MPD import. |