GameSpawn Site Map
Advertisement
GameSpawn Update mailing list
Advertisement
Lee's Lessons

Basic Appearance

2000-05-19

Today I'm going to talk some about Appearances. We've already talked about Geometries and put up some sample code. You might have noticed from the code on 5-15-2000 that there were geometries that had reflective properties, textures, etc. All the aspects of a 3d object other than its shape are pretty much considered its appearance. Java has an Appearance object that encapsulates most of this for you. Today, I'm going to deal with texture mapping. This is a pretty involved subject so all I'm going to do is start off with a quick sample of a texture mapped cube. This is the same one you saw in the first day's code but without all the other junk. The scene will still have directional lighting but very little else. It will not have any event handling or Behaviors built into it becuase that would clutter the code and make it harder to read.

By the way. All the code can be javadoc-ed. Most of the code I write I try to include inline comments to help to understand the code but I try to also include class, field and method documentation for javadoc purposes for better understanding of a class or package.

This demonstrates, yet again, some of the power and ease of Java3D. Here we can see a cube. Nothing fancy as just a cube until you add a texture. The texture mapping is actually handled by the cube itself. It determines how to lay the texutre out across its many faces. This is an extension of the BasicGeometry class except that it uses the Cube geometry, adds an Appearance node and adds the texture, from a file, to that Appearance node. Pretty straight forward stuff.



The source code is here in BasicAppearance.java. Open source as always. It is easy to add your own texture. Just change the paramater to the createAppearance() method call. The parameter is the texture file you with to map to the cube. Setting the texture map coordinates in a geometry is NOT trivial however and we may get into that one day.
Advertisement
Michael C. Lee, Jr.
Advertisement
About
Account
Arcade
Help
Library