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

LSL Wiki : LibraryDumpPrimParameters

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

DumpPrimParameters


This script dumps prim params to a string, which can then be used to recreate settings in code. It also tries to substitute values with constants.

The script only deals with a subset of available params, so please add to this code whenever you implement more of them.
Added support for Flexis Special:Contributions/BartleeArai

// Playahead DumpPrimParams - dump current object prim parameters to LSL list string
// This code is free to copy and modify as long as this header remains intact.
// It would also be prudent to update this script with additions and bug fixes.

string vectorToString( vector val )
{
    if( val == ZERO_VECTOR )
    {
        return "ZERO_VECTOR";
    }
    else
    {
        string dump = "<"+floatToString( val.x )+", "+floatToString( val.y )+", "+floatToString( val.z )+">";
        
        return dump;
    }
}

string floatToString( float val )
{
    integer round = llFloor( val );
    if( val == (float) round )
    {
        return (string)round + ".0";
    }
    else
    {
        return (string) val;
    }
}

string parseListToCSV( list l )
{
    string result;
    integer c = llGetListLength( l );
    integer last = c - 1;
    integer i;
    
    for( i=0; i < c; i++ )
    {
        string strval;
        
        integer entryType = llGetListEntryType( l, i );
        
        if( entryType == TYPE_FLOAT )
        {
            strval = floatToString( llList2Float( l, i ) );
        }
        else
        if( entryType == TYPE_INTEGER )
        {
            integer val = llList2Integer( l, i );
            strval = (string) val;
        }
        else
        if( entryType == TYPE_KEY )
        {
            key val = llList2Key( l, i );
            if( val == NULL_KEY )
            {
                strval = "NULL_KEY";
            }
            else
            {
                strval = (string) val;
            }
        }
        else
        if( entryType == TYPE_ROTATION )
        {
            rotation val = llList2Rot( l, i );
            if( val == ZERO_ROTATION )
            {
                strval = "ZERO_ROTATION";
            }
            else
            {
                strval = (string) val;
            }
        }
        else
        if( entryType == TYPE_STRING )
        {
            string val = llList2String( l, i );
            strval = "\"" + val + "\"";            
        }
        else
        if( entryType == TYPE_VECTOR )
        {
            strval = vectorToString( llList2Vector( l, i ) );        
        }
        
        result += strval;
        
        if( i != last )
        {
            result += ", ";
        }
    }
    
    return result;
}

string AddParam( integer getId, string setName )
{
    string dump;
    
    list params = llGetPrimitiveParams( [ getId ] );
    
    dump = setName + ", " + parseListToCSV( params );
    
    return dump;
}

string AddTypeParam( )
{
    list types = [ "PRIM_TYPE_BOX", "PRIM_TYPE_CYLINDER", "PRIM_TYPE_PRISM",  "PRIM_TYPE_SPHERE", "PRIM_TYPE_TORUS", "PRIM_TYPE_TUBE", "PRIM_TYPE_RING" ];

    string dump;
    
    list params = llGetPrimitiveParams( [ PRIM_TYPE ] );
    
    integer type = llList2Integer( params, 0 );

    params = llDeleteSubList( params, 0, 0 );
    
    dump = "PRIM_TYPE, " + llList2String( types, type ) + ", " + parseListToCSV( params );
    
    return dump;
}

string AddFlexibleParam( )
{
    string dump;
    list params = llGetPrimitiveParams( [ PRIM_FLEXIBLE ] );
    integer torf = llList2Integer( params, 0 );
    string onoff;
    if(torf == 1)
    {
        onoff = "TRUE";
    }
    else
    {
        onoff = "FALSE";
    }
    integer softness = llList2Integer( params, 1 );
    float gravity = llList2Float( params, 2 );
    float friction = llList2Float( params, 3 );
    float wind = llList2Float( params, 4 );
    float tension = llList2Float( params, 5 );
    vector force = llList2Vector( params, 6 );
    dump = "PRIM_FLEXIBLE, " + onoff + "," + (string)softness + "," + (string)gravity +"," + (string)friction +"," + (string)wind +"," + (string)tension + "," + vectorToString( force );
    return dump;
}


string AddColorParam( )
{
    string dump;

    list side0 = llGetPrimitiveParams( [ PRIM_COLOR, 0 ] );
    vector color0 = llList2Vector( side0, 0 );
    float alpha0 = llList2Float( side0, 1 );
        
    integer sides = llGetNumberOfSides();
    
    integer all_sides_same = TRUE;
    
    integer i;
    for( i = 1; i < sides; i++ )
    {
        list side = llGetPrimitiveParams( [ PRIM_COLOR, i ] );
        
        vector color = llList2Vector( side, 0 );
        float alpha = llList2Float( side, 1 );
        
        if( color == color0 && alpha == alpha0 )
        {            
        }
        else
        {
            all_sides_same = FALSE;
            i=sides;
        }
    }

    if( all_sides_same )
    {
        dump = "PRIM_COLOR, ALL_SIDES, "+vectorToString( color0 )+", "+floatToString( alpha0 );
    }
    else
    {
        // Different colors on faces.
        integer last = sides - 1;
        for( i = 0; i < sides; i++ )
        {
            list side = llGetPrimitiveParams( [ PRIM_COLOR, i ] );
            
            vector color = llList2Vector( side, 0 );
            float alpha = llList2Float( side, 1 );
            
            dump += "PRIM_COLOR, "+(string)i+", "+vectorToString( color )+", "+floatToString( alpha );
            if( i != last )
            {
                dump +=", ";
            }
        }
    }        
    
    return dump;
}
string AddTextureParam( )
{
    string dump;

    list texture0 = llGetPrimitiveParams( [ PRIM_TEXTURE, 0 ] );
    
    string uuid0 = llList2String( texture0, 0 );
    vector repeats0 = llList2Vector( texture0, 1 );
    vector offsets0 = llList2Vector( texture0, 2 );
    float rot0 = llList2Float( texture0, 3 );
        
    integer sides = llGetNumberOfSides();
    
    integer all_sides_same = TRUE;
    
    integer i;
    for( i = 1; i < sides; i++ )
    {
        list side = llGetPrimitiveParams( [ PRIM_TEXTURE, i ] );
        
        string uuid = llList2String( side, 0 );
        vector repeats = llList2Vector( side, 1 );
        vector offsets = llList2Vector( side, 2 );
        float rot = llList2Float( side, 3 );
        
        if( uuid == uuid0 && repeats == repeats0 && offsets == offsets0 && rot == rot0 )
        {            
        }
        else
        {
            all_sides_same = FALSE;
            i=sides;
        }
    }

    if( all_sides_same )
    {
        dump += "PRIM_TEXTURE, ALL_SIDES, \""+uuid0+"\", "+vectorToString( repeats0 )+", "+vectorToString( offsets0 )+", "+floatToString( rot0 );
    }
    else
    {
        // Different colors on faces.
        integer last = sides - 1;
        for( i = 0; i < sides; i++ )
        {
            list side = llGetPrimitiveParams( [ PRIM_TEXTURE, i ] );
        
            string uuid = llList2String( side, 0 );
            vector repeats = llList2Vector( side, 1 );
            vector offsets = llList2Vector( side, 2 );
            float rot = llList2Float( side, 3 );
            
            dump += "PRIM_TEXTURE, "+(string)i+", \""+uuid+"\", "+vectorToString( repeats )+", "+vectorToString( offsets )+", "+floatToString( rot );

            if( i != last )
            {
                dump +=", ";
            }
        }
    }        
    
    return dump;
}

list GetParamDumpList( )
{
    list paramDumpList;
    
    paramDumpList += AddTypeParam( );
    paramDumpList += AddParam( PRIM_SIZE, "PRIM_SIZE" );
    paramDumpList += AddParam( PRIM_ROTATION, "PRIM_ROTATION" );
    paramDumpList += AddColorParam( );
    paramDumpList += AddTextureParam( );
    paramDumpList += AddFlexibleParam( );
    
    return paramDumpList;
}

string GetParamDump( )
{
    string dump;
    list paramDumpList = GetParamDumpList();
    
    dump = llList2CSV( paramDumpList );

    dump = "llSetPrimitiveParams([ " + dump + "]);";
    
    return dump;
}


default
{
    state_entry()
    {
        string dump = GetParamDump();
                
        llOwnerSay( dump );
    }
}
Comments [Hide comments/form]
Attach a comment to this page: