Program lacks after attaching a few models

Hi all,



I've a new problem. When I attach a few "bigger" models in my program it starts to lack. Is there a possibility to import and update the models in another thread so the Mainrenderer don't have to do that?

If it's lagging when you load models, you can try loading all your models before you start the game. Otherwise, I'm not sure how to load while the game is running (other than by manually loading bits at a time), since OpenGL only runs in one thread.

There could be one (but only one) separate thread running that loads the models from the binary files or runs them through the importer. After loading it would have to use the GameTaskQueue to add the model to the scenegraph.

@normen

Works only limited that way in JME2 due to materials being directly uploaded in the OpenGl space then. (and still out of context. This is one of the mayor improvements of JME3) So only pure Meshes without anything else will work.



So your best bet is

A precaching every needed model (load them and safe them just ina array, also you a speed loading up by using the jme binary format instead of a standarized)

B instad of reloading duplicate them if you need them several times

C or better use SharedNodes if possible(no animations) they use the same Geometry shared then (great for 1000 identicall trees for example, or bullets , rockets ect).



D take a look at JME3 but it is still very alpha, however background modelloading works already quite fine.

Empire Phoenix said:

Works only limited that way in JME2 due to materials being directly uploaded in the OpenGl space then. (and still out of context. This is one of the mayor improvements of JME3) So only pure Meshes without anything else will work.

Right, we had that topic already, didn't we? It just seemed to work quite well in scalaxy..

I'm already using sharedNodes when a model is loading more then once. The Problem is, that I've a ready loaded stage, where I can import models at any time i want and when it's a few models more, then the program starts to lack. So I hoped there is a possibillity to render the models in another thread as the rest of the stage.



How is it with the GameTaskQueueManager? When I load the models in a Callable and render it with GameTaskQueueManager.getManager().getQueue(GameTaskQueue.RENDER).execute(), could this help?

Not in jme2 in jme3 this works.

sorry for the late reply.



with "bigger" models I mean models (.3ds, .obj) wich size are more then 1 MB.



And, what can I make wrong with loading a model and attach it to a node?

Its probably just the complexity of the model. How many vertices do these bigger models have?

Bastard!  :wink:



I know the issue. The FPS go down to about 1 after attaching complex models … to the scenegraph. Note: The FPS don't go down when the model is loaded, they go down when you ATTACH it to the scenegraph and they are updated and rendered the first time. After that my FPS always normalize again.



I think this must have something to do with the initial updating of the subtree with the values higher up in the original scenegraph? I have no fix for this issue either so …

thanks dhdd, that was a good clue.



Another question, is it possible to cast .3ds models in a trimesh so I can use AreaClodMesh to minimize the problem? When I try to load a model in an AreaClodMesh I get most the failure that it can't be cast into a Trimesh.

hey there.



depends mostly on the importer and i guess all the XYZtoJME importers return a node that has at least one TriMesh as children.



So you can recurse through and add clodmeshes as needed:


  private void setThingsRec(Spatial s) {
    if(s instanceof TriMesh) {
      //wrap it into an AreaClodMesh here
    } else if (s != null && s instanceof Node && ((Node)s).getChildren() != null) {
      for (Spatial spat : ((Node)s).getChildren()) {
        setThingsRec(spat);
      } // for
    } // if
  } // setThingsRec



Though I don't know if it can actually help you with your problem with the lag.

thanks dhdd, your solution works.



But now I get another problem. By some models not the complete model will loaded or by some models I get the following error message:


Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
        at com.jme.renderer.lwjgl.LWJGLRenderer.predrawGeometry(LWJGLRenderer.java:1479)
        at com.jme.renderer.lwjgl.LWJGLRenderer.draw(LWJGLRenderer.java:999)
        at com.jme.scene.SharedMesh.draw(SharedMesh.java:641)
        at com.jme.renderer.RenderQueue.renderOpaqueBucket(RenderQueue.java:249)
        at com.jme.renderer.RenderQueue.renderBuckets(RenderQueue.java:237)
        at com.jme.renderer.Renderer.renderQueue(Renderer.java:389)
        at com.jme.renderer.pass.ShadowedRenderPass.renderScene(ShadowedRenderPass.java:437)
        at com.jme.renderer.pass.ShadowedRenderPass.doRender(ShadowedRenderPass.java:283)
        at com.jme.renderer.pass.Pass.renderPass(Pass.java:96)
        at com.jme.renderer.pass.BasicPassManager.renderPasses(BasicPassManager.java:90)
        at jmetool.LiveNode.simpleRender(LiveNode.java:588)
        at com.jme.system.canvas.SimpleCanvasImpl.doRender(SimpleCanvasImpl.java:142)
        at com.jmex.awt.lwjgl.LWJGLCanvas.paintGL(LWJGLCanvas.java:144)
        at org.lwjgl.opengl.AWTGLCanvas.paint(AWTGLCanvas.java:288)
        at org.lwjgl.opengl.AWTGLCanvas.update(AWTGLCanvas.java:317)
        at sun.awt.RepaintArea.updateComponent(RepaintArea.java:239)
        at sun.awt.RepaintArea.paint(RepaintArea.java:216)
        at sun.awt.windows.WComponentPeer.handleEvent(WComponentPeer.java:306)
        at java.awt.Component.dispatchEventImpl(Component.java:4577)
        at java.awt.Component.dispatchEvent(Component.java:4331)
        at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
        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)




any idead why this is?

what version of jme are you using?



I have fixed this bug a few months back from:


                if (texC != null) {
                    // make sure only the necessary texture coords are sent
                    // through on old cards.
                    oldLimit = texC.coords.limit();
                    texC.coords.limit(g.getVertexCount() * texC.perVert);
                }


to


                if (texC != null && texC.coords != null) {
                    // make sure only the necessary texture coords are sent
                    // through on old cards.
                    oldLimit = texC.coords.limit();
                    texC.coords.limit(g.getVertexCount() * texC.perVert);
                }



so it should be fixed in SVN

EDIT: no its not in SVN. I only fixed that locally, but I guess it will be in in a few days: http://www.jmonkeyengine.com/forum/index.php?topic=13732.0

I'm using the jme2.0.1 stable, so I will wait for the new version

its committed  :wink:

OK, I installed the Jme3 but I can't load .3ds models right?