0

I have a simple solar system consisting of two planets and a sun. I can now map images to spheres, but I want to map an animated gif to a sphere. I assumed this would be the same code, but when I load the animated gif, it simply plays the first frame and doesn't animated through the other frames.

The code that loads the image

            Texture tex = null;
            File img = new File("src/images/earth.jpg");

            try {
                tex = new TextureLoader(ImageIO.read(img)).getTexture();
            } catch (IOException e) {
                e.printStackTrace();
            }

            tex.setBoundaryModeS(Texture.WRAP);
            tex.setBoundaryModeT(Texture.WRAP);

            TextureAttributes texAttr = new TextureAttributes();
            texAttr.setTextureMode(TextureAttributes.MODULATE);

            Appearance ap = new Appearance();
            ap.setTexture(tex);
            ap.setTextureAttributes(texAttr);

            ------

            Node earth = new Sphere(earthRadius, primflags, 100, ap);

Am I missing something obvious? Any help or pointers would be fanatics. If I have failed to give enough detail, please ask and I will be more than happy to supply more code.

connor.p
  • 866
  • 9
  • 19
  • 30
  • 1
    You're loading a JPG for one thing. Also the texture won't animate itself. You have to update it. Eg. make a large texture and offset the coordinates, or use a bunch of textures, and switch which one is in use. – matt Apr 10 '16 at 18:20
  • Hi Matt, the example code above is the code I use to load a regular image. It is incidentally the same code I use to load the gif (which doesn't work as exampled above). So would you load each image (or frame) individually and then add them into a Switch? – connor.p Apr 10 '16 at 18:24
  • 1
    I am not sure what you mean by "load them into a switch," but yes. I would load each frame and then change the displayed texture at regular intervals. – matt Apr 10 '16 at 18:26
  • By "Switch", I'm referring to the j3d library. The Switch class allows for ease of transition between two or more states but I wasn't sure if this was the best way to loop through several images (frames). Thank you any for your input – connor.p Apr 10 '16 at 18:39
  • I think you can do this on the fly if you follow this answer http://stackoverflow.com/questions/8933893/convert-each-animated-gif-frame-to-a-separate-bufferedimage - I dont know if any of that works – gpasch Apr 10 '16 at 20:46

0 Answers0