Loading a picture via url

Hi all!

I’m trying to load a jpeg image from a url to be used as my texture (for, say, a Box).
I figured out I should probably be doing something with the UrlAssetInfo or UrlLocator classes, but I’m afraid I just can’t seem to be able to get this done.
It i very confusing to use (for example, if I register using "assetManager.registerLocator( X, UrlAssetInfo.class) - what goes in the “X” place? In the ZipLocator of the tutorials, we wrote “town.zip” but putting the url there doesn’t help).

I have been programming quite a lot with Java at college-level a few years ago, and so I’d be really comfortable if someone could point out a useful source for me to learn how to do this (if an answer isn’t readily available) - I’m feeling as if I’m searching in the dark and don’t know what I’m doing and that frustrates me :slight_smile:

Thanks!!!
Amir.

I think we would have to have an example URL to be specific enough.

Whatever your URL is, the “asset” will be resolved relative to it.

1 Like

Look at this URL, for example:

How would you load that, as a texture, to a Material object?

Thank you!

My guess from the API:
assetManager.registerLocator( “http://i.telegraph.co.uk/multimedia/archive/02371”, UrlLocator.class );

Then load the image with the path: “karen-ann-jones_2371086k.jpg”

How I found this was to look at the javadoc for AssetManager, specifically:
http://hub.jmonkeyengine.org/javadoc/com/jme3/asset/AssetManager.html#registerLocator(java.lang.String,%20java.lang.Class)

Then I thought “Hmm… AssetLocator” and clicked on that.
http://hub.jmonkeyengine.org/javadoc/com/jme3/asset/AssetLocator.html

Then I saw UrlLocator… and clicked on that.
http://hub.jmonkeyengine.org/javadoc/com/jme3/asset/plugins/UrlLocator.html

You could also break the path down into a higher level directory or whatever and then include part of the path in the path to load the image.

1 Like

Well,

I’ve been all around these pages, searched the javadoc like a nice java student and what I tried didn’t work.
My code looked exactly the same as what you’ve written, only for some stupid reason I was writing “UrlAssetInfo” instead of “UrlLocator”.
I changed that. Now it works :slight_smile:

Your post really helped me understand I was in the (sort of) right direction and eventually get it done - Thank you!

Amir,

Hmmm… surprised it even compiled with UrlAssetInfo.class there.

From the javadoc:

1 Like

Indeed, the compiler forced me to cast the class to Class which should have prompted me something’s wrong, but I was so unsure of what I was doing I really didn’t think that I was just a step away from a working code.
Thanks again :slight_smile: