ObjToJme classcastexception error

I've tried all sorts of things to get this to work, but whenever I try to use the built in ObjToJme converter, I keep getting the following error:



java.lang.ClassCastException: com.jme.scene.TriMesh
   at spaceops.TestObjJmeWrite.simpleInitGame(TestObjJmeWrite.java:71)
   at com.jme.app.BaseSimpleGame.initGame(Unknown Source)
   at com.jme.app.BaseGame.start(Unknown Source)
   at spaceops.TestObjJmeWrite.main(TestObjJmeWrite.java:57)



That's with the example in the jmetest section (from CVS). It'll work with the obj files in the cvs tree, but not with any other I've thrown at it. I've told Blender to translate everything to triangles and whatnot, but still no luck. Is this a bug? Or am I just doing something wrong?

Importers are currently reworked. I would suggest to either use jME version from last week or wait for the conversion to be completed.

try changing:



Node r=(Node)BinaryImporter.getInstance().load(new ByteArrayInputStream(BO.toByteArray()));



to



Spatial r=(Spatial)BinaryImporter.getInstance().load(new ByteArrayInputStream(BO.toByteArray()));



ObjToJme returns a Node, however, so I do not see how this is happening.

Switching it to spatial worked. When is the code revamp expected to be finished?



Also, I can't figure out how to get the ObjToJme to load the specified texture image from the jar (it's in the same folder as the obj and mtl files).



Also, if I may be so bold as to recommend two fixes to the ObjToJme class:



Change line 197 from

String[] parts = s.split(" ");


to

String[] parts = s.split("\s+");


This removes the issue of having double spaces and things on a line.

Change line 199 from

if ("#".equals(parts[0]))


to

if (part[0].charAt(0) == '#')


The current method doesn't work if there isn't a space between the # and the comment (which not all programs do).

Also, line 263 should be changed to:


t.setImageLocation("file:/" + s.trim().substring(7));



rather than (6).

Or, at least, I think this is right, although I still haven't gotten any texture files to load with the objects yet.

Ok… starting at line 261, here's a couple of changes I made so that the texturing works kind of like the mtllib setup:



           Texture t = new Texture();
            t.setWrap(Texture.WM_WRAP_S_WRAP_T);
            URL texURL = new URL((URL)properties.get("texurl"), s.trim().substring(7));
            t.setImageLocation(texURL.toString());
            curGroup.ts.setTexture(t);
            curGroup.ts.setEnabled(true);
            return;



This way, the user can set the "texurl" property just like the "mtllib" property.

Update: This does set the texture path properly, and the texture is loaded. However, I'm getting "WARNING: Texturekey is null, cannot load". Where and how do you enable the texture key in the TestObjJmeWrite.java example?

Here's the code I've been using to convert .obj and .mtl files (from Sketchup in my case) to .jme files.



Also, be sure to refresh CVS; there are lots of changes lately.



Don't take this code as gospel; I suspect a problem with textures (documented in other threads).



public class ConvertObjToJME

{

final static String INPUT_SUFFIX = ".obj";

final static String OUTPUT_SUFFIX = ".jme";



/**

  • ConvertObjToJME directory
  • Converts all files ending with .obj (and any .mtl files in that directory they reference)
  • to .jme format.

    */

    public static void main(String[] args)

    {

    if (args.length != 1)

    throw new RuntimeException("usage: ConvertObjToJME directory");



    try

    {

    String dir = args[0];

    File dirFile = new File(dir);



    // Without the magic mtldir and texdir properties, ObjToJme won't find materials

    // and textures. These set reasonable defaults… same directory as .obj file. bcox

    ObjToJme main = new ObjToJme();

    main.setProperty("mtldir", dir);

    main.setProperty("texdir", dir);



    String[] fileArray = dirFile.list();

    for (int i = 0; i < fileArray.length; i++)

    {

    String s = fileArray;

    if (s.endsWith(INPUT_SUFFIX))

    {

    String o = s.substring(0, s.lastIndexOf(INPUT_SUFFIX))+OUTPUT_SUFFIX;

    File inFile = new File(dirFile, s);

    File outFile = new File(dirFile, o);

    String[] argArray = new String[] {inFile.getCanonicalPath(), outFile.getCanonicalPath()};

    main.attemptFileConvert(argArray);

    }

    }

    System.out.println("Last file done");

    }

    catch (Exception e)

    {

    e.printStackTrace();

    }

    }

    }

elias4444 and gamer99 can you put these bits of info into the IssueTracker?

How do I get to the IssueTracker? I can't find a link on the main page.  :frowning:

https://jme.dev.java.net/issues

done.  :smiley:

Can't do it. Don't have access rights.

Create a java.net account…it's free. :-p



darkfrog

Did that. Only lets you browse, not contribute.

You shouldn't have to have any special rights beyond having an account to contribute to the issue tracker.



darkfrog

gamer99 said:

Did that. Only lets you browse, not contribute.


Make sure you're actually logged in..  java.net is excellent at logging you out without you asking for it.

I'm logged in. Observer status still Pending. No options visible for commenting or adding entries.



Summary  Java gaming engine.

Categories None

License Berkeley Software Distribution (BSD) License

Owner(s) mojomonkey

Your role(s) Observer (Pending)

OK, I'm in. Issue added. Hope its the one you had in mind, mojo.

I made all converters returns Nodes when I updated them. It should return a spatial. Some one must of changed the code.

I just looked at my code, I must of forgot to change it to save a Node. It needs to be updated, saving a Spatial is NOT a good idea.