Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Discussion: Rotate prim while retaining scale

Lex Neva
wears dorky glasses
Join date: 27 Nov 2004
Posts: 1,361
06-22-2006 20:42
This script rotates a prim 90 degrees about an axis while keeping the scale oriented the same way. Have you ever had a time where you hollowed a box prim, only to find that you'd oriented the axes wrong and the hollow was in the wrong side? Correcting this can take several steps and some guesswork. This script makes it easy by reorienting the prim but adjusting the size in each axis so that the overall shape remains the same.

This is also useful for starting with a cylinder and making a tube prim that's shaped exactly the same; just rotate 90 degrees about the Y axis. You can reorient the dimple or cut axes of a sphere, too.

CODE

// Rotate while maintaining scale
//
// This script, when dropped into a prim, will reorient its axes but try to keep its dimensions oriented the same.
// For example, this is useful if you just want to reorient the hollow on a box.
//
// To use, just drop the script into a prim, and choose which (local) axis to rotate about. When you're done,
// click "done", and the script will delete itself.
//
// Concept and implementation by Lex Neva. Free to distribute, modify, turn into a birthday cake, etc, if you
// retain this attribution.

sendDialog(key av) {
llDialog(av, "Rotate how much around which axis?",["90 about X","90 about Y","90 about Z","-90 about X","-90 about Y","-90 about Z","done"],1);
}

default
{
state_entry()
{
sendDialog(llGetOwner());
llListen(1,"","","");
}

touch_start(integer num) {
sendDialog(llDetectedKey(0));
}

listen(integer channel, string name, key id, string message) {
if (id == llGetOwner()
// uncomment the next line to allow group members to use the scripts in shared objects
// otherwise if they drop the script into a shared object they don't own, the script
// won't listen to them
|| llSameGroup(id)
) {

if (message == "done") {
llSay(0,"Rotate script deleting.");
llRemoveInventory(llGetScriptName());
} else {
list parts = llParseString2List(message, [" "],[]);
float degrees = llList2Float(parts,0);
string axisName = llList2String(parts, 2);
vector axis;

if (axisName == "X")
axis = <1,0,0>;
else if (axisName == "Y")
axis = <0,1,0>;
else if (axisName == "Z")
axis = <0,0,1>;

rotation rot = llAxisAngle2Rot(axis, degrees * DEG_TO_RAD);

llSetRot(rot * llGetRot());

// Theoretically I should rotate the scale vector by the inverse of the rotation
// I rotate the prim by... but in practice, it doesn't matter since I'm using 90
// degree rotations and turning negatives to positives.
vector newScale = llGetScale() * rot;

// Correct negative values.

newScale.x = llFabs(newScale.x);
newScale.y = llFabs(newScale.y);
newScale.z = llFabs(newScale.z);

llSetScale(newScale);

sendDialog(id);
}
}
}
}
Nada Epoch
The Librarian
Join date: 4 Nov 2002
Posts: 1,423
Original Thread
06-28-2006 08:31
/15/79/115851/1.html
_____________________
i've got nothing. ;)
Jesse Malthus
OMG HAX!
Join date: 21 Apr 2006
Posts: 649
06-28-2006 09:32
I was there when Lex wrote this script, and I have to say it is AMUSING to watch and quite usefull!
For extra fun, try it on a flexiprim!
Seifert Surface
Mathematician
Join date: 14 Jun 2005
Posts: 912
06-29-2006 04:17
Maybe it's just the way I work, but I'm already finding this so useful it should be part of the client. I'll rez a cube, scale it down to what I want, and only then realise that the cut is in the wrong place to make the shape I want to... but no longer!
_____________________
-Seifert Surface
2G!tGLf 2nLt9cG
Lex Neva
wears dorky glasses
Join date: 27 Nov 2004
Posts: 1,361
06-29-2006 11:41
From: Seifert Surface
Maybe it's just the way I work, but I'm already finding this so useful it should be part of the client. ...


Well, the only problem with that is that it can do confusing and unintuitive things to a pipe/torus unless you know what you're doing. I'm satisfied to have it be an aftermarket addition, so to speak. By now, I have quite a few scripts that are essentially one-use "tools"; I drag them into the prim I want to modify, and they either do one action (stop particles, stop texture anims, etc) and disappear, or pop up a dialog (ie turning individual faces transparent) and then disappear when I tell them to.

My only wish is that I could set up a dedicated inventory tab or window that only showed these tool scripts.
Vlad Bjornson
Virtual Gardener
Join date: 11 Nov 2005
Posts: 650
06-29-2006 12:33
THanks for another useful script, Lex! :)

From: Lex Neva
My only wish is that I could set up a dedicated inventory tab or window that only showed these tool scripts.


Kind of a clunky work-around...You could name all of your one-shot utility scripts with a unique prefix (or postfix), open a second inventory window, Search for that Prefix, then leave that 2nd inventory window open. You'd have to do it every session, and lose a bit of screen real estate, but it should do the trick.
Lex Neva
wears dorky glasses
Join date: 27 Nov 2004
Posts: 1,361
06-30-2006 11:34
Yeah, that could work... it just sounds like such a pain. It really doesn't work for the other use I'd have for such functionality, which is putting my commonly used attachments all in one window. I can't rename all of them because some are no-mod :/