Change font size
It is currently Thu Nov 22, 2018 5:24 am

Forum rules


{L_IMAGE}



Post a new topicPost a reply Page 1 of 1   [ 1 post ]
Author Message
 Post subject: Advanced Sculptie Exporter From Maya (fixed for OpenSim)
PostPosted: Thu Nov 05, 2009 8:12 pm 
OSG Elite
User avatar

Joined: Thu Dec 11, 2008 7:51 am
Posts: 392
Location: England UK
A friend asked me to have a look at some scripts for him that didn't work in OpenSim to export advanced scenes from Maya directly into OpenSim.

Before you go any further please read this page: http://wiki.secondlife.com/wiki/Advance ... _From_Maya
This topic only includes the lsl scripts that are compatible with OpenSim and not the Maya script or instructions, please see the link above for those. Here are the OpenSim compatible scripts only.

I have also added a routine to remove all the left over textures from the prims as the original didn't include that.

Also, as I did not write this script, I will not support it. Please do not ask me for support regarding it; I only made it work in OpenSim ;)

Prim
{L_CODE}:
// assembled by ../bin/lslcc -I. -I.. -I../.. prim.lsl
// by qarl with qLab v0.0.3
// Mon Jun 18 19:11:26 PDT 2007
//
// Fixed for opensim by Adelle Fitzgerald - 5 november 2009

string parseWord;




qUserError(string message)
{
  llOwnerSay(message);
}



__qError(string error, string file, integer line)
{
  llOwnerSay(error + ":" +
          llGetScriptName() + ":" +
          file + "(" +
          (string)line + ")");
}


integer __qDebugLevel = 0;

qDebugSetLevel(integer level)
{
  __qDebugLevel = level;
}



__qDebug(string message, integer level, string file, integer line)
{
  if (level < __qDebugLevel)
    __qError("DEBUG: " + message, file, line);
}




list qCommandCreate(string commandName)
{
  list command;

  command = [ commandName ];

  return command;
}



list qCommandAddSwitch(list command, list switch)
{
  string switchName    = llList2String(switch, 0);
  integer settingCount = llGetListLength(switch) - 1;

  command += [switchName, settingCount];

  if (settingCount > 0)
    command += llList2List(switch, 1, settingCount);

  return command;
}


qCommandUsage(list command)
{
  qUserError("USAGE: " + llList2String(command, 0));

  integer commandLength = llGetListLength(command);

  integer i;
  for (i = 1; i < commandLength; i) // i incremented below
    {
      string output = "";

      string switch         = llList2String(command, i);
      i++;
      integer settingCount  = llList2Integer(command, i);
      i++;

      output = "     " + switch;

      integer j;
      for (j = 0; j < settingCount; j++)
    {
      output = output + " " + llList2String(command, i);
      i++;
    }

      qUserError(output);
    }
}




list qCommandParseText(list command, string text)
{
  integer commandLength = llGetListLength(command);

  list parse = llParseString2List(text, [" "], []);
  integer parseLength = llGetListLength(parse);

  // make sure this is our command
  string parseCommand   = llList2String(parse, 0);
  string commandCommand = llList2String(command, 0);

  string objectName = llGetObjectName();
  string objectKey  = (string)llGetKey();

  if ((parseCommand != "*") &&   // wildcard matches all commands
      (parseCommand != commandCommand) &&
      (parseCommand != objectName + "/" + commandCommand) &&
      (parseCommand != objectKey + "/" + commandCommand))
    return [];

  list switches = [ parseCommand ];;

  integer i;
  for (i = 1; i < parseLength; i) // i incremented below
    {
      parseWord = llList2String(parse, i);
      i++;

      integer found = 0;

      // scan switch list to see which one we've got:
      integer j;
      for (j = 1; (j < commandLength) && (found == 0); j) // j incremented below
    {

      string switch         = llList2String(command, j);
      j++;
      integer settingCount  = llList2Integer(command, j);
      j++;

      if (parseWord == switch)
        {
          found = 1;
          switches += [ switch ];

          integer k;
          for (k = 0; k < settingCount; k++)
        {
          if (i >= parseLength)
            {
              qUserError("\"" + switch + "\" requires " +
                 (string)settingCount + " options.");
              qCommandUsage(command);
              return [];
            }

          parseWord = llList2String(parse, i);
          i++;

          string settingType = llList2String(command, j+k);

          if (settingType == "float")
            switches += [(float) parseWord];

          else if (settingType == "integer")
            switches += [(integer) parseWord];

          else // assume string
            switches += [ llUnescapeURL(parseWord) ];
        }
        }
     
      j += settingCount;
    }


      if (!found)
    {
      qUserError("\"" + parseWord + "\" not understood.");
      qCommandUsage(command);
      return [];
    }
    }


  return switches;
}

// universal switches


list qCommandAddDebugSwitch(list command)
{
  return qCommandAddSwitch(command, ["-debug", "integer"]);
}

list qCommandAddResetSwitch(list command)
{
  return qCommandAddSwitch(command, ["-reset"]);
}

list qCommandAddDieSwitch(list command)
{
  return qCommandAddSwitch(command, ["-die"]);
}

list qCommandAddHelpSwitch(list command)
{
  if (llGetInventoryType("Instruction Manual") == INVENTORY_NOTECARD)
    return qCommandAddSwitch(command, ["-help"]);

  else
    return command;
}


list qCommandAddUniversalSwitches(list command)
{
  command = qCommandAddDebugSwitch(command);
  command = qCommandAddResetSwitch(command);
  command = qCommandAddDieSwitch(command);
  command = qCommandAddHelpSwitch(command);

  return command;
}

integer qCommandExecuteUniversalSwitch(list switches, integer i)
{
  string switch = llList2String(switches, i);

  if (switch == "-debug")
    {
      i++;
      qDebugSetLevel(llList2Integer(switches, i));
      i++;
    }
  else if (switch == "-reset")
    {
      llResetScript();
      i++;
    }
  else if (switch == "-die")
    {
      llDie();
      i++;
    }

  else if (switch == "-help")
    {
      llGiveInventory(llGetOwner(),     
              "Instruction Manual");
      i++;
    }

  return i;
}




vector qGetLocalPosition()
{
  return llGetPos();
}

vector qGetGlobalPosition()
{
  return llGetPos() + llGetRegionCorner();
}

vector qGlobal2LocalPosition(vector global)
{
  return global - llGetRegionCorner();
}

vector qLocal2GlobalPosition(vector local)
{
  return local + llGetRegionCorner();
}

qSetLocalPosition(vector local)
{
  llSetPos(local);
}

qSetGlobalPosition(vector global)
{
  qSetLocalPosition(qGlobal2LocalPosition(global));
}

qGotoGlobalPosition(vector target)
{
  vector position = qGetGlobalPosition();

  integer i;
  for (i = 0;
       ((i < 1000) &&  // no infinite loops, thank you.
    (llVecDist(target, position) > 0.01));
       i++)
    {
      qSetGlobalPosition(target);
      position = qGetGlobalPosition();
    }
}







list primCommand;

buildPrimCommand()
{
  primCommand = qCommandCreate("prim");
  primCommand = qCommandAddUniversalSwitches(primCommand);

  primCommand = qCommandAddSwitch(primCommand, ["-setObjectName",
                                        "string"]);
  primCommand = qCommandAddSwitch(primCommand, ["-setObjectDesc",
                                        "string"]);
  primCommand = qCommandAddSwitch(primCommand, ["-setText",
                                        "string", "float", "float", "float", "float"]);
  primCommand = qCommandAddSwitch(primCommand, ["-setPIN",
                                        "integer"]);
  primCommand = qCommandAddSwitch(primCommand, ["-sleep",
                                        "integer"]);
  primCommand = qCommandAddSwitch(primCommand, ["-deleteScript"]);

}



initPrimCommand()
{
  buildPrimCommand();

  llListen(500, "", NULL_KEY, "");

  integer privateChannel = llGetStartParameter();
  if (privateChannel != 0)
    llListen(privateChannel, "", NULL_KEY, "");
}



executePrimCommand(list switches)
{
  integer switchesLength = llGetListLength(switches);

  integer i;
  for (i = 1; i < switchesLength; i)
    {
      string switch = llList2String(switches, i);

      if (switch == "-deleteScript")
    {
      llRemoveInventory(llGetScriptName());
      i++;
    }

      else if (switch == "-setObjectName")
    {
      llSetObjectName(llList2String(switches, i+1));
      i+=2;
    }

      else if (switch == "-setObjectDesc")
    {
      llSetObjectDesc(llList2String(switches, i+1));
      i+=2;
    }

      else if (switch == "-setText")
    {
      llSetText(llList2String(switches, i+1),
            (< llList2Float(switches, i+2),
             llList2Float(switches, i+3),
             llList2Float(switches, i+4) >),
            llList2Float(switches, i+5));
      i+=6;
    }

      else if (switch == "-setPIN")
    {
      llSetRemoteScriptAccessPin(llList2Integer(switches, i+1));
      i+=2;
    }

      else if (switch == "-sleep")
    {
      llSleep(llList2Integer(switches, i+1));
      i+=2;
    }


      else
    i = qCommandExecuteUniversalSwitch(switches, i);

    }
}

parsePrimCommand(string message)
{
list switches = qCommandParseText(primCommand, message);

  if (switches != [])
    executePrimCommand(switches);

}


listenPrimCommand(integer channel, string name, key id,  string message)
{
  // we only accept commands on the public channel from our owner
  if ((channel == 500) &&
      (name != llKey2Name(llGetOwner())))
    return;

  parsePrimCommand(message);
}


linkMessagePrimCommand(integer sender, integer num, string message, key id)
{
  parsePrimCommand(message);
}


default
{
  state_entry()
    {
      initPrimCommand();
    }

  on_rez(integer n)
    {
      initPrimCommand();
    }

  listen(integer channel, string name, key id,  string message)
    {
      listenPrimCommand(channel, name, id, message);
    }

  link_message(integer sender, integer num, string message, key id)
    {
      linkMessagePrimCommand(sender, num, message, id);
    }
}



Texture
{L_CODE}:
// assembled by ../bin/lslcc -I. -I.. -I../.. texture.lsl
// by qarl with qLab v0.0.3
// Tue Jun 19 13:54:40 PDT 2007
//
// Fixed for opensim by Adelle Fitzgerald and also added clean up routine to remove all the left over textures - 5 november 2009



string parseWord;


qUserError(string message)
{
  llOwnerSay(message);
}



__qError(string error, string file, integer line)
{
  llOwnerSay(error + ":" +
          llGetScriptName() + ":" +
          file + "(" +
          (string)line + ")");
}


integer __qDebugLevel = 0;

qDebugSetLevel(integer level)
{
  __qDebugLevel = level;
}



__qDebug(string message, integer level, string file, integer line)
{
  if (level < __qDebugLevel)
    __qError("DEBUG: " + message, file, line);
}




list qCommandCreate(string commandName)
{
  list command;

  command = [ commandName ];

  return command;
}



list qCommandAddSwitch(list command, list switch)
{
  string switchName    = llList2String(switch, 0);
  integer settingCount = llGetListLength(switch) - 1;

  command += [switchName, settingCount];

  if (settingCount > 0)
    command += llList2List(switch, 1, settingCount);

  return command;
}


qCommandUsage(list command)
{
  qUserError("USAGE: " + llList2String(command, 0));

  integer commandLength = llGetListLength(command);

  integer i;
  for (i = 1; i < commandLength; i) // i incremented below
    {
      string output = "";

      string switch         = llList2String(command, i);
      i++;
      integer settingCount  = llList2Integer(command, i);
      i++;

      output = "     " + switch;

      integer j;
      for (j = 0; j < settingCount; j++)
    {
      output = output + " " + llList2String(command, i);
      i++;
    }

      qUserError(output);
    }
}




list qCommandParseText(list command, string text)
{
  integer commandLength = llGetListLength(command);

  list parse = llParseString2List(text, [" "], []);
  integer parseLength = llGetListLength(parse);

  // make sure this is our command
  string parseCommand   = llList2String(parse, 0);
  string commandCommand = llList2String(command, 0);

  string objectName = llGetObjectName();
  string objectKey  = (string)llGetKey();

  if ((parseCommand != "*") &&   // wildcard matches all commands
      (parseCommand != commandCommand) &&
      (parseCommand != objectName + "/" + commandCommand) &&
      (parseCommand != objectKey + "/" + commandCommand))
    return [];

  list switches = [ parseCommand ];;

  integer i;
  for (i = 1; i < parseLength; i) // i incremented below
    {
      parseWord = llList2String(parse, i);
      i++;

      integer found = 0;

      // scan switch list to see which one we've got:
      integer j;
      for (j = 1; (j < commandLength) && (found == 0); j) // j incremented below
    {

      string switch         = llList2String(command, j);
      j++;
      integer settingCount  = llList2Integer(command, j);
      j++;

      if (parseWord == switch)
        {
          found = 1;
          switches += [ switch ];

          integer k;
          for (k = 0; k < settingCount; k++)
        {
          if (i >= parseLength)
            {
              qUserError("\"" + switch + "\" requires " +
                 (string)settingCount + " options.");
              qCommandUsage(command);
              return [];
            }

          parseWord = llList2String(parse, i);
          i++;

          string settingType = llList2String(command, j+k);

          if (settingType == "float")
            switches += [(float) parseWord];

          else if (settingType == "integer")
            switches += [(integer) parseWord];

          else // assume string
            switches += [ llUnescapeURL(parseWord) ];
        }
        }
     
      j += settingCount;
    }


      if (!found)
    {
      qUserError("\"" + parseWord + "\" not understood.");
      qCommandUsage(command);
      return [];
    }
    }


  return switches;
}

// universal switches


list qCommandAddDebugSwitch(list command)
{
  return qCommandAddSwitch(command, ["-debug", "integer"]);
}

list qCommandAddResetSwitch(list command)
{
  return qCommandAddSwitch(command, ["-reset"]);
}

list qCommandAddDieSwitch(list command)
{
  return qCommandAddSwitch(command, ["-die"]);
}

list qCommandAddHelpSwitch(list command)
{
  if (llGetInventoryType("Instruction Manual") == INVENTORY_NOTECARD)
    return qCommandAddSwitch(command, ["-help"]);

  else
    return command;
}


list qCommandAddUniversalSwitches(list command)
{
  command = qCommandAddDebugSwitch(command);
  command = qCommandAddResetSwitch(command);
  command = qCommandAddDieSwitch(command);
  command = qCommandAddHelpSwitch(command);

  return command;
}

integer qCommandExecuteUniversalSwitch(list switches, integer i)
{
  string switch = llList2String(switches, i);

  if (switch == "-debug")
    {
      i++;
      qDebugSetLevel(llList2Integer(switches, i));
      i++;
    }
  else if (switch == "-reset")
    {
      llResetScript();
      i++;
    }
  else if (switch == "-die")
    {
      llDie();
      i++;
    }

  else if (switch == "-help")
    {
      llGiveInventory(llGetOwner(),     
              "Instruction Manual");
      i++;
    }

  return i;
}




vector qGetLocalPosition()
{
  return llGetPos();
}

vector qGetGlobalPosition()
{
  return llGetPos() + llGetRegionCorner();
}

vector qGlobal2LocalPosition(vector global)
{
  return global - llGetRegionCorner();
}

vector qLocal2GlobalPosition(vector local)
{
  return local + llGetRegionCorner();
}

qSetLocalPosition(vector local)
{
  llSetPos(local);
}

qSetGlobalPosition(vector global)
{
  qSetLocalPosition(qGlobal2LocalPosition(global));
}

qGotoGlobalPosition(vector target)
{
  vector position = qGetGlobalPosition();

  integer i;
  for (i = 0;
       ((i < 1000) &&  // no infinite loops, thank you.
    (llVecDist(target, position) > 0.01));
       i++)
    {
      qSetGlobalPosition(target);
      position = qGetGlobalPosition();
    }
}







list textureCommand;

buildTextureCommand()
{
  textureCommand = qCommandCreate("texture");
  textureCommand = qCommandAddUniversalSwitches(textureCommand);

  textureCommand = qCommandAddSwitch(textureCommand, ["-setColor",
                                        "float", "float", "float", "integer"]);
  textureCommand = qCommandAddSwitch(textureCommand, ["-setAlpha",
                                        "float", "integer"]);
  textureCommand = qCommandAddSwitch(textureCommand, ["-setTexture",
                                        "string", "integer"]);
  textureCommand = qCommandAddSwitch(textureCommand, ["-setTexturePos",
                                        "float", "float", "float", "float", "float", "integer"]);
  textureCommand = qCommandAddSwitch(textureCommand, ["-setFullBright", "integer", "integer" ]);
  textureCommand = qCommandAddSwitch(textureCommand, ["-sleep",
                                        "integer"]);
  textureCommand = qCommandAddSwitch(textureCommand, ["-deleteScript"]);
}



initTextureCommand()
{
  buildTextureCommand();

  llListen(500, "", NULL_KEY, "");

  integer privateChannel = llGetStartParameter();
  if (privateChannel != 0)
    llListen(privateChannel, "", NULL_KEY, "");
}



executeTextureCommand(list switches)
{
  integer switchesLength = llGetListLength(switches);

  integer i;
  for (i = 1; i < switchesLength; i)
    {
      string switch = llList2String(switches, i);

      if (switch == "-setColor")
    {
      llSetColor(<llList2Float(switches, i+1),
             llList2Float(switches, i+2),
             llList2Float(switches, i+3)>,
             llList2Integer(switches, i+4));
      i+=5;
    }
 
      else if (switch == "-setAlpha")
    {
      llSetAlpha(llList2Float(switches, i+1),
             llList2Integer(switches, i+2));
      i+=3;
    }

      else if (switch == "-setTexture")
    {
      string texture = llList2String(switches, i+1);

      if (texture == "blank")
        texture = "5748decc-f629-461c-9a36-a35a221fe21f";

      // if inventory name give, convert to asset id when possible
      key uuid = llGetInventoryKey(texture);
      if (uuid != NULL_KEY)
        texture = (string)uuid;

      llSay(0, "setting texture to: " + texture);

      llSetTexture(texture,
               llList2Integer(switches, i+2));
      i+=3;
    }

      else if (switch == "-setTexturePos")
    {
      integer side = llList2Integer(switches, i+6);

      llOffsetTexture(llList2Float(switches, i+1),
              llList2Float(switches, i+2),
              side);
      llRotateTexture(llList2Float(switches, i+3),
              side);
      llScaleTexture(llList2Float(switches, i+4),
             llList2Float(switches, i+5),
             side);

      i+=7;
    }

      else if (switch == "-setFullBright")
    {
      integer side = llList2Integer(switches, i+1);
      integer on = llList2Integer(switches, i+2);

      llSetPrimitiveParams([PRIM_FULLBRIGHT, side, on]);

      i+=3;
    }

      else if (switch == "-deleteScript")
    {
      llSetTimerEvent(1);
      i++;
    }


      else if (switch == "-sleep")
    {
      llSleep(llList2Integer(switches, i+1));
      i+=2;
    }


      else
    i = qCommandExecuteUniversalSwitch(switches, i);

    }
}


parseTextureCommand(string message)
{
list switches = qCommandParseText(textureCommand, message);

  if (switches != [])
    executeTextureCommand(switches);

}


listenTextureCommand(integer channel, string name, key id,  string message)
{
  // we only accept commands on the public channel from our owner
  if ((channel == 500) &&
      (name != llKey2Name(llGetOwner())))
    return;

  parseTextureCommand(message);
}


linkMessageTextureCommand(integer sender, integer num, string message, key id)
{
  parseTextureCommand(message);
}


default
{
  state_entry()
    {
      initTextureCommand();
    }

  on_rez(integer n)
    {
      initTextureCommand();
    }

  listen(integer channel, string name, key id,  string message)
    {
      listenTextureCommand(channel, name, id, message);
    }

  link_message(integer sender, integer num, string message, key id)
    {
      linkMessageTextureCommand(sender, num, message, id);
    }
    timer()
    {
        //Check to make sure all scripts have removed themselves then clean up textures and remove this script
        if (llGetInventoryNumber(INVENTORY_SCRIPT) == 1)
        {
            integer textureNo = llGetInventoryNumber(INVENTORY_TEXTURE);
            integer i;
            for (i = 0; i < textureNo; i++)
            {
                string textureName = llGetInventoryName(INVENTORY_TEXTURE,0);
                llRemoveInventory(textureName);
                llSleep(0.2);
            }
            llRemoveInventory(llGetScriptName());
        }
        else
        {
            llSetTimerEvent(1);
        }
    }   
}



Transform
{L_CODE}:
// assembled by ../bin/lslcc -I. -I.. -I../.. transform.lsl
// by qarl with qLab v0.0.3
// Mon Jun 18 19:11:27 PDT 2007
//
// Fixed for opensim by Adelle Fitzgerald - 5 november 2009



string parseWord;


qUserError(string message)
{
  llOwnerSay(message);
}



__qError(string error, string file, integer line)
{
  llOwnerSay(error + ":" +
          llGetScriptName() + ":" +
          file + "(" +
          (string)line + ")");
}


integer __qDebugLevel = 0;

qDebugSetLevel(integer level)
{
  __qDebugLevel = level;
}



__qDebug(string message, integer level, string file, integer line)
{
  if (level < __qDebugLevel)
    __qError("DEBUG: " + message, file, line);
}




list qCommandCreate(string commandName)
{
  list command;

  command = [ commandName ];

  return command;
}



list qCommandAddSwitch(list command, list switch)
{
  string switchName    = llList2String(switch, 0);
  integer settingCount = llGetListLength(switch) - 1;

  command += [switchName, settingCount];

  if (settingCount > 0)
    command += llList2List(switch, 1, settingCount);

  return command;
}


qCommandUsage(list command)
{
  qUserError("USAGE: " + llList2String(command, 0));

  integer commandLength = llGetListLength(command);

  integer i;
  for (i = 1; i < commandLength; i) // i incremented below
    {
      string output = "";

      string switch         = llList2String(command, i);
      i++;
      integer settingCount  = llList2Integer(command, i);
      i++;

      output = "     " + switch;

      integer j;
      for (j = 0; j < settingCount; j++)
    {
      output = output + " " + llList2String(command, i);
      i++;
    }

      qUserError(output);
    }
}




list qCommandParseText(list command, string text)
{
  integer commandLength = llGetListLength(command);

  list parse = llParseString2List(text, [" "], []);
  integer parseLength = llGetListLength(parse);

  // make sure this is our command
  string parseCommand   = llList2String(parse, 0);
  string commandCommand = llList2String(command, 0);

  string objectName = llGetObjectName();
  string objectKey  = (string)llGetKey();

  if ((parseCommand != "*") &&   // wildcard matches all commands
      (parseCommand != commandCommand) &&
      (parseCommand != objectName + "/" + commandCommand) &&
      (parseCommand != objectKey + "/" + commandCommand))
    return [];

  list switches = [ parseCommand ];;

  integer i;
  for (i = 1; i < parseLength; i) // i incremented below
    {
      parseWord = llList2String(parse, i);
      i++;

      integer found = 0;

      // scan switch list to see which one we've got:
      integer j;
      for (j = 1; (j < commandLength) && (found == 0); j) // j incremented below
    {

      string switch         = llList2String(command, j);
      j++;
      integer settingCount  = llList2Integer(command, j);
      j++;

      if (parseWord == switch)
        {
          found = 1;
          switches += [ switch ];

          integer k;
          for (k = 0; k < settingCount; k++)
        {
          if (i >= parseLength)
            {
              qUserError("\"" + switch + "\" requires " +
                 (string)settingCount + " options.");
              qCommandUsage(command);
              return [];
            }

          parseWord = llList2String(parse, i);
          i++;

          string settingType = llList2String(command, j+k);

          if (settingType == "float")
            switches += [(float) parseWord];

          else if (settingType == "integer")
            switches += [(integer) parseWord];

          else // assume string
            switches += [ llUnescapeURL(parseWord) ];
        }
        }
     
      j += settingCount;
    }


      if (!found)
    {
      qUserError("\"" + parseWord + "\" not understood.");
      qCommandUsage(command);
      return [];
    }
    }


  return switches;
}

// universal switches


list qCommandAddDebugSwitch(list command)
{
  return qCommandAddSwitch(command, ["-debug", "integer"]);
}

list qCommandAddResetSwitch(list command)
{
  return qCommandAddSwitch(command, ["-reset"]);
}

list qCommandAddDieSwitch(list command)
{
  return qCommandAddSwitch(command, ["-die"]);
}

list qCommandAddHelpSwitch(list command)
{
  if (llGetInventoryType("Instruction Manual") == INVENTORY_NOTECARD)
    return qCommandAddSwitch(command, ["-help"]);

  else
    return command;
}


list qCommandAddUniversalSwitches(list command)
{
  command = qCommandAddDebugSwitch(command);
  command = qCommandAddResetSwitch(command);
  command = qCommandAddDieSwitch(command);
  command = qCommandAddHelpSwitch(command);

  return command;
}

integer qCommandExecuteUniversalSwitch(list switches, integer i)
{
  string switch = llList2String(switches, i);

  if (switch == "-debug")
    {
      i++;
      qDebugSetLevel(llList2Integer(switches, i));
      i++;
    }
  else if (switch == "-reset")
    {
      llResetScript();
      i++;
    }
  else if (switch == "-die")
    {
      llDie();
      i++;
    }

  else if (switch == "-help")
    {
      llGiveInventory(llGetOwner(),     
              "Instruction Manual");
      i++;
    }

  return i;
}




vector qGetLocalPosition()
{
  return llGetPos();
}

vector qGetGlobalPosition()
{
  return llGetPos() + llGetRegionCorner();
}

vector qGlobal2LocalPosition(vector global)
{
  return global - llGetRegionCorner();
}

vector qLocal2GlobalPosition(vector local)
{
  return local + llGetRegionCorner();
}

qSetLocalPosition(vector local)
{
  llSetPos(local);
}

qSetGlobalPosition(vector global)
{
  qSetLocalPosition(qGlobal2LocalPosition(global));
}

qGotoGlobalPosition(vector target)
{
  vector position = qGetGlobalPosition();

  integer i;
  for (i = 0;
       ((i < 1000) &&  // no infinite loops, thank you.
    (llVecDist(target, position) > 0.01));
       i++)
    {
      qSetGlobalPosition(target);
      position = qGetGlobalPosition();
    }
}







list transformCommand;

buildTransformCommand()
{
  transformCommand = qCommandCreate("transform");
  transformCommand = qCommandAddUniversalSwitches(transformCommand);

  transformCommand = qCommandAddSwitch(transformCommand, ["-setPos",
                                        "float", "float", "float"]);
  transformCommand = qCommandAddSwitch(transformCommand, ["-setGlobalPos",
                                        "float", "float", "float"]);
  transformCommand = qCommandAddSwitch(transformCommand, ["-setRelativePos",
                                        "float", "float", "float"]);
  transformCommand = qCommandAddSwitch(transformCommand, ["-setScale",
                                        "float", "float", "float"]);
  transformCommand = qCommandAddSwitch(transformCommand, ["-setRot",
                                        "float", "float", "float"]);

  transformCommand = qCommandAddSwitch(transformCommand, ["-gotoGlobalPos",
                                        "float", "float", "float"]);
  transformCommand = qCommandAddSwitch(transformCommand, ["-gotoRelativePos",
                                        "float", "float", "float"]);
  transformCommand = qCommandAddSwitch(transformCommand, ["-gotoSim",
                                        "integer", "integer"]);
  transformCommand = qCommandAddSwitch(transformCommand, ["-sleep",
                                        "integer"]);
  transformCommand = qCommandAddSwitch(transformCommand, ["-deleteScript"]);
}



initTransformCommand()
{
  buildTransformCommand();

  llListen(500, "", NULL_KEY, "");

  integer privateChannel = llGetStartParameter();
  if (privateChannel != 0)
    llListen(privateChannel, "", NULL_KEY, "");
}



executeTransformCommand(list switches)
{
  integer switchesLength = llGetListLength(switches);

  integer i;
  for (i = 1; i < switchesLength; i)
    {
      string switch = llList2String(switches, i);

      if (switch == "-setPos")
    {
      llSetPos(<llList2Float(switches, i+1),
           llList2Float(switches, i+2),
           llList2Float(switches, i+3)>);
      i+=4;
    }
      else if (switch == "-setGlobalPos")
    {
      qSetGlobalPosition(<llList2Float(switches, i+1),
                 llList2Float(switches, i+2),
                 llList2Float(switches, i+3)>);
      i+=4;
    }
      else if (switch == "-setRelativePos")
    {
      vector position = qGetGlobalPosition();

      qSetGlobalPosition(position + (<llList2Float(switches, i+1),
                     llList2Float(switches, i+2),
                     llList2Float(switches, i+3)>));
      i+=4;
    }
      else if (switch == "-setScale")
    {
      llSetScale(<llList2Float(switches, i+1),
             llList2Float(switches, i+2),
             llList2Float(switches, i+3)>);
      i+=4;
    }
      else if (switch == "-setRot")
    {
      llSetRot(llEuler2Rot(<llList2Float(switches, i+1),
                   llList2Float(switches, i+2),
                   llList2Float(switches, i+3)>));
      i+=4;
    }

      else if (switch == "-deleteScript")
    {
      llRemoveInventory(llGetScriptName());
      i++;
    }


      else if (switch == "-sleep")
    {
      llSleep(llList2Integer(switches, i+1));
      i+=2;
    }

      else if (switch == "-gotoSim")
    {
      vector position = qGetGlobalPosition();
      position.x = llList2Float(switches, i+1) * 256 + 128;
      position.y = llList2Float(switches, i+2) * 256 + 128;
      qGotoGlobalPosition(position);

      i+=3;
    }
      else if (switch == "-gotoGlobalPos")
    {
      qGotoGlobalPosition(<llList2Float(switches, i+1),
                  llList2Float(switches, i+2),
                  llList2Float(switches, i+3)>);
      i+=4;
    }
      else if (switch == "-gotoRelativePos")
    {
      vector position = qGetGlobalPosition();
      qGotoGlobalPosition(position + (<llList2Float(switches, i+1),
                      llList2Float(switches, i+2),
                      llList2Float(switches, i+3)>));
      i+=4;
    }

      else if (switch == "-gotoSim")
    {
      vector position = qGetGlobalPosition();
      position.x = llList2Float(switches, i+1) * 256 + 128;
      position.y = llList2Float(switches, i+2) * 256 + 128;
      qGotoGlobalPosition(position);

      i+=3;
    }



      else
    i = qCommandExecuteUniversalSwitch(switches, i);

    }
}


parseTransformCommand(string message)
{
list switches = qCommandParseText(transformCommand, message);

  if (switches != [])
    executeTransformCommand(switches);

}


listenTransformCommand(integer channel, string name, key id,  string message)
{
  // we only accept commands on the public channel from our owner
  if ((channel == 500) &&
      (name != llKey2Name(llGetOwner())))
    return;

  parseTransformCommand(message);
}


linkMessageTransformCommand(integer sender, integer num, string message, key id)
{
  parseTransformCommand(message);
}


default
{
  state_entry()
    {
      initTransformCommand();
    }

  on_rez(integer n)
    {
      initTransformCommand();
    }

  listen(integer channel, string name, key id,  string message)
    {
      listenTransformCommand(channel, name, id, message);
    }

  link_message(integer sender, integer num, string message, key id)
    {
      linkMessageTransformCommand(sender, num, message, id);
    }
}



Shape
{L_CODE}:
// assembled by ../bin/lslcc -I. -I.. -I../.. shape.lsl
// by qarl with qLab v0.0.3
// Mon Jun 18 19:11:27 PDT 2007
//
// Fixed for opensim by Adelle Fitzgerald - 5 november 2009


string parseWord;



qUserError(string message)
{
  llOwnerSay(message);
}



__qError(string error, string file, integer line)
{
  llOwnerSay(error + ":" +
          llGetScriptName() + ":" +
          file + "(" +
          (string)line + ")");
}


integer __qDebugLevel = 0;

qDebugSetLevel(integer level)
{
  __qDebugLevel = level;
}



__qDebug(string message, integer level, string file, integer line)
{
  if (level < __qDebugLevel)
    __qError("DEBUG: " + message, file, line);
}




list qCommandCreate(string commandName)
{
  list command;

  command = [ commandName ];

  return command;
}



list qCommandAddSwitch(list command, list switch)
{
  string switchName    = llList2String(switch, 0);
  integer settingCount = llGetListLength(switch) - 1;

  command += [switchName, settingCount];

  if (settingCount > 0)
    command += llList2List(switch, 1, settingCount);

  return command;
}


qCommandUsage(list command)
{
  qUserError("USAGE: " + llList2String(command, 0));

  integer commandLength = llGetListLength(command);

  integer i;
  for (i = 1; i < commandLength; i) // i incremented below
    {
      string output = "";

      string switch         = llList2String(command, i);
      i++;
      integer settingCount  = llList2Integer(command, i);
      i++;

      output = "     " + switch;

      integer j;
      for (j = 0; j < settingCount; j++)
    {
      output = output + " " + llList2String(command, i);
      i++;
    }

      qUserError(output);
    }
}




list qCommandParseText(list command, string text)
{
  integer commandLength = llGetListLength(command);

  list parse = llParseString2List(text, [" "], []);
  integer parseLength = llGetListLength(parse);

  // make sure this is our command
  string parseCommand   = llList2String(parse, 0);
  string commandCommand = llList2String(command, 0);

  string objectName = llGetObjectName();
  string objectKey  = (string)llGetKey();

  if ((parseCommand != "*") &&   // wildcard matches all commands
      (parseCommand != commandCommand) &&
      (parseCommand != objectName + "/" + commandCommand) &&
      (parseCommand != objectKey + "/" + commandCommand))
    return [];

  list switches = [ parseCommand ];;

  integer i;
  for (i = 1; i < parseLength; i) // i incremented below
    {
      parseWord = llList2String(parse, i);
      i++;

      integer found = 0;

      // scan switch list to see which one we've got:
      integer j;
      for (j = 1; (j < commandLength) && (found == 0); j) // j incremented below
    {

      string switch         = llList2String(command, j);
      j++;
      integer settingCount  = llList2Integer(command, j);
      j++;

      if (parseWord == switch)
        {
          found = 1;
          switches += [ switch ];

          integer k;
          for (k = 0; k < settingCount; k++)
        {
          if (i >= parseLength)
            {
              qUserError("\"" + switch + "\" requires " +
                 (string)settingCount + " options.");
              qCommandUsage(command);
              return [];
            }

          parseWord = llList2String(parse, i);
          i++;

          string settingType = llList2String(command, j+k);

          if (settingType == "float")
            switches += [(float) parseWord];

          else if (settingType == "integer")
            switches += [(integer) parseWord];

          else // assume string
            switches += [ llUnescapeURL(parseWord) ];
        }
        }
     
      j += settingCount;
    }


      if (!found)
    {
      qUserError("\"" + parseWord + "\" not understood.");
      qCommandUsage(command);
      return [];
    }
    }


  return switches;
}

// universal switches


list qCommandAddDebugSwitch(list command)
{
  return qCommandAddSwitch(command, ["-debug", "integer"]);
}

list qCommandAddResetSwitch(list command)
{
  return qCommandAddSwitch(command, ["-reset"]);
}

list qCommandAddDieSwitch(list command)
{
  return qCommandAddSwitch(command, ["-die"]);
}

list qCommandAddHelpSwitch(list command)
{
  if (llGetInventoryType("Instruction Manual") == INVENTORY_NOTECARD)
    return qCommandAddSwitch(command, ["-help"]);

  else
    return command;
}


list qCommandAddUniversalSwitches(list command)
{
  command = qCommandAddDebugSwitch(command);
  command = qCommandAddResetSwitch(command);
  command = qCommandAddDieSwitch(command);
  command = qCommandAddHelpSwitch(command);

  return command;
}

integer qCommandExecuteUniversalSwitch(list switches, integer i)
{
  string switch = llList2String(switches, i);

  if (switch == "-debug")
    {
      i++;
      qDebugSetLevel(llList2Integer(switches, i));
      i++;
    }
  else if (switch == "-reset")
    {
      llResetScript();
      i++;
    }
  else if (switch == "-die")
    {
      llDie();
      i++;
    }

  else if (switch == "-help")
    {
      llGiveInventory(llGetOwner(),     
              "Instruction Manual");
      i++;
    }

  return i;
}




vector qGetLocalPosition()
{
  return llGetPos();
}

vector qGetGlobalPosition()
{
  return llGetPos() + llGetRegionCorner();
}

vector qGlobal2LocalPosition(vector global)
{
  return global - llGetRegionCorner();
}

vector qLocal2GlobalPosition(vector local)
{
  return local + llGetRegionCorner();
}

qSetLocalPosition(vector local)
{
  llSetPos(local);
}

qSetGlobalPosition(vector global)
{
  qSetLocalPosition(qGlobal2LocalPosition(global));
}

qGotoGlobalPosition(vector target)
{
  vector position = qGetGlobalPosition();

  integer i;
  for (i = 0;
       ((i < 1000) &&  // no infinite loops, thank you.
    (llVecDist(target, position) > 0.01));
       i++)
    {
      qSetGlobalPosition(target);
      position = qGetGlobalPosition();
    }
}







list shapeCommand;

buildShapeCommand()
{
  shapeCommand = qCommandCreate("shape");
  shapeCommand = qCommandAddUniversalSwitches(shapeCommand);

  shapeCommand = qCommandAddSwitch(shapeCommand, ["-setType",
                          "integer"]);
  shapeCommand = qCommandAddSwitch(shapeCommand, ["-setSculpt",
                          "string", "integer"]);
  shapeCommand = qCommandAddSwitch(shapeCommand, ["-sleep",
                          "integer"]);
  shapeCommand = qCommandAddSwitch(shapeCommand, ["-deleteScript"]);

}



initShapeCommand()
{
  buildShapeCommand();

  llListen(500, "", NULL_KEY, "");

  integer privateChannel = llGetStartParameter();
  if (privateChannel != 0)
    llListen(privateChannel, "", NULL_KEY, "");
}



executeShapeCommand(list switches)
{
  integer switchesLength = llGetListLength(switches);

  integer i;
  for (i = 1; i < switchesLength; i)
    {
      string switch = llList2String(switches, i);

      if (switch == "-setType")
    {
      integer type = llList2Integer(switches, i+1);
     
      if (type == 0)
        llSetPrimitiveParams([PRIM_TYPE, PRIM_TYPE_BOX, 0, <0.0, 1.0, 0.0>,
                  0.0, <0.0, 0.0, 0.0>, <1.0, 1.0, 0.0>, <0.0, 0.0, 0.0>]);
      else if (type == 1)
        llSetPrimitiveParams([PRIM_TYPE, PRIM_TYPE_CYLINDER, 0, <0.0, 1.0, 0.0>, 0.0,
                  <0.0, 0.0, 0.0>, <1.0, 1.0, 0.0>, <0.0, 0.0, 0.0>]);

      else if (type == 2)
        llSetPrimitiveParams([PRIM_TYPE, PRIM_TYPE_PRISM, 0, <0.0, 1.0, 0.0>, 0.0,
                  <0.0, 0.0, 0.0>, <0.0, 0.0, 0.0>, <0.0, 0.0, 0.0>]);

      else if (type == 3)
        llSetPrimitiveParams([PRIM_TYPE, PRIM_TYPE_SPHERE, 0, <0.0, 1.0, 0.0>, 0.0,
                  <0.0, 0.0, 0.0>, <0.0, 1.0, 0.0>]);

      else if (type == 4)
        llSetPrimitiveParams([PRIM_TYPE, PRIM_TYPE_TORUS, 0, <0.0, 1.0, 0.0>, 0.0,
                  <0.0, 0.0, 0.0>, <1.0, 0.25, 0.0>, <0.0, 0.0, 0.0>,
                  <0.0, 1.0, 0.0>, <0.0, 0.0, 0.0>, 1.0, 0.0, 0.0]);

      else if (type == 5)
        llSetPrimitiveParams([PRIM_TYPE, PRIM_TYPE_TUBE, 0, <0.0, 1.0, 0.0>, 0.0,
                  <0.0, 0.0, 0.0>, <1.0, 0.25, 0.0>, <0.0, 0.0, 0.0>,
                  <0.0, 1.0, 0.0>, <0.0, 0.0, 0.0>, 1.0, 0.0, 0.0]);

      else if (type == 6)
        llSetPrimitiveParams([PRIM_TYPE, PRIM_TYPE_RING, 0, <0.0, 1.0, 0.0>, 0.0,
                  <0.0, 0.0, 0.0>, <1.0, 0.25, 0.0>, <0.0, 0.0, 0.0>,
                  <0.0, 1.0, 0.0>, <0.0, 0.0, 0.0>, 1.0, 0.0, 0.0]);
                             
       

      i+=2;
    }

      else if (switch == "-setCube")
    {
      // i follow the ordering in llSetPrimParams, which is different than
      // the user interface...
      integer holeType = llList2Integer(switches, i+1);
      float cutBegin   = llList2Float(switches, i+2);
      float cutEnd     = llList2Float(switches, i+3);
      float hollow     = llList2Float(switches, i+4);
      float twistBegin = llList2Float(switches, i+5);
      float twistEnd   = llList2Float(switches, i+6);
      float taperX     = llList2Float(switches, i+7);
      float taperY     = llList2Float(switches, i+8);
      float shearX     = llList2Float(switches, i+9);
      float shearY     = llList2Float(switches, i+10);

      llSetPrimitiveParams([PRIM_TYPE, PRIM_TYPE_BOX, holeType,
                <cutBegin, cutEnd, 0.0>, hollow,
                <twistBegin, twistEnd, 0.0>,
                <taperX, taperY, 0.0>,
                <shearX, shearY, 0.0>]);

      i += 11;
    }

      else if (switch == "-setSculpt")
    {
      string sculptTexture = llList2String(switches, i+1);
      integer sculptType   = llList2Integer(switches, i+2);
      llSetPrimitiveParams([PRIM_TYPE, PRIM_TYPE_SCULPT, sculptTexture, sculptType]);
      i+=3;
    }
      else if (switch == "-deleteScript")
    {
      llRemoveInventory(llGetScriptName());
      i++;
    }


      else if (switch == "-sleep")
    {
      llSleep(llList2Integer(switches, i+1));
      i+=2;
    }


      else
    i = qCommandExecuteUniversalSwitch(switches, i);

    }
}



parseShapeCommand(string message)
{
list switches = qCommandParseText(shapeCommand, message);

  if (switches != [])
    executeShapeCommand(switches);

}


listenShapeCommand(integer channel, string name, key id,  string message)
{
  // we only accept commands on the public channel from our owner
  if ((channel == 500) &&
      (name != llKey2Name(llGetOwner())))
    return;

  parseShapeCommand(message);
}


linkMessageShapeCommand(integer sender, integer num, string message, key id)
{
  parseShapeCommand(message);
}


default
{
  state_entry()
    {
      initShapeCommand();
    }

  on_rez(integer n)
    {
      initShapeCommand();
    }

  listen(integer channel, string name, key id,  string message)
    {
      listenShapeCommand(channel, name, id, message);
    }

  link_message(integer sender, integer num, string message, key id)
    {
      linkMessageShapeCommand(sender, num, message, id);
    }
}



PrimScript
{L_CODE}:
// assembled by ../bin/lslcc -I. -I.. -I../.. primscript.lsl
// by qarl with qLab v0.0.3
// Tue Jun 19 09:27:34 PDT 2007
//
// Fixed for opensim by Adelle Fitzgerald - 5 november 2009


string parseWord;


qUserError(string message)
{
  llOwnerSay(message);
}




__qError(string error, string file, integer line)
{
  llOwnerSay(error + ":" +
          llGetScriptName() + ":" +
          file + "(" +
          (string)line + ")");
}


integer __qDebugLevel = 0;

qDebugSetLevel(integer level)
{
  __qDebugLevel = level;
}



__qDebug(string message, integer level, string file, integer line)
{
  if (level < __qDebugLevel)
    __qError("DEBUG: " + message, file, line);
}





list qCommandCreate(string commandName)
{
  list command;

  command = [ commandName ];

  return command;
}



list qCommandAddSwitch(list command, list switch)
{
  string switchName    = llList2String(switch, 0);
  integer settingCount = llGetListLength(switch) - 1;

  command += [switchName, settingCount];

  if (settingCount > 0)
    command += llList2List(switch, 1, settingCount);

  return command;
}


qCommandUsage(list command)
{
  qUserError("USAGE: " + llList2String(command, 0));

  integer commandLength = llGetListLength(command);

  integer i;
  for (i = 1; i < commandLength; i) // i incremented below
    {
      string output = "";

      string switch         = llList2String(command, i);
      i++;
      integer settingCount  = llList2Integer(command, i);
      i++;

      output = "     " + switch;

      integer j;
      for (j = 0; j < settingCount; j++)
    {
      output = output + " " + llList2String(command, i);
      i++;
    }

      qUserError(output);
    }
}




list qCommandParseText(list command, string text)
{
  integer commandLength = llGetListLength(command);

  list parse = llParseString2List(text, [" "], []);
  integer parseLength = llGetListLength(parse);

  // make sure this is our command
  string parseCommand   = llList2String(parse, 0);
  string commandCommand = llList2String(command, 0);

  string objectName = llGetObjectName();
  string objectKey  = (string)llGetKey();

  if ((parseCommand != "*") &&   // wildcard matches all commands
      (parseCommand != commandCommand) &&
      (parseCommand != objectName + "/" + commandCommand) &&
      (parseCommand != objectKey + "/" + commandCommand))
    return [];

  list switches = [ parseCommand ];;

  integer i;
  for (i = 1; i < parseLength; i) // i incremented below
    {
      parseWord = llList2String(parse, i);
      i++;

      integer found = 0;

      // scan switch list to see which one we've got:
      integer j;
      for (j = 1; (j < commandLength) && (found == 0); j) // j incremented below
    {

      string switch         = llList2String(command, j);
      j++;
      integer settingCount  = llList2Integer(command, j);
      j++;

      if (parseWord == switch)
        {
          found = 1;
          switches += [ switch ];

          integer k;
          for (k = 0; k < settingCount; k++)
        {
          if (i >= parseLength)
            {
              qUserError("\"" + switch + "\" requires " +
                 (string)settingCount + " options.");
              qCommandUsage(command);
              return [];
            }

          parseWord = llList2String(parse, i);
          i++;

          string settingType = llList2String(command, j+k);

          if (settingType == "float")
            switches += [(float) parseWord];

          else if (settingType == "integer")
            switches += [(integer) parseWord];

          else // assume string
            switches += [ llUnescapeURL(parseWord) ];
        }
        }
     
      j += settingCount;
    }


      if (!found)
    {
      qUserError("\"" + parseWord + "\" not understood.");
      qCommandUsage(command);
      return [];
    }
    }


  return switches;
}

// universal switches


list qCommandAddDebugSwitch(list command)
{
  return qCommandAddSwitch(command, ["-debug", "integer"]);
}

list qCommandAddResetSwitch(list command)
{
  return qCommandAddSwitch(command, ["-reset"]);
}

list qCommandAddDieSwitch(list command)
{
  return qCommandAddSwitch(command, ["-die"]);
}

list qCommandAddHelpSwitch(list command)
{
  if (llGetInventoryType("Instruction Manual") == INVENTORY_NOTECARD)
    return qCommandAddSwitch(command, ["-help"]);

  else
    return command;
}


list qCommandAddUniversalSwitches(list command)
{
  command = qCommandAddDebugSwitch(command);
  command = qCommandAddResetSwitch(command);
  command = qCommandAddDieSwitch(command);
  command = qCommandAddHelpSwitch(command);

  return command;
}

integer qCommandExecuteUniversalSwitch(list switches, integer i)
{
  string switch = llList2String(switches, i);

  if (switch == "-debug")
    {
      i++;
      qDebugSetLevel(llList2Integer(switches, i));
      i++;
    }
  else if (switch == "-reset")
    {
      llResetScript();
      i++;
    }
  else if (switch == "-die")
    {
      llDie();
      i++;
    }

  else if (switch == "-help")
    {
      llGiveInventory(llGetOwner(),     
              "Instruction Manual");
      i++;
    }

  return i;
}




// should make most of these #defines - to take advantage of pseudo polymorphism


float qMin(float a, float b)
{
  if (a < b)
    return a;
  else
    return b;
}

float qMax(float a, float b)
{
  if (a > b)
    return a;
  else
    return b;
}


float qClamp(float min, float max, float value)
{
  if (value < min)
    return min;
  if (value > max)
    return max;

  return value;
}



float qScale(float origMin, float origMax,
         float newMin, float newMax,
         float value)
{
  float x = (value - origMin)/(origMax - origMin);
 
  return newMin + x * (newMax - newMin);
}



float qSmoothstep (float edge0, float edge1, float x)
{
   if (x < edge0)
      return 0;

   if (x >= edge1)
      return 1;

   x = (x - edge0) / (edge1 - edge0);

   return x * x * (3.0 - 2.0 * x);
}


float qMod(float value, float divisor)
{
  integer m = llFloor(value / divisor);

  return value - m * divisor;
}

float qRandom(float min, float max)
{
  return llFrand(max - min) + min;
}




// computes bspline index - for either closed (periodic) or open bsplines.
integer qSplineIndex(integer index, integer length, integer closed)
{
  if (closed)
    return (integer) qMod(index, length);

  if (index > length - 1)
    return length - 1;

  if (index < 0)
    return 0;

  return index;
}

// vector spline function - takes a list of
// vectors and creates a spline over
// range [0..llGetListLength(vectors)] (uniform


vector qSplineV(list vectors, float value, integer closed)
{
  float length = llGetListLength(vectors);

  float floor   = (float)llFloor(value);
  float remains = value - floor;
 
  integer i1 = qSplineIndex((integer)(floor - 1.0), (integer)length, closed);
  integer i2 = qSplineIndex((integer)(floor + 0.0), (integer)length, closed);
  integer i3 = qSplineIndex((integer)(floor + 1.0), (integer)length, closed);
  integer i4 = qSplineIndex((integer)(floor + 2.0), (integer)length, closed);

  vector v1 = llList2Vector(vectors, i1);
  vector v2 = llList2Vector(vectors, i2);
  vector v3 = llList2Vector(vectors, i3);
  vector v4 = llList2Vector(vectors, i4);

  // weights derived from bspline matrix - [Foley1990, p. 493]
  float t  = remains;
  float t2 = t * remains;
  float t3 = t2 * remains;

  float w1 = -t3 + (3.0 * t2) - (3.0 * t) + 1.0;
  float w2 = (3.0 * t3) - (6.0 * t2) + 4.0;
  float w3 = (-3.0 * t3) + (3.0 * t2) + (3.0 * t) + 1.0;
  float w4 = t3;


  vector p = ( (w1 * v1) + (w2 * v2) + (w3 * v3) + (w4 * v4) ) / 6.0;

  return p;
}


// calculate approximate length of spline by stepping in segments.
// (you know, i bet this has a closed form.  too bad i'm too lazy/stupid to derive it.)
float qSplineVLength(list vectors, float v1, float v2, integer segments, integer closed)
{
  float length = 0;

  float segmentDelta = (v2 - v1) / segments;

  integer i;
  for (i = 0; i < segments; i++)
    {
      float s1 = v1 + segmentDelta * i;
      float s2 = s1 + segmentDelta;

      vector p1 = qSplineV(vectors, s1, closed);
      vector p2 = qSplineV(vectors, s2, closed);

      length += llVecDist(p1, p2);
    }

  return length;
}





rotation qRotationScale(float a, rotation r)
{
  rotation s;
 
  s.x = r.x * a;
  s.y = r.y * a;
  s.z = r.z * a;
  s.s = r.s * a;

  return s;
}



rotation qRotationMix(rotation a, rotation b, float t)
{
  float o = llAngleBetween(a, b) / 2.0;

  if (llFabs(llSin(o)) < 0.001) // too close!
    return a;

  if (o > PI/2.0)
    a = (a - a); // take shortest path, please

  rotation c = (qRotationScale(llSin((1.0 - t) * o), a) +
        qRotationScale(llSin(t * o), b));

  c = qRotationScale(1.0 / llSin(o), c);
                 
  return c;
}


string qFloat2String(float value, integer precision)
{
  integer base    = llFloor(value);
  float   remainder = value - base;

  string valueStr = (string) base;

  if (remainder != 0)
    {
      string remainderStr = (string) remainder;
      valueStr += llGetSubString(remainderStr, 1, precision + 1);
    }

  return valueStr;
}


string qVector2String(vector value, integer precision)
{

  return ("< " +
      qFloat2String(value.x, precision) + ", " +
      qFloat2String(value.y, precision) + ", " +
      qFloat2String(value.z, precision) + " >");
     
}



list __qDynaPrims;
float __qDynaRadius = 0;
integer __qDynaCount = 10;
vector __qDynaOrigin;


qDynaSetOrigin(vector o)
{
  __qDynaOrigin = o;
}

qDynaSetRadius(float r)
{
  __qDynaRadius = r;
}

qDynaSetCount(integer c)
{
  __qDynaCount = c;
}

integer qDynaRez()
{
  while(llGetListLength(__qDynaPrims) < __qDynaCount)
    {
      integer com = (integer)qRandom(10000, 10000000);

      vector place = (__qDynaOrigin +
              __qDynaRadius * llVecNorm(<llFrand(2.0) - 1,
                        llFrand(2.0) - 1,
                        llFrand(2.0) - 1>));

      llRezObject("qDynaPrim", llGetPos() + place,
          <0,0,0>, ZERO_ROTATION, com);

      // llSleep(1);

      __qDynaPrims = __qDynaPrims + [ com ];

    }

  integer front = llList2Integer(__qDynaPrims, 0);

  __qDynaPrims = llDeleteSubList(__qDynaPrims, 0, 0);

  return front;
}


qDynaCleanup()
{
  llSleep(10);
  while (llGetListLength(__qDynaPrims) > 0)
    {
      integer com = llList2Integer(__qDynaPrims, 0);
      llSay(com, "prim -die");
      __qDynaPrims = llDeleteSubList(__qDynaPrims, 0, 0);
    }
}



list command;
key scriptKey;
integer scriptLineNumber;
integer scriptRunning;
integer scriptCurrentPrim;




executeScriptLine(string line)
{
  __qDebug("executeScriptLine: " + line,  10, "primscript.lsl", 19);
  list words = llParseString2List(line, [" "], []);

  if ((llGetListLength(words) == 1) &&
      (llList2String(words, 0) == "newPrim"))
    scriptCurrentPrim = qDynaRez();
 
  else
    llSay(scriptCurrentPrim, line);
}


startScript(key script)
{
  __qDebug("startScript: " + (string)script,  5, "primscript.lsl", 33);
  scriptRunning = 1;
  scriptKey = script;
  scriptLineNumber = 0;
 
  llGetNotecardLine(scriptKey, scriptLineNumber);
}


endScript()
{
  __qDebug("endScript",  5, "primscript.lsl", 44);
  scriptRunning = 0;
  qDynaCleanup();
}



buildCommand()
{
  command = qCommandCreate("primscript");
  command = qCommandAddSwitch(command, ["-script", "string"]);
  command = qCommandAddUniversalSwitches(command);
}


initCommand()
{
  buildCommand();
 
  llListen(500, "", NULL_KEY, "");
}



executeCommand(list switches)
{
  integer switchesLength = llGetListLength(switches);

  integer i;
  for (i = 1; i < switchesLength; i)
    {
      string switch = llList2String(switches, i);

      if (switch == "-script")
        {
      startScript((key)llList2String(switches, i+1));
          i += 2;
        }
      else
        i = qCommandExecuteUniversalSwitch(switches, i);

    }
}


listenCommand(integer channel, string name, key id,  string message)
{
  // we only accept commands from our owner
  if (id != llGetOwner())
    return;

  list switches = qCommandParseText(command, message);

  if (switches != [])
    executeCommand(switches);
}



default
{
  state_entry()
    {
      scriptRunning = 0;
      initCommand();
    }

  dataserver(key id, string data)
    {
      if (data != EOF)
        {
      executeScriptLine(data);

          scriptLineNumber++;
          llGetNotecardLine(scriptKey, scriptLineNumber);
        }
      else
        endScript();
    }


  listen(integer channel, string name, key id,  string message)
    {
      if(!scriptRunning)
    listenCommand(channel, name, id, message);
    }

}

_________________
"Nothing lasts forever; It's scientific"
~David Byrne (Talking Heads)


Top
 Profile  
 
Display posts from previous:  Sort by  
Post a new topicPost a reply Page 1 of 1   [ 1 post ]


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  


Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
610nm Style by Daniel St. Jules of Gamexe.net