maanantai 15. helmikuuta 2016

Blender Baked Objects

I had to create baked 3D objects, which means that shadows are baked in the image. So if this kind of model would be used in for example Unity where it is possible to cast light, the object would have its own baked shadow no matter how lamps are moved. I am using Blender so shortly about the file formats:

OBJ

The OBJ file format is a model format for static meshes. It supports multiple meshes with different textures and materials. Meshes can also have different materials assigned to their polygons.
Thereby the OBJ format provides more flexibility with respect to textures than the MD2 format which can only use one texture. However the OBJ format does not support animations. Thus, it is recommended to use the OBJ format for high quality static objects and rely on the MD2 or the FBX format for animated models.
obj file needs .mtl which contains the material info and .obj which is the actual 3D object.

MD2
The MD2 file format is an ancient but efficient 3D file format which nicely supports vertex animations. MD2 models cannot have different colours but only one texture. Therefore, textures have to be baked in case for instance "vertex colours" shall be shown. Also the filename of the texture must be the same as the model's.(e.g. modelFile.md2 + modelFile.png)
Note for animations: please use 25 fps when exporting animations.
MD2 converter is deleted from metaio git repository since apple bought it. The converter can be found from Blender forums if looked carefully.

From Image to SVG and exporting to Blender

Any image can be opened with Inkscape and then converted to SVG which can be imported to blender. 
  1. Select image by clicking it
  2. Click Path --> Trace bitmap
  3. Select "Remove background"
  4. Click OK and close window. Before closing window, you can tick "Live Preview" to see if your image works. 

Then fire blender and click File -> Import -> Scalable Vector
Then you can select your imported SVG and extrude it from the path settings.
Here is a tutorial for this task: https://www.youtube.com/watch?v=ows2QTiMRPg

Baking textures to object
To bake textures to object, first define the color of your object and create basic lights for the environment. If you don't want only direct light, you can tick "Ambient Occlusion" from the world tab. If this is unset, some parts of your object will be completely black if there is no light cast to them.
Then it may be a good idea to convert your curve to mesh file, so press ALT + C and convert to mesh from curve. This may do some weird transformations, so it is possible your UV mapping fails because of this and you may need to create the 3D object manually. Then the SVG export is not a solution (sad)
Open UV image editor, select your object in edit mode and press U and select "smart UV project"

Then from the UV editor, click new either "blank" or "UV grid" and ok. Your UV map turns black or UV grid.

Then head to camera render section and from the "Bake" hit bake. Blender will then bake the lightning into the material.

Then we need to apply the baked material to the object. Save the baked image from UV editor save button. 
From the texture settings, check that your object has the saved image set as texture and UV map is set to UV



Blender .obj export settings
  • To export objects properly from Blender the object should: back face follow green (Y) arrow, UP follow (Z) blue arrow, and right side red (X) arrow.
  • Object origin should be in the center of the object and origin should be in the middle of the editor.
  • When exporting to .obj file format Forward and UP values can be default. Scale should be at least 10. Everything else as default is fine.



Finally check that the exported object has mtl file and it points to correct material file if material is used. To test your objects, techie persons can try this canvas loader: https://github.com/xxv/jsc3d/tree/master/jsc3d

Ei kommentteja:

Lähetä kommentti