com.jme3.light.DirectionalLight Java Examples

The following examples show how to use com.jme3.light.DirectionalLight. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: BaseMaterialEditor3DPart.java    From jmonkeybuilder with Apache License 2.0 6 votes vote down vote up
/**
 * Update the light in the scene in the {@link EditorThread}.
 *
 * @param enabled true if light should be enabled.
 */
@JmeThread
protected void updateLightEnabledImpl(final boolean enabled) {
    if (enabled == isLightEnabled()) return;

    final DirectionalLight light = getLightForCamera();
    final Node stateNode = getStateNode();

    if (enabled) {
        stateNode.addLight(light);
    } else {
        stateNode.removeLight(light);
    }

    setLightEnabled(enabled);
}
 
Example #2
Source File: TestBumpModel.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Override
public void simpleInitApp() {
    Spatial signpost = (Spatial) assetManager.loadAsset(new OgreMeshKey("Models/Sign Post/Sign Post.mesh.xml"));
    signpost.setMaterial( (Material) assetManager.loadMaterial("Models/Sign Post/Sign Post.j3m"));
    TangentBinormalGenerator.generate(signpost);
    rootNode.attachChild(signpost);

    lightMdl = new Geometry("Light", new Sphere(10, 10, 0.1f));
    lightMdl.setMaterial( (Material) assetManager.loadMaterial("Common/Materials/RedColor.j3m"));
    rootNode.attachChild(lightMdl);

    // flourescent main light
    pl = new PointLight();
    pl.setColor(new ColorRGBA(0.88f, 0.92f, 0.95f, 1.0f));
    rootNode.addLight(pl);
    
    AmbientLight al = new AmbientLight();
    al.setColor(new ColorRGBA(0.44f, 0.40f, 0.20f, 1.0f));
    rootNode.addLight(al);
    
    DirectionalLight dl = new DirectionalLight();
    dl.setDirection(new Vector3f(1,-1,-1).normalizeLocal());
    dl.setColor(new ColorRGBA(0.92f, 0.85f, 0.8f, 1.0f));
    rootNode.addLight(dl);
}
 
Example #3
Source File: BaseMaterialEditor3DPart.java    From jmonkeybuilder with Apache License 2.0 6 votes vote down vote up
public BaseMaterialEditor3DPart(@NotNull final T fileEditor) {
    super(fileEditor);
    this.testBox = new Geometry("Box", new Box(2, 2, 2));
    this.testSphere = new Geometry("Sphere", new Sphere(30, 30, 2));
    this.testQuad = new Geometry("Quad", new Quad(4, 4));
    this.testQuad.setLocalTranslation(QUAD_OFFSET);
    this.lightEnabled = MaterialFileEditor.DEFAULT_LIGHT_ENABLED;

    TangentGenerator.useMikktspaceGenerator(testBox);
    TangentGenerator.useMikktspaceGenerator(testSphere);
    TangentGenerator.useMikktspaceGenerator(testQuad);

    final DirectionalLight light = notNull(getLightForCamera());
    light.setDirection(LIGHT_DIRECTION);

    final EditorCamera editorCamera = notNull(getEditorCamera());
    editorCamera.setDefaultHorizontalRotation(H_ROTATION);
    editorCamera.setDefaultVerticalRotation(V_ROTATION);

    getModelNode().attachChild(getNodeForCamera());
}
 
Example #4
Source File: TestIssue1340.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public void simpleInitApp() {
    stateManager.attach(new EnvironmentCamera(32));

    DirectionalLight light = new DirectionalLight(Vector3f.UNIT_Y.negate(), ColorRGBA.White);
    rootNode.addLight(light);

    assetManager.registerLocator("https://github.com/KhronosGroup/glTF-Sample-Models/raw/master/2.0/RiggedFigure/", UrlLocator.class);

    model = assetManager.loadModel("/glTF-Embedded/RiggedFigure.gltf");
    SkinningControl skinningControl = getSkinningControl(model);
    if (skinningControl == null || !skinningControl.isHardwareSkinningPreferred()) {
        throw new IllegalArgumentException("This test case requires a model with a SkinningControl and with Hardware skinning preferred!");
    }

    viewPort.setBackgroundColor(ColorRGBA.LightGray);
}
 
Example #5
Source File: ModelEditor3DPart.java    From jmonkeybuilder with Apache License 2.0 6 votes vote down vote up
/**
 * The process of updating the light.
 */
@JmeThread
private void updateLightEnabledImpl(boolean enabled) {

    if (enabled == isLightEnabled()) {
        return;
    }

    final DirectionalLight light = getLightForCamera();
    final Node stateNode = getStateNode();

    if (enabled) {
        stateNode.addLight(light);
    } else {
        stateNode.removeLight(light);
    }

    setLightEnabled(enabled);
}
 
Example #6
Source File: TestTangentGen.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Override
public void simpleInitApp() {
    flyCam.setMoveSpeed(20);
    Sphere sphereMesh = new Sphere(32, 32, 1);
    sphereMesh.setTextureMode(Sphere.TextureMode.Projected);
    sphereMesh.updateGeometry(32, 32, 1, false, false);
    addMesh("Sphere", sphereMesh, new Vector3f(-1, 0, 0));

    Quad quadMesh = new Quad(1, 1);
    quadMesh.updateGeometry(1, 1);
    addMesh("Quad", quadMesh, new Vector3f(1, 0, 0));

    Mesh strip = createTriangleStripMesh();
    addMesh("strip", strip, new Vector3f(0, -3, 0));
    
    DirectionalLight dl = new DirectionalLight();
    dl.setDirection(new Vector3f(1, -1, -1).normalizeLocal());
    dl.setColor(ColorRGBA.White);
    rootNode.addLight(dl);
}
 
Example #7
Source File: LightControl.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private void spatialToLight(Light light) {

        final Vector3f worldTranslation = spatial.getWorldTranslation();

        if (light instanceof PointLight) {
            ((PointLight) light).setPosition(worldTranslation);
            return;
        }

        final TempVars vars = TempVars.get();
        final Vector3f vec = vars.vect1;

        if (light instanceof DirectionalLight) {
            ((DirectionalLight) light).setDirection(vec.set(worldTranslation).multLocal(-1.0f));
        }

        if (light instanceof SpotLight) {
            final SpotLight spotLight = (SpotLight) light;
            spotLight.setPosition(worldTranslation);
            spotLight.setDirection(spatial.getWorldRotation().multLocal(vec.set(Vector3f.UNIT_Y).multLocal(-1)));
        }

        vars.release();
    }
 
Example #8
Source File: TestBlenderAnim.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Override
public void simpleInitApp() {
    flyCam.setMoveSpeed(10f);
    cam.setLocation(new Vector3f(6.4013605f, 7.488437f, 12.843031f));
    cam.setRotation(new Quaternion(-0.060740203f, 0.93925786f, -0.2398315f, -0.2378785f));

    DirectionalLight dl = new DirectionalLight();
    dl.setDirection(new Vector3f(-0.1f, -0.7f, -1).normalizeLocal());
    dl.setColor(new ColorRGBA(1f, 1f, 1f, 1.0f));
    rootNode.addLight(dl);

    BlenderKey blenderKey = new BlenderKey("Blender/2.4x/BaseMesh_249.blend");
    
    Spatial scene = (Spatial) assetManager.loadModel(blenderKey);
    rootNode.attachChild(scene);
    
    Spatial model = this.findNode(rootNode, "BaseMesh_01");
    model.center();
    
    control = model.getControl(AnimControl.class);
    channel = control.createChannel();

    channel.setAnim("run_01");
}
 
Example #9
Source File: ArmatureDebugAppState.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
protected void initialize(Application app) {
    vp = app.getRenderManager().createMainView("debug", app.getCamera());
    vp.attachScene(debugNode);
    vp.setClearDepth(true);
    this.app = app;
    for (ArmatureDebugger armatureDebugger : armatures.values()) {
        armatureDebugger.initialize(app.getAssetManager(), app.getCamera());
    }
    app.getInputManager().addListener(actionListener, "shoot", "toggleJoints");
    app.getInputManager().addMapping("shoot", new MouseButtonTrigger(MouseInput.BUTTON_LEFT), new MouseButtonTrigger(MouseInput.BUTTON_RIGHT));
    app.getInputManager().addMapping("toggleJoints", new KeyTrigger(KeyInput.KEY_F10));

    debugNode.addLight(new DirectionalLight(new Vector3f(-1f, -1f, -1f).normalizeLocal()));

    debugNode.addLight(new DirectionalLight(new Vector3f(1f, 1f, 1f).normalizeLocal(), new ColorRGBA(0.5f, 0.5f, 0.5f, 1.0f)));
    vp.setEnabled(false);
}
 
Example #10
Source File: TestFog.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void simpleInitApp() {
    this.flyCam.setMoveSpeed(50);
    Node mainScene=new Node();
    cam.setLocation(new Vector3f(-34.74095f, 95.21318f, -287.4945f));
    cam.setRotation(new Quaternion(0.023536969f, 0.9361278f, -0.016098259f, -0.35050195f));

    // load sky
    mainScene.attachChild(SkyFactory.createSky(assetManager, 
            "Textures/Sky/Bright/BrightSky.dds", 
            SkyFactory.EnvMapType.CubeMap));
    createTerrain(mainScene);



    DirectionalLight sun = new DirectionalLight();
    Vector3f lightDir=new Vector3f(-0.37352666f, -0.50444174f, -0.7784704f);
    sun.setDirection(lightDir);
    sun.setColor(ColorRGBA.White.clone().multLocal(2));
    mainScene.addLight(sun);

    rootNode.attachChild(mainScene);

    fpp=new FilterPostProcessor(assetManager);
    //fpp.setNumSamples(4);
    int numSamples = getContext().getSettings().getSamples();
    if( numSamples > 0 ) {
        fpp.setNumSamples(numSamples); 
    }
    fog=new FogFilter();
    fog.setFogColor(new ColorRGBA(0.9f, 0.9f, 0.9f, 1.0f));
    fog.setFogDistance(155);
    fog.setFogDensity(1.0f);
    fpp.addFilter(fog);
    viewPort.addProcessor(fpp);
    initInputs();
}
 
Example #11
Source File: TestSceneLoading.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public void simpleInitApp() {
    this.flyCam.setMoveSpeed(10);

    // load sky
    rootNode.attachChild(SkyFactory.createSky(assetManager, "Textures/Sky/Bright/BrightSky.dds", false));

    File file = new File("wildhouse.zip");
    if (!file.exists()) {
        useHttp = true;
    }
    // create the geometry and attach it
    // load the level from zip or http zip
    if (useHttp) {
        assetManager.registerLocator("http://jmonkeyengine.googlecode.com/files/wildhouse.zip", HttpZipLocator.class.getName());
    } else {
        assetManager.registerLocator("wildhouse.zip", ZipLocator.class.getName());
    }
    Spatial scene = assetManager.loadModel("main.scene");

    AmbientLight al = new AmbientLight();
    scene.addLight(al);

    DirectionalLight sun = new DirectionalLight();
    sun.setDirection(new Vector3f(0.69077975f, -0.6277887f, -0.35875428f).normalizeLocal());
    sun.setColor(ColorRGBA.White.clone().multLocal(2));
    scene.addLight(sun);

    rootNode.attachChild(scene);
}
 
Example #12
Source File: TestMousePick.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
protected Spatial makeCharacter() {
    // load a character from jme3test-test-data
    Spatial golem = assetManager.loadModel("Models/Oto/Oto.mesh.xml");
    golem.scale(0.5f);
    golem.setLocalTranslation(-1.0f, -1.5f, -0.6f);

    // We must add a light to make the model visible
    DirectionalLight sun = new DirectionalLight();
    sun.setDirection(new Vector3f(-0.1f, -0.7f, -1.0f).normalizeLocal());
    golem.addLight(sun);
    return golem;
}
 
Example #13
Source File: TerrainTestModifyHeight.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public void simpleInitApp() {
    loadHintText();
    initCrossHairs();
    setupKeys();
    
    createMarker();

    // WIREFRAME material
    matWire = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    matWire.getAdditionalRenderState().setWireframe(true);
    matWire.setColor("Color", ColorRGBA.Green);
    
    createTerrain();
    //createTerrainGrid();
    
    DirectionalLight light = new DirectionalLight();
    light.setDirection((new Vector3f(-0.5f, -1f, -0.5f)).normalize());
    rootNode.addLight(light);

    AmbientLight ambLight = new AmbientLight();
    ambLight.setColor(new ColorRGBA(1f, 1f, 0.8f, 0.2f));
    rootNode.addLight(ambLight);

    cam.setLocation(new Vector3f(0, 256, 0));
    cam.lookAtDirection(new Vector3f(0, -1f, 0).normalizeLocal(), Vector3f.UNIT_X);
}
 
Example #14
Source File: HelloCollision.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private void setUpLight() {
  // We add light so we see the scene
  AmbientLight al = new AmbientLight();
  al.setColor(ColorRGBA.White.mult(1.3f));
  rootNode.addLight(al);

  DirectionalLight dl = new DirectionalLight();
  dl.setColor(ColorRGBA.White);
  dl.setDirection(new Vector3f(2.8f, -2.8f, -2.8f).normalizeLocal());
  rootNode.addLight(dl);
}
 
Example #15
Source File: DirectionalLightShadowRendererVR.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void read(JmeImporter im) throws IOException {
    super.read(im);
    InputCapsule ic = im.getCapsule(this);
    lambda = ic.readFloat("lambda", 0.65f);
    zFarOverride = ic.readInt("zFarOverride", 0);
    light = (DirectionalLight) ic.readSavable("light", null);
    fadeInfo = (Vector2f) ic.readSavable("fadeInfo", null);
    fadeLength = ic.readFloat("fadeLength", 0f);
    init(nbShadowMaps, (int) shadowMapSize);
}
 
Example #16
Source File: WaterFilter.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private DirectionalLight findLight(Node node) {
    for (Light light : node.getWorldLightList()) {
        if (light instanceof DirectionalLight) {
            return (DirectionalLight) light;
        }
    }
    for (Spatial child : node.getChildren()) {
        if (child instanceof Node) {
            return findLight((Node) child);
        }
    }

    return null;
}
 
Example #17
Source File: TestWalkingChar.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private void createLight() {
    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);
}
 
Example #18
Source File: TestTriangleCollision.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void simpleInitApp() {
    // Create two boxes
    Mesh mesh1 = new Box(0.5f, 0.5f, 0.5f);
    geom1 = new Geometry("Box", mesh1);
    geom1.move(2, 2, -.5f);
    Material m1 = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    m1.setColor("Color", ColorRGBA.Blue);
    geom1.setMaterial(m1);
    rootNode.attachChild(geom1);

    // load a character from jme3test-test-data
    golem = assetManager.loadModel("Models/Oto/Oto.mesh.xml");
    golem.scale(0.5f);
    golem.setLocalTranslation(-1.0f, -1.5f, -0.6f);

    // We must add a light to make the model visible
    DirectionalLight sun = new DirectionalLight();
    sun.setDirection(new Vector3f(-0.1f, -0.7f, -1.0f).normalizeLocal());
    golem.addLight(sun);
    rootNode.attachChild(golem);

    // Create input
    inputManager.addMapping("MoveRight", new KeyTrigger(KeyInput.KEY_L));
    inputManager.addMapping("MoveLeft", new KeyTrigger(KeyInput.KEY_J));
    inputManager.addMapping("MoveUp", new KeyTrigger(KeyInput.KEY_I));
    inputManager.addMapping("MoveDown", new KeyTrigger(KeyInput.KEY_K));

    inputManager.addListener(analogListener, new String[]{
                "MoveRight", "MoveLeft", "MoveUp", "MoveDown"
            });
}
 
Example #19
Source File: TestMousePick.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
protected Spatial makeCharacter() {
    // load a character from jme3test-test-data
    Spatial golem = assetManager.loadModel("Models/Oto/Oto.mesh.xml");
    golem.scale(0.5f);
    golem.setLocalTranslation(-1.0f, -1.5f, -0.6f);

    // We must add a light to make the model visible
    DirectionalLight sun = new DirectionalLight();
    sun.setDirection(new Vector3f(-0.1f, -0.7f, -1.0f).normalizeLocal());
    golem.addLight(sun);
    return golem;
}
 
Example #20
Source File: HelloPicking.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
protected Spatial makeCharacter() {
  // load a character from jme3test-test-data
  Spatial golem = assetManager.loadModel("Models/Oto/Oto.mesh.xml");
  golem.scale(0.5f);
  golem.setLocalTranslation(-1.0f, -1.5f, -0.6f);

  // We must add a light to make the model visible
  DirectionalLight sun = new DirectionalLight();
  sun.setDirection(new Vector3f(-0.1f, -0.7f, -1.0f));
  golem.addLight(sun);
  return golem;
}
 
Example #21
Source File: TestTriangleCollision.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public void simpleInitApp() {
    // Create two boxes
    Mesh mesh1 = new Box(0.5f, 0.5f, 0.5f);
    geom1 = new Geometry("Box", mesh1);
    geom1.move(2, 2, -.5f);
    Material m1 = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    m1.setColor("Color", ColorRGBA.Blue);
    geom1.setMaterial(m1);
    rootNode.attachChild(geom1);

    // load a character from jme3test-test-data
    golem = assetManager.loadModel("Models/Oto/Oto.mesh.xml");
    golem.scale(0.5f);
    golem.setLocalTranslation(-1.0f, -1.5f, -0.6f);

    // We must add a light to make the model visible
    DirectionalLight sun = new DirectionalLight();
    sun.setDirection(new Vector3f(-0.1f, -0.7f, -1.0f).normalizeLocal());
    golem.addLight(sun);
    rootNode.attachChild(golem);

    // Create input
    inputManager.addMapping("MoveRight", new KeyTrigger(KeyInput.KEY_L));
    inputManager.addMapping("MoveLeft", new KeyTrigger(KeyInput.KEY_J));
    inputManager.addMapping("MoveUp", new KeyTrigger(KeyInput.KEY_I));
    inputManager.addMapping("MoveDown", new KeyTrigger(KeyInput.KEY_K));

    inputManager.addListener(analogListener, new String[]{
                "MoveRight", "MoveLeft", "MoveUp", "MoveDown"
            });
}
 
Example #22
Source File: TestHWSkinningOld.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void simpleInitApp() {
    flyCam.setMoveSpeed(10f);
    flyCam.setDragToRotate(true);
    setPauseOnLostFocus(false);
    cam.setLocation(new Vector3f(24.746134f, 13.081396f, 32.72753f));
    cam.setRotation(new Quaternion(-0.06867662f, 0.92435044f, -0.19981281f, -0.31770203f));
    makeHudText();

    DirectionalLight dl = new DirectionalLight();
    dl.setDirection(new Vector3f(-0.1f, -0.7f, -1).normalizeLocal());
    dl.setColor(new ColorRGBA(1f, 1f, 1f, 1.0f));
    rootNode.addLight(dl);

    for (int i = 0; i < SIZE; i++) {
        for (int j = 0; j < SIZE; j++) {
            Spatial model = assetManager.loadModel("Models/Oto/OtoOldAnim.j3o");
            model.setLocalScale(0.1f);
            model.setLocalTranslation(i - SIZE / 2, 0, j - SIZE / 2);
            control = model.getControl(AnimControl.class);

            channel = control.createChannel();
            channel.setAnim(animNames[(i + j) % 4]);
            SkeletonControl skeletonControl = model.getControl(SkeletonControl.class);
            skeletonControl.setHardwareSkinningPreferred(hwSkinningEnable);
            skControls.add(skeletonControl);
            rootNode.attachChild(model);
        }
    }

    inputManager.addListener(this, "toggleHWS");
    inputManager.addMapping("toggleHWS", new KeyTrigger(KeyInput.KEY_SPACE));
}
 
Example #23
Source File: TestCartoonEdge.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public void setupLighting(){

     DirectionalLight dl = new DirectionalLight();
     dl.setDirection(new Vector3f(-1, -1, 1).normalizeLocal());
     dl.setColor(new ColorRGBA(2,2,2,1));

     rootNode.addLight(dl);
 }
 
Example #24
Source File: TestLodStress.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public void simpleInitApp() {
        DirectionalLight dl = new DirectionalLight();
        dl.setDirection(new Vector3f(-1,-1,-1).normalizeLocal());
        rootNode.addLight(dl);

        Node teapotNode = (Node) assetManager.loadModel("Models/Teapot/Teapot.mesh.xml");
        Geometry teapot = (Geometry) teapotNode.getChild(0);
        
//        Sphere sph = new Sphere(16, 16, 4);
//        Geometry teapot = new Geometry("teapot", sph);

        Material mat = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md");
        mat.setFloat("Shininess", 16f);
        mat.setBoolean("VertexLighting", true);
        teapot.setMaterial(mat);
        
       // show normals as material
        //Material mat = new Material(assetManager, "Common/MatDefs/Misc/ShowNormals.j3md");

        for (int y = -10; y < 10; y++){
            for (int x = -10; x < 10; x++){
                Geometry clonePot = teapot.clone();
                
                //clonePot.setMaterial(mat);
                clonePot.setLocalTranslation(x * .5f, 0, y * .5f);
                clonePot.setLocalScale(.15f);
                
                LodControl control = new LodControl();
                clonePot.addControl(control);
                rootNode.attachChild(clonePot);
            }
        }

        cam.setLocation(new Vector3f(8.378951f, 5.4324f, 8.795956f));
        cam.setRotation(new Quaternion(-0.083419204f, 0.90370524f, -0.20599906f, -0.36595422f));
    }
 
Example #25
Source File: TestOgreAnim.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public void simpleInitApp() {
    flyCam.setMoveSpeed(10f);
    cam.setLocation(new Vector3f(6.4013605f, 7.488437f, 12.843031f));
    cam.setRotation(new Quaternion(-0.060740203f, 0.93925786f, -0.2398315f, -0.2378785f));

    DirectionalLight dl = new DirectionalLight();
    dl.setDirection(new Vector3f(-0.1f, -0.7f, -1).normalizeLocal());
    dl.setColor(new ColorRGBA(1f, 1f, 1f, 1.0f));
    rootNode.addLight(dl);

    Spatial model = (Spatial) assetManager.loadModel("Models/Oto/Oto.mesh.xml");
    model.center();

    control = model.getControl(AnimControl.class);
    control.addListener(this);
    channel = control.createChannel();

    for (String anim : control.getAnimationNames())
        System.out.println(anim);

    channel.setAnim("stand");

    SkeletonControl skeletonControl = model.getControl(SkeletonControl.class);

    Box b = new Box(.25f,3f,.25f);
    Geometry item = new Geometry("Item", b);
    item.move(0, 1.5f, 0);
    item.setMaterial(assetManager.loadMaterial("Common/Materials/RedColor.j3m"));
    Node n = skeletonControl.getAttachmentsNode("hand.right");
    n.attachChild(item);

    rootNode.attachChild(model);

    inputManager.addListener(this, "Attack");
    inputManager.addMapping("Attack", new KeyTrigger(KeyInput.KEY_SPACE));
}
 
Example #26
Source File: HelloCollision.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private void setUpLight() {
  // We add light so we see the scene
  AmbientLight al = new AmbientLight();
  al.setColor(ColorRGBA.White.mult(1.3f));
  rootNode.addLight(al);

  DirectionalLight dl = new DirectionalLight();
  dl.setColor(ColorRGBA.White);
  dl.setDirection(new Vector3f(2.8f, -2.8f, -2.8f).normalizeLocal());
  rootNode.addLight(dl);
}
 
Example #27
Source File: TestOgreLoading.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
    public void simpleInitApp() {
//        PointLight pl = new PointLight();
//        pl.setPosition(new Vector3f(10, 10, -10));
//        rootNode.addLight(pl);
        flyCam.setMoveSpeed(10f);

        // sunset light
        DirectionalLight dl = new DirectionalLight();
        dl.setDirection(new Vector3f(-0.1f, -0.7f, 1).normalizeLocal());
        dl.setColor(new ColorRGBA(1f, 1f, 1f, 1.0f));
        rootNode.addLight(dl);


        lightMdl = new Geometry("Light", new Sphere(10, 10, 0.1f));
        lightMdl.setMaterial(assetManager.loadMaterial("Common/Materials/RedColor.j3m"));
        rootNode.attachChild(lightMdl);

        lightMd2 = new Geometry("Light", new Sphere(10, 10, 0.1f));
        lightMd2.setMaterial(assetManager.loadMaterial("Common/Materials/WhiteColor.j3m"));
        rootNode.attachChild(lightMd2);


        pl = new PointLight();
        pl.setColor(new ColorRGBA(1, 0.9f, 0.9f, 0));
        pl.setPosition(new Vector3f(0f, 0f, 4f));
        rootNode.addLight(pl);

        p2 = new PointLight();
        p2.setColor(new ColorRGBA(0.9f, 1, 0.9f, 0));
        p2.setPosition(new Vector3f(0f, 0f, 3f));
        rootNode.addLight(p2);


        // create the geometry and attach it
        Spatial elephant = assetManager.loadModel("Models/Elephant/Elephant.mesh.xml");
        float scale = 0.05f;
        elephant.scale(scale, scale, scale);
        rootNode.attachChild(elephant);
    }
 
Example #28
Source File: TestSceneLoading.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void simpleInitApp() {
    File file = new File("wildhouse.zip");
    if (!file.exists()) {
        useHttp = true;
    }
    
    this.flyCam.setMoveSpeed(10);

    // load sky
    rootNode.attachChild(SkyFactory.createSky(assetManager, 
            "Textures/Sky/Bright/BrightSky.dds", 
            SkyFactory.EnvMapType.CubeMap));
    
    // create the geometry and attach it
    // load the level from zip or http zip
    if (useHttp) {
        assetManager.registerLocator("https://storage.googleapis.com/google-code-archive-downloads/v2/code.google.com/jmonkeyengine/wildhouse.zip", HttpZipLocator.class);
    } else {
        assetManager.registerLocator("wildhouse.zip", ZipLocator.class);
    }
    Spatial scene = assetManager.loadModel("main.scene");

    AmbientLight al = new AmbientLight();
    scene.addLight(al);

    DirectionalLight sun = new DirectionalLight();
    sun.setDirection(new Vector3f(0.69077975f, -0.6277887f, -0.35875428f).normalizeLocal());
    sun.setColor(ColorRGBA.White.clone().multLocal(2));
    scene.addLight(sun);

    rootNode.attachChild(scene);
}
 
Example #29
Source File: TestEnvironmentMapping.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void simpleInitApp() {
    final Node buggy = (Node) assetManager.loadModel("Models/Buggy/Buggy.j3o");

    TextureKey key = new TextureKey("Textures/Sky/Bright/BrightSky.dds", true);
    key.setGenerateMips(true);
    key.setTextureTypeHint(Texture.Type.CubeMap);
    final Texture tex = assetManager.loadTexture(key);

    for (Spatial geom : buggy.getChildren()) {
        if (geom instanceof Geometry) {
            Material m = ((Geometry) geom).getMaterial();
            m.setTexture("EnvMap", tex);
            m.setVector3("FresnelParams", new Vector3f(0.05f, 0.18f, 0.11f));
        }
    }

    flyCam.setEnabled(false);

    ChaseCamera chaseCam = new ChaseCamera(cam, inputManager);
    chaseCam.setLookAtOffset(new Vector3f(0,0.5f,-1.0f));
    buggy.addControl(chaseCam);
    rootNode.attachChild(buggy);
    rootNode.attachChild(SkyFactory.createSky(assetManager, tex,
            SkyFactory.EnvMapType.CubeMap));

    FilterPostProcessor fpp = new FilterPostProcessor(assetManager);
    BloomFilter bf = new BloomFilter(BloomFilter.GlowMode.Objects);
    bf.setBloomIntensity(2.3f);
    bf.setExposurePower(0.6f);
    
    fpp.addFilter(bf);
    
    DirectionalLight l = new DirectionalLight();
    l.setDirection(new Vector3f(0, -1, -1));
    rootNode.addLight(l);
    
    viewPort.addProcessor(fpp);
}
 
Example #30
Source File: WaterFilter.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private DirectionalLight findLight(Node node) {
    for (Light light : node.getWorldLightList()) {
        if (light instanceof DirectionalLight) {
            return (DirectionalLight) light;
        }
    }
    for (Spatial child : node.getChildren()) {
        if (child instanceof Node) {
            return findLight((Node) child);
        }
    }

    return null;
}