Hi everyone, I wanted to use these cool particle effects features, but I noticed that the sample code looks completely outdated and broken.
@Override
public void simpleInitApp() {
// Since we actually use a full lit material for these particles we need
// to add a light to the scene in order to see anything.
DirectionalLight dl = new DirectionalLight();
dl.setDirection(new Vector3f(-0.1f,-0.7f,-1).normalizeLocal());
dl.setColor(new ColorRGBA(0.6f, 0.60f, 0.60f, 1.0f));
rootNode.addLight(dl);
// A standard lit material is used, this rock texture was taking from the
// jme3 test data but you can easily substitute your own.
Material rock = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md");
rock.setTexture("DiffuseMap", assetManager.loadTexture("Textures/Rock.PNG"));
rock.setFloat("Shininess", 100f);
// A PointSource is actually a fully featured Spatial object, in this case
// we simply adjust its translation, but it can actually be attached to the
// scene graph and the source will automatically move as the Node to which
// it is attached is transformed.
PointSource source = new PointSource(new Vector3f(-5,-5,-5), new Vector3f(5,5,5));
source.setLocalTranslation(0, 10, -20);
// A TemplateMesh uses any number of standard meshes to be the template for
// each 3d particle. This model was generated simply by taking a cube in
// Blender and running a fracture script on it to generate 20 fragments.
Node n = (Node) assetManager.loadModel("Models/FracturedCube.j3o");
Mesh[] templates = new Mesh[n.getChildren().size()];
int i = 0;
for (Spatial s: n.getChildren()) {
Geometry g = (Geometry)((Node)s).getChild(0);
templates[i++] = g.getMesh();
}
// Construct the new particle controller
ParticleController rockCtrl = new ParticleController(
"TemplateMesh",
// The TemplateMesh uses the rock material we created previously, the two boolean
// flags say that we are not interested in vertex colours but we do want the vertex
// normals. The array of meshes extracted from the model is then passed in to use
// as models for each particle.
new TemplateMesh(rock, false, true, templates),
// A maximum of 64 particles at once, each lasting for 5 to 5.5 seconds.
64,
5,
5.5f,
// Particles are emitted from the source that we created and positioned earlier
source,
// Emit 8 particles per second
new RegularEmission(8),
// The "sprites" in this case are the available templates. The TemplateMesh has
// one spriteColumn for each template it has been provided, so the standard
// RandomSpriteInfluencer just causes one to be picked at random each time a
// particle is emitted.
new RandomSpriteInfluencer(),
// Rocks fall.
new GravityInfluencer(new Vector3f(0, -4, 0)),
// Rocks spin.
new RotationInfluencer(new Vector3f(-2, -2, -2), new Vector3f(2, 2, 2), false));
rootNode.attachChild(rockCtrl.getGeometry());
}
Could you write me the updated code for these features? Thanks in advance.
Edit: I’m using jme3.3.2