Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Building tools!

Christopher Omega
Oxymoron
Join date: 28 Mar 2003
Posts: 1,828
02-07-2004 12:38
Hi everyone! Me, being a cruddy builder and a bit of a perfectionist, began designing some tools to make building more accurate then using the edit window.


So far, Ive been able to replicate the actions of a prim being rescaled with edit menu's "Stretch Both Sides" option turned off.

------------------

The resizeSide() function:

CODE

integer sidePosX = 1;
integer sideNegX = 2;
integer sidePosY = 3;
integer sideNegY = 4;
integer sidePosZ = 5;
integer sideNegZ = 6;

resizeSide(integer side, float newScale)
{
vector curPos = llGetPos();
rotation curRot = llGetRot();
vector curSize = llGetScale();

vector newSize;
vector offset;

if(side == sidePosX)
{
newSize = <newScale,curSize.y,curSize.z>;
offset = <newSize.x - curSize.x,0,0> / 2;
}
else if(side == sideNegX)
{
newSize = <newScale,curSize.y,curSize.z>;
offset = <-(newSize.x - curSize.x),0,0> / 2;
}
else if(side == sidePosY)
{
newSize = <curSize.x,newScale,curSize.z>;
offset = <0,newSize.y - curSize.y,0> / 2;
}
else if(side == sideNegY)
{
newSize = <curSize.x,newScale,curSize.z>;
offset = <0,-(newSize.y - curSize.y),0> / 2;
}
else if(side == sidePosZ)
{
newSize = <curSize.x,curSize.y,newScale>;
offset = <0,0,newSize.z - curSize.z> / 2;
}
else if(side == sideNegZ)
{
newSize = <curSize.x,curSize.y,newScale>;
offset = <0,0,-(newSize.z - curSize.z)> / 2;
}

offset *= curRot;
llSetScale(newSize);

integer linkNum = llGetLinkNumber();
if(linkNum == 0)
{
llSleep(linkNum);
llSetPos(llGetLocalPos() + offset);
}
}


And example usage:

CODE

default
{
state_entry()
{
llListen(0,"",llGetOwner(),"");

}
listen(integer c, string n, key id, string m)
{
if(llSubStringIndex(m,llGetObjectName()) == 0) //w00t, the script gets to do something!
{
m = llToLower(m);
list mSplit = llParseString2List(m,[" "],[]);

string command = llList2String(mSplit,1);

if(command == "sidescale")
{
string param1 = llList2String(mSplit,2);
string param2 = llList2String(mSplit,3);
if(param1 == "+x")
{
resizeSide(sidePosX,(float)param2);
}
else if(param1 == "-x")
{
resizeSide(sideNegX,(float)param2);
}
else if(param1 == "+y")
{
resizeSide(sidePosY,(float)param2);
}
else if(param1 == "-y")
{
resizeSide(sideNegY,(float)param2);
}
else if(param1 == "+z")
{
resizeSide(sidePosZ,(float)param2);
}
else if(param1 == "-z")
{
resizeSide(sideNegZ,(float)param2);
}
}
}
}
}


What it does:

Lets say I have an object named A:

CODE

_______
| |
| |
|______|


With dimensions 1x1x1.

I say "A sidescale -z 4"

The resulting object has dimensions 1x1x4, however, the top of the object stays in the same position, like this:

CODE

Before: After:
_______ _______
| | | |
| x | | |
|______| | |
| x |
| |
| |
| |
|______|


The little x is the center of the objects.

Aside: Good god ascii art is HARD :rolleyes:

You 'talk' to the sidescale script like so:
(Lets say the script is in an object named "Foo";)

Foo sidescale +z 6
That makes Foo's z scale 6, but leaves the base of foo in the same position, and raises the top.

Foo sidescale +x 8
This makes Foo's positive x scale 8, but leaves the side of foo on the negative x axis (x axis is the red arrow you see when in edit mode, negative is the direction opposite the way the arrow is pointing) in the same position.

Foo sidescale +y 9
This makes Foo's positive y scale 9, but leaves the side of foo on the negative x axis in the same position, and resizes the side on the positive y axis.

To undo a scaling operation:

Lets say you have an object with dimensions 1x1x1

and say "Object sidescale +x 5"
This resizes the object to 5x1x1, and changes its position accordingly. To reset the object back to its original size and position, say "Object sidescale +x 1"

------------------

More functions coming soon! :D

==Chris
_____________________
October 3rd is the Day Against DRM (Digital Restrictions Management), learn more at http://www.defectivebydesign.org/what_is_drm
Synthia Gynoid
PRIMAL DREAMS
Join date: 10 Jul 2007
Posts: 52
11-26-2007 07:10
I can't seem to find the resizeSide() function in the LSL wiki.... I'm fairly new to coding, so maybe I'm missing something crucial, but also this function returns a syntax error when I try to use it in scripting. :(
Synthia Gynoid
PRIMAL DREAMS
Join date: 10 Jul 2007
Posts: 52
unable to use function
11-26-2007 16:05
I've looked up and down, and I can't seem to find the resizeSide() function in the LSL wiki or anywhere else, and it doesn't work in actual scripting. I'm new to scripting, so I'm probably missing something obvious. How does this function work, or what is the correct syntax? Thanks! :)