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:
- You can easily re-use an avatar in multiple scenes without having to copy and paste it
- It keeps your main scene file tidier
- For multi-user environments, it's necessary so that individual users can load the same scene but with different avatars
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"))
First we'll create a user file, and then add it into the valley scene. Here's the two files:
// valley.scene
#include "User0.scene"
light ()
environment (skyColor(.3 .5 1.0))
object (file("valley.pfb"))
(c) Ben Chang