I would like to change the texture of a shape on the fly.
Changing texture on TextureState takes lot of time.
Someone, in the forum, suggested to manage TextureBuffer.
Could someone points me to info about TextureBuffer ?
Or does anybody has a better suggestion ?
Seems to me there's no way out.
Take a look at Google Heart. It changes the texture on the fly, and the speed, only depends on the connection.
I think that there must be a way to do the same.
I'm digging deeper in the code to the renderer class; in you opinion is possbile to make some changes to interact directly on the images rendered as texture ?
Changing textures on TextureState is not that slow, try the webstart demo linked at http://www.jmonkeyengine.com/jmeforum/index.php?topic=4146.0 to get an impression. There's no magic in there, in fact the alpha texture gets regenerated from a BufferedImage every frame while painting.
Just make sure you have your textures preloaded, or load them as .dds (with mipmaps included, mipmap generation takes up a huge part of texture loading), or don't use mipmaps/flipping.
You’re absolutly right, actually the operation taked too long due to the use of anisotropic filter.
Take a look, I’m working on it.
http://www.youtube.com/watch?v=tgOBh8ZjOk8
Hey, that's pretty cool
That is cool, I am trying to implement a camera that works the same way, would you mind sharing your setup?
Back from holydays.
SphericalMouseLookHandler.java
package it.phoenix.input;
import it.phoenix.input.action.SphericalMouseLook;
import com.jme.input.InputHandler;
import com.jme.input.RelativeMouse;
import com.jme.intersection.PickResults;
import com.jme.math.Vector3f;
import com.jme.renderer.Camera;
public class SphericalMouseLookHandler extends InputHandler {
private SphericalMouseLook mouseLook;
public SphericalMouseLookHandler( Camera cam, float speed, int radius) {
RelativeMouse mouse = new RelativeMouse("Mouse Input");
mouse.registerWithInputHandler( this );
mouseLook = new SphericalMouseLook(mouse, cam, speed, radius);
mouseLook.setLockAxis(new Vector3f(cam.getUp()));
addAction(mouseLook);
}
public void setLockAxis(Vector3f lock) {
mouseLook.setLockAxis(new Vector3f(lock));
}
public SphericalMouseLook getMouseLook() {
return mouseLook;
}
}
SphericalMouseLook.java
package it.phoenix.input.action;
import com.jme.input.Mouse;
import com.jme.input.MouseInput;
import com.jme.input.MouseInputListener;
import com.jme.input.action.InputActionEvent;
import com.jme.input.action.KeyBackwardAction;
import com.jme.input.action.KeyForwardAction;
import com.jme.input.action.KeyStrafeDownAction;
import com.jme.input.action.KeyStrafeLeftAction;
import com.jme.input.action.KeyStrafeRightAction;
import com.jme.input.action.KeyStrafeUpAction;
import com.jme.input.action.MouseInputAction;
import com.jme.math.FastMath;
import com.jme.math.Vector2f;
import com.jme.math.Vector3f;
import com.jme.renderer.Camera;
public class SphericalMouseLook extends MouseInputAction {
//actions to handle looking up down left and right.
private KeyStrafeUpAction strafeUp;
private KeyStrafeDownAction strafeDown;
private KeyStrafeLeftAction strafeLeft;
private KeyStrafeRightAction strafeRight;
private KeyForwardAction moveForward;
private KeyBackwardAction moveBackward;
//the axis to lock.
private Vector3f lockAxis;
//the event to distribute to the looking actions.
private InputActionEvent event;
private boolean dxButtonDown;
private boolean sxButtonDown;
private Camera camera;
private int radius;
private Vector3f cameraPolar;
private Vector3f cameraCart;
private Vector2f mousePosition = new Vector2f();
private int wheel = 0;
public SphericalMouseLook(Mouse mouse, Camera camera, float speed, int radius) {
this.mouse = mouse;
this.speed = speed;
this.radius = radius;
this.camera = camera;
cameraPolar = new Vector3f();
cameraCart = camera.getLocation();
strafeDown = new KeyStrafeDownAction(camera, speed);
strafeUp = new KeyStrafeUpAction(camera, speed);
strafeLeft = new KeyStrafeLeftAction(camera, speed);
strafeRight = new KeyStrafeRightAction(camera, speed);
moveForward = new KeyForwardAction(camera, speed);
moveBackward = new KeyBackwardAction(camera, speed);
event = new InputActionEvent();
MouseInput.get().addListener(new MouseInputListener() {
public void onButton(int button, boolean pressed, int x, int y) {
if (button == 0){
sxButtonDown = pressed;
}
if (button == 1){
dxButtonDown = pressed;
}
}
public void onMove(int xDelta, int yDelta, int newX, int newY) {
mousePosition.x = newX;
mousePosition.y = newY;
}
public void onWheel(int wheelDelta, int x, int y) {
wheel = wheelDelta;
}
});
}
public void setLockAxis(Vector3f lockAxis) {
this.lockAxis = lockAxis;
}
public Vector3f getLockAxis() {
return lockAxis;
}
public void setSpeed(float speed) {
super.setSpeed( speed );
strafeDown.setSpeed(speed);
strafeUp.setSpeed(speed);
strafeRight.setSpeed(speed);
strafeLeft.setSpeed(speed);
}
public void performAction(InputActionEvent evt) {
float time = 0.01f * speed;
if (wheel > 0){
event.setTime(time * wheel);
radius += (event.getTime() * (radius / 100));
cameraPolar.x = radius;
FastMath.sphericalToCartesian(cameraPolar, cameraCart);
camera.setLocation(cameraCart);
wheel = 0;
}
if (wheel < 0){
event.setTime(time * wheel);
radius += (event.getTime() * (radius / 100));
cameraPolar.x = radius;
FastMath.sphericalToCartesian(cameraPolar, cameraCart);
camera.setLocation(cameraCart);
wheel = 0;
}
if (mouse.getLocalTranslation().x > 0) {
event.setTime(time * mouse.getLocalTranslation().x);
FastMath.cartesianToSpherical(camera.getLocation(), cameraPolar);
cameraPolar.x = radius;
cameraPolar.y -= (FastMath.PI / 10 * event.getTime());
FastMath.sphericalToCartesian(cameraPolar, cameraCart);
camera.setLocation(cameraCart);
} else if (mouse.getLocalTranslation().x < 0) {
event.setTime(time * mouse.getLocalTranslation().x * -1);
FastMath.cartesianToSpherical(camera.getLocation(), cameraPolar);
cameraPolar.x = radius;
cameraPolar.y += (FastMath.PI / 10 * event.getTime());
FastMath.sphericalToCartesian(cameraPolar, cameraCart);
camera.setLocation(cameraCart);
}
if (mouse.getLocalTranslation().y > 0) {
event.setTime(time * mouse.getLocalTranslation().y);
FastMath.cartesianToSpherical(camera.getLocation(), cameraPolar);
cameraPolar.x = radius;
cameraPolar.z += (FastMath.PI / 10 * event.getTime());
FastMath.sphericalToCartesian(cameraPolar, cameraCart);
camera.setLocation(cameraCart);
} else if (mouse.getLocalTranslation().y < 0) {
event.setTime(time * mouse.getLocalTranslation().y * -1);
FastMath.cartesianToSpherical(camera.getLocation(), cameraPolar);
cameraPolar.x = radius;
cameraPolar.z -= (FastMath.PI / 10 * event.getTime());
FastMath.sphericalToCartesian(cameraPolar, cameraCart);
camera.setLocation(cameraCart);
}
camera.lookAt (new Vector3f(0, 0, 0), new Vector3f(0, 0, 0));
}
}
Enjoy.
Champion!