Jump to content

Texture Changer by Channel (for unlinked objects)


Britt32 Beck
 Share

You are about to reply to a thread that has been inactive for 1398 days.

Please take a moment to consider if this thread is worth bumping.

Recommended Posts

The non-linked objects will need a listener script inside them. It's not hard to make and you do not need different channels for that.

You did not mention if you intend to have the same faces changed each time, or is you need to change face 1, then face 2, etc. but here's how you would do it:

  • You make a sender and a listener script, you will then have one sender object, and multiple listener objects.
  • In the sender object you make the decision which face needs to be changed and to which texture it needs to change. Based on this you create a string based on the face and the texture, it would read something like this "2#01234567-89ab-cdef-0123-456789abcdef" where the hash sign is the separator (this separator can be any character you like).
  • The listener script then separates the face from the texture ID and applies it to the object.

You can include more information in the string that you send, like full bright, the color of the face, glow, etc. You just need to make sure that this information it always in the same spot in the string or at a marker to identify the parameter but that's it.

Link to comment
Share on other sites

Hello there Britt32 Beck!
I wrote some utility scripts for you.
I hope these will set you on the right track.

TASK 01: FIND FACE IDS
===================
If you want to change texture on a face of an object, first you need to find out the ID of the target face. If you paste the following code to an object
& click on any of the faces, the script will output the ID of the face.
You will need to use this ID when you write the texture applier script.
 

default
{
    touch_end(integer n)
    {
        integer face = llDetectedTouchFace(0);
        llOwnerSay("face id => " + (string)face);
    }
}

 

TASK 02: SET UP LISTENERS
=======================

Okay, once you find out which face ids you're targeting its time to
write the script which actually receives your commands, thus the
names (or ids) of the textures (you want to apply) and the
faces you want to use for those textures.
If your objects are not linked you need to set up "Listeners" in each object
so they can receive commands from an object which sends the instructions to them.

The core idea is to set up a "Listener" on a specific channel
and send information from a "Sender" to that channel with special commands designed to make your object behave in a way you wish to
(in this case, commands relate to the texture you want to apply).
Once you receive the "message" in the "Listener" you set up conditions,
to make sure things work out the way expected.

If you paste the following code to an object & click on the object,
it will create a listener for you & display notices.

Next, if you type into your chat window:
/-5 t1

You essentially say, send this message at channel -5 and say t1.
t1 doesn't make a lot of sense from the first glance (because I made it up) but it represents a shorter version for texture_01.
Anyway if you keep sending messages to this channel, it should display the feedback in your "debugger" window.
 

integer gListenerA;
integer gChannelA    = -5;
string textureName01 = "Texture name 01";
string textureName02 = "Texture name 02";
string textureName03 = "Texture name 03";

default
{

    // touch the object and it will create a listener
    touch_end(integer n)
    {
        gListenerA = llListen(gChannelA, "", llGetOwner(), "");
        llOwnerSay("listening at channel => " + (string)gChannelA);
    }

    // listen at channel gChannelA (-5)
    listen(integer channel, string name, key id, string message)
    {

        if (message == "t1")
        {
            llOwnerSay("apply texture => " + textureName01);
        }
        else if (message == "t2")
        {
            llOwnerSay("apply texture => " + textureName02);
        }
        else
        {
            llOwnerSay("unknown texture name => " + message);
        }

    }

}

 

TASK 03: TEXTURE NAMES
======================

Okay, so (hopefully) now you can detect faces ids and you have some basic
understanding of how listeners may work. It's time to take a look at texturing with LSL.

Luckily, it's quite simple, to apply a texture to an object you will need to know two things,
the name of the texture you want to apply and the face id of the object.

If you want to make this one work, you need to place the texture
you want to apply to the inventory of the object,
and you need to change the textureName variable to match your texture's name.
 

default
{
    touch_end(integer n)
    {
        string textureName = "Concrete 03";
        integer faceId     = 0;
        llSetTexture(textureName, faceId);
    }
}

 

TASK 04: BRINGING ALL TOGETHER
=============================

So now you should know:
- how to detect faces,
- how to set up listeners on specific channels
- how to change textures on an object

All we miss is to combine everything together and create a sender object
which sends the commands to your listener object.
Plus we need to extend your listener to apply the textures, but that's easy.
 

integer gListenerA;
integer gChannelA     = -5;
string gTextureName01 = "Texture name 01";
string gTextureName02 = "Texture name 02";
string gTextureName03 = "Texture name 03";

default
{

    // touch the object and it will create a listener,
    touch_end(integer n)
    {
        gListenerA = llListen(gChannelA, "", llGetOwner(), "");
        llOwnerSay("listening at channel => " + (string)gChannelA);
    }

    // listen at channel gChannelA (-5)
    listen(integer channel, string name, key id, string message)
    {

        if (message == "t1")
        {
            string textureName = gTextureName01;
            integer faceId     = 1;
            llSetTexture(textureName, faceId);
        }
        else if (message == "t2")
        {
            string textureName = gTextureName02;
            integer faceId     = 2;
            llSetTexture(textureName, faceId);
        }
        else
        {
            llOwnerSay("unknown texture name => " + message);
        }

    }

}

 

STEP 01
=======

Place the face detector script to the object you want to texture.
Find out the face ID you're targeting by touching the object.
Write down the face ID.

STEP 02
=======

Replace the face detector script with the listener script
and extend it with the texture applier (llSetTexture) function.
Make sure your object has the required textures in it's inventory & you properly pasted the names of each texture to the gTextureName* variables.

STEP 03
=======

Create a "Sender" object which sends commands to your "Listener" or "Listeners".
 

integer gChannelA = -5;

default
{
    touch_end(integer n)
    {
        llRegionSay(gChannelA,"t1");
    }
}

 

SUM
====

And that's it basically.
Of course we're just scratching the surface here, and there are
many many aspects of these scripts we could (and should) improve since
they're not so efficient. But my goal was to provide you with enough information to get started with some experimentation of your own.
So if you're looking for further advices post your code on the forums and the community with help you out.

Cheers
Eth3l
 

REFERENCES:
===========

http://wiki.secondlife.com/wiki/LlSetTexture
http://wiki.secondlife.com/wiki/LlListen
http://wiki.secondlife.com/wiki/LlDetectedTouchFace
http://wiki.secondlife.com/wiki/LlRegionSay
http://wiki.secondlife.com/wiki/LlOwnerSay

  • Like 1
  • Thanks 1
Link to comment
Share on other sites

Thank you for the very detailed reply, much appreciated. Does this technique work on a menu? I need the user to be able to call up a blue menu that has all of the color options available for them to choose from. 

 

Thank you again, that was way more than I expected. 

Link to comment
Share on other sites

You're welcome.
The "Blue menu" is called a dialog box.
It's very similar to our "Listener" unit.

I created a slightly modified version of the "Listener" script
to give you an idea about this one.

I hope this helps!
 

integer gListenerA;
integer gChannelA     = -5;
string gTextureName01 = "Texture name 01";
string gTextureName02 = "Texture name 02";
string gTextureName03 = "Texture name 03";

default
{

    // touch the object and it will create a listener
    touch_end(integer n)
    {

        // get the UUID of the person touching this prim
        // we will need this when we call the dialog box
        key userKey = llDetectedKey(0);

        // set up listener
        gListenerA = llListen(gChannelA, "", userKey, "");

        // store the dialog message & list of options
        string dialogMessage = "Choose color please.";
        list dialogOptions = ["color_01", "color_02"];

        // create the dialog
        llDialog(userKey, dialogMessage, dialogOptions, gChannelA);

    }

    // listen at channel gChannelA (-5)
    listen(integer channel, string name, key id, string message)
    {

        if (message == "color_01")
        {
            string textureName = gTextureName01;
            integer faceId     = 1;
            llSetTexture(textureName, faceId);

        }
        else if (message == "color_02")
        {
            string textureName = gTextureName02;
            integer faceId     = 2;
            llSetTexture(textureName, faceId);
        }
        else
        {
            llOwnerSay("unknown texture name => " + message);
        }

    }

}

 

REFERENCES
===========

http://wiki.secondlife.com/wiki/LlDialog
http://wiki.secondlife.com/wiki/LlDetectedKey

 

Link to comment
Share on other sites

You are about to reply to a thread that has been inactive for 1398 days.

Please take a moment to consider if this thread is worth bumping.

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
 Share

×
×
  • Create New...