Secrets of exporting from Blender to Unity

  • Tutorial

- Theory of the coordinate system (right-handed and left-handed)
- The theory of the correct creation of 3d models in blender
- Quick export of files from Blender to Unity3d.
- How to correctly compare the scale of the model in Blender and Unity.
- Export with the correct orientation of the model
- Why is the number of vertices displayed differently in Unity and Blender?

Scripts for automatic export from Blender to Unity3d (Link provided by darkfrei user)

Video to the article


Blender lesson number 1

Blender lesson number 2

Blender lesson number 3

Bonus texture tutorial in Unity3d


Theory of the coordinate system (right and left)


In fact, this is the most important part, I encountered a number of problems in the physics of 3d models due to incorrect export. And so let's first get acquainted with the coordinate system of the right and left.

Blender uses a right-handed coordinate system with the Z axis pointing up. Such a coordinate system is used by almost all CAD systems . See figure:

image

Unity3d, like almost any other game engine, uses a left-handed coordinate system. When Y is up, X is sideways, Z is forward. We look at the picture:

image

The theory of the correct creation of 3d models in blender


First you need to study the folder and file structure of our 3D model in Blender.
Refence - a folder in which auxiliary drawings can be stored, drawings that help build the 3D model
Textures - a folder in which textures should be stored.
Flags_snow.blend - our 3d model in blender format



Now for the correct export of the 3d model, we must understand for ourselves that Z + will be the direction in the game when the object moves forward, (Z-) is the direction when the object moves backward. (X + -) are the directions of rotation to the side - but this is in Unity , which uses a left-handed coordinate system . And in the right-handed coordinate system(Blender, 3ds max) Y + this will be the direction when the object is looking forward and (X + -) this is the sideways direction. This means that the object should be in the scene as in the figure, otherwise expect physics problems:



All rotation parameters should be set to 0 for further work and for the correct generation of the Mesh, Scale must be set by default. To do this, we will do the following in Blender.

1) Select all the objects in the scene (A key)
2) Object> Apply> Rotate & Scale.

Now all rotation parameters are accepted and set to 0 . And the scaling parameters (Scale) are set to the default (1) . We look at the picture:

image

Thanks to the user Leopotam, it turned out that it is better to assign a texture in Unity3d itself, and not in Blender , otherwise, with each export of the FBX file, you will create an object.fbm folder (an empty folder that does not affect anything except creates an extra object in the window by Project .

Export with the correct model orientation


Now we can do the “Right Export” from the right-handed coordinate system to the left-handed coordinate system.

1)
Select all objects (A key) 2) Press the sequence R> X> -90 .
3) Object> Apply> Rotate.
4) Press the sequence R> X> 90 .

Be sure to do this in this sequence. Next, export the model to Unity . File> Export> FBX with the following settings:



Fast file export from Blender to Unity3d.


After exporting the model:
1) Go to the folder with this model and copy the Textures folder (folder with textures) and our FBX file .



2) Insert into the Assets folder of our project. This will allow Unity to import the model directly with the textures that were configured in Blender .



Why is the number of vertices displayed differently in Unity and Blender?


As we see in the figure, the number of vertices (verts) on the object in Unity3d shows 28.
We look at the figure:


And the number of vertices in Blender = 8



This is due to the fact that in Unity3d the number of vertices of the figure itself and the number of vertices in the UV scan are calculated:



When creating seams , one face is divided into 2 faces, and following mathematics, 1 face consists of 2 vertices, therefore there will be 4 vertices of 2 faces. For example, use the Smart UV Project scan and set the maximum Angle Limit .



We look in Blender and the number of vertices is reduced from 28 to 24 vertices. If anyone has a more optimized way. Write in the comments, we will discuss. Some will say that it was reduced by only 4 vertices, and imagine if there are 100 or 200 of such objects, or the number of vertices in more detailed objects is reduced by 100-300. In my opinion, not a bad optimization method.



How to correctly compare the scale of the model in Blender and Unity.


All units of measure that in Blender that in Unity default to a unit of measure Units . 1 Units = 1 Meter . Therefore, developers are advised to take 1 unit of game space for 1 real meter, and it is better to adhere to this (at least to tinker with physics).
And so we will understand the units in Blender, in the principle in Blender they can be changed, but by default in Blender Units is used .

We look at the figure:



We see the Dimension parameter . in the figure we see Dimension in X, Y, Z = 1,1,1; hence this figure is a cube with dimensions of 1x1x1 meter. We export to Unity and go to the Inspector tab,



look at the parameterScale Factor , if you have Unity version less than 5, then the default Scale Factor will be 0.01, we will correct this parameter by 1, if you have Unity5 then the Scale Factor will default to 1.

Conclusion


That's the whole article, as we see the export of 3d models from Blender to Unity , this is not so difficult. For a more detailed discussion of this material, I suggest watching the video tutorials at the beginning of the article >> link

Supplement from Leopotam


Leopotam:
Nothing was said that you can’t hang textures in the material (only that in the UV-window), otherwise the unit will start to create folders like object.fbm and try to import textures into them regardless of what is in the neighboring Textures folder. Here lies the problem - it is useless to delete them, the next time you re-import (for example, when you select the repository in a new folder or changing the target platform), the asset folder will appear again. The only solution is to properly prepare this case in a blender. Well, or disable the import of materials and configure prefabs with your hands.

Answer:
Yes, indeed, in Unity 5, these folders started to be created (during primary import) before I didn’t notice them, but they are empty and can be deleted (they are created only during primary import) and look for textures in the Textures folder and the Shader is applied depending on the material settings, if the material is standard and then apply Diffuse with an already configured texture, if Transperty is used in materials, then apply the corresponding Transperty shader in Unity3d and the texture also apply. Changed the target platform, from Web Player to Desktop - nothing has changed, folders have not been created. Changed to Ios - nothing has changed. Unity 5.0.1f1

Leopotam:
Nothing was said that if an armature with animations is exported, then you can’t use the FBX 7.4 BINARY format, only the old FBX 6.1 ASCII, otherwise everything in the unit will go in the style of “bloodsuckers ...”.

Answer:
Thanks for the additional information, I didn’t work with animation in Blender and, in fact, in the developed project, bone animation is not required, therefore I knew little about this material.

Also popular now: