How import compressed vrml model in JMonkey

hi,



i know import 3ds model… but  compressed vrml format is smaller then others…



i wanna know how to import compressed vrml format to JMonkey, or if exists a better format…

For production games you should always save your models as jme binaries to avoid overhead from importing models.



Cheers,

Normen

thanks!



but, how i save my models as jme binaries???



in 3d Studio Max exists a way to save in jme binaries???



jme binaries is much faster to load than other formats?


No export functionality in 3ds Max, they aren't cool enough to have that functionality built in :wink:



You can simply import a .3ds model and then export it as a jME binary.  It is much faster to load since it doesn't have to re-parse all of the information on each load as its stored in a format native to jME

I thought jme binaries were a type of file as .3ds …



I made a method that loads a model .obj in the scene:




private Spatial[] criaModelo (String urlModelo[],Texture textura[])
    {

        // textures of models

           for (int i=0; i<textura.length;i++)
           {
               
                   File textures = new File( textura[i].getImageLocation() );
                   SimpleResourceLocator location=null;
                try {
                    try {
                        location = new SimpleResourceLocator(textures.toURI().toURL());
                    } catch (MalformedURLException ex) {
                        Logger.getLogger(Modelo.class.getName()).log(Level.SEVERE, null, ex);
                    }
                } catch (URISyntaxException ex) {
                    Logger.getLogger(Modelo.class.getName()).log(Level.SEVERE, null, ex);
                }
                   ResourceLocatorTool.addResourceLocator(ResourceLocatorTool.TYPE_TEXTURE, location );
          }
           
          

           //array sapatial of models

           Spatial MODELOS[]= new Spatial[urlModelo.length];

           for (int i=0; i<=urlModelo.length;i++)
           {
                Spatial Modelo=null;
                ByteArrayOutputStream outStream = new ByteArrayOutputStream();
                FileInputStream rawIn = null;
            try {
                rawIn = new FileInputStream(urlModelo[i]);
            } catch (FileNotFoundException ex) {
                Logger.getLogger(Modelo.class.getName()).log(Level.SEVERE, null, ex);
            }
            try {
                CONVERTER_OBJ.convert(rawIn, outStream);
            } catch (IOException ex) {
                Logger.getLogger(Modelo.class.getName()).log(Level.SEVERE, null, ex);
            }
            try {
                rawIn.close();
            } catch (IOException ex) {
                Logger.getLogger(Modelo.class.getName()).log(Level.SEVERE, null, ex);
            }
                ByteArrayInputStream convertedIn =   new ByteArrayInputStream(outStream.toByteArray());
            try {
                Modelo = (Spatial) BinaryImporter.getInstance().load(convertedIn);
            } catch (IOException ex) {
                Logger.getLogger(Modelo.class.getName()).log(Level.SEVERE, null, ex);
            }
                Modelo.setModelBound(new BoundingSphere());
                Modelo.updateWorldBound();
                Modelo.updateModelBound();
                Modelo.updateRenderState();
                Modelo.updateGeometricState( 0, true );
                MODELOS[i] = Modelo;
           }

            return MODELOS;
    }



This method is good?or exists a better way to do this?

obj format  is better than 3ds?

I want to do something that is quick to load at the scene and that takes up little disk space....
sarkozy said:

I thought jme binaries were a type of file as .3ds ...


They are a type of file.  You create them by loading the original .3ds or .obj file and then using BinaryExporter

sarkozy said:

I want to do something that is quick to load at the scene and that takes up little disk space....


The quickest way to load is always from the jME Binary format.  Once you import the 3ds or OBJ models once and export them as jME Binary's then you can load the binary files rather than the 3ds/obj/etc

i made this methods:



void export (Spatial s)
        {
            BinaryExporter exp = new BinaryExporter();
           try
           {
               if (exp.save(s, new File("D:/teste.dat")))
                 JOptionPane.showMessageDialog(null,"yes!","file binary", JOptionPane.INFORMATION_MESSAGE);
           }
           catch (IOException ex) {
            Logger.getLogger(Modelo.class.getName()).log(Level.SEVERE, null, ex);
           }

        }


 private Spatial open ()
        {
            BinaryImporter im = new BinaryImporter();
            try {
                Spatial s = (Spatial) im.load(new File("D:/teste.dat"));
            } catch (IOException ex) {
                Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
            }

            return s;
        }



it's that way even if it does?

Another thing, exists any file format that is very compact? Because I might leave files that are smaller and renders in jme binary after  first execution of the game ... So the game would be smaller and easier to download!

Yes, that would be the correct way to do an operation like that.  Was there a problem you were experiencing?



As far as shipping a product, the binary file is one of the smallest you will find…  So it's smaller and faster to load, it's really quite nice :wink:

I tested and worked perfectly!



Thank you for your help!





Hooray for JMonkey! hehehe