Saturday, May 9, 2015

Exporting 3D Max Models Into Unity 3D Engine

Exporting 3D Max Models Into Unity 3D Engine


Part I: 3D Studio Max Model Preparation For Use in Unity 3D

1. Model

We will use already created model of the building for this tutorial. Our model was done in 3ds Max and prepared for render with V-ray. Unity 3d is not able to recognize textures of such scene, so we need to optimise model and switch to scanline materials for integration into unity 3D.
Open file that contains model. Check system units. We used millimetres in 3ds Max. Unity 3d is having it’s own units, 100 millimetres equals 1 unit in Unity 3d.
Model

2. Texture location

All the textures need to be placed into one file for the convenience of use and further optimisation. This can be done using one of utilities of 3d max – Bitmap/Photometric Paths. Click on “Edit Resources” in “Path Editor” (under “Utilities”) a window of different utilities will open up. Select “Bitmap/Photometric Paths.
Texture Location
Select all the files and click “Copy Files”, find the location of the folder where all textures will be stored in the “New Path”. Then once more select all the files, click “Set Path” and direct to the same folder. All the textures will be stored in the same location.
Texture Location 2

3. Model Optimisation

3.1 Pay attention to the amount of high-poly elements

(for example door meshes, bolts, window systems, landscaping, etc..)
Model Optimisation 1Model Optimisation 2Model Optimisation 3
It isn’t too important in our case as we are going to work with one house only and almost any video-card would be able to manage such amount of polygons. Optimisation of high poly objects is very important when working on large projects with lots of 3D objects. With large amount of hi-poly objects the project would use too much of disc space and wouldn’t be working smoothly. It would also be unsuitable for online purposes.

3.2 Sorting the objects by textures and names

We often don’t pay enough attention to identical copies of textures or objects without textures when creating model for render. It often happens when creating scene from ready libraries that have several identical textures for glass, chrome, wood, etc.. If not sorted properly this mess would cause a lot of fixing afterwards.
So, to get it sorted properly do the following:
Open Material Editor. It is recommended to clear up all the slots. Open “Utilities” and click on “Reset Material Editor Slots”
Sort by Textures and Names
A. Select instrument “Pick material from Object” and click on any object in the scene. Material of that object appears in the material editor slot:
Select Instrument
B. Click on “Select by Material”. A list of all objects with this material appears. Click select. We recommend to go to Isolate mode now by clicking Alt + Q.
C. Check if there are no grouped objects on the list. “Select by Material” tool is usually showing all the group if there is one object with the selected material. If you’ll see any group in the list you have to ungroup the objects and repeat the steps starting with B.
D. Select any of the objects. In the list of “Editable poly or Editable Mesh” choose “Attach list”. Select all the objects and click “Attach”. We get one object. It is recommended to name it as the name of material, so that it would be clear what texture is used on it. In our case it is “WoodPlank”.
Select By Material
Attach List
Everything needs to be repeated from A with all materials and objects in the scene (for glass, metal, tiles, plastic, etc..)
* The case of scene that contains Multi Sub-Object materials. If there is an object with multi sub-objects, for example the window frames are joined with the glass, you can :
a) Either leave it as it is but all the objects with this material should be joined together,
b) or use functions in object polygon settings (mesh or poly) – select ID, select all in a row and separate all elements creating simple materials for each of them.

3.3. Checking of layered polygons and normal maps

It is necessary to turn off backside polygons reflection of all prepared objects because all polygons are reflected as one sided in Unity3d. Select all the objects in the scene Ctrl+A, go to “Object Properties”, place tick on “Backface cull”.

3.4 Geometry check-up

After turning off reflection we see that the back side of the house became invisible because it’s normal maps are turned to the exterior of back elevation.
Geometry Check Up
In order to fix it we need to create internal walls. We do have object “Int_wall” in our scene already. It has several interior walls. We will add the missing ones to this object.
Geometry Check Up 2Geometry Check Up 3
There is handy tool in 3dsMax for checking overlapping polygons (available in 3dsMax 12 and higher versions). It can ve found in “Views” – “xViews” – “Overlapping faces”.
Overlapping Faces
All overlapping polygons become highlighted in green after this tool is selected. This check-up needs to be done for the entire model, not only inside of selected object (for example floor of the top floor sitting on the ceiling of lower floor).
Overlapping Polygons
Also, it is recommended to remove all the polygons that won’t be visible from any angle, for example the lower polygon of terrace.
Lower PolygonLower Polygon 2
This is essential as it will make the model lighter and if you decide to use complex textures for shadows it will reduce the areas of this texture.
You can also remove inner and side polygons of the glass as Unity 3d is not rendering correct reflections.
Inner and Side PolygonsInner and Side Polygons 2
After the process of optimisation our house consists of 12 objects with 12 unique materials and 9700 polygons. This sort of model will can be easily managed by Unity3D engine even on mobile devices.

4. Texture Preparation

Initially our model was prepared for Vray rendering, so we used several procedural maps, such as Tiles. These do not export into Unity3D, so we have to convert all materials to standard scanlines and all procedural maps replace with bitmaps. We also need textures for terrain – Normal bump and reflection maps.

4.1. Procedural maps, such as Noise, Tiles, vrayDirt

If you have difficult material and don’t want to draw it yourself, you can render this texture. Choose the texture in required material, click on “show end result”.
Show End Result
Double click on material preview, right click on the texture preview window, select “Render Map”. Enter settings (resolution and path) and click “Render”. After rendering it we can replace material with raster image.
Material PreviewRender MapRender Map 2
Note: All the settings of materials texture tiling will be ignored when exporting to Unity3d. Only the settings of texture coordinates are used for the object.
Texture Coordinates
The easiest way to create normal maps is with the help of Crazybump software, or using free plugin from Nvidia.
The more accurate and complex way is to bake maps directly in 3dsMax.
The other thing to note is that resolution of all textures should be in powers of 2 sequence (2,4,8,16,32,64,128,256,512,1024,2048…). Unity3D is automatically correcting and converting resolution that is not in powers of 2 resolution to the closest in powers of 2. For example, if your texture is 720×1025, it will be converted and saves as 1024×2048 by Unity3D.
After preparing all the textures you will need to reconvert all the materials in the scene to standard, using the only texture map in “Diffuse” slot. It is impossible to do it automatically, we need to create clear standard material and join it with texture map in “Diffuse” slot.
After going through all steps the model is optimized with:
  • Minimal quantity of objects
  • Names of the objects matching the names of materials in the scene
  • Every object has texture coordinates and standard material in texture slot “diffuse”
  • All textures are in one folder and have resolution in powers of 2
2014-09-03_183318
*Please note that size of the texture, duplication setting are going to be applied only using texture coordinates of the model, all the settings of materials (tiling, size, angle) will be ignored.
It is recommended to place our objects into the start of coordinates and set all the pivots for 0.0.0. To do this we need to select all and move everything to the centre of coordinates. Then in the “Hierarchy” tab we click “Affect Pivot Only”. Then right click on Select and Move and right click on the coordinates arrows in “Absolute World” group. We repeat all this for rotation.
Affect Pivot Only
Absolute World
The scene is now ready for the export.

This is the second part in our tutorial on exporting 3D Max models into Unity 3D Engine. In this part we show you how to setup scene size, terrain, light and camera. You can read Part 1 here.

Scene Size, Terrain, Light and Camera Setup in Unity 3D

Setting sizes

It is important to note measurement system. Our 3ds Max scene was set in millimetres. When exporting metric system to Unity 3D 100 millimetres equal 1 measurement unit in unity. The measurements of our house in 3ds Max scene are 30,000 x 15,000 x 8,000mm, but it changes to 300x150x80 in Unity3D. We’ll have to change some of the settings in Unity 3D if we decide to leave the measuring settings as they are. More detailed instructions to follow.
Start Unity. File -> New Project. Select a folder for new Project.
We also need to select components that we prepared in advance, for example scripts, special effects, etc..

Our Components:

  • Light Flares.unityPackage – optical highlighting effect in camera
  • Scripts.unityPackage – Camera control script
  • Terrain Assets.unityPackage
  • SkyBoxes – panoramic surroundings
Setup defaults for:3D
Unity 3D File > New Project
Unity 3D Project Location
Import Light Light Flares Package
Click on “Create”
After that Unity will restart with all selected components and create a number of necessary folders in the project folder.
Unity will create necessary folders
Use Drag & Drop into Assets Window to Perform Model Export
First we need to create our own folder in Unity Assets section, for example “Models”. To do that right click on Assets and select Create -> Folder
Double click to open this folder in Unity. Then we open the folder that was used to prepare textures and models for export. We select all the textures and models and drag them into our “Models” folder in Unity.
Unity Assets > Models
In order to see the model in working mode of Unity we need to drag model icon from “assets/model” field into “hierarchy”.
If all the textures exported correctly, all the materials were standard and all texture cards we used were in “diffuse” slots then we will see our model fully textured in Unity window.

Terrain, Light and Camera Setup in Unity 3D

Unity has very useful tool for creating environment, elevated landscapes, plants and a variety of different textures terrain surfaces.
In order to create landscape we need to go to either “hierarchy”-> “create” or “Game Object” -> “Create Other” , choose object “Terrain”. This object allows to quickly create landscape including plants and a variety of different textures.
We will see this object’s name in the “hierarchy” panel after adding it and if we select it we will see all its properties on the right “inspector” panel. The size of our landscape would be 2000×2000 units by default, it would be enough for the house and to cover up everything up to the line of horizon. If we decide to use real time shadows in unity for more realistic effect we need to go to settings of render “Edit->Project Setting->Quality” and set visible distance of shadow reflection “Shadow distance”.
Unity 3D Inspector Quality Settings
This needs to be done for every preset of graphics as this setting effects performance of our app.
Quality Levels
To avoid guessing this parameter we can reduce size of our scene so that maximum distance of visible shadows would always be in camera field. We need to select object v1 in “hierarchy” panel, then “Inspector -> Transformation -> Scale” . There are 3 digits in the tab that correspond to the scale of axis x y z.
Inspector > Transformation > Scale
As was mentioned earlier the size of our object is 300x150x80. Shadow distance in the default preset “Good” is only 40. So, our house model is approximately 7.5 times larger than shadow distance. In order to look at the house from the side with all it’s shadow it would have to be 300+80. This is if we don’t want to see shadows from trees around. And if we would like to add shadows of the trees that are 10 metres around house, the size would be 480… While actual shadow distance is only 40. So, we suggest to scale down the scene 20 times, so that all important objects would appear in 25-30 units. To do this we need to change xyz scale settings of v2 in Inspector tab to 0.05 (1/20).
Transform Settings
We can now centre and scale down object “Terrain, as it is quite large in size by default. We need to select “Terrain” and adjust settings in Inspector tab.
Unity 3D Terrain Script
Terrain Settings
We recommend to set 80 Terrain Width x 80 Terrain Length.
Inspector WindowCentre the terrain with the use of these tools:
2014-09-08_181711
Unity 3D Scene
Adjust Light Settings
We can access this through “Hierarchy -> Create -> Directional Light” or GameObject. Only Directional Light can reflect shadows in Unity.
Hierarchy -> Create -> Directional Light
We position it in the scene; turn on shadows in “Inspector ->Shadow type -> Hard Shadow”.
If you can’t see shadows try zooming into the object or check the scale of the scene or update Shadow distance quality settings.
Shadow Distance
Proceed to Camera Setup
Every new project in Unity is having standard camera already. It is possible to move it only in the edit mode. In order to have camera move in a game style we need to add script for camera control.
Select camera. Go to Inspector window click on “Add Components -> Camera -> Control -> Mouse Orbit”.
Add Components -> Camera -> Control -> Mouse Orbit
Additional settings appear in Inspector window.
Additional Inspector Settingss
Now we need to set the target of orbit. Click on the button to the right of “Target” line and select V2 from the list. Or you can drag the object v2 from Hierarchy panel into Target field.
To review if everything works properly click onto Play button on the top centre of the screen.
3D animation play button top centre
Play button close up
If the house doesn’t fit in and camera disappears above the ground it is possible to add restrictions for movement on Y axis and create longer distance for camera.
Y Axis Restrictions
We need to go back to the light settings now. All the parts that are in the shadow side appear black at the moment because there is global lighting missing in the scene. We can use “Ambient Light” to fix it, it lights up all the edges of our objects and creates effect of global light.
Go to menu “Edit -> Render settings -> Ambient Light”
Edit -> Render settings -> Ambient Light
You can select colour of ambient light, all the shadows will be filled in the colour selected.
Fog settings can be adjusted for more realistic perspective.
Skybox Material –   select sky settings for the scene. In case there is no list of materials to select for the sky, Skybox library will need to be imported:
Import Skyboxes
After choosing following settings:
Skybox Render Settings
The result:
Final ResultG-Net 3D is an award winning 3D architectural visualisation and animation practice with offices in London & Manchester.

0 comments:

Post a Comment

Live Translation!

Recent Posts!

Popular Posts

Contact Form

Name

Email *

Message *

CGI Dinelson. Powered by Blogger.