Showing posts with label llOffsetTexture. Show all posts
Showing posts with label llOffsetTexture. Show all posts

Wednesday, August 25, 2010


I had a discussion with another developer about the moonphase virtual sculpture. They mentioned a technique that might improve bandwidth usage by using llSetTextureAnim instead of setting the offset of the texture directly. The idea being that llSetTextureAnim would be running on the actual client which doesn't require any bandwidth, while llOffsetTexture is run on the server and all the clients viewing that object need to receive a message that the object change.

So I did some testing with llSetTextureAnim and I couldn't get the same results. When you use ROTATE in llSetTextureAnim then you can't specify the texture offset, only which portion of the texture you want to use. It seems like it is used to have a tiled texture where each section of the tile can be used as an individual tile. In my case, I used a half transparent texture and am rotating that around the sphere. Using llSetTextureAnim I don't see a way to get the same effect. I'm a little slow most of the time so I may be missing something. Here is a screen shot of using
default
{ state_entry()
{
llSetTextureAnim(ANIM_ON | LOOP | SMOOTH | ROTATE,ALL_SIDES, 1,1, 0, TWO_PI, TWO_PI/360);
}
}



I also tried using a non-ROTATE texture animation which only cause the texture to turn on and off when the "tile" reached the non-transparent section.

I really like the idea of reducing bandwidth by having the texture changes run on each client, but don't see a way to get this to work for this sculpture. llSetTextureAnim is definitely a good tool for the tool belt and I'll have to consider some sort of sculpture using a tiled texture. That would mean that each client would see something different on their machine so there couldn't be a discussion about the "current" look of the sculpture between two people, but I'm not sure that's a real problem.

Thursday, July 24, 2008

Second Life Physics Scripting - Pinball #19 - Puck Flipper Mechanic

Since the flipper mechanic just wasn't going to work I've decided for a bar at the bottom of the table where you can move what area is currently active. Sort of like pong, but more primitive. I'm hoping that people will identify with it as a puck because it's attached to a pinball machine. I wanted to use a changing texture on a single primitive to increase the speed changes since there aren't the same delays for texture changes as there are for position and rotation. This is some quick temporary art I came up with as the texture.



The image is split into four positions that will bounce the ball if it hits in the current position. I offset a little into the other colors to make it a little easier and allow for you to hit things that were right on the borders of the colors.

I'm sliding this around on a cube face much like I did the number texture. There was nothing fancy when figuring out the offsets. Hit and miss and tweaking the u/v numbers on the texture editing. I did only apply this texture to a single side of a rectangular cube. You do that by toggling the "select texture" radio button on the editor. Here is the script that changes which color is currently active.


// texture offsets
// h = 0;
// v =
// 0.375 (red=1)
// 0.125 (blue=2)
// -0.125 (green = 3)
// -0.375 (yellow = 4)
integer curval = 1;
doOffset()
{
//llOwnerSay("offset ="+(string)ftmp);
if (curval<0)
{
curval = 3;
}
else if (curval>3)
{
curval = 0;
}
float foffset = 0.375;
if (curval == 1)
{
foffset = 0.125;
}
else if (curval == 2)
{
foffset = -0.125;
}
else if (curval == 3)
{
foffset = -0.375;
}
llOffsetTexture(0.0,foffset,ALL_SIDES);
}

default
{
state_entry()
{
doOffset();
}

touch_start(integer total_number)
{
curval++;
doOffset();
}
}


Thursday, June 26, 2008

Second Life Script - Number Texture Display

I needed a number display system. I've seen these in other items, but as usual I'm willing to just figure it out and build my own.

I first created a simple 16x256 pixel image of all the numbers. I made 16 numbers because textures are all power of two stuff. I doubt I'll do any hexadecimal displays, but I had the extra room.


I then used hit and miss to figure out the offsets for the numbers. I found the change from one number to the next was about 0.6 then worked backwards and forwards until I had both edges and -0.47 and +0.47. To make this programticall, I used (0.47*2)/16 to get 0.05875 which I tried, then finally figured out that I needed to divide by 15 because one cell is not counted in the actual size. That gave me an offset of 0.62666666.

integer curval = 0;
doOffset()
{
float ftmp = -0.47+(curval*0.062666);
llOwnerSay("offset ="+(string)ftmp);
llOffsetTexture(ftmp,0.0,ALL_SIDES);
}

default
{
state_entry()
{
doOffset();
}

touch_start(integer total_number)
{
// u offsets
//0=-0.47
//1=-0.41
//2=-0.35
//3=-0.29 *
//4=-0.22
//5=-0.16
//6=-0.10
//7=-0.04 *
//8=0.03
//9=0.09
//A=0.15
//B=0.21
//C=0.28 *
//D=0.34
//E=0.41
//F=0.47
// 0.47*2/15 = 0.06266666
curval++;
if (curval>16)
curval = 0;
doOffset();
}
}

There is one glaring problem I noticed after I got the number image uploaded. I probably need one cell that is only transparent so I can turn of the number. I'll do this later with another image upload and use -1 to display the blank number, but then I will not be able to show a hexadecimal number! Oh well... I'll probably end up making the other columns numeric symbols like dollar, pound, comma, period and such.



Make sure you apply the number texture to only one face. The rest of the faces are completely transparent. A simple trick is to select the texture face on the build dialog, then click on the individual faces to apply the texture to only that face.