Skip to content

Exporting from Blender

tobspr edited this page Jul 17, 2014 · 28 revisions

This article is divided into two sections. The first section covers how to create your materials properly for the pipeline. The second section describes how to export them to Panda3D.

Preparing your materials

This pipeline uses Physically Based Shading. In order to create your materials properly in Blender, there are a few important things:

First, every material has 4 or 5 textures, in the following order (explanation below, keep reading!):

  1. Diffuse
  2. Normal
  3. Specular
  4. Roughness
  5. Displace (Optional)

It is important that you don't skip any of the slots, as the indices change then! If you have a material which does not require a normal texture for example, setup an empty texture for it. There are empty textures included in the pipeline at Data/Textures/EmptyXXXTexture.png. It could look like this then:

Material with no real assigned textures

You should use the empty textures provided by the pipeline, as they contain some fixed (necessary) values. Remember to use UV-Mapped coordinates for all textures, otherwise yabee can not export them properly.

All textures sizes should be a power-of two. I recommend a size of 1024x1024 or less, but for highly detailed materials you can use higher resolutions. Notice that not all textures have to have the same size. You can for example use a 512x512 for the diffuse, but a 2048x2048 texture for the specular to increase detail.

Your diffuse texture should be 8bit RGBA, storing the alpha mask in the alpha channel. If your texture is RGB only, no alpha mask will be used. A sample diffuse texture could look like this:

Sample diffuse texture

Your normal texture should be 8bit RGB, and store values from 0 to 1. It is important that you don't use the normal texture to modify the intensity of the bump mapping, but instead the bump-map-strength parameter (see below), and store the full intensity in the normal map. The values in the normal map should be normalized from -1 .. 1 to 0 .. 1 (most exporters like crazyBump, shaderMap already do that). Again, a sample normal texture:

Sample normal texture

The specular texture should be 8bit RGB, although only the R channel is used. When packing the pipeline (todo: link to manual page), it will be merged with the other textures. The values should range from 0 .. 1, again, don't use this texture to adjust the specular intensity! Modify the specular-factor instead (see below). Sample specular texture:

Sample specular texture

The roughness texture will be empty the most time, but you can use it to add scratches or rust to the surface. The same rules as for the specular texture apply.

Now, that you have setup the textures, you want to adjust the material scalars. There are multiple of them, each should be tweaked carefully:

Base Color

The base color is also known as diffuse or albedo. When the material is not metallic, this is the diffuse color. When the material is metallic, this represents the specular color. Your diffuse texture will get multiplied with that. The diffuse texture is stored in the Diffuse section of the material properties:

Diffuse modifier

Specular Factor

This factor controls the specular intensity. Your specular texture get's multiplied with this factor to determine the final specular factor. The specular factor is stored in the R component of the Specular Color in Blender:

Specular factor

You have to set specular intensity to 1.0 in order to get proper results! Otherwise all your factors will get multiplied by the specular intensity, what do you don't want! This also applies for all other scalars which are stored in the specular component.

Specular intensity

Metallic

This determines wheter your material is metallic or not. It should be either 0.0 or 1.0, but very rarely something between. It is stored in the G component of the specular.

Roughness

This stores how rough your material is. (Todo: Link wiki page to scalars). It should be between 0 and 1, but mostly will be something inbetween, like 0.2. It is stored in the B component of the specular. Again, your roughness texture gets multiplied with this to compute the final roughness value.

Bump-Map Strength

This scalar gets multiplied with your normal map. It controls the intensity of the normal map, and should be stored in the alpha component. To make the alpha component available, first enable transparency:

enabling transparency

Then, set the transparency mode to mask and store the bump map strength in the alpha field:

setting alpha

(Todo: Add information about the displacement texture.)

Notice: Your objects might now look strange in blender. This is okay, as we misused blenders material properties to store our own properties. If you followed this guide correctly, they should look okay in the pipeline.

Exporting your models

Now, as you have setup your materials and textures, you already mastered the biggest part of work. To export the geometry to Panda3D, you should use YABEE. When you have installed it into blender, just select all models you want to export and select File>Export>Panda3D (.egg):

Exporting from blender

(Shortcut: Press space and type 'egg', then press arrow-down)

This will now open a dialog, asking to save your egg file. You should use the following settings for export:

YABEE Export options

When you hit "Export to Panda3D EGG", it should generate an .egg file at the specified location. When you have many vertices, this could take a while (I once waited a hour to export a model with 2kk vertices).

Now, as you have your .egg file, I highly recommend converting it to a .bam file. This will make loading much faster. You can convert it with the following command:

egg2bam -noabs -o myModel.bam myModel.egg

Whereas myModel.egg is the path to your model, and myModel.bam is the path where the converted file will be saved.

When it finished converting, you can simply load the model in the pipeline with loader.loadModel("PathToMyModel"). I recommend calling flattenLight() on the model then, as that gives a small performance improvement. Finally, you have to apply the material shader to your object:

model.setShader(renderPipeline.getDefaultObjectShader(useTesselation))

The method getDefaultObject shader returns the default shader for all normal scene objects. If you want to have your object tesselated (then you need a displacement map), set useTesselation to True. (Notice: Experimental!). Otherwise set it to False.

Now, if you did everything correct, you should see your model in the pipeline.