Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- //##############################################################################
- //
- // Simply:PBRTextureUpdater v0.2
- //
- // Since the inception of PBR Materials, builders have complained about missing
- // functions to easily set the Alpha and Color of PBR materials.
- //
- // These included functions are designed to make life easier for builders and scripters
- //
- // These are free scripts, designed by me, and you can use them in any way you like.
- // Use them in your scripts, your builds, modify them, whatever you like.
- //
- // Just don't sell them as is.
- //
- // Dorex Delicioso 2024
- //
- // YouTube: https://www.youtube.com/@SecondLifeSimplyScripting
- // Marketplace: https://marketplace.secondlife.com/stores/173632
- //
- //##############################################################################
- //##############################################################################
- //##############################################################################
- //
- // Main Functions
- //
- // setPBRAlpha(alpha, face)
- // setPBRColor(color, face)
- // setPBRLinkAlpha(link, alpha, face)
- // setPBRLinkColor(link, color, face);
- //
- //##############################################################################
- //##############################################################################
- setPBRAlpha(float alpha, integer face){
- //
- // sets the alpha value for PBR material on one or more faces
- //
- setPBRData(LINK_THIS , face, alpha, <0,0,0> , "Alpha");
- }
- setPBRColor(vector color, integer face){
- //
- // sets the color value for PBR material on one or more faces
- //
- setPBRData(LINK_THIS , face, 0, color , "Color");
- }
- setPBRLinkAlpha(integer link, float alpha, integer face){
- //
- // sets the alpha value for a PBR material on one or more faces on a specified link or all links
- //
- setPBRData(link, face, alpha, <0,0,0> , "Alpha");
- }
- setPBRLinkColor(integer link, vector color, integer face){
- //
- // sets the color tint value for a PBR material on one or more faces on a specified link or all links
- //
- setPBRData(link, face, 0, color , "Color");
- }
- //##############################################################################
- //##############################################################################
- //
- // Helper Scripts
- //
- //##############################################################################
- //##############################################################################
- setPBRData(integer link, integer face, float alpha, vector color, string changeType){
- //
- // this is just a helper function, the ugly starts here
- //
- integer stride = 9; // number of values returned for each face
- list params;
- integer startLink = link;
- integer endLink = link;
- if (startLink == LINK_SET){
- startLink = !!llGetLinkNumber();
- endLink = llGetObjectPrimCount(llGetKey());
- }
- integer alphaMode = PRIM_GLTF_ALPHA_MODE_OPAQUE;
- if (alpha < 1.0){
- alphaMode = PRIM_GLTF_ALPHA_MODE_BLEND;
- }
- for( ; startLink <= endLink; ++startLink){
- //
- // to set a PBR value without losing other data, we have read all settings first, then change only what we want
- // while that's not 'always' exactly true, it's safer to assume it is.
- // we read PRIM_GLTF_BASE_COLOR once per link
- //
- list details = llGetLinkPrimitiveParams(startLink, [PRIM_GLTF_BASE_COLOR, ALL_SIDES ]);
- //
- // return values for each face for PRIM_GLTF_BASE_COLOR
- // texture, repeats, offsets, rotation_in_radians, color, alpha, gltf_alpha_mode, alpha_mask_cutoff, double_sided
- // texture, repeats, offsets, rotation_in_radians, color, alpha, gltf_alpha_mode, alpha_mask_cutoff, double_sided
- // etc
- //
- integer startFace = face;
- integer endFace = face + 1;
- if (startFace == ALL_SIDES ){
- startFace = 0;
- endFace = llGetLinkNumberOfSides(startLink);
- }
- params += [PRIM_LINK_TARGET, startLink];
- for( ; startFace < endFace; ++startFace){
- //
- // set the start parameter and face number
- //
- params += [PRIM_GLTF_BASE_COLOR, startFace];
- if (changeType == "Alpha"){
- //
- // we're changing the alpha value
- // take the first 5 values up to alpha for this face
- //
- params += llList2List(details, (startFace * stride), (startFace * stride) + 4);
- //
- // add alpha and alphaMode for this face
- //
- params += [alpha, alphaMode];
- //
- // add the last 2 values for this face
- //
- params += llList2List(details, (startFace * stride) + 7, (startFace * stride) + 8);
- } else if (changeType == "Color"){
- //
- // we're chaning the color value
- // take the first 4 values up to color for this face
- //
- params += llList2List(details, (startFace * stride), (startFace * stride) + 3);
- //
- // add the color for this face
- //
- params += [color];
- //
- // add the last 4 values for this face
- //
- params += llList2List(details, (startFace * stride) + 5, (startFace * stride) + 8);
- }
- }
- }
- llSetLinkPrimitiveParamsFast(1, params);
- }
- default
- {
- touch_start(integer total_number)
- {
- llOwnerSay((string)llGetUsedMemory());
- //
- // Uncomment each function call one at a time and touch the linkset to run the script
- //
- // for single prims
- //
- // {alpha 0.0 = transparent => 1.0 = opaque}, {face # or ALL_SIDES}
- // setPBRAlpha(1, 0 );
- //
- // {color}, {face # or ALL_SIDES}
- // setPBRColor(<1, 1, 1>, 0 );
- //
- // for linksets
- //
- // {Link # or LINK_SET} ,{alpha 0 == transparent => 1.0 = opaque}, {face number or ALL_SIDES}
- // setPBRLinkAlpha(LINK_SET , 1.1, ALL_SIDES );
- //
- // {Link # or LINK_SET}, {color}, {face number or ALL_SIDES}
- setPBRLinkColor(LINK_SET, <1, 0, 0> , 0);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement