Freitag, 9. April 2010

Generic preprocessor in use

Now the second step, equiping of the real attachments with TASC processor and preporocessor generically. We want to use the script system instead of common resizers. There are two sorts of attachments where that resizers are known to produce lag, the boots and hair styles. Reason: Those attachments are prim-intensive and as the resizer script must reside in each prim, the solutions are also script-intensive. To avoid that problem the resizer script must offer their removal possibility, and some versions actually do.

But back to topic. We want test the TASC processor system in practice. To do that we link two attachments to a single atached object and teach the processor system to handle individually the prims that belong prevously to each attachment.

1. Building the model

For this project i decided for a pretty hair style and a nice hair flower. After linking them together (the hair remains root, this avoids the afterlink adjustmends) and wearing the style i look like that:
Picture 1: The hair linked with red flower,
Hair: "VIVIEN ponytail" by Mirja Mills
Flower: "Full Perm Flower Sculpty for Builder" by Gumi Yao

The hair style: "VIVIEN ponytail", the vendor you will find by SAVOIR hair, or visit the main shop with very many other hair styles. The rose you find as product at XStreetSL, or inworld in the shop as well.

The hair is mod and copy, so we can work on the copy, that is always important, the hair is not scripted, so we must not destroy any build-in functionality by installing our scripts. The rose is even full-perm and has two more advantages: It is a single prim and uses a grayscale texture. That allow us to easilly change the flower color in future.

2. Installing the procesor system

Now we have to install the processor scritp "macs.processor.tasc" in every prim of our model. The attachment has over 100 Prims, so placing it manually will not work good, thus we use the distributor. To do that we look into the TASC package and open the resources box. We take the processor and distributor scripts from it and place in this order into the root prim of the model.

After few seconds the distributor script tells to restart the processors. To do that we pick the hair from the world (or detach) and rezz it again (or attach) than edit and hit the menu "Tools" / "Set Scripts Running in Selection" of the viewer. A windows opens and fills with "Runing macs.processor.tasc" entries. After a minute the "Close" buttons becomes active, we click it and are ready with processors.

Next part: the preprocessor script. We take first the script from the last post and put it into the root prim of the hair style without any changes. Now we get the known menu if we touch the hair. Rescalling "(all prims)"  changes the size of the hair inclusive the rose, if we touch the rose first and select "(this)", we can rescale the rose only.

That was quite easy but it can not be all.

3. Grouping prims

To make the processor system to distinct between prims that belong prevously to the hair and rose, we have to put the prim in two groups. We do that by setting the prim description. The only prim of the rose will get the description "flower", and each prim of the hair must get the description "hair". That seems not to be easy with the number of hair prims but we have LSL to do that. All we need is this script:

//--------------------------------------------------------
// Description synchronizer. Usage:
//
// 1. Put into the root prim of your object.
// 2. The script distributes itself to every child prim
//    and deletes itself from the root prim.
// 3. Pick up the object from the world or detach if
//    attachment.
// 4. Rezz the object inworld or attach again.
// 5. Edit the object and set its description as required.
// 6. While the edit window is open, go to the viewer menu,
//    and hit the menu "Tools" / "Set Scripts to Running
//    in Selection".
//    The scripts in all child prim take over the
//    description of the root prim and delete themselves.
//--------------------------------------------------------
default {
    state_entry() {
        string name = llGetScriptName();
  
        if (llGetLinkNumber() == 1) {
            integer i;
   
            for (i = llGetNumberOfPrims() ; i > 1 ; --i) {
                llGiveInventory(llGetLinkKey(i), name);
            }
   
            llOwnerSay("::: Please rerezz or reattach me and "+
                "restart all Scripts via Tools menu");
        }

        else {
            key root = llGetLinkKey(1);
            if (root != NULL_KEY) {
                list det = [OBJECT_DESC];
                det = llGetObjectDetails(root, det);
                llSetObjectDesc(llList2String(det, 0));
            }
        }

        llRemoveInventory(name);
    }
}

The script comment says what to do: put the script into the root prim, than pick the hair up / detach, than rezz or attach it again, change the description of the root prim to "hair" and set the scripts running in same way as done with the processors. We can check now, the description is taken over and set to every prim.

Although this way works fine, in the future it might be a good idea to synchronize the prims description with this script before the processor scripts are installed. Because than the number of scripts installed into the object is smaller.

Ok, the rose has got now a 'wrong' description, we put it into the "hair" group by giving all prims same description. We have to change it's description to "flower" manually and rerezz the hair, as the processor script reads the prims description only while rezzing or attaching of the object. After this is done we are ready with the item, too.

What is the sense of grouping prims we did? The prim group is noted in the prim description. This field is read by the processor script running in the prim. The preprocessor script will send a command saying something like "please change the size of every prim belonging to the group 'hair' by the factor 1.1". Every prim that has the description 'hair' is in this group, so the command will affect the prim. I described the processor commands more closelly in the messages tutorial earlier.

Step 3. Registering groups by the preprocessor

The prims are grouped but the preprocesor script does not know anything about it. But this part is quite simple: Just open the script and look for this line:

list    PRIM_GROUPS    = [];

It is only the place to change. Namelly in this:

list    PRIM_GROUPS    = ["hair", "flower"];

After the script is saved and recompiled, it knows now both prim groups.

4. Processor system in action

The main menu changes now, and we can select and rescale any group of prims individually, even the 100 prims of the hair are rescaled with one click, leaving the flower unchanged and vice versa.
Picture 2: Preprocessor menus with registered prim groups

Notice that the prim groups are now shown in the main menu, and we also have two more resize menus: The resize menus for "(this prim)" and "(all prims)" we know already, but now we have also new menus for "hair" and "flower" prim groups.

5. Script removal

What hapens if we hit the "(clean)" button in main menu? Nothing seems to hapen, just the hair says something like

[17:15]  VIVIEN ponytail: ::: Removing processor scripts...
[17:15]  VIVIEN ponytail: ::: Removing process complete

Actuallly if we would look into the prims of the hair, we will see that processor scripts given prevously to every child prim are now gone. Only one in the root prim remains. This means that the hair became very lag-friendly,  but also that we are no more able to resize the hair before we reinstall the processor script into the hair prims.

But this time it goes automatically. All we need is to touch the hair. The preprocessor script knows the processors are cleaned, thus it tells the remained processor script to give itself to every prim of the hair. The script says than this:

[17:16]  VIVIEN ponytail: ::: Installing processor scripts...

and starts the job. No more reattaching, no manual starting of the scripts. But there is a prize we have to pay for this service and lag reduction: LSL makes a restriction that installing running scripts this way takes 3 seconds per prim. Reinstalling the scripts into our 100 prim hair takes about 5 minutes! Time to take a break. Drink coffee or do something else usefull around the computer.

While script installation we can see a progress bar as a hover text above the hair style. As soon the job is ready we read also this line in chat:

[17:21]  VIVIEN ponytail: ::: Installing process complete

Now our model behaves as if nothing hapened. Actually we are ready with the second step. But i have something for you before to start with the last one...

A homework for you

There are some tasks helpfull for understanding what we'll do in the next tutorial. Especially if you are a scripter.

Task 1: Find a hair style and accessory similar to used in this post.

You must not take the same, but perhaps you find something else adequate. Both, the hair and accessory must match and it should be possibly to change the accessory color very easy.

Task 2: Reproduce the tutorial step by step.

You must not have exactly the same prim group names but if you take others, remember and use the new names.

Further tasks are rather for scripters under us.

Task 3: Add two constants that deactivate the "(all)" and "(this)"  buttons in main menu.

If working with prim groups, at least the "(this)" button becomes obsolete. Using constants that activate or deactivate them is more developer-friendly. But think also about hiding the button description in the menu text.

Task 4: Add a installation menu that appears if the hair is touched and the scripts are cleaned out.

Reason: For lag minimization you will have to clean out the procesor scripts. An occasional touching the hair would start reinstalling of the scripts even in a club or whereever you do not need it. A menu asking if to start the installation process will prevent it.

Task 5: Find out the processor command syntax for setting transparency and color of prims.

In the next step we will hide the flower and change it's color via preprocessor menu. Somewhere in MACS tutorials is denoted how that commands should look like. If you do not find the place, i will describe that next time anyway.

See you at the next post

Keine Kommentare:

Kommentar veröffentlichen