BinaryImporter load issues

I just updated my code from the JmeBinaryReader to the BinaryImporter.



None of the issues on other threads have worked for me, so let's try this:-)



I noticed another GZIP issue, but my problem was not fixed by that, so here we go.



Note: yes I borrowed the NodeRotator from airCarrier so i could test my display.



import com.gerbildrop.dradis.util.NodeRotator;
import com.jme.system.DisplaySystem;
import com.jme.scene.Node;

public class Battlestar {
    Model battlestarModel = null;
    public static enum BattlestarType {GALACTICA, PEGASUS}

    public void load(DisplaySystem display) {
        load(display, BattlestarType.GALACTICA);
    }

    public void load(DisplaySystem display, BattlestarType type) {
        if (type == BattlestarType.PEGASUS) {
            battlestarModel = ModelFactory.getInstance().createModel(display, "dradis/models/colbstr2.tga", "dradis/models/colbstr2cox.jme");
        } else {
            battlestarModel = ModelFactory.getInstance().createModel(display, "dradis/models/colbst1c.tga", "dradis/models/colbstr1cox.jme");
        }

        NodeRotator.rotate(getNode(), Model.ROLL, (float) Math.toRadians(180));
        NodeRotator.rotate(getNode(), Model.PITCH, (float) Math.toRadians(90));
    }

    public Model getModel() {
        return battlestarModel;
    }

    public void setModel(Model model) {
        battlestarModel = model;
    }

    public Node getNode() {
        return battlestarModel.getNode();
    }
}





import com.jme.math.Vector3f;
import com.jme.scene.Node;
import com.jme.scene.state.CullState;
import com.jme.scene.state.TextureState;
import com.jme.system.DisplaySystem;
import com.jme.util.TextureManager;
import com.jme.util.export.binary.BinaryImporter;
import com.jmex.model.XMLparser.JmeBinaryReader;

import java.io.IOException;
import java.net.URL;

public class ModelFactory {
    private static final ModelFactory _INSTANCE = new ModelFactory();

    public Model createModel(DisplaySystem display, String texture, String model) {
        Model m = new Model();
        Node rootNode = null;

        URL _texturePath = (ModelFactory.class).getClassLoader().getResource(texture);
        URL _modelPath = (ModelFactory.class).getClassLoader().getResource(model);

        BinaryImporter jbr = BinaryImporter.getInstance();
//        JmeBinaryReader jbr = new JmeBinaryReader();

        assert _modelPath != null;
        assert _texturePath != null;

        try {
//            long time = System.currentTimeMillis();
            rootNode = (Node) jbr.load(_modelPath.openStream());
//            rootNode = jbr.loadBinaryFormat(_modelPath.openStream());
        } catch (IOException e) {
            e.printStackTrace();
        }

        assert rootNode != null;
        TextureState ts = display.getRenderer().createTextureState();
        ts.setEnabled(true);
        ts.setTexture(TextureManager.loadTexture(_texturePath, 2, 1));

        rootNode.setRenderState(ts);
        rootNode.setLocalTranslation(new Vector3f(0.0F, 0.0F, 0F));
        rootNode.setLocalScale(0.1F);
        rootNode.updateGeometricState(0.0F, true);

        rootNode.setLocalScale(.1f);
        if (rootNode.getChild(0).getControllers().size() != 0)
            rootNode.getChild(0).getController(0).setSpeed(20);

        CullState cullState = DisplaySystem.getDisplaySystem().getRenderer().createCullState();
        cullState.setCullMode(CullState.CS_BACK);

        m.setModelPath(_modelPath);
        m.setTexturePath(_texturePath);
        m.setNode(rootNode);

        return m;
    }

    public static ModelFactory getInstance() {
        return _INSTANCE;
    }
}



StackTrace


java.io.IOException: Not in GZIP format
   at java.util.zip.GZIPInputStream.readHeader(GZIPInputStream.java:132)
   at java.util.zip.GZIPInputStream.<init>(GZIPInputStream.java:58)
   at java.util.zip.GZIPInputStream.<init>(GZIPInputStream.java:68)
   at com.jme.util.export.binary.BinaryImporter.load(Unknown Source)
   at com.gerbildrop.dradis.ships.ModelFactory.createModel(ModelFactory.java:33)
   at com.gerbildrop.dradis.ships.Battlestar.load(Battlestar.java:19)
   at com.gerbildrop.dradis.ships.Battlestar.load(Battlestar.java:12)
   at com.gerbildrop.dradis.DradisMain.simpleInitGame(DradisMain.java:46)
   at com.gerbildrop.dradis.DradisGame.initGame(DradisGame.java:448)
   at com.jme.app.BaseGame.start(Unknown Source)
   at com.gerbildrop.dradis.DradisMain.main(DradisMain.java:110)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
   at java.lang.reflect.Method.invoke(Method.java:585)
   at com.intellij.rt.execution.application.AppMain.main(AppMain.java:90)
java.lang.NullPointerException
   at com.gerbildrop.dradis.ships.ModelFactory.createModel(ModelFactory.java:44)
   at com.gerbildrop.dradis.ships.Battlestar.load(Battlestar.java:19)
   at com.gerbildrop.dradis.ships.Battlestar.load(Battlestar.java:12)
   at com.gerbildrop.dradis.DradisMain.simpleInitGame(DradisMain.java:46)
   at com.gerbildrop.dradis.DradisGame.initGame(DradisGame.java:448)
   at com.jme.app.BaseGame.start(Unknown Source)
   at com.gerbildrop.dradis.DradisMain.main(DradisMain.java:110)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
   at java.lang.reflect.Method.invoke(Method.java:585)
   at com.intellij.rt.execution.application.AppMain.main(AppMain.java:90)



Any thoughts would be appreciated.

thx

timo

Looks like your model is simply still in the old format (made with JmeBinaryWriter).



BinaryImporter can only load files made with BinaryImporter (so yes, it's BinaryImporterAndExporter really).

ok, thx, I exported the models with a model converter,  I'll look again.



I did also try to import the 3ds model with the MaxToJme converter, no dice there either.



I'll try to export the 3ds model again and put it in the jar in the classpath



thx,



timo

Maybe you're using the old MaxToJme or something? Check in the source if it uses BinaryImporter. If it doesn't, update from nightly build or CVS.

Just verified, though didn't need to, it is using BinaryImporter… I say didn't need to, b/c I am actually using the latest nightly build.



I'll try using the 3ds directly and see if maybe I was trying to convert with a different lib.

Ok, I figured out what was going on… it took me a bit, but believe it or not parts of another thread helped (no kidding?)



What also helped was reading the source code.  The biggest change were these three lines:


if (textureForModel != null) {
     //muy muy importante for the texture of a model or you'll get an error that states could not find /texture.extension
     maxConverter.setProperty("texurl", textureForModel);
}



If you're not getting your textures to display with 3ds models, this is more than likely your problem (I tested it on over 50 models I have)

with that said, I made some mods to TestMaxJmeWrite (if anyone cares).  Note that I did not update the main method to reflect two arguments, IF anyone likes the changes and wants to put them into CVS I figured that they might have their own way of putting the multiple arguments together (as opposed to my way):


/*
 * Copyright (c) 2003-2006 jMonkeyEngine All rights reserved. Redistribution and
 * use in source and binary forms, with or without modification, are permitted
 * provided that the following conditions are met: * Redistributions of source
 * code must retain the above copyright notice, this list of conditions and the
 * following disclaimer. * Redistributions in binary form must reproduce the
 * above copyright notice, this list of conditions and the following disclaimer
 * in the documentation and/or other materials provided with the distribution. *
 * Neither the name of 'jMonkeyEngine' nor the names of its contributors may be
 * used to endorse or promote products derived from this software without
 * specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT
 * HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
 * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
 * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */
package jmetest.renderer.loader;

import java.io.BufferedInputStream;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;

import com.jme.app.AbstractGame;
import com.jme.app.SimpleGame;
import com.jme.math.FastMath;
import com.jme.math.Quaternion;
import com.jme.math.Vector3f;
import com.jme.scene.Node;
import com.jme.util.export.binary.BinaryImporter;
import com.jmex.model.XMLparser.Converters.MaxToJme;
import com.jmex.model.XMLparser.Converters.FormatConverter;

/**
 * Started Date: Jun 26, 2004<br>
 * <br>
 * This class test the ability to save adn write .3ds files
 *
 * @author Jack Lindamood
 */
public class TestMaxJmeWrite extends SimpleGame {
    public static void main(String[] args) {

        TestMaxJmeWrite app = new TestMaxJmeWrite();

        if (args.length > 0) {
            app.setModelToLoad(args[0]);
        }

        app.setDialogBehaviour(AbstractGame.FIRSTRUN_OR_NOCONFIGFILE_SHOW_PROPS_DIALOG);
        app.setDialogBehaviour(SimpleGame.FIRSTRUN_OR_NOCONFIGFILE_SHOW_PROPS_DIALOG);
        app.start();
    }

    private URL modelToLoad = null;
    private URL textureForModel = null;

    private void setModelToLoad(String string) {
        try {
            modelToLoad = (new File(string)).toURL();
        } catch (MalformedURLException e) {
            //No Op
        }
    }

    protected void simpleInitGame() {
        if (modelToLoad == null) {
            modelToLoad = TestMaxJmeWrite.class.getClassLoader().getResource("jmetest/data/model/Character.3DS");
        }

        try {
            FormatConverter maxConverter = new MaxToJme();
            ByteArrayOutputStream BO = new ByteArrayOutputStream();

            if (textureForModel != null) {
                maxConverter.setProperty("texurl", textureForModel);
            }

            maxConverter.convert(new BufferedInputStream(modelToLoad.openStream()), BO);
            Node r1 = (Node)BinaryImporter.getInstance().load(new ByteArrayInputStream(BO.toByteArray()));

            r1.setLocalScale(.1f);
            if (r1.getChild(0).getControllers().size() != 0)
                r1.getChild(0).getController(0).setSpeed(20);

            Quaternion temp = new Quaternion();
            temp.fromAngleAxis(FastMath.PI / 2, new Vector3f(-1, 0, 0));
            rootNode.setLocalRotation(temp);
            r1.setLocalTranslation(new Vector3f(10,0,0));
            rootNode.attachChild(r1);
        } catch (IOException e) {
            System.out.println("Damn exceptions:" + e);
            e.printStackTrace();
        }
    }
}

You must have seen something about that on the console though right? (missing textures). As opposed to the GZIP error (whic means the wrong format)



Anyway, since I don't do much model loading I can't say much about any changes. But maybe another dev reads this?

yeah, sorry, I should have changed the topic I guess.



You were correct about the BinaryImporter… the 3ds file that I had converted was converted with an OLDER version of the file converters.



I took the Test file and ran it, and didn't have any issues with the 3ds file I was loading

So after a few other tests I was getting this error:

java.io.FileNotFoundException: COLMFTR1.TGA (The system cannot find the file specified)

I found that my textures were never being imported.  I then read a post that you had replied to about tex_url or setting the override location and checked the source code for the texture property for MaxToJme and thus on down the line, fixed my own issue.  I have converted my files with a custom converter and now they import with BinaryImporter correctly.



Again, my apologies, I should have started a new topic for this fix or something else… now it doesn't really belong in this thread.  Hours of coding makes the brain mushy.



thx,



timo