2

Rezing "clusters" (objects) in a scene

In recent days Linden Lab released the capability to rez objects in a scene. Here is a sample script that demonstrates it. Drop it in an object and be sure to select some object from inventory for its only setting.

 

using System;
using Sansar;
using Sansar.Script;
using Sansar.Simulation;

public class TestScript : SceneObjectScript {


public ClusterResource SelectObjectToRez;

private Cluster RezedCluster;


public override void Init() {

ScenePrivate.CreateCluster(
SelectObjectToRez,
new Vector(0, 2, 2),
Quaternion.FromEulerAngles(new Vector(0, 0, 0)),
new Vector(0, 0, 0),
CreateClusterHandler
);

}


private void CreateClusterHandler(
bool Success, string Message, Cluster ClusterReference
) {
  try {
// Keep a reference to the new cluster
RezedCluster = ClusterReference;

// Get a reference to the cluster's rigid body
RigidBodyComponent RezedObject;
ClusterReference.GetObjectPrivate(0)
.TryGetFirstComponent(out RezedObject);

// Read a property of the rigid body
ScenePrivate.Chat.MessageAllUsers(
"Position: " + RezedObject.GetPosition().ToString());

// Eventually delete the object
StartCoroutine(DestroyCluster);

} catch (Exception Ex) {
ScenePrivate.Chat.MessageAllUsers("Error: " + Ex.Message);
}
}


private void DestroyCluster() {
Wait(TimeSpan.FromSeconds(10));
RezedCluster.Destroy(); // Delete the cluster from the scene
}


}

 

15 comments

Please sign in to leave a comment.