Difference between revisions of "Using Blender"

From Minetest Wiki
Jump to navigation Jump to search
(added info to animated textures text)
Line 2: Line 2:
 
<!--This was made using Blender 2.70, but instructions should also work for Blender 2.5 or 2.6 as menu structure is pretty similar (but possibly not 2.4 or prior).-->
 
<!--This was made using Blender 2.70, but instructions should also work for Blender 2.5 or 2.6 as menu structure is pretty similar (but possibly not 2.4 or prior).-->
  
=== On file formats ===
+
=== File format support ===
  
Minetest uses the 3D rendering library provided by [http://irrlicht.sourceforge.net/ '''Irrlicht'''].<ref>As stated on the [http://dev.minetest.net/Terminology Terminology page] of the developer Minetest Wiki</ref> As of version 1.8.1 Irrlicht can import the following mesh-formats<ref>[http://irrlicht.sourceforge.net/?page_id=45 Irrlicht Features] - section Supported Media Formats and a more detailed description of how to import the supported 3D-formats into Irrlicht [http://irrlicht.sourceforge.net/docu/classirr_1_1scene_1_1_i_scene_manager.html#a63894c3f3d46cfc385116f1705935e03 here]</ref>:
+
Minetest currently supports the following media formats for 3D content:
  
Animated objects:
+
Animated, skinned models:
* B3D files (.b3d, r, skeleton)
+
* B3D files (.b3d)
* Microsoft DirectX (.x, r) (binary & text, skeleton)
+
* Microsoft DirectX (.x) (binary & text, compression is not supported)
* Milkshape (.ms3d, r, skeleton)
 
* Quake 3 models (.md3, r, morph)
 
* Quake 2 models (.md2, r, morph)
 
  
Static objects:
+
Static meshes:
* Irrlicht scenes (.irr, r/w)
+
* OBJ (.obj)
* Irrlicht static meshes (.irrmesh, r/w)
 
* 3D Studio meshes (.3ds, r)
 
* Alias Wavefront Maya (.obj, r/w)
 
* Lightwave Objects (.lwo, r)
 
* COLLADA 1.4 (.xml, .dae, r/w)
 
* OGRE meshes (.mesh, r)
 
* My3DTools 3 (.my3D, r)
 
* Pulsar LMTools (.lmts, r)
 
* Quake 3 levels (.bsp, r)
 
* DeleD (.dmf, r)
 
* FSRad oct (.oct, r)
 
* Cartography shop 4 (.csm, r)
 
* STL 3D files (.stl, r/w)
 
* PLY 3D files (.ply, r/w)
 
  
The minetest engine does not make use of all of these formats though.
+
Textures:
The server only accepts the following file formats for media<ref>As is hardcoded in the source file [https://github.com/minetest/minetest/blob/master/src/server.cpp#L2442 server.ccp near line 2442] as of July 2021</ref>:
 
 
 
3d-Models:
 
* .b3d (B3D)
 
* .x  (Microsoft DirectX)
 
* .md2 (Quake 2 models)
 
* .obj (Alias Wavefront Maya /static)
 
 
 
Images (textures):
 
 
* .png
 
* .png
 
* .jpg
 
* .jpg
 
* .bmp
 
* .bmp
* .tga
 
* .pcx
 
* .ppm
 
* .psd
 
* .wal
 
* .rgb
 
  
Sounds:
+
Any formats not mentioned above but known to work in the past are considered deprecated and may not work in future versions. When in doubt, stick to PNG textures and the model formats listed above.
* .ogg
+
 
 +
Do not use .b3d and .x files for static meshes at the moment, Minetest currently spawns animated mesh scene nodes for these, which may result in reduced performance.
  
and for names, descriptions and other UI stuff the translation file format might also be usefull:
+
=== Picking a skinned mesh format ===
* .tr
 
  
 +
You have two skinned mesh formats to choose from, and both have their advantages and disadvantages.
  
'''Notes:''' All other media file formats including those Irrlicht might otherwise support are ignored. Different file formats may perform differently in other setups, DirectX and B3D allow animation.
+
* B3D
Animation in textures is simulated by rotating through linear aligned single frames within a given texture file, a technique called verticalframe animations in contrast to animation by layers as used by the gif format for example. (but this crib sheet doesn't cover all that)
+
** [+] Binary format means a small size
 +
** [-] Difficult to postprocess after exporting
 +
** [-] Difficult to debug problems
  
 +
* X (text version)
 +
** [+] Can be parsed easily with lua scripts
 +
** [+] Can be easily generated by scripts
 +
** [+] Easy to debug issues (you can just read it)
 +
** [+] Can be optimized by quantizing some data
 +
** [-] Blender exporter is kinda buggy and inefficient
 +
** [-] Probably still bigger than an equivalent .b3d
 +
 +
''Avoid using the binary X format!'' It's actually just a tokenized version of the ASCII representation,
 +
and may actually be less efficient than a sufficiently optimized text .x file!
 +
 +
=== Coordinate space options ===
 +
 +
Minetest uses a Lefthanded Y-up coordinate space. In a space like this:
 +
* Z axis points "forward"
 +
* Y axis points "up"
 +
* X axis points "right"
 +
 +
Be sure to export all your models in this space to avoid surprises.
 +
 +
=== Exporting animations ===
 +
 +
Animation is currently only supported in the form of playing ranges on a single timeline. Do not attempt to export separate actions, instead use the Nonlinear Animation (NLA) editor to arrange your actions into a single strip for export.
 +
 +
Be aware that placing actions next to one another on an NLA track will "eat" the first frame of each animation, so you might want to place a dummy keyframe at frame 0 in each action and treat frame 1 as the action's start.
 +
 +
Keyframes are always interpolated linearly in the game.
 +
 +
=== Materials and textures ===
 +
 +
Multiple materials are allowed on all mesh formats that we support. You can assign different textures to each material slot in the lua API, both on nodes and on entities.
 +
 +
Use only one UV coordinate set for your models.
 +
 +
=== Optimizing your model for network transfer ===
 +
 +
Text formats like .obj and the text variant of .x may be optimized by removing unnecessary characters and truncating decimal digits. This will make your mod download much faster when hosted on a server or downloaded from the ContentDB.
 +
 +
=== Exporting OBJ files ===
 +
 +
OBJ file support is built into most known versions of Blender, so just use the provided built-in plugin.
 +
 +
There is no need to write the MTL file as Minetest will not parse it.
 +
 +
=== Exporting B3D files ===
  
 
* If you want to be able to export from Blender in B3D (Blitz 3D) format (with 2.70)
 
* If you want to be able to export from Blender in B3D (Blitz 3D) format (with 2.70)
Line 76: Line 92:
 
* Another script is the [https://github.com/joric/io_scene_b3d io_scene_b3d] script by joric for Blender 2.80 that may work with Blender 2.79/2.9 (as of Jan.2021) versions.   
 
* Another script is the [https://github.com/joric/io_scene_b3d io_scene_b3d] script by joric for Blender 2.80 that may work with Blender 2.79/2.9 (as of Jan.2021) versions.   
 
* Yet another version of [https://github.com/GreenXenith/io_scene_b3d io_scene_b3d] is maintained by GreenXenith (as of march 2020)<ref>As mentioned in the forum thread: [https://forum.minetest.net/viewtopic.php?f=47&t=24292 Which tools to export animated models?]</ref>.
 
* Yet another version of [https://github.com/GreenXenith/io_scene_b3d io_scene_b3d] is maintained by GreenXenith (as of march 2020)<ref>As mentioned in the forum thread: [https://forum.minetest.net/viewtopic.php?f=47&t=24292 Which tools to export animated models?]</ref>.
* A python script to export from Blender to DirectX format .x is [https://github.com/minetest/io_scene_x io_scene_x] by hecktest. It is written to work with version 2.8 but this plugin is known to work in Blender versions up to 3.0.0 Alpha as of July 2021. As minetest uses a lefthanded Y-up coordinate space, you may have to adjust some values according to a matrix shown in the readme.md file
+
 
 +
=== Exporting DirectX (.x) files ===
 +
 
 +
==== Blender 2.79 and earlier ====
 +
Versions of Blender before 2.8 already come with an .x exporter capable of producing text .x files.
 +
 
 +
==== Blender 2.8 ====
 +
A version of the exporter updated for 2.8 API changes is hosted here: [https://github.com/minetest/io_scene_x io_scene_x]
 +
 
 +
As of 7/2020 this exporter is known to work with Blender 3.0
 +
 
 +
The README.md file in that repository contains instructions on how to deal with coordinate space and attachment problems.
  
 
== Begin with a basic mob ==
 
== Begin with a basic mob ==

Revision as of 18:42, 22 July 2021

This is a basic crib sheet for creating a mob in Blender. It could be used to create any other mod relatively easily.

File format support

Minetest currently supports the following media formats for 3D content:

Animated, skinned models:

  • B3D files (.b3d)
  • Microsoft DirectX (.x) (binary & text, compression is not supported)

Static meshes:

  • OBJ (.obj)

Textures:

  • .png
  • .jpg
  • .bmp

Any formats not mentioned above but known to work in the past are considered deprecated and may not work in future versions. When in doubt, stick to PNG textures and the model formats listed above.

Do not use .b3d and .x files for static meshes at the moment, Minetest currently spawns animated mesh scene nodes for these, which may result in reduced performance.

Picking a skinned mesh format

You have two skinned mesh formats to choose from, and both have their advantages and disadvantages.

  • B3D
    • [+] Binary format means a small size
    • [-] Difficult to postprocess after exporting
    • [-] Difficult to debug problems
  • X (text version)
    • [+] Can be parsed easily with lua scripts
    • [+] Can be easily generated by scripts
    • [+] Easy to debug issues (you can just read it)
    • [+] Can be optimized by quantizing some data
    • [-] Blender exporter is kinda buggy and inefficient
    • [-] Probably still bigger than an equivalent .b3d

Avoid using the binary X format! It's actually just a tokenized version of the ASCII representation, and may actually be less efficient than a sufficiently optimized text .x file!

Coordinate space options

Minetest uses a Lefthanded Y-up coordinate space. In a space like this:

  • Z axis points "forward"
  • Y axis points "up"
  • X axis points "right"

Be sure to export all your models in this space to avoid surprises.

Exporting animations

Animation is currently only supported in the form of playing ranges on a single timeline. Do not attempt to export separate actions, instead use the Nonlinear Animation (NLA) editor to arrange your actions into a single strip for export.

Be aware that placing actions next to one another on an NLA track will "eat" the first frame of each animation, so you might want to place a dummy keyframe at frame 0 in each action and treat frame 1 as the action's start.

Keyframes are always interpolated linearly in the game.

Materials and textures

Multiple materials are allowed on all mesh formats that we support. You can assign different textures to each material slot in the lua API, both on nodes and on entities.

Use only one UV coordinate set for your models.

Optimizing your model for network transfer

Text formats like .obj and the text variant of .x may be optimized by removing unnecessary characters and truncating decimal digits. This will make your mod download much faster when hosted on a server or downloaded from the ContentDB.

Exporting OBJ files

OBJ file support is built into most known versions of Blender, so just use the provided built-in plugin.

There is no need to write the MTL file as Minetest will not parse it.

Exporting B3D files

  • If you want to be able to export from Blender in B3D (Blitz 3D) format (with 2.70)
  1. Download the Blender export script B3DExport.py
  2. On GNU/Linux: copy to ~/.config/blender/2.71/scripts/addons
    Alternatively, you can skip this step and see step 4 to see a different method*.
  3. Open Blender
  4. In Blender open the menu File/User Preferences/Addons. *From here you can press 'Install Add-on from File', navigate to the .py file, and press 'Install'. Now go to File/User Preferences/Addons/Import Export/B3D (Blitz 3D) Model Exporter.
  5. Tick the box on the left to enable it
    (If you want .x (directX) then find this and enable it too.)
  6. While you're in preferences on the file tab you may want to enable Save&Load/Compress File (for much smaller saved files), and Autosave/Keep Session (to save on exit)
  7. Save User Settings
  8. Close Preferences Window
  • If you want to import, install version 2.49, save as a Blender file, then open with 2.70 to edit.
  • Another script is the io_scene_b3d script by joric for Blender 2.80 that may work with Blender 2.79/2.9 (as of Jan.2021) versions.
  • Yet another version of io_scene_b3d is maintained by GreenXenith (as of march 2020)[1].

Exporting DirectX (.x) files

Blender 2.79 and earlier

Versions of Blender before 2.8 already come with an .x exporter capable of producing text .x files.

Blender 2.8

A version of the exporter updated for 2.8 API changes is hosted here: io_scene_x

As of 7/2020 this exporter is known to work with Blender 3.0

The README.md file in that repository contains instructions on how to deal with coordinate space and attachment problems.

Begin with a basic mob

To create a basic mob, copy an animal from animals_modpack-2.3.6. Then in the init.lua you only have to do a search and replace of the name of the animal, and delete any irrelevant code. You can edit speed, acceleration, etc as you wish.

Create a 3D model

Don't bother with materials – Minetest doesn't handle them – you need a texture to define any colours. If you want your model to walk forwards, you must create it with “forward” pointing in the +ve x direction (i.e. right when you select view point KP 7, or facing in the direction of the red “x” arrow when an object is selected).

Create object

  1. In 3D View
  2. If not already active switch to object mode (dropdown in 3D viewport)
  3. Add objects (eg 3D Menu → Add → Mesh → Cube)
  4. Move around by right-clicking to select and dragging arrows.
    B box/border select. G grab to move.
    Resize or rotate using the properties viewport (has a row of camera, cube, spanner, etc at top)
  5. Select the cube
  6. Use rotation and scale to transform objects
    [See the hundreds of Blender tutorials for more advanced editing techniques.]

Save primary Blender model

  1. Save as a Blender file (Ctrl-S or File → Save)
  2. Save with the name: yourname.blend (or similar)
  3. You might also want to save a separate “unjoined” copy before the following join operation, as you won't be able to access the base components afterward

Texturing

When the basic model is completed, you'll need to create a texture.

  1. Switch to Object mode
    1. Press A (perhaps twice) to select all objects
    2. Ctrl + J to join all objects in a model together
  2. Switch to Edit Mode
    1. Mesh/UV Unwrap/Smart UV Project [see one of the many UV Mapping tutorials if you want seams to match, etc]
      [optional] Set island margin to 0.004 (this leaves a gap between faces, so there will be less risk of bleeding of colour across sharp edges. 0.002 is approx 1 pixel for a 512 pixel image)
  3. Move mouse to the top of the 3D window to get and up/down arrow. Right click/split window and size to 50:50.
    1. On the R hand new window select the litle cube (3D viewport) icon and switch to UV Map viewport
    2. LowMenubar:New
      1. Set name - eg 'yourname UV Map'
      2. Click UV Test Grid (optional)
      3. OK (=Save)
        [if you want to resize the image use a power of 2 (512/1024/etc) for x and y dimensions as it significantly speeds processing]
    3. LowMenubar:Image → Pack as PNG → Accept warning (this ensures you will save a copy of the image within the .blend file (I think in 2.4 this may have to be updated manually, but the tickbox in 2.7 implies is should be saved with the rest of the file)
    4. Check UV map fits on image - adjust with: G - move, R - rotate, S - scale (menu:UV → Transform)
      The UV vertices won't always align to pixel boundaries, which means if you don't use 'island margin' above, then painting on one face may also unavoidable paint onto another face. There is reference in the manual to a UV snap-to-pixel option (to align UV vertices to pixel edges) but I haven't figured how to access it yet (and it would only perfectly stop bleed for horizontal or vertically aligned vertices).
  4. In 3D View window
    1. Switch to Texture Paint (from Edit Mode)
    2. in the Toolbar set:-
      1. Brush
        Select white (should be selected by default)
        Strength 1.0 (ie 100% replacement of the underlying colour)
        Radi 500 (or whatever brush radius you want)
      2. Curve
        select the square profile if you want a solid colour brush
        select the 'normal distribution curve' if you want a fading brush
        (or any other profile you like)
  5. UV Map window
    1. Switch to Paint (from View)
    2. Paint the entire object white (or some other basecoat). This is easiest to do in UV Map window
  6. In 3D View window
    1. To paint only particular faces, click the face Menu/faceselect (the cube with grid pattern on the face), you will then be able to select an entire face/s with R click (or shift R-click for multiple faces).
    2. Change colour, strength, radius, curve… and paint the different parts as you wish – painting in either 3D or UV Mesh windows.
      NB the colour picker has an eyedropper to copy the colour from within the 3D or UV Map windows – just click on the currently displayed colour (under the colour wheel) to bring it up.

Animation

  1. Make sure your mesh is child of Armature.
  2. Make sure there's only one bone parenting all others (having a child bone being parent of another one is no problem).
  3. All faces need to be members of a vertex group.
  4. Make sure all of your vertex groups have same name as at least one bone.
  5. Don't forget to export animation when exporting to .x file.

Save your work and export the files

  1. Save the mesh
    1. Export as a .b3d file (File/Export/B3D)
    2. Save with the name: models/animal_yourname.b3d
    3. Don't forget to look for and OK the overwrite message if needed or it will disappear and you won't have saved your file.
  2. Save the texture
    1. UV Window → Image → Save As Image
    2. Save with the name: textures/animal_yourname_yourname_mesh.png

Create or copy the inventory texture

Find or create a nice graphic to be the image in the inventory.
A flat texture can be created with a 6 sided cube model (eg animal_yourname_yourname.png)
The inventory image is animal_yourname_yourname_item.png
(Remember to respect copyright – use screenshots of your model, perhaps with the help of a “green screen” for transparency, if you want a simple free graphic. To turn off the 3D viewport grid floor open the propertles menu (+ at top R of window), and untick display/grid floor).

Rendering the model

If you want to be able to render the model (F12'), you'll first need to do the following steps to enable the texture:

  1. In 3D edit view. Add → Lamp → Hemi. You might need to move this around to adjust lighting direction, but probably not.
  2. In properties viewpane:-
  3. Select checkered box tab,
    1. Change texture type to Image → Movie,
    2. Click on image dropdown below this and select your UV texture image,
    3. Under mapping dropdown change coord to UV.

Now, rendering should work…

Notes and references

  1. As mentioned in the forum thread: Which tools to export animated models?