Search in sources :

Example 66 with AssetManager

use of com.jme3.asset.AssetManager in project jmonkeyengine by jMonkeyEngine.

the class TestTangentSpace method simpleInitApp.

@Override
public void simpleInitApp() {
    renderManager.setSinglePassLightBatchSize(2);
    renderManager.setPreferredLightMode(TechniqueDef.LightMode.SinglePass);
    initView();
    Spatial s = assetManager.loadModel("Models/Test/BasicCubeLow.obj");
    rootNode.attachChild(s);
    Material m = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md");
    m.setTexture("NormalMap", assetManager.loadTexture("Models/Test/Normal_pixel.png"));
    Geometry g = (Geometry) s;
    Geometry g2 = (Geometry) g.deepClone();
    g2.move(5, 0, 0);
    g.getParent().attachChild(g2);
    g.setMaterial(m);
    g2.setMaterial(m);
    //Regular tangent generation (left geom)
    TangentBinormalGenerator.generate(g2.getMesh(), true);
    //MikkTSPace Tangent generation (right geom)        
    MikktspaceTangentGenerator.generate(g);
    createDebugTangents(g2);
    createDebugTangents(g);
    inputManager.addListener(new ActionListener() {

        @Override
        public void onAction(String name, boolean isPressed, float tpf) {
            if (name.equals("toggleDebug") && isPressed) {
                if (debugNode.getParent() == null) {
                    rootNode.attachChild(debugNode);
                } else {
                    debugNode.removeFromParent();
                }
            }
        }
    }, "toggleDebug");
    inputManager.addMapping("toggleDebug", new KeyTrigger(KeyInput.KEY_SPACE));
    DirectionalLight dl = new DirectionalLight(new Vector3f(-1, -1, -1).normalizeLocal());
    rootNode.addLight(dl);
}
Also used : Geometry(com.jme3.scene.Geometry) ActionListener(com.jme3.input.controls.ActionListener) Spatial(com.jme3.scene.Spatial) KeyTrigger(com.jme3.input.controls.KeyTrigger) DirectionalLight(com.jme3.light.DirectionalLight) Vector3f(com.jme3.math.Vector3f)

Example 67 with AssetManager

use of com.jme3.asset.AssetManager in project jmonkeyengine by jMonkeyEngine.

the class TestChaseCamera method simpleInitApp.

public void simpleInitApp() {
    // Load a teapot model
    teaGeom = (Geometry) assetManager.loadModel("Models/Teapot/Teapot.obj");
    Material mat_tea = new Material(assetManager, "Common/MatDefs/Misc/ShowNormals.j3md");
    teaGeom.setMaterial(mat_tea);
    rootNode.attachChild(teaGeom);
    // Load a floor model
    Material mat_ground = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    mat_ground.setTexture("ColorMap", assetManager.loadTexture("Interface/Logo/Monkey.jpg"));
    Geometry ground = new Geometry("ground", new Quad(50, 50));
    ground.setLocalRotation(new Quaternion().fromAngleAxis(-FastMath.HALF_PI, Vector3f.UNIT_X));
    ground.setLocalTranslation(-25, -1, 25);
    ground.setMaterial(mat_ground);
    rootNode.attachChild(ground);
    // Disable the default first-person cam!
    flyCam.setEnabled(false);
    // Enable a chase cam
    chaseCam = new ChaseCamera(cam, teaGeom, inputManager);
    //Uncomment this to invert the camera's vertical rotation Axis 
    //chaseCam.setInvertVerticalAxis(true);
    //Uncomment this to invert the camera's horizontal rotation Axis
    //chaseCam.setInvertHorizontalAxis(true);
    //Comment this to disable smooth camera motion
    chaseCam.setSmoothMotion(true);
    //Uncomment this to disable trailing of the camera 
    //WARNING, trailing only works with smooth motion enabled. It is true by default.
    //chaseCam.setTrailingEnabled(false);
    //Uncomment this to look 3 world units above the target
    //chaseCam.setLookAtOffset(Vector3f.UNIT_Y.mult(3));
    //Uncomment this to enable rotation when the middle mouse button is pressed (like Blender)
    //WARNING : setting this trigger disable the rotation on right and left mouse button click
    //chaseCam.setToggleRotationTrigger(new MouseButtonTrigger(MouseInput.BUTTON_MIDDLE));
    //Uncomment this to set mutiple triggers to enable rotation of the cam
    //Here spade bar and middle mouse button
    //chaseCam.setToggleRotationTrigger(new MouseButtonTrigger(MouseInput.BUTTON_MIDDLE),new KeyTrigger(KeyInput.KEY_SPACE));
    //registering inputs for target's movement
    registerInput();
}
Also used : Geometry(com.jme3.scene.Geometry) Quad(com.jme3.scene.shape.Quad) Quaternion(com.jme3.math.Quaternion) ChaseCamera(com.jme3.input.ChaseCamera) Material(com.jme3.material.Material)

Example 68 with AssetManager

use of com.jme3.asset.AssetManager in project jmonkeyengine by jMonkeyEngine.

the class RefEnv method simpleUpdate.

@Override
public void simpleUpdate(float tpf) {
    frame++;
    if (frame == 2) {
        final LightProbe probe = LightProbeFactory.makeProbe(stateManager.getState(EnvironmentCamera.class), rootNode, new JobProgressAdapter<LightProbe>() {

            @Override
            public void done(LightProbe result) {
                System.err.println("Done rendering env maps");
                tex = EnvMapUtils.getCubeMapCrossDebugViewWithMipMaps(result.getPrefilteredEnvMap(), assetManager);
                //  guiNode.attachChild(tex);
                rootNode.getChild("Scene").setCullHint(Spatial.CullHint.Dynamic);
            }
        });
        ((BoundingSphere) probe.getBounds()).setRadius(100);
        rootNode.addLight(probe);
    }
}
Also used : BoundingSphere(com.jme3.bounding.BoundingSphere) LightProbe(com.jme3.light.LightProbe) EnvironmentCamera(com.jme3.environment.EnvironmentCamera)

Example 69 with AssetManager

use of com.jme3.asset.AssetManager in project jmonkeyengine by jMonkeyEngine.

the class TestPBRLighting method simpleUpdate.

@Override
public void simpleUpdate(float tpf) {
    frame++;
    if (frame == 2) {
        modelNode.removeFromParent();
        final LightProbe probe = LightProbeFactory.makeProbe(stateManager.getState(EnvironmentCamera.class), rootNode, new JobProgressAdapter<LightProbe>() {

            @Override
            public void done(LightProbe result) {
                System.err.println("Done rendering env maps");
                tex = EnvMapUtils.getCubeMapCrossDebugViewWithMipMaps(result.getPrefilteredEnvMap(), assetManager);
                tex2 = EnvMapUtils.getCubeMapCrossDebugView(result.getIrradianceMap(), assetManager);
            }
        });
        ((BoundingSphere) probe.getBounds()).setRadius(100);
        rootNode.addLight(probe);
    //getStateManager().getState(EnvironmentManager.class).addEnvProbe(probe);
    }
    if (frame > 10 && modelNode.getParent() == null) {
        rootNode.attachChild(modelNode);
    }
}
Also used : BoundingSphere(com.jme3.bounding.BoundingSphere) LightProbe(com.jme3.light.LightProbe) EnvironmentCamera(com.jme3.environment.EnvironmentCamera)

Example 70 with AssetManager

use of com.jme3.asset.AssetManager in project jmonkeyengine by jMonkeyEngine.

the class AssetLinkNode method attachLinkedChildren.

/**
     * Loads the linked children AssetKeys from the AssetManager and attaches them to the Node<br>
     * If they are already attached, they will be reloaded.
     * @param manager
     */
public void attachLinkedChildren(AssetManager manager) {
    detachLinkedChildren();
    for (Iterator<ModelKey> it = assetLoaderKeys.iterator(); it.hasNext(); ) {
        ModelKey assetKey = it.next();
        Spatial curChild = assetChildren.get(assetKey);
        if (curChild != null) {
            curChild.removeFromParent();
        }
        Spatial child = manager.loadAsset(assetKey);
        attachChild(child);
        assetChildren.put(assetKey, child);
    }
}
Also used : ModelKey(com.jme3.asset.ModelKey)

Aggregations

Material (com.jme3.material.Material)213 Geometry (com.jme3.scene.Geometry)138 Vector3f (com.jme3.math.Vector3f)137 Box (com.jme3.scene.shape.Box)73 Texture (com.jme3.texture.Texture)73 DirectionalLight (com.jme3.light.DirectionalLight)66 Node (com.jme3.scene.Node)52 Sphere (com.jme3.scene.shape.Sphere)47 Quaternion (com.jme3.math.Quaternion)46 Spatial (com.jme3.scene.Spatial)43 FilterPostProcessor (com.jme3.post.FilterPostProcessor)38 ColorRGBA (com.jme3.math.ColorRGBA)37 KeyTrigger (com.jme3.input.controls.KeyTrigger)31 RigidBodyControl (com.jme3.bullet.control.RigidBodyControl)27 BulletAppState (com.jme3.bullet.BulletAppState)26 Quad (com.jme3.scene.shape.Quad)23 TextureKey (com.jme3.asset.TextureKey)22 ActionListener (com.jme3.input.controls.ActionListener)21 AmbientLight (com.jme3.light.AmbientLight)20 Texture2D (com.jme3.texture.Texture2D)20