Accessing Prim Properties

From OpenSimulator

Revision as of 09:45, 17 June 2023 by JeffKelley (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search
DRAFT


A bit of history

First, there was llSetColor.

Then, there was llSetLinkColor. That was a huge step forward, since it was releaving you from the burden to script each and every prim in your hair. Don't laugh. You may still find such blatantly outdated scripts on the Hypergrid. Do us a favor. Don't propagate them. Trash them. Rewrite them.

Later, it was recognized that the ability to access every property of a prim in a linkset from a master script was a Good Thing. It makes your application simpler to understand and to maintain, and helps reduce script count. llSetLinkPrimitiveParams was born.

Finally, OpenSimulator added it's own touch. Why not manipulate prims outside the linkset from a master script ? And we had osSetPrimitiveParams.

llGet/SetLinkPrimitiveParams, osGet/SetPrimitiveParams are the workhorse of prim manipulations. You can access every existing property of a prim from a centralized location. Streamlined, faster code. No more need for chat, or LinkedMessages between prims.

A special note about llGetObjectLinkKey : Introduced September, 2022, this function is the glue you need to access prims outside the linkset. Once you get the id of an external object (maybe using llSensor), you may call llGetObjectPrimCount (also consider osGetPrimCount which does not count sitting avatars) then iterate on llGetObjectLinkKey to get the id of each prim in the remote object. Finally, apply osGet/SetPrimitiveParams.

The following tables tries to sort out the functions available to manipulate prims, for each addressing method.


Target is script's host
(prim containing the script)
Target is link number
(inside the linkset)
Target is prim id
(any prim you own in the scene)
llGetOwner
llGetKey llGetLinkKey(num)
llSetText
llGetRot / llSetRot
llGetScale / llSetScale
llGetAlpha / llSetAlpha llSetLinkAlpha(num)
llGetColor / llSetColor llSetLinkColor(num)
llGetPos / llSetPos
llGetObjectName / llSetObjectName llGetLinkName(num)
llGetObjectDesc / llSetObjectDesc
llGetNumberOfSides llGetLinkNumberOfSides(num)
llGetTexture / llSetTexture llSetLinkTexture(num)
llSetTextureAnim llSetLinkTextureAnim(num)
llParticleSystem llLinkParticleSystem(num)
llSetPrimMediaParams llSetLinkMedia(num)
llGetObjectPrimCount(uuid)
llGetObjectDetails(uuid)
llGetObjectLinkKey(uuid,num)
"Universal" access (list of rules)
llGet/SetPrimitiveParams llGet/SetLinkPrimitiveParams(num) osGet/SetPrimitiveParams(uuid)


Writing accessors

The Get/SetPrimitiveParams family of functions is awesomely powerful. It is also quite arcane to write and decipher. A way to get rid of these long lists of parameters cluttering your code is to encapsulate Get/SetPrimitiveParams in individual get/set accessors, actually 'filling the blanks' in the above table. Although this is much pleasant to read, note that doing so may hurt performance when you want to change many properties at once, which SetPrimitiveParams can do in one call. The following library is offered as an example.

// Index of properties for PRIM_TYPE_BOX, PRIM_TYPE_CYLINDER, PRIM_TYPE_PRISM
 
integer INDEX_TYPE      = 0;
integer INDEX_HOLE      = 1;
integer INDEX_CUT       = 2;
integer INDEX_HOLLOW    = 3;
integer INDEX_TWIST     = 4;
integer INDEX_TAPER     = 5;
integer INDEX_SHEAR     = 6;
 
// Index of properties for PRIM_TEXTURE
 
integer INDEX_TEXTURE   = 0;
integer INDEX_REPEATS   = 1;
integer INDEX_OFFSETS   = 2;
integer INDEX_ROTATION  = 3;
 
 
//                client        script
//          +---------------+------------+
//  Taper   | -1.0 0  +1.0  |  2.0   0.0 | 
//  Shear   | -0.5 0  +0.5  | -0.5  +0.5 |
//  Twist   | -180 0  +180  | -1.0  +1.0 | 
//          +---------------+------------+
 
 
//
// Set accessors
//
 
mySetLinkName (integer link, string text) {
    llSetLinkPrimitiveParamsFast (link, [PRIM_NAME, text]);
}
 
mySetLinkDesc (integer link, string text) {
    llSetLinkPrimitiveParamsFast (link, [PRIM_DESC, text]);
}
 
mySetLinkText (integer link, string text, vector color) {
    llSetLinkPrimitiveParamsFast (link, [PRIM_TEXT, text, color, 1.0]);
}
 
mySetLinkColor (integer link, vector color, integer face) {
    llSetLinkPrimitiveParamsFast (link, [PRIM_COLOR, face, color, 1.0]);
}
 
mySetLinkBright (integer link, integer bright, integer face) {
    llSetLinkPrimitiveParamsFast (link, [PRIM_FULLBRIGHT, face, bright]);
}
 
mySetLinkGlow (integer link, float glow, integer face) {
    llSetLinkPrimitiveParamsFast (link, [PRIM_GLOW, face, glow]);
}
 
// Les 3 suivants ne marchent pas pour ALL_SIDES
 
mySetLinkTexture (integer link, key texture, integer face) {
    list l = llGetLinkPrimitiveParams (link, [PRIM_TEXTURE, face]);
    l = llListReplaceList(l, [texture], INDEX_TEXTURE, INDEX_TEXTURE);
    llSetLinkPrimitiveParamsFast (link, [PRIM_TEXTURE, face] + l);
}
 
mySetLinkRepeat (integer link, vector repeat, integer face) {
    list l = llGetLinkPrimitiveParams (link, [PRIM_TEXTURE, face]);
    l = llListReplaceList(l, [repeat], INDEX_REPEATS, INDEX_REPEATS);
    llSetLinkPrimitiveParamsFast (link, [PRIM_TEXTURE, face] + l);
}
 
mySetLinkOffset (integer link, vector offset, integer face) {
    list l = llGetLinkPrimitiveParams (link, [PRIM_TEXTURE, face]);
    l = llListReplaceList(l, [offset], INDEX_OFFSETS, INDEX_OFFSETS);
    llSetLinkPrimitiveParamsFast (link, [PRIM_TEXTURE, face] + l);
}
 
mySetLinkPos (integer link, vector pos) {
    llSetLinkPrimitiveParamsFast (link, [PRIM_POS_LOCAL, pos]);
}
 
mySetLinkRot (integer link, rotation rot) {
    llSetLinkPrimitiveParamsFast (link, [PRIM_ROT_LOCAL, rot]);
}
 
mySetLinkSize (integer link, vector size) {
    llSetLinkPrimitiveParamsFast (link, [PRIM_SIZE, size]);
}
 
mySetLinkCut (integer link, vector cut) {
    list l = llGetLinkPrimitiveParams (link, [PRIM_TYPE]);
    l = llListReplaceList(l, [cut], INDEX_CUT, INDEX_CUT);
    llSetLinkPrimitiveParamsFast (link, [PRIM_TYPE] + l);
}
 
mySetLinkTwist (integer link, vector twist) {
    list l = llGetLinkPrimitiveParams (link, [PRIM_TYPE]);
    l = llListReplaceList(l, [twist], INDEX_TWIST, INDEX_TWIST);
    llSetLinkPrimitiveParamsFast (link, [PRIM_TYPE] + l);
}
 
mySetLinkTaper (integer link, vector taper) {
    list l = llGetLinkPrimitiveParams (link, [PRIM_TYPE]);
    l = llListReplaceList(l, [taper], INDEX_TAPER, INDEX_TAPER);
    llSetLinkPrimitiveParamsFast (link, [PRIM_TYPE] + l);
}
 
mySetLinkShear (integer link, vector shear) {
    list l = llGetLinkPrimitiveParams (link, [PRIM_TYPE]);
    l = llListReplaceList(l, [shear], INDEX_SHEAR, INDEX_SHEAR);
    llSetLinkPrimitiveParamsFast (link, [PRIM_TYPE] + l);
}
 
mySetLinkHollow (integer link, float hollow) {
    list l = llGetLinkPrimitiveParams (link, [PRIM_TYPE]);
    l = llListReplaceList(l, [hollow], INDEX_HOLLOW, INDEX_HOLLOW);
    llSetLinkPrimitiveParamsFast (link, [PRIM_TYPE] + l);
}
 
//
// Get accessors
//
 
string myGetLinkName (integer link) {
    list l = llGetLinkPrimitiveParams (link, [PRIM_NAME]);
    return llList2String (l,0);
}
 
string myGetLinkDesc (integer link) {
    list l = llGetLinkPrimitiveParams (link, [PRIM_DESC]);
    return llList2String (l,0);
}
 
string myGetLinkText (integer link) {
    list l = llGetLinkPrimitiveParams (link, [PRIM_TEXT]);
    return llList2String (l,0);
}
 
vector myGetLinkColor (integer link, integer face) {
    list l = llGetLinkPrimitiveParams (link, [PRIM_COLOR, face]);
    return llList2Vector (l,0);
}
 
integer myGetLinkBright (integer link, integer face) {
    list l = llGetLinkPrimitiveParams (link, [PRIM_FULLBRIGHT, face]);
    return llList2Integer (l,0);
}
 
float myGetLinkGlow (integer link, integer face) {
    list l = llGetLinkPrimitiveParams (link, [PRIM_GLOW, face]);
    return llList2Float (l,0);
}
 
key myGetLinkTexture (integer link, integer face) {
    list l = llGetLinkPrimitiveParams (link, [PRIM_TEXTURE, face]);
    return llList2Key(l,0);
}
 
vector myGetLinkRepeat (integer link, integer face) {
    list l = llGetLinkPrimitiveParams (link, [PRIM_TEXTURE, face]);
    return llList2Vector(l,1);
}
 
vector myGetLinkOffset (integer link, integer face) {
    list l = llGetLinkPrimitiveParams (link, [PRIM_TEXTURE, face]);
    return llList2Vector(l,2);
}
 
vector myGetLinkPos (integer link) {
    list l = llGetLinkPrimitiveParams (link, [PRIM_POS_LOCAL]);
    return llList2Vector (l,0);
}
 
vector myGetLinkSize (integer link) {
    list l = llGetLinkPrimitiveParams (link, [PRIM_SIZE]);
    return llList2Vector (l,0);
}
 
vector myGetLinkCut (integer link) {
    list l = llGetLinkPrimitiveParams (link, [PRIM_TYPE]);
    return llList2Vector (l, INDEX_CUT);
}
 
vector myGetLinkTwist (integer link) {
    list l = llGetLinkPrimitiveParams (link, [PRIM_TYPE]);
    return llList2Vector (l, INDEX_TWIST);
}
 
vector myGetLinkTaper (integer link) {
    list l = llGetLinkPrimitiveParams (link, [PRIM_TYPE]);
    return llList2Vector (l, INDEX_TAPER);
}
 
vector myGetLinkShear (integer link) {
    list l = llGetLinkPrimitiveParams (link, [PRIM_TYPE]);
    return llList2Vector (l, INDEX_SHEAR);
}
 
float myGetLinkHollow (integer link) {
    list l = llGetLinkPrimitiveParams (link, [PRIM_TYPE]);
    return llList2Float (l, INDEX_HOLLOW);
}
Personal tools
General
About This Wiki