Christopher Snowbear
08-18-2009, 08:57 PM
Drop this in a prim, and you can drag around the textures on it just by touching and dragging. It doesn't matter if they're planar or default mapped, rotated, scaled, or flipped. It doesn't matter what type of prim it is. It should work on everything (I've never actually tested it on a sculpty... but it should work).
// Change this to TRUE, to allow anyone to drag textures around.
integer allow_anyone = FALSE;
key avatar_touching = NULL_KEY;
vector start_touch_offset = ZERO_VECTOR;
vector start_texture_offset = ZERO_VECTOR;
integer touch_side = 0;
default
{
touch_start(integer n)
{
key detected_avatar = llDetectedKey(0);
touch_side = llDetectedTouchFace(0);
if ((avatar_touching == NULL_KEY || llGetTime() > 0.25) && (detected_avatar == llGetOwner() || allow_anyone) && llDetectedLinkNumber(0) == llGetLinkNumber() && touch_side != 0xFFFFFFFF)
{
avatar_touching = detected_avatar;
start_touch_offset = llDetectedTouchUV(0);
start_texture_offset = llGetTextureOffset(touch_side);
}
}
touch(integer n)
{
if (avatar_touching == llDetectedKey(0))
{
if (llDetectedTouchFace(0) != touch_side)
{
llOffsetTexture(start_texture_offset.x, start_texture_offset.y, touch_side);
return;
}
vector texture_offset = llGetTextureOffset(touch_side) - (llDetectedTouchUV(0) - start_touch_offset);
while (texture_offset.x > 1.0) texture_offset.x -= 2.0;
while (texture_offset.x < -1.0) texture_offset.x += 2.0;
while (texture_offset.y > 1.0) texture_offset.y -= 2.0;
while (texture_offset.y < -1.0) texture_offset.y += 2.0;
llOffsetTexture(texture_offset.x, texture_offset.y, touch_side);
llResetTime();
}
}
touch_end(integer n)
{
integer i;
for (i = 0; i < n; i += 1)
{
if (llDetectedKey(i) == avatar_touching)
{
avatar_touching = NULL_KEY;
return;
}
}
}
}
// Change this to TRUE, to allow anyone to drag textures around.
integer allow_anyone = FALSE;
key avatar_touching = NULL_KEY;
vector start_touch_offset = ZERO_VECTOR;
vector start_texture_offset = ZERO_VECTOR;
integer touch_side = 0;
default
{
touch_start(integer n)
{
key detected_avatar = llDetectedKey(0);
touch_side = llDetectedTouchFace(0);
if ((avatar_touching == NULL_KEY || llGetTime() > 0.25) && (detected_avatar == llGetOwner() || allow_anyone) && llDetectedLinkNumber(0) == llGetLinkNumber() && touch_side != 0xFFFFFFFF)
{
avatar_touching = detected_avatar;
start_touch_offset = llDetectedTouchUV(0);
start_texture_offset = llGetTextureOffset(touch_side);
}
}
touch(integer n)
{
if (avatar_touching == llDetectedKey(0))
{
if (llDetectedTouchFace(0) != touch_side)
{
llOffsetTexture(start_texture_offset.x, start_texture_offset.y, touch_side);
return;
}
vector texture_offset = llGetTextureOffset(touch_side) - (llDetectedTouchUV(0) - start_touch_offset);
while (texture_offset.x > 1.0) texture_offset.x -= 2.0;
while (texture_offset.x < -1.0) texture_offset.x += 2.0;
while (texture_offset.y > 1.0) texture_offset.y -= 2.0;
while (texture_offset.y < -1.0) texture_offset.y += 2.0;
llOffsetTexture(texture_offset.x, texture_offset.y, touch_side);
llResetTime();
}
}
touch_end(integer n)
{
integer i;
for (i = 0; i < n; i += 1)
{
if (llDetectedKey(i) == avatar_touching)
{
avatar_touching = NULL_KEY;
return;
}
}
}
}