Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Prim Resizing / Scaling

DeeDee Deepdene
Registered User
Join date: 8 Nov 2006
Posts: 7
03-05-2007 02:19
Hi

Wonder if anyone can point me in the right direction. Hopefully very simple.
Trying to package photographs and art and so have a one prim 'canvas' with image as texture. All images different sizes and so original prim will have correct dimensions.

Don't want the item to be set with Mod permissions and so would like a script to scale the canvas to the user requirements. Found some script to do this with linked prims on wiki but whats the point if I only need the one prim.

Ideally want a button control to adjust the size e.g. <, >, and reset however a chat command based script would be fine:-

and so here's what I did which is a bit daft but gotta learn somehow

in the linked prim

default {
link_message(integer sender_num, integer num, string str, key id) {
float scale; // size factor
list primparams;

scale = (float)str;

primparams = [];

primparams += [PRIM_SIZE, llGetScale() * scale]; // resize

if (llGetLinkNumber() > 1) { // only move if we're not the root object
primparams += [PRIM_POSITION, llGetLocalPos() * scale]; // reposition
}

llSetPrimitiveParams(primparams);
}
}

and in the root prim being 100% alpha invisible at the back of the picture

// rescales the linked set by the specified factor. factor > 1 makes it larger, < 1 smaller
// example: "/9 2.5"
Resize(float scale) {
integer num_prims = llGetNumberOfPrims();
integer i;

for (i = 1; i <= num_prims; i++) { // first prim in a linked set is 1
llMessageLinked(i, 0, (string)scale, NULL_KEY);
}

}

default {
state_entry() {
llListen(9, "", llGetOwner(), "";);
}

listen(integer channel, string name, key id, string message) {
float scale;

scale = (float)message;
if ( scale == 0.0 ) return; // we don't resize by factor 0.0

llSay(0, "Resizing by factor " + (string)scale);

Resize(scale);
}
}


all above as per wiki example....great it works BUT
how do i accomadate for silly user entry. The max size is obviously always going to be 10m x 10 X 10 and so if a user enters a scale of 2000 you end up with a 10m cube. Basically what I am trying to say is that the depth of the picture should always remain the same i.e. 0.25m.

Hope that all makes sense

Noob to scripting but reasonably intelligent...lol....any advice would be gratefully accepted

XX
DD
Newgate Ludd
Out of Chesse Error
Join date: 8 Apr 2005
Posts: 2,103
03-05-2007 03:59
From: DeeDee Deepdene
Hi

Wonder if anyone can point me in the right direction. Hopefully very simple.
Trying to package photographs and art and so have a one prim 'canvas' with image as texture. All images different sizes and so original prim will have correct dimensions.

Don't want the item to be set with Mod permissions and so would like a script to scale the canvas to the user requirements. Found some script to do this with linked prims on wiki but whats the point if I only need the one prim.

Ideally want a button control to adjust the size e.g. <, >, and reset however a chat command based script would be fine:-

and so here's what I did which is a bit daft but gotta learn somehow

....

all above as per wiki example....great it works BUT
how do i accomadate for silly user entry. The max size is obviously always going to be 10m x 10 X 10 and so if a user enters a scale of 2000 you end up with a 10m cube. Basically what I am trying to say is that the depth of the picture should always remain the same i.e. 0.25m.

Hope that all makes sense

Noob to scripting but reasonably intelligent...lol....any advice would be gratefully accepted

XX
DD

Please post using php tags, make it easier to read.

Check for and override any scale values that you dont like.

As for not allowing the thickness to change , just overwrite it with the required value.

Script based on performing calulation in child prim.
CODE


default
{
link_message(integer sender_num, integer num, string str, key id)
{
float scale = (float)str;
vector currentsize = llGetScale();
vector newsize = currentsize * scale;

if( ( newsize.x > 10.0 ) || ( newsize.y > 10.0) )
{
float ymax = 10.0 / currentsize.y;
float xmax = 10.0 / currentsize.x;

if(ymax <= xmax)scale = ymax;
else scale = xmax;

newsize = currentsize * scale;
}
newsize.z = 0.25; // Always 0.25m

list primparams = [];

primparams += [PRIM_SIZE, newsize]; // resize

if (llGetLinkNumber() > 1)
{
// only move if we're not the root object
primparams += [PRIM_POSITION, llGetLocalPos() * scale]; // reposition
}

llSetPrimitiveParams(primparams);
}
}


If all your prims start of the same size then you can keep a copy of the size in the root prim and precalculate any out of range scales.
DeeDee Deepdene
Registered User
Join date: 8 Nov 2006
Posts: 7
03-05-2007 04:08
Thank you so much :) DD
Works a treat BTW