Jump to content

Newbie LSL scripter (but HTML/CSS pro) wants to ask ... displaying a random image on a prim face, but from web server?


Katherine Heartsong
 Share

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

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

Recommended Posts

Hi there, simple question I hope.

I can easily upload a few images (inspirational quotes about art) and also a small script to a flat, canvas like prim in world (in the Content tab) and display a random one of those images on a face when the object is touched. Happy to have learned that. But can this be done from a web server?

Suppose I have a directory on a server called /art-quotes and I hosted 100 images in that directory names sequentially quote-1.jpg, quote-2.jpg, quote-3.jpg ... or even just any non sequential name, like avery-1.jpg , Picasso-2.jpg , Richter-3.jpg, etc. I want to know if I can write a similar script that would then display one of those images randomly from my server's directory onto the face, rather than uploading 100 images to my Texture folder and manually adding them all to the prim's Content tab.

Thanks. If you can point me to the LSL Wiki to find out how to do that, I'd appreciate it.

Edited by Katherine Heartsong
spelling
Link to comment
Share on other sites

You're looking for Shared Media (known colloquially as Media On A Prim or MOAP).  You essentially want to present a static web page on a prim face as if you were using an auditorium projector to display it on a screen in your conference room in RL.  Have a look in the LSL wiki at http://wiki.secondlife.com/wiki/LlSetPrimMediaParams and read the Knowledge Base article on it 

The tricky part will be hosting your images someplace where you can refer to them with a URL that you can drop into the MOAP functions.  You might try saving them as Google photos, perhaps.

  • Thanks 1
Link to comment
Share on other sites

4 hours ago, Katherine Heartsong said:

So if the URL referenced a Javascript that loaded a random image on refresh/touch. Hmm. That would get me my randomness I need. I'll review those links, thanks so much!

The URL can reference e.g. a HTML page that loads random image using Javascript.

However keep in mind that not all residents have Shared Media enabled by default. They will have to click your prim first to see anything at all.

  • Thanks 1
Link to comment
Share on other sites

@Katherine Heartsong

Quote

I want to know if I can write a similar script that would then display one of those images randomly from my server's directory onto the face

the prim you are using will display a webpage on a prim face.

most likely your script would be server side, not a script in SL.

here is a basic example of a slideshow hosted outside of SL,

just set your media face to the url of your page...

JS iframe slideshow

 

 

Edited by Xiija
  • Thanks 1
Link to comment
Share on other sites

14 hours ago, Katherine Heartsong said:

Looking through the examples and documentation it appears as though I'll get browser controls when touching the prim. Is there no way to just show the random image that's being shown on page load?

You are correct. If we refer to a image as being a actual texture on a prim there is no other way that to upload that image to SL. The alternative provided is in simple words just showing a webpage on a prim. You of course with the use of some programming language like PHP make a page that randomly selects a image from a folder and displays that.

Link to comment
Share on other sites

On 1/14/2022 at 4:27 PM, Katherine Heartsong said:

Suppose I have a directory on a server called /art-quotes and I hosted 100 images in that directory names sequentially quote-1.jpg, quote-2.jpg, quote-3.jpg ... or even just any non sequential name, like avery-1.jpg , Picasso-2.jpg , Richter-3.jpg, etc. I want to know if I can write a similar script that would then display one of those images randomly from my server's directory onto the face

While you can construct a web page that randomly displays content using javascript, as others have suggested, it is also quite possible to do the random selection from within an LSL script and just point to a directory of images.

Using your example, if the URL to your directory is "someserver.com/art-quotes/" and all of the files within follow the same naming scheme of "quote-X.jpg", then the only part that actually needs to change is the X portion of the filename. If they're just integers, you can easily use llFrand() to choose a random number within a range and construct the full url to the image with it.

string url = "someserver.com/art-quotes/quote-";
integer img_count = 100;

default
{
    touch_start(integer total_number)
    {
        integer x = (integer)llFrand(img_count)+1;    //random number of range 1 to img_count
        llSetPrimMediaParams(0,
        [
            PRIM_MEDIA_CURRENT_URL, url + (string) x +".jpg"
        ]);
    }
}

 

A similar thing can be done for the artwork images. However, if you give both the art and quote files the same generic base name and only differentiated them by a number at the end, then you can use the above code for cover both at the same time. The only downside is that you lose some implicit descriptiveness about the file from the name.

  • Like 2
Link to comment
Share on other sites

Ah yes, some additional caveats...

First make sure your viewer preferences are set to enable the showing of media (many people have it disabled). In the official SL viewer you can find it in Preferences > Sound & Media > and ensure the "Enabled" checkbox for Media is on.

Secondly, even with media enabled, you still need to click on the prim's media face in order to initialize the browser. My demo uses face 0, which would be the "top" face of a default cube. Click it and the media face should activate. THEN you need to click on any OTHER face on that prim to trigger the touch_start event and thus run the demo code. Any clicks to the media face on the prim get directed into the browser and are not seen by the script.

If you want the picture change to happen automatically, you would want to use a timer event instead of a touch event.

Edit: So after looking at it again, I see that in my attempt to write a minimalist example, I made it behave awkardly... Click the top face twice. The first click will run the touch_start event which sets up the face as media on a prim. THEN clicking the top face a second time will activate the browser in your viewer. After that, clicks to any other face on the prim will run the touch_start event and cycle the picture. Sorry about the confusion.

Edited by Fenix Eldritch
correction
Link to comment
Share on other sites

Click the top face twice. (And wait a couple seconds between each click)

First click triggers the touch_start event which actually configures the top face to be prim media for the first time. You'll see the control bar hover over the face briefly and then fade away, but the media won't show yet.

Second click actually enables the prim media face to be active and visible on your viewer. The face should become highlighted with a selection border and begin to load up whatever url was last set. Remember, once the prim media is configured, you and everyone who wants to see it must click on the prim media face for the first time to activate it for their view. It's common for creators to somehow label the face with instructions saying as much.

To cycle to random images, click any other face on the prim besides the top face, as the prim media face will not relay further clicks on it to the script once the prim media is active.

This awkwardness is due to my bare bones minimalist example: because the demo only contains a touch_start event, everything is driven by it. You could add a state_entry and another llSetPrimMedia in it to automatically configure the face for prim media when the script first starts. That would save you one click. But you'd still need to click on the media face at least once to enable it on your viewer.

Link to comment
Share on other sites

@Katherine Heartsong

dunno if this helps, but here is a working example...

this displays on the forward X face ( face 2 ) .. you still have to add media to that face ...

( i set mine to ...  h ttps://img-test-2.tikihed.repl.co/images/img-0.png ... to start)

image numbers should start at zero.

there seems to be a 4 second delay in loading images for some reason ...

 

the LSL script >

string url        = "https://img-test-2.tikihed.repl.co/images/img-";
integer img_count = 2;
integer x         = 0;

default
{
    state_entry()
    {
       llSetPrimMediaParams(  2, 
       [  PRIM_MEDIA_AUTO_SCALE,TRUE,
          PRIM_MEDIA_PERMS_INTERACT,0x1, // owner
          PRIM_MEDIA_PERMS_CONTROL,0x0 , // none
          PRIM_MEDIA_AUTO_LOOP,TRUE,
          PRIM_MEDIA_AUTO_PLAY,TRUE 
       ]);
       llSetTimerEvent(0.5);
       
    }
    timer()
    {   llSetTimerEvent(6.0);
        x = ++x % img_count;   
        string show = url + (string) x +".png";      
        llSetPrimMediaParams(2,
        [  PRIM_MEDIA_CURRENT_URL, show
        ]);      
    }  
}

the server  i'm using, hosting files...

the Repl server

 

p.s. this is using .png as the file extension, you can use whatever, but make sure all your images are the same format?

Edited by Xiija
Link to comment
Share on other sites

You can do this, but media on a prim is deliberately limited, because the overhead is huge. Each prim face with media launches a full copy of a web browser inside each viewer that can see it. (It's Google Chromium, the open-source form of Chrome without DRM, and it shows up as  "Dullihan" in your active processes.)

The worst case can be seen in Cretopia, where there is a ring of prims in the air with media on a prim on each one. If you enable all of them, you need a computer with a lot of CPUs and maybe 32GB of memory.

Works fine for watching TV and movies in SL (although not for paid services such as Netflix, because those use DRM and each viewer copy has to pay). For ordinary images, it works, but should be used sparingly.

  • Like 1
Link to comment
Share on other sites

You are about to reply to a thread that has been inactive for 830 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...