Hi
I try use ExplosionFactory from jme example but effect is not visible. I have message in console that node is created and attached to scene but still nothing happend. I read all "explosion" and "particlemesh" topics but I cant find solution. Please help me ;P!
PS. I'm beginer and this is my first example so bug can be stupid.
Myengine class:
public class engine extends BaseGame {
protected Timer timer;
private TerrainBlock tb;
//the root node of the scene graph
private Node scene;
private Node model;
private Plane player;
GameControlManager manager = new GameControlManager();
Sphere t = null;
//private NodeHandler inputHandler;
ParticleMesh explosion;
int i=10;
int ammocount=0;
int distance=100;
boolean fire=false;
float lifeTime = 5;
Skybox sb;
ArrayList<Bullet> lista=new ArrayList<Bullet>();
private TextureState ts;
private TextureState ts2;
private TextureState ts5;
protected InputHandler input;
// Our camera object for viewing the scene
private Camera cam;
//The chase camera, this will follow our player as he zooms around the level
private ChaseCamera chaser;
//display attributes for the window. We will keep these values
//to allow the user to change them
private int width, height, depth, freq;
private boolean fullscreen;
private enum Direction {
RIGHT,
LEFT,
FORWARD,
BACKWARD;
}
Direction dir;
private void buildTerrain() {
// Generate a random terrain data
MidPointHeightMap heightMap = new MidPointHeightMap(128, 0.7f);
// Scale the data
Vector3f terrainScale = new Vector3f(20, 0.5f, 20);
// create a terrainblock
tb = new TerrainBlock("Terrain", heightMap.getSize(), terrainScale,
heightMap.getHeightMap(), new Vector3f(-30, 0, -2100), false);
tb.setModelBound(new BoundingBox());
tb.updateModelBound();
// generate a terrain texture with 3 textures
ProceduralTextureGenerator pt = new ProceduralTextureGenerator(
heightMap);
pt.addTexture(new ImageIcon(("res/grass.jpg")), -128, 0, 128);
pt.addTexture(new ImageIcon(("res/sand.jpg")), 0, 128, 255);
pt.addTexture(new ImageIcon(("res/grass.png")), 128, 255, 384);
//pt.addTexture(new ImageIcon(("res/highest.png")), 128, 255,384);
pt.createTexture(32);
//pt.
// assign the texture to the terrain
TextureState ts = display.getRenderer().createTextureState();
ts.setEnabled(true);
Texture t1 = TextureManager.loadTexture(pt.getImageIcon().getImage(),
Texture.MM_LINEAR_LINEAR, Texture.FM_LINEAR, true);
//ts.setTexture(t1, 0);
Texture t2 = TextureManager.loadTexture(("res/grass.jpg"), Texture.MM_LINEAR_LINEAR, Texture.FM_LINEAR);
ts.setTexture(t2, 1);
t2.setWrap(Texture.WM_WRAP_S_WRAP_T);
t1.setApply(Texture.AM_COMBINE);
t1.setCombineFuncRGB(Texture.ACF_MODULATE);
t1.setCombineSrc0RGB(Texture.ACS_TEXTURE);
t1.setCombineOp0RGB(Texture.ACO_SRC_COLOR);
t1.setCombineSrc1RGB(Texture.ACS_PRIMARY_COLOR);
t1.setCombineOp1RGB(Texture.ACO_SRC_COLOR);
t1.setCombineScaleRGB(1.0f);
t2.setApply(Texture.AM_COMBINE);
t2.setCombineFuncRGB(Texture.ACF_ADD_SIGNED);
t2.setCombineSrc0RGB(Texture.ACS_TEXTURE);
t2.setCombineOp0RGB(Texture.ACO_SRC_COLOR);
t2.setCombineSrc1RGB(Texture.ACS_PREVIOUS);
t2.setCombineOp1RGB(Texture.ACO_SRC_COLOR);
t2.setCombineScaleRGB(1.0f);
tb.setRenderState(ts);
tb.setDetailTexture(1, 16);
tb.setRenderQueueMode(Renderer.QUEUE_OPAQUE);
//tb.setRenderState(ts);
//tb.setTextureCombineMode(0);
//tb.setLightCombineMode(LightState.OFF);
tb.updateRenderState();
scene.updateRenderState();
}
/**
- Main entry point of the application
*/
/
* creates a light for the terrain.
/
private void buildLighting() {
/ Set up a basic, default light. /
DirectionalLight light = new DirectionalLight();
light.setDiffuse(new ColorRGBA(1.0f, 1.0f, 1.0f, 1.0f));
light.setAmbient(new ColorRGBA(0.5f, 0.5f, 0.5f, 1.0f));
light.setDirection(new Vector3f(1,-1,0));
light.setEnabled(true);
/ Attach the light to a lightState and the lightState to
rootNode. */
LightState lightState = display.getRenderer().createLightState();
lightState.setEnabled(true);
lightState.attach(light);
scene.setRenderState(lightState);
}
public static void main(String[] args) {
engine app = new engine();
//We will load our own "fantastic" Flag Rush logo. Yes, I'm an artist.
app.setDialogBehaviour(ALWAYS_SHOW_PROPS_DIALOG,
("res/splashscrean.png"));
app.start();
}
void checkCollisions(){
// if(player.hasCollision(tb, false))
System.out.println("colizja");
}
/**
- During an update we only look for the escape button and update the
timer
- to get the framerate.
/
protected void update(float interpolation) {
//update the time to get the framerate
timer.update();
// checkCollisions();
tb.getWorldTranslation().z=tb.getLocalTranslation().z;
if(lifeTime==5000){
lista.add(new Bullet());
lista.get(lista.size()-1).getLocalTranslation().set(player.getLocalTranslation());
scene.attachChild(lista.get(lista.size()-1));
lifeTime --;
}
for(int i=0;i<lista.size();i++)
{
if (lista.get(i).lifet > 1000) {
scene.detachChild(lista.get(i));
lista.remove(i);
System.out.println("remove: "+i);
}
else{
{
System.out.println("dupa2");
lista.get(i).getLocalTranslation().z-=70 timer.getTimePerFrame();
//player.getLocalTranslation().y += player.getMaxSpeed() * timer.getTimePerFrame();
lista.get(i).updateWorldBound();
//lifeTime --;
lista.get(i).lifet++;
}
}
}
//vry
//sb.getLocalTranslation().set(cam.getLocation().x, cam.getLocation().y,
// cam.getLocation().z);
//if(KeyBindingManager.getKeyBindingManager().isValidCommand("fire"))
if(MouseInput.get().isButtonDown(0))
{
lifeTime=5000;
}
cam.update();
if (KeyBindingManager.getKeyBindingManager().isValidCommand("BALLTHROWER_SHOOT")) {
//t= Shoot();
//fire=true;
buulets gg=new buulets();
System.out.println("id rownasie"+gg.id);
}
if (KeyBindingManager.getKeyBindingManager().isValidCommand("exit")) {
finished = true;//KEY_W
}
if (KeyBindingManager.getKeyBindingManager().isValidCommand("moveFwd")) {
player.getLocalTranslation().y += player.getMaxSpeed() * timer.getTimePerFrame();
}
if (KeyBindingManager.getKeyBindingManager().isValidCommand("moveBwd")) {
player.getLocalTranslation().y -= player.getMaxSpeed()* timer.getTimePerFrame();
}
if (KeyBindingManager.getKeyBindingManager().isValidCommand("rotateLeft")) {
player.getLocalTranslation().x -= player.getMaxSpeed()* timer.getTimePerFrame();
//ExplosionFactory.warmup();
explosion = ExplosionFactory.getExplosion();
// explosion.setOriginOffset(player.getLocalTranslation().clone());
//explosion.setOriginOffset(500.0f, 160.0f, 450.0f);
explosion.forceRespawn();
scene.attachChild(explosion);
explosion.forceRespawn();
// explosion.setCullMode(Spatial.COMPOSITE_MESH);
// explosion.getLocalScale().set(2.5f, 2.5f, 2.5f);
// explosion.getLocalTranslation().set( 500.0f, 160.0f, 450.0f );
// explosion.updateRenderState();
// explosion.updateGeometricState(0,true);
// explosion.updateWorldVectors();
//scene.updateWorldVectors();
// scene.setParticlesInWorldCoords(boolean);
}
if (KeyBindingManager.getKeyBindingManager().isValidCommand("rotateRight")) {
player.getLocalTranslation().x += player.getMaxSpeed()* timer.getTimePerFrame();
//cam.getWorldCoordinates(arg0, arg1)
}
if (KeyBindingManager.getKeyBindingManager().isValidCommand("start")) {
player.getLocalTranslation().z -= player.getMaxSpeed()* timer.getTimePerFrame();
cam.getLocation().z-=player.getMaxSpeed() * timer.getTimePerFrame();
//cam.getDirection().y-=player.getMaxSpeed() * timer.getTimePerFrame();
}
if (KeyBindingManager.getKeyBindingManager().isValidCommand("back")) {
//player.setLocalRotation(new Quaternion(new float[] { FastMath.DEG_TO_RAD*-90, i, 0} ));
player.getLocalTranslation().z += (player.getMaxSpeed()* timer.getTimePerFrame());
cam.getLocation().z+=player.getMaxSpeed() * timer.getTimePerFrame();
}
// input.update(interpolation);
// scene.updateWorldBound();
// model.updateWorldBound();
player.updateWorldBound();
//input.update(interpolation);
scene.updateWorldBound();
model.updateWorldBound();
scene.updateGeometricState(1.0f, true);
scene.updateRenderState();
}
private void setupSky() {
sb = new Skybox( "skybox", 300, 300,300 );
try {
ResourceLocatorTool.addResourceLocator(
ResourceLocatorTool.TYPE_TEXTURE,
new SimpleResourceLocator(getClass().getResource(
"workspace1/try/")));
} catch (Exception e) {
System.out.println("Unable to access texture directory gfgfg.");
e.printStackTrace();
}
// sb.setTexture( Skybox.NORTH, TextureManager.loadTexture("res/Clouds2.jpg", Texture.MM_LINEAR, Texture.FM_LINEAR ) );
// sb.setTexture( Skybox.WEST, TextureManager.loadTexture("res/Clouds2.jpg", Texture.MM_LINEAR, Texture.FM_LINEAR ) );
sb.setTexture( Skybox.SOUTH, TextureManager.loadTexture("res/Clouds2.jpg", Texture.MM_LINEAR, Texture.FM_LINEAR ) );
sb.setTexture( Skybox.EAST, TextureManager.loadTexture("res/Clouds2.jpg", Texture.MM_LINEAR, Texture.FM_LINEAR ) );
sb.setTexture( Skybox.UP, TextureManager.loadTexture("res/Clouds2.jpg", Texture.MM_LINEAR, Texture.FM_LINEAR ) );
sb.setTexture( Skybox.DOWN, TextureManager.loadTexture("res/Clouds2.jpg", Texture.MM_LINEAR, Texture.FM_LINEAR ) );
sb.preloadTextures();//rolling_hills
// Texture generatedClouds = generateClouds(128, 128);
//sb.setTexture(Skybox.SOUTH, generatedClouds);
CullState cullState = display.getRenderer().createCullState();
cullState.setCullMode( CullState.CS_NONE);
cullState.setEnabled( true );
sb.setRenderState( cullState );
sb.updateRenderState();
}
/**
- draws the scene graph
-
@return
*/
protected void render(float interpolation) {
//Clear the screen
display.getRenderer().clearBuffers();
display.getRenderer().draw(scene);
}
/**
- initializes the display and camera.
/
protected void initSystem() {
//store the properties information
width = properties.getWidth();
height = properties.getHeight();
depth = properties.getDepth();
freq = properties.getFreq();
fullscreen = properties.getFullscreen();
try {
display = DisplaySystem.getDisplaySystem(properties.getRenderer());
display.createWindow(width, height, depth, freq, fullscreen);
cam = display.getRenderer().createCamera(width, height);
} catch (JmeException e) {
e.printStackTrace();
System.exit(1);
}
//set the background to black
display.getRenderer().setBackgroundColor(ColorRGBA.white);
//initialize the camera
cam.setFrustumPerspective(45.0f, (float) width / (float) height, 1, 1000);//5000
// Vector3f loc = new Vector3f(0.0f, 0.0f, 25.0f);
// Vector3f left = new Vector3f(-1.0f, 0.0f, 0.0f);
// Vector3f up = new Vector3f(0.0f, 1.0f, 0.0f);
// Vector3f dir = new Vector3f(0.0f, 0f, -1.0f);
Vector3f loc = new Vector3f(500.0f, 150.0f, 500.0f);
Vector3f left = new Vector3f(0.0f, 0.0f, 0.0f);
Vector3f up = new Vector3f(0.0f, 1.0f, 0.0f);
Vector3f dir = new Vector3f(0.0f, 0.0f, -1.0f);
// Move our camera to a correct place and orientation.
cam.setFrame(loc, left, up, dir);
/* Signal that we've changed our camera's location/frustum. /
cam.update();
/* Get a high resolution timer for FPS updates. /
timer = Timer.getTimer();
display.getRenderer().setCamera(cam);
GameControl fire = manager.addControl("fire");
KeyBindingManager.getKeyBindingManager().set("moveFwd", KeyInput.KEY_W);
KeyBindingManager.getKeyBindingManager().set("moveBwd", KeyInput.KEY_S);
KeyBindingManager.getKeyBindingManager().set("rotateLeft", KeyInput.KEY_A);
KeyBindingManager.getKeyBindingManager().set("rotateRight", KeyInput.KEY_D);
KeyBindingManager.getKeyBindingManager().set("start", KeyInput.KEY_F);
KeyBindingManager.getKeyBindingManager().set("back", KeyInput.KEY_G);
KeyBindingManager.getKeyBindingManager().set("BALLTHROWER_SHOOT", KeyInput.KEY_SPACE);
KeyBindingManager.getKeyBindingManager().set("exit",
KeyInput.KEY_ESCAPE);
// KeyBindingManager.getKeyBindingManager().set("fire", KeyInput.KEY_SPACE);
fire.addBinding(new MouseButtonBinding(MouseButtonBinding.LEFT_BUTTON));
KeyBindingManager.getKeyBindingManager().set("exit",
KeyInput.KEY_ESCAPE);
}
private void buildChaseCamera() {
}
private void buildPlayer() {
//box stand in
model=getModel3ds(new File("res/fighter1.3ds"));//Matt_Drums.3ds
//model.setLocalScale(0.6f);
//model.setLocalTranslation(new Vector3f(100,0, 100));
model.setModelBound(new BoundingBox());
model.updateModelBound();
try {
MultiFormatResourceLocator loc3 = new MultiFormatResourceLocator(new File("c:/").toURI(), ".jpg", ".png", ".tga");
ResourceLocatorTool.addResourceLocator(ResourceLocatorTool.TYPE_TEXTURE, loc3);
} catch (Exception e) {
e.printStackTrace();
}
try {
//ts2.setTexture(t2, 0);
//URL ul=getClass().getClassLoader().getResource("kaoskiwi.jpg");
URL ul=this.getClass().getResource("cinfa.jpg");
ts5 = display.getRenderer().createTextureState();
Texture t1 = TextureManager.loadTexture(ul,
Texture.MM_LINEAR_LINEAR, Texture.FM_LINEAR);
ts5.setTexture(t1,0);
model.setRenderState(ts5);
model.setTextureCombineMode(1);
model.updateRenderState();
scene.updateRenderState();
} catch (Exception e) {
System.out.println("aaaaaaaaaaaaaa");
e.printStackTrace();
}
model.getLocalRenderQueueMode();
// ts2.setEnabled(true);
model.setLightCombineMode(LightState.OFF);
player = new Plane("Player Node", model);
scene.updateRenderState();
player.updateRenderState();
model.updateRenderState();
player.setAcceleration(15);
player.setBraking(25);
player.setTurnSpeed(5);
player.setWeight(25);
player.setMaxSpeed(25);
player.setMinSpeed(15);
//crono782.jpg
player.getLocalScale().set(0.5f, 0.5f, 0.5f);
player.getLocalTranslation().set( 500.0f, 160.0f, 450.0f );
//player.getLocalTranslation().set( 0.25f, -0.1f, -40.0f );//0.0f,-2.0f,19.0f
player.setLocalRotation(new Quaternion(new float[] { FastMath.DEG_TO_RAD-90, 80, 0} ));
player.updateWorldBound();
scene.attachChild(player);
scene.updateWorldBound();
player.setRenderQueueMode(Renderer.QUEUE_TRANSPARENT);
}
/**
- initializes the scene
*/
protected void initGame() {
scene = new Node("Scene graph node");
// setupSky();
buildTerrain();
scene.attachChild(tb);
scene.updateWorldBound();
ZBufferState buf = display.getRenderer().createZBufferState();
buf.setEnabled(true);
buf.setFunction(ZBufferState.CF_LEQUAL);
scene.setRenderState(buf);
buildLighting();
buildPlayer();
// CullState cs = display.getRenderer().createCullState();
// cs.setCullMode(CullState.RS_FOG);
// scene.setRenderState(cs);
// scene.attachChild(sb);
// buildChaseCamera();
// buildInput();
scene.updateGeometricState(1.0f, true);
scene.updateRenderState();
}
/**
- will be called if the resolution changes
*
*/
protected void reinit() {
display.recreateWindow(width, height, depth, freq, fullscreen);
}
/**
- clean up the textures.
*
*/
protected void cleanup() {
ts.deleteAll();
}
public Node getModel3ds(File file) {
FormatConverter converter = new MaxToJme();
Node model = null;
ByteArrayOutputStream bo = new ByteArrayOutputStream();
File input = new File("cache/"+file.getName() + ".jme");
// check if there is a cached jme format model for the requested file
if(input.isFile()) {
try {
ResourceLocatorTool.addResourceLocator(ResourceLocatorTool.TYPE_MODEL,
new SimpleResourceLocator(file.getParentFile().toURI()));
model =
(Node)BinaryImporter.getInstance().load(input);
ResourceLocatorTool.removeResourceLocator(ResourceLocatorTool.TYPE_MODEL,
new SimpleResourceLocator(file.getParentFile().toURI()));
return model;
} catch(IOException e) {
e.printStackTrace();
}
}
// no cached model found -> convert the 3ds file and cache it
try {
ResourceLocatorTool.addResourceLocator(ResourceLocatorTool.TYPE_TEXTURE,
new SimpleResourceLocator(file.getParentFile().toURI()));
converter.convert(new FileInputStream(file), bo);
model = (Node)BinaryImporter.getInstance().load(new
ByteArrayInputStream(bo.toByteArray()));
bo.writeTo(new
FileOutputStream("cache/"+file.getName()+".jme"));
ResourceLocatorTool.removeResourceLocator(ResourceLocatorTool.TYPE_TEXTURE,
new SimpleResourceLocator(file.getParentFile().toURI()));
} catch(IOException e) {
e.printStackTrace();
}
return model;
}
}