Documentation/Tutorials/Creating a Simple Object Type
From NeoAxis 3D Engine Wiki
|Language:||English • Russian||Status:||Approved|
Almost every project's maps and levels are made with static objects. For example tunnels, rooms, hallways, rocks, towers, buildings, etc. In NeoAxis, you have two ways to make this kind of objects:
- By using StaticMesh.type,
- By creating an object type (.type file) in the Resource Editor that you will then place on the map.
Each method has it pluses and minuses.
There is no need for you to create a type in the Resource Editor when using StaticMesh.type for your objects. You just need to place the model (.mesh file) on the map and configure it's settings if needed, for each instance of the mesh. This method is the best for creating large static objects (buildings, rooms and geometry, etc.) the player will not interact with. It's also the most optimized.
The other way requires you to create an object type (.type file). The benefit is that you can set the object parameters once and just use it on the map then. Moreover, you should use this way if you want to add interactivity to the object (for example, to change some parameters at runtime). How to use and configure an object type is described in the creating a simple object type tutorial.
A method for placing static objects on the map by creating an object type (.type file) will be described below.
In this tutorial we will learn how to create new object types. As an example, we will create a simple stone.
For this tutorial we need to prepare some resources:
- stone model
For this tutorial you can import a custom 3D model or use an existing one.
For the tutorial, we will use a stone model that is already in the SDK.
Launch the Resource Editor.
First of all, create a folder where you will put your new object type. To do this, right click on the Data\Types\StaticObjects folder and in the context menu, select New -> Folder.
Specify a name for the newly created directory: MyStone.
For our new type, we will need the following files:
- texture MyStone.dds,
- material MyStone.highMaterial,
- model MyStone.mesh.
Copy in newly created directory the original resources from the Data\Types\StaticObjects\Stone folder. To do this select the Stone.dds, Stone.highMaterial and Stone.mesh files white holding Shift. Then click the right mouse button and in the context menu select Copy.
Then, paste the files in the MyStone folder using Paste from the context menu.
Now rename the 3 files to MyStone.dds, MyStone.material and MyStone.mesh by right clicking on an object and using Rename in the context menu.
When editing a material (*.highMaterial), a special window appears and displays the suggested name. You can leave it or enter another one.
For some types of resources (materials, object types) names must be unique within the project.
To complete the preparatory part of the lesson, we will edit the MyStone.highMaterial material a bit and assign it to the MyStone.mesh model.
Select the material and switch to edit mode: right click on it and in the context menu, click on Edit. Another way to enter edit mode for a resource is to double click on it.
In the Properties material settings window), select the Diffuse1Map property and press the ... button in front of it.
In the popup window, select the MyStone.dds texture from the Types\StaticObjects\MyStone folder and click OK.
To save changes, press the (Save) button (with the floppy disk icon) in the main panel. Then leave edit mode by pressing Close Editing in the context menu. Another way to exit edit mode: click Close Editing on the main panel or clik on another resource in the resource tree.
Now you will setup the texture on MyStone.mesh 3D model. Switch to edit mode (press Edit in the context menu or the main panel). Replace the old material with the new one that we just edited. To do this, expand SubMeshes in the properties so it displays the settings for the 0-th submesh. Now just press the ... button in front of MaterialName.
Now just select the MyStone.highMaterial located in the Types\StaticObjects\MyStone directory.
To finish editing, click on the Save button, then on Close Editing in the toolbar. After this our texture, material and 3D model are ready to be used.
Creating a New Type
Now we will start creating a new type for our object. *.type (object type) is the main configuration file describing the object. It contains the main parameters that allow you to manage them.
Click the right mouse button on the MyStone folder. Select New -> Entity Type in the context menu.
In the popup window, specify the name of the type - MyStone - and select the object class MapObject. This class is the base for most simple objects. Then, click on Next.
We will now edit the type. To do this, select MyStone.type and right click on it. In the context menu select the Edit.
Now let's add a 3D model to the type. Right click on the workspace and from the appearing context menu select Attach Object -> 3D Model.
In the popup window, select our 3D model - MyStone.mesh - and click on OK.
Now we can see the model on the screen. We can also find it in the list of attached objects.
Yellow frame around the workspace editor means that the object has been changed but not saved yet.
In order to avoid other dynamic objects (for example, our character) to pass through the stone, we need to adjust the collision detection (Collision). To do this, select the attached model in the Objects window. Next, in the properties window (Properties) set the Collision property to True. Now the physics collision mesh will be calculated based on the object's geometry.
Now, make sure that the object can be created in the Map Editor. To do this, select the root MyStone object in the Objects window.
Then check that the property CreatableInMapEditor is set to True. This flag determines whether the object will be displayed in the list of objects in the Map Editor.
After setting all the properties, click Save in the main panel to save the changes, then leave the edit mode. To do this, click on Close Editing in the main panel.
The creation of our new object type is now done!
Placing Types in Map Editor
Run the Map Editor to place the object type you have just created on a map.
Open any map or create a new one.
In the object creation window (Object Creation), select the MyStone type in the Types\StaticObjects folder. Place one or more stones in the workspace, then press press Escape to complete the process of adding stones to the map.
To view the object's properties, select it and look at the properties window (Properties).
Congratulations, you have completed the tutorial!
In this tutorial we learned how to prepare resources for new object types, to create and configure .type files and to place them in the Map Editor.