Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

automatic UV change when object is stretched

Eep Quirk
Absolutely Relative
Join date: 15 Dec 2004
Posts: 1,211
01-04-2005 17:09
I have a chainlink fence that needs to be tiled at certain increments in order to look right and I was wondering, instead of having to make so many different-sized chainlink fence sizes if there's a way I can have the texture UVing automatically adjust depending on the size? I'm sure it's possible but I'm not that advanced at scripting...yet. ;)
Torley Linden
Enlightenment!
Join date: 15 Sep 2004
Posts: 16,530
01-04-2005 17:12
From: Eep Quirk
I have a chainlink fence that needs to be tiled at certain increments in order to look right and I was wondering, instead of having to make so many different-sized chainlink fence sizes if there's a way I can have the texture UVing automatically adjust depending on the size? I'm sure it's possible but I'm not that advanced at scripting...yet. ;)


Hm, what specifically do you mean by "UV"? I don't know what that stands for. Is what you refer to the same as the "Stretch Textures" checkbox or not? :)
_____________________
Eep Quirk
Absolutely Relative
Join date: 15 Dec 2004
Posts: 1,211
01-04-2005 17:39
http://tnlc.com/rw/terms.html#uv
DoteDote Edison
Thinks Too Much
Join date: 6 Jun 2004
Posts: 790
01-04-2005 18:22
Figure what your repeat would be on a 10m prim, store that as a float constant:

float hRepeatsAt10m = 5.0;
float vRepeatsAt10m = 1.0;

Then, use something like llGetScale() to get the length of your segment. something along the lines of:

vector fence = llGetScale();

Multiply the length component of that vector by the repeats:

float fenceLength = fence.x / 10; (or fence.y)
float fenceHeight = fence.z / 10;
float hRepeats = fenceLength * hRepeatsAt10m;
float vRepeats = fenceHeight * vRepeatsAt10m;

Finally, set the texture repeats:

llScaleTexture(hRepeats, vRepeats, ALL_SIDES);
Eep Quirk
Absolutely Relative
Join date: 15 Dec 2004
Posts: 1,211
01-04-2005 18:24
Yea, I'm pretty sure it's possible...I guess I was wondering if anyone had such a script... ;)
Malachi Petunia
Gentle Miscreant
Join date: 21 Sep 2003
Posts: 3,414
01-04-2005 21:05
It's pretty easy but I can't get in to check this pseudo-code:
CODE
float hRep = 1.0; // horizontal repeats per face
float vRep = 1.0; // vertical
default {
changed(integer c) {
if(c & CHANGED_SCALE)
llScaleTexture(hRep, vRep, ALL_SIDES);
}
}

Hope that helps.
DoteDote Edison
Thinks Too Much
Join date: 6 Jun 2004
Posts: 790
01-04-2005 21:25
I think Eep is looking for a way to establish world UV coordinates, such as found in 3D apps. Currently, SL only allows object-oriented mapping coordinates. I would like to see an option for world coordinates. This would allow textures to match despite varying prim sizes.
Eep Quirk
Absolutely Relative
Join date: 15 Dec 2004
Posts: 1,211
01-05-2005 03:35
From: Malachi Petunia
It's pretty easy but I can't get in to check this pseudo-code:
CODE
float hRep = 1.0; // horizontal repeats per face
float vRep = 1.0; // vertical
default {
changed(integer c) {
if(c & CHANGED_SCALE)
llScaleTexture(hRep, vRep, ALL_SIDES);
}
}

Hope that helps.


Awesome! Thanks. :) Now how do I get it to only affect specific sides? The Wiki lists the side numbers but how do I just affect sides 1 and 3? I don't know how to represent that as a single integer...
Malachi Petunia
Gentle Miscreant
Join date: 21 Sep 2003
Posts: 3,414
01-05-2005 04:12
Eep, ya gotta use two calls to llScaleTexture: one for side 1 and one for side 3.
Eep Quirk
Absolutely Relative
Join date: 15 Dec 2004
Posts: 1,211
01-05-2005 04:17
Bummer...inefficient. OK, thanks.
Eep Quirk
Absolutely Relative
Join date: 15 Dec 2004
Posts: 1,211
01-05-2005 16:57
OK, guess I didn't test it out enough initially, but this script doesn't seem to be doing what I'm shooting for. It seems to keep the set UV settings when the object is stretched, but what I want it to do is figure out the proportional UV settings relative to the new size. So if the UV is 1x1 when the object is 1m x 1m, if stretched to 2m x 2m the UV would change to 2x2; 1m x 2m would give UV 1x2, etc. Is that possible?
DoteDote Edison
Thinks Too Much
Join date: 6 Jun 2004
Posts: 790
01-05-2005 17:52
My out-of-world guess at a solution:

CODE

float hRepAt10m = 2.5; // horizontal repeats on a 10³ prim
float vRepAt10m = 5.0; // vertical repeats on a 10³ prim

default {
changed(integer c) {
vector fence = llGetScale();
float fenceLength = fence.x / 10; (or fence.y)
float fenceHeight = fence.z / 10;
float hRepNew = fenceLength * hRepAt10m;
float vRepNew = fenceHeight * vRepAt10m;
llScaleTexture(hRepNew, vRepeats, 1);
llScaleTexture(hRepNew, vRepeats, 3);
}
}


Use touch_start() in place of changed() if you don't want the prim to keep updating when you're drag-sizing it. Not a problem if you type numbers to resize, though.
Eep Quirk
Absolutely Relative
Join date: 15 Dec 2004
Posts: 1,211
04-16-2006 01:31
I should mention that I didn't know about the "stretch textures" option (which isn't documented that I could/can tell) which makes these scripts unnecessary, but it's still nice to be able to control texture tiling on-the-fly like that. Thanks for your help, everyone.