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
Sculpt SL_Sculpt_to_PHP_script  

SL_Sculpt_to_PHP_script

OpenLoft - Description

Category: Sculpt
By : Falados Kapuskas
Created: 2012-09-18 Edited: 2012-09-18
Worlds: Second Life

the Zip file

Download all files for SL_Sculpt_to_PHP_script
Contents are in zip format, with .LSL (text) source code and LSLEdit (text + Solution) formats.
Get file # 1. SL_Sculpt_to_PHP_script_1.lsl
Get file # 2. SL_Sculpt_to_PHP_script_10.lsl
Get file # 3. SL_Sculpt_to_PHP_script_11.lsl
Get file # 4. SL_Sculpt_to_PHP_script_12.lsl
Get file # 5. SL_Sculpt_to_PHP_script_13.lsl
Get file # 6. SL_Sculpt_to_PHP_script_14.lsl
Get file # 7. SL_Sculpt_to_PHP_script_15.lsl
Get file # 8. SL_Sculpt_to_PHP_script_16.lsl
Get file # 9. SL_Sculpt_to_PHP_script_17.lsl
Get file # 10. SL_Sculpt_to_PHP_script_18.lsl
Get file # 11. SL_Sculpt_to_PHP_script_19.lsl
Get file # 12. SL_Sculpt_to_PHP_script_2.lsl
Get file # 13. SL_Sculpt_to_PHP_script_20.lsl
Get file # 14. SL_Sculpt_to_PHP_script_21.lsl
Get file # 15. SL_Sculpt_to_PHP_script_3.lsl
Get file # 16. SL_Sculpt_to_PHP_script_4.lsl
Get file # 17. SL_Sculpt_to_PHP_script_5.lsl
Get file # 18. SL_Sculpt_to_PHP_script_6.lsl
Get file # 19. SL_Sculpt_to_PHP_script_7.lsl
Get file # 20. SL_Sculpt_to_PHP_script_8.lsl
Get file # 21. SL_Sculpt_to_PHP_script_9.lsl
1 ==Introduction==
2 Thanks for Downloading OpenLoft!
3
4 This tool is designed to help builders create sculpted prims in world. This readme should
5 give you a rough idea of how to get up and running with open loft.
6
7 ==Quick Start Guide==
8
9 ===Step 1===
10 The first thing you must do is get online web space. Now this isn't as difficult as it sounds. A lot of places have some free limited web space, but you need to be picky about which one you get. The on I used is [http://www.x10hosting.com/] and they've been very good so far. You must apply for their Intermediate PHP version, which they usually accepts without question. This version will give you access to the required php functions that are otherwise restricted.
11
12 A list of other sites can be found here which have a lot of specifications:
13 [http://www.free-webhosts.com/free-php-webhosting.php]
14
15 You'll need the ability to write files with PHP and also the GD library so that PHP can also construct images (the backbone of the sculpt rendering system)
16
17 ===Step 2===
18 Rez the Open Loft Tool object.
19
20 ===Step 3===
21 Put the URL of the vertext2sculpt.php file in the OpenLoft URL notecard.
22 --Example--
23 http://example.com/example_site/vertex2sculpt.php
24
25 ===Step 4===
26 Take a copy of the Open Loft Tool object. This is so that you have a copy readily available with the URL already inside of it.
27
28 ===Step 5===
29 Click on the Open Loft Tool to bring up a menu and start sculpting
30
31 ==The Open Loft Tool Menu==
32
33 There are eleven buttons that will come up in the open loft menu.
34
35 ===RENDER===
36 This will render the current sculpt on your server. This sends all the verticies to the server
37 and the php script constructs the image. When the sculpt is successfully created, you will
38 be notified by an inworld message (Owner Say) denoting the URL of your image.
39
40 Click this URL to load the image in your web browser.
41 Save this image and upload it to Second Life (10L).
42 Be sure to use LOSSLESS COMPRESSION, otherwise your sculpt will be distorted
43
44 ===REZ===
45 Rezes all of the disks that will help you sculpt. This is a simple rez that
46 puts all of the discs one on top of the other in a column or cylinder
47
48 ===POLYREZ===
49 PolyRez or Polynomial Rezing will rez the discs along a curve defined in the Polyrez Parameters
50 A polynomial you may recognize from algebra, and takes the form p[0] + p[1]x^1 + p[2]x^2 ... p[n]x^n
51 The parameters in this notecard define the coeficients of the polynomial. Depending on the number
52 of P values specified, you can rez the discs along a curve that is linear, quadradic, cubic, etc...
53
54 ===SHOW===
55 Shows all the disks if they were previously hidden
56
57 ===HIDE===
58 Hides all the disks by making them transparent. This also hides the nodes from each disk of the nodes
59 were visible
60
61 ===VERTS===
62 Causes all the discs to detach their verticies from the central disc, allowing you to hand-place each vertex manually
63
64 ===RESIZE===
65 Resizes all the disks to fit all their detached nodes. Only works if the nodes of the disk are detached.
66
67 ===ATTACH===
68 Attaches all the previously detached nodes back to the disc. The disc now contains node data and can be scaled, moved, and rotated. Thiese operations will result in modifying the nodes internally. The disks will change color indicating that there is node-data stored inside.
69
70 If for instance, you had arranged your nodes into a straight line, scaling the disk will also scale that line
71
72 ===CSEC===
73 Instructs all detached nodes to attempt a cross-section of physical objects. The nodes will inch towards the center
74 of the disc until they either reach the center, or hit a physical object. If they do not hit a physical object, they will retry this process three times until it ultimately fails, then they will return to the position before the CSECT command.
75
76 ===ENCLOSE===
77 The OpenLoftTool will attempt to enclose all nodes/discs of the sculpture.
78 USE THIS COMMAND BEFORE THE RENDER COMMAND.
79
80 Auto-encloser maximizes the size of the sculpture and ensures that no space is wasted.
81 If you want to hav very small sculptures you can scale the OpenLoftTool bigger than the discs inside, which will make the resulting sculpture smaller than normal.
82
83 ===SMOOTH===
84 Allows you to pick from three different vertex smoothing algorithms.
85 LINNEAR: Blurs the resulting images slightly, which removes fine detail
86 GAUSSIAN: Selectively blurs the image, has a tendancy to keep some finer detail
87 NONE: No bluring at all, a perfect repreduction of the verticies.
88
89 ==Disk Tool Menu==
90
91 Clicking on the Disk tool will give you several options.
92
93 ===DETACH VERT===
94 Detach the internal nodes or verticies from the disk, allowing you to edit
95 them individually.
96
97 ===Make Point===
98 Converts the disk into a single point, essentially bringing all verticies
99 together into the center. The disk will change shape into a small sphere.
100
101 ===Reset Verts===
102 Internally, the verticies will be reset to their default position
103 which is: spaced evenly around the perimeter of the disk.
104
105 ==Disk Tool Menu: Detached Verticies==
106
107 When the verticies of a disk are detached, there will be different
108 options presented to you when you click on that disk.
109
110 ===Attach Verts===
111 This will attach the verticies to the disk again, storing their positions.
112 The disk will change color indicating that there is node-data stored inside.
113
114 ===Cross Section===
115 Instructs all detached nodes to attempt a cross-section of physical objects. The nodes will inch towards the center
116 of the disc until they either reach the center, or hit a physical object. If they do not hit a physical object, they will retry this process three times until it ultimately fails, then they will return to the position before the CSECT command.
117
118
119 ==Disk Tool Menu: Linked Disks==
120 When you link disks together, you make invoke operations on the entire
121 set of disks.
122
123 NOTE: The order of linking matters. Please link each node from start to finish
124 selecting each and every disk individually. Once they are selected, link them
125 together. Click the root node to invide the Linked Disk Menu.
126
127 ===Copy Verts===
128 Copys the verticies stored in the root node into every other node
129 in the link set.
130
131 ===Clear Set===
132 Performes the 'Reset Verts' function on each disk in the set
133
134 ===Resize Set==
135 Resizes each disk to match the scale of the root node
136
137 ===Interpolate===
138
139 Brings up a menu allowing you to automatically generate steps inbetween the Root Link and the last link. Interpolation is the reason why the order of the links matters.
140
141 If you don't know what interpolation means:
142 http://en.wikipedia.org/wiki/Interpolation
143
144 ====Scale====
145 Interpolates the scale of each disk from Root to End
146
147 ====Rotation====
148 Interpolates the rotation of each disk from Root to End
149
150 ====Node Data====
151 Each disk has internal node data stored inside of it. This
152 function tries to interpolate each disks node data between the first disk
153 and the last disk.
154
155 Essentially, this produces a shape that appears to transform itself
156 gradually from the first disk into the last disk.
157
158 ===Notes About Linking===
159 Be sure to unlink your disks after you are done playing
160 with the link set. The Open Loft Tool menu doesn't
161 work too well when the disks are linked together.

SL_Sculpt_to_PHP_script

Openloft.lsl

Category: Sculpt
By : Falados Kapuskas
Created: 2012-09-18 Edited: 2012-09-18
Worlds: Second Life

1 // This file is part of OpenLoft.
2 //
3 // OpenLoft is free software: you can redistribute it and/or modify
4 // it under the terms of the GNU General Public License as published by
5 // the Free Software Foundation, either version 3 of the License, or
6 // (at your option) any later version.
7 //
8 // OpenLoft is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 // GNU General Public License for more details.
12 //
13 // You should have received a copy of the GNU General Public License
14 // along with OpenLoft. If not, see <http://www.gnu.org/licenses/>.
15 //
16 // Authors: Falados Kapuskas, JoeTheCatboy Freelunch
17
18 //-- CONSTANTS --//
19 list HTTP_PARAMS = [
20 HTTP_METHOD, "POST",
21 HTTP_MIMETYPE,"application/x-www-form-urlencoded"
22 ];
23
24 list MAIN_DIALOG = [
25 "[RESOLUTION] Change Resolution","RESOLUTION",
26 "[REZ] Creates disk column","REZ",
27 "[REZ2] Creates a Torus","REZ2",
28 "[RENDERING] Render Menu","RENDERING",
29 "[TOOLS] Tools Menu","TOOLS",
30 "[SPLINE] Spline Menu","SPLINE",
31 "[ACCESS] Access Levels","ACCESS"
32 ];
33
34 list RENDER_DIALOG =
35 [
36 "[RENDER] Render Menu","RENDER",
37 "[ENCLOSE] Auto-encloses the sculpture","ENCLOSE",
38 "[SMOOTH] Change the smoothing parameter","SMOOTH"
39 ];
40
41 list TOOLS_DIALOG =
42 [
43 "[SHOW] Shows all disks and nodes","SHOW",
44 "[HIDE] Hides all disks and nodes","HIDE",
45 "[NODES] Create Copy Tool","NODES",
46 "[MIRROR] Create Node Mirror Tool","MIRROR"
47 ];
48
49 list ACCESS_DIALOG =
50 [
51 "[EVERYONE] Everyone can use this","EVERYONE",
52 "[GROUP] Group-members can you this","GROUP",
53 "[OWNER] Only Owner can use this","OWNER"
54 ];
55
56 list SPLINE_DIALOG =
57 [
58 "[ADD CTRL] Adds a control point","ADD CTRL",
59 "[DEL CTRL] Deletes the last control point","DEL CTRL",
60 "[BEZ STOP] Stops disks from following the spline","BEZ STOP",
61 "[BEZ START] Lets disks follow the bezier curve","BEZ START"
62 ];
63
64 list SMOOTH_DIALOG =
65 [
66 "[NONE] No smoothing, use raw vertex data","NONE",
67 "[LINEAR] Blurs the image slightly to smooth out bumps","LINEAR",
68 "[GAUSSIAN] Blurs the image, but preserves some finer details","GAUSSIAN"
69 ];
70
71 list RESOLUTIONS =
72 [
73 "32x32",<32,32,0>,
74 "16x16",<16,16,0>,
75 "8x8",<8,8,0>,
76 "64x16",<64,16,0>,
77 "128x8",<128,8,0>,
78 "256x4",<256,4,0>,
79 "16x64",<16,64,0>,
80 "8x128",<8,128,0>,
81 "4x256",<4,256,0>
82 ];
83
84 list ACCESS_LEVELS = [
85 "OWNER",2,
86 "GROUP",1,
87 "EVERYONE",0
88 ];
89
90 string NODE_NAME = "sculpt";
91 string CONTROL_NAME = "control";
92 integer BROADCAST_CHANNEL;
93 integer CHANNEL_MASK = 0xFFFFFF00;
94 integer CONTROL_POINT_MASK = 0xFF;
95 integer DIALOG_CHANNEL = 4209249;
96 integer RESOLUTION_CHANNEL = 123913;
97 integer MAX_NODES = 32;
98 integer ENCLOSED = FALSE;
99 string URL; //Set Via Notecard
100 integer ACCESS_LEVEL = 2;
101 integer COLUMNS = 32;
102 //-- Globals --//
103 key gCurrentKey;
104 key gDataserverRequest;
105 key gHTTPRequest;
106 string gBlurType = "none";
107 integer gHasRezed;
108 integer gListenHandle_Broadcast;
109 integer gListenHandle_Enclose; //Listen for Nodes
110 integer gListenHandle_Agent; //Avatar listen callback
111 integer gListenHandle_Errors; //Render Errors
112 integer gListenHandle_Success; //Render Success
113 integer n;
114
115
116 vector bbox_lower;
117 vector bbox_higher;
118
119 //-- FUNCTIONS --//
120
121 rezSculptNodes(integer i)
122 {
123 llRegionSay(BROADCAST_CHANNEL,"#die#");
124 list params;
125 if(i == 1) {
126 params = [13,MAX_NODES,CONTROL_NAME,NODE_NAME,1];
127 } else {
128 params = [2,MAX_NODES,CONTROL_NAME,NODE_NAME,0];
129 }
130 llMessageLinked(LINK_THIS,BROADCAST_CHANNEL,llList2CSV(params),"#rez#");
131 }
132
133
134 //Starts the Rendering Process by announcing and waiting
135 //for replies. Once all replies are in, a final request
136 //is sent that informs the server to compile the image.
137 render(){
138 n = 0;
139 llListenRemove(gListenHandle_Errors);
140 llListenRemove(gListenHandle_Success);
141 gListenHandle_Errors = llListen(-2002,"","","");
142 gListenHandle_Success = llListen(-2001,"","","");
143 llShout(BROADCAST_CHANNEL,"#render#"+URL);
144 }
145
146 minmax(vector vert) {
147 //Min
148 if( vert.x < bbox_lower.x ) bbox_lower.x = vert.x;
149 if( vert.y < bbox_lower.y ) bbox_lower.y = vert.y;
150 if( vert.z < bbox_lower.z ) bbox_lower.z = vert.z;
151
152 //Max
153 if( vert.x > bbox_higher.x ) bbox_higher.x = vert.x;
154 if( vert.y > bbox_higher.y ) bbox_higher.y = vert.y;
155 if( vert.z > bbox_higher.z ) bbox_higher.z = vert.z;
156 }
157
158 dialog(string message, list dialog, key id, integer channel)
159 {
160 gListenHandle_Agent = llListen(channel,"",id,"");
161 string m = message + llDumpList2String( llList2ListStrided(dialog,0,-1,2) , "\n");
162 llDialog(id,m,llList2ListStrided( llDeleteSubList(dialog,0,0), 0,-1,2),channel);
163 }
164
165 //Get Access Allowed/Denited
166 integer has_access(key agent)
167 {
168 //Everyone has access
169 if(ACCESS_LEVEL == 0) return TRUE;
170 else
171 //Owner has access
172 if(ACCESS_LEVEL == 2)
173 {
174 return agent == llGetOwner();
175 }
176 else
177 //Group has access
178 if(ACCESS_LEVEL == 1)
179 {
180 return llSameGroup(agent);
181 }
182 //Failed
183 return FALSE;
184 }
185
186 //-- STATES --//
187
188 default
189 {
191 {
192 BROADCAST_CHANNEL = (-(integer)(llFrand(1e+6) + 1e+6)) & CHANNEL_MASK;
193 }
194 on_rez(integer p){
196 }
197 listen(integer c, string st, key id, string m)
198 {
199 if( c == DIALOG_CHANNEL ) {
200 llListenRemove(gListenHandle_Agent);
201 //--- SUB MENUS ---///
202 if(m == "RENDERING")
203 {
204 dialog("Choose an action:\n",RENDER_DIALOG,id,DIALOG_CHANNEL);
205 return;
206 }
207 if(m == "RESOLUTION")
208 {
209 gListenHandle_Agent = llListen(RESOLUTION_CHANNEL,"",id,"");
210 llDialog(id,"Pick a resolution",llList2ListStrided(RESOLUTIONS,0,-1,2),RESOLUTION_CHANNEL);
211 return;
212 }
213 if(m == "SMOOTH")
214 {
215 dialog("Pick a smoothing option\n",SMOOTH_DIALOG,id,DIALOG_CHANNEL);
216 return;
217 }
218 if(m == "SPLINE")
219 {
220 dialog("Pick a SPLINE action:\n",SPLINE_DIALOG,id,DIALOG_CHANNEL);
221 return;
222 }
223 if(m == "TOOLS")
224 {
225 dialog("Choose an action:\n",TOOLS_DIALOG,id,DIALOG_CHANNEL);
226 return;
227 }
228 if(m == "ACCESS")
229 {
230 dialog("Choose an access level:\n",ACCESS_DIALOG,id,DIALOG_CHANNEL);
231 return;
232 }
233 // - REZ BUTTON - //
234 if(m == "REZ"){
235 if(gHasRezed) llShout(BROADCAST_CHANNEL,"#die#");
236 rezSculptNodes(0);
237 return;
238 }
239 // - REZ BUTTON - //
240 if(m == "REZ2"){
241 if(gHasRezed) llShout(BROADCAST_CHANNEL,"#die#");
242 rezSculptNodes(1);
243 return;
244 }
245 // - RENDER MENU - //
246 if(m == "ENCLOSE"){
247 n = 0;
248 ENCLOSED = FALSE;
249 llListenRemove(gListenHandle_Enclose);
250 gListenHandle_Enclose = llListen(-2000,"","","");
251 bbox_lower = <9999,9999,9999>;
252 bbox_higher = <-9999,-9999,-9999>;
254 llShout(BROADCAST_CHANNEL,"#enclose#");
255 llSetTimerEvent(15.0);
256 return;
257 }
258 if(m == "RENDER"){
259 if(ENCLOSED) {
260 gCurrentKey=id;
261 render();
262 } else {
263 llOwnerSay("You must first ENCLOSE the sculpt before you can render it");
264 }
265 return;
266 }
267 // - TOOLS MENU - //
268 if( m == "SHOW" || m == "HIDE") {
269 llShout(BROADCAST_CHANNEL,"#" +llToLower(m)+"#");
270 return;
271 }
272 if(m == "MIRROR") {
273 list d = llGetObjectDetails(id,[OBJECT_POS,OBJECT_ROT" title="View Definition" class="tooltip">OBJECT_ROT]);
274 vector pos = llList2Vector(d,0) + llRot2Fwd(llList2Rot(d,1))*2;
275 llRezObject("Mirror Tool",pos,ZERO_VECTOR,ZERO_ROTATION,BROADCAST_CHANNEL);
276 }
277 if(m == "NODES") {
278 list d = llGetObjectDetails(id,[OBJECT_POS,OBJECT_ROT" title="View Definition" class="tooltip">OBJECT_ROT]);
279 vector pos = llList2Vector(d,0) + llRot2Fwd(llList2Rot(d,1))*2;
280 llRezObject("Node Tool",llGetPos()+<0,0,.5>,ZERO_VECTOR,llEuler2Rot(<-PI_BY_TWO,0,0>),BROADCAST_CHANNEL);
281 }
282 // - SMOOTH MENU - //
283 if(m == "LINEAR" || m== "GAUSSIAN" || m =="NONE"){
284 gBlurType = llToLower(m);
285 return;
286 }
287 // - SPLINE MENU -- //
288 if( m == "ADD CTRL")
289 {
290 llMessageLinked(LINK_THIS,BROADCAST_CHANNEL,"","#add_control#");
291 return;
292 }
293 if( m == "DEL CTRL")
294 {
295 llMessageLinked(LINK_THIS,BROADCAST_CHANNEL,"","#remove_control#");
296 return;
297 }
298 if( m == "BEZ STOP")
299 {
300 llShout(BROADCAST_CHANNEL,"#bezier-stop#");
301 return;
302 }
303 if( m == "BEZ START")
304 {
305 llShout(BROADCAST_CHANNEL,"#bezier-start#");
306 return;
307 }
308 // - ACCESS LEVELS -
309 integer ac = llListFindList(ACCESS_LEVELS,[m]);
310 if(ac != -1 ) {
311 ACCESS_LEVEL = llList2Integer(ACCESS_LEVELS,ac+1);
312 llShout(BROADCAST_CHANNEL,"#setup#" + llList2CSV([COLUMNS,ACCESS_LEVEL,URL,MAX_NODES]));
313 return;
314 }
315 }
316 if( c == RESOLUTION_CHANNEL)
317 {
318 llListenRemove(gListenHandle_Agent);
319 integer i = llListFindList(RESOLUTIONS,[m]);
320 if(i != -1)
321 {
322 vector v = llList2Vector(RESOLUTIONS,i+1);
323 MAX_NODES = (integer)v.x;
324 COLUMNS = (integer)v.y;
325 }
326 }
327 //Size Reponses
328 if( c == -2000 )
329 {
331 llSetTimerEvent(15.0);
332 ++n;
333 integer break = llSubStringIndex(m,"|");
334 if( break != -1 )
335 {
336 minmax((vector)llGetSubString(m,0,break-1));
337 minmax((vector)llGetSubString(m,break+1,-1));
338 } else {
339 minmax((vector)m);
340 }
341
342 if( n >= MAX_NODES ) {
343 vector scale = bbox_higher - bbox_lower;
344 vector pos = bbox_lower + scale*.5;
345 if( llVecMag(scale) < 17.4 ) {
346 llSetPos(pos);
347 llSetScale(scale*1.01);
348 ENCLOSED = TRUE;
349 } else {
350 llOwnerSay("Enclose Failed - Size Too Big");
351 }
352 llSetTimerEvent(0.0);
353 llListenRemove(gListenHandle_Enclose);
354 }
355 }
356 //Successful Upload Responses
357 if( c == -2001 ) {
358 ++n;
359 if( n == MAX_NODES ) {
360 if(URL != "" && URL != "none") {
361 gHTTPRequest = llHTTPRequest(URL + "action=render",HTTP_PARAMS,
362 "scale=" + llEscapeURL((string)llGetScale()) +
363 "&org=" + llEscapeURL((string)llGetPos()) +
364 "&smooth=" + gBlurType +
365 "&w=" + (string)COLUMNS +
366 "&h=" + (string)MAX_NODES
367 );
368 }
369 }
370 }
371 //Errored Responses
372 if( c == -2002 ) {
373 llOwnerSay("Error on row " + m);
374 }
375 }
376 timer() {
377 llSetTimerEvent(0.0);
378 llListenRemove(gListenHandle_Enclose);
379 llOwnerSay("Enclose Failed - Not All Nodes Responded");
380 }
382 {
383 //Done Rezing
384 if( id == "#rez_fin#" )
385 {
386 gDataserverRequest = llGetNotecardLine("OpenLoft URL",0);
387 }
388 }
389
390 touch_start(integer total_number)
391 {
392 if(!has_access(llDetectedKey(0))) return;
393 dialog("Choose an action:\n",MAIN_DIALOG,llDetectedKey(0),DIALOG_CHANNEL);
394 }
395
396 dataserver( key request_id, string data)
397 {
398 if( gDataserverRequest == request_id) {
399 URL = data;
400 if( URL != "URL HERE") {
401 if(llSubStringIndex(URL,"?") == -1) URL = URL + "?";
402 } else {
403 llOwnerSay("You must replace the url in the 'OpenLoft URL' notecard");
404 URL = "none";
405 }
406 llShout(BROADCAST_CHANNEL,"#setup#" + llList2CSV([COLUMNS,ACCESS_LEVEL,MAX_NODES]));
407 }
408 }
409
410 //This is here simply to echo the links that the server replies with
411 http_response( key request_id, integer status, list meta, string data)
412 {
413 if(gHTTPRequest != request_id) return;
414 if( status == 200 ) { //OK
415 if( llStringTrim(data,STRING_TRIM) != "" )
416 llInstantMessage(gCurrentKey,data);
417 } else {
418 llInstantMessage(gCurrentKey,"Server Error: " + (string)status + "\n" + llList2CSV(meta) + "\n" + data);
419 }
420 }
421 }

SL_Sculpt_to_PHP_script

BezierRez.lsl

Category: Sculpt
By : Falados Kapuskas
Created: 2012-09-18 Edited: 2012-09-18
Worlds: Second Life

1 vector ORIGIN;
2 vector SIZE = <10,10,10>;
3 integer gRezed;
4 integer CONTROL_POINTS = 4;
5 integer INTERP_POINTS = 15;
6 integer CHANNEL;
7 integer CHANNEL_MASK = 0xFFFFFF00;
8 string CONTROL_OBJECT;
9 string INTERP_OBJECT;
10 integer OFF = FALSE;
11 list gControlPoints;
12 list gAnchorPoints;
13 integer gRezState;
14 integer gDiskNum;
15 integer gAnnounceFinish;
16 go_pos(vector p)
17 {
18 while(llGetPos() != p) {
19 llSetPos(p);
20 }
21 }
22
23 integer rez_disk(integer i)
24 {
25 if(i >= INTERP_POINTS) return FALSE;
26 llRezObject(INTERP_OBJECT,llGetPos(),ZERO_VECTOR,ZERO_ROTATION,CHANNEL | (i & 0xFF) );
27 llSetText("Rezing Disks : " + (string)(i+1) + " of " + (string)INTERP_POINTS,<0,1,0>,1.0);
28 llSleep(0.2);
29 return TRUE;
30 }
31
32 default
33 {
34 link_message(integer sn, integer i, string str, key id)
35 {
36 if(id == "#rez#")
37 {
38 gAnnounceFinish = TRUE;
39 list params = llCSV2List(str);
40 CHANNEL = i & CHANNEL_MASK;
41 integer i;
42 vector p = llGetPos();
43 vector pos;
44 rotation rot;
45 ORIGIN = llGetPos() + <0,0,.5>;
46 CONTROL_POINTS = llList2Integer(params,0);
47 INTERP_POINTS = llList2Integer(params,1);
48 CONTROL_OBJECT = llList2String(params,2);
49 INTERP_OBJECT = llList2String(params,3);
50 integer type = llList2Integer(params,4);
51 float magic = 0.551784;
52 list cpos;
53 list crot;
54 if(type == 1)
55 {
56 cpos = [
57 ORIGIN + <0,0,0>,
58 ORIGIN + <0,2.5*magic,0>,
59 ORIGIN + <0,2.5,2.5-2.5*magic>,
60 ORIGIN + <0,2.5,2.5>,
61 ORIGIN + <0,2.5,2.5+2.5*magic>,
62 ORIGIN + <0,2.5*magic,5>,
63 ORIGIN + <0,0,5>,
64 ORIGIN + <0,-2.5*magic,5>,
65 ORIGIN + <0,-2.5,2.5+2.5*magic>,
66 ORIGIN + <0,-2.5,2.5>,
67 ORIGIN + <0,-2.5,2.5-2.5*magic>,
68 ORIGIN + <0,-2.5*magic,0>,
69 ORIGIN + <0,0,0>
70 ];
71 crot = [
72 llEuler2Rot(<-PI_BY_TWO,0,0>),
73 llEuler2Rot(<-PI_BY_TWO,0,0>),
74 llEuler2Rot(<0,0,0>),
75 llEuler2Rot(<0,0,0>),
76 llEuler2Rot(<0,0,0>),
77 llEuler2Rot(<PI_BY_TWO,0,0>),
78 llEuler2Rot(<PI_BY_TWO,0,0>),
79 llEuler2Rot(<PI_BY_TWO,0,0>),
80 llEuler2Rot(<PI,0,0>),
81 llEuler2Rot(<PI,0,0>),
82 llEuler2Rot(<PI,0,0>),
83 llEuler2Rot(<-PI_BY_TWO,0,0>),
84 llEuler2Rot(<-PI_BY_TWO,0,0>)
85 ];
86 }
87 gRezed = 0;
88 gRezState = 0;
89 gControlPoints = [];
90 gAnchorPoints = [];
91 for( i = 0; i < CONTROL_POINTS; ++i)
92 {
93 if(type == 1)
94 {
95 pos = llList2Vector(cpos,i);
96 rot = llList2Rot(crot,i);
97 } else {
98 pos = ORIGIN + <0,0,5> * ((float)i/(float)(CONTROL_POINTS-1));
99 rot = ZERO_ROTATION;
100 }
101 llSetText("Rezing Control Points : " + (string)(i+1) + " of " + (string)CONTROL_POINTS,<1,1,0>,1.0);
102 go_pos(pos);
103 llRezObject(CONTROL_OBJECT,pos,ZERO_VECTOR,rot,CHANNEL | (i & 0xFF) );
104 }
105 go_pos(p);
106 gDiskNum = 0;
107 rez_disk(gDiskNum);
108 return;
109 }
110 if(id == "#add_control#")
111 {
112 gAnnounceFinish = FALSE;
113 vector p = llGetPos();
114 gRezState = 0;
115 list details = llGetObjectDetails(llList2Key(gControlPoints,-1),[OBJECT_POS,OBJECT_ROT" title="View Definition" class="tooltip">OBJECT_ROT]);
116 vector pos = llList2Vector(details,0);
117 rotation rot = llList2Rot(details,1);
118 if(pos == ZERO_VECTOR) return;
119 pos += llRot2Up(rot);
120 ++CONTROL_POINTS;
121 go_pos(pos);
122 llRezObject(CONTROL_OBJECT,pos,ZERO_VECTOR,rot,CHANNEL | (CONTROL_POINTS-1 & 0xFF) );
123 go_pos(p);
124 }
125 if( id == "#remove_control#" )
126 {
127 if(llGetListLength(gControlPoints) > 2)
128 {
129 key k = llList2Key(gControlPoints,-1);
130 if(llKey2Name(k) == "") return;
131 --CONTROL_POINTS;
132 --gRezed;
133 gControlPoints = llDeleteSubList(gControlPoints,-1,-1);
134 llRegionSay(CHANNEL,"#ctrl#"+llList2CSV(gControlPoints));
135 }
136 }
137 }
139 {
140 ++gRezed;
141 if(gRezState == 0)
142 {
143 gControlPoints =(gControlPoints=[])+gControlPoints+[k];
144 if( (gRezed-1) % 3 == 0 ) gAnchorPoints += k;
145 if( llGetListLength(gControlPoints) == CONTROL_POINTS ) gRezState = 1;
146 }
147 if( gRezed == CONTROL_POINTS )
148 {
149 llRegionSay(CHANNEL,"#ctrl#"+llList2CSV(gControlPoints));
150 llSleep(.20);
151 llRegionSay(CHANNEL,"#anchors#"+llList2CSV(gAnchorPoints));
152 }
153 if(gRezState == 1)
154 {
155 if(!rez_disk(++gDiskNum))
156 {
157 gRezState = 2;
158 }
159 }
160 if( gRezed >= (CONTROL_POINTS + INTERP_POINTS) )
161 {
162 gRezed = 0;
163 llSetText("",ZERO_VECTOR,0.0);
164 llRegionSay(CHANNEL,"#ctrl#"+llList2CSV(gControlPoints));
165 if(gAnnounceFinish) llMessageLinked(LINK_THIS,0,"","#rez_fin#");
166 }
167 }
168 }

SL_Sculpt_to_PHP_script

control.lsl

Category: Sculpt
By : Falados Kapuskas
Created: 2012-09-18 Edited: 2012-09-18
Worlds: Second Life

1 integer CHANNEL_MASK = 0xFFFFFF00;
2 integer CONTROL_POINT_MASK = 0xFF;
3 integer BROADCAST_CHANNEL;
4 integer CONTROL_POINT_NUM;
5 integer ACCESS_LEVEL;
6
7 integer MAX_CONTROL_POINTS;
8 integer MAX_INTER_POINTS;
9
10 integer gListenHandle;
11 integer gPointType;
12
13 //Shoot a beam of particles from one node to the next
14 particleBeam(key target)
15 {
16 if( target)
25 PSYS_SRC_BURST_RADIUS,0.000000,
26 PSYS_SRC_ANGLE_BEGIN,0.000000,
28 PSYS_PART_START_COLOR,<1.000000, 1.000000, 1.000000>,
29 PSYS_PART_START_ALPHA,1.000000,
30 PSYS_PART_START_SCALE,<0.050000, 0.100000, 0.000000>,
31 PSYS_SRC_TEXTURE,"5748decc-f629-461c-9a36-a35a221fe21f",
32 PSYS_PART_MAX_AGE,1.000000,
35 ]);
37 }
38 processRootCommands(string message)
39 {
40 if( llSubStringIndex(message,"#ctrl#") == 0 )
41 {
42 list parameters = llCSV2List( llGetSubString(message,6,-1));
43 MAX_CONTROL_POINTS = llGetListLength(parameters);
44 CONTROL_POINT_NUM = llListFindList(parameters,[(string)llGetKey()]);
45 if( CONTROL_POINT_NUM == -1) llDie();
46 if(CONTROL_POINT_NUM == 0 || CONTROL_POINT_NUM == MAX_CONTROL_POINTS-1 || gPointType == 1)
47 {
48 state anchor_point_loop;
49 } else {
50 state control_point_loop;
51 }
52 }
53 if( llSubStringIndex(message,"#setup#") == 0)
54 {
55 list l = llCSV2List(llGetSubString(message,7,-1));
56 ACCESS_LEVEL = (integer)llList2String(l,1);
57 }
58 if( llSubStringIndex(message,"#anchors#") == 0)
59 {
60 list parameters = llCSV2List( llGetSubString(message,9,-1));
61 integer anchor = llListFindList(parameters,[(string)llGetKey()]);
62 if(CONTROL_POINT_NUM == 0 || CONTROL_POINT_NUM == MAX_CONTROL_POINTS-1 || anchor != -1)
63 {
64 state anchor_point_loop;
65 } else {
66 state control_point_loop;
67 }
68 }
69 if( message == "#die#") { llDie(); }
70 }
71
72 //Get Access Allowed/Denited
73 integer has_access(key agent)
74 {
75 //Everyone has access
76 if(ACCESS_LEVEL == 0) return TRUE;
77 else
78 //Owner has access
79 if(ACCESS_LEVEL == 2)
80 {
81 return agent == llGetOwner();
82 }
83 else
84 //Group has access
85 if(ACCESS_LEVEL == 1)
86 {
87 return llSameGroup(agent);
88 }
89 //Failed
90 return FALSE;
91 }
92
93 default
94 {
96 {
97 BROADCAST_CHANNEL = (i & CHANNEL_MASK);
98 gListenHandle = llListen(BROADCAST_CHANNEL, "","","");
99 CONTROL_POINT_NUM = i & CONTROL_POINT_MASK;
100 llSetObjectDesc((string)CONTROL_POINT_NUM);
101 llSetText(llGetObjectDesc(),<1,1,1>,1.0);
102 }
103 listen(integer channel, string name, key id, string message)
104 {
105 processRootCommands(message);
106 }
108 {
109 integer i;
110 integer num;
111 for(i = 0; i < n; ++i)
112 {
114 if( num == CONTROL_POINT_NUM + 1)
115 {
116 particleBeam(llDetectedKey(i));
117 return;
118 }
119 }
120 }
121 }
122
123 state control_point_loop {
124 state_entry() { state control_point;}
125 }
126 state control_point
127 {
129 {
130 gPointType=0;
131 llSetColor(<1,0,0>,-1);
132 gListenHandle = llListen(BROADCAST_CHANNEL, "","","");
133 llSetObjectName("control");
134 }
135 listen(integer channel, string name, key id, string message)
136 {
137 processRootCommands(message);
138 }
140 {
141 if(!has_access(llDetectedKey(0))) return;
142 state anchor_point;
143 }
144 }
145 state anchor_point_loop {
146 state_entry() { state anchor_point;}
147 }
148 state anchor_point
149 {
151 {
152 gPointType=1;
153 llSetColor(<0,0,1>,-1);
154 gListenHandle = llListen(BROADCAST_CHANNEL, "","","");
155 llSetObjectName("anchor");
156 }
157 listen(integer channel, string name, key id, string message)
158 {
159 processRootCommands(message);
160 }
162 {
163 if(!has_access(llDetectedKey(0))) return;
164 if(CONTROL_POINT_NUM == 0 || CONTROL_POINT_NUM == MAX_CONTROL_POINTS-1)
165 {
166 return;
167 }
168 state control_point;
169
170
171 }
172 }

SL_Sculpt_to_PHP_script

encloser.lsl

Category: Sculpt
By : Falados Kapuskas
Created: 2012-09-18 Edited: 2012-09-18
Worlds: Second Life

1 integer CHANNEL_MASK = 0xFFFFFF00;
2 integer BROADCAST_CHANNEL;
3 integer ENCLOSE_CHANNEL;
4 integer ACCESS_LEVEL = 2;
5 integer ROWS;
6 integer gListenHandle_Enclose;
7 integer gScaleResponses;
8 vector gMax;
9 vector gMin;
10 float MAX_RESPONSE_TIME = 15.0;
11 key gOperator;
12 integer gAutoEnclose;
13 vector gScale;
14 vector gPos;
15
16 processRootCommands(string message)
17 {
18 if( llSubStringIndex(message,"#setup#") == 0)
19 {
20 list l = llCSV2List(llGetSubString(message,7,-1));
21 ACCESS_LEVEL = (integer)llList2String(l,1);
22 ROWS = (integer)llList2String(l,2);
23 }
24 if( message == "#die#" || message == "#enc-die#") { llDie(); }
25 }
26
27 //Get Access Allowed/Denited
28 integer has_access(key agent)
29 {
30 //Everyone has access
31 if(ACCESS_LEVEL == 0) return TRUE;
32 else
33 //Owner has access
34 if(ACCESS_LEVEL == 2)
35 {
36 return agent == llGetOwner();
37 }
38 else
39 //Group has access
40 if(ACCESS_LEVEL == 1)
41 {
42 return llSameGroup(agent);
43 }
44 //Failed
45 return FALSE;
46 }
47
48 minmax(vector vert) {
49 //Min
50 if( vert.x < gMin.x ) gMin.x = vert.x;
51 if( vert.y < gMin.y ) gMin.y = vert.y;
52 if( vert.z < gMin.z ) gMin.z = vert.z;
53
54 //Max
55 if( vert.x > gMax.x ) gMax.x = vert.x;
56 if( vert.y > gMax.y ) gMax.y = vert.y;
57 if( vert.z > gMax.z ) gMax.z = vert.z;
58 }
59
60 default
61 {
63 {
64 BROADCAST_CHANNEL = (i & CHANNEL_MASK);
65 llListen(BROADCAST_CHANNEL, "","","");
66 llSetText("Touch to Enclose",<1,1,1>,1.0);
67 llSetTimerEvent(0.1);
68 }
69 listen(integer channel, string name, key id, string message)
70 {
71 key k = llGetOwnerKey(id);
72 if(!has_access(k)) return;
73 if(channel == BROADCAST_CHANNEL)
74 {
75 processRootCommands(message);
76 return;
77 }
78 //Size Reponses
79 if( channel == ENCLOSE_CHANNEL )
80 {
82 ++gScaleResponses;
83 integer break = llSubStringIndex(message,"|");
84 if( break != -1 )
85 {
86 minmax((vector)llGetSubString(message,0,break-1));
87 minmax((vector)llGetSubString(message,break+1,-1));
88 } else {
89 minmax((vector)message);
90 }
91
92 if( gScaleResponses >= ROWS ) {
93
94 vector pos = (gMin + gMax)*0.5;
95 vector scale = <99,99,99>;
96 if( llFabs(gMax.x-pos.x) > llFabs(gMin.x-pos.x) ) scale.x = 2*llFabs(gMax.x-pos.x);
97 else scale.x = 2*llFabs(gMin.x-pos.x);
98
99 if( llFabs(gMax.y-pos.y) > llFabs(gMin.y-pos.y) ) scale.y = 2*llFabs(gMax.y-pos.y);
100 else scale.y = 2*llFabs(gMin.y-pos.y);
101
102 if( llFabs(gMax.z-pos.z) > llFabs(gMin.z-pos.z) ) scale.z = 2*llFabs(gMax.z-pos.z);
103 else scale.z = 2*llFabs(gMin.z-pos.z);
104
105 if( llVecMag(scale) < 17.4 ) {
106 gScale = scale*1.01;
107 gPos = pos;
108 llSetPos(gPos);
109 llSetScale(gScale);
111 llRegionSay(BROADCAST_CHANNEL,"#enc-size#" + llList2CSV([gPos,gScale]));
112 } else {
113 llInstantMessage(gOperator,"Enclose Failed - Size Too Big");
114 }
115 gAutoEnclose = FALSE;
116 llListenRemove(gListenHandle_Enclose);
117 llSetText("Touch to Enclose",<1,1,1>,1.0);
118 }
119 }
120
121 }
123 {
124 key k = llDetectedKey(0);
125 if(!has_access(k)) return;
126 gOperator = k;
127 llSetText("",<1,1,1>,1.0);
128 ENCLOSE_CHANNEL = (integer)(llFrand(-1e6) - 1e6);
129 gScaleResponses = 0;
130 llListenRemove(gListenHandle_Enclose);
131 gListenHandle_Enclose = llListen(ENCLOSE_CHANNEL,"","","");
132 gMin = <9999,9999,9999>;
133 gMax = <-9999,-9999,-9999>;
134 llShout(BROADCAST_CHANNEL,"#enclose#" + (string)ENCLOSE_CHANNEL);
135 gAutoEnclose = TRUE;
137 }
138 timer() {
139 if(llGetScale() != gScale || llGetPos() != gPos)
140 {
141 gScale = llGetScale();
142 gPos = llGetPos();
143 if(BROADCAST_CHANNEL != 0) llRegionSay(BROADCAST_CHANNEL,"#enc-size#" + llList2CSV([gPos,gScale]));
144 }
145 if( gAutoEnclose && llGetTime() > MAX_RESPONSE_TIME)
146 {
147 gAutoEnclose = FALSE;
148 llSetText("Touch to Enclose",<1,1,1>,1.0);
149 llListenRemove(gListenHandle_Enclose);
150 llInstantMessage(gOperator,"Enclose Failed - Not all nodes responded in time");
151 }
152 }
153 }

SL_Sculpt_to_PHP_script

mirror.lsl

Category: Sculpt
By : Falados Kapuskas
Created: 2012-09-18 Edited: 2012-09-18
Worlds: Second Life

1 integer CHANNEL_MASK = 0xFFFFFF00;
2 integer CONTROL_POINT_MASK = 0xFF;
3 integer BROADCAST_CHANNEL;
4 integer INPUT_CHANNEL = 9;
5 integer ACCESS_LEVEL = 2;
6 integer ROWS;
7
8 integer src_start;
9 integer src_end;
10 integer dst_start;
11 integer dst_end;
12
13 integer gListenHandle;
14 vector MAXIS = <1,0,0>;
15
16 processRootCommands(string message)
17 {
18 if( llSubStringIndex(message,"#setup#") == 0)
19 {
20 list l = llCSV2List(llGetSubString(message,7,-1));
21 ACCESS_LEVEL = (integer)llList2String(l,1);
22 ROWS = (integer)llList2String(l,2);
23 }
24 if( message == "#die#") { llDie(); }
25 }
26
27 //Get Access Allowed/Denited
28 integer has_access(key agent)
29 {
30 //Everyone has access
31 if(ACCESS_LEVEL == 0) return TRUE;
32 else
33 //Owner has access
34 if(ACCESS_LEVEL == 2)
35 {
36 return agent == llGetOwner();
37 }
38 else
39 //Group has access
40 if(ACCESS_LEVEL == 1)
41 {
42 return llSameGroup(agent);
43 }
44 //Failed
45 return FALSE;
46 }
47
48 dialog(key k)
49 {
50 llListenRemove(gListenHandle);
51 gListenHandle = llListen(INPUT_CHANNEL,"",k,"");
52 list buttons = ["Mirror","----","Cancel"];
53 if(MAXIS.x) buttons += ["X [x]"];
54 else buttons += ["X [ ]"];
55
56 if(MAXIS.y) buttons += ["Y [x]"];
57 else buttons += ["Y [ ]"];
58
59 if(MAXIS.z) buttons += ["Z [x]"];
60 else buttons += ["Z [ ]"];
61
62 llDialog(k,"Pick an action:",buttons,INPUT_CHANNEL);
63 }
64
65 integer startswith(string src, string pattern)
66 {
67 return llSubStringIndex(src,pattern) == 0;
68 }
69
70 mirror()
71 {
72 integer channel = (integer)(-1e6 - llFrand(1e6));
73 llShout(BROADCAST_CHANNEL,"#bezier-stop#");
74 llShout(BROADCAST_CHANNEL,"#mirror#" + llList2CSV([channel,MAXIS,src_start,src_end,dst_start,dst_end]));
75 }
76
77
78 integer parse_input(string message,key id)
79 {
80 list sides = llParseString2List(llToLower(llStringTrim(message,STRING_TRIM)),["to"],[]);
83 if( llGetListLength(sides) != 2 )
84 {
85 llInstantMessage(id,"Malformed Input");
86 return FALSE;
87 }
88
89 if( llGetListLength(src) == 1)
90 {
91 src_end = src_start = llList2Integer(src,0);
92 } else {
93 src_start = llList2Integer(src,0);
94 src_end = llList2Integer(src,1);
95 }
96
97 if( llGetListLength(dst) == 1)
98 {
99 dst_end = dst_start = llList2Integer(src,0);
100 } else {
101 dst_start = llList2Integer(dst,0);
102 dst_end = llList2Integer(dst,1);
103 }
104
105
106 if( src_end - src_start != dst_end-dst_start )
107 {
108 llInstantMessage(id,"Each side must be the same number of disks.");
109 return FALSE;
110 }
111
112 if( src_end >= ROWS || src_start >= ROWS || dst_start >= ROWS || dst_end >= ROWS)
113 {
114 llInstantMessage(id,"Disk out of range (Max = " + (string)ROWS + ")");
115 return FALSE;
116 }
117
118 return TRUE;
119 }
120
121 default
122 {
124 {
125 BROADCAST_CHANNEL = (i & CHANNEL_MASK);
126 llListen(BROADCAST_CHANNEL, "","","");
127 llSetText("Touch to Setup",<1,1,1>,1.0);
128 }
130 {
131 llSetText("",<1,1,1>,1.0);
132 }
133 listen(integer channel, string name, key id, string message)
134 {
135 key k = llGetOwnerKey(id);
136 if(!has_access(k)) return;
137 if(channel == BROADCAST_CHANNEL)
138 {
139 processRootCommands(message);
140 return;
141 }
142 if(channel == INPUT_CHANNEL)
143 {
144 llListenRemove(gListenHandle);
145 if(parse_input(message,id))
146 {
147 state active;
148 }
149 }
150
151 }
153 {
154 key k = llDetectedKey(0);
155 if(!has_access(k)) return;
156 llListenRemove(gListenHandle);
157 gListenHandle = llListen(INPUT_CHANNEL,"",k,"");
158 llInstantMessage(k,"Say the Disk Set on channel " + (string)INPUT_CHANNEL + "\n"
159 +"Example: '0-7 to 8-15' will mirror the disk set 0-7 onto 8-15\n");
160 }
161 }
162
163 state active
164 {
166 {
167 llListen(BROADCAST_CHANNEL, "","","");
168 llSetText((string)src_start + " - " + (string)src_end + " // " + (string)dst_start + " - " + (string)dst_end,<0,1,0>,1.0);
169 }
171 {
172 key k = llDetectedKey(0);
173 if(!has_access(k)) return;
174 dialog(k);
175 }
176 listen(integer channel, string name, key id, string message)
177 {
178 key k = llGetOwnerKey(id);
179 if(!has_access(k)) return;
180 if(channel == BROADCAST_CHANNEL)
181 {
182 processRootCommands(message);
183 }
184 if(channel == INPUT_CHANNEL)
185 {
186 llListenRemove(gListenHandle);
187 if( message != "Cancel" ) {
188 if(startswith(message,"X")) { MAXIS.x = !(integer)MAXIS.x; dialog(id);}
189 if(startswith(message,"Y")) { MAXIS.y = !(integer)MAXIS.y; dialog(id);}
190 if(startswith(message,"Z")) { MAXIS.z = !(integer)MAXIS.z; dialog(id);}
191 if(message == "Mirror") { mirror(); dialog(id);}
192 }
193 }
194 }
195 }

SL_Sculpt_to_PHP_script

nodetools.lsl

Category: Sculpt
By : Falados Kapuskas
Created: 2012-09-18 Edited: 2012-09-18
Worlds: Second Life

1 integer CHANNEL_MASK = 0xFFFFFF00;
2 integer CONTROL_POINT_MASK = 0xFF;
3 integer BROADCAST_CHANNEL;
4 integer INPUT_CHANNEL = 9;
5 integer ACCESS_LEVEL = 2;
6 integer ROWS;
7
8 integer src_start;
9 integer src_end;
10 integer dst_start;
11 integer dst_end;
12
13 integer gListenHandle;
14
15 list DIALOG = [
16 "[MIRROR] Mirror node data","MIRROR",
17 "[COPY] Copy node data","COPY",
18 "[SCALE] Scale disks evenly","SCALE",
19 "[ROT] Rotate disks evenly","ROT",
20 "[POS] Position disks evenly","POS",
21 "[NODE] Morph node data","NODE"
22 ];
23
24 processRootCommands(string message)
25 {
26 if( llSubStringIndex(message,"#setup#") == 0)
27 {
28 list l = llCSV2List(llGetSubString(message,7,-1));
29 ACCESS_LEVEL = (integer)llList2String(l,1);
30 ROWS = (integer)llList2String(l,2);
31 }
32 if( message == "#die#") { llDie(); }
33 }
34
35 //Get Access Allowed/Denited
36 integer has_access(key agent)
37 {
38 //Everyone has access
39 if(ACCESS_LEVEL == 0) return TRUE;
40 else
41 //Owner has access
42 if(ACCESS_LEVEL == 2)
43 {
44 return agent == llGetOwner();
45 }
46 else
47 //Group has access
48 if(ACCESS_LEVEL == 1)
49 {
50 return llSameGroup(agent);
51 }
52 //Failed
53 return FALSE;
54 }
55
56 dialog(string message, list dialog, key id)
57 {
58 llListenRemove(gListenHandle);
59 gListenHandle = llListen(INPUT_CHANNEL,"",id,"");
60 string m = message + llDumpList2String( llList2ListStrided(dialog,0,-1,2) , "\n");
61 llDialog(id,m,llList2ListStrided( llDeleteSubList(dialog,0,0), 0,-1,2),INPUT_CHANNEL);
62 }
63
64
65 integer startswith(string src, string pattern)
66 {
67 return llSubStringIndex(src,pattern) == 0;
68 }
69
70
71 mirror()
72 {
73 integer channel = (integer)(-1e6 - llFrand(1e6));
74 llShout(BROADCAST_CHANNEL,"#copy#" + llList2CSV([channel,src_start,src_end,dst_end,dst_start]));
75 }
76 copy()
77 {
78 integer channel = (integer)(-1e6 - llFrand(1e6));
79 llShout(BROADCAST_CHANNEL,"#copy#" + llList2CSV([channel,src_start,src_end,dst_start,dst_end]));
80 }
81 interp(integer type)
82 {
83 if(type != 3) llShout(BROADCAST_CHANNEL,"#bezier-stop#");
84 integer channel = (integer)(-1e6 - llFrand(1e6));
85 llShout(BROADCAST_CHANNEL,"#lerp#" + llList2CSV([channel,src_start,dst_end,type]));
86 }
87
88 integer parse_input(string message,key id)
89 {
90 list sides = llParseString2List(llToLower(llStringTrim(message,STRING_TRIM)),["to"],[]);
93 if( llGetListLength(sides) != 2 )
94 {
95 llInstantMessage(id,"Malformed Input");
96 return FALSE;
97 }
98
99 if( llGetListLength(src) == 1)
100 {
101 src_end = src_start = llList2Integer(sides,0);
102 } else {
103 src_start = llList2Integer(src,0);
104 src_end = llList2Integer(src,1);
105 }
106
107 if( llGetListLength(dst) == 1)
108 {
109 dst_end = dst_start = llList2Integer(sides,1);
110 } else {
111 dst_start = llList2Integer(dst,0);
112 dst_end = llList2Integer(dst,1);
113 }
114
115 if( src_end - src_start != dst_end-dst_start && llGetListLength(src) != 1)
116 {
117 llInstantMessage(id,"Start range must be either 1 or equal to end range");
118 return FALSE;
119 }
120
121 if( src_end >= ROWS || src_start >= ROWS || dst_start >= ROWS || dst_end >= ROWS)
122 {
123 llInstantMessage(id,"Disk out of range (Max = " + (string)ROWS + ")");
124 return FALSE;
125 }
126
127 return TRUE;
128 }
129
130 default
131 {
133 {
134 BROADCAST_CHANNEL = (i & CHANNEL_MASK);
135 llListen(BROADCAST_CHANNEL, "","","");
136 llSetText("Touch to Setup",<1,1,1>,1.0);
137 }
139 {
140 llSetText("",<1,1,1>,1.0);
141 }
142 listen(integer channel, string name, key id, string message)
143 {
144 key k = llGetOwnerKey(id);
145 if(!has_access(k)) return;
146 if(channel == BROADCAST_CHANNEL)
147 {
148 processRootCommands(message);
149 return;
150 }
151 if(channel == INPUT_CHANNEL)
152 {
153 llListenRemove(gListenHandle);
154 if(parse_input(message,id))
155 {
156 state active;
157 }
158 }
159
160 }
162 {
163 key k = llDetectedKey(0);
164 if(!has_access(k)) return;
165 llListenRemove(gListenHandle);
166 gListenHandle = llListen(INPUT_CHANNEL,"",k,"");
167 llInstantMessage(k,"Say the Disk Set on channel " + (string)INPUT_CHANNEL + "\n"
168 +"Example: '0-7 to 8-15' will mirror the disk set 0-7 onto 8-15\n");
169 }
170 }
171
172 state active
173 {
175 {
176 llListen(BROADCAST_CHANNEL, "","","");
177 string start = (string)src_start;
178 if(src_start != src_end) start += " - " + (string)src_end;
179 string end = (string)dst_start;
180 if(dst_start != dst_end) end += " - " + (string)dst_end;
181 INPUT_CHANNEL = (integer)(llFrand(1e6) + 1e6);
182 llSetText("Mirror/Copy " + start + " onto " + end + "\nInterpolate: " + (string)src_start + " to " + (string)dst_end,<0,1,0>,1.0);
183 }
185 {
186 key k = llDetectedKey(0);
187 if(!has_access(k)) return;
188 dialog("Pick an action:",DIALOG,k);
189 }
190 listen(integer channel, string name, key id, string message)
191 {
192 key k = llGetOwnerKey(id);
193 if(!has_access(k)) return;
194 if(channel == BROADCAST_CHANNEL)
195 {
196 processRootCommands(message);
197 }
198 if(channel == INPUT_CHANNEL)
199 {
200 llListenRemove(gListenHandle);
201 if( message != "Cancel" ) {
202 if(message == "COPY") { copy(); dialog("Pick an action:",DIALOG,id);}
203 if(message == "MIRROR") { mirror(); dialog("Pick an action:",DIALOG,id);}
204 if(message == "POS" ) { interp(0); dialog("Pick an action:",DIALOG,id); }
205 if(message == "SCALE" ) { interp(1); dialog("Pick an action:",DIALOG,id); }
206 if(message == "ROT" ) { interp(2); dialog("Pick an action:",DIALOG,id); }
207 if(message == "NODE" ) { interp(3); dialog("Pick an action:",DIALOG,id); }
208 }
209 }
210 }
211 }

SL_Sculpt_to_PHP_script

Sculpt: State Control.lsl

Category: Sculpt
By : Falados Kapuskas
Created: 2012-09-18 Edited: 2012-09-18
Worlds: Second Life

1 // This file is part of OpenLoft.
2 //
3 // OpenLoft is free software: you can redistribute it and/or modify
4 // it under the terms of the GNU General Public License as published by
5 // the Free Software Foundation, either version 3 of the License, or
6 // (at your option) any later version.
7 //
8 // OpenLoft is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 // GNU General Public License for more details.
12 //
13 // You should have received a copy of the GNU General Public License
14 // along with OpenLoft. If not, see <http://www.gnu.org/licenses/>.
15 //
16 // Authors: Falados Kapuskas, JoeTheCatboy Freelunch
17
18 //-- CONSTANTS --//
19 integer BROADCAST_CHANNEL;
20 integer CHANNEL_MASK = 0xFFFFFF00;
21 integer CONTROL_POINT_MASK = 0xFF;
22 integer ACCESS_LEVEL = 2; //2 = OWNER, 1 = GROUP, 0 = ALL
23 integer MY_ROW; //Set on_rez
24 integer ROWS;
25 integer COLUMNS;
26
27 //SculptTypes
28 integer SCULPT_POINT = 0;
29 integer SCULPT_DISK = 1;
30 integer SCULPT_NODE = 2;
31
32 //LinkCommands
33 integer COMMAND_CTYPE = -1;
34 integer COMMAND_RESET = -2;
35 integer COMMAND_SCALE = -3;
36 integer COMMAND_LERP = -4;
37 integer COMMAND_RENDER = -5;
38 integer COMMAND_CSECT = -6;
39 integer COMMAND_NODES = -7;
40 integer COMMAND_SPAWNSHAPE = -11;
41 integer COMMAND_SETUP_PARAMS= -12;
42
43 //-- GLOBALS --//
44 integer gListenHandle_Broadcast;
45 integer gListenHandle_Dialog;
46 vector gScale;
47 vector gLastColor;
48 integer gSculptType;
49 integer gSpawnShape;
50 integer gListenHandle;
51
52 //-- DIALOGS ---//
53 list DISK_DIALOG = [
54 "[EDIT] Edit the verticies","EDIT",
55 "[POINT] Transform into a point","POINT",
56 "[SQUARE] Transform into a square","SQUARE",
57 "[CIRCLE] Transform into a Circle","CIRCLE",
58 "[RESET] Reset modified verticies to default","RESET"
59 ];
60
61 list NODE_DIALOG = [
62 "[SAVE] - Save the custom verticies back into the shape","SAVE",
63 "[CSECT] Attempt to collide with physical objects penetrating the disk","CSECT"
64 ];
65
66 list POINT_DIALOG = [
67 "[EXPAND] Expand back into a disk","EXPAND"
68 ];
69
70
71 //-- FUNCTIONS --//
72
73 dialog(string message, list dialog, key id, integer channel)
74 {
75 llListenRemove(gListenHandle_Dialog);
76 gListenHandle_Dialog = llListen(channel,"",id,"");
77 string m = message + llDumpList2String( llList2ListStrided(dialog,0,-1,2) , "\n");
78 llDialog(id,m,llList2ListStrided( llDeleteSubList(dialog,0,0), 0,-1,2),channel);
79 }
80
81 //Get Access Allowed/Denited
82 integer has_access(key agent)
83 {
84 //Everyone has access
85 if(ACCESS_LEVEL == 0) return TRUE;
86 else
87 //Owner has access
88 if(ACCESS_LEVEL == 2)
89 {
90 return agent == llGetOwner();
91 }
92 else
93 //Group has access
94 if(ACCESS_LEVEL == 1)
95 {
96 return llSameGroup(agent);
97 }
98 //Failed
99 return FALSE;
100 }
101
102 //Get LOD Color
103 vector get_color(integer r)
104 {
105 integer ASPECT_R = 1;
106 if(ROWS < 32 && ROWS != 0)
107 {
108 ASPECT_R = 32/ROWS;
109 }
110 if( (r+2)*ASPECT_R % 4 == 0) return <1,0,0>;
111 if( (r+1)*ASPECT_R % 2 == 0) return <0,1,0>;
112 return <0,0,1>;
113 }
114
115 //Shoot a beam of particles from one disk center to the next
116 particleBeam(key target)
117 {
118 if( target)
128 PSYS_PART_START_SCALE,<1,1,1>*0.2,
134 PSYS_SRC_TEXTURE,"cce0f112-878f-4586-a2e2-a8f104bba271" //White Dot
135 ]);
137 }
138
139 //Sets the shape of the prim depending on the type
140 setShape(vector color)
141 {
142 vector DEFAULT_COLOR = get_color(MY_ROW);
143 gLastColor = color;
144 if( gSculptType == SCULPT_POINT ) {
146 PRIM_TYPE,PRIM_TYPE_SPHERE,PRIM_HOLE_DEFAULT ,<0,1,0>,0.0,<0,0,0>,<0,1,0>,
147 PRIM_TEXTURE,ALL_SIDES,"5748decc-f629-461c-9a36-a35a221fe21f", <1,1,0>, <0,0,0>, 0,
148 PRIM_COLOR,ALL_SIDES,DEFAULT_COLOR,1.0,
149 PRIM_SIZE,<.05,.05,.05>
150 ]);
151 }
152 if(gSpawnShape == 0 && gSculptType == SCULPT_DISK) {
154 PRIM_TYPE,PRIM_TYPE_CYLINDER, PRIM_HOLE_DEFAULT, <0,1,0>, 0.0, <0,0,0>, <1,1,0>, <0,0,0>,
155 PRIM_TEXTURE,0,"2cc5dcb6-595d-cbb9-e559-7d9e78270f2c", <1,1,0>, <0,0,0>, -PI_BY_TWO,
156 PRIM_TEXTURE,1,"5748decc-f629-461c-9a36-a35a221fe21f", <1,1,0>, <0,0,0>, 0,
157 PRIM_TEXTURE,2,"2cc5dcb6-595d-cbb9-e559-7d9e78270f2c", <1,1,0>, <0,0,0>, -PI_BY_TWO,
158 PRIM_COLOR,0,color,1.0,
159 PRIM_COLOR,1,DEFAULT_COLOR,1.0,
160 PRIM_COLOR,2,color*.5,1.0,
161 PRIM_SIZE,gScale
162 ]);
163 }
164 if(gSpawnShape == 1 || gSculptType == SCULPT_NODE) {
166 PRIM_TYPE,PRIM_TYPE_BOX,PRIM_HOLE_DEFAULT,<0, 1, 0>, 0, <0, 0, 0>, <1, 1, 0>, <0, 0, 0>,
167 PRIM_TEXTURE,0,"2cc5dcb6-595d-cbb9-e559-7d9e78270f2c", <1, 1, 0>, <0, 0, 0>, -PI_BY_TWO,
168 PRIM_TEXTURE,1,"5748decc-f629-461c-9a36-a35a221fe21f", <1, 1, 0>, <0, 0, 0>, 0,
169 PRIM_TEXTURE,2,"5748decc-f629-461c-9a36-a35a221fe21f", <1, 1, 0>, <0, 0, 0>, 0,
170 PRIM_TEXTURE,3,"5748decc-f629-461c-9a36-a35a221fe21f", <1, 1, 0>, <0, 0, 0>, 0,
171 PRIM_TEXTURE,4,"5748decc-f629-461c-9a36-a35a221fe21f", <1, 1, 0>, <0, 0, 0>, 0,
172 PRIM_TEXTURE,5,"2cc5dcb6-595d-cbb9-e559-7d9e78270f2c", <1, 1, 0>, <0, 0, 0>, -PI_BY_TWO,
173 PRIM_COLOR,0,color, .9,
174 PRIM_COLOR,1,DEFAULT_COLOR, .9,
175 PRIM_COLOR,2,DEFAULT_COLOR, .9,
176 PRIM_COLOR,3,DEFAULT_COLOR, .9,
177 PRIM_COLOR,4,DEFAULT_COLOR, .9,
178 PRIM_COLOR,5,color*.5, .9,
179 PRIM_SIZE,gScale
180 ]);
181 }
182 }
183
184 list params(string command, string message)
185 {
186 if(llStringLength(command) == llStringLength(message)) return [];
187 return llCSV2List(llGetSubString(message,llStringLength(command),-1));
188 }
189
190 integer handleRootCommand(string message) {
191 integer s = gSculptType;
192 list params;
193 if( message == "#die#") { llDie(); }
194 if( llSubStringIndex(message,"#die#") == 0)
195 {
196 params = params("#die#",message);
197 if( MY_ROW == llList2Integer(params,0) ) llDie();
198 }
199 if(parse_setup_string(message)) return s;
200 if( llSubStringIndex(message,"#lerp#") == 0)
201 {
202 llMessageLinked(LINK_THIS,COMMAND_LERP,llList2CSV(params("#lerp#",message)),"#lerp#");
203 }
204 if( llSubStringIndex(message,"#render#") == 0 ) { llMessageLinked(LINK_THIS,COMMAND_RENDER,llGetSubString(message,8,-1),""); }
205 if( message == "#show#" ) { llSetAlpha(1.0,ALL_SIDES); }
206 if( message == "#hide#" ) { llSetAlpha(0.0,ALL_SIDES); }
207 if( llSubStringIndex(message,"#enclose#") == 0) { llMessageLinked(LINK_THIS,COMMAND_SCALE,llGetSubString(message,9,-1),""); }
208 return s;
209 }
210
211 integer parse_setup_string(string message)
212 {
213 if( llSubStringIndex(message,"#setup#") == 0)
214 {
215 list l = llCSV2List(llGetSubString(message,7,-1));
216 COLUMNS = (integer)llList2String(l,0);
217 ACCESS_LEVEL = (integer)llList2String(l,1);
218 ROWS = (integer)llList2String(l,2);
219 return TRUE;
220 }
221 return FALSE;
222 }
223
224 //-- STATES --//
225
226 default
227 {
228 on_rez(integer param)
229 {
230 if(!param) return;
231 BROADCAST_CHANNEL = (param & CHANNEL_MASK);
232 gListenHandle = llListen(BROADCAST_CHANNEL, "","","");
233 MY_ROW = param & CONTROL_POINT_MASK;
234
235 gSculptType = SCULPT_DISK;
236 gScale = <0.5,0.5,0.05>;
237 llSetObjectName("sculpt:" + (string)MY_ROW);
238 setShape(<1,1,1>);
239 llListen(BROADCAST_CHANNEL,"","","");
240 }
241 state_entry() {
242 gSculptType = SCULPT_DISK;
243 if( gScale != ZERO_VECTOR) setShape(<1,1,1>);
244 }
245 listen( integer channel, string name, key id, string message )
246 {
247 if( !has_access(llGetOwnerKey(id)) ) return;
248 //Establishes Link between the loft-root and this disk
249 if(channel == BROADCAST_CHANNEL)
250 {
251 if(parse_setup_string(message))
252 {
253 state link_disks;
254 }
255 }
256 }
257 }
258
259 //Links a particle beam between the disks
260 state link_disks {
261 state_entry() {
262 //ROW 32 *should* trigger no_sensor
263 llSensor("sculpt:" + (string)(MY_ROW+1),"",SCRIPTED,10.0,TWO_PI);
264 }
265 sensor(integer total_number)
266 {
267 particleBeam(llDetectedKey(0));
268 if(gSculptType == SCULPT_POINT) state point;
269 else state disk;
270 }
271 no_sensor() {
272 if(gSculptType == SCULPT_POINT) state point;
273 else state disk;
274 }
275 }
276
277 //Handles Actions in the POINT state
278
279 state point {
280 state_entry() {
281 gSculptType=SCULPT_POINT;
282 setShape(ZERO_VECTOR);
283 llMessageLinked(LINK_THIS,COMMAND_CTYPE,(string)SCULPT_POINT,"");
284 llListen(BROADCAST_CHANNEL,"","","");
285 }
286 listen( integer channel, string name, key id, string message)
287 {
288 if( channel == BROADCAST_CHANNEL ) {
289 integer i = handleRootCommand(message);
290 if( i != gSculptType ) {
291 if( i == SCULPT_NODE ) state nodes;
292 if( i == SCULPT_POINT ) state point;
293 }
294 return;
295 }
296 llListenRemove(gListenHandle_Dialog);
297 if( message == "EXPAND" ) {
298 state disk;
299 }
300 }
302 if( !has_access(llDetectedKey(0)) ) return;
303 if( llGetLinkNumber() == 0) { //Not Linked
304 integer a = (integer)llFrand(-100000);
305 dialog("Pick an action for Row " + (string)MY_ROW + "\n",POINT_DIALOG,llDetectedKey(0),a);
306 }
307 }
308 link_message(integer sender_number, integer num, string str, key id)
309 {
310 if( (string)id == "recolor" ) {
311 setShape((vector)str);
312 }
313 }
314 }
315 state disk {
316 state_entry() {
317 llListen(BROADCAST_CHANNEL,"","","");
318 gSculptType=SCULPT_DISK;
319 setShape(<1,1,1>);
320 llMessageLinked(LINK_THIS,COMMAND_CTYPE,(string)SCULPT_DISK,"");
321 }
323 {
324 gScale = llGetScale();
325 }
327 if( !has_access(llDetectedKey(0)) ) return;
328 if( llGetLinkNumber() == 0) { //Not Linked
329 integer a = (integer)llFrand(-100000);
330 dialog("Pick an action for Row " + (string)MY_ROW + "\n",DISK_DIALOG,llDetectedKey(0),a);
331 }
332 }
333 listen( integer channel, string name, key id, string message)
334 {
335 if( channel == BROADCAST_CHANNEL ) {
336 integer i = handleRootCommand(message);
337 if( i != gSculptType ) {
338 if( i == SCULPT_NODE ) state nodes;
339 if( i == SCULPT_POINT ) state point;
340 }
341 return;
342 }
343 llListenRemove(gListenHandle_Dialog);
344 if( message == "EDIT" ) {
345 state nodes;
346 }
347 if( message == "POINT" ) {
348 state point;
349 }
350 if( message == "RESET" ) {
351 llMessageLinked(LINK_THIS, COMMAND_RESET,"","");
352 }
353 if( message == "SQUARE")
354 {
355 gSpawnShape = 1;
356 llMessageLinked(LINK_SET,COMMAND_SPAWNSHAPE,(string)gSpawnShape,"");
357 setShape(gLastColor);
358 }
359 if( message == "CIRCLE")
360 {
361 gSpawnShape = 0;
362 llMessageLinked(LINK_SET,COMMAND_SPAWNSHAPE,(string)gSpawnShape,"");
363 setShape(gLastColor);
364 }
365 }
366 link_message(integer sender_number, integer num, string str, key id)
367 {
368 if( (string)id == "recolor" ) {
369 gScale = llGetScale();
370 setShape((vector)str);
371 }
372 }
373 }
374
375 //Handles actions for the NODE state
376 //Will Revert back to DISK if anything happens
377 state nodes {
378 state_entry() {
379 gSculptType=SCULPT_NODE;
380 setShape(<1,1,1>);
381 llMessageLinked(LINK_THIS,COMMAND_CTYPE,(string)SCULPT_NODE,"");
382 llListen(BROADCAST_CHANNEL,"","","");
383 }
385 if( !has_access(llDetectedKey(0)) ) return;
386 if( llGetLinkNumber() == 0) { //Not Linked
387 integer a = (integer)llFrand(-100000);
388 dialog("Pick an action for Row " + (string)MY_ROW + "\n",NODE_DIALOG,llDetectedKey(0),a);
389 }
390 }
392 {
393 gScale = llGetScale();
394 }
395 //Node Actions
396 listen( integer channel, string name, key id, string message)
397 {
398 if( channel == BROADCAST_CHANNEL ) {
399 integer i = handleRootCommand(message);
400 if( i != gSculptType ) {
401 if( i == SCULPT_NODE ) state nodes;
402 if( i == SCULPT_POINT ) state point;
403 }
404 return;
405 }
406 llListenRemove(gListenHandle_Dialog);
407 if( message == "SAVE" ) {
408 state disk;
409 }
410 if( message == "CSECT" ) {
411 llMessageLinked(LINK_SET,COMMAND_CSECT,"","");
412 }
413 }
414
415 link_message( integer send_num, integer num, string str, key id)
416 {
417 if( (string)id == "recolor" ) {
418 gScale = llGetScale();
419 setShape((vector)str);
420 }
421 if( num == -5 ) {
422 if( str == "disk" ) {
423 state disk;
424 }
425 }
426 }
427 //Collapse All Children if this becomes ROOT
428 //If they have verticies outside of the disk, they
429 //are instantly attached
430 changed( integer i )
431 {
433 llMessageLinked(LINK_ALL_OTHERS, -5, "disk","");
434 state disk;
435 }
436 }
437 }

SL_Sculpt_to_PHP_script

Sculpt: Node Control.lsl

Category: Sculpt
By : Falados Kapuskas
Created: 2012-09-18 Edited: 2012-09-18
Worlds: Second Life

1 // This file is part of OpenLoft.
2 //
3 // OpenLoft is free software: you can redistribute it and/or modify
4 // it under the terms of the GNU General Public License as published by
5 // the Free Software Foundation, either version 3 of the License, or
6 // (at your option) any later version.
7 //
8 // OpenLoft is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 // GNU General Public License for more details.
12 //
13 // You should have received a copy of the GNU General Public License
14 // along with OpenLoft. If not, see <http://www.gnu.org/licenses/>.
15 //
16 // Authors: Falados Kapuskas, JoeTheCatboy Freelunch
17
18 //-- CONSTANTS --//
19 integer BROADCAST_CHANNEL;
20 integer NODE_CHANNEL;
21 integer CHANNEL_MASK = 0xFFFFFF00;
22 integer CONTROL_POINT_MASK = 0xFF;
23 integer LERP_CHANNEL;
24 integer ENCLOSE_CHANNEL = -1;
25 integer MY_ROW; //Set on_rez
26 integer COLUMNS = 32;
27 integer ROWS = 32;
28 integer ACCESS_LEVEL = 2;
29 //Actions
30 integer SPAWN_NODES = 0;
31 integer ATTACH_VERTS = 1;
32 integer SEND_NODES = 2;
33 integer RESET_VERTS = 3;
34 integer SEND_SCALE = 4;
35 //SculptTypes
36 integer SCULPT_POINT = 0;
37 integer SCULPT_DISK = 1;
38 integer SCULPT_NODE = 2;
39 //LinkCommands
40 integer COMMAND_CTYPE = -1;
41 integer COMMAND_RESET = -2;
42 integer COMMAND_SCALE = -3;
43 integer COMMAND_LERP = -4;
44 integer COMMAND_RENDER = -5;
45 integer COMMAND_CSECT = -6;
46 integer COMMAND_NODES = -7;
47 integer COMMAND_INTERP = -8;
48 integer COMMAND_COPY = -9;
49 integer COMMAND_SENDNODES = -10;
50 integer COMMAND_SPAWNSHAPE = -11;
51 integer COMMAND_SETUP_PARAMS= -12;
52
53 //-- GLOBALS --//
54 vector gScale;
55 vector gPosition;
56 rotation gRotation;
57 list gRezedNodes;
58 list gNodeInfo=[];
59 integer gSculptType;
60 integer gSpawnShape=0;
61 integer gListenHandle;
62 integer gListenHandle_Lerp;
63 integer gListenHandle_Copy;
64
65 //For Interpolation
66 vector gRootScale;
67 rotation gRootRot;
68 list gRootNodes;
69
70 //-- FUNCTIONS --//
71
72 // Performs actions using a common status notifier
73 performAction(integer action) {
74 vector color = llGetColor(0);
75 llMessageLinked(LINK_THIS,0,"<1,1,0>","recolor");
76 gPosition = llGetPos();
77 gRotation = llGetRot();
78 gScale = llGetScale();
79 if( action == SPAWN_NODES )
80 {
81 llSetText("Spawning Nodes\n"+(string)MY_ROW,<1,1,0>,1);
82 spawnNodes();
83 }
84 if( action == ATTACH_VERTS )
85 {
86 llSetText("Attaching Verticies\n"+(string)MY_ROW,<1,1,0>,1);
87 gNodeInfo = [];
88 storeNodeInfo();
89 rescale();
90 gNodeInfo = [];
91 gPosition = llGetPos();
92 gScale = llGetScale();
93 announce_nodes();
94 }
95 if( action == SEND_NODES )
96 {
97 llSetText("Sending Nodes\n"+(string)MY_ROW,<1,1,0>,1);
98 sendNodes();
99 }
100 if( action == RESET_VERTS )
101 {
102 llSetText("Resetting Verticies\n"+(string)MY_ROW,<1,1,0>,1);
103 gNodeInfo = [];
104 announce_nodes();
105 }
106 if( action == SEND_SCALE )
107 {
108 llSetText("Sending Scale Information\n"+(string)MY_ROW,<1,1,0>,1);
109 sendScaleInfo();
110 }
111 llMessageLinked(LINK_THIS,0,(string)color,"recolor");
112 llSetText("",<0,0,1>,1);
113 }
114
115 vector get_node_offset(integer i, integer formula)
116 {
117 if(!formula && gNodeInfo != [])
118 {
119 return (vector)llList2String(gNodeInfo,i);
120 }
121 float t = (float)i/COLUMNS;
122 if(gSpawnShape == 0) //CIRCLE
123 {
124 t *= TWO_PI;
125 return <llCos(t),llSin(t),0>;
126 }else
127 if(gSpawnShape == 1) //BO
128 X {
129 return <
130 .25 - llFabs(t-0) + llFabs(t-.25) + llFabs(t-.5) - llFabs(t-.75),
131 .25 - llFabs(t-.25) + llFabs(t-.5) + llFabs(t-.75) - llFabs(t-1),0>*4;
132
133 }
134 return ZERO_VECTOR;
135 }
136
137 integer rez_node(integer i)
138 {
139 if(i >= COLUMNS) return FALSE;
140 vector offset;
142 integer f = llGetListLength(gNodeInfo) != COLUMNS;
143 if(gSpawnShape==0)
144 {
145 offset = get_node_offset(i,f);
146 rot = llEuler2Rot( <0,0,1>* (float)i/COLUMNS*TWO_PI);
147 }
148 llRezObject("node",unpackNode(offset),ZERO_VECTOR,rot*gRotation, NODE_CHANNEL | (i & CONTROL_POINT_MASK) );
149 return TRUE;
150 }
151 //Announces nodes within the prim
152 announce_nodes()
153 {
154 if( gSculptType != SCULPT_POINT) {
155 if(gNodeInfo == [])
156 {
157 gPosition = llGetPos();
158 gRotation = llGetRot();
159 gScale = llGetScale();
160 if( gSculptType == SCULPT_NODE) storeNodeInfo();
161 if( gSculptType == SCULPT_DISK) resetVerts();
162 }
163 llMessageLinked(LINK_THIS,COMMAND_NODES,llList2CSV(gNodeInfo),"");
164 } else {
166 }
167 }
168 // Spawns the individual nodes that can be moved around
169 integer spawnNodes(){
170 gRezedNodes = [];
171 gPosition = llGetPos();
172 gRotation = llGetRot();
173 gScale = llGetScale();
174 return rez_node(0);
175 }
176
177 // Resets the verticies back into a disk
178 resetVerts()
179 {
180 integer i;
181 gNodeInfo = [];
182 float t;
183 vector offset;
184 for( i = 0; i < COLUMNS; ++i) {
185 gNodeInfo = (gNodeInfo = []) + gNodeInfo + get_node_offset(i,TRUE);
186 }
187 }
188
189 // Applys the new position, rotation, and gScale information to normalized data
190 vector unpackNode(vector node) {
191 node.x *= (gScale.x/2);
192 node.y *= (gScale.y/2);
193 return node * gRotation+gPosition;
194 }
195
196 // Removes all relative information, thereby normalizing the data
197 vector packNode(vector node) {
198 node -= gPosition;
199 node /= gRotation;
200 node.x /= (gScale.x/2);
201 node.y /= (gScale.y/2);
202 return node;
203 }
204
205 // Retrieves and normalizes all individual nodes, storing them in the dumplist
206 storeNodeInfo() {
207 gNodeInfo = [];
208 integer MAX = llGetListLength(gRezedNodes);
209 integer i;
210 for( i = 0; i < MAX; ++i)
211 {
212 gNodeInfo = (gNodeInfo = []) + gNodeInfo +
213 packNode(llList2Vector(llGetObjectDetails(llList2Key(gRezedNodes,i),[OBJECT_POS]),0));
214 }
215 }
216
217 // Sends nodes to the server for processing
218 sendNodes(){
219 string r = (string)MY_ROW;
220 if( gSculptType == SCULPT_POINT ) { llMessageLinked(LINK_THIS,COMMAND_SENDNODES,(string)llGetPos(),r); return; }
221 if( gNodeInfo == []) resetVerts();
222 integer i;
223 integer MAX = llGetListLength(gNodeInfo);
224 string dump;
225 for( i = 0; i < MAX; ++i) {
226 dump += (string)( unpackNode((vector)llList2String(gNodeInfo,i)) );
227 if( i < MAX-1 ) dump += ",";
228 }
229 llMessageLinked(LINK_THIS,COMMAND_SENDNODES,dump,r);
230 }
231
232 //Get extreme points
233 list getExtrema()
234 {
235
236 integer i;
237 integer MAX = llGetListLength(gNodeInfo);
238 vector v;
239 vector max = <1,1,1>*-9999;
240 vector min = <1,1,1>*9999;
241 for( i = 0; i < MAX; ++i) {
242 if(gRezedNodes == [])
243 v = unpackNode(llList2Vector(gNodeInfo,i));
244 else
246 if( v.x > max.x ) max.x = v.x;
247 if( v.y > max.y ) max.y = v.y;
248 if( v.z > max.z ) max.z = v.z;
249
250 if( v.x < min.x ) min.x = v.x;
251 if( v.y < min.y ) min.y = v.y;
252 if( v.z < min.z ) min.z = v.z;
253 }
254 return [min,max];
255 }
256
257 //Rescale the box based on extrema
258 rescale()
259 {
260 list minmax = getExtrema();
261 vector min = llList2Vector(minmax,0);
262 vector max = llList2Vector(minmax,1);
263 vector center = (min + max)*0.5;
264 vector scale = <0,0,0.05>;
265
266 if( llFabs(max.x-center.x) > llFabs(min.x-center.x) ) scale.x = 2*llFabs(max.x-center.x);
267 else scale.x = 2*llFabs(min.x-center.x);
268
269 if( llFabs(max.y-center.y) > llFabs(min.y-center.y) ) scale.y = 2*llFabs(max.y-center.y);
270 else scale.y = 2*llFabs(min.y-center.y);
271
272 llSetPos(center);
273 llSetScale(scale);
274 }
275
276 // Announces the extreme points, used for scaling the bounding box
277 sendScaleInfo() {
278 llSleep(llFrand(3.0));
279 if( gSculptType == SCULPT_POINT ) {
280 llShout(ENCLOSE_CHANNEL,(string)llGetPos());
281 return;
282 }
283 list d;
284 if( gNodeInfo == [] ) {
285 vector p = llGetPos();
286 rotation r = llGetRot();
288 d = ( d=[]) + [llList2Vector(d,0)*r + p,llList2Vector(d,1)*r + p];
289 } else {
290 d = getExtrema();
291 }
292 llShout(ENCLOSE_CHANNEL,llList2String(d,0) + "|" + llList2String(d,1));
293 }
294
295 //Hashes the color using a simple hashing function
296 vector getColorHash()
297 {
298 integer i;
299 integer MAX = llGetListLength(gNodeInfo);
301 for( i = 0; i < MAX; ++i) {
302 v += ((vector)llList2String(gNodeInfo,i));
303 }
304 v.x = llFabs(v.x);
305 v.y = llFabs(v.y);
306 v.z = llFabs(v.z);
307 if(v == ZERO_VECTOR) v = <1,1,1>;
308 return llVecNorm(v);
309 }
310
311 integer parse_setup_string(string message)
312 {
313 if( llSubStringIndex(message,"#setup#") == 0)
314 {
315 list l = llCSV2List(llGetSubString(message,7,-1));
316 if(COLUMNS != (integer)llList2String(l,0) )
317 {
318 COLUMNS = (integer)llList2String(l,0);
319 performAction(RESET_VERTS);
320 }
321 ACCESS_LEVEL = (integer)llList2String(l,1);
322 ROWS = (integer)llList2String(l,2);
323 return TRUE;
324 }
325 return FALSE;
326 }
327
328 //-- STATES --//
329
330 default
331 {
332 on_rez(integer param)
333 {
334 if(!param) return;
335 NODE_CHANNEL = (integer)(llFrand(-1e6) - 1e6) & CHANNEL_MASK;
336 BROADCAST_CHANNEL = (param & CHANNEL_MASK);
337 gListenHandle = llListen(BROADCAST_CHANNEL, "","","");
338 MY_ROW = param & CONTROL_POINT_MASK;
339 gSculptType = SCULPT_DISK;
340 gRezedNodes = [];
341 announce_nodes();
342 llSetText("",<1,1,1>,1);
343 }
344 listen(integer channel, string name, key id, string message)
345 {
346 parse_setup_string(message);
347 }
348 link_message( integer send_num, integer num, string str, key id)
349 {
350 if( num == COMMAND_CTYPE) {
351 integer new = (integer)str;
352 if( new == gSculptType) return;
353 if( new == SCULPT_NODE ) {
354 //Stop Bezier Interpolation for this disk
355 llMessageLinked(LINK_THIS,0,"","#bez_stop#");
356 //Unpack Nodes
357 performAction(SPAWN_NODES);
358 }
359 if( new == SCULPT_DISK )
360 {
361 performAction(ATTACH_VERTS);
362 if( gNodeInfo != [] )
363 {
364 llMessageLinked(LINK_THIS,0,(string)getColorHash(),"recolor");
365 }
366 gRezedNodes = [];
367 llShout(NODE_CHANNEL,"#die#");
368 }
369 if( new == SCULPT_POINT) { gRezedNodes = []; gNodeInfo = []; }
370 gSculptType = new;
371 }
372
373 if( num == COMMAND_RESET ) {
374 if( gSculptType == SCULPT_DISK ) {
375 performAction(RESET_VERTS);
376 llMessageLinked(LINK_THIS,0,"<1,1,1>","recolor");
377 }
378 }
379 if( num == COMMAND_RENDER ) {
380 if( gSculptType == SCULPT_NODE ) performAction(ATTACH_VERTS);
381 performAction(SEND_NODES);
382 }
383 if( num == COMMAND_SCALE ) {
384 ENCLOSE_CHANNEL = (integer)str;
385 if( gSculptType == SCULPT_NODE) performAction(ATTACH_VERTS);
386 performAction(SEND_SCALE);
387 }
388 if( num == COMMAND_CSECT ) {
389 if( gSculptType == SCULPT_NODE) llShout(NODE_CHANNEL,"#csect#");
390 }
391 if( num == COMMAND_COPY)
392 {
393 gNodeInfo = llCSV2List(str);
394 llMessageLinked(LINK_THIS,COMMAND_NODES,str,"");
395 llMessageLinked(LINK_THIS,0,(string)getColorHash(),"recolor");
396 }
397 if( num == COMMAND_INTERP)
398 {
399 gNodeInfo = [];
400 list tailnodes = llCSV2List((string)id);
401 float p;
402 list headnodes = llParseString2List(str,["|"],[]);
403 p = llList2Float(headnodes,0);
404 headnodes = llCSV2List(llList2String(headnodes,1));
405 integer i = 0;
406 integer len = llGetListLength(tailnodes);
407 for( i = 0; i < len; ++i)
408 {
409 gNodeInfo = (gNodeInfo = []) + gNodeInfo + [(vector)llList2String(headnodes,i)*(1.0-p) + (vector)llList2String(tailnodes,i)*p];
410 }
411 tailnodes = [];
412 gRootNodes = [];
413 llMessageLinked(LINK_THIS,COMMAND_NODES,llList2CSV(gNodeInfo),"");
414 llMessageLinked(LINK_THIS,0,(string)getColorHash(),"recolor");
415 }
416 if(num == COMMAND_SPAWNSHAPE)
417 {
418 gSpawnShape = (integer)str;
419 performAction(RESET_VERTS);
420 llMessageLinked(LINK_THIS,0,"<1,1,1>","recolor");
421 }
422 }
423 object_rez(key id)
424 {
425 gRezedNodes = (gRezedNodes = []) + gRezedNodes + id;
426 integer i = llGetListLength(gRezedNodes);
427 if(!rez_node(i))
428 {
429 llShout(NODE_CHANNEL,llList2CSV(["al",ACCESS_LEVEL,"rw",ROWS,"cl",COLUMNS,"bc",BROADCAST_CHANNEL]));
430 }
431 }
432 }

SL_Sculpt_to_PHP_script

Sculpt: HTTP Sender.lsl

Category: Sculpt
By : Falados Kapuskas
Created: 2012-09-18 Edited: 2012-09-18
Worlds: Second Life

1 // This file is part of OpenLoft.
2 //
3 // OpenLoft is free software: you can redistribute it and/or modify
4 // it under the terms of the GNU General Public License as published by
5 // the Free Software Foundation, either version 3 of the License, or
6 // (at your option) any later version.
7 //
8 // OpenLoft is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 // GNU General Public License for more details.
12 //
13 // You should have received a copy of the GNU General Public License
14 // along with OpenLoft. If not, see <http://www.gnu.org/licenses/>.
15 //
16 // Authors: Falados Kapuskas, JoeTheCatboy Freelunch
17
18 //-- CONSTANTS --//
19 integer DISPLAY_CHANNEL = -131415;
20 integer DATA_CHANNEL = 0;
21 integer BROADCAST_CHANNEL;
22 integer CHANNEL_MASK = 0xFFFFFF00;
23 integer CONTROL_POINT_MASK = 0xFF;
24 integer SUCCESS_CHANNEL = -2001;
25 integer ERROR_CHANNEL = -2002;
26 string URL;
27 list HTTP_PARAMS = [
28 HTTP_METHOD, "POST",
29 HTTP_MIMETYPE,"application/x-www-form-urlencoded"
30 ];
31
32 integer MY_ROW; //Set on_rez
33
34 //-- GLOBALS --//
35 key gHTTPRequest;
36 integer gListenHandle_DISPLAY;
37 //-- FUNCTIONS --//
38
39 sendNodes(integer row, string data) {
40
41 if(DATA_CHANNEL != 0)
42 {
43 list l = llCSV2List(data);
44 if( llGetListLength(l) > 1) {
45 llSay(DATA_CHANNEL,llList2CSV([0]+llList2List(l,0,15)));
46 llSay(DATA_CHANNEL,llList2CSV([16]+llList2List(l,16,-1)));
47 } else {
48 llSay(DATA_CHANNEL,data);
49 }
50 } else {
51 MY_ROW = row;
52 string request = "action=upload&row=" + (string)row;
53 gHTTPRequest = llHTTPRequest(URL + request,HTTP_PARAMS,"verts=" + llEscapeURL(data));
54 }
55 }
56
57 //-- STATES --//
58
59 default {
60 on_rez(integer param) {
61 if(!param) return;
62 BROADCAST_CHANNEL = (param & CHANNEL_MASK);
63 MY_ROW = param & CONTROL_POINT_MASK;
64 gListenHandle_DISPLAY = llListen(DISPLAY_CHANNEL,"","","");
65 }
66 listen(integer channel, string name, key id, string msg) {
67 if( llGetOwner() != llGetOwnerKey(id)) return;
68 if(channel == DISPLAY_CHANNEL)
69 {
70 DATA_CHANNEL = (integer)msg;
71 }
72 }
73
74 link_message( integer send_num, integer num, string str, key id) {
75 if( num == -5)
76 {
77 URL = str;
78 }
79 if( num == -10) {
80 if( llSubStringIndex(URL,"http") == 0 ) {
81 sendNodes(MY_ROW , str);
82 }
83 }
84 }
85 http_response(key request_id, integer status, list meta, string message)
86 {
87 if( request_id == gHTTPRequest) {
88 if( llStringTrim(message,STRING_TRIM) == "") {
89 llShout(SUCCESS_CHANNEL,(string)MY_ROW);
90 } else {
91 llShout(ERROR_CHANNEL,(string)MY_ROW + ": " + message);
92 }
93 }
94 }
95 }

SL_Sculpt_to_PHP_script

Sculpt: Data transfer.lsl

Category: Sculpt
By : Falados Kapuskas
Created: 2012-09-18 Edited: 2012-09-18
Worlds: Second Life

1 //LinkCommands
2 integer COMMAND_NODES = -7;
3 integer COMMAND_INTERP = -8;
4 integer COMMAND_LERP = -4;
5 integer COMMAND_COPY = -9;
6
7 integer BROADCAST_CHANNEL;
8 integer COPY_CHANNEL;
9 integer MIRROR_CHANNEL;
10
11 integer MY_ROW;
12 string gNodeData;
13
14 integer gListenHandle;
15 integer gStreamsComplete;
16
17 //Linear Interpolation
18 integer LERP_CHANNEL;
19 integer gLerpStart;
20 integer gLerpEnd;
21 integer gLerpType;
22 list gPacketsReceived_H;
23 list gPacketsReceived_T;
24
25 //Copy
26 integer gCopyNumber;
27 list gPacketsReceived_C;
28
29 //Mirror
30 integer gMirrorNumber;
31 vector gMirrorPos = ZERO_VECTOR;
32 rotation gMirrorRot = ZERO_ROTATION;
33 vector MIRROR_AXIS;
34
35
36 rotation slerp( rotation a, rotation b, float f ) {
37 float angleBetween = llAngleBetween(a, b);
38 if( angleBetween > PI )
39 angleBetween = angleBetween - TWO_PI;
40 return a*llAxisAngle2Rot(llRot2Axis(b/a)*a, angleBetween*f);
41 }
42
43 lerp(list params)
44 {
45 llListenRemove(gListenHandle);
46 LERP_CHANNEL = llList2Integer(params,0);
47 gLerpStart = llList2Integer(params,1);
48 gLerpEnd = llList2Integer(params,2);
49 gLerpType = llList2Integer(params,3);
50 if(MY_ROW == gLerpStart || MY_ROW == gLerpEnd)
51 {
52 string p = "H" + (string)gLerpType;
53 if(MY_ROW == gLerpEnd) p = "T" + (string)gLerpType;
54 string send;
55 if(gLerpType == 0)
56 {
57 send = (string)llGetPos();
58 }else if(gLerpType == 1)
59 {
60 send = (string)llGetScale();
61 } else if(gLerpType == 2)
62 {
63 send = (string)llGetRot();
64 } else if(gLerpType == 3)
65 {
66 send = gNodeData;
67 }
68 integer packets = llCeil(llStringLength(send) / 1000.0);
69 integer max_packets = packets;
70 string header;
71 integer sent = 0;
72 llSleep(1.0); //Give them time to listen
73 while(packets > 0)
74 {
75 header = p + "|" + (string)sent + "/" + (string)max_packets + "|";
76 if(packets == 1) {
77 llRegionSay(LERP_CHANNEL,header + send);
78 } else {
79 llRegionSay(LERP_CHANNEL,header + llGetSubString(send,0,999));
80 send = llGetSubString(send,1000,-1);
81 }
82 llSleep(0.25);
83 --packets;
84 ++sent;
85 }
86 } else if(MY_ROW > gLerpStart && MY_ROW < gLerpEnd) {
87 gPacketsReceived_H = gPacketsReceived_T = [];
88 gStreamsComplete = 0;
89 gListenHandle = llListen(LERP_CHANNEL,"","","");
90 }
91 }
92
93 mirror(list params, key id)
94 {
95 llListenRemove(gListenHandle);
96 gMirrorNumber = -1;
97 list d = llGetObjectDetails(id,[OBJECT_POS,OBJECT_ROT" title="View Definition" class="tooltip">OBJECT_ROT]);
98 gMirrorPos = llList2Vector(d,0);
99 gMirrorRot = llList2Rot(d,1);
100 MIRROR_CHANNEL = llList2Integer(params,0);
101 MIRROR_AXIS = (vector)llList2String(params,1);
102 list range_from = llList2List(params,2,3);
103 list range_to = llList2List(params,4,5);
104 integer len_from = (integer)llFabs(llList2Integer(range_from,-1) - llList2Integer(range_from,0));
105 integer len_to = (integer)llFabs(llList2Integer(range_to,-1) - llList2Integer(range_to,0));
106 integer SEND = FALSE;
107 integer LISTEN = FALSE;
108 //Can't Mirror uneven stuff
109 if(len_from != len_to)
110 {
111 return;
112 }
113
114 integer SRC_START = llList2Integer(range_from,0);
115 integer SRC_END = llList2Integer(range_from,-1);
116 integer DST_START = llList2Integer(range_to,0);
117 integer DST_END = llList2Integer(range_to,-1);
118
119 if(DST_START > DST_END)
120 {
121 SEND = DST_START;
122 DST_START = DST_END;
123 DST_END = SEND;
124 }
125 if(SRC_START > SRC_END)
126 {
127 SEND = SRC_START;
128 SRC_START = SRC_END;
129 SRC_END = SEND;
130 }
131 SEND = FALSE;
132
133 if( MY_ROW >= SRC_START && MY_ROW <= SRC_END ) SEND = TRUE;
134 else if( MY_ROW >= DST_START && MY_ROW <= DST_END) {
135 LISTEN = TRUE;
136 }
137
138 if(LISTEN)
139 {
140 float t = 0;
141 if(len_to != 0) t = (MY_ROW - DST_START)/(llFabs(len_to));
142 gMirrorNumber = SRC_START;
143 if(len_from != 0)
144 {
145 gMirrorNumber += llRound(((float)len_from)*(1.0-t));
146 }
147 gListenHandle = llListen(MIRROR_CHANNEL,"","","");
148 return;
149 }
150 if(SEND) {
151 llSleep(1); //Give them time to listen?
152 string header = (string)MY_ROW + "|";
153 string send = llList2CSV([llGetPos(),llGetRot()]);
154 llRegionSay(MIRROR_CHANNEL,header + send);
155 }
156 }
157
158 copy(list params)
159 {
160 llListenRemove(gListenHandle);
161 gCopyNumber = -1;
162 gPacketsReceived_C = [];
163 COPY_CHANNEL = llList2Integer(params,0);
164 list range_from = llList2List(params,1,2);
165 list range_to = llList2List(params,3,4);
166 integer len_from = llList2Integer(range_from,-1) - llList2Integer(range_from,0);
167 integer len_to = llList2Integer(range_to,-1) - llList2Integer(range_to,0);
168 integer SEND = FALSE;
169 integer LISTEN = FALSE;
170 integer MIRROR = 0;
171
172 //Copy Only
173 if(llFabs(len_from) != llFabs(len_to))
174 {
175 //Cant copy x1-x2 to y1-y2 when they are not 1-to-1
176 //It's ambiguous. We can copy 1 disk to several disks
177 if((integer)llFabs(len_from) != 1) return;
178 }
179
180 //Check for the mirror case (Exclusive or)
181 if( len_from < 0 && len_to > 0)
182 {
183 len_from = -len_from;
184 MIRROR = 1;
185 }
186 if( len_to < 0 && len_from > 0 )
187 {
188 len_to = -len_to;
189 MIRROR = 1;
190 }
191
192 integer SRC_START = llList2Integer(range_from,0);
193 integer SRC_END = llList2Integer(range_from,-1);
194 integer DST_START = llList2Integer(range_to,0);
195 integer DST_END = llList2Integer(range_to,-1);
196
197 if(DST_START > DST_END)
198 {
199 SEND = DST_START;
200 DST_START = DST_END;
201 DST_END = SEND;
202 }
203 if(SRC_START > SRC_END)
204 {
205 SEND = SRC_START;
206 SRC_START = SRC_END;
207 SRC_END = SEND;
208 }
209 SEND = FALSE;
210
211 if( MY_ROW >= SRC_START && MY_ROW <= SRC_END ) SEND = TRUE;
212 else if( MY_ROW >= DST_START && MY_ROW <= DST_END) {
213 LISTEN = TRUE;
214 }
215
216 if(LISTEN)
217 {
218 float t = 0;
219 if(len_to != 0) t = (MY_ROW - DST_START)/(llFabs(len_to));
220 if(len_from == 0) {
221 gCopyNumber = SRC_START;
222 } else {
223 gCopyNumber = SRC_START + llFloor(llFabs(len_from)*llFabs((float)MIRROR-t));
224 }
225 gListenHandle = llListen(COPY_CHANNEL,"","","");
226 return;
227 }
228 if(SEND) {
229 llSleep(1); //Give them time to listen?
230 string send = gNodeData;
231 integer packets = llCeil(llStringLength(send) / 1000.0);
232 integer max_packets = packets;
233 string header;
234 integer sent = 0;
235 while(packets > 0)
236 {
237 llSleep(0.25);
238 header = (string)MY_ROW + "|" + (string)sent + "/" + (string)max_packets + "|";
239 if(packets == 1) {
240 llRegionSay(COPY_CHANNEL,header + send);
241 } else {
242 llRegionSay(COPY_CHANNEL,header + llGetSubString(send,0,999));
243 send = llGetSubString(send,1000,-1);
244 }
245 --packets;
246 ++sent;
247 }
248 }
249 }
250
251 link_commands(integer sn, integer i, string str, key id)
252 {
253 if( i == COMMAND_NODES && str != "")
254 {
255 gNodeData = str;
256 }
257 }
258
259 default
260 {
261 on_rez(integer param)
262 {
263 if(!param) return;
264 MY_ROW = param & 0xFF;
265 BROADCAST_CHANNEL = param & 0xFFFFFF00;
266 llListen(BROADCAST_CHANNEL,"","","");
267 }
268 link_message(integer sn, integer i, string str, key id)
269 {
270 link_commands(sn,i,str,id);
271 }
272 listen(integer channel, string name, key id, string message)
273 {
274 if(channel == BROADCAST_CHANNEL)
275 {
276 if(llSubStringIndex(message,"#lerp#") == 0)
277 {
278 lerp(llCSV2List(llGetSubString(message,6,-1)));
279 }
280 if(llSubStringIndex(message,"#copy#") == 0)
281 {
282 copy(llCSV2List(llGetSubString(message,6,-1)));
283 }
284 if(llSubStringIndex(message,"#mirror#") == 0)
285 {
286 mirror(llCSV2List(llGetSubString(message,8,-1)),id);
287 }
288 return;
289 }
290 if(channel == MIRROR_CHANNEL)
291 {
292 list params = llParseString2List(message,["|"],[]);
293 list details = llCSV2List(llList2String(params,1));
294 integer MIR_NUM = llList2Integer(params,0);
295 if(gMirrorNumber != MIR_NUM) {
296 return;
297 }
298 vector pos = (vector)llList2String(details,0);
299 rotation rot = (rotation)llList2String(details,1);
300 vector relPos = (pos - gMirrorPos)/gMirrorRot;
301 rotation relRot = rot/gMirrorRot;
302 vector relRot2 = llRot2Euler(relRot);
303
304 if(MIRROR_AXIS.x) // If X Axis option is set...
305 {
306 relPos.x *= -1;
307 relRot2.z *= -1;
308 relRot2.y *= -1;
309 relRot2 = llRot2Euler(<-0, -1, -0, 0> * llEuler2Rot(relRot2));
310 }
311 if(MIRROR_AXIS.y) // If Y Axis option is set...
312 {
313 relPos.y *= -1;
314 relRot2.x *= -1;
315 relRot2.z *= -1;
316 relRot2 = llRot2Euler(<1, -0, -0, 0> * llEuler2Rot(relRot2));
317 }
318 if(MIRROR_AXIS.z) // If Z Axis option is set...
319 {
320 relPos.z *= -1;
321 relRot2.x *= -1;
322 relRot2.y *= -1;
323 }
324 relRot = llEuler2Rot(relRot2);
325 pos = gMirrorPos + (relPos*gMirrorRot);
326 rot = relRot * gMirrorRot;
328 }
329 if(channel == COPY_CHANNEL)
330 {
331 list params = llParseString2List(message,["|"],[]);
332 list packets = llParseString2List(llList2String(params,1),["/"],[]);
333 integer COPY_NUM = llList2Integer(params,0);
334 if(gCopyNumber != COPY_NUM) {
335 return;
336 }
337 gPacketsReceived_C = (gPacketsReceived_C = []) + gPacketsReceived_C + [llList2Integer(packets,0),llList2String(params,2)];
338 if( llGetListLength(gPacketsReceived_C) / 2 == llList2Integer(packets,1))
339 {
340 packets = [];
341 params = [];
342 llMessageLinked(LINK_THIS,0,"","#bez_stop#");
343 llMessageLinked(LINK_THIS,COMMAND_COPY,
344 llDumpList2String(llList2ListStrided(llDeleteSubList(llListSort(gPacketsReceived_C,2,TRUE),0,0),0,-1,2),"")
345 ,"");
346 list details = llGetObjectDetails(id,[OBJECT_ROT" title="View Definition" class="tooltip">OBJECT_ROT]);
347 list bbox = llGetBoundingBox(id);
348 vector scale = llList2Vector(bbox,1)-llList2Vector(bbox,0);
349 scale.z = 0.05;
351 gCopyNumber = -1;
352 gPacketsReceived_C = [];
353 llListenRemove(gListenHandle);
354 }
355 }
356 if(channel == LERP_CHANNEL)
357 {
358 list params = llParseString2List(message,["|"],[]);
359 list packets = llParseString2List(llList2String(params,1),["/"],[]);
360 integer IS_HEAD = (llGetSubString(llList2String(params,0),0,0) == "H");
361 gLerpType = (integer)(llGetSubString(llList2String(params,0),1,-1));
362 if(IS_HEAD)
363 {
364 gPacketsReceived_H += [llList2Integer(packets,0),llList2String(params,2)];
365 //Received All Packets
366 if( llGetListLength(gPacketsReceived_H) / 2 == llList2Integer(packets,1))
367 {
368 packets = [];
369 params = [];
370 ++gStreamsComplete;
371 }
372 } else {
373 gPacketsReceived_T += [llList2Integer(packets,1),llList2String(params,2)];
374 if( llGetListLength(gPacketsReceived_T) / 2 == llList2Integer(packets,1))
375 {
376 packets = [];
377 params = [];
378 ++gStreamsComplete;
379 }
380 }
381 //Both Packet Streams are done, interpolate now
382 if(gStreamsComplete >= 2)
383 {
384 string tdata = llDumpList2String((gPacketsReceived_H=[]) + llList2ListStrided(llDeleteSubList(llListSort(gPacketsReceived_H,2,TRUE),0,0),0,-1,2),"");
385 string hdata = llDumpList2String((gPacketsReceived_T=[]) + llList2ListStrided(llDeleteSubList(llListSort(gPacketsReceived_T,2,TRUE),0,0),0,-1,2),"");
386 float t = (MY_ROW - gLerpStart) / (float)(gLerpEnd - gLerpStart);
387 if(gLerpType == 0)
388 {
389 llSetPos(t * ((vector)hdata) + ((vector)tdata)*(1-t));
390 }else if(gLerpType == 1)
391 {
392 llSetScale(t * ((vector)hdata) + ((vector)tdata)*(1-t));
393 } else if(gLerpType == 2)
394 {
395 llSetRot(slerp((rotation)tdata,(rotation)hdata,t));
396 } else if(gLerpType == 3)
397 {
398 llMessageLinked(LINK_THIS,COMMAND_INTERP,(string)t + "|" + tdata,hdata);
399 }
400 llListenRemove(gListenHandle);
401 }
402 }
403 }
404 }

SL_Sculpt_to_PHP_script

Sculpt: Bezier.lsl

Category: Sculpt
By : Falados Kapuskas
Created: 2012-09-18 Edited: 2012-09-18
Worlds: Second Life

1 integer MAX_FACTORIAL = 20;
2 integer FACTORIAL_N = 0;
3 integer LAST_N=-1;
4
5 list control_keys;
6 list control_pos;
7 list control_scale;
8 list control_rot;
9 list anchors;
10 float t = 0.5;
11
12 vector START_POS;
13 key ORIGIN = NULL_KEY;
14 integer CHANNEL_MASK = 0xFFFFFF00;
15 integer CONTROL_POINT_MASK = 0xFF;
16 integer BROADCAST_CHANNEL;
17 integer CONTROL_POINT_NUM;
18 integer MY_NUM;
19 integer MAX_CONTROL_POINTS;
20 integer MAX_INTER_POINTS;
21 integer ANCHOR_POINTS;
22 integer gListenHandle;
23
24 get_control_points()
25 {
26 integer i;
27 integer num;
28 key k;
29 list bbox;
30 string name;
31 ANCHOR_POINTS = 0;
32 control_scale = [];
33 control_pos = [];
34 control_rot = [];
35 anchors = [];
36 for( i = 0; i < MAX_CONTROL_POINTS; ++i)
37 {
38 k = (key)llList2String(control_keys,i);
39 if( llKey2Name(k) == "")
40 {
41 jump continue;
42 }
44 control_pos = (control_pos = []) + control_pos + llGetObjectDetails(k,[OBJECT_POS]);
45 bbox = llGetBoundingBox(k);
46 control_scale = (control_scale = []) + control_scale + [llList2Vector(bbox,1)-llList2Vector(bbox,0)];
47 control_rot = (control_rot = []) + control_rot + llGetObjectDetails(k,[OBJECT_ROT" title="View Definition" class="tooltip">OBJECT_ROT]);
48 if( name == "anchor")
49 {
50 anchors += [i];
51 ++ANCHOR_POINTS;
52 }
53 @continue;
54 }
55 }
56
57 setOriginPos()
58 {
59 START_POS = llList2Vector(llGetObjectDetails(llList2Key(control_keys,0),[OBJECT_POS]),0);
60 }
61
62 // Factorial (!) function : n(n-1)(n-2)...(1)
63 integer factorial(integer n)
64 {
65 if( n == 0 || n == 1) return 1;
66 if( n > MAX_FACTORIAL)
67 {
68 llSay(DEBUG_CHANNEL,"Factorial size too big : " + (string)n + "\nLimited to " + (string)MAX_FACTORIAL);
69 return 1/0; //Error Out with MATH ERROR
70 }
71 return n * factorial(n-1);
72 }
73
74 // Mathematical nCr function = n! / (c! * (n-c)!)
75 integer nCr(integer n, integer c)
76 {
77 if(LAST_N != n || FACTORIAL_N == 0)
78 {
79 LAST_N = n;
80 FACTORIAL_N = factorial(n);
81 }
82 return FACTORIAL_N / ( factorial(c) * factorial(n-c) );
83 }
84
85 rotation slerp( rotation a, rotation b, float f ) {
86 float angleBetween = llAngleBetween(a, b);
87 if( angleBetween > PI )
88 angleBetween = angleBetween - TWO_PI;
89 return a*llAxisAngle2Rot(llRot2Axis(b/a)*a, angleBetween*f);
90 }
91
92
93 bezier()
94 {
95 if(control_keys == [] || MAX_CONTROL_POINTS <= 1) return;
96 get_control_points();
97 setOriginPos();
98 integer i;
99 integer start=0;
100 for(i = 0; i < ANCHOR_POINTS-1; ++i)
101 {
102 if( t >= llList2Float(anchors,i)/(MAX_CONTROL_POINTS-1) )
103 {
104 start = i;
105 }
106 }
107
108 i = llList2Integer(anchors,start);
109 integer j = llList2Integer(anchors,start+1);
110 integer n = llRound(MAX_INTER_POINTS*((j-i)/(float)(MAX_CONTROL_POINTS-1)))-1;
111 start = llRound(MAX_INTER_POINTS*(i/(float)(MAX_CONTROL_POINTS-1)));
112 if(start != 0)
113 {
114 --start;
115 ++n;
116 }
117 float tlocal;
118 if(n != 0) {
119 tlocal = (MY_NUM - start) / (float)(n);
120 if(tlocal>1) tlocal = 1;
121 if(tlocal<0) tlocal = 0;
122 } else {
123 if(MY_NUM-start == 0) tlocal = 0;
124 else tlocal = 1;
125 }
126 vector pos = ZERO_VECTOR;
127 vector scale = ZERO_VECTOR;
128 vector p;
129 float b;
130 n = j-i;
131 start = i;
132 for(i=0; i <= n; ++i)
133 {
134 b = nCr(n,i) * llPow(tlocal,i) * llPow(1.0-tlocal,n-i);
135 p = (llList2Vector(control_pos,start+i));
136 pos += b * p;
137 scale += b * (llList2Vector(control_scale,start+i));
138 }
139 vector s = llGetScale();
140 scale.z = s.z;
141 llSetPos(pos);
142 llSetScale(scale);
143 llSetRot(slerp(llList2Rot(control_rot,start),llList2Rot(control_rot,start+i-1),tlocal));
144
145 }
146
147 default {
149 {
150 state enabled;
151 }
152 }
153
154 state enabled
155 {
156 link_message(integer send_num, integer num, string str, key command)
157 {
158
159 if( command == "#bez_info#" )
160 {
161 FACTORIAL_N = 0;
162 list parameters = llCSV2List(str);
163 MAX_INTER_POINTS = llList2Integer(parameters,0);
164 MY_NUM = llList2Integer(parameters,1);
165 if(MAX_INTER_POINTS == 1) {
166 t = 1.0;
167 } else {
168 t = (float)MY_NUM/(MAX_INTER_POINTS-1);
169 }
170 control_keys = [];
171 llSetTimerEvent(0.0);
172 } else
173 if( command == "#bez_start#")
174 {
175 control_keys = llCSV2List(str);
176 MAX_CONTROL_POINTS = llGetListLength(control_keys);
177 llSetTimerEvent(1.0);
178 }
179 if( command == "#bez_stop#")
180 {
181 state default;
182 }
183 }
184 timer()
185 {
186 bezier();
187 }
189 {
191 }
192 }

SL_Sculpt_to_PHP_script

sculpt: Bezier Controller.lsl

Category: Sculpt
By : Falados Kapuskas
Created: 2012-09-18 Edited: 2012-09-18
Worlds: Second Life

1 // This file is part of OpenLoft.
2 //
3 // OpenLoft is free software: you can redistribute it and/or modify
4 // it under the terms of the GNU General Public License as published by
5 // the Free Software Foundation, either version 3 of the License, or
6 // (at your option) any later version.
7 //
8 // OpenLoft is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 // GNU General Public License for more details.
12 //
13 // You should have received a copy of the GNU General Public License
14 // along with OpenLoft. If not, see <http://www.gnu.org/licenses/>.
15 //
16 // Authors: Falados Kapuskas, JoeTheCatboy Freelunch
17
18 //-- CONSTANTS --//
19 integer BROADCAST_CHANNEL;
20 integer CHANNEL_MASK = 0xFFFFFF00;
21 integer CONTROL_POINT_MASK = 0xFF;
22 integer ACCESS_LEVEL = 2; //2 = OWNER, 1 = GROUP, 0 = ALL
23 integer MY_ROW; //Set on_rez
24 integer ROWS;
25 integer COLUMNS;
26 integer IS_ACTIVE = FALSE;
27
28 //LinkCommands
29 integer COMMAND_CTYPE = -1;
30 integer COMMAND_RESET = -2;
31 integer COMMAND_SCALE = -3;
32 integer COMMAND_VISIBLE = -4;
33 integer COMMAND_RENDER = -5;
34 integer COMMAND_CSECT = -6;
35 integer COMMAND_INTERP = -7;
36 integer COMMAND_SIZE = -8;
37 integer COMMAND_COPY = -9;
38 integer COMMAND_SENDNODES = -10;
39 integer COMMAND_SPAWNSHAPE = -11;
40 integer COMMAND_SETUP_PARAMS= -12;
41
42 string control_points;
43
44 //Globals
45 integer gListenHandle;
46 //-- FUNCTIONS --//
47
48 //Get Access Allowed/Denited
49 integer has_access(key agent)
50 {
51 //Everyone has access
52 if(ACCESS_LEVEL == 0) return TRUE;
53 else
54 //Owner has access
55 if(ACCESS_LEVEL == 2)
56 {
57 return agent == llGetOwner();
58 }
59 else
60 //Group has access
61 if(ACCESS_LEVEL == 1)
62 {
63 return llSameGroup(agent);
64 }
65 //Failed
66 return FALSE;
67 }
68
69 handleRootCommand(string message)
70 {
71 if(llSubStringIndex(message,"#ctrl#")==0)
72 {
73 control_points = llGetSubString(message,6,-1);
74 if(IS_ACTIVE)
75 {
76 llMessageLinked(LINK_THIS,0,llList2CSV([ROWS+1,MY_ROW]),"#bez_info#");
77 llMessageLinked(LINK_THIS,0,control_points,"#bez_start#");
78 }
79 }
80 if(message == "#bezier-start#")
81 {
82 llSetScriptState("bezier",TRUE);
83 }
84 if(message == "#bezier-stop#")
85 {
86 llMessageLinked(LINK_THIS,0,"","#bez_stop#");
87 }
88 }
89
90 integer parse_setup_string(string message)
91 {
92 if( llSubStringIndex(message,"#setup#") == 0)
93 {
94 list l = llCSV2List(llGetSubString(message,7,-1));
95 COLUMNS = (integer)llList2String(l,0);
96 ACCESS_LEVEL = (integer)llList2String(l,1);
97 ROWS = (integer)llList2String(l,2);
98 return TRUE;
99 }
100 return FALSE;
101 }
102
103 //-- STATES --//
104
105 default
106 {
108 {
109 BROADCAST_CHANNEL = (i & CHANNEL_MASK);
110 gListenHandle = llListen(BROADCAST_CHANNEL, "","","");
111 MY_ROW = i & CONTROL_POINT_MASK;
112 }
113 listen( integer channel, string name, key id, string message )
114 {
115 if( !has_access(llGetOwnerKey(id)) ) return;
116 handleRootCommand(message);
117 if(parse_setup_string(message))
118 {
119 state active;
120 }
121 }
122 }
123
124 state active
125 {
127 {
128 llListen(BROADCAST_CHANNEL,"","","");
129 IS_ACTIVE = TRUE;
130 llMessageLinked(LINK_THIS,0,llList2CSV([ROWS+1,MY_ROW]),"#bez_info#");
131 llMessageLinked(LINK_THIS,0,control_points,"#bez_start#");
132 }
133 listen( integer channel, string name, key id, string message )
134 {
135 if( !has_access(llGetOwnerKey(id)) ) return;
136 handleRootCommand(message);
137 }
138 }

SL_Sculpt_to_PHP_script

Node: Node.lsl

Category: Sculpt
By : Falados Kapuskas
Created: 2012-09-18 Edited: 2012-09-18
Worlds: Second Life

1 // This file is part of OpenLoft.
2 //
3 // OpenLoft is free software: you can redistribute it and/or modify
4 // it under the terms of the GNU General Public License as published by
5 // the Free Software Foundation, either version 3 of the License, or
6 // (at your option) any later version.
7 //
8 // OpenLoft is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 // GNU General Public License for more details.
12 //
13 // You should have received a copy of the GNU General Public License
14 // along with OpenLoft. If not, see <http://www.gnu.org/licenses/>.
15 //
16 // Authors: Falados Kapuskas, JoeTheCatboy Freelunch
17
18 //-- CONSTANTS --//
19 integer NODE_CHANNEL;
20 integer BROADCAST_CHANNEL;
21 integer CHANNEL_MASK = 0xFFFFFF00;
22 integer CONTROL_POINT_MASK = 0xFF;
23 integer COMM_CHANNEL = -2000;
24 integer SCALE_CHANNEL = -2003;
25 list NODE_SHAPE = [PRIM_TYPE,PRIM_TYPE_BOX,PRIM_HOLE_DEFAULT, <0,1,0>, 0.0, <0,0,0>, <1,1,0>, <0,0,0>];
26 list CSECT_SHAPE = [PRIM_TYPE,PRIM_TYPE_SPHERE,PRIM_HOLE_DEFAULT, <0,1,0>, 0.0, <0,0,0>, <0,1,0>];
27 integer COLUMN; //Set on_rez
28 integer ROW; //Set on_rez
29 integer RETRY_COUNT = 3;
30 float MOVE_STEP = 0.025; //Move this much every step
31 float MOVE_SEC = 0.35; //Move ever X seconds
32 integer ACCESS_LEVEL=2;
33 integer ROWS;
34 integer COLUMNS;
35 //-- GLOBALS --//
36 key gRootDisk;
37 float gTravelTime;
38 vector gRootPos;
39 integer gRetry;
40 vector gOldPosition;
41 integer gListenHandle_Node;
42 integer gListenHandle_Comm;
43 integer gListenHandle_Broadcast;
44
45 //Get Color based on divisibility by 4
46 vector get_color(integer r, integer c)
47 {
48 integer ASPECT_R = 1;
49 integer ASPECT_C = 1;
50 if(ROWS != 0) {
51 if( ROWS < 32)
52 {
53 ASPECT_R = 32/ROWS;
54 }
55 }
56 if(COLUMNS != 0)
57 {
58 if( COLUMNS < 32)
59 {
60 ASPECT_C = 32/COLUMNS;
61 }
62 }
63 if( (r+2)*ASPECT_R % 4 == 0 && (c+2)*ASPECT_C % 4 == 0 ) return <1,0,0>;
64 if( (r+1)*ASPECT_R % 2 == 0 && (c+1)*ASPECT_C % 2 == 0 ) return <0,1,0>;
65 return <0,0,1>;
66 }
67
68 //Shoot a beam of particles from one node to the next
69 particleBeam(key target)
70 {
71 if( target)
80 PSYS_SRC_BURST_RADIUS,0.000000,
81 PSYS_SRC_ANGLE_BEGIN,0.000000,
83 PSYS_PART_START_COLOR,<1.000000, 1.000000, 1.000000>,
84 PSYS_PART_START_ALPHA,1.000000,
85 PSYS_PART_START_SCALE,<0.050000, 0.100000, 0.000000>,
86 PSYS_SRC_TEXTURE,"5748decc-f629-461c-9a36-a35a221fe21f",
87 PSYS_PART_MAX_AGE,1.000000,
90 ]);
92 }
93
94 integer validCollision(key target,vector pos)
95 {
96 if( llKey2Name(target) == llGetObjectName() ) return FALSE;
97 if( llKey2Name(target) == "" ) return FALSE;
98 list l = llGetBoundingBox(target);
99 vector other_min = llList2Vector(l,0)+pos;
100 vector other_max = llList2Vector(l,1)+pos;
101 vector s = llGetScale();
102 vector p = llGetPos();
103 vector my_min = p - s*.5;
104 vector my_max = p + s*.5;
105
106 return ( my_min.x < other_max.x ) && ( my_max.x > other_min.x ) &&
107 ( my_min.y < other_max.y ) && ( my_max.y > other_min.y ) &&
108 ( my_min.z < other_max.z ) && ( my_max.z > other_min.z );
109 }
110
111 parse_disk_info(string message)
112 {
113 if(message == "#die#")
114 {
115 llDie();
116 return;
117 }
118 list params = llCSV2List(message);
119 string var;
120 string val;
121 while( params != [])
122 {
123 var = llList2String(params,0);
124 val = llList2String(params,1);
125 if(var == "al")
126 {
127 ACCESS_LEVEL = (integer)val;
128 }
129 if(var == "rw")
130 {
131 ROWS = (integer)val;
132 }
133 if(var == "cl")
134 {
135 COLUMNS = (integer)val;
136 }
137 if(var == "bc")
138 {
139 BROADCAST_CHANNEL = (integer)val;
140 llListenRemove(gListenHandle_Broadcast);
141 gListenHandle_Broadcast = llListen(BROADCAST_CHANNEL,"","","");
142 }
143 params = llDeleteSubList(params,0,1);
144 }
145 }
146
147 default
148 {
149
150 on_rez(integer param) {
151 if(!param) return;
152 NODE_CHANNEL = (param & CHANNEL_MASK);
153 gListenHandle_Node = llListen(NODE_CHANNEL, "","","");
154 COLUMN = param & CONTROL_POINT_MASK;
155 llSetTimerEvent(30.0);
156 }
157 listen(integer channel, string name, key id, string message)
158 {
159 if( llGetOwnerKey(id) != llGetOwner()) return;
160 parse_disk_info(message);
161 ROW = (integer)llGetSubString(name,llSubStringIndex(name,":")+1,-1);
162 llSetObjectName( "node:" + (string)ROW + "-" + (string)COLUMN );
163 gRootDisk = id;
164 state link_nodes;
165 }
166 timer() { llDie(); }
167 }
168
169 state link_nodes {
170 state_entry() {
171 llSleep(0.1);
172 llSensor( "node:" + (string)ROW + "-" + (string)((COLUMN + 1) % COLUMNS),"",SCRIPTED,10.0,TWO_PI);
173 }
174 sensor(integer i) {
175 particleBeam(llDetectedKey(0));
176 state active;
177 }
178 no_sensor()
179 {
180 state active;
181 }
182 }
183
184 state active {
185 on_rez(integer p) { llDie(); }
187 {
188 llSetScale(<1,1,1>*0.06);
189 llSetColor(get_color(ROW,COLUMN),ALL_SIDES);
190 llSetPrimitiveParams(NODE_SHAPE);
191 gListenHandle_Node = llListen(NODE_CHANNEL,"",gRootDisk,"");
192 gListenHandle_Broadcast = llListen(BROADCAST_CHANNEL,"","","");
193 gListenHandle_Comm = llListen(COMM_CHANNEL,"","","");
194 llSetTimerEvent(3.0);
195 }
196
197 listen(integer channel, string name, key id, string message)
198 {
199 if( llGetOwnerKey(id) != llGetOwner() ) return;
200
201 if( message == "#show#") llSetAlpha(1.0,ALL_SIDES);
202 if( message == "#hide#") llSetAlpha(0.0,ALL_SIDES);
203 if( message == "#csect#") {
204 gOldPosition = llGetPos();
205 gRetry = RETRY_COUNT;
206 state csect;
207 }
208 if( message == "#die#" )
209 {
210 llDie();
211 }
212 if( channel == NODE_CHANNEL )
213 {
214 parse_disk_info(message);
215 }
216 }
217 timer() {
218 if( llGetObjectMass(gRootDisk) == 0.0 ) llDie();
219 }
220 }
221
222 state csect
223 {
225 {
226 gListenHandle_Node = llListen(NODE_CHANNEL,"",gRootDisk,"");
227 gListenHandle_Broadcast = llListen(BROADCAST_CHANNEL,"","","");
228 gTravelTime = llVecMag(gRootPos - llGetPos())*MOVE_SEC/MOVE_STEP; //Avoid the nasty infinite loop by limiting the seek time
229 llSetScale(<1,1,1>*0.1);
231 llSetPrimitiveParams(CSECT_SHAPE);
232 llSetStatus(STATUS_PHANTOM,TRUE);
234 llSetTimerEvent(MOVE_SEC);
235 gRootPos = llList2Vector( llGetObjectDetails(gRootDisk,[OBJECT_POS]),0);
236 }
238 {
240 llSetStatus(STATUS_PHANTOM,TRUE);
241 }
242 listen(integer channel, string name, key id, string message)
243 {
244 if( llGetOwnerKey(id) != llGetOwner() ) return;
245 if( message == "#die#" )
246 {
247 llDie();
248 }
249 }
250 timer() {
251 vector p = llVecNorm(gRootPos - llGetPos());
252 llSetPos(llGetPos() + p*MOVE_STEP);
253 if( llVecMag(gRootPos - llGetPos()) <= MOVE_STEP * 2 || llGetTime() > gTravelTime*1.2 )
254 {
255 llSetPos(gOldPosition);
257 --gRetry;
258 if( gRetry <= 0) {
259 state active;
260 }
261 }
262 }
263 collision_end(integer total_number)
264 {
265 if(validCollision(llDetectedKey(0),llDetectedPos(0)))
266 state active;
267 }
268 collision_start(integer total_number)
269 {
270 if(validCollision(llDetectedKey(0),llDetectedPos(0)))
271 state active;
272 }
273 }

SL_Sculpt_to_PHP_script

Change Log

Category: Sculpt
By : Falados Kapuskas
Created: 2012-09-18 Edited: 2012-09-18
Worlds: Second Life

1 #summary Change Log for Open Loft
2 ==v2.0==
3 *Completely Redone*
4
5 * Fixed many bugs
6 * Support for Oblong Sculpts (eg: 16x64 , 8x128 , 4x256 )
7 * Removed Sculpt Preview (No longer works for oblong sculpts)
8 * Removed PolyRez
9 * Disks are positioned by Bezier Curves
10 * Can add/remove anchor/control points
11 * Bezier can be turned on/off with the menu buttons
12 * Changed Default Menu
13 * Extracted functions into duplicateable Tools
14 * Encloser Tool
15 * Mirror Tool
16 * Mirror position around and combination of x/y/z axes
17 * Copy Tool
18 * Copy ranges of disks onto other ranges
19 * Mirror ranges of disks onto other ranges
20 * Interpolate Scale / Position / Rotation / Node Data
21
22 ==v1.3==
23 * Added a work-around for image convolution (Smoothing functions) on PHP versions < 5.10
24
25 ==v1.2==
26 * Added Sculpt Preview
27 This object allows you to view and save your sculpty in-world without the assistance of a webserver
28 Rez the object next to your completed sculpture, press the green button at the top.
29 Now when you press RENDER, the sculpt preview object will draw the texture on the surface.
30 To save this texture, simply sit on the orb and configure your SNAPSHOP window.
31 You save this texture to your harddrive and play with it outside of SL, or upload it right away for 10L
32 ==v1.1==
33 * Added color to each node and row indicating their LOD.
34 * RED = LOD Low
35 * GREEN = LOD Medium
36 * BLUE = LOD High
37 * Increased the threshold that resets nodes when they are stuck trying to collide with a physical object
38 * Added utility script to make and object physical and keep it in place
39 * Fixed vertex2sculpt.php
40 It now creates the directories that it previously was missing
41 * Added reminder to replace the URL in the Open Loft Tool object
42 * Added reminder to ENCLOSE a sculpt before RENDER

SL_Sculpt_to_PHP_script

Physical - keep still

Category: Sculpt
By : Falados Kapuskas
Created: 2012-09-18 Edited: 2012-09-18
Worlds: Second Life

1 // This file is part of OpenLoft.
2 //
3 // OpenLoft is free software: you can redistribute it and/or modify
4 // it under the terms of the GNU General Public License as published by
5 // the Free Software Foundation, either version 3 of the License, or
6 // (at your option) any later version.
7 //
8 // OpenLoft is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 // GNU General Public License for more details.
12 //
13 // You should have received a copy of the GNU General Public License
14 // along with OpenLoft. If not, see <http://www.gnu.org/licenses/>.
15 //
16 // Authors: Falados Kapuskas, JoeTheCatboy Freelunch
17
18
19 //Makes the object physical
20 //And keeps it in place
21 vector pos;
22 rotation rot;
23 default
24 {
26 {
27 //Make Physical
29
30 //Save Position
31 pos = llGetPos();
32 rot = llGetRot();
33
34 llSetTimerEvent(0.05);
35 }
36 timer()
37 {
38 //Jitter
39 llApplyImpulse(<1,1,1>*0.001,TRUE);
40
41 //Keep In Place
42 llMoveToTarget(pos,0.1);
43 llRotLookAt(rot,100,0.1);
44 }
45 }

SL_Sculpt_to_PHP_script

Category: Sculpt
By : Falados Kapuskas
Created: 2012-09-18 Edited: 2012-09-18
Worlds: Second Life

1 Image of openloft

SL_Sculpt_to_PHP_script

func.gdbundle.php

Category: Sculpt
By : Falados Kapuskas
Created: 2012-09-18 Edited: 2012-09-18
Worlds: Second Life

1 <?php
2
3 /*
4 * Code taken from Imarty <http://code.google.com/p/imarty/
5 * Original Licence: GPL v2 <http://www.gnu.org/licenses/old-licenses/gpl-2.0.html>
6 * New License: GPL v3 <http://www.gnu.org/licenses/gpl-3.0.html>
7 */
8
9 //Here, it contains imageconvolution and imagefilter workaround
10 //these two functions only show up on PHP 5 and must be using bundled GD
11 //Well, even Imarty are not made for PHP4, not all servers uses bundled GD
12 //Like Ubuntu does come with PHP and GD, but there are not bundled.
13
14 if(!function_exists('imageconvolution')){
15 function imageconvolution($src, $filter, $filter_div, $offset){
16 if($src==NULL) {
17 return false;
18 }
19
20 $sx = imagesx($src);
21 $sy = imagesy($src);
22 $srcback = ImageCreateTrueColor ($sx, $sy);
23 ImageCopy($srcback, $src,0,0,0,0,$sx,$sy);
24
25 if($srcback==NULL){
26 return 0;
27 }
28
29 for ($y=0; $y<$sy; ++$y){
30 for($x=0; $x<$sx; ++$x){
31 $new_r = $new_g = $new_b = 0;
32 $alpha = imagecolorat($srcback, $pxl[0], $pxl[1]);
33 $new_a = $alpha >> 24;
34
35 for ($j=0; $j<3; ++$j) {
36 $yv = min(max($y - 1 + $j, 0), $sy - 1);
37 for ($i=0; $i<3; ++$i) {
38 $pxl = array(min(max($x - 1 + $i, 0), $sx - 1), $yv);
39 $rgb = imagecolorat($srcback, $pxl[0], $pxl[1]);
40 $new_r += (($rgb >> 16) & 0xFF) * $filter[$j][$i];
41 $new_g += (($rgb >> 8) & 0xFF) * $filter[$j][$i];
42 $new_b += ($rgb & 0xFF) * $filter[$j][$i];
43 }
44 }
45
46 $new_r = ($new_r/$filter_div)+$offset;
47 $new_g = ($new_g/$filter_div)+$offset;
48 $new_b = ($new_b/$filter_div)+$offset;
49
50 $new_r = ($new_r > 255)? 255 : (($new_r < 0)? 0:$new_r);
51 $new_g = ($new_g > 255)? 255 : (($new_g < 0)? 0:$new_g);
52 $new_b = ($new_b > 255)? 255 : (($new_b < 0)? 0:$new_b);
53
54 $new_pxl = ImageColorAllocateAlpha($src, (int)$new_r, (int)$new_g, (int)$new_b, $new_a);
55 if($new_pxl == -1) {
56 $new_pxl = ImageColorClosestAlpha($src, (int)$new_r, (int)$new_g, (int)$new_b, $new_a);
57 }
58 if(($y >= 0) && ($y < $sy)) {
59 imagesetpixel($src, $x, $y, $new_pxl);
60 }
61 }
62 }
63 imagedestroy($srcback);
64 return true;
65 }
66 }
67
68 if(!function_exists('imagefilter')){
69 function imagefilter($source, $var, $arg1 = null, $arg2 = null, $arg3 = null){
70 #define('IMAGE_FILTER_NEGATE',0);
71 #define('IMAGE_FILTER_GRAYSCALE',0);
72 #define('IMAGE_FILTER_BRIGHTNESS',2);
73 #define('IMAGE_FILTER_CONTRAST',3);
74 #define('IMAGE_FILTER_COLORIZE',4);
75 #define('IMAGE_FILTER_EDGEDETECT',5);
76 #define('IMAGE_FILTER_EMBOSS',6);
77 #define('IMAGE_FILTER_GAUSSIAN_BLUR',7);
78 #define('IMAGE_FILTER_SELECTIVE_BLUR',8);
79 #define('IMAGE_FILTER_MEAN_REMOVAL',9);
80 #define('IMAGE_FILTER_SMOOTH',10);
81 $max_y = imagesy($source);
82 $max_x = imagesx($source);
83 switch ($var){
84 case 0:
85 $y = 0;
86 while($y<$max_y) {
87 $x = 0;
88 while($x<$max_x){
89 $rgb = imagecolorat($source,$x,$y);
90 $r = 255 - (($rgb >> 16) & 0xFF);
91 $g = 255 - (($rgb >> 8) & 0xFF);
92 $b = 255 - ($rgb & 0xFF);
93 $a = $rgb >> 24;
94 $new_pxl = imagecolorallocatealpha($source, $r, $g, $b, $a);
95 if($new_pxl == false){
96 $new_pxl = imagecolorclosestalpha($source, $r, $g, $b, $a);
97 }
98 imagesetpixel($source,$x,$y,$new_pxl);
99 ++$x;
100 }
101 ++$y;
102 }
103 return true;
104 break;
105 case 1:
106 $y = 0;
107 while($y<$max_y) {
108 $x = 0;
109 while($x<$max_x){
110 $rgb = imagecolorat($source,$x,$y);
111 $a = $rgb >> 24;
112 $r = ((($rgb >> 16) & 0xFF)*0.299)+((($rgb >> 8) & 0xFF)*0.587)+(($rgb & 0xFF)*0.114);
113 $new_pxl = imagecolorallocatealpha($source, $r, $r, $r, $a);
114 if($new_pxl == false){
115 $new_pxl = imagecolorclosestalpha($source, $r, $r, $r, $a);
116 }
117 imagesetpixel($source,$x,$y,$new_pxl);
118 ++$x;
119 }
120 ++$y;
121 }
122 return true;
123 break;
124 case 2:
125 $y = 0;
126 while($y<$max_y) {
127 $x = 0;
128 while($x<$max_x){
129 $rgb = imagecolorat($source,$x,$y);
130 $r = (($rgb >> 16) & 0xFF) + $arg1;
131 $g = (($rgb >> 8) & 0xFF) + $arg1;
132 $b = ($rgb & 0xFF) + $arg1;
133 $a = $rgb >> 24;
134 $r = ($r > 255)? 255 : (($r < 0)? 0:$r);
135 $g = ($g > 255)? 255 : (($g < 0)? 0:$g);
136 $b = ($b > 255)? 255 : (($b < 0)? 0:$b);
137 $new_pxl = imagecolorallocatealpha($source, $r, $g, $b, $a);
138 if($new_pxl == false){
139 $new_pxl = imagecolorclosestalpha($source, $r, $g, $b, $a);
140 }
141 imagesetpixel($source,$x,$y,$new_pxl);
142 ++$x;
143 }
144 ++$y;
145 }
146 return true;
147 break;
148 case 3:
149 $contrast = pow((100-$arg1)/100,2);
150 $y = 0;
151 while($y<$max_y) {
152 $x = 0;
153 while($x<$max_x){
154 $rgb = imagecolorat($source,$x,$y);
155 $a = $rgb >> 24;
156 $r = (((((($rgb >> 16) & 0xFF)/255)-0.5)*$contrast)+0.5)*255;
157 $g = (((((($rgb >> 8) & 0xFF)/255)-0.5)*$contrast)+0.5)*255;
158 $b = ((((($rgb & 0xFF)/255)-0.5)*$contrast)+0.5)*255;
159 $r = ($r > 255)? 255 : (($r < 0)? 0:$r);
160 $g = ($g > 255)? 255 : (($g < 0)? 0:$g);
161 $b = ($b > 255)? 255 : (($b < 0)? 0:$b);
162 $new_pxl = imagecolorallocatealpha($source, $r, $g, $b, $a);
163 if($new_pxl == false){
164 $new_pxl = imagecolorclosestalpha($source, $r, $g, $b, $a);
165 }
166 imagesetpixel($source,$x,$y,$new_pxl);
167 ++$x;
168 }
169 ++$y;
170 }
171 return true;
172 break;
173 case 4:
174 $x = 0;
175 while($x<$max_x){
176 $y = 0;
177 while($y<$max_y){
178 $rgb = imagecolorat($source, $x, $y);
179 $r = (($rgb >> 16) & 0xFF) + $arg1;
180 $g = (($rgb >> 8) & 0xFF) + $arg2;
181 $b = ($rgb & 0xFF) + $arg3;
182 $a = $rgb >> 24;
183 $r = ($r > 255)? 255 : (($r < 0)? 0:$r);
184 $g = ($g > 255)? 255 : (($g < 0)? 0:$g);
185 $b = ($b > 255)? 255 : (($b < 0)? 0:$b);
186 $new_pxl = imagecolorallocatealpha($source, $r, $g, $b, $a);
187 if($new_pxl == false){
188 $new_pxl = imagecolorclosestalpha($source, $r, $g, $b, $a);
189 }
190 imagesetpixel($source,$x,$y,$new_pxl);
191 ++$y;
192 }
193 ++$x;
194 }
195 return true;
196 break;
197 case 5:
198 return imageconvolution($source, array(array(-1,0,-1), array(0,4,0), array(-1,0,-1)), 1, 127);
199 break;
200 case 6:
201 return imageconvolution($source, array(array(1.5, 0, 0), array(0, 0, 0), array(0, 0, -1.5)), 1, 127);
202 break;
203 case 7:
204 return imageconvolution($source, array(array(1, 2, 1), array(2, 4, 2), array(1, 2, 1)), 16, 0);
205 break;
206 case 8:
207 for($y = 0; $y<$max_y; $y++) {
208 for ($x = 0; $x<$max_x; $x++) {
209 $flt_r_sum = $flt_g_sum = $flt_b_sum = 0;
210 $cpxl = imagecolorat($source, $x, $y);
211 for ($j=0; $j<3; $j++) {
212 for ($i=0; $i<3; $i++) {
213 if(($j == 1) && ($i == 1)) {
214 $flt_r[1][1] = $flt_g[1][1] = $flt_b[1][1] = 0.5;
215 } else {
216 $pxl = imagecolorat($source, $x-(3>>1)+$i, $y-(3>>1)+$j);
217
218 $new_a = $pxl >> 24;
219 //$r = (($pxl >> 16) & 0xFF);
220 //$g = (($pxl >> 8) & 0xFF);
221 //$b = ($pxl & 0xFF);
222 $new_r = abs((($cpxl >> 16) & 0xFF) - (($pxl >> 16) & 0xFF));
223 if($new_r != 0) {
224 $flt_r[$j][$i] = 1/$new_r;
225 } else {
226 $flt_r[$j][$i] = 1;
227 }
228
229 $new_g = abs((($cpxl >> 8) & 0xFF) - (($pxl >> 8) & 0xFF));
230 if($new_g != 0) {
231 $flt_g[$j][$i] = 1/$new_g;
232 } else {
233 $flt_g[$j][$i] = 1;
234 }
235
236 $new_b = abs(($cpxl & 0xFF) - ($pxl & 0xFF));
237 if($new_b != 0) {
238 $flt_b[$j][$i] = 1/$new_b;
239 } else {
240 $flt_b[$j][$i] = 1;
241 }
242 }
243
244 $flt_r_sum += $flt_r[$j][$i];
245 $flt_g_sum += $flt_g[$j][$i];
246 $flt_b_sum += $flt_b[$j][$i];
247 }
248 }
249
250 for ($j=0; $j<3; $j++) {
251 for ($i=0; $i<3; $i++) {
252 if($flt_r_sum != 0) {
253 $flt_r[$j][$i] /= $flt_r_sum;
254 }
255 if($flt_g_sum != 0) {
256 $flt_g[$j][$i] /= $flt_g_sum;
257 }
258 if($flt_b_sum != 0) {
259 $flt_b[$j][$i] /= $flt_b_sum;
260 }
261 }
262 }
263
264 $new_r = $new_g = $new_b = 0;
265
266 for ($j=0; $j<3; $j++) {
267 for ($i=0; $i<3; $i++) {
268 $pxl = imagecolorat($source, $x-(3>>1)+$i, $y-(3>>1)+$j);
269 $new_r += (($pxl >> 16) & 0xFF) * $flt_r[$j][$i];
270 $new_g += (($pxl >> 8) & 0xFF) * $flt_g[$j][$i];
271 $new_b += ($pxl & 0xFF) * $flt_b[$j][$i];
272 }
273 }
274
275 $new_r = ($new_r > 255)? 255 : (($new_r < 0)? 0:$new_r);
276 $new_g = ($new_g > 255)? 255 : (($new_g < 0)? 0:$new_g);
277 $new_b = ($new_b > 255)? 255 : (($new_b < 0)? 0:$new_b);
278 $new_pxl = ImageColorAllocateAlpha($source, (int)$new_r, (int)$new_g, (int)$new_b, $new_a);
279 if($new_pxl == false) {
280 $new_pxl = ImageColorClosestAlpha($source, (int)$new_r, (int)$new_g, (int)$new_b, $new_a);
281 }
282 imagesetpixel($source,$x,$y,$new_pxl);
283 }
284 }
285 return true;
286 break;
287 case 9:
288 return imageconvolution($source, array(array(-1,-1,-1),array(-1,9,-1),array(-1,-1,-1)), 1, 0);
289 break;
290 case 10:
291 return imageconvolution($source, array(array(1,1,1),array(1,$arg1,1),array(1,1,1)), $arg1+8, 0);
292 break;
293 }
294 }
295 }
296 ?>

SL_Sculpt_to_PHP_script

http_request.inc.php

Category: Sculpt
By : Falados Kapuskas
Created: 2012-09-18 Edited: 2012-09-18
Worlds: Second Life

1 <?php
2
3 /*
4 * Access the HTTP Request
5 */
6 class http_request {
7
8 /** additional HTTP headers not prefixed with HTTP_ in $_SERVER superglobal */
9 var $add_headers = array('CONTENT_TYPE', 'CONTENT_LENGTH');
10
11 /**
12 * Construtor
13 * Retrieve HTTP Body
14 * @param Array Additional Headers to retrieve
15 */
16 function http_request($add_headers = false) {
17
18 $this->retrieve_headers($add_headers);
19 $this->body = @file_get_contents('php://input');
20 }
21
22 /**
23 * Retrieve the HTTP request headers from the $_SERVER superglobal
24 * @param Array Additional Headers to retrieve
25 */
26 function retrieve_headers($add_headers = false) {
27
28 if($add_headers) {
29 $this->add_headers = array_merge($this->add_headers, $add_headers);
30 }
31
32 if(isset($_SERVER['HTTP_METHOD'])) {
33 $this->method = $_SERVER['HTTP_METHOD'];
34 unset($_SERVER['HTTP_METHOD']);
35 } else {
36 $this->method = isset($_SERVER['REQUEST_METHOD']) ? $_SERVER['REQUEST_METHOD'] : false;
37 }
38 $this->protocol = isset($_SERVER['SERVER_PROTOCOL']) ? $_SERVER['SERVER_PROTOCOL'] : false;
39 $this->request_method = isset($_SERVER['REQUEST_METHOD']) ? $_SERVER['REQUEST_METHOD'] : false;
40
41 $this->headers = array();
42 foreach($_SERVER as $i=>$val) {
43 if(strpos($i, 'HTTP_') === 0 || in_array($i, $this->add_headers)) {
44 $name = str_replace(array('HTTP_', '_'), array('', '-'), $i);
45 $this->headers[$name] = $val;
46 }
47 }
48 }
49
50 /**
51 * Retrieve HTTP Method
52 */
53 function method() {
54 return $this->method;
55 }
56
57 /**
58 * Retrieve HTTP Body
59 */
60 function body() {
61 return $this->body;
62 }
63
64 /**
65 * Retrieve an HTTP Header
66 * @param string Case-Insensitive HTTP Header Name (eg: "User-Agent")
67 */
68 function header($name) {
69 $name = strtoupper($name);
70 return isset($this->headers[$name]) ? $this->headers[$name] : false;
71 }
72
73 /**
74 * Retrieve all HTTP Headers
75 * @return array HTTP Headers
76 */
77 function headers() {
78 return $this->headers;
79 }
80
81 /**
82 * Return Raw HTTP Request (note: This is incomplete)
83 * @param bool ReBuild the Raw HTTP Request
84 */
85 function raw($refresh = false) {
86
87 if(isset($this->raw) && !$refresh) {
88 return $this->raw; // return cached
89 }
90
91 $headers = $this->headers();
92 $this->raw = "{$this->method}\r\n";
93
94 foreach($headers as $i=>$header) {
95 $this->raw .= "$i: $header\r\n";
96 }
97
98 $this->raw .= "\r\n{$http_request->body}";
99
100 return $this->raw;
101 }
102
103 }
104 ?>

SL_Sculpt_to_PHP_script

openloft_config.inc.php

Category: Sculpt
By : Falados Kapuskas
Created: 2012-09-18 Edited: 2012-09-18
Worlds: Second Life

1 <?
2 // This file is part of OpenLoft.
3 //
4 // OpenLoft is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
8 //
9 // OpenLoft is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with OpenLoft. If not, see <http://www.gnu.org/licenses/>.
16 //
17 // Authors: Falados Kapuskas, JoeTheCatboy Freelunch
18
19 require_once 'http_request.inc.php';
20 //--Configuration Parameters--//
21
22 //--Uncomment the below line to enable authentication
23 // To only allow the following users with the correct password
24 // This is disabled by default
25 //define('ENABLE_AUTH','1');
26
27 //--Avatars allowed to access the OpenLoft server
28 $ll_allowed = array(
29 "fdbec268-0518-49f7-a334-320d70375c75", //Falados Kapuskas
30 "22c701fd-d887-40d9-ae92-7cfe8a641335" //JoeTheCatboy Freelunch
31 );
32 //--The password to use for the open-loft server
33 $ll_password = 'openloft';
34
35 //--Subnets for LL Servers--//
36 $ll_subnets = array(
37 "8.2.32.0/22",
38 "63.210.156.0/22",
39 "64.129.40.0/22",
40 "64.129.44.0/22",
41 "64.154.220.0/22",
42 "8.4.128.0/22",
43 "8.10.144.0/21",
44 "216.82.0.0/18"
45 );
46
47 //--Other Neat Stuff--//
48
49 function net_match($network, $ip) {
50 // determines if a network in the form of 192.168.17.1/16 or
51 // 127.0.0.1/255.255.255.255 or 10.0.0.1 matches a given ip
52 $ip_arr = explode('/', $network);
53 $network_long = ip2long($ip_arr[0]);
54
55 $x = ip2long($ip_arr[1]);
56 $mask = long2ip($x) == $ip_arr[1] ? $x : 0xffffffff << (32 - $ip_arr[1]);
57 $ip_long = ip2long($ip);
58
59 // echo ">".$ip_arr[1]."> ".decbin($mask)."\n";
60 return ($ip_long & $mask) == ($network_long & $mask);
61 }
62
63 $is_ll = FALSE;
64 foreach( $ll_subnets as $network) {
65 if(net_match($network,$_SERVER['REMOTE_ADDR'] )) {
66 $is_ll = TRUE;
67 break;
68 }
69 }
70
71 $p = $_REQUEST['p'];
72 $request = new http_request();
73
74 $nheaders = array_map('strtolower',$request->headers());
75 $headers = array();
76 foreach( $nheaders as $key => $value )
77 {
78 $headers[strtolower($key)] = $value;
79 }
80
81 //OWNER
82 $owner_key = $headers['x-secondlife-owner-key'];
83
84 //OBJECT
85 $object_key = $headers['x-secondlife-object-key'];
86
87 $is_allowed = $is_ll &&
88 in_array(trim(strtolower($owner_key)),$ll_allowed) &&
89 $p == $ll_password;
90 ?>

SL_Sculpt_to_PHP_script

vertex2sculpt.php

Category: Sculpt
By : Falados Kapuskas
Created: 2012-09-18 Edited: 2012-09-18
Worlds: Second Life

1 <?
2 // This file is part of OpenLoft.
3 //
4 // OpenLoft is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
8 //
9 // OpenLoft is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with OpenLoft. If not, see <http://www.gnu.org/licenses/>.
16 //
17 // Authors: Falados Kapuskas, JoeTheCatboy Freelunch
18
19 require_once('openloft_config.inc.php');
20 require_once('func.gdbundle.php');
21
22 if( defined(ENABLE_AUTH) && !$is_allowed) die('Not Allowed');
23
24 define('FLOAT_PRECISION',3);
25
26 //Make the directories if they are missing
27 if( !file_exists("cache") ) mkdir("cache");
28 if( !file_exists("sculpts") ) mkdir("sculpts");
29
30 function fullpath($file){
31 $host = $_SERVER['HTTP_HOST'];
32 $uri = rtrim($_SERVER['PHP_SELF'], "/\\");
33 $uri = str_replace(basename($_SERVER['PHP_SELF']),"",$uri);
34 return "http://$host$uri$file";
35 }
36
37
38 class vertex {
39 var $x=0.0;
40 var $y=0.0;
41 var $z=0.0;
42 function load(/*.array.*/ $arr) {
43 $this->x = floatval($arr[0]);
44 $this->y = floatval($arr[1]);
45 $this->z = floatval($arr[2]);
46 }
47 function mult($scalar=1.0)
48 {
49 $this->x *=floatval($scalar);
50 $this->y *=floatval($scalar);
51 $this->z *=floatval($scalar);
52 }
53 function combine(/*.vertex.*/ $vector)
54 {
55 $this->x /= $vector->x;
56 $this->y /= $vector->y;
57 $this->z /= $vector->z;
58 }
59 function add(/*.vertex.*/ $vertex)
60 {
61 $this->x += $vertex->x;
62 $this->y += $vertex->y;
63 $this->z += $vertex->z;
64 }
65 function get_array() {
66 return array($this->x,$this->y,$this->z);
67 }
68 function toString() {
69 return "<$this->x,$this->y,$this->z>";
70 }
71 };
72
73 function make_sculpty($verts,$sc,$o,$width,$height,$upsample, $smooth) {
74 global $owner_key,$object_key;
75
76 $image = imagecreatetruecolor($width,$height);
77
78
79
80 $scale = new vertex;
81 $orig = new vertex;
82
83 $orig->load($o);
84 $orig->mult(-1);
85
86 $scale->load($sc);
87 $scale->mult(0.5); //Radius
88
89 $this_row = 0;
90
91 foreach( $verts as $vert_row ) //Rows
92 {
93 $x = 0;
94 $row = explode("|",$vert_row);
95 $point = FALSE;
96 if( count($row) == 1 ) $point = TRUE;
97 $y = $height - 1 - $this_row;
98 foreach( $row as $v ) //Columns
99 {
100 $vert = new vertex;
101 $vert->load(explode(",",$v));
102 $vert->add($orig);
103 $vert->combine($scale);
104
105 $red = floor(127*round($vert->x,FLOAT_PRECISION))+128;
106 $green = floor(127*round($vert->y,FLOAT_PRECISION))+128;
107 $blue = floor(127*round($vert->z,FLOAT_PRECISION))+128;
108
109 if( $red > 255) $red = 255;
110 if( $blue > 255) $blue = 255;
111 if( $green > 255) $green = 255;
112 if( $red < 0) $red = 0;
113 if( $blue < 0) $blue = 0;
114 if( $green < 0) $green = 0;
115
116 $color = imagecolorallocate($image,$red,$green,$blue);
117
118 if($point) {
119 imageline($image,0,$y,$width-1,$y,$color);
120 break;
121 } else {
122 imagesetpixel($image,$x,$y,$color);
123 }
124 ++$x;
125 if($x >= $width) break;
126 }
127 $this_row++;
128 if( $this_row >= $height) break;
129 }
130
131 //Up-sample the image
132 if($upsample)
133 {
134 $new_h = $height*2;
135 $new_w = $width*2;
136 $image_resampled = imagecreatetruecolor($new_w,$new_h);
137 imagecopyresized($image_resampled , $image , 0 , 0 , 0 , 0 , $new_w , $new_h , $width, $height );
138 imagedestroy($image);
139 $image = $image_resampled;
140 }
141
142 if( $smooth == "gaussian" ) {
143 $gaussian = array(array(1.0, 2.0, 1.0), array(2.0, 4.0, 2.0), array(1.0, 2.0, 1.0));
144 imageconvolution($image, $gaussian, 16, 0);
145 }
146 if( $smooth == "linear" ) {
147 $linear = array(array(1.0, 1.0, 1.0), array(1.0, 1.0, 1.0), array(1.0, 1.0, 1.0));
148 imageconvolution($image, $linear, 9, 0);
149 }
150
151 //Name it after the object and owner key, otherwise the name given during the render command
152 $imagename = "$owner_key-$object_key.png";
153 if(isset($_REQUEST['name'])) $imagename = $_REQUEST['name'];
154
155 imagepng($image,"sculpts/$imagename");
156 imagedestroy($image);
157 echo("\nYour Sculpt: <" . fullpath("sculpts/$imagename") . ">\n");
158 }
159
160 $action = $_REQUEST['action'];
161
162 //Make 'unique' filename
163 $image_id = $owner_key;
164
165 if($action == "upload")
166 {
167
168 //Convinence Variables
169 $issplit = FALSE;
170 if(isset($_REQUEST['split']))
171 {
172 $issplit = TRUE;
173 $s = explode("of",stripslashes($_REQUEST['split']));
174 $start = $s[0];
175 $end = $s[1];
176 }
177
178 $verts = stripslashes($_REQUEST['verts']);
179 $row = stripslashes($_REQUEST['row']);
180 $params = stripslashes($_REQUEST['params']);
181
182 //Parse Verticies
183 $nverts = preg_replace("/> *, *</","|",$verts);
184 $nverts = preg_replace("/[> <]/","",$nverts);
185
186 //Write vertex packet splits to a split file
187 //Populate the verticies on the row when all splits are received
188 if($issplit) {
189
190 $fd = fopen("cache/$image_id.split","a+");
191 $fd || die("Could not open file: " . "$image_id.split$row");
192 fwrite($fd,$nverts);
193 if($start == $end) {
194 $nverts = fread($fd, filesize("$image_id.split$row"));
195 fclose($fd);
196 $fd = FALSE;
197 unlink("cache/$image_id.split");
198 } else {
199 $nverts = FALSE;
200 }
201 if($fd) fclose($fd);
202 }
203
204 $row_filename = "cache/$image_id-$row.verts";
205
206 //Write vertex dump to file
207 if( $nverts ) {
208 $fd = fopen($row_filename,"w");
209 $fd || die("Could not open file: $row_filename");
210 fwrite($fd,"$nverts");
211 fclose($fd);
212 }
213 }
214
215 if( $action == "render") {
216 $xverts = stripslashes($_REQUEST['w']);
217 $yverts = stripslashes($_REQUEST['h']);
218 $smooth = stripslashes($_REQUEST['smooth']);
219 $scale = stripslashes($_REQUEST['scale']);
220 $orig = stripslashes($_REQUEST['org']);
221 $input = array();
222 for($r = 0; $r < $yverts; ++$r)
223 {
224 $row_filename = "cache/$image_id-$r.verts";
225 if( $input[] = file_get_contents($row_filename) ) {
226 //unlink($row_filename);
227 } else {
228 die("Couldn't open file for row $r");
229 }
230 }
231 //Parse Scale
232 $scale = preg_replace("/[> <]/","",$scale);
233 $scale = explode(",",$scale);
234
235 //Parse Origin
236 $orig = preg_replace("/[> <]/","",$orig);
237 $orig = explode(",",$orig);
238
239 make_sculpty($input,$scale,$orig,$xverts,$yverts,TRUE,$smooth);
240 }
241 ?>

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