Vanishing Objects

Hello,



I’m new to JME and tried to learn it by copying some stuff from the provided test-classes to create something “new”. The test-classes all work well.

But I have in both tests I’ve done the problem that with moving/rotating the camera water surfaces and the sky turn black and with further movement normal again. Because it’s shorter I will post this code here. In my other class the character I used from the test files appears but if I add more than one additional model just one of them is visible at a time and the visible one changes by moving the camera, too. The walking character is visible all the time.

Please give me a hint :cry:



[java]import com.jme3.app.SimpleApplication;

import com.jme3.effect.ParticleEmitter;

import com.jme3.effect.ParticleMesh;

import com.jme3.light.DirectionalLight;

import com.jme3.material.Material;

import com.jme3.renderer.queue.RenderQueue.ShadowMode;

import com.jme3.math.ColorRGBA;

import com.jme3.math.FastMath;

import com.jme3.math.Plane;

import com.jme3.math.Quaternion;

import com.jme3.math.Vector2f;

import com.jme3.math.Vector3f;

import com.jme3.renderer.Camera;

import com.jme3.scene.Geometry;

import com.jme3.scene.Node;

import com.jme3.scene.shape.Quad;

import com.jme3.scene.shape.Sphere;

import com.jme3.terrain.geomipmap.TerrainLodControl;

import com.jme3.terrain.heightmap.AbstractHeightMap;

import com.jme3.terrain.geomipmap.TerrainQuad;

import com.jme3.terrain.heightmap.HillHeightMap;

import com.jme3.terrain.heightmap.ImageBasedHeightMap;

import com.jme3.texture.Texture;

import com.jme3.texture.Texture.WrapMode;

import com.jme3.util.SkyFactory;

import com.jme3.water.SimpleWaterProcessor;

import java.util.ArrayList;

import java.util.List;

import jme3test.water.WaterUI;

import jme3tools.converters.ImageToAwt;



public class HelloTerrain extends SimpleApplication {



private TerrainQuad terrain;

Material mat_terrain;



public static void main(String[] args) {

HelloTerrain app = new HelloTerrain();

app.start();

}



@Override

public void simpleInitApp() {

flyCam.setMoveSpeed(200);



/** 1. Create terrain material and load four textures into it. /

mat_terrain = new Material(assetManager, “Common/MatDefs/Terrain/Terrain.j3md”);



/
* 1.1) Add ALPHA map (for red-blue-green coded splat textures) /

mat_terrain.setTexture(“m_Alpha”,

assetManager.loadTexture(“Textures/Terrain/splat/alphamap.png”));



/
* 1.2) Add GRASS texture into the red layer (m_Tex1). /

Texture grass = assetManager.loadTexture(“Textures/Terrain/splat/grass.jpg”);

grass.setWrap(WrapMode.Repeat);

mat_terrain.setTexture(“m_Tex1”, grass);

mat_terrain.setFloat(“m_Tex1Scale”, 64f);



/
* 1.3) Add DIRT texture into the green layer (m_Tex2) /

Texture dirt = assetManager.loadTexture(“Textures/Terrain/splat/dirt.jpg”);

dirt.setWrap(WrapMode.Repeat);

mat_terrain.setTexture(“m_Tex2”, dirt);

mat_terrain.setFloat(“m_Tex2Scale”, 32f);



/
* 1.4) Add ROAD texture into the blue layer (m_Tex3) /

Texture rock = assetManager.loadTexture(“Textures/Terrain/splat/road.jpg”);

rock.setWrap(WrapMode.Repeat);

mat_terrain.setTexture(“m_Tex3”, rock);

mat_terrain.setFloat(“m_Tex3Scale”, 128f);



/
* 2. Create the height map /

//final Texture heightMapImage =

// assetManager.loadTexture(“Textures/Terrain/splat/mountains512.png”);

final Texture heightMapImage =

assetManager.loadTexture(“assets/texture/heightmaps/test.png”);

final AbstractHeightMap heightmap =

new ImageBasedHeightMap(

ImageToAwt.convert(

heightMapImage.getImage(), false, true, 0));

heightmap.load();



terrain = new TerrainQuad(“my terrain”, 65, 1025, heightmap.getHeightMap());



/
* 4. We give the terrain its material, position & scale it, and attach it. /

terrain.setMaterial(mat_terrain);

terrain.setLocalTranslation(0, -100, 0);

terrain.setLocalScale(2f, 1f, 2f);

rootNode.attachChild(terrain);



terrain = new TerrainQuad(“my terrain”, 65, 1025, heightmap.getHeightMap());



/
* 4. We give the terrain its material, position & scale it, and attach it. /

terrain.setMaterial(mat_terrain);

terrain.setLocalScale(2f, 1f, 2f);

terrain.setLocalTranslation(2046,-100, 0);

rootNode.attachChild(terrain);



/
* 5. The LOD (level of detail) depends on were the camera is: */

List<Camera> cameras = new ArrayList<Camera>();

cameras.add(getCamera());

TerrainLodControl control = new TerrainLodControl(terrain, cameras);

terrain.addControl(control);



this.addWater();



}



public void addWater() {

DirectionalLight sun = new DirectionalLight();

Vector3f lightDir=new Vector3f(-0.37352666f, -0.50444174f, -0.7784704f);

sun.setDirection(lightDir);

sun.setColor(ColorRGBA.White.clone().multLocal(2));



Material mat = new Material(assetManager, “Common/MatDefs/Misc/SimpleTextured.j3md”);

mat.setTexture(“ColorMap”, assetManager.loadTexture(“Interface/Logo/Monkey.jpg”));



Node mainScene=new Node();

mainScene.addLight(sun);

// load sky

mainScene.attachChild(SkyFactory.createSky(assetManager, “Textures/Sky/Bright/BrightSky.dds”, false));



Sphere lite=new Sphere(8, 8, 3.0f);

Geometry lightSphere=new Geometry(“lightsphere”, lite);

lightSphere.setMaterial(mat);

Vector3f lightPos=lightDir.multLocal(-400);

lightSphere.setLocalTranslation(lightPos);

rootNode.attachChild(lightSphere);



Quad quad = new Quad(400,400);

SimpleWaterProcessor waterProcessor = new SimpleWaterProcessor(assetManager);

waterProcessor.setReflectionScene(mainScene);

waterProcessor.setDebug(false);

waterProcessor.setLightPosition(lightPos);

waterProcessor.setRefractionClippingOffset(1.0f);



Vector3f waterLocation=new Vector3f(0,-20,0);

waterProcessor.setPlane(new Plane(Vector3f.UNIT_Y, waterLocation.dot(Vector3f.UNIT_Y)));

WaterUI waterUi=new WaterUI(inputManager, waterProcessor);

waterProcessor.setWaterColor(ColorRGBA.Brown);

waterProcessor.setDebug(true);



//the texture coordinates define the general size of the waves

quad.scaleTextureCoordinates(new Vector2f(6f,6f));

Geometry water=new Geometry(“water”, quad);

water.setShadowMode(ShadowMode.Receive);

water.setLocalRotation(new Quaternion().fromAngleAxis(-FastMath.HALF_PI, Vector3f.UNIT_X));

water.setMaterial(waterProcessor.getMaterial());

water.setLocalTranslation(-200, -20, 250);



viewPort.addProcessor(waterProcessor);



rootNode.attachChild(mainScene);

rootNode.attachChild(water);

}

}[/java]

you’ll resolve your first issue by doing this



Spatial sky = SkyFactory.createSky(assetManager, “Textures/Sky/Bright/BrightSky.dds”, false);

sky.setLocalScale(100);

mainScene.attachChild(sky);



The thing is the sky is a sphere that have a radius of 10 units. It’s rendered always in the far distance so it looks like it’s all around you.

But in fact…it’s a sphere with a radius of 10 at the center of your scene.

So when you look away from the center of your scene it goes out of the camera field of view and get culled (not rendered).

So setting its scale to 100, will make it a sphere with a 1000 units radius, which will make this issue a lot less likely to occur.

1 Like

Just set the cullHint of the Sky to never… It should always be rendered anyway, shouldn’t it?

Or that yes :p…

I think I’ve seen this before…there might be a bug in the matrix…

Thanks Nehon. It works.

This: sky.setCullHint(CullHint.Never); unfortunately causes the same problem.



But it does not solve the problem in my other class where I do not use any sky (just a backgroundcolor). For Showing the problem I wanted to build a class using the teapot from the tutorial instead of my models and they worked. So for now I just post the part where the models are placed maybe there is the mistake.



This one works:

[java]Spatial teapot = assetManager.loadModel(“Models/Teapot/Teapot.obj”);

Material mat_default = new Material(

assetManager, “Common/MatDefs/Misc/ShowNormals.j3md”);

teapot.setMaterial(mat_default);

teapot.setLocalTranslation(30, -46f, 20);

rootNode.attachChild(teapot);

teapot = assetManager.loadModel(“Models/Teapot/Teapot.obj”);

teapot.setMaterial(mat_default);

teapot.setLocalTranslation(30, -46f, 15);

rootNode.attachChild(teapot);

teapot = assetManager.loadModel(“Models/Teapot/Teapot.obj”);

teapot.setMaterial(mat_default);

teapot.setLocalTranslation(20, -46f, 15);

rootNode.attachChild(teapot);[/java]



This one doesn’t:

[java]Spatial flower = assetManager.loadModel(“assets/models/flower2.obj”);

flower.setModelBound(new BoundingBox());

flower.updateModelBound();

flower.setLocalScale(0.5f);

flower.setLocalTranslation(20, -46f, 5);

rootNode.attachChild(flower);

Node flow = (Node) assetManager.loadModel(“assets/models/flowerGood.obj”);

flow.setModelBound(new BoundingBox());

flow.updateModelBound();

flow.setLocalTranslation(30, -46f, 20);

rootNode.attachChild(flow);

flower = assetManager.loadModel(“assets/models/flower2.obj”);

flower.setLocalTranslation(30, -46f, 15);

flower.setModelBound(new BoundingBox());

flower.updateModelBound();

rootNode.attachChild(flower);[/java]

(Using different types for the models ist just a try to find the mistake^^)

you don’t need this



flower.setModelBound(new BoundingBox());

flower.updateModelBound();



It is at best useless, at worst causing the issue…

the model bound are handled by the engine, remove those lines and see if it works.

Unfortunately I added this just because I read about similar problems in this forum and this seemed to help there.

I created a very much shortened version of my class which still shows the same problems. A second detail: Since the flower got colors (a friend of mine is doing the modelling stuff parallel to my programming) it shows even more weird behavior: It just shows one leave of the bloom and the shown leave can change when the camera moves. If there is a second flower even this litle leave disappears completely and reappears if the other flower disappears.

I loaded both models up maybe it’s theire fault? http://enum.pytalhost.net/flower.zip



(For this test I chose the default terrain that’s used in the tests, so the flowers will be on the ground next to the landing position of the golem… the teapots float near your camera startingposition)

[java]package FirstTest;

import jme3tools.converters.ImageToAwt;

import com.jme3.animation.AnimChannel;

import com.jme3.animation.AnimControl;

import com.jme3.app.SimpleApplication;

import com.jme3.bullet.BulletAppState;

import com.jme3.bullet.PhysicsSpace;

import com.jme3.bullet.collision.shapes.CapsuleCollisionShape;

import com.jme3.bullet.control.CharacterControl;

import com.jme3.bullet.control.RigidBodyControl;

import com.jme3.bullet.util.CollisionShapeFactory;

import com.jme3.light.DirectionalLight;

import com.jme3.material.Material;

import com.jme3.math.ColorRGBA;

import com.jme3.math.Vector3f;

import com.jme3.scene.Node;

import com.jme3.scene.Spatial;

import com.jme3.terrain.geomipmap.TerrainQuad;

import com.jme3.terrain.heightmap.AbstractHeightMap;

import com.jme3.terrain.heightmap.ImageBasedHeightMap;

import com.jme3.texture.Texture;

import com.jme3.texture.Texture.WrapMode;

public class Show extends SimpleApplication {

private BulletAppState bulletAppState;

private CharacterControl player;

private Node model;

AnimChannel animationChannel;

AnimControl animationControl;

float airTime = 0;

//Main

//

public static void main(String[] args) {

Show app = new Show();

app.start();

}

@Override

public void simpleInitApp() {

bulletAppState = new BulletAppState();

bulletAppState.setThreadingType(BulletAppState.ThreadingType.PARALLEL);

stateManager.attach(bulletAppState);

initLandscape();

initLight();

initCharacter();

initCamera();

addFlower();

}

private void initLandscape() {

viewPort.setBackgroundColor(new ColorRGBA(0.7f,0.8f,1f,1f));

Material matTerrain = new Material(assetManager, “Common/MatDefs/Terrain/Terrain.j3md”);

matTerrain.setTexture(“m_Alpha”, assetManager.loadTexture(“Textures/Terrain/splat/alphamap.png”));

Texture grass = assetManager.loadTexture(“Textures/Terrain/splat/grass.jpg”);

grass.setWrap(WrapMode.Repeat);

matTerrain.setTexture(“m_Tex1”, grass);

matTerrain.setFloat(“m_Tex1Scale”, 64f);

Texture dirt = assetManager.loadTexture(“Textures/Terrain/splat/dirt.jpg”);

dirt.setWrap(WrapMode.Repeat);

matTerrain.setTexture(“m_Tex2”, dirt);

matTerrain.setFloat(“m_Tex2Scale”, 32f);

Texture rock = assetManager.loadTexture(“Textures/Terrain/splat/road.jpg”);

rock.setWrap(WrapMode.Repeat);

matTerrain.setTexture(“m_Tex3”, rock);

matTerrain.setFloat(“m_Tex3Scale”, 128f);

final Texture heightMapImage = assetManager.loadTexture(“Textures/Terrain/splat/mountains512.png”);

final AbstractHeightMap heightmap = new ImageBasedHeightMap(ImageToAwt.convert(heightMapImage.getImage(), false, true, 0));

heightmap.load();

TerrainQuad terrain = new TerrainQuad(“my terrain”, 65, 1025, heightmap.getHeightMap());

terrain.setMaterial(matTerrain);

terrain.setLocalTranslation(0, -100, 0);

terrain.setLocalScale(2f, 1f, 2f);

//Mass 0, there’s no gravity pulling the ground

RigidBodyControl terrainPhysicsNode = new RigidBodyControl(CollisionShapeFactory.createMeshShape(terrain), 0);

terrain.addControl(terrainPhysicsNode);

getPhysicsSpace().add(terrainPhysicsNode);

rootNode.attachChild(terrain);

} //End initLandscape

private void initLight() {

Vector3f direction = new Vector3f(-0.1f, -0.7f, -1).normalizeLocal();

DirectionalLight dl = new DirectionalLight();

dl.setDirection(direction);

dl.setColor(new ColorRGBA(1f, 1f, 1f, 1.0f));

rootNode.addLight(dl);

}

private void initCharacter() {

CapsuleCollisionShape capsule = new CapsuleCollisionShape(1.5f, 2f);

player = new CharacterControl(capsule, 0.01f);

model = (Node) assetManager.loadModel(“Models/Oto/Oto.mesh.xml”);

model.setLocalScale(0.5f);

model.addControl(player);

player.setPhysicsLocation(new Vector3f(0, 0, 0));

player.setJumpSpeed(20);

player.setFallSpeed(30);

player.setGravity(30);

rootNode.attachChild(model);

getPhysicsSpace().add(player);

}

private void initCamera() {

flyCam.setMoveSpeed(50);

}

private void addFlower() {

Spatial flower = assetManager.loadModel(“assets/models/flower2.obj”);

flower.setLocalScale(0.5f);

flower.setLocalTranslation(20, -99f, 5);

rootNode.attachChild(flower);

Node flow = (Node) assetManager.loadModel(“assets/models/flowerGood.obj”);

flow.setLocalTranslation(30, -99f, 20);

rootNode.attachChild(flow);

Spatial flowe = assetManager.loadModel(“assets/models/flower2.obj”);

flowe.setLocalTranslation(30, -99f, 15);

rootNode.attachChild(flowe);

/Spatial teapot = assetManager.loadModel(“Models/Teapot/Teapot.obj”);

Material mat_default = new Material(

assetManager, “Common/MatDefs/Misc/ShowNormals.j3md”);

teapot.setMaterial(mat_default);

teapot.setLocalTranslation(30, -46f, 20);

rootNode.attachChild(teapot);

teapot = assetManager.loadModel(“Models/Teapot/Teapot.obj”);

teapot.setMaterial(mat_default);

teapot.setLocalTranslation(30, -46f, 15);

rootNode.attachChild(teapot);

teapot = assetManager.loadModel(“Models/Teapot/Teapot.obj”);

teapot.setMaterial(mat_default);

teapot.setLocalTranslation(20, -46f, 15);

rootNode.attachChild(teapot);
/

}

private PhysicsSpace getPhysicsSpace() {

return bulletAppState.getPhysicsSpace();

}

} //End Show

[/java]

After exporting the beginning cube from blender to wavefront .obj and seeing the same behavior I’m even more confused… Could it be that blender does not export the models in the way JMonkeyEngine needs them to be?

I wanted to try the OGRE Exporter but it seems not to be ready for blender 2.57, is it?

No its not.

It’s indeed a matter of model’s quality… I installed Blender 2.49b, Python and the export script and the exported cubes work : )

Now I need to find out how to make them having the color they got in blender^^ (I think I will find this out by myself with your great tutorials but a hint how to do such things best is always welcome ; ) )