Site icon Mike's Software Blog

libgdx 3D particle effects in HTML

2017-03-flame

It is not immediately obvious in libgdx why the 3D particle effects don’t work in a HTML target. I’m sharing this snippet for future readers.

In short, the “reflection cache” that is created from the Java code does not include everything required, since many of the classes are only referenced at runtime, when the particle definition is loaded.

These class names are visible in the saved files from the 3D effects editor:

$ cat engine.p | fold -w 80
{unique:{billboardBatch:{class:com.badlogic.gdx.graphics.g3d.particles.ResourceD
ata$SaveData,data:{cfg:{class:com.badlogic.gdx.graphics.g3d.particles.batches.Bi
llboardParticleBatch$Config,mode:Screen}},indices:[0]}},data:[],assets:[{filenam
e:"pre_particle.png",type:com.badlogic.gdx.graphics.Texture}],resource:{class:co
....

At runtime, this message is displayed on the web page:

GwtApplication: exception: com.badlogic.gdx.utils.GdxRuntimeException: Could not submit AsyncTask: Error reading file: (filename)
com.badlogic.gdx.utils.GdxRuntimeException: Could not submit AsyncTask: Error reading file: (filename)
Could not submit AsyncTask: Error reading file: (filename)
Error reading file: (filename)
Couldn't find Type for class 'com.badlogic.gdx.graphics.g3d.particles.batches.BillboardParticleBatch$Config'

The reflection is documented on the libgdx Wiki here, and notes that-

With this in mind, I added the following two lines to the root element in a file called GdxDefinition.gwt.xml

<extend-configuration-property name="gdx.reflect.include" value="com.badlogic.gdx.graphics.g3d.particles.batches.BillboardParticleBatch" />
<extend-configuration-property name="gdx.reflect.include" value="com.badlogic.gdx.graphics.g3d.particles.ParticleShader" />

This did the trick, and the 3D particle feature does indeed work in the libgdx HTML target.

Exit mobile version