|
Tutorial
Index
Painting Vegetation In Freeworld3D
In this tutorial
you will learn how to create vegetation layers with the new
Vegetation System
in Freeworld3D v2.5. The following are the topics
covered in this tutorial.
Introduction
Freeworld3D v2.5
will support an easy to use vegetation system. Laying
vegetation down on the terrain works the same as painting a
terrain layer.
There are two
types of vegetation: Billboards and Custom Mesh. The
Billboards type renders camera aligned quads that represent
each piece of vegetation. The Custom Mesh type allows
the user to create their own vegetation mesh using a 3rd
party tool, such as 3dsmax, Maya or Milkshape, and then
import it into Freeworld3D to use as vegetation.
Billboards
The Billboard
vegetation type requires a texture to be specified for each
billboard quad. Freeworld3D also allows the user to
pack in multiple textures into a single image. For
instance, if the user wishes to have 4 different types of
grass, each grass texture should be packed into a larger
image horizontally across. Then when painting
the vegetation there is an option that allows the user to
choose which texture cell to use when painting the
vegetation.
Custom Mesh
The Custom Mesh
format requires the loading of one of the supported model
file formats. NOTE: The loaded model must
contain only a single submesh and a single texture!
This is very important, as any other type of model will not
work. This is for optimization purposes so that
hundreds or thousands of pieces of vegetation may be
rendered in the most optimal manner.
Creating
a vegetation layer
- Create a custom terrain

-
Navigate to
the Vegetation tab in the Control Panel.
- Click New.
Check the Billboards check box.
- Choose a texture. Then
click Ok.
- You will have a vegetation layer
item in the listbox as shown below.

- Highlight the vegetation layer
and change the Width and Height values to
0.4.
- Set the Tool combobox to
Paint. Set the Density to 5.
Set the Radius appropriately.
- Start painting.

Packing textures
into a single image.
- After inserting all vegetation
textures into a single image, create a new vegetation
layer as above and load the texture.
- Highlight the vegetation layer
and change its Cell Count property to the number
of Texture Cells within the texture image.
- When painting set the Texture
Cell Index text box to the index of the texture cell
you wish to use while painting, starting with 0.
- Check the Random Cell
checkbox to have the texture cell index be randomized
during painting.
Reading
exported vegetation data
After using the Custom Export
feature to export your Freeworld3D project, each Vegetation
Layer will have its own binary data file. Each data
file contains the positions of each piece of vegetation
within the layer.
The general layout of the file is as
follows:
map width - 32bit float
map height - 32bit float
density - 32bit integer
x y z - 3 32bit floats
...
...
... continues from i
= 0 to i = density |
This file is in binary to save space due
to the large amount of data that will be present.
Below is C++ code to aid in reading the file and to give a
better understanding of the format.
FILE *fp = fopen(filename, "rb");
if(!fp) Message("Error opening file");
// mapWidth and mapHeight
will be the same value as the size of the
terrain
int mapWidth, int mapHeight;
fread(&mapWidth, sizeof(int), 1, fp);
fread(&mapHeight, sizeof(int), 1, fp);
// the rest of the file
contains a 2-dimensional map containing cells of
positions
// the number of x,y,z values in each cell is
determined by the density value
for(int y = 0; y < mapHeight;
y++)
{
for(int x = 0; x < mapWidth; x++)
{
int density;
fread(&density, sizeof(int), 1, fp);
for(int d = 0; d < density; d++)
{
float position[3];
fread(&position[0], sizeof(float), 3, fp);
// store position array somewhere
}
}
} |
|