Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Multi point attachment

Joannah Cramer
Registered User
Join date: 12 Apr 2006
Posts: 1,539
10-25-2006 17:56
The idea for script came from this thread. Basically, it will memorize offsets and rotations of item separately for each AV attachment point the item is attached to, and restore them as needed. This way rather than having to create separate versions of one attachment aligned for each of possible points, the item maker can just ship single item which will align itself properly in all pre-recorded spots, no matter where exactly the buyer picks to fit it.

How to use: drop into root prim of attachment. Attach it to AV point, move and rotate around until it's positioned the way you like. Detach the item, attach it again to another point, position and rotate like before, detach when it looks fine there too. Repeat the attach-position-detach thing for each of the points you want to have recorded.

CODE

// this script memorizes position and rotation of object for each attachment point it was worn on.
// allows easy creation of items like weapons looking proper both in hand and when put on the hip/back,
// skirts and body parts which can be easily switched between lower torso points,
// headphones switching position when moved from head onto chest, etc
//
// USE: put the script in the root prim of your object.
// position and angle of last used attach point will be memorized when the object is detached.
//
// to pre-set positions for multiple points attach the item to selected point, adjust position and angle,
// then detach the item, attach it to another point, adjust position and angle, detach... repeat for all
// desired attachment points.

list attach_points;
list attach_offsets;
list attach_angles;
integer current_point;

default {

state_entry() { current_point = llGetAttached(); } // grab the attach point when script is first put in the item

attach( key Contact ) {

if( Contact != NULL_KEY ) {
// item is being attached
current_point = llGetAttached(); // cache the point so correct data can be saved on detach
integer idx = llListFindList( attach_points, [ current_point ] );
if( idx != -1 ) {
// previously used attach point, restore memorized position of object
llSetPrimitiveParams( [ PRIM_POSITION, llList2Vector( attach_offsets, idx ),
PRIM_ROTATION, llList2Rot( attach_angles, idx ) ] );
}
else {
// a new attach location. remove potential offsets from last recognized attach point.
llSetPrimitiveParams( [ PRIM_POSITION, ZERO_VECTOR, PRIM_ROTATION, ZERO_ROTATION ] );
}
}
else {
// item is being detached, store the data
if( current_point == 0 ) { return; }
integer idx = llListFindList( attach_points, [ current_point ] );
vector offset = llGetLocalPos();
rotation angle = llGetLocalRot();
if( idx == -1 ) {
// add new point data
attach_points += current_point;
attach_offsets += offset;
attach_angles += angle;
}
else {
// update existing point data
attach_offsets = llListReplaceList( attach_offsets, [ offset ], idx, idx );
attach_angles = llListReplaceList( attach_angles, [ angle ], idx, idx );
}
}
}
}
Nada Epoch
The Librarian
Join date: 4 Nov 2002
Posts: 1,423
Discussion Thread
10-25-2006 22:47
/54/40/145553/1.html
_____________________
i've got nothing. ;)