Don't click here unless you want to be banned.

LSL Wiki : LibraryPreloadTextures

HomePage :: PageIndex :: RecentChanges :: RecentlyCommented :: UserSettings :: You are crawl423.us.archive.org

Preloading Textures

by Sendao Goodman

So, textures load slow, and it's especially obvious when giving a presentation or showing pictures to your friends.

Here's an easy fix.

How do you use this script?

1) Drop it in a box.
2) Adjust the box size/shape to match your desire; the non-black face will be used for textures
3) Drop in whatever pictures you like

//--------------------------
// preloads textures on a box
// just drop it in with the images and it will cycle every 10 seconds, or change the picture_pace variable to change the speed
// updates on touch as well
//--------------------------

// Change this next line to adjust the image rotation speed
float picture_pace=10.0;

// Sendao Goodman, 2007

integer reload;
list pictures;
integer slideno;

loadPictures()
{
    pictures=[];
    integer i = llGetInventoryNumber(INVENTORY_TEXTURE);
    if( i > 0 ) {
        while( i > 0 ) {
            i--;
            pictures=(pictures=[])+pictures+[llGetInventoryName(INVENTORY_TEXTURE,i)];
        }
        llOwnerSay((string)llGetListLength(pictures)+" pictures loaded");
        pictures = llListSort( pictures, 1, TRUE ); // put them in order
        llSetTimerEvent(picture_pace);
    } else if( reload == 0 ) {
        llSetTimerEvent(0.0);
    }
}

string getSlide(integer slide)
{
    return llList2String( pictures, (slide+llGetListLength(pictures))%llGetListLength(pictures) );
}

default
{
    on_rez(integer sp)
    {
        loadPictures();
        slideno=0;
        reload=0;
    }
    state_entry()
    {
        loadPictures();
        slideno=0;
        reload=0;
        llSetColor( <0,0,0>, 0 );
        llSetColor( <0,0,0>, 1 );
        llSetColor( <1,1,1>, 2 );
        llSetColor( <0,0,0>, 3 );
        llSetColor( <0,0,0>, 4 );
        llSetColor( <0,0,0>, 5 );
    }
    
    changed( integer ch )
    {
        if( ch & CHANGED_INVENTORY ) {
            reload=1;
            llSetTimerEvent(2.0);
        }
    }

    touch_start(integer nd)
    {
        if( llGetListLength(pictures) > 0 ) {
            integer i=6;
            while( i > 0 ) {
                i--;
                llSetTexture( getSlide(slideno+(i-2)), i);
            }
            slideno = (slideno+1)%llGetListLength(pictures);
        }
    }        

    
    timer()
    {
        if( reload == 1 ) {
            reload = 0;
            loadPictures();
            return;
        }
        integer i=6;
        while( i > 0 ) {
            i--;
            llSetTexture( getSlide(slideno+(i-2)), i);
        }
        slideno = (slideno+1)%llGetListLength(pictures);
    }
}

ScriptLibrary
Comments [Hide comments/form]
Attach a comment to this page: