Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

changing color of temp-rez-objects

Haruki Watanabe
llSLCrash(void);
Join date: 28 Mar 2007
Posts: 434
09-10-2007 09:28
OK ppl - there's another wicked question from me... :)


I have a box that rezzes temp-objects. After they're rezzed, I want to change Color and Alpha of the rezzed object.

BUT since a temp-object doesn't produce an asset on the server, I guess I won't receive an id in the on_rez-event, do I? And also, I don't want to link the rezzed object...

Is there a way to change the color and alpha of an object BEFORE it is rezzed? That would actually be the easiest way to achieve my goal...

Thanks for every help!
Deanna Trollop
BZ Enterprises
Join date: 30 Jan 2006
Posts: 671
09-10-2007 10:42
From: Haruki Watanabe
BUT since a temp-object doesn't produce an asset on the server
Rezzing an object *never* creates an asset.

From: someone
I guess I won't receive an id in the on_rez-event, do I?
Have you tried it?
Jesse Barnett
500,000 scoville units
Join date: 21 May 2006
Posts: 4,160
09-10-2007 14:23
From: someone

llRezObject triggers the object_rez event, passing the new object's key to any script in the rezzing object. The newly rezzed object will receive a on_rez event. This is useful for replicating objects.

You can get the key of the rezzed object and you can also pass it a parameter vaule that a script can read in the rezzed object to change it's color etc.
_____________________
I (who is a she not a he) reserve the right to exercise selective comprehension of the OP's question at anytime.
From: someone
I am still around, just no longer here. See you across the aisle. Hope LL burns in hell for archiving this forum
Haruki Watanabe
llSLCrash(void);
Join date: 28 Mar 2007
Posts: 434
09-10-2007 15:04
The rezzed object does not know by default, which color it will have (I get those values from the web). The only value I can pass in the llRezObject-command, is an integer, so I won't be able to pass a vector (for the color).

When I link the object to the object that rezzes it, it will not be temporary anymore (and it has to be temporary, since there will be «a bunch» of them). But without linking the rezzed object to the rezzer, I can't set the color values. I could pass the value to the object while it is linked and then unlink it immediately - but this would be too time consuming...

I already thought about opening a listener, when the object is rezzed, «say» the objects key on a channel and then send the rgb-values back to the object. Again, since there will be quite a lot of these objects, this would cause heavy lag, I guess...

Another thing I was thinking of, is using llRemoteLoadScriptPin. But this would end up in the same problem as above, that I have to pass this script the rgb-values - which actually ends up in the same problem as before...
Ziggy Puff
Registered User
Join date: 15 Jul 2005
Posts: 1,143
09-10-2007 15:14
From: someone
The only value I can pass in the llRezObject-command, is an integer, so I won't be able to pass a vector (for the color)


You only have 256 * 256 * 256 possible values, which is 16777216, and that will fit in an integer. So yes, you can't directly pass a vector, but you could come up with a simple encoding scheme to convert 3 numbers in the 0-255 range into a single large integer, and then decode it back in the rezzed object to get back the 3 values.

In fact, the encoding is probably as simple as converting to hex. Take the values of the 3 colors, convert them to hex, line them up (either using string concatenation or numeric addition offset by the appropriate power of 256), and there's your big integer.

Or even just string concatenate the decimal values. Your values will be in the range of 0 (000000000) through 255255255, which will also fit in a 32 bit integer. On the receive side, pad out any leading 0s that would have been stripped off to get back your 9 digits, strip them down into the 3-digit sets, and there's your 3 color values again.

And finally, a floating point division by 255.0 will give you the color values in the 0-1 range needed by SL.

Example: Maybe something like this (untested, so probably buggy):

integer Rn = whatever; // Decimal value for red, in the 0-255 range
string Rs = (string)Rn;
while (llGetStringLength(Rs) < 3) {
Rs = "0" + Rs;
}

// Now Rs should be a "3-digit string"

string Colors = Rs + Gs + Bs;
integer rezParam = (integer)Colors;

And on the decode side:

on_rez (integer param) {
string params = (string)param;

// May be less than 9 digits, if there are any leading 0s
while (llGetStringLength(params) < 9) {
params = "0" + params;
}

// Now we have a 9-digit string
integer Rn = (integer)llGetSubString(params, 0, 2);
integer Gn = (integer)llGetSubString(params, 3, 5);
integer Bn = (integer)llGetSubString(params, 6, 8);

Like I said, untested and probably buggy
Malachi Petunia
Gentle Miscreant
Join date: 21 Sep 2003
Posts: 3,414
09-10-2007 15:20
Ummm, what Ziggy said...

From: someone
The rezzed object does not know by default, which color it will have (I get those values from the web). The only value I can pass in the llRezObject-command, is an integer, so I won't be able to pass a vector (for the color).
I can fit at least three octets in an integer:

color = ((red % 256) << 16)
color += ((green % 256) << 8)
color += (blue % 256)

Try it, it's fun!
_____________________
Ziggy Puff
Registered User
Join date: 15 Jul 2005
Posts: 1,143
09-10-2007 15:22
Or... Malachi's much easier solution, that doesn't involve mucking with strings and therefore will be way less laggy :)
Jesse Barnett
500,000 scoville units
Join date: 21 May 2006
Posts: 4,160
09-10-2007 16:50
Yeah. Like Ziggy & Malachi said :)
_____________________
I (who is a she not a he) reserve the right to exercise selective comprehension of the OP's question at anytime.
From: someone
I am still around, just no longer here. See you across the aisle. Hope LL burns in hell for archiving this forum
Squirrel Wood
Nuteater. Beware!
Join date: 14 Jun 2006
Posts: 471
09-10-2007 23:23
another option:

integer color = r*65536 + g * 256 + b;
Haruki Watanabe
llSLCrash(void);
Join date: 28 Mar 2007
Posts: 434
09-11-2007 00:29
Took me a moment to figure out how to reverse Malachi's math... but it works!!!

Bea-Tea-ful!! :)

Thanks a lot!

( that's how I did it - I bet, there's an even easier solution:

red = (color >> 16);

color -= ((red % 256) << 16);

green = color >> 8;

color -= ((green % 256) << 8);

blue = color;

)
Malachi Petunia
Gentle Miscreant
Join date: 21 Sep 2003
Posts: 3,414
09-11-2007 02:46
Reversing is a tad easier than encoding:

red = (color & 0xff0000) >> 16;
green = (color & 0x00ff00) >> 8;
blue = (color & 0x00000ff);
_____________________
Talarus Luan
Ancient Archaean Dragon
Join date: 18 Mar 2006
Posts: 4,831
09-11-2007 03:03
From the Wiki:

Useful functions for storing/retrieving color and alpha values to/from integers:

integer ColorAlphatoRGBA(vector color, float alpha) {
return (((integer)(alpha * 255.0) & 0xFF) << 24) |
(((integer)(color.x * 255.0) & 0xFF) << 16) |
(((integer)(color.y * 255.0) & 0xFF) << 8) |
((integer)(color.z * 255.0) & 0xFF);
}

vector RGBAtoColor(integer rgba) {
return < ((rgba >> 16) & 0xFF) / 255.0, ((rgba >> 8) & 0xFF) / 255.0, (rgba & 0xFF) / 255.0 >;
}

float RGBAtoAlpha(integer rgba) {
return ((rgba >> 24) & 0xFF) / 255.0;
}
Haruki Watanabe
llSLCrash(void);
Join date: 28 Mar 2007
Posts: 434
09-11-2007 03:34
guys, I guess I give up scripting... when I look at this, I feel like a complete idiot who has no idea about programming... ;)

Thanks again for your help!!!