Hey guys I am trying to make an app that I can generate a dice and throw it but when I try running the engine with this code everything is just black and I dont know why. I suspect it may be the models I am trying to use. Maby one of you can take a look.
`*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package mygame;
import com.jme3.app.SimpleApplication;
import com.jme3.bullet.BulletAppState;
import com.jme3.bullet.control.RigidBodyControl;
import com.jme3.font.BitmapText;
import com.jme3.input.MouseInput;
import com.jme3.input.controls.ActionListener;
import com.jme3.input.controls.MouseButtonTrigger;
import com.jme3.light.DirectionalLight;
import com.jme3.light.PointLight;
import com.jme3.material.Material;
import com.jme3.math.ColorRGBA;
import com.jme3.math.Vector3f;
import com.jme3.scene.Geometry;
import com.jme3.scene.Spatial;
import com.jme3.scene.shape.Box;
import com.jme3.scene.shape.Sphere;
/**
*
* @author Shane.P.Drafahl
*/
public class DiceSim extends SimpleApplication {
public static void main(String[] args){
DiceSim app = new DiceSim();
app.start();
}
/** Prepare the Physics Application State (jBullet) */
private BulletAppState bulletAppState;
/** Prepare geometries and physical nodes for bricks and cannon balls. */
private RigidBodyControl dice_phy;
private Spatial dice;
private RigidBodyControl floor_phy;
private Spatial floor;
@Override
public void simpleInitApp() {
//assets
dice = assetManager.loadModel("Models/dice_0.scene");
floor = assetManager.loadModel("Models/platform.scene");
//physics stuff
bulletAppState = new BulletAppState();
stateManager.attach(bulletAppState);
//Stuff to set camera location
cam.setLocation(new Vector3f(6f, 20f, 6f));// 0, 4f,6f
cam.lookAt(new Vector3f(2, 2, 0), Vector3f.UNIT_Y);
//testing controls
inputManager.addMapping("shoot", new MouseButtonTrigger(MouseInput.BUTTON_LEFT));
initCrossHairs();
platForm();
//light
DirectionalLight sun = new DirectionalLight();
sun.setColor(ColorRGBA.White);
sun.setDirection(new Vector3f(-.5f,-.5f,-.5f).normalizeLocal());
rootNode.addLight(sun);
}
public void platForm(){
this.rootNode.attachChild(floor);
floor_phy = new RigidBodyControl(0.0f);
floor.addControl(floor_phy);
bulletAppState.getPhysicsSpace().add(floor_phy);
}
private ActionListener actionListener = new ActionListener() {
public void onAction(String name, boolean keyPressed, float tpf) {
if (name.equals("shoot") && !keyPressed) {
throwDice();
}
}
};
public void throwDice(){
this.rootNode.attachChild(dice);
dice.setLocalTranslation(cam.getLocation());
dice_phy = new RigidBodyControl(1f);
dice.addControl(dice_phy);
bulletAppState.getPhysicsSpace().add(dice_phy);
dice_phy.setLinearVelocity(cam.getDirection().mult(25));
}
protected void initCrossHairs() {
guiNode.detachAllChildren();
guiFont = assetManager.loadFont("Interface/Fonts/Default.fnt");
BitmapText ch = new BitmapText(guiFont, false);
ch.setSize(guiFont.getCharSet().getRenderedSize() * 2);
ch.setText("+");
ch.setLocalTranslation(
settings.getWidth() / 2 - guiFont.getCharSet().getRenderedSize() / 3 * 2,
settings.getHeight() / 2 + ch.getLineHeight() / 2, 0);
guiNode.attachChild(ch);
}
}
`