1Passive objects
2===============
3
4Besides physical interaction and perception via cameras or depth sensors,
5passive objects in a simulation can be interacted with in several other ways.
6
7For instance some objects can be set to be graspable by a robot (or a human),
8and specific sensors like the :doc:`Semantic camera <../sensors/semantic_camera>`
9may provide extended information about a particular object, such as its type.
10
11Creating passive objects
12------------------------
13
14Passive objects are either plain, regular Blender objects, or a group
15of objects.
16
17
18.. image:: ../../../media/object_grouping.png
19  :align: center
20
21In the screenshot above (from
22``$MORSE/share/morse/data/props/objects.blend``), the ``RollingChair``
23hierarchy is made up of an empty object (the ``RollingChair`` itself) and
24five child objects (four for the bounding box, one for the actual mesh).
25
26Since all these six Blender objects share the same prefix, they will be
27correctly imported together when using the MORSE Builder API.
28
29When imported manually (from the Blender user interface), this eases the selection
30of relevant objects.
31
32.. note::
33
34   You can also have a look at the tips on adding a :doc:`bounding box around your objects
35   <../tips/bounding_boxes>`.
36
37For complex objects with non-trivial bounding-boxes, we recommend the
38creation of groups (which also has performance advantages, through
39*group instances*). To do this:
40
41#. Select all the objects that you want to group
42#. **make sure they are properly centered on the Blender origin**
43#. Press :kbd:`Ctrl+G` to create a new group (they should appear in green in
44   the viewport)
45#. In the outliner, select the *Groups* view. You can double-click on the group
46   name to change it.
47
48Passive objects properties
49--------------------------
50
51To be set as an **interactive** passive object, you only have to add the (Game)
52property ``Object`` to the object, and to set this as boolean property
53with the value ``True``.
54
55Other, **optional**, properties allow us to control other features of the object:
56
57- ``Label`` (``String``): the name (or label) of the object [#]_,
58- ``Description`` (``String``): a longer description of the object [#]_,
59- ``Type`` (``String``): the type of the object [#]_,
60- ``Graspable`` (``Boolean``): if the object is graspable or not [#]_.
61
62You can temporarly disable an object by simply setting its ``Object`` property to ``False``.
63
64.. [#] Used to display the object name in :doc:`human's manipulation mode <human>`
65   and by the semantic camera sensor as ID of tracked objects.
66.. [#] Not used yet.
67.. [#] Used by the semantic camera sensor, defaults to ``Object``.
68.. [#] Used by the human's manipulation mode and the :doc:`gripper <../actuators/gripper>`
69   actuators.
70
71.. note::
72
73   For the manipulation routines to work, the above properties (especially, ``Graspable``)
74   must be set on the **object holding the mesh you want to grab**.
75
76Importing passive objects with the MORSE Builder API
77----------------------------------------------------
78
79Passive objects can easily get added to a scenario defined with the
80:doc:`MORSE Builder API <../../user/builder>`.
81
82The following example imports the ``SmallTable`` Blender object from the
83``props/objects.blend`` assets file, set some properties, and places it
84in the scene:
85
86.. code-block:: python
87
88    from morse.builder import *
89
90    table = PassiveObject('props/objects', 'SmallTable')
91    table.setgraspable()
92    table.translate(x=3.5, y=-3, z=0)
93    table.rotate(z=0.2)
94
95As with any other property, the game properties can be set using the following method:
96
97.. code-block:: python
98
99  table.properties(Object = True, Graspable = False, Label = "TABLE")
100
101.. warning::
102    To set an object to be graspable, you **must** also call the ``setgraspable(..)`` function.
103    It adds an internal collision sensor to the object, required for pick and place
104    actions with the human avatar.
105
106
107The next example shows how to add semi-randomly placed chairs in a
108scene:
109
110.. code-block:: python
111
112    import random
113    from morse.builder import *
114
115    # Add some randomly placed chairs
116    for i in range(3):
117        chair = PassiveObject('props/objects', 'RollingChair')
118        chair.translate(x=random.uniform(1.5, 7.0),
119                        y=random.uniform(-5.0, 0.0),
120                        z=0.0000)
121        chair.rotate(z=random.uniform(0.0, 6.2)) # rotation in radians
122
123Combining passive objects with switches
124---------------------------------------
125
126It is possible to create portable devices by combining switches with
127a passive object. The creation of such devices will be explained in
128terms of a flashlight.
129
130First of all we need to create the mesh of our flashlight. After that
131create the switch as a seperate object and make it a child of the mesh. Next
132add a lamp object and again, make it a child of the mesh. Name all these
133objects so that they all share the same prefix.
134Now all that's left is defining the single objects for the use with Morse.
135So use the :doc:`Morse Utils <../addons/morse_utils>` Addon to define the
136switch. Add the Logic for the lamp using the ``Morse Light`` preset.
137Disable the physics for the switch with the ``Ghost`` option in the Physics
138Properties, so that there can't be collisions with the mesh.
139
140You can now import the flashlight using the :doc:`MORSE Builder API <../../user/builder>`
141as explained above. You can also import it manually and set the mesh to be
142a passive object using the ``Morse Utils``.
143
144.. warning::
145    If you use :doc:`compound bounding boxes <../tips/bounding_boxes>` do not use the ``Compound``
146    option on the switch object. Also do not make it a ``No Collision``
147    object or otherwise you can't use the switch.
148
149The switch works exactly the same as a static one. Use the ``Left Mouse Button``
150to turn the device on and off. This also works while the object is carried.
151