Hi everyone,
I always have to wait a little before my Game starts… Is there a way to make the following faster?
It loads an object file (bis quad with a texture on it and a big palm leaves over it) for every each node! Without this the Game loads pretty fast G
Any ideas on how to speed up my game here?
Thanks
JackNeil said:
Yeah.. but I meant: How much can loading times be decreased with multi-threading? Anyone created a benchmark?
It is not really faster, look at the implementation, it only put a ModelLoaderCallable into the update queue.
public static Node initBillboard(){
URL folder= Start.class.getClassLoader().getResource("data/models");
URL model = Start.class.getClassLoader().getResource("data/models/plant.obj");
FormatConverter converter=new ObjToJme();
converter.setProperty("mtllib", folder);
converter.setProperty("texdir", folder);
ByteArrayOutputStream BO=new ByteArrayOutputStream();
try {
converter.convert(model.openStream(), BO);
treeBoard=(Spatial) BinaryImporter.getInstance().load(new ByteArrayInputStream(BO.toByteArray()));
treeBoard.setLocalTranslation(new Vector3f(335,2,357));
treeBoard.setLocalRotation(new Matrix3f(0,0,-1.0f,0,1.0f,0,1.0f,0,0));
//treeBoard 2
treeBoard2=(Spatial) BinaryImporter.getInstance().load(new ByteArrayInputStream(BO.toByteArray()));
treeBoard2.setLocalTranslation(new Vector3f(269,2,357));
treeBoard2.setLocalRotation(new Matrix3f(0,0,-1.0f,0,1.0f,0,1.0f,0,0));
//treeBoard3
treeBoard3=(Spatial) BinaryImporter.getInstance().load(new ByteArrayInputStream(BO.toByteArray()));
treeBoard3.setLocalTranslation(new Vector3f(203,2,357));
treeBoard3.setLocalRotation(new Matrix3f(0,0,-1.0f,0,1.0f,0,1.0f,0,0));
//treeBoard4
treeBoard4=(Spatial) BinaryImporter.getInstance().load(new ByteArrayInputStream(BO.toByteArray()));
treeBoard4.setLocalTranslation(new Vector3f(137,2,357));
treeBoard4.setLocalRotation(new Matrix3f(0,0,-1.0f,0,1.0f,0,1.0f,0,0));
//treeBoard5
treeBoard5=(Spatial) BinaryImporter.getInstance().load(new ByteArrayInputStream(BO.toByteArray()));
treeBoard5.setLocalTranslation(new Vector3f(71,2,357));
treeBoard5.setLocalRotation(new Matrix3f(0,0,-1.0f,0,1.0f,0,1.0f,0,0));
//treeBoard6
treeBoard6=(Spatial) BinaryImporter.getInstance().load(new ByteArrayInputStream(BO.toByteArray()));
treeBoard6.setLocalTranslation(new Vector3f(5,2,357));
treeBoard6.setLocalRotation(new Matrix3f(0,0,-1.0f,0,1.0f,0,1.0f,0,0));
//treeBoard7
treeBoard7=(Spatial) BinaryImporter.getInstance().load(new ByteArrayInputStream(BO.toByteArray()));
treeBoard7.setLocalTranslation(new Vector3f(-61,2,357));
treeBoard7.setLocalRotation(new Matrix3f(0,0,-1.0f,0,1.0f,0,1.0f,0,0));
//treeBoard8
treeBoard8=(Spatial) BinaryImporter.getInstance().load(new ByteArrayInputStream(BO.toByteArray()));
treeBoard8.setLocalTranslation(new Vector3f(-127,2,357));
treeBoard8.setLocalRotation(new Matrix3f(0,0,-1.0f,0,1.0f,0,1.0f,0,0));
//treeBoard9
treeBoard9=(Spatial) BinaryImporter.getInstance().load(new ByteArrayInputStream(BO.toByteArray()));
treeBoard9.setLocalTranslation(new Vector3f(-193,2,357));
treeBoard9.setLocalRotation(new Matrix3f(0,0,-1.0f,0,1.0f,0,1.0f,0,0));
//treeBoard10
treeBoard10=(Spatial) BinaryImporter.getInstance().load(new ByteArrayInputStream(BO.toByteArray()));
treeBoard10.setLocalTranslation(new Vector3f(-259,2,357));
treeBoard10.setLocalRotation(new Matrix3f(0,0,-1.0f,0,1.0f,0,1.0f,0,0));
//treeBoard11
treeBoard11=(Spatial) BinaryImporter.getInstance().load(new ByteArrayInputStream(BO.toByteArray()));
treeBoard11.setLocalTranslation(new Vector3f(-325,2,357));
treeBoard11.setLocalRotation(new Matrix3f(0,0,-1.0f,0,1.0f,0,1.0f,0,0));
//treeBoard12
treeBoard12=(Spatial) BinaryImporter.getInstance().load(new ByteArrayInputStream(BO.toByteArray()));
treeBoard12.setLocalTranslation(new Vector3f(-391,2,357));
treeBoard12.setLocalRotation(new Matrix3f(0,0,-1.0f,0,1.0f,0,1.0f,0,0));
// back side!!!!!!
//treeBoard13
treeBoard13=(Spatial) BinaryImporter.getInstance().load(new ByteArrayInputStream(BO.toByteArray()));
treeBoard13.setLocalTranslation(new Vector3f(-380,2,251));
treeBoard13.setLocalRotation(new Matrix3f(0,0,-1.0f,0,1.0f,0,1.0f,0,0));
//treeBoard14
treeBoard14=(Spatial) BinaryImporter.getInstance().load(new ByteArrayInputStream(BO.toByteArray()));
treeBoard14.setLocalTranslation(new Vector3f(-314,2,251));
treeBoard14.setLocalRotation(new Matrix3f(0,0,-1.0f,0,1.0f,0,1.0f,0,0));
//treeBoard15
treeBoard15=(Spatial) BinaryImporter.getInstance().load(new ByteArrayInputStream(BO.toByteArray()));
treeBoard15.setLocalTranslation(new Vector3f(-248,2,251));
treeBoard15.setLocalRotation(new Matrix3f(0,0,-1.0f,0,1.0f,0,1.0f,0,0));
//treeBoard16
treeBoard16=(Spatial) BinaryImporter.getInstance().load(new ByteArrayInputStream(BO.toByteArray()));
treeBoard16.setLocalTranslation(new Vector3f(-182,2,251));
treeBoard16.setLocalRotation(new Matrix3f(0,0,-1.0f,0,1.0f,0,1.0f,0,0));
// parallel back side!!!!!!
//treeBoard17
treeBoard17=(Spatial) BinaryImporter.getInstance().load(new ByteArrayInputStream(BO.toByteArray()));
treeBoard17.setLocalTranslation(new Vector3f(-380,2,221));
treeBoard17.setLocalRotation(new Matrix3f(0,0,-1.0f,0,1.0f,0,1.0f,0,0));
//treeBoard18
treeBoard18=(Spatial) BinaryImporter.getInstance().load(new ByteArrayInputStream(BO.toByteArray()));
treeBoard18.setLocalTranslation(new Vector3f(-314,2,221));
treeBoard18.setLocalRotation(new Matrix3f(0,0,-1.0f,0,1.0f,0,1.0f,0,0));
//treeBoard19
treeBoard19=(Spatial) BinaryImporter.getInstance().load(new ByteArrayInputStream(BO.toByteArray()));
treeBoard19.setLocalTranslation(new Vector3f(-248,2,221));
treeBoard19.setLocalRotation(new Matrix3f(0,0,-1.0f,0,1.0f,0,1.0f,0,0));
//treeBoard20
rotQuat1.fromAngleAxis(70, axis);
treeBoard20=(Spatial) BinaryImporter.getInstance().load(new ByteArrayInputStream(BO.toByteArray()));
treeBoard20.setLocalTranslation(new Vector3f(-150,2,250));
treeBoard20.setLocalRotation(rotQuat1);
//front_side
//treeBoard21
treeBoard21=(Spatial) BinaryImporter.getInstance().load(new ByteArrayInputStream(BO.toByteArray()));
treeBoard21.setLocalTranslation(new Vector3f(70,2,357));//
//treeBoard22
treeBoard22=(Spatial) BinaryImporter.getInstance().load(new ByteArrayInputStream(BO.toByteArray()));
treeBoard22.setLocalTranslation(new Vector3f(70,2,291));
//treeBoard23
treeBoard23=(Spatial) BinaryImporter.getInstance().load(new ByteArrayInputStream(BO.toByteArray()));
treeBoard23.setLocalTranslation(new Vector3f(70,2,225));
//treeBoard24
treeBoard24=(Spatial) BinaryImporter.getInstance().load(new ByteArrayInputStream(BO.toByteArray()));
treeBoard24.setLocalTranslation(new Vector3f(70,2,159));
//treeBoard25
treeBoard25=(Spatial) BinaryImporter.getInstance().load(new ByteArrayInputStream(BO.toByteArray()));
treeBoard25.setLocalTranslation(new Vector3f(70,2,93));
// treeBoard25.setLocalRotation(new Matrix3f(0,0,-1.0f,0,1.0f,0,1.0f,0,0));
//treeBoard26
rotQuat1.fromAngleAxis(100, axis);
treeBoard26=(Spatial) BinaryImporter.getInstance().load(new ByteArrayInputStream(BO.toByteArray()));
treeBoard26.setLocalTranslation(new Vector3f(70,2,27));
treeBoard26.setLocalRotation(rotQuat1);
//treeBoard27
rotQuat1.fromAngleAxis(100, axis);
treeBoard27=(Spatial) BinaryImporter.getInstance().load(new ByteArrayInputStream(BO.toByteArray()));
treeBoard27.setLocalTranslation(new Vector3f(97.5f,2,-20));
treeBoard27.setLocalRotation(rotQuat1);
//treeBoard28
rotQuat1.fromAngleAxis(100, axis);
treeBoard28=(Spatial) BinaryImporter.getInstance().load(new ByteArrayInputStream(BO.toByteArray()));
treeBoard28.setLocalTranslation(new Vector3f(130.8f,2,-77));
treeBoard28.setLocalRotation(rotQuat1);
//middle row /insel
//treeBoard29
treeBoard29=(Spatial) BinaryImporter.getInstance().load(new ByteArrayInputStream(BO.toByteArray()));
treeBoard29.setLocalTranslation(new Vector3f(155.8f,2,-134));
//treeBoard30
treeBoard30=(Spatial) BinaryImporter.getInstance().load(new ByteArrayInputStream(BO.toByteArray()));
treeBoard30.setLocalTranslation(new Vector3f(110,2,-184));
treeBoard30.setLocalRotation(new Matrix3f(0,0,-1.0f,0,1.0f,0,1.0f,0,0));
//attach the Nodes to the rootNode
billboard = new Node("billboard");
billboard.setRenderQueueMode(Renderer.QUEUE_INHERIT);
billboard.setLightCombineMode(LightState.OFF);
billboard.attachChild(treeBoard);
billboard.attachChild(treeBoard2);
billboard.attachChild(treeBoard3);
billboard.attachChild(treeBoard4);
billboard.attachChild(treeBoard5);
billboard.attachChild(treeBoard6);
billboard.attachChild(treeBoard7);
billboard.attachChild(treeBoard8);
billboard.attachChild(treeBoard9);
billboard.attachChild(treeBoard10);
billboard.attachChild(treeBoard11);
billboard.attachChild(treeBoard12);
billboard.attachChild(treeBoard13);
billboard.attachChild(treeBoard14);
billboard.attachChild(treeBoard15);
billboard.attachChild(treeBoard16);
billboard.attachChild(treeBoard17);
billboard.attachChild(treeBoard18);
billboard.attachChild(treeBoard19);
billboard.attachChild(treeBoard20);
billboard.attachChild(treeBoard21);
billboard.attachChild(treeBoard22);
billboard.attachChild(treeBoard23);
billboard.attachChild(treeBoard24);
billboard.attachChild(treeBoard25);
billboard.attachChild(treeBoard26);
billboard.attachChild(treeBoard27);
billboard.attachChild(treeBoard28);
billboard.attachChild(treeBoard29);
billboard.attachChild(treeBoard30);
Only convert the obj to jme once and save it a .jme binary.
Or don't load the obj at all and only use the converted .jme file.
You probably can also only create one template plant, and then use SharedMesh or Sharednode, to multiply them.
You would save some memory that way.
Hi!
Core-Dump said:
Only convert the obj to jme once and save it a .jme binary.
Or don't load the obj at all and only use the converted .jme file.
Don't load the models in Wavefront OBJ format, just convert them into JME binary format once and only use them, this is the fastest option. If you convert your files each time you launch your game, it will use a lot of memory and it will be time consuming.
Core-Dump said:
You probably can also only create one template plant, and then use SharedMesh or Sharednode, to multiply them.
You would save some memory that way.
I agree with him but it will work only if you don't need to animate your plants or if it is not important that all your plants share the animation.
Thanks for the answers!
I converted the .obj file into a .jme file with the ModelLoader! So we have a plant.jme now!
Then I tried to load this file:
treeBoard= ModelLoader.loadModel("data/models/plant.jme");
treeBoard.setLocalTranslation(new Vector3f(335,2,357));
treeBoard.setLocalRotation(new Matrix3f(0,0,-1.0f,0,1.0f,0,1.0f,0,0));
The game freezes at this point! So I am sure it is the wrong way of loading a .jme file into the game!
How do I load it correctly? And how do I use this for all the other? Do I load the file for each Node? Or can I just say something like:
treeBoard = ...loading file correctly
treeBoard2 = treeBoard;
Thanks again...
Hi!
I use this to load the file:
Spatial spatial=null;
try{spatial=(Spatial)BinaryImporter.getInstance().load(MyOwnClass.class.getResource(path));}
catch(IOException ioe)
{ioe.printStackTrace();}
I don't use ModelLoader. Use the debug mode to see what is wrong. Maybe do this instead:
treeBoard= ModelLoader.loadModel("/data/models/plant.jme");
Hi gouessej,
your code works really nicely ;) Thank you!
RapidM said:
Hi gouessej,
your code works really nicely ;) Thank you!
You're welcome.
ModelLoader.loadModel() only works in a multi threaded environment like StandardGame.
Core-Dump said:
ModelLoader.loadModel() only works in a multi threaded environment like StandardGame.
Ok but it is not written in the documentation.
Is it worth using multi-threading while loading game-ressources? Or does it make no real difference because the hard drive and disc accesses consume most of the time?
And what can we do to reduce the delay after the first frame?
JackNeil said:
Is it worth using multi-threading while loading game-ressources? Or does it make no real difference because the hard drive and disc accesses consume most of the time?
And what can we do to reduce the delay after the first frame?
Multi-threading may allow you to display something (a progress bar for example) while loading the resources, it avoids to let the users believe your game has just crashed because you have frozen the screen.
Yeah… but I meant: How much can loading times be decreased with multi-threading? Anyone created a benchmark?