Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Duplicating the Align Media Texture Button

Squeebee Wakawaka
Newbie Savant
Join date: 22 Feb 2006
Posts: 28
02-12-2007 15:57
Hi All;

As you probably know, using auto-align has a very detrimental effect on framerate, but I can't expect all my videos to be the same aspect ratio.

What I want to do is determine a way to automatically perform the adjustments made by the "Align Media Texture" button, assuming that I know the dimensions of the video being displayed.

Does anyone out there have any experience in doing this in a script? Ideally I wish the functionality of the button could just be called in code but I can't depend on that solution.

Thanks!
Lightwave Valkyrie
Registered User
Join date: 30 Jan 2004
Posts: 666
02-12-2007 16:04
what i did was offset scale my video screen and set all the videro sizes
like this:
CODE
    listen( integer channel, string name, key id, string message )
{
if(message=="size1")
{
llScaleTexture(1,1,ALL_SIDES);
llOffsetTexture(0,0,ALL_SIDES);
}
if(message=="size2")
{
llScaleTexture(0.7,0.55,ALL_SIDES);
llOffsetTexture(-0.155,-0.23,ALL_SIDES);
}
if(message=="size5")
{
llScaleTexture(0.6,0.8,ALL_SIDES);
llOffsetTexture(-0.2,0.0,ALL_SIDES);
}
}
}

then when i call my video from my selector i set the scale/offset with:
CODE
llSay(5,"size5");//scale my screen

you can see this in action at my anime music videos in Kaili (180,200,26)
-LW
_____________________
L$ is the root of all evil
videos work! thanks SL :)
Newgate Ludd
Out of Chesse Error
Join date: 8 Apr 2005
Posts: 2,103
02-13-2007 00:32
I have something similar to Lightwave's solution only it is held in the notecard along with the video name and URL.
Squeebee Wakawaka
Newbie Savant
Join date: 22 Feb 2006
Posts: 28
02-13-2007 19:58
Interesting, but I would have to hope that the proper scales and offsets could be determined programmically so that you would not need to have a preset defined. I think I'll have to do some math.

Of course, with the client being open source now, I suppose I could dig around till I find the code the Lindens are using.
Newgate Ludd
Out of Chesse Error
Join date: 8 Apr 2005
Posts: 2,103
02-14-2007 00:19
From: Squeebee Wakawaka
Interesting, but I would have to hope that the proper scales and offsets could be determined programmically so that you would not need to have a preset defined. I think I'll have to do some math.

Of course, with the client being open source now, I suppose I could dig around till I find the code the Lindens are using.



I dont think there are any functions that can give you back the parameters of the streamed data which is why we have had to resort to such workarounds.
Squeebee Wakawaka
Newbie Savant
Join date: 22 Feb 2006
Posts: 28
02-14-2007 08:17
I think perhaps I was unclear. I intend to store the dimensions of the video to be played in a notecard along with the name and URL, then use those dimensions to calculate the proper offsets and scales rather than depend on the dimensions matching a pre-defined list.
Newgate Ludd
Out of Chesse Error
Join date: 8 Apr 2005
Posts: 2,103
02-14-2007 11:13
Ah, yes thats what I do with my system.
Squeebee Wakawaka
Newbie Savant
Join date: 22 Feb 2006
Posts: 28
02-14-2007 11:49
Cool, can I ask how you convert the film dimensions into the appropriate scales and offsets?
Speon Beerbaum
Registered User
Join date: 29 Mar 2007
Posts: 11
Need that one too, getting stream res would be better though
04-26-2007 03:33
I'm currently looking for exact the same thing.
Since there is that button "Align media texture" in my client, i can't get the point why i cannot reproduce this functionality with a script.

This renders video streaming practically useless for me, as i was going to sell some media viewers and i don't want my customers to mess around with resolutions and aligning textures.
Since i can't even get the resolution of the stream, i can't calculate the offsets. *sigh*
Not to mention, that this auto align won't work with a multi-prim viewer. Therefore i really need to know the dimensions of the video, so i can calculate the size of the video on the texture and map it accordingly.

One of those LSL limitations i really don't like.
Guess i'm going to query my server, who will then query the stream and get it's resolution. Maybe i can then somehow calculate the offsets, if i have the dimensions of the stream.
I'm not that happy to use my server for something like that though. :(

Hopefully there will be added something to help us out in near future. Although i don't believe that. :-/

Regards,
Speon
Deanna Trollop
BZ Enterprises
Join date: 30 Jan 2006
Posts: 671
04-26-2007 07:57
From: Speon Beerbaum
Since there is that button "Align media texture" in my client, i can't get the point why i cannot reproduce this functionality with a script.
Possibly because, through llParcelMediaCommandList, stream URLs can be assigned on a client-by-client basis. Hence, only the client can know for sure the frame size of the stream assigned to it. And given the above possibility, setting the repeats and offsets for a face based on one stream would not be correct for a different size of stream, so in the case of multiple clients viewing different sized streams on the same prim face, at most one of them could be correct.

Assuming you'll only be setting one stream URL for the parcel, you could load the streams one at a time, use the Align Media Texture button to set the repeats/offsets, and record that information in a notecard or script for use when that particular stream is assigned.
Deanna Trollop
BZ Enterprises
Join date: 30 Jan 2006
Posts: 671
04-26-2007 08:35
But to answer the OP, this function will set the repeats and offsets of the specified face based on the media stream pixel width and height passed to it:

CODE

SetFrame( integer Width, integer Height, integer Face )
{
float Log2 = llLog( 2. );

// Video streams are padded on top and right
// to make their dimensions powers of 2
float TexWidth = 1 << llCeil( llLog( Width ) / Log2 );
float TexHeight = 1 << llCeil( llLog( Height ) / Log2 );

float XRep = Width / TexWidth;
float YRep = Height / TexHeight;

float XOff = ( XRep - 1. ) / 2.;
float YOff = ( YRep - 1. ) / 2.;

llScaleTexture( XRep, YRep, Face );
llOffsetTexture( XOff, YOff, Face );
}