contents.gifindex.gif

pueblo00000000.gif Adding Avatar support in VRML spaces

In order to use an avatar, you have to do three things:

pueblo00000005.gif Add the avatar to the scene

pueblo00000005.gif Make it move with the player’s position

pueblo00000005.gif Get rid of the avatar when the player leaves

Adding the Avatar to the scene

What we need to add an avatar to the VRML scene is someplace to add it to the scene, some node that lets us maneuver the avatar, and the avatar geometry. In PuebloMush 2.0, we always use the Separator node AvatarRoot in VRML files that are to support avatars. This gives us a known place to add avatars. We use a Transform called AvatarTransform to maneuver the avatar. For anything but trivial shapes, we use a WWWInline node to point to the geometry URL. We also need to call the avatar something. PuebloMush 2.0 uses the convention that the avatar is named “Avatar<object-id>“. This lets us address the Transform node as Avatar<object-id>.AvatarTransform when we need to change its fields later.

So here are the pieces. The scene .wrl file contains this node somewhere in it:

DEF AvatarRoot Separator { }

This node should be in the same frame of reference as the camera to keep things simple. Putting it right after the PerspectiveCamera node, or after the Cameras Switch node is a good place.

We’d like to add this VRML as a child of AvatarRoot:

DEF Avatar3792 Separator {

DEF AvatarTransform Transform { }

Rotation { rotation 0 1 0 3.14159265 }

WWWInline { name
http://www.chaco.com/~pueblomush/vrml/avatars/m1red.wrl.gz }

Translation { translation .25 0 0 }

FontStyle { size .5 }

AsciiText { string Ralph }

}

This gets the geometry from a .wrl file, and adds a label by the feet. Of course, you’ll probably want to generate a better name than “Ralph”!

To add the new avatar to the scene, we add the VRML node “Avatar3792” like this:

<img xch_graph="event AvatarRoot SFNode add_children" xch_graph_vrml="DEF Avatar3792 Separator { DEF AvatarTransform Transform { } Rotation { rotation 0 1 0 3.14159265 } WWWInline { name http://www.chaco.com/~pueblomush/vrml/avatars/m1red.wrl.gz } Translation { translation .25 0 0 } FontStyle { size .5 } AsciiText { string Ralph } }">

There's a lot of stuff in there you don't need, but that's what PuebloMUSH sends when you walk into the Avatar demo room.

Moving the Avatar with the player’s position

The spinning monolith example (from the PuebloMush demos area) is a good example for discussing movement.

In the monolith VRML file, you have this Rotation node:

DEF Monolith_rotation Rotation { rotation 0 1 0 0 }

When you want to modify it to change the rotation of the objects below that Rotation node, you send HTML like this:

<img xch_graph="event Monolith_rotation SFRotation set_rotation 0 1 0 3.1415926535">

(See xch_graph for the complete list of things you can set.)

The flip side of this is that for avatars, you want the mud to be notified when the user moves around in the world. Here's how to do that:

<img event=move params="position orientation">

This tells Pueblo to send the PUEBLOMOVE command whenever the user moves. For more info about when & what will be sent, check the help for the event attribute.

Once you’ve sent the <img event=move> command, you’ll be getting PUEBLOMOVE commands from the client. The world server needs to respond to these commands by notifying all of the Pueblo-enhanced clients in the space that a specified avatar has moved.

To set the position & orientation of an avatar (based on another players’ PUEBLOMOVE command), you'd do something like:

<img xch_graph="event Avatar3792.AvatarTransform SFVec3f set_translation 0 0 0"><img xch_graph="event Avatar3792.AvatarTransform SFRotation set_rotation 0 1 0 3.14159265">

The PUEBLOMOVE command we asked for above (with the 'event' tag) will give us back 7 numbers. The first 3 are the position of the "camera" in the scene. The last 4 are the orientation. Those set_translation and set_orientation statements just pull that information out and send it as-is, so that's pretty easy. Also, notice the Avatar3792.AvatarTransform dotted notation. We need to be careful to rotate the right node, since every avatar has a node called “AvatarTransform”.

Note: The avatars in PuebloMUSH, like m1red.wrl.gz above, were done by Tom Woof, an artist outside Chaco, so you'd have to talk with him before using his models in another world. They're about $5 each, though, which is very cool.

You can reach him at siepiau@pacific.net.sg. You might want to check out his web page at http://home.pacific.net.sg/~siepiau/.

Removing the Avatar

When the player leaves the room, you need to get rid of his avatar in everybody else’s world, so send the other players something like:

<img xch_graph="event AvatarRoot MFNode remove_children Avatar3792">

and poof, the avatar vanishes.

Also see

Pueblo VRML extensions

TinyMUSH extensions

Building TinyMUSH sound generators

Building TinyMush VRML Animations

event

xch_graph