Skybox constructor

Hi all.

I'm n00b in this forum, so excuse-me if I'm posting in the wrong place.

I'm developing a 3d map and had the following problem:



Skybox sky = new Skybox();

Texture t2 = TextureManager.loadTexture("c:/temp/sky.jpg", Texture.MM_LINEAR, Texture.FM_LINEAR);

sky.setTexture(Skybox.NORTH, t2);





And I got an error:

java.lang.NullPointerException

at com.jme.scene.Skybox.setTexture(Unknown Source)



The problem: Skybox constructor CANNOT be used without parameters.

My sugestion: Change public Skybox() {} to private Skybox() {}. If you can't use anyway, the method can't be public.



Thank you

The errors indicate that your file cannot be found.

You should use the ResourceLocatorTool instead of the TextureManager… This feature was added in version 1.0

duenez said:

You should use the ResourceLocatorTool instead of the TextureManager... This feature was added in version 1.0


Really? Because this works for me with 1.0:


    private Skybox getSkybox(String... textures) {
        Skybox sb = new Skybox("skybox", 500, 500, 500);
        for (int i = 0; i < 6; i++) {
            URL imgURL = GalaxyGameState.class.getClassLoader().getResource(textures[i]);
            Texture tex = TextureManager.loadTexture(imgURL, Texture.MM_LINEAR_LINEAR, Texture.FM_LINEAR, Image.GUESS_FORMAT_NO_S3TC, 1, true);
            sb.setTexture(i, tex);
        }
        return sb;
    }
   
    private void initSkybox() {
        Skybox skybox = getSkybox(
                "risetothestars/img/skyboxGalaxy/front.png",
                "risetothestars/img/skyboxGalaxy/back.png",
                "risetothestars/img/skyboxGalaxy/right.png",
                "risetothestars/img/skyboxGalaxy/left.png",
                "risetothestars/img/skyboxGalaxy/up.png",
                "risetothestars/img/skyboxGalaxy/down.png");
        rootNode.attachChild(skybox);
    }



I found this post by Renanse but I am still a bit unsure - why would I want to use it? Is it that it allows finding files outside my src folder or... what? I am still quite confused about locating and placing resources - so far I have kept them all in my src folder. Could you please offer some advice on how this could be better handled and if it would still work with webstart etc.

Your approach also works mindgamer, but with the ResourceLocator you tell jME in which folders to look for different types of resrouces.



Later when you need to load them you can simply call loadResource("name.png");

The advantage to this is for example, that can change the directory of the resources at a central point in the source.

Core-Dump said:

Your approach also works mindgamer, but with the ResourceLocator you tell jME in which folders to look for different types of resrouces.

Later when you need to lead them you can simply call loadResource("name.png");
The advantage to this is for example, that can change the directory of the resources at a central point in the source.


Are there any further benefits besides this? I can achieve exactly the same thing by doing for example:


TextureManager.loadTexture(
    CommonConstants.IMG_RESOURCES_FOLDER + imgFileName,
    Texture.MM_LINEAR_LINEAR,
    Texture.FM_LINEAR,
    Image.GUESS_FORMAT_NO_S3TC,
    1,
    true);



... and have my CommonConstants.IMG_RESOURCES_FOLDER point to for example "risetothestars/img". I am sure there are benefits to the ResourceLocator - i'd just like to fully understand them.

ResourceLocators also allow you to get around the garbage that artists put into their models… so a model with some kind of entry like this does not trip you up:


<material texture="c:my really awesome textureslevel1testmaterialsskinsmyskin.jpg">



The resource locator tool will grab that path and look for it in your defined locators, chopping it down path by path.  So if you had a jar with a texture such as /textures/skins/myskin.jpg, it can find it for you.