Import/export
Several type of data and formats can be imported to, or exported from CoppeliaSim:
mesh data, via various formats
scene/model data, via CoppeliaSim's XML format
scene/model data, via the URDF format
scene/model data, via the SDF format
animation or scene data, via the GLTF format
video data, via various formats
image data, via various formats
text/binary data
miscellaneous data
New importers/exports can easily be created via an add-on, or via a plugin.
Importing/exporting mesh data
The 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 --> Grouping/Merging --> Divide selected shapes].
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 selected shape...]
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.
Exporting a simulation as GLTF
A 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: GLTFExporter and GLTFAnimationExporter, available via [Menu bar --> Add-ons].
See also the API functions related to GLTF export.
Importing/exporting images
Images 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 data
Following 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 data
The Floor Plan Importer add-on 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
The add-on is available via [Menu bar --> Modules]. After selecting the menu entry, an image file must be selected, then a few import options can be specified:
- pixel size: the scaling of the image. One pixel in the image will correspond to this length in the real world.
- For every class (walls, windows, doors):
- height: the height of the wall/hole in the real world.
- range: the range of the intensity (grayscale value) in the image.
- color: the color of the walls shape.
- respondable: wether the walls shape will be respondable.
- optimize: if checked, the lines will be dissected to a minimal number of rectangles, so the shape will contain a low count of pure (cuboid) shapes.
- invert image values: if checked, the image values will be inverted before processing.
|