The User File

In Ygdrasil, the user nodes which define the avatar are often kept in a different file from the rest of the scene. This is called a "User File", and is saved in the yg/users directory. You don't have to do this - it is perfectly ok to define the avatar as part of your main scene file. However, there are a couple of good reasons to use an independent file:

  1. You can easily re-use an avatar in multiple scenes without having to copy and paste it
  2. It keeps your main scene file tidier
  3. For multi-user environments, it's necessary so that individual users can load the same scene but with different avatars
A user file can then be used in several different ways - you can put a reference to the file into your main scene file, or you can load it from the RUN script while loading the main scene. The latter method is what you would use for creating multiuser networked scenes.

The user file can be loaded by the main scene file using the #include command. This is like a macro - it loads a file, and essentially pastes it into the other file while it's loading. (In Ygdrasil 0.4 and higher, there is a specific node to do this, which is often better than using #include). The user file is essentially a fragment of a YG scene file - it uses exactly the same syntax as a regular YG scene file, it contains YG nodes, etc. Using #include allows you to also load any YG scene file into the middle of another one; it's often used to manage large worlds, by dividing the world up into smaller individual files and then using #include from one master file to load all the smaller ones.

Creating and Using a User File

The user file is necessary for another reason - without it, you can't move in YG! The following scene has a terrain and sky - it will load, but you would be unable to move.

// valley.scene
light ()
environment (skyColor(.3 .5 1.0))
object (file("valley.pfb"))
In simulator mode, you can move around a little bit using the arrow keys. Remember that that's not moving in the virtual environment - it simulates physically walking around within the confines of the cube of the CAVE!

First we'll create a user file, and then add it into the valley scene. Here's the two files:
user User0 () { caveNavigator navigatorUser0 () caveHead headUser0 () caveTracker wandTrackerUser0 (sensor(1)) { caveWand wandUser0 () { } } }

// valley.scene
#include "User0.scene"
light ()
environment (skyColor(.3 .5 1.0))
object (file("valley.pfb"))
save User0.scene in yg/users, and valley.scene in yg/scenes.
(c) Ben Chang