Difference between revisions of "LlSetColor"

From Second Life Wiki
Jump to navigation Jump to search
(add caveats about PBR)
 
(8 intermediate revisions by 5 users not shown)
Line 1: Line 1:
{{LSL Function/color|color}}{{LSL_Function/face|face|}}
{{LSL_Function
{{LSL_Function
|inject-2={{LSL Function/color|color}}{{LSL_Function/face|face|}}
|func_id=49|func_sleep=0.0|func_energy=10.0
|func_id=49|func_sleep=0.0|func_energy=10.0
|func=llSetColor
|func=llSetColor
|p1_type=vector|p1_name=color|p2_type=integer|p2_name=face
|p1_type=vector|p1_name=color|p2_type=integer|p2_name=face
|func_footnote
|func_footnote
|func_desc=Sets the '''color''' on '''face'''
|func_desc=Sets the [[PBR_Materials#Nomenclature_changes|Blinn-Phong]] {{LSLP|color}} on {{LSLP|face}} of the prim.
|return_text
|return_text
|spec
|spec
|caveats
|caveats=
* llSetColor will have no visible effect on faces with a PBR material. To work on faces both with and without a PBR material, use this snippet: <source lang="lsl2">
llSetColor(color, ALL_SIDES);
llSetLinkPrimitiveParamsFast(LINK_THIS, [PRIM_GLTF_BASE_COLOR, ALL_SIDES, "", "", "", "", llsRGB2Linear(color), "", "", "", ""]);
</source>
|constants
|constants
 
|examples=<source lang="lsl2">
<b>NewbieNotes</b>
llSetColor changes the color of a prim, either on a specific side (face) or the entire prim.
Example:  llSetColor(<r,g,b>,ALL_SIDES);
r,g,b:  values for red, green, blue ranging from <0.0,0.0,0.0> (black) to <1.0,1.0,1.0> (white)
Since this is a vector value, be sure to include the <>.
Example color values:  <1.0,1.0,0> = yellow  <0.0,1.0,1.0> = cyan  <0,1,0> = green
ALL_SIDES means all sides of the prim will be changed to the new color.
If you use an integer value instead, only that side of the prim will be changed
Example:  A cube has 6 sides, with values from 0 to 5.  llSetColor(<1,1,1>,0); would change the top side of the cube to white.
 
 
|examples=<lsl>
integer face = -1;
integer face = -1;
vector color = <1.0, 1.0, 1.0>;
vector color = <1.0, 1.0, 1.0>;
Line 30: Line 22:
     touch_start(integer num)
     touch_start(integer num)
     {
     {
         if(~face)//quick & dirty check for -1
         if(~face)       //quick & dirty but efficient way of testing if face is not equal to -1
             llSetColor(color, face); //restore the color
             llSetColor(color, face); //restore the color
         face = (face + 1) % llGetNumberOfSides(); //increment and keep the face number in range
         face = (face + 1) % llGetNumberOfSides(); //increment and keep the face number in range
         color = llGetColor(face); //save the face's color
         color = llGetColor(face); //save the face's color
         llSetColor(<0.5, 0.0, 0.0>, face );//change the face's color
         llSetColor(<0.5, 0.0, 0.0>, face ); //change the face's color
     }
     }
}
}
</lsl>
</source>
|helpers
|helpers=
{{{!}} class="sortable" {{Prettytable}}
{{!}}- {{Hl2}}
! Color
! Hexadecimal code
! LSL color representations
{{!}}-
{{!}} style="color: white; background: #001f3f" {{!}}NAVY
{{!}} #001f3f
{{!}}<code><0.000, 0.122, 0.247></code>
{{!}}-
{{!}} style="background: #0074d9" {{!}}BLUE
{{!}} #0074d9
{{!}}<code><0.000, 0.455, 0.851></code>
{{!}}-
{{!}} style="background: #7fdbff" {{!}}AQUA
{{!}} #7fdbff
{{!}}<code><0.498, 0.859, 1.000></code>
{{!}}-
{{!}} style="background: #39cccc" {{!}}TEAL
{{!}} #39cccc
{{!}}<code><0.224, 0.800, 0.800></code>
{{!}}-
{{!}} style="background: #3d9970" {{!}}OLIVE
{{!}} #3d9970
{{!}}<code><0.239, 0.600, 0.439></code>
{{!}}-
{{!}} style="background: #2ecc40" {{!}}GREEN
{{!}} #2ecc40
{{!}}<code><0.180, 0.800, 0.251></code>
{{!}}-
{{!}} style="background: #01ff70" {{!}}LIME
{{!}} #01ff70
{{!}}<code><0.004, 1.000, 0.439></code>
{{!}}-
{{!}} style="background: #ffdc00" {{!}}YELLOW
{{!}} #ffdc00
{{!}}<code><1.000, 0.863, 0.000></code>
{{!}}-
{{!}} style="background: #ff851b" {{!}}ORANGE
{{!}} #ff851b
{{!}}<code><1.000, 0.522, 0.106></code>
{{!}}-
{{!}} style="background: #ff4136" {{!}}RED
{{!}} #ff4136
{{!}}<code><1.000, 0.255, 0.212></code>
{{!}}-
{{!}} style="color: white; background: #85144b" {{!}}MAROON
{{!}} #85144b
{{!}}<code><0.522, 0.078, 0.294></code>
{{!}}-
{{!}} style="background: #f012be" {{!}}FUCHSIA
{{!}} #f012be
{{!}}<code><0.941, 0.071, 0.745></code>
{{!}}-
{{!}} style="color: white; background: #b10dc9" {{!}}PURPLE
{{!}} #b10dc9
{{!}}<code><0.694, 0.051, 0.788></code>
{{!}}-
{{!}} style="background: #ffffff" {{!}}WHITE
{{!}} #ffffff
{{!}}<code><1.000, 1.000, 1.000></code>
{{!}}-
{{!}} style="background: #dddddd" {{!}}SILVER
{{!}} #dddddd
{{!}}<code><0.867, 0.867, 0.867></code>
{{!}}-
{{!}} style="background: #aaaaaa" {{!}}GRAY
{{!}} #aaaaaa
{{!}}<code><0.667, 0.667, 0.667></code>
{{!}}-
{{!}} style="color: white; background: #111111" {{!}}BLACK
{{!}} #111111
{{!}}<code><0.067, 0.067, 0.067></code>
{{!}}}
|also_functions=
|also_functions=
{{LSL DefineRow||[[llGetAlpha]]|Gets the prim's alpha}}
{{LSL DefineRow||[[llGetAlpha]]|Gets the prim's alpha}}
Line 45: Line 111:
{{LSL DefineRow||[[llSetLinkColor]]|Sets link's color}}
{{LSL DefineRow||[[llSetLinkColor]]|Sets link's color}}
{{LSL DefineRow||[[llSetLinkAlpha]]|Sets link's alpha}}
{{LSL DefineRow||[[llSetLinkAlpha]]|Sets link's alpha}}
{{LSL DefineRow||[[PRIM_COLOR]]|The equivilant parameter for [[llSetPrimitiveParams]]}}
{{LSL DefineRow||[[PRIM_GLTF_BASE_COLOR]]|The equivilant PBR parameter for [[llSetPrimitiveParams]]}}
|also_tests
|also_tests
|also_events=
|also_events=
{{LSL DefineRow||[[changed]]|[[CHANGED_COLOR]]}}
{{LSL DefineRow||[[changed]]|[[CHANGED_COLOR]]}}
|also_articles
|also_articles=
{{LSL DefineRow||[[Color and Scripting]]}}
|notes
|notes
|deprecated
|deprecated

Latest revision as of 15:28, 11 December 2024

Summary

Function: llSetColor( vector color, integer face );
0.0 Forced Delay
10.0 Energy

Sets the Blinn-Phong color on face of the prim.

• vector color color in RGB <R, G, B> (<0.0, 0.0, 0.0> = black, <1.0, 1.0, 1.0> = white)
• integer face face number or ALL_SIDES

If face is ALL_SIDES then the function works on all sides.

Newbie Notes

llSetColor changes the color of a prim, either on a specific side (face) or the entire prim.

Example:
llSetColor(<r, g, b>, ALL_SIDES);

r, g, b: values for red, green, blue ranging from <0.0, 0.0, 0.0> (black) to <1.0, 1.0, 1.0> (white)

To continue reading see: Newbie Notes

Caveats

  • The function silently fails if its face value indicates a face that does not exist.
  • llSetColor will have no visible effect on faces with a PBR material. To work on faces both with and without a PBR material, use this snippet:
    llSetColor(color, ALL_SIDES);
    llSetLinkPrimitiveParamsFast(LINK_THIS, [PRIM_GLTF_BASE_COLOR, ALL_SIDES, "", "", "", "", llsRGB2Linear(color), "", "", "", ""]);
    

Examples

integer face = -1;
vector color = <1.0, 1.0, 1.0>;

default
{
    touch_start(integer num)
    {
        if(~face)       //quick & dirty but efficient way of testing if face is not equal to -1
            llSetColor(color, face); //restore the color
        face = (face + 1) % llGetNumberOfSides(); //increment and keep the face number in range
        color = llGetColor(face); //save the face's color
        llSetColor(<0.5, 0.0, 0.0>, face );  //change the face's color
    }
}

Useful Snippets

Color Hexadecimal code LSL color representations
NAVY #001f3f <0.000, 0.122, 0.247>
BLUE #0074d9 <0.000, 0.455, 0.851>
AQUA #7fdbff <0.498, 0.859, 1.000>
TEAL #39cccc <0.224, 0.800, 0.800>
OLIVE #3d9970 <0.239, 0.600, 0.439>
GREEN #2ecc40 <0.180, 0.800, 0.251>
LIME #01ff70 <0.004, 1.000, 0.439>
YELLOW #ffdc00 <1.000, 0.863, 0.000>
ORANGE #ff851b <1.000, 0.522, 0.106>
RED #ff4136 <1.000, 0.255, 0.212>
MAROON #85144b <0.522, 0.078, 0.294>
FUCHSIA #f012be <0.941, 0.071, 0.745>
PURPLE #b10dc9 <0.694, 0.051, 0.788>
WHITE #ffffff <1.000, 1.000, 1.000>
SILVER #dddddd <0.867, 0.867, 0.867>
GRAY #aaaaaa <0.667, 0.667, 0.667>
BLACK #111111 <0.067, 0.067, 0.067>

See Also

Events

•  changed CHANGED_COLOR

Functions

•  llGetAlpha Gets the prim's alpha
•  llSetAlpha Sets the prim's alpha
•  llGetColor Gets the prim's color
•  llSetLinkColor Sets link's color
•  llSetLinkAlpha Sets link's alpha
•  PRIM_COLOR The equivilant parameter for llSetPrimitiveParams
•  PRIM_GLTF_BASE_COLOR The equivilant PBR parameter for llSetPrimitiveParams

Articles

•  Color in LSL
•  Color and Scripting

Deep Notes

Signature

function void llSetColor( vector color, integer face );