Join us in Outworldz at www.outworldz.com:9000 or follow us:

Search dozens of selected web sites for OpenSim and LSL script

New! Script Meta-Search will search thousands of scripts here and at other sites for LSL or Opensim scripts.
Loading

Want to add a script or a project? Upload it and a half million people will see it and your name here this year.

Home   Show All
Category: Contributor: Creator
Attachment Multi_point_attachment  

Multi_point_attachment

Multi point attachment by Joannah Cramer.lsl

Category: Attachment
By : Joannah Cramer
Created: 2010-01-10 Edited: 2010-01-10
Worlds: Second Life

the Zip file

Download all files for Multi_point_attachment
Contents are in zip format, with .LSL (text) source code and LSLEdit (text + Solution) formats.
Get file # 1. Multi_point_attachment_by_Joannah_C_1.lsl
1
2 //********************************************************
3 //This Script was pulled out for you by YadNi Monde from the SL FORUMS at http://forums.secondlife.com/forumdisplay.php?f=15, it is intended to stay FREE by it s author(s) and all the comments here in ORANGE must NOT be deleted. They include notes on how to use it and no help will be provided either by YadNi Monde or it s Author(s). IF YOU DO NOT AGREE WITH THIS JUST DONT USE!!!
4 //********************************************************
5
6
7
8
9
10
11
12 // Multi point attachment by Joannah Cramer
13 //The idea for script came from this thread (http://forums.secondlife.com/showthread.php?t=145241). 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.
14 //
15 //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.
16
17
18
19
20 // this script memorizes position and rotation of object for each attachment point it was worn on.
21 // allows easy creation of items like weapons looking proper both in hand and when put on the hip/back,
22 // skirts and body parts which can be easily switched between lower torso points,
23 // headphones switching position when moved from head onto chest, etc
24 //
25 // USE: put the script in the root prim of your object.
26 // position and angle of last used attach point will be memorized when the object is detached.
27 //
28 // to pre-set positions for multiple points attach the item to selected point, adjust position and angle,
29 // then detach the item, attach it to another point, adjust position and angle, detach... repeat for all
30 // desired attachment points.
31
32 list attach_points;
33 list attach_offsets;
34 list attach_angles;
35 integer current_point;
36
37 default {
38
39 state_entry() { current_point = llGetAttached(); } // grab the attach point when script is first put in the item
40
41 attach( key Contact ) {
42
43 if( Contact != NULL_KEY ) {
44 // item is being attached
45 current_point = llGetAttached(); // cache the point so correct data can be saved on detach
46 integer idx = llListFindList( attach_points, [ current_point ] );
47 if( idx != -1 ) {
48 // previously used attach point, restore memorized position of object
49 llSetPrimitiveParams( [ PRIM_POSITION, llList2Vector( attach_offsets, idx ),
50 PRIM_ROTATION, llList2Rot( attach_angles, idx ) ] );
51 }
52 else {
53 // a new attach location. remove potential offsets from last recognized attach point.
55 }
56 }
57 else {
58 // item is being detached, store the data
59 if( current_point == 0 ) { return; }
60 integer idx = llListFindList( attach_points, [ current_point ] );
61 vector offset = llGetLocalPos();
62 rotation angle = llGetLocalRot();
63 if( idx == -1 ) {
64 // add new point data
65 attach_points += current_point;
66 attach_offsets += offset;
67 attach_angles += angle;
68 }
69 else {
70 // update existing point data
71 attach_offsets = llListReplaceList( attach_offsets, [ offset ], idx, idx );
72 attach_angles = llListReplaceList( attach_angles, [ angle ], idx, idx );
73 }
74 }
75 }
76 } // END //

Back to the Best Free Tools in Second Life and OpenSim.