Search in sources :

Example 36 with BitmapText

use of com.jme3.font.BitmapText in project jmonkeyengine by jMonkeyEngine.

the class TestPhysicsRayCast method initCrossHair.

private void initCrossHair() {
    BitmapText bitmapText = new BitmapText(guiFont);
    bitmapText.setText("+");
    bitmapText.setLocalTranslation((settings.getWidth() - bitmapText.getLineWidth()) * 0.5f, (settings.getHeight() + bitmapText.getLineHeight()) * 0.5f, 0);
    guiNode.attachChild(bitmapText);
}
Also used : BitmapText(com.jme3.font.BitmapText)

Example 37 with BitmapText

use of com.jme3.font.BitmapText in project jmonkeyengine by jMonkeyEngine.

the class TestManyLightsSingle method simpleInitApp.

@Override
public void simpleInitApp() {
    renderManager.setPreferredLightMode(lm);
    renderManager.setSinglePassLightBatchSize(6);
    flyCam.setMoveSpeed(10);
    Node scene = (Node) assetManager.loadModel("Scenes/ManyLights/Main.scene");
    rootNode.attachChild(scene);
    Node n = (Node) rootNode.getChild(0);
    final LightList lightList = n.getWorldLightList();
    final Geometry g = (Geometry) n.getChild("Grid-geom-1");
    g.getMaterial().setColor("Ambient", new ColorRGBA(0.2f, 0.2f, 0.2f, 1f));
    /* A colored lit cube. Needs light source! */
    Box boxMesh = new Box(1f, 1f, 1f);
    final Geometry boxGeo = new Geometry("Colored Box", boxMesh);
    Material boxMat = g.getMaterial().clone();
    boxMat.clearParam("DiffuseMap");
    boxMat.setBoolean("UseMaterialColors", true);
    boxMat.setColor("Ambient", new ColorRGBA(0.2f, 0.2f, 0.2f, 1f));
    boxMat.setColor("Diffuse", ColorRGBA.Blue);
    boxGeo.setMaterial(boxMat);
    final Node cubeNodes = new Node();
    n.attachChild(cubeNodes);
    int nb = 0;
    for (Light light : lightList) {
        nb++;
        PointLight p = (PointLight) light;
        if (nb > 60) {
            n.removeLight(light);
        } else {
            LightNode ln = new LightNode("l", light);
            n.attachChild(ln);
            ln.setLocalTranslation(p.getPosition());
            int rand = FastMath.nextRandomInt(0, 3);
            switch(rand) {
                case 0:
                    light.setColor(ColorRGBA.Red);
                    //   ln.addControl(new MoveControl(5f));
                    break;
                case 1:
                    light.setColor(ColorRGBA.Yellow);
                    //    ln.addControl(new MoveControl(5f));
                    break;
                case 2:
                    light.setColor(ColorRGBA.Green);
                    //ln.addControl(new MoveControl(-5f));
                    break;
                case 3:
                    light.setColor(ColorRGBA.Orange);
                    //ln.addControl(new MoveControl(-5f));
                    break;
            }
        }
        Geometry b = boxGeo.clone(false);
        cubeNodes.attachChild(b);
        b.setLocalTranslation(p.getPosition().x, 2, p.getPosition().z);
    }
    //        cam.setLocation(new Vector3f(3.1893547f, 17.977385f, 30.8378f));
    //        cam.setRotation(new Quaternion(0.14317635f, 0.82302624f, -0.23777823f, 0.49557027f));
    cam.setLocation(new Vector3f(-1.8901939f, 29.34097f, 73.07533f));
    cam.setRotation(new Quaternion(0.0021000702f, 0.971012f, -0.23886925f, 0.008527749f));
    BasicProfilerState profiler = new BasicProfilerState(true);
    profiler.setGraphScale(1000f);
    //  getStateManager().attach(profiler);
    //        guiNode.setCullHint(CullHint.Always);
    flyCam.setDragToRotate(true);
    flyCam.setMoveSpeed(50);
    final MaterialDebugAppState debug = new MaterialDebugAppState();
    stateManager.attach(debug);
    inputManager.addListener(new ActionListener() {

        public void onAction(String name, boolean isPressed, float tpf) {
            if (name.equals("toggle") && isPressed) {
                if (lm == TechniqueDef.LightMode.SinglePass) {
                    lm = TechniqueDef.LightMode.MultiPass;
                    helloText.setText("(Multi pass)");
                } else {
                    lm = TechniqueDef.LightMode.SinglePass;
                    helloText.setText("(Single pass) nb lights per batch : " + renderManager.getSinglePassLightBatchSize());
                }
                renderManager.setPreferredLightMode(lm);
                reloadScene(g, boxGeo, cubeNodes);
            }
            if (name.equals("lightsUp") && isPressed) {
                renderManager.setSinglePassLightBatchSize(renderManager.getSinglePassLightBatchSize() + 1);
                helloText.setText("(Single pass) nb lights per batch : " + renderManager.getSinglePassLightBatchSize());
            }
            if (name.equals("lightsDown") && isPressed) {
                renderManager.setSinglePassLightBatchSize(renderManager.getSinglePassLightBatchSize() - 1);
                helloText.setText("(Single pass) nb lights per batch : " + renderManager.getSinglePassLightBatchSize());
            }
            if (name.equals("toggleOnOff") && isPressed) {
                for (final Light light : lightList) {
                    if (light instanceof AmbientLight) {
                        continue;
                    }
                    light.setEnabled(!light.isEnabled());
                }
            }
        }
    }, "toggle", "lightsUp", "lightsDown", "toggleOnOff");
    inputManager.addMapping("toggle", new KeyTrigger(KeyInput.KEY_SPACE));
    inputManager.addMapping("lightsUp", new KeyTrigger(KeyInput.KEY_UP));
    inputManager.addMapping("lightsDown", new KeyTrigger(KeyInput.KEY_DOWN));
    inputManager.addMapping("toggleOnOff", new KeyTrigger(KeyInput.KEY_L));
    SpotLight spot = new SpotLight();
    spot.setDirection(new Vector3f(-1f, -1f, -1f).normalizeLocal());
    spot.setColor(ColorRGBA.Blue.mult(5));
    spot.setSpotOuterAngle(FastMath.DEG_TO_RAD * 20);
    spot.setSpotInnerAngle(FastMath.DEG_TO_RAD * 5);
    spot.setPosition(new Vector3f(10, 10, 20));
    rootNode.addLight(spot);
    DirectionalLight dl = new DirectionalLight();
    dl.setDirection(new Vector3f(-1, -1, 1));
    rootNode.addLight(dl);
    AmbientLight al = new AmbientLight();
    al.setColor(new ColorRGBA(0.2f, 0.2f, 0.2f, 1f));
    rootNode.addLight(al);
    /**
         * Write text on the screen (HUD)
         */
    guiNode.detachAllChildren();
    guiFont = assetManager.loadFont("Interface/Fonts/Default.fnt");
    helloText = new BitmapText(guiFont, false);
    helloText.setSize(guiFont.getCharSet().getRenderedSize());
    helloText.setText("(Single pass) nb lights per batch : " + renderManager.getSinglePassLightBatchSize());
    helloText.setLocalTranslation(300, helloText.getLineHeight(), 0);
    guiNode.attachChild(helloText);
}
Also used : Quaternion(com.jme3.math.Quaternion) MaterialDebugAppState(com.jme3.util.MaterialDebugAppState) LightNode(com.jme3.scene.LightNode) Node(com.jme3.scene.Node) KeyTrigger(com.jme3.input.controls.KeyTrigger) Box(com.jme3.scene.shape.Box) Material(com.jme3.material.Material) SpotLight(com.jme3.light.SpotLight) BasicProfilerState(com.jme3.app.BasicProfilerState) Geometry(com.jme3.scene.Geometry) ColorRGBA(com.jme3.math.ColorRGBA) ActionListener(com.jme3.input.controls.ActionListener) BitmapText(com.jme3.font.BitmapText) LightNode(com.jme3.scene.LightNode) DirectionalLight(com.jme3.light.DirectionalLight) SpotLight(com.jme3.light.SpotLight) PointLight(com.jme3.light.PointLight) Light(com.jme3.light.Light) AmbientLight(com.jme3.light.AmbientLight) Vector3f(com.jme3.math.Vector3f) DirectionalLight(com.jme3.light.DirectionalLight) LightList(com.jme3.light.LightList) PointLight(com.jme3.light.PointLight) AmbientLight(com.jme3.light.AmbientLight)

Example 38 with BitmapText

use of com.jme3.font.BitmapText in project jmonkeyengine by jMonkeyEngine.

the class TestTangentGenBadModels method simpleInitApp.

@Override
public void simpleInitApp() {
    //        assetManager.registerLocator("http://jme-glsl-shaders.googlecode.com/hg/assets/Models/LightBlow/", UrlLocator.class);
    //        assetManager.registerLocator("http://jmonkeyengine.googlecode.com/files/", UrlLocator.class);
    final Spatial badModel = assetManager.loadModel("Models/TangentBugs/test.blend");
    //        badModel.setLocalScale(1f);
    Material mat = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md");
    mat.setTexture("NormalMap", assetManager.loadTexture("Models/TangentBugs/test_normal.png"));
    //        Material mat = assetManager.loadMaterial("Textures/BumpMapTest/Tangent.j3m");
    badModel.setMaterial(mat);
    rootNode.attachChild(badModel);
    // TODO: For some reason blender loader fails to load this.
    // need to check it
    //        Spatial model = assetManager.loadModel("test.blend");
    //        rootNode.attachChild(model);
    final Node debugTangents = new Node("debug tangents");
    debugTangents.setCullHint(CullHint.Always);
    rootNode.attachChild(debugTangents);
    final Material debugMat = assetManager.loadMaterial("Common/Materials/VertexColor.j3m");
    badModel.depthFirstTraversal(new SceneGraphVisitorAdapter() {

        @Override
        public void visit(Geometry g) {
            Mesh m = g.getMesh();
            Material mat = g.getMaterial();
            //                if (mat.getParam("DiffuseMap") != null){
            //                    mat.setTexture("DiffuseMap", null);
            //                }
            TangentBinormalGenerator.generate(m);
            Geometry debug = new Geometry("debug tangents geom", TangentBinormalGenerator.genTbnLines(g.getMesh(), 0.2f));
            debug.setMaterial(debugMat);
            debug.setCullHint(Spatial.CullHint.Never);
            debug.setLocalTransform(g.getWorldTransform());
            debugTangents.attachChild(debug);
        }
    });
    DirectionalLight dl = new DirectionalLight();
    dl.setDirection(new Vector3f(-0.8f, -0.6f, -0.08f).normalizeLocal());
    dl.setColor(new ColorRGBA(1, 1, 1, 1));
    rootNode.addLight(dl);
    lightMdl = new Geometry("Light", new Sphere(10, 10, 0.1f));
    lightMdl.setMaterial(assetManager.loadMaterial("Common/Materials/RedColor.j3m"));
    lightMdl.getMesh().setStatic();
    rootNode.attachChild(lightMdl);
    pl = new PointLight();
    pl.setColor(ColorRGBA.White);
    //        rootNode.addLight(pl);
    BitmapText info = new BitmapText(guiFont);
    info.setText("Press SPACE to switch between lighting and tangent display");
    info.setQueueBucket(Bucket.Gui);
    info.move(0, settings.getHeight() - info.getLineHeight(), 0);
    rootNode.attachChild(info);
    inputManager.addMapping("space", new KeyTrigger(KeyInput.KEY_SPACE));
    inputManager.addListener(new ActionListener() {

        private boolean isLit = true;

        public void onAction(String name, boolean isPressed, float tpf) {
            if (isPressed)
                return;
            Material mat;
            if (isLit) {
                mat = assetManager.loadMaterial("Textures/BumpMapTest/Tangent.j3m");
                debugTangents.setCullHint(CullHint.Inherit);
            } else {
                mat = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md");
                mat.setTexture("NormalMap", assetManager.loadTexture("Models/TangentBugs/test_normal.png"));
                debugTangents.setCullHint(CullHint.Always);
            }
            isLit = !isLit;
            badModel.setMaterial(mat);
        }
    }, "space");
}
Also used : KeyTrigger(com.jme3.input.controls.KeyTrigger) Material(com.jme3.material.Material) Sphere(com.jme3.scene.shape.Sphere) ColorRGBA(com.jme3.math.ColorRGBA) BitmapText(com.jme3.font.BitmapText) ActionListener(com.jme3.input.controls.ActionListener) DirectionalLight(com.jme3.light.DirectionalLight) Vector3f(com.jme3.math.Vector3f) PointLight(com.jme3.light.PointLight)

Example 39 with BitmapText

use of com.jme3.font.BitmapText in project jmonkeyengine by jMonkeyEngine.

the class TestJoystick method addInfo.

protected void addInfo(String info, int column) {
    BitmapText t = new BitmapText(guiFont);
    t.setText(info);
    t.setLocalTranslation(column * 200, yInfo, 0);
    joystickInfo.attachChild(t);
    yInfo -= t.getHeight();
}
Also used : BitmapText(com.jme3.font.BitmapText)

Example 40 with BitmapText

use of com.jme3.font.BitmapText in project jmonkeyengine by jMonkeyEngine.

the class HelloPicking method initCrossHairs.

/** A centred plus sign to help the player aim. */
protected void initCrossHairs() {
    setDisplayStatView(false);
    guiFont = assetManager.loadFont("Interface/Fonts/Default.fnt");
    BitmapText ch = new BitmapText(guiFont, false);
    ch.setSize(guiFont.getCharSet().getRenderedSize() * 2);
    // crosshairs
    ch.setText("+");
    // center
    ch.setLocalTranslation(settings.getWidth() / 2 - ch.getLineWidth() / 2, settings.getHeight() / 2 + ch.getLineHeight() / 2, 0);
    guiNode.attachChild(ch);
}
Also used : BitmapText(com.jme3.font.BitmapText)

Aggregations

BitmapText (com.jme3.font.BitmapText)52 Vector3f (com.jme3.math.Vector3f)10 Geometry (com.jme3.scene.Geometry)9 KeyTrigger (com.jme3.input.controls.KeyTrigger)8 Material (com.jme3.material.Material)8 BitmapFont (com.jme3.font.BitmapFont)7 DirectionalLight (com.jme3.light.DirectionalLight)5 ColorRGBA (com.jme3.math.ColorRGBA)5 Spatial (com.jme3.scene.Spatial)5 Rectangle (com.jme3.font.Rectangle)4 ChaseCamera (com.jme3.input.ChaseCamera)4 Quaternion (com.jme3.math.Quaternion)4 Node (com.jme3.scene.Node)4 Box (com.jme3.scene.shape.Box)4 Quad (com.jme3.scene.shape.Quad)4 ActionListener (com.jme3.input.controls.ActionListener)3 Wire (com.cas.circuit.vo.Wire)2 MotionPath (com.jme3.cinematic.MotionPath)2 MotionPathListener (com.jme3.cinematic.MotionPathListener)2 MotionEvent (com.jme3.cinematic.events.MotionEvent)2