Geometry Instancing

A couple of months ago I created a small interface for creating larger Meshes (batches) from instances of other meshes (“Geometry Instancing”), which was added to jME. When this is used in the correct way the application can get a significant speed boost. Since then I have evolved the interface into something that is easier and more straight forward to use. To demo this I have created two test applications that I would like to get some feedback on, as well as the source.



Test #1 (aka “Test”): Shows the FPS difference when rendering a grid of cubes, with and without the geometry instancing.

        http://snylt.nonsen.se/jme/GeometryInstancing/source/web/test.jnlp

Test #2 (aka “Demo”): Shows how to extend the classes to create something more advanced, in this case I added tangents and a shader to the final mesh.

        http://snylt.nonsen.se/jme/GeometryInstancing/source/web/demo.jnlp



The source for everything can be found here:

        http://snylt.nonsen.se/jme/GeometryInstancing/source/src.rar



Related posts:

        http://www.jmonkeyengine.com/jmeforum/index.php?topic=4623.0

        http://www.jmonkeyengine.com/jmeforum/index.php?topic=5764.0

        http://www.jmonkeyengine.com/jmeforum/index.php?topic=5043.0

Cool! I've updated jcrpg to use the new code! Works good.





One small thing:



        if ((instanceBatch.getType() & TriangleBatch.TRIANGLEBATCH)>0) {
           return ((TriangleBatch)instanceBatch).getMaxIndex();           
        }



I modified GeometryBatchSpatialInstance.java like above to avoid use of "instanceof".

In jre 1.6 instanceof is likely to be even be faster than that…

Irrisor beat me to it.  :stuck_out_tongue:

irrisor said:

In jre 1.6 instanceof is likely to be even be faster than that...


Hmm. Sorry for hijacking the thread, but is 1.6 faster with JME than 1.5?

afaik any application runs faster in jre1.6 than in jre1.5, so do jME apps

BTW Snylt, I tried out your webstart demo.  It looks very nice. :slight_smile:

The webstart demo does not run for me :frowning:

System: Linux (32 bit), Geforce 7600 with latest drivers.

The webstart is windows only, I will fix it asap…

getting a crash on the mac when trying to run DemoGeometryInstancing from the src link provided



Oct 4, 2007 1:42:16 PM class externaldevcode.test.DemoGeometryInstancing start()
SEVERE: Exception in game loop
java.lang.IllegalArgumentException
   at java.nio.Buffer.position(Buffer.java:218)
   at externaldevcode.geometryinstancing.GeometryBatchSpatialInstance.skipBuffer(GeometryBatchSpatialInstance.java:115)
   at externaldevcode.geometryinstancing.GeometryBatchTangentSpatialInstance.commitTangents(GeometryBatchTangentSpatialInstance.java:40)
   at externaldevcode.geometryinstancing.GeometryBatchTangentSpatialInstance.commitNormals(GeometryBatchTangentSpatialInstance.java:47)
   at externaldevcode.geometryinstancing.GeometryBatchSpatialInstance.commit(GeometryBatchSpatialInstance.java:100)
   at externaldevcode.geometryinstancing.GeometryBatchMesh.commit(GeometryBatchMesh.java:121)
   at externaldevcode.geometryinstancing.GeometryBatchMesh.draw(GeometryBatchMesh.java:135)
   at com.jme.scene.Spatial.onDraw(Spatial.java:252)
   at externaldevcode.geometryinstancing.GeometryBatchMesh.onDraw(GeometryBatchMesh.java:131)
   at com.jme.scene.Node.draw(Node.java:504)
   at com.jme.scene.Spatial.onDraw(Spatial.java:252)
   at com.jme.renderer.lwjgl.LWJGLRenderer.draw(LWJGLRenderer.java:1185)
   at com.jme.renderer.pass.RenderPass.doRender(RenderPass.java:52)
   at com.jme.renderer.pass.Pass.renderPass(Pass.java:90)
   at com.jme.renderer.pass.BasicPassManager.renderPasses(BasicPassManager.java:89)
   at com.jme.app.SimplePassGame.render(SimplePassGame.java:81)
   at com.jme.app.BaseGame.start(BaseGame.java:82)
   at externaldevcode.test.DemoGeometryInstancing.main(DemoGeometryInstancing.java:52)
Oct 4, 2007 1:42:16 PM com.jme.app.BaseSimpleGame cleanup



the TestGeometryInstancing runs fine and improved framerate from 44fps to 90fps....which is a serious boost....
test on an intel i-mac....