Aller au contenu

Working with prefabs

The usefulness of a prefab lies in the fact that you can add complex tree structures in one click. The creation procedure is reduced to a few simple steps.

Create a prefab

The VRmaze graphical interface allows the creation of prefab in one click. Indeed, the property panel of the selected object gives access to the creation command just like the vertical toolbar.

A prefab is therefore a structure starting from a root node that will be added to a protocol tree. The very function of addition excludes de facto a certain number of entities that cannot be added. It is therefore not possible to create a prefab with a protocol as root node (in this case it is a complete protocol file). It is also not possible to create a prefab from a node that has not been added, but that is present in the native structure of the parent node: for example, it is not possible to create a prefab on the labyrinth node of a Morris pool experiment since VRmaze will not allow its addition. Last constraint, it is not possible to create a prefab of a list.

Prefab of a list

It is not possible to make a prefab of a list. However, it is possible to prefab a simple logical node containing one (or more) list(s). Logical structure makes sense here: a well-established logical structure allows for simple understanding and greater potential re-usability.

Beware of links to other objects

When creating prefab, only the objects in the structure are saved and with them, the links and references to third party objects and entities. If these entities are not part of the internal structure of the prefab, they will not be saved. When adding the prefab in a new protocol, the external reference will not be found, and the behavior of the prefab will be different or even problematic.

When creating a prefab, the name of the prefab in the add context menu will be that of the root node, while the tooltip will take the content of the description.

Creation procedure

The creation procedure is simple. The most complex part is of course creating the logical structure. In the following example, we have created a simple logical structure under the test. We are going to create a prefab of the trial so that we can add it and all its hierarchical structure.

Procedure capture
Let's create a simple hierarchical structure for the example and select the trial that will be used to create the prefab. !
Assign a name and a description to the trial !
Click on the prefab creation button on the vertical toolbar !

The creation procedure is finished. We can now use our prefab.

Use a prefab

!

The context menu displays the prefab and its description

A prefab is considered a logical node in VRmaze. Thus, it can be added via the context menu of a host entity. In our case, we have created a prefab of a trial. We can thus add the trial to a logical container, i.e. a list of trials. By right-clicking on a list of trials, we can see our trial prefab, so it is possible to add it. When adding, the whole logical structure is added.

It should be noted that the prefab is copied entirely into the tree structure hosting it. Thus, it is possible to modify the structure added via the prefab, without modifying the prefab in the database. Each prefab addition is independent of the original prefab, it is quite possible to modify it at will, like a conventional node.

!

The prefab added and modified (adding a new 3D object).

Also, deleting the prefab from the database will not cause a loss of data in all protocols that have added this prefab.

Using a prefab

Adding a prefab in a logical structure is subject to the same constraints as the nodes themselves. Indeed, a compatibility check will be performed before offering the possibility to add a prefab. In our use case, the test will only be compatible with the parent experiment type. Therefore, not all prefabs are available all the time and under all conditions.

Structure of the prefabs storage folder

When creating a prefab, VRmaze will store the data as an .Xml file in the Prefabs folder in the user data folder. This database is structured as a folder by entity type.

!

The structure of the prefabs database

We can find our prefab, based on the GenericTrial type, in the folder of the same name. The filename nomenclature is ObjectName-DateCreation.xml.

!

Our test prefab file.

Prefab modification

Editing a source prefab is visually impossible after creation. VRmaze does not offer the possibility to modify registered prefabs. It is possible, but not recommended, to edit the .Xml file with a text editor. The easiest way is to add the prefab to a tree structure, modify it and create a new prefab. To finish, it will be enough to delete the old prefab.

Deleting a prefab

The VRmaze GUI does not allow deleting prefabs. However, the prefab database, available in the user data folder, stores prefabs as files. Deleting a file causes the prefab in the database to be deleted.