Crystal Space 2.0.0: 5.8.6 Exporting Portals

[ < ] | [ > ] |  | [ << ] | [ Up ] | [ >> ] |  |  |  |  | [Top] | [Contents] | [Index] | [ ? ]

### 5.8.6 Exporting Portals

This section presents how portals can be created in order to link the different sectors of a virtual environment. Each Blender scene in the file is exported as a Crystal Space sector, and the use of specific meshes allows to define portals between them.

This is made using the `‘Crystal Space Portal’` panel that is found in the `‘Object Data’` context of the `‘Properties’` window:

#### Creating portals

In order to define a portal, you must create two meshes that will be the source and the destination of the portal. Each mesh will be in a separate Blender scene so that the portal will lead from the first scene to the second one (this is not a limitation and a portal is allowed to lead to the same sector than the starting one).

You must pay attention to the shape of your source mesh as well as to the order of its vertices. The shape of the mesh will be used as the one of the Crystal Space portal, but one tricky problem is that the order of creation of the vertices will also define its orientation. For a correct behavior, be sure to create the vertices of your source mesh in clockwise order when you look at the portal.

Unless you plan to create another portal to go back in the other direction, the actual shape of the destination mesh has no importance at all, only its position will be important.

Once the two portal meshes are created, select the source mesh, go to the `‘Crystal Space Portal’` panel, and activate the `‘Portal’` checkbox. A text entry `‘Destination mesh’` appears, you must now type into it the name of the destination mesh of the portal. Once done, the object will be exported as a portal instead of a mesh.

You must also pay attention to the relative transform of the source and destination meshes since it will define the warping transform that is applied when crossing the portal. If the source and the destination of the portal are the same (i.e. there is no warping transform), then the two meshes should be at the same position.

#### The `‘portaltut’` example file

As an example we will follow the making of the file `‘portaltut.blend’` that can be found in the CS/browser/CSAssets/trunk/blender/ SVN repository.

The example is split in three different scenes that will correspond to three different sectors in Crystal Space: two rooms `‘roomA’` and `‘roomB’`, to be linked by a transitional sector `‘Corridor’`. The goal of this example will be to create the portals in order to travel from one room to the other.

The walls of the rooms have already been created, and some holes have been dug that have to be replaced by the portals:

Let's do the following steps:

- Position the cursor where the portal will be defined: in `‘Edit’` mode, select the vertices at the boundary of the portal, the press `‘Shift-S’` then `‘Cursor to selected’`.

- Create the source mesh of the portal: add a new dummy mesh, e.g. a cube, then go to `‘Edit’` mode and remove all the vertices of the mesh.

- Create the vertices of the source mesh: use `‘Ctrl-LMB’` for all vertices, being sure to turn in clockwise order. You can create a face after that.

- After a set of `‘Shift-S’` operations, the vertices have been aligned to the walls, and the mesh has been renamed purposely `‘PortalA2C’`.

- Now we will create the destination mesh: in object mode, select your source mesh and duplicate it with `‘Shift-D + LMB’`, create a link to it in the scene `‘Corridor’` with `‘Ctrl-L’` then `‘Objects to scene’`, delete the copy in the first scene, then finally rename your destination mesh into `‘PortalC2A’`.
- Re-orient the vertices of the destination mesh: since the mesh is a copy of the original one, the vertices will be in counter-clockwise order when facing the portal. In order to fix this, go to `‘Edit’` mode, select all the vertices and rotate them with `‘R-X-180’` (or whatever rotation axis).

- Now that both meshes have been created, we can define them as portals. Select the source mesh, go to the `‘Crystal Space Portal’` panel (in the `‘Object Data’` context of the `‘Properties’` window), select the checkbox `‘Portal’`, and enter the name of the destination mesh, i.e. `‘PortalC2A’`. Repeat the same process for the destination mesh in order to define a portal back to the first room.

- Repeat the process for the other portals leading to the second room. Here is the result once you press the `‘Export and Run’` button:

#### Troubleshooting

If some of the portals don't look ok while exporting Blender worlds, check that:

- the name of the destination mesh has been accepted, i.e. the error message `‘ERROR: unknown mesh name’` does not appear in the portal tool panel.
- there is no error message on the console.
- you have defined the vertices of the portal in clockwise order (if done wrong, you may typically see some problems with the triangles of the portal).
- the destination mesh is not linked at several places in the scenes (in this case, the script will randomly pick one of those linked meshes).
- the relative position of the source and the destination mesh corresponds correctly to the warping transform of the portal (i.e. they are at the same position if the warping is an identity transform).

If you still have a defective portal after you have checked those points, it is highly probable that the relative transform of the source and destination mesh is causing the problem. A good hint in this case is to move the destination mesh at the same position and orientation than the source mesh in order to get a valid portal with an identity warping transform, then, starting from this configuration, move the destination mesh by small steps in order to visualize the changes.

[ < ] | [ > ] |  | [ << ] | [ Up ] | [ >> ] |  |  |  |  | [Top] | [Contents] | [Index] | [ ? ]

This document was generated using texi2html 1.76.