Перші кроки Кімнатами та Порталами¶
Керівник кімнат RoomManager¶
Завжди, коли ви хочете використовувати систему порталів, вам потрібно включити спеціальний вузол у своє дерево сцени, який називається RoomManager (Керівник Кімнат). RoomManager відповідає за технічне обслуговування системи, особливо перетворення об'єктів у ваших кімнатах всередині кімнатної діаграми, яке використовується під час виконання вибракування оклюзії та інших завдань.
Перетворення кімнати¶
This conversion must take place every time you want to activate the system. It does not store the room graph in your project (for flexibility and to save memory). You can either trigger it by pressing the Convert Rooms button in the editor toolbar (which also has a keyboard shortcut) or by calling the rooms_convert()
method in the RoomManager. The latter method will be what you use in-game. Note that for safety, best practice is to call rooms_clear()
before unloading or changing levels.

If you convert the level while the editor is running, the portal culling system will take over from the normal Godot frustum culling, potentially interfering with editor features. To get around this, you can turn portal culling on and off using either the View Portal Culling toggle in the View menu on the editor toolbar (which also has a keyboard shortcut) or the Active setting in the RoomManager node.
Примітка
To use the RoomManager, you have to tell it where the rooms are in your scene tree, or, more specifically, where the RoomList node is. This RoomList is the parent of your rooms - see below. If the RoomList is not set, conversion will fail, and you will see a warning dialog box.

RoomList (Список Кімнат)¶
Before we create any rooms, we must first create a node to be the parent of all the static objects, rooms, roomgroups, and so on in our level. This node is referred to as the the RoomList
.

Примітка
The roomlist is not a special node type – it can just be a regular Spatial.
You will need to assign the roomlist node in the RoomManager so that it knows where to find the rooms.
Why do we use a specific branch of the scene tree and not the scene root? The answer is that there are many internal details of the system which are easier to manage if the rooms are placed on their own branch.
Often you will end up completely replacing the roomlist branch at runtime in your game as you load and unload levels.
Кімнати¶
Що таке кімната?¶
Rooms are a way of spatially partitioning your level into areas that make sense in terms of level design. Rooms often quite literally are rooms (like in a building). Ultimately though, as far as the engine is concerned, a room represents a non-overlapping convex volume in which you typically place most of your objects that fall within that area.
A room doesn't need to correspond to a literal room. It could, for example, also be a canyon in an outdoor area or a smaller part of a concave room. With a little imagination, you can use the system in almost any scenario.
Чому опукла?¶
Rooms are defined as convex volumes (or convex hulls) because it's trivial to mathematically determine whether a point is within a convex hull. A simple plane check will tell you the distance of a point from a plane. If a point is behind all the planes bounding the convex hull, then by definition it is inside the room. This makes all kinds of things easier in the internals of the system, such as checking which room a camera is within.
Опуклий корпус. Корпус визначається як серія площин, повернутих назовні. Якщо точка знаходиться позаду всіх площин, вона знаходиться в корпусі.

Чому недопустимі перетини?¶
Якщо дві кімнати перетинаються, і камера, або гравець, знаходиться в зоні перетину, то немає ніякого способу вказати, в якій кімнаті повинен знаходитися (і відтворюватися) об'єкт. Вимога для кімнат не перетинатися, має наслідки для проектування рівня.
If you accidentally create overlapping rooms, the editor will warn you when you convert the rooms, indicating any overlapping zones in red.

The system does attempt to cope with overlapping rooms as best as possible by making the current room "sticky". Each object remembers which room it was in during the previous frame and stays within it as long as it does not move outside the convex hull room bound. This can result in some hysteresis in these overlapping zones.
There is one exception, however, for internal rooms. You do not have to worry about these to start with.
Як створити кімнату?¶
Кімната - це тип вузла під назвою Room, який можна додати до дерева сцени, як і будь-який інший. Ви можете розмістити об'єкти всередині кімнати, зробивши їх дітьми та онуками вузла Room.
Як визначити форму і положення опуклого корпусу моєї кімнати?¶
Оскільки визначення меж кімнати є найважливішим аспектом системи, є ТРИ методи, доступні для визначення форми кімнати в Godot:
Використовуйте геометрію об'єктів, що містяться в кімнаті, щоб автоматично створити приблизну межу.
Manually edit the points that define the convex hull in the room inspector or drag the points around using the editor gizmo (see Редагування точок кімнати).
Provide a manual bound. This is a MeshInstance in the room that has geometry in the shape of the desired bound, with a name with the postfix
-bound
. This is something you might choose to do if you create your levels in Blender or similar (see Створення систем кімнат в Blender (або інших інструментах моделювання)).
While the first option can be all that is required, particularly with simple rooms or for pre-production, using manual bounds gives you ultimate control at the expense of a small amount of editing. You can also combine the two approaches, perhaps using automatic bounds for most rooms but manually editing problem areas.
Автоматичний метод використовується щоразу, коли не надається ручна прив'язка.
Проста пара кімнат. Поле порталу показано напівпрозорим червоним кольором, а корпуси приміщення показані зеленим каркасом.

Портали¶
If you create some rooms, place objects within them, then convert the level in the editor, you will see the objects in the rooms appearing and showing as you move between rooms. There is one problem, however! Although you can see the objects within the room that the camera is in, you can't see to any neighbouring rooms! For that we need portals.
Portals are special convex polygons that you position over the openings between rooms in order to allow the system to see between them. You can create a portal node directly in the editor. The default portal has 4 points and behaves much like a plane
MeshInstance. You can add or remove points using the inspector. A portal requires at least 3 points to work - this is because it needs to form a polygon rather than a point or line.
To save editing effort, only one Portal is required between each pair of Rooms. You do not need to (and indeed should not) create two Portals that overlap in opposite directions. Portals default to being two-way, but you can make them one-way in the Portal inspector.
Тому ви повинні розмістити портал тільки в одній з кожної пари сусідніх кімнат - це "вихідна кімната" порталу. Як правило, не має значення, яку кімнату ви виберете в якості вихідної. Нормаль порталу (стрілка в gizmo) повинна бути спрямована назовні від вихідної кімнати.

Не плутайтеся зі стрілкою. Хоча стрілка показує, в якому напрямку спрямований портал, більшість порталів будуть двосторонніми, крізь них можна дивитися з обох напрямків. Стрілка важливіша для забезпечення того, щоб портал посилався на правильну сусідню кімнату.
Прив'язка Порталу¶
There are two ways to specify which room the portal should link to:
Залиште Linked Room (Пов'язану Кімнату) в інспекторі порожнім. Система спробує автоматично зв'язати портал з найближчою сусідньою кімнатою під час перетворення. У більшості випадків це добре працює.
Explicitly specify the room by setting the Linked Room in the inspector.
Примітка
Портали визначаються як набір 2D-точок. Це гарантує, що утворений багатокутник знаходиться в одній площині. Перетворення визначає орієнтацію порталу. Точки також повинні утворювати опуклий багатокутник. Це застосовується шляхом перевірки вказаних точок, ігноруючи будь-які, які не утворюють опуклу фігуру. Це полегшує редагування, зменшуючи помилки системи.
Тепер спробуйте¶
By now you should be able to create a couple of rooms, add some nodes such as MeshInstances within the rooms, and add a portal between the rooms. Try converting the rooms in the editor and see if you can now view the objects in neighbouring rooms through the portal.

Тепер ви освоїли основні принципи системи.
Наступним кроком є вивчення різних типів об'єктів, якими може керувати система.