Adding Object into a New World
Starting to work with Unigine engine is easy. This tutorial will help you to find out how to create a simple static scene by adding an object from the third-party application into a new world.
To start with, we will need to export the model from a 3D model editor. We are going to use Autodesk 3ds Max, but export from Autodesk Maya is also available and can be done in the same way. After that, we will create a new world (a scene), add the model and tell the renderer how to make the model look like in real-time.
Still reading? Get started with your own Unigine-powered project right away!
Requirements
- You should have Unigine plugins and ImageDDS installed. They are installed automatically by default.
- It is supposed that you already have a finished 3D model with assigned materials ready to be exported.
See also
- You can also watch a video tutorial Exporting an Object from 3ds Max to Unigine Engine on the same topic.
- Detailed recommendations and tips for exported meshes can be found in the Static Geometry article.
Step 1. Set Up a File Structure
First of all, set up a file structure of a new project. Recommendations are as following:
- data - the new project should be stored in this folder, as all data required for rendering worlds is read from this folder.
- new_project
- materials - folder to store materials libraries. They contain settings for all materials used in the created world.
- common
- meshes
- textures
- uncompressed - a separate folder to store source uncompressed textures.
- materials - folder to store materials libraries. They contain settings for all materials used in the created world.
- new_project
Step 2. Export a Mesh
-
Open the mesh in 3ds Max and prepare it for export:
- Move the model close to zero as possible. Otherwise, you may encounter accuracy problems.
- Unigine engine supports the following formats of textures:
- Targa (TGA)
- Portable Network Graphics (PNG)
- JPEG (JPG)
- PhotoShop Document (PSD)
- Direct Draw Surface (DDS)
- Make sure that either dimension of any texture is a power of two. Textures of improper size produce mipmap artifacts.
- Select the mesh. All the selected objects will constitute one mesh with different surfaces. The surfaces will be automatically named after objects in 3ds Max.
- In the main menu bar click Unigine -> Mesh export. Only geometry will be exported.
- Select Mesh File dialog will be opened. Here, choose a folder to save the mesh and a name for the created mesh file.
All filenames in Unigine are case sensitive!
- Next you will see a dialog with export options.
It means that the mesh will be exported with the following parameters:
- Split by material. Unchecked box indicates that the mesh need not be split by multi-material ID assigned to polygons. Instead, it will be exported as one mesh.
- Vertex Cache. This optimization allows to take the maximum advantage of the vertex cache by reordering the faces of the mesh so that triangles sharing vertices are exported reasonably close together. It maximizes vertex cache hits and is better to be always checked.
- Align. Here you can select the origin of coordinates for experted mesh. "World" means the world origin of coordinates. "Pivot" means the pivot point of the model. Other values specify positions relative to the model bounding sphere.
- Scale. This is a multiplier to scale the model, if it is modeled too large or too small. The default value of 1 means the mesh is exported without scaling. Keep in mind that all default Unigine settings (for example, camera speed and default light radii) imply that 1 unit = 1 meter.
- Digits. This field specifies a required precision of numbers. In our case, the amount of digits after a decimal point will equal 6. In most cases this value can be left unchanged.
- Map channel 1 and Map channel 2. Here it is specified that into the first channel of the exported UV map should be copied the first UV channel. The second channel will be filled with zeros.
- Click OK for the mesh to be exported.
Step 3. Create a New World
- Run Unigine Editor. To release the mouse, if grabbed, press Esc. Other controls are listed here.
- Load the editor:
- Press ` to open console.
- Type editor_load command.
To reload the editor next time, simply press U. If you quit Unigine while the editor is opened, it will be loaded automatically next time you run Unigine. - To create a new world, click Create new world button on the editor interface panel, or press CTRL + N.
- Choose the directory and a File Name for the new world. It must be created under <Unigine>/data folder.
After that, two new files will be created:
- newworld.world - an XML file containing nodes, material libraries and different rendering settings.
- newworld.cpp - a world script file.
A new world with default sun node is created. You can keep it or delete at your own discretion.
Step 4. Adding a Mesh into the World
- On the editor panel click Add an object button and choose Static or skinned mesh.
- In the opened file dialog, choose the mesh file you've exported from 3ds Max.
- The model will appear in gray. This is because it uses a default material mesh_base. To change it, you will first need to create new material.
- The node can be renamed in the Name field (Nodes -> Node tab).
Step 5. Assign Materials
- Open the Materials panel by pressing M.
- Open the list of preloaded material libraries under the preview area:
- At the present moment no custom libraries are associated with the world. Click the Add library button to create one.
- Name the created library and click OK.
- Now you've got a material library to save new materials to.
- To create a custom material for the mesh, select mesh_base (or any other basic material) in the list and click inherit the material.
The inherited (child) material takes all properties and their values from its parent material but overrides those that should be different (like textures). If you change some setting in the parent material, its child materials will be changed automatically the same way, unless they override that setting.
- Choose the material library, where to the material will be saved, and specify the name.
- Select the new material in the list.
- Go to the Textures tab to load uncompressed textures, that need to be assigned to the mesh.
- Select the path to the textures.
The textures will be automatically compressed if they are stored in /uncompressed folder and have the following postfixes:
- Diffuse - "_d"
- Normal - "_n"
- Specular - "_s"
If uncompressed textures are changed when the editor is loaded, they are compressed and automatically replace old textures. If changes are made while the editor closed, the compressed texture will not be updated. - In the nodes list select a target node (by pressing N). Open the Surfaces tab on the right. Select the surfaces for which a material should be assigned.
- Materials can be assigned in two ways:
- You can assign materials in the Node settings: And select the material in the list.
- Or simply click Assign material button in Materials (it will be assigned to the currently selected surface of the node that is chosen in the Nodes list):
Step 6. Save the World
After finishing the work, save the world by pressing CTRL + S or Save world button on the editor panel.