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
XS Pets Texture_server_for_XS_Pets  

Texture_server_for_XS_Pets

Texture Server
An article on how to use this script is located at http://metaverse.mitsi.com/Secondlife/Posts/Breedable-pet-robot/texture-server.htm

Category: XS Pets
By : Ferd Frederix
Created: 2012-08-16 Edited: 2012-08-16
Worlds: Second Life

the Zip file

Download all files for Texture_server_for_XS_Pets
Contents are in zip format, with .LSL (text) source code and LSLEdit (text + Solution) formats.
Get file # 1. Texture_server_for_XS_Pets_1.lsl
Get file # 2. Texture_server_for_XS_Pets_2.lsl
Get file # 3. Texture_server_for_XS_Pets_3.lsl

This script by Ferd Frederix may be used in any manner, modified, and republished.  Unless specified otherwise, my scripts are always free and open source.  Objects made with these scripts may be sold with no restrictions.  All I ask is that you point others to this location should they ask you about it and to not sell this script, unless it is for $0 L. Please help improve my work by reporting bugs and improvements.

1
2 // Xs_Pets textures by Ferd Frederix
3
4 /////////////////////////////////////////////////////////////////////
5 // This code is licensed as Creative Commons Attribution/NonCommercial/Share Alike
6
7 // See http://creativecommons.org/licenses/by-nc-sa/3.0/
8 // Noncommercial -- You may not use this work for commercial purposes
9 // If you alter, transform, or build upon this work, you may distribute the resulting work only under the same or similar license to this one.
10 // This means that you cannot sell this code but you may share this code.
11 // You must attribute authorship to me and leave this notice intact.
12 //
13 // Exception: I am allowing this script to be sold inside an original build.
14 // You are not selling the script, you are selling the build.
15 // Ferd Frederix
16
17
18 ////////////////////////////////////////////////////////////////////y
19
20 // You must put any textures you want to send to your pets in the same prim as this server.
21 // Colors such as color1 and color2 are stored in the Description of the pet prims. Use the prim Name for the texture name
22 //
23 // The names must match the following pattern:
24 // PrimName N
25 // Where PrimName is the name you put in the prim to be textured, and N is a number from 0 to however many sets of skins you have.
26 //
27 // 2-prime xample: Body 0
28 // Head 0
29 // Body 1
30 // Head 1
31 //
32 // In this case, there should be two ( or more) prims in the pet whoes prim name is Body or Head
33 // So you will end up with two possible breeds for your pets, either the 0th or the 1st textures.
34 //
35 // If the breedable param Color1.x value (Red coloration) is < 0.5, you get Body 0 and Head 0
36 // If the breedable param Color1.x value (Red coloration) is > 0.5, you get Body 1 and Head 1
37
38
39 // The pets breed by mixing colors. If a 1.0 (all Red) breeds with a 0.0 (No Red), you get a code near the average, or 0.5.
40 // Root prim:
41 // There is a special name 'root' for the root prim since your pet could be renamed, whioch would change the name of the root prim..
42 // root 0 would be the name to use for the first root prim texture, root 1 for the second, and so on.
43 // If your root prim is an invisible prim or is not to be textured, you can ignore this 'root' name.
44
45
46 // Deeper example:
47 // You have a pet robot with 3 sets of breedable skins, and 4 prims, called 'head'. 'body', 'leg' and 'tail'.
48 // You will need 3X4, or 12 textures in all.
49 // edit the pet, and change the name of the head to 'head', change the body name to 'body', the left leg to 'leg', and the right leg to 'leg'.
50 // each texture must also a single digit after it to represent the breed type:
51 // head 0, head 1 and head 2
52 // body 0, body 1, and body 2
53 // leg 0, leg 1, and leg 2
54 // tail 0 , tail 1, and tail 2
55
56 // you may have up to 254 total textures in the server. In the above example, there are
57 // 4 textures per skin set, so you can have 254/4, or 63 skins for your pet.
58
59 // What about the root prim?
60 // The last prim you link to is the root prim. It holds the xs_pet scripts.
61 // This prim gets renamed in various objects, so you cannot add a name to the prim that matches a
62 // texture. A special texture name 'root 0', 'root 1' etc. is set aside for this prim.
63 // Most xs_pets will not need to use the root prim texture, because the root prim is the base of the pet
64 // and it usually is made invisible. If your root prim needs to be visible and textured,
65 // just add a root 0, root1 and so on texture for each texture set.
66
67
68 //////////////////////////////////////////////////////////
69 // CONFIGURATION //
70 //////////////////////////////////////////////////////////
71
72 // you must put in a UUID from this web site here and in the brain script
73 //http://gridurl.appspot.com/random
74
75 string UUID = "48246356-a7c5-474b-a6fe-f2cec98926b2";
76 integer debug = FALSE; // set to 1 or TRUE for debuging information to the owner
77 //////////////////////////////////////////////////////////
78 // INTERNALS //
79 //////////////////////////////////////////////////////////
80
81
82
83 list textureDB; // texture storage
84 integer nTextures; // how many we find
85 integer nServed; // how many we served
86 integer nPrims ; // how many prims there must be
87 integer nBreeds; // how man breeds
88 list lNames; // a list of names
89 key gtextureUUID; // The UUID of the detected texture
90 string gtextureName; // the name of the detected texture
91 key URLReq = NULL_KEY;
92 string url; // sop we can release HTTP-In keys
93 key urlRequestId;
94
95 request_url()
96 {
97 llReleaseURL(url);
98 url = "";
99
100 urlRequestId = llRequestURL();
101 }
102
103 getImage(integer breedNum, string breedName)
104 {
105
106 DEBUG("Seeking Name " + breedName );
107 DEBUG("Seeking Number " + (string) breedNum );
108
109 integer i;
110 integer j = llGetListLength(textureDB);
111 for (i = 0; i < j; i += 3)
112 {
113 integer myBreedParam = llList2Integer(textureDB,i);
114 string humanName = llList2String(textureDB,i+1);
115 key UUID = llList2Key(textureDB,i+2);
116
117 if(myBreedParam > breedNum )
118 {
119 DEBUG("Found it!");
120 return;
121 }
122
123 if(breedName == humanName)
124 {
125 gtextureName = humanName;
126 gtextureUUID = UUID;;
127 DEBUG("saving " + humanName + " " + (string) myBreedParam);
128 }
129 }
130
131 return;
132 }
133
134 list ListUnique( list lAll ) {
135 integer i;
136 list lFiltered = llList2List(lAll, 0, 0);
137 integer iAll = llGetListLength( lAll );
138 for (i = 1; i < iAll; ++i) {
139 if( llListFindList(lFiltered, llList2List(lAll, i, i) ) == -1 ) {
140 lFiltered += llList2List(lAll, i, i);
141 }
142 }
143 return lFiltered;
144 }
145 list parsePostData(string message)
146 {
147 list postData = [];
148 list parsedMessage = llParseString2List(message,["&"],[]);
149 integer len = ~llGetListLength(parsedMessage);
150
151 while(++len) {
152 string currentField = llList2String(parsedMessage, len);
153
154 integer split = llSubStringIndex(currentField,"=");
155 if(split == -1) {
156 postData += [llUnescapeURL(currentField),""];
157 } else {
158 postData += [llUnescapeURL(llDeleteSubString(currentField,split,-1)), llUnescapeURL(llDeleteSubString(currentField,0,split))];
159 }
160 }
161
162 return postData ;
163 }
164
165
166 getTextures()
167 {
168 textureDB = [];
169 lNames = [];
170
172 integer i;
173
174 for (i = 0; i < j ; i++)
175 {
177 list splits = llParseString2List(textureName,[" "],[]);
178 integer n = llGetListLength(splits);
179
180 string humanName = llList2String(splits,0);
181 string breedParam = llList2String(splits,1);
182 key UUID = llGetInventoryKey(textureName);
183
184 textureDB += breedParam;
185 textureDB += humanName;
186 textureDB += UUID;
187
188 lNames += humanName;
189 }
190 nTextures = llGetListLength(textureDB)/3;
191 lNames = ListUnique(lNames);
192 nPrims = llGetListLength(lNames);
193 DEBUG("Number of colorable prims = " + (string) nPrims);
194
195 nBreeds = nTextures / nPrims;
196
197 textureDB = llListSort(textureDB,3,1);
198
199 DEBUG("Number of textures = " + (string) nTextures);
200 DEBUG("Number of breeds = " + (string) nBreeds);
201 }
202 string getTexture(string body)
203 {
204
205 DEBUG("Parsing " + body);
206 list incomingMessage = parsePostData(body);
207 DEBUG("Params: " + llDumpList2String(incomingMessage,"\n"));
208
209 if(llList2String(incomingMessage,0) == "breed")
210 {
211 float myBreed = (float) llList2String(incomingMessage,1);
212 DEBUG("Scanning for Breed: " + (string) myBreed);
213
214 integer myBreedNum = llCeil((myBreed * nBreeds));
215
216 DEBUG("Looking for myBreed " + (string) myBreedNum);
217
218 llSetText("Served:" + (string) nServed + "\nLast Breed:"+ (string) myBreedNum + "\nParam:" + (string) myBreed ,<1,1,1>,1.0);
219
220 string response;
221 integer i;
222
223 for (i = 0; i < nPrims; i++)
224 {
225 string breedName = llList2String(lNames,i);
226
227 getImage(myBreedNum,breedName);
228 response += gtextureName + "|";
229 response += (string) gtextureUUID + "|";
230 }
231 return "texture|" + response;
232 }
233 return "texture|" + (string) TEXTURE_BLANK;
234 }
235 key Request(string URL)
236 {
237 llSetText("Registering",<1,1,1>,1.0);
238 string url = "http://gridurl.appspot.com/reg?service=" + UUID + "&url=" + llEscapeURL(URL) + "/";
239 return llHTTPRequest( url, [HTTP_METHOD, "GET"], "");
240 }
241
242
243 throw_exception(string inputString)
244 {
245 key owner = llGetOwner();
246 llInstantMessage(owner, inputString);
247 llSleep(60); // so we do not flood owner with IM's
249 }
250
251
252
253
254 DEBUG(string msg)
255 {
256 if(debug)
257 llOwnerSay(llGetScriptName() + " : " + msg);
258 }
259
260
261 default
262 {
264 {
265 getTextures();
266 llSetText("Initializing",<1,1,1>,1.0);
267 request_url();
268 }
269 on_rez(integer param)
270 {
272 }
273
274
275 http_request(key id, string method, string body)
276 {
277 if(method == URL_REQUEST_GRANTED)
278 {
279 DEBUG(body);
280 url = body; // save body response so we can release it.
281 URLReq = Request(body);
282 llSetText("Granted",<0,1,0>,1.0);
283 }
284 else if(method == URL_REQUEST_DENIED)
285 {
286 llOwnerSay("ERROR: URL REQUEST was DENIED "+body);
287 llSetText("ERROR: URL REQUEST was DENIED",<1,0,0>,1.0);
288 llSleep(5);
290 }
291 else if(id == URLReq)
292 {
293 if(body == "OK")
294 {
295 llSetText("OK",<1,0,0>,1.0);
296 }
297 else
298 {
299 llSetText("Unable to register",<0,0,1>,1.0);
300 }
301 }
302 else if(method == "POST")
303 {
304 nServed++;
305 string resp = getTexture(llGetHTTPHeader(id, "x-query-string"));
306 llHTTPResponse(id, 200, resp);
307 }
308 else
309 {
310
311 llSetText("Not Implemented",<1,0,0>,1.0);
312 llHTTPResponse(id, 501, "Not Implemented "+method);
313 }
314 }
315 http_response(key request_id, integer status, list metadata, string body)
316 {
317 if(URLReq == request_id)
318 {
319 URLReq = NULL_KEY;
320 if(status == 200)
321 {
322 llSetText("Ok",<1,1,1>,1.0);
323 }
324 else
325 {
326 llSetText("Request failed",<1,0,0>,1.0);
327 llOwnerSay("Request failed status="+(string)status+" "+body);
328 llSleep(10);
329 request_url();
330 }
331 }
332 }
333
334
335 changed (integer what)
336 {
337 if(what & CHANGED_INVENTORY)
338 {
339 getTextures();
340 }
341
342 if(what & (CHANGED_REGION_START ))
343 {
344 llReleaseURL(url);
346 }
347
348 }
349 }

Texture_server_for_XS_Pets

xs_texture plug
An article on how to use this script is located at http://metaverse.mitsi.com/Secondlife/Posts/Breedable-pet-robot/texture-server.htm

Category: XS Pets
By : Ferd Frederix
Created: 2012-08-16 Edited: 2012-08-16
Worlds: Second Life


This script by Ferd Frederix may be used in any manner, modified, and republished.  Unless specified otherwise, my scripts are always free and open source.  Objects made with these scripts may be sold with no restrictions.  All I ask is that you point others to this location should they ask you about it and to not sell this script, unless it is for $0 L. Please help improve my work by reporting bugs and improvements.

1 //xs_texture plug in
2
3 // 12-3-2012 - no longer dorks with the offset, repeat, or rotation when applying a texture
4
5 /////////////////////////////////////////////////////////////////////
6 // This code is licensed as Creative Commons Attribution/NonCommercial/Share Alike
7
8 // See http://creativecommons.org/licenses/by-nc-sa/3.0/
9 // Noncommercial -- You may not use this work for commercial purposes
10 // If you alter, transform, or build upon this work, you may distribute the resulting work only under the same or similar license to this one.
11 // This means that you cannot sell this code but you may share this code.
12 // You must attribute authorship to me and leave this notice intact.
13 //
14 // Exception: I am allowing this script to be sold inside an original build.
15 // You are not selling the script, you are selling the build.
16 // Ferd Frederix
17
18
19
20 //////////////////////////////////////////////////////////
21 // CONFIGURATION //
22 //////////////////////////////////////////////////////////
23 // you must put in a UUID from this web site here and in the Server script
24 // http://gridurl.appspot.com/random
25
26 string UUID = "48246356-a7c5-474b-a6fe-f2cec98926b2"; // do not use this number, use your own from http://gridurl.appspot.com/random
27 integer debug = FALSE; // set to TRUE to see debug messages
28 //////////////////////////////////////////////////////////
29 // INTERNALS //
30 //////////////////////////////////////////////////////////
31
32 integer LINK_TEXTURE = 801; // ask for a new texture, or paint a color
33
34 key URLRqstKey;
35 key textureRqstKey;
36 string newpath ;
37
38 // globals to hold the params linked in from the brain
39 vector colorCode1;
40 vector colorCode2;
41 integer sex;
42 integer shine;
43 float glow;
44 float breed;
45
46
47
48 DEBUG(string msg)
49 {
50 if(debug)
51 llOwnerSay(llGetScriptName() + " : " + msg);
52 }
53
54 key Request(string cmd)
55 {
56 DEBUG("Sending:"+newpath+"?"+cmd);
57 return llHTTPRequest( newpath+"?"+cmd, [HTTP_METHOD, "GET"], "");
58 }
59
60 key TextureRequest()
61 {
62 string URL = newpath + "?breed=" + llEscapeURL((string) breed) ;
63 DEBUG("Sending: "+ URL);
64 return llHTTPRequest( URL, [HTTP_METHOD, "POST"], "");
65 }
66
67
68 // change texture of amny prims named texture1 to texture6
69 TextureIt(list textures)
70 {
71 integer nPrims = llGetNumberOfPrims();
72 integer i;
73 for (i = 0; i <= nPrims; i++)
74 {
75 list param = llGetLinkPrimitiveParams(i,[PRIM_NAME]); // name holds the texture number
76 string primName = llList2String(param,0);
77
78 // root is special
79 if( i == 1)
80 primName = "root";
81
82 integer where = llListFindList(textures,[primName]);
83
84 if(where >= 0)
85 {
86 key UUID = (key) llList2String(textures,where+1);
87 //DEBUG("UUID :" + (string) UUID);
88
89 // DEBUG("Set Texture: " + primName + " on prim #" + (string) i);
90 // apply texture and the other params
91 llSetLinkPrimitiveParamsFast(i, [PRIM_COLOR, ALL_SIDES, <1,1,1>, 1.0, PRIM_BUMP_SHINY, ALL_SIDES, shine, PRIM_BUMP_NONE, PRIM_GLOW, ALL_SIDES, glow]); // delete the prim texture
92 llSetLinkTexture(i,UUID,ALL_SIDES); // add this line which sets the texture with no offset or repeat or rotation changes
93 }
94
95
96 }
97 }
98
99
100 default
101 {
103 {
104
105 }
106
107 on_rez(integer param)
108 {
110 }
111
112 link_message(integer who, integer num, string str, key id)
113 {
114
115 // there are two vectors, sent in one packet
116 if(num == LINK_TEXTURE)
117 {
118 DEBUG("received LINK_TEXTURE");
119 list params = llParseString2List(str,["^"],[]);
120 colorCode1 = (vector) llList2String(params,0);
121 colorCode2 = (vector) llList2String(params,1);
122 sex = (integer) llList2String(params,2);
123 shine = (integer) llList2String(params,3);
124 glow = (float) llList2String(params,4);
125 breed = colorCode1.x; // the breed is based on the Red value of Color 1
126
127 URLRqstKey = llHTTPRequest( "http://gridurl.appspot.com/get/"+ llEscapeURL(UUID ), [HTTP_METHOD, "GET"], ""); // find the other object/script
128
129 }
130
131 }
132
133
134
135 http_response(key request_id, integer status, list metadata, string body)
136 {
137 if(URLRqstKey == request_id)
138 {
139 URLRqstKey = NULL_KEY; // the same event sometimes shows up more then once
140 if(status != 200)
141 llOwnerSay("The internet is broken! status="+(string)status+" "+body);
142 else
143 {
144 DEBUG(body);
145 newpath= body;
146 textureRqstKey = TextureRequest(); // request the object name
147 }
148 }
149 else if(textureRqstKey == request_id)
150 {
151 if(status != 200)
152 llOwnerSay("request failed status="+(string)status+" "+ body);
153 else {
154 DEBUG("response:" + body); // report what was returned from request
155 list textures = llParseString2List(body,["|"],[]);
156 if(llList2String(textures,0) == "texture")
157 {
158 TextureIt(textures);
159 }
160 }
161 }
162 }
163 }

Texture_server_for_XS_Pets

test code for texture server. Put this into a set of prims with the pet texture script and touch it. Any prim with the same name as a texture in the server will change to that texture.

Category: XS Pets
By : Ferd Frederix
Created: 2012-08-16 Edited: 2012-08-16
Worlds: Second Life


This script by Ferd Frederix may be used in any manner, modified, and republished.  Unless specified otherwise, my scripts are always free and open source.  Objects made with these scripts may be sold with no restrictions.  All I ask is that you point others to this location should they ask you about it and to not sell this script, unless it is for $0 L. Please help improve my work by reporting bugs and improvements.

1 // test code to make a pet change textures.
2 // Just put this in a prim inside the pet, and touch it again and again.
3 // The pet should change textures on any prim name that
4 /////////////////////////////////////////////////////////////////////
5 // This code is licensed as Creative Commons Attribution/NonCommercial/Share Alike
6
7 // See http://creativecommons.org/licenses/by-nc-sa/3.0/
8 // Noncommercial -- You may not use this work for commercial purposes
9 // If you alter, transform, or build upon this work, you may distribute the resulting work only under the same or similar license to this one.
10 // This means that you cannot sell this code but you may share this code.
11 // You must attribute authorship to me and leave this notice intact.
12 //
13 // Exception: I am allowing this script to be sold inside an original build.
14 // You are not selling the script, you are selling the build.
15 // Ferd Frederix
16
17
18
19 integer LINK_TEXTURE = 801; // ask for a new texture, or paint a color
20
21 ///////// end global Link constants ////////
22
23 vector colour1 = <1,1,1>;
24 vector colour2 = <0,0,0>;
25 integer sex = 1;
26 integer shine = 0;
27 float glow = 0.0;
28
29
30 default
31 {
32
33 touch_start(integer total_number)
34 {
35
36 colour1.x = llFrand(1.0); // pick a random texture
37 llOwnerSay("Breed Param:" + (string) colour1.x);
38
39 string msg = (string) colour1 + "^" +
40 (string) colour2 + "^" +
41 (string) sex + "^" +
42 (string) shine + "^" +
43 (string) glow + "^";
44
45 llMessageLinked(LINK_SET,LINK_TEXTURE,msg,NULL_KEY);
46
47 }
48 }

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