Hello to all. I would like some help on an issue.
I hava a scene with 3 objects. One teapot, the ninja from the examples and one model that i have made and exported in ogrexml.
The problem is that the teapot and the ninja can be viewed corectly but my model is black. I can see it correctly only when the camera is very close to the object. I have attached two screenshots of the issue.
Also i had the same problem when loading the elephant from the tutorials.
This is the code i have.
Thanks in advance.
package my_first_jm3_scene;
import hello.HelloAssets;
import com.jme3.app.SimpleBulletApplication;
import com.jme3.asset.TextureKey;
import com.jme3.bullet.collision.shapes.MeshCollisionShape;
import com.jme3.bullet.nodes.PhysicsNode;
import com.jme3.light.DirectionalLight;
import com.jme3.light.PointLight;
import com.jme3.material.Material;
import com.jme3.math.Vector3f;
import com.jme3.renderer.queue.RenderQueue.ShadowMode;
import com.jme3.scene.Geometry;
import com.jme3.scene.Node;
import com.jme3.scene.Spatial;
import com.jme3.scene.shape.Box;
import com.jme3.texture.Texture;
public class FirstScene extends SimpleBulletApplication {
private Geometry floor;
private Node nionios;
@Override
public void simpleInitApp() {
setuplight();
setupFloor();
load_models("nionios/nionios.mesh.xml");
}
/**
* This loads the models we want on our scene from the Models folder.
*
* @param model The name of the model to load
*/
private void load_models(String model) {
//This shows the path where the folder Models is located
assetManager.registerLocator("assets/", "com.jme3.asset.plugins.ClasspathLocator");
// load a model
nionios = (Node) assetManager.loadModel("Models/"+model);
nionios.setLocalTranslation(0, -2, 0);
nionios.setLocalScale(0.01f);
rootNode.attachChild(nionios);
Geometry teapot = (Geometry) assetManager.loadModel("Models/Teapot/Teapot.obj");
Material mat = new Material(assetManager, "Common/MatDefs/Misc/ShowNormals.j3md");
teapot.setMaterial(mat);
teapot.setLocalTranslation(new Vector3f(1, 0, 0));
rootNode.attachChild(teapot);
// Load a Ninja model from jme3testdata.jar
Spatial ninja = assetManager.loadModel("Models/Ninja/Ninja.meshxml");
ninja.setLocalScale(0.01f);
ninja.rotate(0.0f , -3.0f , 0.0f);
ninja.setLocalTranslation(0.0f, -5.0f, -2.0f);
rootNode.attachChild(ninja);
}
public void setuplight() {
DirectionalLight dl = new DirectionalLight();
dl.setDirection(new Vector3f(-0.5f, -1f, -0.3f).normalizeLocal());
rootNode.addLight(dl);
dl = new DirectionalLight();
dl.setDirection(new Vector3f(0.5f, -0.1f, 0.3f).normalizeLocal());
rootNode.addLight(dl);
}
/**
* Setup a floor for our scene
*/
public void setupFloor() {
Material mat = new Material(assetManager, "Common/MatDefs/Misc/SimpleTextured.j3md");
TextureKey key = new TextureKey("Interface/Logo/Monkey.jpg", true);
key.setGenerateMips(true);
Texture tex = assetManager.loadTexture(key);
tex.setMinFilter(Texture.MinFilter.Trilinear);
mat.setTexture("m_ColorMap", tex);
Box floor = new Box(Vector3f.ZERO, 100, 1f, 100);
Geometry floorGeom = new Geometry("Floor", floor);
floorGeom.setMaterial(mat);
floorGeom.updateModelBound();
PhysicsNode tb=new PhysicsNode(floorGeom,new MeshCollisionShape(floorGeom.getMesh()),0);
rootNode.attachChild(tb);
tb.setLocalTranslation(new Vector3f(0f,-6,0f));
tb.updateModelBound();
tb.updateGeometricState();
getPhysicsSpace().add(tb);
}
/**
* @param args
*/
public static void main(String[] args) {
FirstScene app = new FirstScene();
app.start();
}
}