Site Archive (Complete)
AI / Robotics Blog: How to make Coffee in SL
AI
A MILLION MONKEYS

A Blog about AI, UI and HI

by John Jainschigg
Second Life ... Third Shift

... So I said to the giant cockroach ... Stop me if you've heard this ...

by John Zhaoying
February 20, 2007

How to make Coffee in SL

The Dr. Dobb's/InformationWeek coffee hours (Tuesdays at 7 AM SLT, Fridays at 12 PM SLT). have been running for several months now, and are becoming popular get-togethers for some of SL's kickiest devs, builders and entrepreneurs.

Today's coffee-hour was pretty diverting -- the topic was "How do you make money in Second Life?" And it was significantly enhanced by our service of Dr. Dobb's Java(tm) -- viewed (by us, anyway) as one of Second Life's most finely-wrought coffee-simulations.

Doesn't look like much, does it? But even simple objects in SL can hide significant complexity.

Let's start with the physical object itself. Four primitives: the cup shape (a stretched, hollowed half-sphere with the Dr. Dobb's Portal texture applied to the side), the handle-shape (stretched torus), and the black pool of coffee (black disk). These are linked to form the completed object -- the cup-shape is the so-called 'root prim,' and the rest are 'child prims.'

The 'steam' (which is animated, rises into the air, trails behind you if you walk around while carrying the cup, and fades out neatly in a second or two) is emitted by code residing in the black 'coffee' disk. This code parameterizes and calls the SL 'particle system' -- a software subsystem that runs on the SL client (so produces effects that are not part of the shared scenario represented on the SL server). The particle system is a very powerful tool for creating a wide range of effects -- fire, smoke, explosions, temporary phantom constructs, etc. Once triggered, the particle system will continue emitting from the object particles of appropriate parameters, which include alpha transparency, size and dimensions, gravity and negative-gravity effects, response to 'sim wind,' etc. Particles are typically given a lifespan, so survive only a fixed amount of time following emission. In this case, we create a gradual emission of 'puff of steam-sized' particles, white and highly transparent, which rise from the emitting disk and quickly disappear. The code embedded in the coffee disk is set up to execute independently, when triggered by the object's being 'rezzed' (instantiated) in-world.

So now we have a coffee-cup that emits steam. How do we drink from it? That's an animation, triggered by code that runs in the 'cup' object, and imposed on the avatar holding the cup (in fact, wearing the cup as an attachment on its right hand). The animation is retriggered about every 15 seconds, on a timer interrupt, so the avatar appears to hold the cup steady, then periodically tosses back a gulp. We appropriated this animation (from where, I don't recall) -- judging from its title, which is something like 'Hand Rt Handgun,' it was itself developed as an extension of a handgun-pointing pose.

But there's still a rub. In Second Life, when your avatar chats with other avs, it makes a "typing" gesture. And this typing animation runs at a very high priority. Which means that the 'holding the cup steady and level' animation gets overridden -- result: whenever you chat, it looks like you're pouring coffee in your own lap.

The fix is to make the cup vanish while you're typing, then reappear when you finish. This is sponsored by additional code in the 'cup' that polls the holding avatar's state, figures out when it's typing, and issues an llSetAlpha command to turn all prims in the set invisible.

This works for all the prims -- but not the particles, which keep emitting from the (now invisible) black disk. So an extra step in the cup code sends a message to the disk, which hears it on an inter-prim messaging interrupt and turns the particle-emitter off. The process is reversed when the cup senses that typing is no longer occurring.

Typical Second Life: Where a simple cup of coffee becomes an exercise in building, animation, client-side particle emission and inter-object messaging. Is it any wonder I love this place?

Posted by John Jainschigg at 05:36 PM  Permalink



This is a public forum. CMP Media and its affiliates are not responsible for and do not control what is posted herein. CMP Media makes no warranties or guarantees concerning any advice dispensed by its staff members or readers.

Community standards in this comment area do not permit hate language, excessive profanity, or other patently offensive language. Please be aware that all information posted to this comment area becomes the property of CMP Media LLC and may be edited and republished in print or electronic format as outlined in CMP Media's Terms of Service.

Important Note: This comment area is NOT intended for commercial messages or solicitations of business.


 
INFO-LINK


Related Sites: DotNetJunkies, SD Expo, SqlJunkies