Hello Matthew,
In 1998, I have worked for a video game company. My task there was to create
visual effects like the one you mention, "smoke".
I am rather new to the Java3D API (The effects for that company were created
in C++ using the MS Direct3D Immediate Mode API), so I can only tell you the
concepts you need to create such effects, not always the corresponding
Java3D Classes or Methods.
OK, first of all you need DECALs for many visual effects - and you need them
for smoke. A decal is simply a Quad or some other Polygon that is always
perpendicular to the EYE RAY. In other words, a decal is always positioned
in a way that the viewer looks directly on top of it. This is something that
you would certainly not expect from any normal object polygon.
I think the Java3D API contains classes for Decals, but I have not used them
yet. In the worst case you can do it manually by calculating the correct
decal position with some cross multiplications.
A decal is normally texture-mapped. Because it is always perpendicular, you
look always right on the texture. As for your "Smoke", you might want to
create the texture of a single smoke "mini-cloud". (I dont know the correct
word for this in english). I have included such a cloud which I have just
created for you with Photoshop. (You should definitively have and know how
to use Photoshop (Windows) or the Gimp (Linux) when you are into any kind of
graphics programming).
The tricky part is that the Cloud bitmap you create has to be transparent.
The problem is that the current Java specification can only read JPG and GIF
images, but without transparency. The new Java 1.3 API includes a PNG image
reader - PNG is a very well-designed and versatile format, which also
supports transparency (alpha channels). But with getImage() you cannot
specify whether the alpha values are premultiplied or not - and Photoshop
always writes premultiplied alpha, while Java seems to expect
non-premultipled data.
The whole transparency thing is very tricky, if you need help here I can
send you a class I have written which reads TGA images along with some
instructions how to save an image correspondingly in Photoshop so that
transparency is preserved.
Assumed you have managed to create and read in the transparent image and now
have a "java.awt.Image" or a "java.awt.BufferedImage". You can now pass this
object to a TextureLoader to obtain a Texture object which you can then
attach to an Appearance. Next, make sure that the Appearance is equipped for
alpha values:
appearance.setTransparencyAttributes(new
TransparencyAttributes(TransparencyAttributes.BLENDED,1.f));
OK now render the decal. If all went OK you now have a transparent image of
a single small smoke cloud which is on a decal, so that the viewer always
looks right onto the texture.
But you certainly do not want one single cloud, you want to have a hundred
for your smoke to look good.
So all what is left to do is to create kind of a "particle system". A
particle system is simply a collection of geometry objects (in this case, a
collection of decals) with a rule that specifies movement for each of the
objects during time. The particle system's task is to move all contained
objects each frame according to the rule.
Also, a particle can "die" (a smoke particle, for example, would die when it
is so high that it has completely dimmed away.) Whenever a particle dies,
you create a new particle in the particle systems, so that the total number
of particles always stays the same. (You may want to "recycle" a dead
particle object to prevent calling 'new' over and over again.)
As for the smoke problem, you might want to choose a rule that moves the
individual clouds up (that is, along the Y axis - because smoke rises to the
sky) and then add some smooth random motion along the X and the Z axis which
is scaled by a factor that depends on the height. In other words, the clouds
should stay near their origin when they begin to rise up, but the higher
they get, the more should they spread in the X and Z direction.
You wrote:
>> In other words it is thicker near the origin and fades as it gets
farther.
Now, this is simple: just decrease the transparency value while the clouds
rise up. The transparency value is the second value passed to the
TransparencyAttributes constructor. In the above example, it is set to 1.
You just have to decrease this value while the smoke rises. Then it looks
like the smoke would "dissolve" when it has reached a certain height.
My experience during the game project was that the hardest part of creating
good visual effects is not the basic coding, but instead finding the
formulas for motion and transparency etc. that make the effect look
REALISTIC. I wish you good luck.
Things you can also try: make polygons larger while become more transparent.
create 3 or 4 bitmaps with different small cloud fragments and randomly
choose one whenever a new particle is born.
BTW, you should take a look at the following sites and the sites that they
refer to:
http://www.red.com/cwr/boids.html
-- A VERY good site for everyone interested in visual effects. Craig
Reynolds, the owner of the site, is the pioneer in Procedural Animation and
has worked on a number of well-know movies, such as "TRON", "Batman Returns"
and other. Take a look at his resume, this is a cool guy. The sites he
refers to are also very interesting.
http://www.game-developer.com
-- They have a library which contains some useful source codes and
tutorials, with free access.
http://www.gamasutra.com
-- A professional game developer site. You have to become member, but I
think when you do you get access to lots of stuff like the one you are
interested in.
Hope this is of help to you, if you have any question left feel free to ask.
I'm glad that I can contribute a little to this list.
-- Julian
-----Ursprüngliche Nachricht-----
Von: Discussion list for Java 3D API
[mailto:[EMAIL PROTECTED]]Im Auftrag von Matthew Flagg
Gesendet: Mittwoch, 2. Februar 2000 16:33
An: [EMAIL PROTECTED]
Betreff: [JAVA3D] Smoke
Hey everyone,
Does any one have any idea how to make smoke? I want to animate
things like a fire or vehicle exhaust. I thought maybe some kind of
derivative of fog but it would have to work in reverse. In other words it
thicker near the origin and fades as it gets farther. I don't think fog
would really work but that is the best I could come up with at the moment.
Any ideas? Thanks.
Matthew Flagg
Java Programmer
Enterprise Computer Systems, Inc.
Greenville, SC
[EMAIL PROTECTED]
===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff JAVA3D-INTEREST". For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".
smoke-cloud.zip