5 Replies Latest reply: May 19, 2011 3:48 AM by 862749 RSS

    TextureCubeMap loading images

    862749
      I need to use TextureCubeMap to apply a shader to a group of Shape3D objects in a Java3D graph.
      I cannot load the images - continously getting errors.
      The code is:

                               String testTexName                = "resources/holition/images/test.jpg";     
                               URL testTexURL     =     Resources.getResource( testTexName);
                               TextureLoader loader = new TextureLoader( testTexURL, observ);
                               ImageComponent2D globeImage = loader.getImage();
                               globeImage.setCapability(ImageComponent2D.FORMAT_RGBA8);
                               System.out.println( "\t" + globeImage.getWidth() + "x" + globeImage.getHeight());
                               Texture2D texture = new Texture2D(Texture2D.BASE_LEVEL, Texture2D.RGB,
                                         globeImage.getHeight(), globeImage.getWidth());

                     TextureCubeMap rflMapTex     =     new TextureCubeMap( Texture.BASE_LEVEL, Texture2D.RGB,
                               globeImage.getWidth());                         
                               rflMapTex.setImage( Texture.BASE_LEVEL, TextureCubeMap.POSITIVE_X, globeImage);

      This gives me the following exception:
      Exception in thread "AWT-EventQueue-0" java.lang.IllegalArgumentException: Texture:illegal image size
           at javax.media.j3d.TextureRetained.checkImageSize(TextureRetained.java:419)
           at javax.media.j3d.TextureCubeMapRetained.initImage(TextureCubeMapRetained.java:65)
           at javax.media.j3d.TextureCubeMap.setImage(TextureCubeMap.java:217)

      For Texture2D class I've seen the solution is to set the image at level 0, but Texture.BASE_LEVEL = 0x01 so if instead of the last line in the code above I write
      rflMapTex.setImage( 0, TextureCubeMap.POSITIVE_X, globeImage);
      I don't get an exception anymore at loading, but when I apply the shader I obviously get the error:

      Exception in thread "AWT-EventQueue-0" java.lang.IllegalArgumentException: Texture: mipmap image not set at level0
           at javax.media.j3d.TextureRetained.setLive(TextureRetained.java:979)
           at javax.media.j3d.TextureUnitStateRetained.setLive(TextureUnitStateRetained.java:484)
           at javax.media.j3d.AppearanceRetained.doSetLive(AppearanceRetained.java:931)
           at javax.media.j3d.ShaderAppearanceRetained.doSetLive(ShaderAppearanceRetained.java:260)
           at javax.media.j3d.AppearanceRetained.setLive(AppearanceRetained.java:897)
           at javax.media.j3d.Shape3DRetained.doSetLive(Shape3DRetained.java:1150)
           at javax.media.j3d.Shape3DRetained.setLive(Shape3DRetained.java:975)
           at javax.media.j3d.GroupRetained.childDoSetLive(GroupRetained.java:2196)
           at javax.media.j3d.GroupRetained.doSetLive(GroupRetained.java:2249)
           at javax.media.j3d.BranchGroupRetained.setLive(BranchGroupRetained.java:187)
           at javax.media.j3d.GroupRetained.childDoSetLive(GroupRetained.java:2196)
           at javax.media.j3d.GroupRetained.doSetLive(GroupRetained.java:2249)
           at javax.media.j3d.TransformGroupRetained.setLive(TransformGroupRetained.java:567)
           at javax.media.j3d.GroupRetained.childDoSetLive(GroupRetained.java:2196)
           at javax.media.j3d.GroupRetained.doSetLive(GroupRetained.java:2249)
           at javax.media.j3d.TransformGroupRetained.setLive(TransformGroupRetained.java:567)
           at javax.media.j3d.GroupRetained.childDoSetLive(GroupRetained.java:2196)
           at javax.media.j3d.GroupRetained.doSetLive(GroupRetained.java:2249)
           at javax.media.j3d.BranchGroupRetained.setLive(BranchGroupRetained.java:187)
           at javax.media.j3d.Locale.doAddBranchGraph(Locale.java:230)
           at javax.media.j3d.Locale.addBranchGraph(Locale.java:189)
           at com.sun.j3d.utils.universe.SimpleUniverse.addBranchGraph(SimpleUniverse.java:388)
           at com.ibsm.holition.shaders.demo.ShadersDemoRing.<init>(ShadersDemoRing.java:235)
           at com.ibsm.holition.shaders.demo.ShadersDemoRing$2.run(ShadersDemoRing.java:267)
           at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)
           at java.awt.EventQueue.dispatchEvent(EventQueue.java:597)
           at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
           at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
           at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
           at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
           at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
           at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)


      For me it is an obvious Java3D bug.


      Did anyone of you had any experience using the TextureCubeMap class in Java3D ?
        • 1. Re: TextureCubeMap loading images
          LeW
          ..not sure, but I suspect this error message points primary problem:

          "Exception in thread "AWT-EventQueue-0" java.lang.IllegalArgumentException: Texture:illegal image size"
          • 2. Re: TextureCubeMap loading images
            862749
            Believe me, I've tried with image sizes from 256 x 256 down to 16 x 16, all power of 2.
            I've looked into the Java3D source code and it all boils down to

            TextureRetained.checkImageSize with the following code:

            final void checkImageSize(int level, ImageComponent image) {
            if (image != null) {
                 int imgWidth = ((ImageComponentRetained)image.retained).width;
            int imgHeight = ((ImageComponentRetained)image.retained).height;

            int wdh = width;
                 int hgt = height;
                 for (int i = 0; i < level; i++) {
            wdh >>= 1;
            hgt >>= 1;
            }

                 if (wdh < 1) wdh = 1;
                 if (hgt < 1) hgt = 1;

                 if ((wdh != (imgWidth - 2*boundaryWidth)) ||
            (hgt != (imgHeight - 2*boundaryWidth))) {
                 throw new IllegalArgumentException(
                                J3dI18N.getString("TextureRetained1"));
                 }
            }
            }


            Now, the issue is I am passing Texture.BASE_LEVEL (equaling 1) to TextureCubeMap.setImage first parameter, so the above code never works.
            I strongly suspect a Java3D bug.
            • 3. Re: TextureCubeMap loading images
              LeW
              ..do you tried ask on another java3d forum -
              http://www.java.net/forums/javadesktop/java-desktop-technologies/java-3d
              if not, try

              also, if posible, you can prepare test case, ppl will can try your problem on their environments.
              • 4. Re: TextureCubeMap loading images
                InteractiveMesh
                Hi, hope that following hints are helpful:

                - 'globeImage.setCapability(ImageComponent2D.FORMAT_RGBA8);' : ImageComponent2D.FORMAT_RGBA8 is not a capability flag! The format of an ImageComponent2D instance can't be changed and will be set in the constructor. What do you intend to achieve?

                - Texture.BASE_LEVEL is a mipmap mode flag to be used in texture constructors. It must not be used to set a mipmap level. Mipmap levels are just integers starting at '0' for the base level image: 'rflMapTex.setImage(0, TextureCubeMap.POSITIVE_X, globeImage);'.

                - Exception in thread "AWT-EventQueue-0" java.lang.IllegalArgumentException: Texture: mipmap image not set at level 0' is thrown at javax.media.j3d.TextureRetained.setLive(TextureRetained.java:979) because in case of TextureCubeMap all six images for the six faces must be set: numFaces has the value '6'. Did you set all six images?

                August
                • 5. Re: TextureCubeMap loading images
                  862749
                  Thank you very much for the info. After around 4 hours of tests I got to the same conclusion: the second exception mentioned in my email was because I had not set all 6 images.
                  However, the man page for TextureCubeMap said the level had to be Texture.BASE_LEVEL (which has the value 1), so that was the value I had used.
                  Basically, using 0 instead of Texture.BASE_LEVEL as the first param in TextureCubeMap.setImage, PLUS setting all 6 images had solved the problem.
                  Thank you very much for the effort.