Rez a prim

From libopenmetaverse - libomv - Developer Wiki

Jump to: navigation, search



  • This tutorial assumes that you were able to successfully build LibOpenMetaverse! If you have not compiled libomv, please follow the instructions on the Getting Started wikipage.
  • Also, if you have no experience with the C# (c-sharp) programming language, I highly recommend that you stop now and please follow the list of links to csharp tutorials located here.
  • A copy of the libomv source code; you can get this by exporting the trunk from SVN or downloading the binaries from the Download page

Rezing Prims

There are two basic ways to rez primitives, either by creating a new object from data, or rezzing from Inventory. For creating new prims or foliage the methods are in ObjectManager, to rez from Inventory the functions are in InventoryManager

Rez a prim at a position and rotation relative to your Avatar

The following example will rez a new prim 5 meters infront of your Avatar no matter what rotation and position it is in

// specify the distance from your avatar, a negative number would be behind your agent
float rezDist = 5.0f;
Vector3 scale = new Vector3(0.5f, 0.5f, 0.5f);
// the X, Y, Z distance used to caluclate the position. 
Vector3 distance = new Vector3(rezDist, 0f, 0f);
// calculate the position based on your avatars current position and rotation
Vector3 rezPos = Client.Self.RelativePosition + distance * Client.Self.RelativeRotation;
// create a box prim
Primitive.ConstructionData prim = ObjectManager.BuildBasicShape(PrimType.Box);
// rez the prim
Client.Objects.AddPrim(Client.Network.CurrentSim, prim, UUID.Zero, rezPos, scale, Client.Self.RelativeRotation);

Rez Foliage

Vector3 scale = new Vector3(1f, 1f, 1f);
Vector3 position = new Vector3(128f, 128f, 30f);
// rez a tree
Client.Objects.AddTree(Client.Network.CurrentSim, scale, Quaternion.Identity, position, Tree.Eucalyptus, UUID.Zero, true);
// or rez grass
Client.Objects.AddGrass(Client.Network.CurrentSim, scale, Quaternion.Identity, position, Grass.Grass0, UUID.Zero);


Parameter Meaning
Client.Network.CurrentSim Specifies the default simulator your Avatar is connected to, this could be any valid simulator your agent is currently connected to
scale Specify the size of the tree, valid numbers are from <0.1f, 0.1f, 0.1f> through <1.0f, 1.0f, 1.0f>, smaller numbers specify a smaller object
Quaternion.Identity Specify the rotation of the object. Quaternion.Identity is the default rotation and specifies the object will face East
position This is a Vector3 that represents the X, Y, and Z position of the object
Tree.Eucalyptus/Grass.Grass0 Specifies the foliage species, see the following table for valid values, notice AddTree uses the Tree column whereas AddGrass uses the Grass column
UUID.Zero This is the Unique ID to specify which Group the tree is set
true Specifies to use the new foliage types (this should be set to true in 100% of the cases

Foliage Types

Tree Species Grass Species
Pine1 Grass0
Oak Grass1
TropicalBush1 Grass2
Palm1 Grass3
Dogwood Grass4
TropicalBush2 Undergrowth1