.. _world_blocks: Definition of blocks -------------------------------------------- Blocks are non-vehicle objects in the simulation world, typically representing obstacles, furniture, buildings, or any static or dynamic object that is not a controllable robot/vehicle. An XML block with tag name ```` *can* be provided for each block *class*, then each ```` will *instantiate* a block of a particular *class*. .. note:: Blocks and vehicles share the common :ref:`Simulable ` and :ref:`VisualObject ` interfaces. Block classes ======================= Block classes are reusable templates defined with ```` tags. They allow you to define a block type once and instantiate it multiple times with different poses or parameters. .. code-block:: xml 50.0 0.0 1.0 #8B4513 0.8 -0.5 -0.5 -0.5 0.5 0.5 0.5 0.5 -0.5 https://example.com/models/box.dae 1.0 Block parameters ======================= Blocks support the following parameters, which can be defined either in the ```` definition or in individual ```` instances: Physical properties ^^^^^^^^^^^^^^^^^^^^^ - **mass**: Mass of the block in kilograms (Default: 30.0) - **static**: Boolean indicating if the block is fixed in place (Default: false) - **ground_friction**: Friction coefficient with the ground (Default: 0.5) - **lateral_friction**: Lateral friction coefficient (Default: 0.5) - **restitution**: Coefficient of restitution for collisions (Default: 0.01) - **intangible**: If true, the block is rendered but doesn't collide or affect sensors (Default: false) Geometry properties ^^^^^^^^^^^^^^^^^^^^^ - **zmin**: Distance from bottom of the block to ground [meters] - **zmax**: Distance from top of the block to ground [meters] - **color**: Block color (see :ref:`color formatting `) Visual properties ^^^^^^^^^^^^^^^^^^^^^ All parameters from the :ref:`VisualObject ` interface apply, including: - **visual_scale**: Per-instance override for 3D model scale. If specified, this overrides the ``model_scale`` defined in the visual model. Useful for creating size variations of the same block class. Example: .. code-block:: xml 10 20 0 0.5 15 25 0 2.0 Block shape definition ======================= Blocks can define their 2D collision shape in three ways: 1. Explicit polygon shape ^^^^^^^^^^^^^^^^^^^^^^^^^^^ Define the block's footprint as a polygon using ```` tag: .. code-block:: xml -1.0 -0.5 -1.0 0.5 1.0 0.5 1.0 -0.5 2. Automatic shape from visual model ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Use ```` to automatically derive the collision shape from the 3D model's bounding box: .. code-block:: xml building.dae .. note:: When using ````, the ``zmin`` and ``zmax`` values are also automatically extracted from the 3D model. 3. Geometric primitives ^^^^^^^^^^^^^^^^^^^^^^^^^ Use simple geometric shapes with the ```` tag: .. code-block:: xml Supported geometry types: - **cylinder**: Requires ``radius``, ``length``, optional ``vertex_count`` (default: 10) - **sphere**: Requires ``radius``, optional ``vertex_count`` (default: 10) - **box**: Requires ``lx`` (length), ``ly`` (width), ``lz`` (height) - **ramp**: Requires ``lx``, ``ly``, ``lz`` - **semi_cylinder_bump**: Requires ``lx``, ``ly``, ``lz``, optional ``vertex_count`` Block instances ======================= Each block class can be instantiated multiple times with the ```` tag: .. code-block:: xml 5.0 3.0 0 8.0 3.0 45 75.0 Parameters in block instances ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - **name**: Unique identifier for the block (required if not auto-generated) - **class**: Reference to a ```` definition - **init_pose**: Initial position in global coordinates: ``x y yaw_deg`` - Any parameter from the class definition can be overridden in the instance Blocks without classes ======================== Blocks can also be defined inline without a class: .. code-block:: xml 12.0 8.0 0 100.0 true 0.0 2.5 -2.0 -1.0 -2.0 1.0 2.0 1.0 2.0 -1.0 Complete example ======================= .. code-block:: xml 25.0 0.0 0.15 #A0522D 0.6 https://mrpt.github.io/mvsim-models/pallet.dae 0.01 $f{i*2.0} 5.0 0 $f{0.8 + i*0.1} 0 0 0 0.0 1.2 #FF0000 Advanced features ======================= Dynamic blocks ^^^^^^^^^^^^^^^^^ Blocks with ``static="false"`` (the default) participate in the physics simulation and can be pushed, moved, or affected by forces: .. code-block:: xml 3.0 2.0 0 50.0 0.7 Intangible blocks ^^^^^^^^^^^^^^^^^^^ Blocks with ``intangible="true"`` are rendered visually but don't collide: .. code-block:: xml 0 0 0 ghost.dae This is useful for decorative elements, visual markers, or semi-transparent objects. Tips and best practices ========================= 1. **Use classes for reusability**: Define common obstacles as classes and instantiate them multiple times 2. **Leverage** ``visual_scale`` for variety: Create size variations without defining new classes 3. **Use** ``shape_from_visual`` when possible: Automatically derive collision shapes from 3D models 4. **Combine with loops**: Use ```` loops (see :ref:`flow control `) to create patterns of blocks 5. **Minimize collision complexity**: Use simple shapes when possible for better performance 6. **Mark decorative objects** as ``intangible`` to avoid unnecessary collision checks