Jump to content

Texture rotation on a prim face.


Thomas Pallis
 Share

You are about to reply to a thread that has been inactive for 499 days.

Please take a moment to consider if this thread is worth bumping.

Recommended Posts

This problem has been driving me crazy for over a week now, so perhaps someone here can lend me a few brain cells.

I am trying to set the rotation of a texture on the face of a prim using llSetLinkPrimitiveParamsFast while maintaining its aspect ratio. 

When the rotation is 0°, the long side of the prim face should have a texture repeat of 1, and the short side of the prim face should have a repeat short/long. As the the texture is rotated I would like it maintain its aspect ratio. This requires that I change the horizontal and vertical repeats to account for the texture rotation.

I have a partial solution that works for the cardinal directions (0, 90, 180, 270).  But the texture becomes distorted as it rotates between these points. How do I maintain the aspect ratio of the texture as it is rotated?

Here are some images that demonstrate what I'm seeing.

The texture rotation at 0 and 90 degrees.

897053c6dcaac70ab345c47f83fcf79c.png014fdafbe316f8858ed4b138106fd293.png

Texture rotation at 45 and 22.5 degrees.

3d6c1ac2756dd9468e47a4ccf9ad325e.jpg283981a845db2516d90fd347dd5e2797.png

And here is my code so far

fixTexture()
{
        list params = llGetLinkPrimitiveParams(LINK_THIS, [
            PRIM_TEXTURE, 0
        ]);
        string texture = "90cd268c-d657-0b36-238c-5e39ed7929c4"; //llList2String(params, 0);
        vector repeats = <1, 1, 0>; // actual repeats calculated below.
        vector offsets = llList2Vector(params, 2);
        float zrot = llList2Float(params, 3);
        rotation texture_rot = llEuler2Rot(<0, 0, zrot>);
        
        vector dims = llGetScale(); // we want the X/Y of the prim
        dims.z = 0; // we don't care about z.
        
        // The larger dim determines our actual number of repeats.
        // I want 1 repeat across the larger of X or Y, the other
        // is some fraction of 1.
        if (dims.x > dims.y)
            repeats.y = dims.y / dims.x;
        else if (dims.y > dims.x)
            repeats.x = dims.x / dims.y;

        // this is what's missing *something* 
        // It works at the cardinal points (0, 90, 180, 270), but 
        // stretches in between. Wost distortion at 22.5 
        repeats = repeats * texture_rot;
        repeats.x = llFabs(repeats.x);
        repeats.y = llFabs(repeats.y);
        
        //llOwnerSay("repeats now: " + (string)repeats);
        
        llSetLinkPrimitiveParamsFast(LINK_THIS, [
            PRIM_TEXTURE, 0,    texture, repeats, offsets, zrot
        ]);
        
        integer degrees = (integer)(zrot * RAD_TO_DEG);
        llSetText((string)degrees + "°\n" +
                (string)repeats, <1,1,1>, 1);
}

integer STARTED = FALSE;

default
{
    state_entry()
    {
        STARTED = TRUE;
        llSetTimerEvent(0.1);
    }

    touch_start(integer total_number)
    {
        fixTexture();
        STARTED = !STARTED;
        if (STARTED)
            llSetTimerEvent(0.1);
        else 
            llSetTimerEvent(0);
    }
    
    timer()
    {
        fixTexture();
    }
}

 

Link to comment
Share on other sites

Sorry if my advice was over-simplistic and didn't really answer your question -  I bet if we wait longer, someone will provide better advice.

In any case, if your current code DOES work with a "square" prim, then it is probably your "# Repeats" logic vs. the X/Y dimensions.  (I think that is what you said!)

Good luck!

 

Link to comment
Share on other sites

Here's a picture of two overlapping prims:
- The bottom one has no texture rotation, the whole prim is rotated 45 degrees.
- The top one has been rotated ~20.5 degrees, so that the textures align vertically (if you follow the edges of each column)

202305202238_20b565943588d50f.png.870b8781d4c4819f3beeab512963e9af.png

You can tell that the top (rotated) texture is skewed, even though they technically align. This cannot be fixed by adjusting the repeats on the second axis. I think this problem is related to how non-planar texture mapping is handled, and it's impossible to preserve the square appearance on a non-square surface.

...unless you set the texture type to Planar, at which point the texture will rotate exactly how you want, without any math required.

 

Edited by Wulfie Reanimator
  • Thanks 2
Link to comment
Share on other sites

7 minutes ago, Wulfie Reanimator said:

You can tell that the top (rotated) texture is skewed, even though they technically align. I think this is related to how non-planar texture mapping is handled, and it's impossible to preserve the square appearance on a non-square surface.

...unless you set the texture type to Planar, at which point the texture will rotate exactly how you want, without any math required.

Thanks, and that is sad news. 

I had solved the problem for planar mapping, but I was hoping I'd be able to do it for a the default repeat mapping since that addresses another issue I was having with sloped surfaces and the dimensions of the face. 

The application I'm working on displays a texture on the top face of an object.  A secondary object is rezzed on top of the first and picks up the texture from the object under it and displays the portion of the texture that it would otherwise obscure. (the image below is using planar mapping.)

5353f4a2bd8bd7d9834801bda6687f99.jpg

  • Like 2
Link to comment
Share on other sites

1 hour ago, Thomas Pallis said:

The application I'm working on displays a texture on the top face of an object.  A secondary object is rezzed on top of the first and picks up the texture from the object under it and displays the portion of the texture that it would otherwise obscure. (the image below is using planar mapping.)

Have you considered projecting the texture onto your setup from an invisible prim above? That seems like it could get a similar result to your image.

  • Thanks 1
Link to comment
Share on other sites

This can be solved with some clever prim manipulation - no need to set planar mapping or use complicate script calculations. Make a square prim with 1:1 texture ratio. Then modify the prim's slice begin and slice end parameters to shave of the top and bottom until you recreate the desired shape. Modifying the prim's shape in this way is different for normal scaling in that it does not alter the aspect ratio of the prim face. So a regular texture rotation wil not distort the texture because it's still technically 1:1

Edited by Fenix Eldritch
  • Like 1
Link to comment
Share on other sites

You are about to reply to a thread that has been inactive for 499 days.

Please take a moment to consider if this thread is worth bumping.

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
 Share

×
×
  • Create New...