Leaves Sprite HOW-TO

Introduction

Several people have asked if I could write a step by step HOW-TO instructions to explain how the Leaves World plants and trees were created. This page describes the procedure that was used in Leaves World. However, there are many other excellent methods to make objects. If you prefer another, cool.... have fun.



Software

I use PaintShopPro, by Jasc Software. I've used PaintShopPro for years, starting with Version 3, and I am currently using PSP-8. It's available in most stores. If memory serves correctly, the example below was created using PSP-6, but I believe earlier versions will work if they support "layers".

Although not necessary, I use a Wacom digitizer pad. This allows use of an electronic pen with a pressure sensitive tip. However, when I'm too lazy clear a space on the desk, I use my standard mouse, so certainly, a digitizer is not necessary.



What is Sprite?

What is a sprite?

A sprite is not truely a 3-dimensional object. Rather, is a 2-D object that may be used in a 3-D environment. It typically consists of a photograph that is rendered onto a single surface rectangular object, and the object is set to automatically rotate around the vertical axis so the picture is always facing toward the viewer. (This is why sprites are also called "facers", because they always "face" toward the viewer.)

Why use 2-D objects when 3-D objects are Possible?

The main reason is computer speed and download speed. When computers get faster and faster, perhaps sprites will become obsolete. However, a sprite is an object that contains only one single surface with one texture image. It is a typically a very small file, it loads quickly and consumes little resources. In Leaves World, we use a large number of sprites in order to allow the visibility to be increased to large distances without slow frame rates.

What about 3-D trees? I think they are some of the most beautiful trees that I've seen. However, the ones that I like have 100's of textured surfaces. When experimenting, a thick forest of 3-D trees brings my computer almost to a crawl. I prefer a compromise. Place a limited number of 3-D trees in key places, then fill the background with sprites. From a distance it is hard to tell them apart.

If you would like to see an example of this, try flying into the air and looking down on a sprite object from above. The following picture shows a typical sprite tree.



Three Steps

There are basically 3 steps to create a sprite

  • 1 - Create the image files from a photograph using PaintShopPro.
  • 2 - Create the object model file (RWX) using windows Notepad.exe.
  • 3 - Test the file using Activeworlds browser.
These will be explained in detail in the following sections.


1.1 Selection of photograph

Probably the most important aspect to making sprites is selection of the photograph. Bottom line: A poor photograph will make a poor object. Consier the following four criteria:

Size - Most of Leaves World sprites are 256 x 256 pixels. It is necessary to choose a photo that is large enough to allow at least 256 x 256 pixels after cropping.

Contrasting background - A contrasting background allows easy creation of the mask.

Lighting - The key to making a sprite look 3-D is to choose photo graphs that have lighting that show some shadow on one side of the object, giving the appearance of 3D.

Focus - Try to avoid using blurry photos. It is difficult to make the mask, and blurry photos tend to look "flat" when rendered in 3-D environment.

For this example, we will take a look at an older object, fflo04.rwx that was made back in July 2000. Below is the 640 x 480 pixel image what was used for this sprite.



1.2 Crop and size the image.

Using PSP, the image is first cropped, then re-sized to 256 x 256. When cropping, cut the edges of the picture as close to the object as possible. You may use other sizes if you like, but I will continue with 256 x 256 in this example. When resizing, I suggest using "Pixel Resize", but other sampling may be used if you prefer.

  • First - Crop
  • Second - Resize 256 x 256
Cropped Image (345 x 337 pixel)




Resized image.



1.3 Save as PaintShopPro PSP type file

Choose File --> SaveAs. In the dialog window, select file type: "Paint Shop Pro Image". It is necessary to SaveAs in this format so the file will support multiple image layers.



What is a Mask?

The concept of mask can be very confusing, because there are two different types of masks. PaintShopPro has a mask capability that is described in the PSP help files. Please ignore the PSP mask. The PSP mask is a tool that is used during editing of drawings inside PSP. Other sprite methods may use this, but our method will not.

The second type of mask, is the Activeworlds image mask file. Condider the anology of making paper doll clothes. Sizzors are used to carefully cut around the pictures of paper doll closes, and these cut out clothes may be placed over the paper doll to dress it.

In the same way, a mask file is used to "cut around" the edges of an image, making them transparent. It is typically a 2-color windows bitmap (.BMP) file that is zipped into a (.ZIP) file and uploaded with the image photograph. Each pixel of the mask image would have only 2 colors, black and white. When a masked object is rendered by the AW browser, it will load both the base photograph and the mask file into memory. Areas of the photograph that correspond to the white color in the mask will be visible, and area of the photograph that correspond to black area of the mask will be transparent (invisible). Here is an example of a mask file.

The first question everyone asks, How in the heck to you create separate independant image and mask files while maintaining the alignment of the object edges? This is not easy, and most people find this fustrating at first.

In Leaves, we use a technique that allows the mask and image to exist inside the same PSP file using a tool known as "layers".



1.4 Create Layers

What is a layer?

A layer is a second photograph image than is super-imposed over the base image. When new layers are created, they are transparent by default. When multiple layers are created, one layer will be selected as the "active layer", and any changes to the image will me made to the active layer, without changes to the base layer.

To view a list of layers, in PSP-8, you can either press F8 key, or else use the menu View--> Palettes--> Layers. In earlier versions of PSP, check the help file on use of layers. You will open a layer dialog that looks like this:



Create two layers. Name the first layer "Solid White", and name the second layer "Black mask". There is an eye icon in the list. The eye icon will turn a layer on/off, so the layer will be visible or invisible. The lower entry in the list will be the bottom layer which I call layer #1 (background). Each higher entry in the list will be "on top" of the lower entries. I refer to the top layer in the list as layer #3 (Black mask).






You have now created 3 layers with the following contents:



1.5 Solid Fill White Layer

The next stop will be to solid fill the middle layer with white color, then turn off the middle layer.

In the layer list, highlight the middle layer, and make sure the eye icon is not checked.

Using the PSP "Solid Fill Tool", select the color pure white (red=255, green=255, blue=255). Click the picture with the solid fill tool, and the layer will be painted solid white.

In the layer list, click the eye icon for the middle layer, and the white fill will disappear, and you should see again see the the base image.

If you have succeeded, you can turn the middle layer on and off, and the image will revert between the photograph and solid white. The layers look like this.



1.6 Create the Mask

First, using the layer list, set the following

Layer 3 Selected as Active Layer (we will draw layer 3).
Layer 3 ON (visible), this is empty now.
Layer 2 OFF (invisible), this is the solid white mask.
Layer 1 ON (visible), this is the base plant image.

The layer list should look like this.

In PSP, the picture should look like this.



1.7 Set brush type

Select the "Paint Brush" tool for drawing. Recommended properties are as follows:

Shape = round
Size = 1
Hardness = 100
Step = 50
Density = 100
Thickness = 100
Rotation = 0
Opacity = 100
Blend Mode = Normal

Set the color to Black (red=0, green=0, blue=0).



1.8 Draw the Mask

While coloring on the top layer, carefully fill in the area round the object.

After draing a small amount, try turning the "Black Mask" layer ON and OFF, to make sure you are drawing on the correct layer.

It will be easier if the zoom is increased.




When completed, the layers have the following contents.




And the PSP screen should look like this.

At this point, we are looking at the object against a black background, but it is possible it could be used against a light background. It is also possible the background of the base image could contain black or almost black, making the mask hard to see. We recommend viewing the mask as both light and dark background. Next, we will test the mask against a light background.

With the Black Mask layer 3 still selected as the active layer,

From the pulldown menu, select: Adjust--> Negative Image.

The black mask will be inverted to it's opposite color (white). The layers will temporarily have the following contents.




And the screen will look like this.




If needed the mask layer may be edited with the white color. When you are satisfied the mask is appropriate for a light background, we need to switch the mask color back to black.

With the Black Mask layer 3 still selected as the active layer,

From the pulldown menu, select: Adjust--> Negative Image.

When completed, the layers have the following contents.




And the PSP screen should look like this.



1.9 Save the PaintShopPro PSP type file

Choose File --> SaveAs. In the dialog window, select file type: "Paint Shop Pro Image". It is necessary to SaveAs in this format so the file will support multiple image layers. Here is the example file fflo04.psp (I believe this is PSP-6). In my copy of PSP-8 it will save as fflo04.pspimage



1.10 Create the Image (JPG) file

Select Layers as follows:

Layer 3 ON (Black Mask)
Layer 2 OFF (Solid WHite)
Layer 1 ON (Base Image).


And the PSP screen should look like this.



From the pulldown menu, select File --> Save-Copy-As. (Do Not use save-as)

Choose the image type: JPEG Compliant (.JPG).

Name the image fflo04.jpg (sample copy)

You will get a warning that "Save Copy As" will convert the image to a single layer in order to create a JPG file, which is a single layer file type. This is normal.

Small note: If you use texture MIP map enabled in your world, you might get some of the black bleed through the edges of the image. In our world, we recommend Options--> Settings--> Performance use texture MIP maps disabled. We prefer the black background, because it makes the JPG file smaller in file size in bytes.



1.11 Create the mask image and zip files

Select Layers as follows:

Layer 3 ON (Black Mask)
Layer 2 ON (Solid White)
Layer 1 OFF (Base Image).


And the PSP screen should look like this.

Limiting the file to a 2 color format will create a very small file, which when zipped in the following example will create a 8.4k bitmap mask which will be only 295 byte zip file.

From the pulldown menu, select Layer--> Merge--> Merge All (Flatten).

From the pulldown menu, select Image --> Decrease Color Depth--> 2 Color (1 bit).

From the pulldown menu, select File --> Save-Copy-As. (Do Not use save-as)

Choose the image type: Windows or OS2 Bitmap (.BMP)

Name the image fflo04m.bmp (sample copy)

Do not save the base file!. The layers have been removed. Close the document window, but DO NOT SAVE.

Using a windows file zip utility, zip the file fflo04m.bmp into the zip file fflo04m.zip (sample file).



1.12 Image summary.

You have now created two picture files, fflo04.jpg (photo image) and fflo04m.zip (zipped bitmap mask file.) We hare half done. This pair of files contains only the texture (photo) data. The physical geometry of the object must be created next. We will return to these files shortly.



2.0 Create the Model RWX file

The next step in the process is to create the model files. If you are experienced in creating RWX files, you may skip this section. This will be a very simplified explanation of how to substitue limited data into a pre-existing sprite template. RWX modeling is beyond the scope of this HOWTO.

2.1 What is an RWX file?

What is a RWX model file?

A model file is a zipped text file that contains renderware code to create the geometry of the object model. This file contains the coordinates of points called vertices. Surfaces are created by connecting groups of vertices into triangles, rectangles and polygons. The file can specify texture photo images to be mapped onto these surfaces.

Do I need to know RWX code to create sprites?

No, sprite files very simple and may be created by editing templates.

Do I need special modeling programs to create sprites?

No, the windows Notepad.exe is sufficient to create sprites.



2.2 Editing the RWX template.

The easiest way to make a sprite is to copy an existing sprite .RWX file. You may use the following example or else, download any sample sprite. The Alphaworld object path has many examples. If the files is compressed (filename end in .ZIP), decompress with zinzip, multizip, or other utilities. Windows XP can unzip by right clicking the filename in explorer.

The following is a rwx file for the Leaves version of fflo04.rwx.

Only 3 items are require manditory editing.

1 - Edit the object width of the object. You will see the number .075 appears 4 times, highlighted in blue, and two are negative numbers. This represents 0.075 dekameters, or 75 centimeters. Since the left and right sides of the object are equal space on either side of the object's center, the total width of our fflo04 object is 75cm + 75cm = 150cm. For example, if you wanted to shrink the object to 80cm wide, you would substitute .04 and -.04.

The leading "0" and the trailing "0" may be added if you like "0.040" is the same as ".04", but the shortest version is historically used to maximize the number of object that will fit into one data cell.

2 - Edit the object height. Unlike the width, we desire to have the origin of the object at the bottom of the object, thus by default, the height of the bottom of the sprite is zero, and this is rarely changed for sprites. Therefore, unlike the width, which requires a 4 number edit, the height only requires 2 numbers to be edited. Highlighted in yellow, the value .15 appears two times. This represents 0.15 dekameters or 150 centimeters. You may substitue other heights.

When entering height and width, all 4 numbers for the width should be the same (two are negative), and both numbers for the height should be the same. The other numbers should remain the unchanged, so do not edit them.

3 - The last step in editing the RWX file is to substitue two filenames for the texture and mask. The filename extensions are omitted, so you see it is important that the image and mask are different names. We append "m" on the bitmap mask file to designate it as a mask.

The file should no look like this, you may cut/paste from here.


TextureMipmapState off
ModelBegin
  ClumpBegin
    AxisAlignment ZOrientY
    #! Collision off
    Vertex -.075 0 0 UV 0 1
    Vertex .075 0 0 UV 1 1
    Vertex .075 .15 0 UV 1 0
    Vertex -.075 .15 0 UV 0 0
    TextureModes NULL
    #! textureaddressmode clamp
    Texture fflo04 Mask fflo04m
    Quad 1 2 3 4
  ClumpEnd
ModelEnd

Experienced users may notice a couple extra lines. You may remove them if you like.

We force the browser to deactivate MIP map when rendering the sprite.

     TextureMipmapState off

The following command causes the object to rotate, always facing the viewer. However, if this line is removed, the object will not rotate, but it will only have one side.

     AxisAlignment ZOrientY

By default, we make trees and plants "Solid Off".

     #! Collision off

This command will elimnate strange edge effects where lines may appear at the top of the transparent edges of a sprite.

     #! textureaddressmode clamp


2.3 Saving and compressing the RWX file.

When you are done substituting the data into the RWX template, save the file using the extension ".rwx". Be careful that you are not creating a file called fflo04.rwx.txt. You might want to un-check "Hide file extensions for known file types" in the window explorer so you can see the full filenames. If .TXT was appended by mistake, you may rename it using windows explorer. In our example we used the name fflo04.rwx (sample file).

The next step will be to zip the file using a zip utility like winzip or multizip. Our example when zipped is named fflo04.zip. (do not confuse this with the zipped bitmap mask files that we previously named fflo04m.zip).



2.4 Object Model summary

We have now created a total of 3 files ready for testing.
When done testing, these 3 will be uploaded to the server.

fflo04.jpg (texture photo image in JPEG format)
fflo04m.zip (mask file in widows 2 color BitMap format, compressed to zip file.
fflo04.zip (object RWX model file, compressed to zip file.

The following files are temporary, and will not be uploaded. However most people save these files so they can edit the objects in the future. When we are done testing, you may save or delete at your preference.

fflo04.psp (Paintshop file file with layer formats, may be .pspimage extension).
fflo04m.bmp (mask file before zip compression)
fflo04.rwx (object RWX model before compression)



3.0 Testing the new sprite object.

Sorry, under construction

In the future, I would like to add a full explanation of sprite testing using the AW browser local path capabilities. This will allow testing the files before they are uploaded. Until then here are a couple of simple steps.



3.1 Setting objectrefresh

The main issue most people encounter when testing objects is refresh of the browser file cache. The first time a new object is loaded, your browser will download the model, texture and mask files and store copies of these files on your local hard drive in the Activeworlds browser cache. With each future visit, no download will be required, because the objects are already cached on the local hard drive.

If you decide to edit a new sprite object, perhaps the size is too small, you can upload the new files to your object path web server. However, when you view the newly edited object, unfortunately you will still see the previous version, because you are viewing your "cached" copy, not the new one.

One possible solution is deletion of all or part of the local cache files, however, this will result in excessive downloads of the files. Most users would discourage this option for other than minor texture edits where individual texture files can be eliminated from the cache.

The recommended solution is to temporarily change the world settings for "objectrefresh" to zero. The default value for objectrefresh is 10080. This is the number of minutes in one week. At the default setting of 10080, your browser will check for updated object path files one time per week. It will query the object path web server and check the file date/time compared with files in the browser cache. If the dates are newer, the newer files will be downloaded, else the existing cache files will remain without download. When this occurs, it will look like a regular download, counting the objects in the status bar, but the upload will proceed very quickly, becaues most object will not require download.

When the objectrefresh setting is set to zero, each time the world is entered, all of the files visible to the user in the world will be checked for availability of newer versions on the object path server. With this, you simply need to bounce to another world, then return, and your browser will load and display any editied objects that you have uploaded to your object path.

To avoid excessive downloading on your server, it is strongly recommended that object refresh be restored to 10080 when editing is completed. Many people have a spare world license they use for object testing. A P5 or P10 will work excellently. You may use an empty world to test the objects, and the object download is therefore very small.

Additionally, a local path may be setup. For now, refer to help files for use of the local path. This will allow files to be viewed and edited locally without upload to the object path.

It is also suggested to check "Print object errors" as shown below.



3.2 Testing the new sprite object.

To test a sprite, perform the following

1 - Upload the zipped model file to the object path models folder. In our example, the file is named fflo04.zip. This file contains the compressed RWX file.

2 - Upload the texture file to the object path textures folder. This file contains the JPEG graphic file. JPG files are already compressed internally, so they are not zipped. In our example, this file is fflo04.jpg

3 - Upload the zipped mask file to the object path texturs folder. This file contains the 2 color windows bitmap format file that is compressed into a zip file. In our example, it is named fflo04m.zip

Next, you may enter the world, and create the object for viewing. Watch the browser text window for printed object errors.


Here is the object being testing in an empty world.

Here is the object in use.