Problem with initializing filters

I have a class that extends rigid body control. I use it so that I can modify every fired objects trajectory and to stop it when it hits something. I was testing bloom effects on my fired objects and it worked ok, I just initialized filters once in the main class and added material and rigid body control to the fired object. Now I was trying to add bloom only when a object hits a target, and that required me to initialize filters in my class that extends rigid body control, and I did so. Problem is when I fire multiple arrows my fps drops and it starts lagging. I know its because I initialize filters more than once, so I need help to understand how to do this. I know its because of initializing filters because I tried initializing filters multiple times in my main class and it caused lagg same as this.

Can you post how you are doing it presently?

[java]
import com.jme3.asset.AssetManager;
import com.jme3.bullet.BulletAppState;
import com.jme3.bullet.collision.PhysicsCollisionEvent;
import com.jme3.bullet.collision.PhysicsCollisionListener;
import com.jme3.bullet.collision.shapes.CollisionShape;
import com.jme3.bullet.control.RigidBodyControl;
import com.jme3.material.Material;
import com.jme3.math.ColorRGBA;
import com.jme3.math.Quaternion;
import com.jme3.math.Vector3f;
import com.jme3.post.FilterPostProcessor;
import com.jme3.post.filters.BloomFilter;
import com.jme3.renderer.ViewPort;
import com.jme3.scene.Node;

/**
*

  • @author Racunalo
    */
    public class RigidArrow extends RigidBodyControl implements PhysicsCollisionListener {
    Vector3f bullet_latest_point,counter;
    boolean shoot=false;
    AssetManager asset;
    FilterPostProcessor fpp;
    BloomFilter bloom;
    ViewPort view;
    Material matBullet;

    public RigidArrow(CollisionShape shape, float mass, BulletAppState bull, AssetManager ass, ViewPort vie, Vector3f latest) {
    super(shape, mass);
    setBulletAppState(bull);
    setBullet_latest_point(latest);
    setAssetManager(ass);
    setViewPort(vie);
    setupFilter();
    initMaterial();
    }

    @Override
    public void update(float tpf) {
    super.update(tpf);
    if(shoot==false){
    spatial.setLocalRotation(arrow_rot(spatial.getLocalTranslation(), bullet_latest_point));
    }
    if(!counter.equals(spatial.getLocalTranslation())){
    bullet_latest_point=counter;
    }
    counter=spatial.getLocalTranslation().clone();
    }

    public Quaternion arrow_rot(Vector3f curr_poss, Vector3f nex_poss){
    Node r=new Node(“aa”);
    r.setLocalTranslation(curr_poss);
    r.lookAt(nex_poss, Vector3f.UNIT_Y);
    r.rotate(3.14f, 0, 0);
    return r.getLocalRotation();
    }

    public void setBullet_latest_point(Vector3f bullet_latest_point) {
    this.bullet_latest_point = bullet_latest_point;
    counter=bullet_latest_point;
    }

    public void setBulletAppState(BulletAppState bull){
    bull.getPhysicsSpace().addCollisionListener(this);
    }
    public void setAssetManager(AssetManager ass){
    asset=ass;
    }
    public void setViewPort(ViewPort vie){
    view=vie;
    }
    public void collision(PhysicsCollisionEvent event) {
    if(!“player”.equals(event.getNodeA().getName())&&!“player”.equals(event.getNodeB().getName())){
    if (event.getObjectA() == this || event.getObjectB() == this){
    shoot=true;
    spatial.setMaterial(matBullet);
    setKinematic(true);
    }
    }
    }
    public void initMaterial(){
    matBullet = new Material(asset, “Common/MatDefs/Misc/Unshaded.j3md”);
    matBullet.setColor(“Color”, ColorRGBA.Green);
    matBullet.setColor(“GlowColor”, ColorRGBA.Green);
    }
    private void setupFilter() {
    fpp = new FilterPostProcessor(asset);
    bloom = new BloomFilter(BloomFilter.GlowMode.Objects);
    fpp.addFilter(bloom);
    view.addProcessor(fpp);
    }

}[/java]
Also have a problem when I shoot an arrow and it collides sometimes it rotates backwards, so the pointy end is sticking out. I think its because when the arrow hits a object it manages to bounce just a little bit and game rememberes that location and then rotates the tail towards it(you can see in my code that my arrows rotate so that the latest location is remembered and then the tail is rotated to that spot), so I need a way to stop the arrow in the exactly the same time it hits an object, or a little bit earlyer.

Create 1 fpp and bloom filter in simpleInitApp.

1 Like

Tnx, now it works. So simple. I dont even get how it works.