📜 ⬆️ ⬇️

Urho3D Editor (Part 1)

We continue to deal with the engine Urho3D. This time I want to focus on the editor. It is quite simple to use, but some points definitely require explanation, and official documentation does not disclose them. Well, at the same time write a small toy. Let's get started



Editor too game


The editor is an AngelScript script run by the laucher that we used last time . This means that its code can be studied along with other examples and, if desired, easily modified. You can start the editor using the batch file Build / bin / Editor.bat.

Navigation is similar to control in a shooter. W and S - move forward and backward, A and D - left and right, Q and E - down and up. With squeezed shifto move faster. You can use the arrows. The clamped right mouse button allows you to rotate the camera in different directions. When the middle button is held down, it rotates around the selected object. If you turn the wheel, then the viewing angle (fov) changes. Full list of keys can be found here .
')

Settings


View-> Editor Settings - setting display and control. For fans of Blender, there is an opportunity to choose an alternative keyboard layout. An option to pay attention to - New node mode. The default mode is Use distance. In this mode, new nodes are created in the center of the screen at the distance specified in the New node distance column. As for me, this is not very convenient. I like the second mode much more - In center. In this mode, new nodes are created in the center of coordinates and can be moved from there to the desired position. The third mode (Raycast) is similar to the first, only the fixed distance is not used, but the intersection with the scene is sought.

View-> Editor Preferences - setting up the interface. Of the interesting things here is the ability to select a language (including Russian) and set the transparency of the interface. Minimum opacity - transparency when moving the view, Maximum opacity - the rest of the time. I usually set both values ​​to 1 for distracting. Note: for new values ​​to apply, press Enter after input.

All settings are stored in the file c: \ Users \ USERNAME \ AppData \ Roaming \ urho3d \ Editor \ Config.xml (in Windows). To reset the settings, this file can be deleted.

Console


Pressing F1 opens the console. It can work in two modes, switching between which is done using the button to the left of the input field.

In FileSystem mode, the console works as a normal Windows command line (if you have Windows of course). For example, if you type “notepad.exe”, a notebook will open.

In Script mode, all commands entered are executed by the AngelScript interpreter. For example, the command “log.Write (1 + 2)” will output 3. Here we come to understand that the console output is a log. The log in text form is written to the file c: \ Users \ USER_NAME \ AppData \ Roaming \ urho3d \ logs \ Editor.as.log. It will help you a lot when debugging scripts.

The first steps


Take the Urho3DHabrahabr02Start.zip archive from the github.com/1vanK/Urho3DHabrahabr02 repository and unzip it into an empty folder (I have this path “d: \ MyGames \ Urho3DHabrahabr02 \ Urho3DHabrahabr02 \”, so I will use it for clarity, I will use it for clarity, I will use it for clarity, I will use it for clarity, I will use it for an example of clarity for the sake of reference This archive contains resources that we will need when creating the game: several models, materials for them, and one sound file.

In the editor, click File-> Set resource path ... and specify the path "d: \ MyGames \ Urho3DHabrahabr02 \ Urho3DHabrahabr02 \ GameData \". Now the editor has access to three folders with resources: its own Data and CoreData folders, which are located next to it, and the GameData folder, which we specified.

Create a scene


In the Resource Browser, select the Models folder and drag Ground.mdl to the root Scene node in the Hierarchy window.



A new node with the StaticModel component (a simple model without a skeleton) will be created automatically. In the Attribute inspector window, specify the name Ground for the node, click the Pick button next to the Material column and select Materials / Ground.xml.



Now we have the floor, but the scene is poorly lit, so let's add a light source.

To begin, create a new node. Select the root Scene node and select the menu item Create-> Local node. You can also create a Replicated node. In our case, there is no difference, since the replicated nodes are synchronized during network interaction, and we do not plan to work with the network. Nodes can also be created not through the menu, but with the help of a vertical panel on the left side of the editor.

Make sure that the newly created node is selected, and select the menu item Create-> Component-> Scene-> Light (many components are duplicated on the left vertical panel). In the Attribute inspector window, set a name for the node, select the source type Directional (sunlight), specify the brightness, rotation, position (for this type of light the position does not matter, but raise the node higher so as not to interfere with the scene). Also enable the Cast Shadows option so that the light source can create shadows.



Now change the background lighting. Select the root node of the Scene and create the Zone component (Create-> Component-> Scene-> Zone). Set the background color (Fog Color) and background color (Ambient Color). These values ​​will be used only if the camera is within the zone, so expand the boundaries (Bounding Box Min / Max).



Scripts


Create a new node, add the AnimatedModel component (a model with a skeleton) to it, and specify the Models / Cannon.mdl model and Materials / Cannon.xml material. Move the gun up a bit, and also turn on the Cast Shadows option so that the gun casts a shadow.



The child nodes that you see on the cannon are bones built into the model. For now, ignore them.

In the GameData \ Scripts folder, create a Cannon.as file with the following contents:

class Cannon : ScriptObject { //      . int direction = 1; //    . void Update(float timeStep) { //     x (node   ,    ). float pitch = node.rotation.pitch; //   ,       . if (pitch >= 70.0f) direction = -1; else if (pitch <= -10.0f) direction = 1; pitch += 30.0f * direction * timeStep; node.rotation = Quaternion(pitch, 0.0f, 0.0f); } } 

It is better to save scripts in UTF-8 encoding, then there will be no problems with Cyrillic.

Add a ScriptInstance component to the Cannon node (Create-> Component-> Logic-> ScriptInstance). Click on the Pick button and select the newly created file, and in the Class Name column, enter Cannon (the file may contain several classes). After entering do not forget to press Enter. If everything is done correctly, the direction variable that we declared in the script should appear below the class name.

Make sure that the RevertOnPause switch (the third button on the top panel) is activated and click the RunUpdatePlay button (the first button on the top panel). The gun will start to rotate back and forth. To stop, click RunUpdatePause (middle button).



What does the RevertOnPause switch do? If it is active, before starting the state of the scene is remembered, and when you click on a pause, the state is restored to its original state. This button is still useful to us in the second part of the lesson.

In the meantime, save the scene (File-> Save scene as ...) to the GameData / Scenes / Level01.xml file.

To be continued...

Source: https://habr.com/ru/post/265749/


All Articles