Billboard problem

hi, i want to create one billboard,

When i create it, it has the wrong position ( it depends on billboard size and camera position).

Wrong position

[java]

public Geometry createSun1(String particleTexture, float radius)

{

Geometry sun = new Geometry("", new Quad(radius, radius));

BillboardControl bc = new BillboardControl();

sun.addControl(bc);

Material mat = new Material(scene.getAssetManager(), “Common/MatDefs/Misc/Particle.j3md”);

mat.setTexture(“Texture”, scene.getAssetManager().loadTexture(particleTexture));

sun.setMaterial(mat);

sun.setQueueBucket(Bucket.Transparent);

return sun;

}

[/java]

I can create it correctly with particle emitter, but i think it will be slower.

Correct position

[java]

public Geometry createSun(String particleTexture, float radius)

{

ParticleEmitter emit = new ParticleEmitter(“Emitter”, Type.Point, 1);

emit.setShape(new EmitterBoxShape(new Vector3f(0f, 0, 0), new Vector3f(0f, 0f, 0f)));

emit.setStartSize(10.05f);

emit.setEndSize(10.05f);

emit.setStartColor(ColorRGBA.White);

emit.setEndColor(ColorRGBA.White);

Material mat = new Material(scene.getAssetManager(), “Common/MatDefs/Misc/Particle.j3md”);

mat.setBoolean(“PointSprite”, true);

mat.setTexture(“Texture”, scene.getAssetManager().loadTexture(particleTexture));

emit.setMaterial(mat);

return emit;

}

[/java]

by the way jme3test.model.shape.TestBillboard has the same bug,

which means it is a bug with jme.

Just at a quick glance… some things that might be messing you up:


  1. A quad is from 0 to width and 0 to height. Your use of the word “radius” makes me think you might be misunderstanding this point. So it will not be centered over 0,0… for example, it is not from -radius to radius. This means if you want a quad to “billboard” around its center then you have to offset it. In this case, I guess it means that you would translate the geometry by -width * 0.5, stick it under a node and put the billboard on that node.


  2. Using Particle.j3md for regular geometry may give weird results on its own. You probably want Unshaded when you are using a Quad. Was there a reason you chose the particle material for your quad?
  1. done and it now works correcly, thx

    [java]

    public Spatial createSun1(String particleTexture, float radius, int imgX, int imgY)

    {

    Node sunGeom = new Node();

    Geometry sun = new Geometry("", new Quad(radius, radius));

    Material mat = Utilities.getUnshadedMaterial(particleTexture, null, scene.getAssetManager());

    mat.getAdditionalRenderState().setBlendMode(BlendMode.Alpha);

    mat.setTransparent(true);

    sun.setMaterial(mat);

    sun.setQueueBucket(Bucket.Transparent);

    sunGeom.attachChild(sun);

    sun.move(-radius/2f, -radius/2f, -radius/2f);

    BillboardControl bc = new BillboardControl();

    sunGeom.addControl(bc);

    return sunGeom;

    }

    [/java]


  2. Generating the sun with a particle emitter no longer works.



    setLocalTranslation(); refuses to move the particle, it totally ignores the call, and only updates the particle position once per 5 seconds. (so the sun teleports every 5 sec)



    It works normally if i use a 3d sphere or the quad billboard “method 1”. ( the sun moves smoothly)

Probably because the particles are in world space. Try emitter.setInWorldSpace(false)