Forum Stats

  • 3,872,586 Users
  • 2,266,452 Discussions
  • 7,911,259 Comments

Discussions

GeometryArray: cannot directly access data in BY_REFERENCE mode

843799
843799 Member Posts: 49,999
edited Dec 10, 2009 10:19PM in Java 3D
I m loading *.obj file to my scene. After loading i want to save this scene using j3dfly. But this exception occurs. Any solution to this?



java.lang.IllegalStateException: GeometryArray: cannot directly access data in BY_REFERENCE mode
at javax.media.j3d.GeometryArray.getCoordinates(Unknown Source)
at com.sun.j3d.demos.utils.scenegraph.io.state.javax.media.j3d.GeometryArrayState.writeObject(GeometryArrayState.java:53)
at com.sun.j3d.demos.utils.scenegraph.io.state.javax.media.j3d.TriangleArrayState.writeObject(TriangleArrayState.java:31)
at com.sun.j3d.demos.utils.scenegraph.io.retained.Controller.writeObject(Controller.java:271)
at com.sun.j3d.demos.utils.scenegraph.io.retained.RandomAccessFileControl.writeObject(RandomAccessFileControl.java:359)
at com.sun.j3d.demos.utils.scenegraph.io.retained.RandomAccessFileControl.writeNodeComponents(RandomAccessFileControl.java:309)
at com.sun.j3d.demos.utils.scenegraph.io.retained.RandomAccessFileControl.writeBranchGraph(RandomAccessFileControl.java:183)
at com.sun.j3d.demos.utils.scenegraph.io.SceneGraphFileWriter.writeBranchGraph(SceneGraphFileWriter.java:94)
at com.sun.j3d.demos.utils.scenegraph.io.SceneGraphFileWriter.writeBranchGraph(SceneGraphFileWriter.java:83)
at net.ege.yzgrafik.ec3d.action.SceneUtility.saveSceneGraph(SceneUtility.java:117)
at net.ege.yzgrafik.ec3d.action.SceneUtility.saveScene(SceneUtility.java:72)

Comments

  • 843799
    843799 Member Posts: 49,999
    you can convert the geometry to another wrapper if BY_REFERENCE doesn`t work for you. This code from java.net furum -
      /**
       * convert Shape3D's geometryArrays  using GeometryInfo. 
       * @param shp - the Shape3D target
       * @param indexed - creates a indexed GeometryArray
       * @param compact - compact, if indexed.
       * @param byRef - create a BY_REFERENCE geometry
       * @param interleaved -  create a INTERLEAVED geometry
       * @param useCoordIndexOnly - force USE_COORD_INDEX_ONLY in indexed Geometries
       * @param nio - Use NIO buffers
       */
       public  void convert(Shape3D shp,boolean indexed,
                                        boolean compact,
                                        boolean byRef,
                                        boolean interleaved,
                                        boolean useCoordIndexOnly,
                                        boolean nio)
       {     
        Enumeration enum =  shp.getAllGeometries();
        while (enum.hasMoreElements())
        {
          GeometryArray geo = (GeometryArray)enum.nextElement();
          shp.removeGeometry(geo);       
          GeometryInfo gi = new GeometryInfo(geo);
          NormalGenerator ng = new NormalGenerator();
          ng.generateNormals(gi);      
          GeometryArray ga; 
          if (indexed)
          {
            ga = gi.getIndexedGeometryArray(compact,
                                             byRef,
                                             interleaved,
                                             useCoordIndexOnly,
                                             nio);
          }
          else
          {
            ga = gi.getGeometryArray(byRef,interleaved,nio); 
          }
          shp.addGeometry(ga);
         }
       }
       
       /**
       * Some Basic info about a Shape3D 
       * @param shp
       */
       public void printInfo(Shape3D shp)
       {
         Enumeration enum =  shp.getAllGeometries();
        while (enum.hasMoreElements())
        {
          Object obj = enum.nextElement();
          if (obj instanceof GeometryArray)
          {
           GeometryArray geo = (GeometryArray) obj; //enum.nextElement(); 
           System.out.println("Geometry " + geo.getClass().getName());
           
           int vertexFormat = geo.getVertexFormat();    
           
           System.out.println("VertexCount: " + geo.getVertexCount() );
           System.out.println("ValidVertexCount: " + geo.getValidVertexCount() );
           
           boolean isReference = bInA(GeometryArray.BY_REFERENCE,vertexFormat) ;
           boolean isTC2 = bInA(GeometryArray.TEXTURE_COORDINATE_2,vertexFormat);
           boolean isTC3 = bInA(GeometryArray.TEXTURE_COORDINATE_3,vertexFormat);
           boolean isTC4 = bInA(GeometryArray.TEXTURE_COORDINATE_4,vertexFormat);
           boolean isInterleaved = bInA(GeometryArray.INTERLEAVED,vertexFormat);
           boolean isUSE_NIO_BUFFER = bInA(GeometryArray.USE_NIO_BUFFER,vertexFormat);
           boolean isUSE_COORD_INDEX_ONLY = bInA(GeometryArray.USE_COORD_INDEX_ONLY,vertexFormat);
           boolean isNORMALS = bInA(GeometryArray.NORMALS,vertexFormat);
           
            System.out.println("Is BY_REFERENCE: " + isReference );
            System.out.println("Is TEXCOORD2: " + isTC2 );
            System.out.println("Is TEXCOORD3: " + isTC3 );
            System.out.println("Is TEXCOORD4: " + isTC4 );
            System.out.println("Is INTERLEAVED: " + isInterleaved );
            System.out.println("Is USE_NIO_BUFFER: " + isUSE_NIO_BUFFER );
            System.out.println("Is USE_COORD_INDEX_ONLY: " + isUSE_COORD_INDEX_ONLY );
            System.out.println("Has isNORMALS: " + isNORMALS );       
         }
        }
       }
       
       /**
       * Check if b values is ORed in a
       * @param b checking value 
       * @param a ORed value
       * @return true if b is ORed in a
       */
       private boolean bInA(int b, int a)
       {
         return (a & b) == b;
       }
       
  • 843799
    843799 Member Posts: 49,999
    Thanks for your reply. But my problem is with j3fly.

    In this paragraph giving exception:
    	if ((vertexFormat & GeometryArray.COORDINATES)!=0 ) {
    	    float[] points = new float[ vertexCount*3 ];
    	    ((GeometryArray)node).getCoordinates( 0, points );//This line giving exception
    
    	    writeFloatArray( out, points );
    	}
    I dont know how to solve that. If anyone used j3fly and encounter this exception please help.
  • 843799
    843799 Member Posts: 49,999
    Here is solution for my problem,thanks for help.

    http://forums.java.net/jive/thread.jspa?forumID=70&threadID=12860&messageID=79800#79800
  • 843799
    843799 Member Posts: 49,999
    Warm Greetings,

    You need the .obj file loader, MilkShape 3D is a nice one from chumbalumsoft.ch. The program can import the .obj file then save it to a .ms3d file (unmodified) and then load the .ms3d file into java using the MilkShape3dLoader class.

    Check out the web site, or look up the authoring tool such as Studio 3d Max and find the "Studio max 3d Loader" to download and put that in your library section so your IDE compiler detects it.

    The Loader acts as a translator which transforms the content of a file, such as MilkShape3D and transforms it into Primitive object types like Box, Cone, etc. and then loads the artwork into the Scenegraph as a "scene" file into a javax.media.j3d.BranchGroup object.

    I suggest MilkShape3D which can load in FBX format from AutoDesk Maya 2010 and AutoDesk Studio 3DS Max 2010, I have tested on those recently.

    Cheers,
    -Cymryjian.

    Try googling it.
This discussion has been closed.