Java Code Examples for com.jme3.light.DirectionalLight#setColor()

The following examples show how to use com.jme3.light.DirectionalLight#setColor() . 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: 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 2
Source File: TestParallelProjection.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public void simpleInitApp() {
    Geometry teaGeom = (Geometry) assetManager.loadModel("Models/Teapot/Teapot.obj");

    DirectionalLight dl = new DirectionalLight();
    dl.setColor(ColorRGBA.White);
    dl.setDirection(Vector3f.UNIT_XYZ.negate());

    rootNode.addLight(dl);
    rootNode.attachChild(teaGeom);

    // Setup first view
    cam.setParallelProjection(true);
    float aspect = (float) cam.getWidth() / cam.getHeight();
    cam.setFrustum(-1000, 1000, -aspect * frustumSize, aspect * frustumSize, frustumSize, -frustumSize);

    inputManager.addListener(this, "Size+", "Size-");
    inputManager.addMapping("Size+", new KeyTrigger(KeyInput.KEY_W));
    inputManager.addMapping("Size-", new KeyTrigger(KeyInput.KEY_S));
}
 
Example 3
Source File: TestParallelProjection.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public void simpleInitApp() {
    Geometry teaGeom = (Geometry) assetManager.loadModel("Models/Teapot/Teapot.obj");

    DirectionalLight dl = new DirectionalLight();
    dl.setColor(ColorRGBA.White);
    dl.setDirection(Vector3f.UNIT_XYZ.negate());

    rootNode.addLight(dl);
    rootNode.attachChild(teaGeom);

    // Setup first view
    cam.setParallelProjection(true);
    float aspect = (float) cam.getWidth() / cam.getHeight();
    cam.setFrustum(-1000, 1000, -aspect * frustumSize, aspect * frustumSize, frustumSize, -frustumSize);

    inputManager.addListener(this, "Size+", "Size-");
    inputManager.addMapping("Size+", new KeyTrigger(KeyInput.KEY_W));
    inputManager.addMapping("Size-", new KeyTrigger(KeyInput.KEY_S));
}
 
Example 4
Source File: TranslateUtil.java    From OpenRTS with MIT License 6 votes vote down vote up
public static DirectionalLight toJMELight(DirectionalLighting dl) {
	DirectionalLight res = new DirectionalLight();
	res.setColor(toColorRGBA(dl.color).multLocal((float) (dl.intensity)));

	Node world = new Node();

	Node yaw = new Node();
	world.attachChild(yaw);

	Node pitch = new Node();
	yaw.attachChild(pitch);

	Node offset = new Node();
	pitch.attachChild(offset);
	offset.setLocalTranslation(Vector3f.UNIT_X);

	pitch.rotate(0, (float) dl.pitch, 0);

	yaw.rotate(0, 0, (float) dl.yaw);
	res.setDirection(offset.getWorldTranslation());
	return res;
}
 
Example 5
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 6
Source File: TestBoneRagdoll.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private void setupLight() {
    // AmbientLight al = new AmbientLight();
    //  al.setColor(ColorRGBA.White.mult(1));
    //   rootNode.addLight(al);

    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);
}
 
Example 7
Source File: TestHWSkinning.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(38.76639f, 14.744472f, 45.097454f));
    cam.setRotation(new Quaternion(-0.06086266f, 0.92303723f, -0.1639443f, -0.34266636f));

    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);

    Spatial models[] = new Spatial[4];
    for (int i = 0; i < 4; i++) {
        models[i] =loadModel(i);
    }

    for (int i = 0; i < SIZE; i++) {
        for (int j = 0; j < SIZE; j++) {
            Node model = (Node)models[(i + j) % 4];
            Spatial s = model.getChild(0).clone();
            model.attachChild(s);
            float x = (i - SIZE / 2) / 0.1f;
            float z = (j - SIZE / 2) / 0.1f;
            s.setLocalTranslation(x, 0, z);
        }
    }

    inputManager.addListener(this, "toggleHWS");
    inputManager.addMapping("toggleHWS", new KeyTrigger(KeyInput.KEY_SPACE));

}
 
Example 8
Source File: TestHoveringTank.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
    public void simpleInitApp() {
        bulletAppState = new BulletAppState();
        bulletAppState.setThreadingType(BulletAppState.ThreadingType.PARALLEL);
        stateManager.attach(bulletAppState);
//        bulletAppState.getPhysicsSpace().enableDebug(assetManager);
        bulletAppState.getPhysicsSpace().setAccuracy(1f/30f);
        rootNode.attachChild(SkyFactory.createSky(assetManager, "Textures/Sky/Bright/BrightSky.dds", false));

        PssmShadowRenderer pssmr = new PssmShadowRenderer(assetManager, 2048, 3);
        pssmr.setDirection(new Vector3f(-0.5f, -0.3f, -0.3f).normalizeLocal());
        pssmr.setLambda(0.55f);
        pssmr.setShadowIntensity(0.6f);
        pssmr.setCompareMode(CompareMode.Hardware);
        pssmr.setFilterMode(FilterMode.Bilinear);
        viewPort.addProcessor(pssmr);

        setupKeys();
        createTerrain();
        buildPlayer();

        DirectionalLight dl = new DirectionalLight();
        dl.setColor(new ColorRGBA(1.0f, 0.94f, 0.8f, 1f).multLocal(1.3f));
        dl.setDirection(new Vector3f(-0.5f, -0.3f, -0.3f).normalizeLocal());
        rootNode.addLight(dl);

        Vector3f lightDir2 = new Vector3f(0.70518064f, 0.5902297f, -0.39287305f);
        DirectionalLight dl2 = new DirectionalLight();
        dl2.setColor(new ColorRGBA(0.7f, 0.85f, 1.0f, 1f));
        dl2.setDirection(lightDir2);
        rootNode.addLight(dl2);
    }
 
Example 9
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 10
Source File: TestPointDirectionalAndSpotLightShadows.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public void simpleInitApp() {
    flyCam.setMoveSpeed(10);
    cam.setLocation(new Vector3f(0.040581334f, 1.7745866f, 6.155161f));
    cam.setRotation(new Quaternion(4.3868728E-5f, 0.9999293f, -0.011230096f, 0.0039059948f));


    Node scene = (Node) assetManager.loadModel("Models/Test/CornellBox.j3o");
    scene.setShadowMode(RenderQueue.ShadowMode.CastAndReceive);
    rootNode.attachChild(scene);
    rootNode.getChild("Cube").setShadowMode(RenderQueue.ShadowMode.Receive);
    lightNode = (Node) rootNode.getChild("Lamp");
    Geometry lightMdl = new Geometry("Light", new Sphere(10, 10, 0.1f));
    //Geometry  lightMdl = new Geometry("Light", new Box(.1f,.1f,.1f));
    lightMdl.setMaterial(assetManager.loadMaterial("Common/Materials/RedColor.j3m"));
    lightMdl.setShadowMode(RenderQueue.ShadowMode.Off);
    lightNode.attachChild(lightMdl);
    //lightMdl.setLocalTranslation(lightNode.getLocalTranslation());


    Geometry box = new Geometry("box", new Box(0.2f, 0.2f, 0.2f));
    //Geometry  lightMdl = new Geometry("Light", new Box(.1f,.1f,.1f));
    box.setMaterial(assetManager.loadMaterial("Common/Materials/RedColor.j3m"));
    box.setShadowMode(RenderQueue.ShadowMode.CastAndReceive);
    rootNode.attachChild(box);
    box.setLocalTranslation(-1f, 0.5f, -2);

    scene.getLocalLightList().get(0).setColor(ColorRGBA.Red);
    
    plsr = new PointLightShadowRenderer(assetManager, SHADOWMAP_SIZE);
    plsr.setLight((PointLight) scene.getLocalLightList().get(0));
    plsr.setEdgeFilteringMode(EdgeFilteringMode.PCF4);



    plsf = new PointLightShadowFilter(assetManager, SHADOWMAP_SIZE);
    plsf.setLight((PointLight) scene.getLocalLightList().get(0));     
    plsf.setEdgeFilteringMode(EdgeFilteringMode.PCF4);
    plsf.setEnabled(useFilter);

    //DIRECTIONAL LIGHT
    DirectionalLight directionalLight = new DirectionalLight();
    rootNode.addLight(directionalLight);
    directionalLight.setColor(ColorRGBA.Blue);
    directionalLight.setDirection(new Vector3f(-1f, -.2f, 0f));
    dlsr = new DirectionalLightShadowRenderer(assetManager, SHADOWMAP_SIZE*2, 4);
    dlsr.setLight(directionalLight);
    dlsr.setEdgeFilteringMode(EdgeFilteringMode.PCF4);
    
    dlsf = new DirectionalLightShadowFilter(assetManager, SHADOWMAP_SIZE*2, 4);
    dlsf.setEdgeFilteringMode(EdgeFilteringMode.PCF4);
    dlsf.setLight(directionalLight);        
    dlsf.setEnabled(useFilter);
    
    //SPOT LIGHT
    spotLight = new SpotLight();
    spotLight.setDirection(new Vector3f(1f,-1f,0f));
    spotLight.setPosition(new Vector3f(-1f,3f,0f));
    spotLight.setSpotOuterAngle(0.5f);
    spotLight.setColor(ColorRGBA.Green);
    Sphere sphere = new Sphere(8, 8, .1f);
    Geometry sphereGeometry = new Geometry("Sphere", sphere);
    sphereGeometry.setLocalTranslation(-1f, 3f, 0f);
    sphereGeometry.setMaterial(assetManager.loadMaterial("Common/Materials/WhiteColor.j3m"));
    rootNode.attachChild(sphereGeometry);
    rootNode.addLight(spotLight);
    
    slsr = new SpotLightShadowRenderer(assetManager, SHADOWMAP_SIZE);
    slsr.setLight(spotLight);
    slsr.setEdgeFilteringMode(EdgeFilteringMode.PCF4);
    
    slsf = new SpotLightShadowFilter(assetManager, SHADOWMAP_SIZE);
    slsf.setLight(spotLight);
    slsf.setEdgeFilteringMode(EdgeFilteringMode.PCF4);
    slsf.setEnabled(useFilter);
    
    
    
    if (!useFilter)viewPort.addProcessor(slsr);
    if (!useFilter)viewPort.addProcessor(plsr);
    if (!useFilter)viewPort.addProcessor(dlsr);
    
    FilterPostProcessor fpp = new FilterPostProcessor(assetManager);
    fpp.addFilter(plsf);
    fpp.addFilter(dlsf);
    fpp.addFilter(slsf);
    viewPort.addProcessor(fpp);
          
    ShadowTestUIManager uiMan = new ShadowTestUIManager(assetManager, plsr, plsf, guiNode, inputManager, viewPort);
    ShadowTestUIManager uiManPls = new ShadowTestUIManager(assetManager, plsr, plsf, guiNode, inputManager, viewPort);
    ShadowTestUIManager uiManDls = new ShadowTestUIManager(assetManager, dlsr, dlsf, guiNode, inputManager, viewPort);
    ShadowTestUIManager uiManSls = new ShadowTestUIManager(assetManager, slsr, slsf, guiNode, inputManager, viewPort);
  
}
 
Example 11
Source File: TestTangentGenBadUV.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public void simpleInitApp() {
    Spatial teapot = assetManager.loadModel("Models/Teapot/Teapot.obj");
    if (teapot instanceof Geometry){
        Geometry g = (Geometry) teapot;
        TangentBinormalGenerator.generate(g.getMesh());
    }else{
        throw new RuntimeException();
    }
    teapot.setLocalScale(2f);
    Material mat = assetManager.loadMaterial("Textures/BumpMapTest/Tangent.j3m");
    teapot.setMaterial(mat);
    rootNode.attachChild(teapot);

    Geometry debug = new Geometry(
            "Debug Teapot",
            TangentBinormalGenerator.genTbnLines(((Geometry) teapot).getMesh(), 0.03f)
    );
    Material debugMat = assetManager.loadMaterial("Common/Materials/VertexColor.j3m");
    debug.setMaterial(debugMat);
    debug.setCullHint(Spatial.CullHint.Never);
    debug.getLocalTranslation().set(teapot.getLocalTranslation());
    debug.getLocalScale().set(teapot.getLocalScale());
    rootNode.attachChild(debug);


    DirectionalLight dl = new DirectionalLight();
    dl.setDirection(new Vector3f(1,-1,-1).normalizeLocal());
    dl.setColor(ColorRGBA.White);
    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);
    //pl.setRadius(3f);
    rootNode.addLight(pl);
}
 
Example 12
Source File: TestCrossHatch.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@Override
public void simpleInitApp() {
    // put the camera in a bad position
    cam.setLocation(new Vector3f(-2.336393f, 11.91392f, -7.139601f));
    cam.setRotation(new Quaternion(0.23602544f, 0.11321983f, -0.027698677f, 0.96473104f));
    //cam.setFrustumFar(1000);


    Material mat = new Material(assetManager,"Common/MatDefs/Light/Lighting.j3md");
    mat.setFloat("Shininess", 15f);
    mat.setBoolean("UseMaterialColors", true);
    mat.setColor("Ambient", ColorRGBA.Yellow.mult(0.2f));
    mat.setColor("Diffuse", ColorRGBA.Yellow.mult(0.2f));
    mat.setColor("Specular", ColorRGBA.Yellow.mult(0.8f));




    Material matSoil = new Material(assetManager,"Common/MatDefs/Light/Lighting.j3md");
    matSoil.setFloat("Shininess", 15f);
    matSoil.setBoolean("UseMaterialColors", true);
    matSoil.setColor("Ambient", ColorRGBA.Gray);
    matSoil.setColor("Diffuse", ColorRGBA.Black);
    matSoil.setColor("Specular", ColorRGBA.Gray);
   


    teapot = assetManager.loadModel("Models/Teapot/Teapot.obj");
    teapot.setLocalTranslation(0,0,10);

    teapot.setMaterial(mat);
    teapot.setShadowMode(ShadowMode.CastAndReceive);
    teapot.setLocalScale(10.0f);
    rootNode.attachChild(teapot);

  

    Geometry soil=new Geometry("soil", new Box(new Vector3f(0, -13, 550), 800, 10, 700));
    soil.setMaterial(matSoil);
    soil.setShadowMode(ShadowMode.CastAndReceive);
    rootNode.attachChild(soil);

    DirectionalLight light=new DirectionalLight();
    light.setDirection(new Vector3f(-1, -1, -1).normalizeLocal());
    light.setColor(ColorRGBA.White.mult(1.5f));
    rootNode.addLight(light);

    // load sky
    Spatial sky = SkyFactory.createSky(assetManager, "Textures/Sky/Bright/FullskiesBlueClear03.dds", false);
    sky.setCullHint(Spatial.CullHint.Never);
    rootNode.attachChild(sky);

    fpp=new FilterPostProcessor(assetManager);
    CrossHatchFilter chf=new CrossHatchFilter();
    
   

    viewPort.addProcessor(fpp);
    fpp.addFilter(chf);
    initInputs();

}
 
Example 13
Source File: TestBloom.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public void simpleInitApp() {
    // put the camera in a bad position
    cam.setLocation(new Vector3f(-2.336393f, 11.91392f, -7.139601f));
    cam.setRotation(new Quaternion(0.23602544f, 0.11321983f, -0.027698677f, 0.96473104f));
    //cam.setFrustumFar(1000);


    Material mat = new Material(assetManager,"Common/MatDefs/Light/Lighting.j3md");
    mat.setFloat("Shininess", 15f);
    mat.setBoolean("UseMaterialColors", true);
    mat.setColor("Ambient", ColorRGBA.Yellow.mult(0.2f));
    mat.setColor("Diffuse", ColorRGBA.Yellow.mult(0.2f));
    mat.setColor("Specular", ColorRGBA.Yellow.mult(0.8f));




    Material matSoil = new Material(assetManager,"Common/MatDefs/Light/Lighting.j3md");
    matSoil.setFloat("Shininess", 15f);
    matSoil.setBoolean("UseMaterialColors", true);
    matSoil.setColor("Ambient", ColorRGBA.Gray);
    matSoil.setColor("Diffuse", ColorRGBA.Black);
    matSoil.setColor("Specular", ColorRGBA.Gray);
   


    teapot = assetManager.loadModel("Models/Teapot/Teapot.obj");
    teapot.setLocalTranslation(0,0,10);

    teapot.setMaterial(mat);
    teapot.setShadowMode(ShadowMode.CastAndReceive);
    teapot.setLocalScale(10.0f);
    rootNode.attachChild(teapot);

  

    Geometry soil = new Geometry("soil", new Box(800, 10, 700));
    soil.setLocalTranslation(0, -13, 550);
    soil.setMaterial(matSoil);
    soil.setShadowMode(ShadowMode.CastAndReceive);
    rootNode.attachChild(soil);

    DirectionalLight light=new DirectionalLight();
    light.setDirection(new Vector3f(-1, -1, -1).normalizeLocal());
    light.setColor(ColorRGBA.White.mult(1.5f));
    rootNode.addLight(light);

    // load sky
    Spatial sky = SkyFactory.createSky(assetManager, 
            "Textures/Sky/Bright/FullskiesBlueClear03.dds", 
            EnvMapType.CubeMap);
    sky.setCullHint(Spatial.CullHint.Never);
    rootNode.attachChild(sky);

    fpp=new FilterPostProcessor(assetManager);
   // fpp.setNumSamples(4);
    int numSamples = getContext().getSettings().getSamples();
    if( numSamples > 0 ) {
        fpp.setNumSamples(numSamples); 
    }
    
    BloomFilter bloom=new BloomFilter();
    bloom.setDownSamplingFactor(2);
    bloom.setBlurScale(1.37f);
    bloom.setExposurePower(3.30f);
    bloom.setExposureCutOff(0.2f);
    bloom.setBloomIntensity(2.45f);
    BloomUI ui=new BloomUI(inputManager, bloom);
   

    viewPort.addProcessor(fpp);
    fpp.addFilter(bloom);
    initInputs();

}
 
Example 14
Source File: TestPosterization.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public void simpleInitApp() {
    // put the camera in a bad position
    cam.setLocation(new Vector3f(-2.336393f, 11.91392f, -7.139601f));
    cam.setRotation(new Quaternion(0.23602544f, 0.11321983f, -0.027698677f, 0.96473104f));

    Material mat = new Material(assetManager,"Common/MatDefs/Light/Lighting.j3md");
    mat.setFloat("Shininess", 15f);
    mat.setBoolean("UseMaterialColors", true);
    mat.setColor("Ambient", ColorRGBA.Yellow.mult(0.2f));
    mat.setColor("Diffuse", ColorRGBA.Yellow.mult(0.2f));
    mat.setColor("Specular", ColorRGBA.Yellow.mult(0.8f));

    Material matSoil = new Material(assetManager,"Common/MatDefs/Light/Lighting.j3md");
    matSoil.setFloat("Shininess", 15f);
    matSoil.setBoolean("UseMaterialColors", true);
    matSoil.setColor("Ambient", ColorRGBA.Gray);
    matSoil.setColor("Diffuse", ColorRGBA.Black);
    matSoil.setColor("Specular", ColorRGBA.Gray);

    teapot = assetManager.loadModel("Models/Teapot/Teapot.obj");
    teapot.setLocalTranslation(0,0,10);

    teapot.setMaterial(mat);
    teapot.setShadowMode(ShadowMode.CastAndReceive);
    teapot.setLocalScale(10.0f);
    rootNode.attachChild(teapot);

    Geometry soil = new Geometry("soil", new Box(800, 10, 700));
    soil.setLocalTranslation(0, -13, 550);
    soil.setMaterial(matSoil);
    soil.setShadowMode(ShadowMode.CastAndReceive);
    rootNode.attachChild(soil);

    DirectionalLight light=new DirectionalLight();
    light.setDirection(new Vector3f(-1, -1, -1).normalizeLocal());
    light.setColor(ColorRGBA.White.mult(1.5f));
    rootNode.addLight(light);

    // load sky
    Spatial sky = SkyFactory.createSky(assetManager, "Textures/Sky/Bright/FullskiesBlueClear03.dds", SkyFactory.EnvMapType.CubeMap);
    sky.setCullHint(Spatial.CullHint.Never);
    rootNode.attachChild(sky);

    FilterPostProcessor fpp = new FilterPostProcessor(assetManager);
    int numSamples = getContext().getSettings().getSamples();
    if (numSamples > 0) {
        fpp.setNumSamples(numSamples);
    }
    pf = new PosterizationFilter();
    fpp.addFilter(pf);

    viewPort.addProcessor(fpp);
    initInputs();

}
 
Example 15
Source File: TestBatchNode.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
    public void simpleInitApp() {
        timer = new NanoTimer();
        batch = new BatchNode("theBatchNode");



        /**
         * A cube with a color "bleeding" through transparent texture. Uses
         * Texture from jme3-test-data library!
         */
        Box boxshape4 = new Box(1f, 1f, 1f);
        cube = new Geometry("cube1", boxshape4);
        Material mat = assetManager.loadMaterial("Textures/Terrain/Pond/Pond.j3m");
        cube.setMaterial(mat);
//        Material mat = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md");        
//        mat.setColor("Diffuse", ColorRGBA.Blue);
//        mat.setBoolean("UseMaterialColors", true);
        /**
         * A cube with a color "bleeding" through transparent texture. Uses
         * Texture from jme3-test-data library!
         */
        Box box = new Box(1f, 1f, 1f);
        cube2 = new Geometry("cube2", box);
        cube2.setMaterial(mat);

        TangentBinormalGenerator.generate(cube);
        TangentBinormalGenerator.generate(cube2);


        n = new Node("aNode");
        // n.attachChild(cube2);
        batch.attachChild(cube);
        //  batch.attachChild(cube2);
        //  batch.setMaterial(mat);
        batch.batch();
        rootNode.attachChild(batch);
        cube.setLocalTranslation(3, 0, 0);
        cube2.setLocalTranslation(0, 20, 0);


        updateBoindPoints(points);
        frustum = new WireFrustum(points);
        frustumMdl = new Geometry("f", frustum);
        frustumMdl.setCullHint(Spatial.CullHint.Never);
        frustumMdl.setMaterial(new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md"));
        frustumMdl.getMaterial().getAdditionalRenderState().setWireframe(true);
        frustumMdl.getMaterial().setColor("Color", ColorRGBA.Red);
        rootNode.attachChild(frustumMdl);
        dl = new DirectionalLight();
        dl.setColor(ColorRGBA.White.mult(2));
        dl.setDirection(new Vector3f(1, -1, -1));
        rootNode.addLight(dl);
        flyCam.setMoveSpeed(10);
    }
 
Example 16
Source File: TestOctree.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public void simpleInitApp() {
//        this.flyCam.setMoveSpeed(2000);
//        this.cam.setFrustumFar(10000);
        MeshLoader.AUTO_INTERLEAVE = false;

//        mat = new Material(assetManager, "Common/MatDefs/Misc/WireColor.j3md");
//        mat.setColor("Color", ColorRGBA.White);

//        mat2 = new Material(assetManager, "Common/MatDefs/Misc/ShowNormals.j3md");

        assetManager.registerLocator("quake3level.zip", "com.jme3.asset.plugins.ZipLocator");
        MaterialList matList = (MaterialList) assetManager.loadAsset("Scene.material");
        OgreMeshKey key = new OgreMeshKey("main.meshxml", matList);
        Spatial scene = assetManager.loadModel(key);

//        Spatial scene = assetManager.loadModel("Models/Teapot/teapot.obj");
//        scene.scale(3);

        DirectionalLight dl = new DirectionalLight();
        dl.setColor(ColorRGBA.White);
        dl.setDirection(new Vector3f(-1, -1, -1).normalize());
        rootNode.addLight(dl);

        DirectionalLight dl2 = new DirectionalLight();
        dl2.setColor(ColorRGBA.White);
        dl2.setDirection(new Vector3f(1, -1, 1).normalize());
        rootNode.addLight(dl2);

        // generate octree
//        tree = new Octree(scene, 20000);
        tree = new Octree(scene, 50);
        tree.construct();
        
        ArrayList<Geometry> globalGeomList = new ArrayList<Geometry>();
        tree.createFastOctnodes(globalGeomList);
        tree.generateFastOctnodeLinks();

        for (Geometry geom : globalGeomList){
            geom.addLight(dl);
            geom.addLight(dl2);
            geom.updateGeometricState();
        }
        
        globalGeoms = globalGeomList.toArray(new Geometry[0]);
        fastRoot = tree.getFastRoot();
        octBox = tree.getBound();

        viewPort.addProcessor(this);
    }
 
Example 17
Source File: TestQ3.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public void simpleInitApp() {
    bulletAppState = new BulletAppState();
    stateManager.attach(bulletAppState);
    flyCam.setMoveSpeed(100);
    setupKeys();

    this.cam.setFrustumFar(2000);

    DirectionalLight dl = new DirectionalLight();
    dl.setColor(ColorRGBA.White.clone().multLocal(2));
    dl.setDirection(new Vector3f(-1, -1, -1).normalize());
    rootNode.addLight(dl);

    AmbientLight am = new AmbientLight();
    am.setColor(ColorRGBA.White.mult(2));
    rootNode.addLight(am);

    // load the level from zip or http zip
    if (useHttp) {
        assetManager.registerLocator("http://jmonkeyengine.googlecode.com/files/quake3level.zip", HttpZipLocator.class.getName());
    } else {
        assetManager.registerLocator("quake3level.zip", ZipLocator.class.getName());
    }

    // create the geometry and attach it
    MaterialList matList = (MaterialList) assetManager.loadAsset("Scene.material");
    OgreMeshKey key = new OgreMeshKey("main.meshxml", matList);
    gameLevel = (Node) assetManager.loadAsset(key);
    gameLevel.setLocalScale(0.1f);

    // add a physics control, it will generate a MeshCollisionShape based on the gameLevel
    gameLevel.addControl(new RigidBodyControl(0));

    player = new PhysicsCharacter(new SphereCollisionShape(5), .01f);
    player.setJumpSpeed(20);
    player.setFallSpeed(30);
    player.setGravity(30);

    player.setPhysicsLocation(new Vector3f(60, 10, -60));

    rootNode.attachChild(gameLevel);

    getPhysicsSpace().addAll(gameLevel);
    getPhysicsSpace().add(player);
}
 
Example 18
Source File: TestSimpleLighting.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
    public void simpleInitApp() {
        Geometry teapot = (Geometry) assetManager.loadModel("Models/Teapot/Teapot.obj");
        TangentBinormalGenerator.generate(teapot.getMesh(), true);

        teapot.setLocalScale(2f);
        Material mat = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md");
//        mat.selectTechnique("GBuf");
        mat.setFloat("Shininess", 25);
        mat.setBoolean("UseMaterialColors", true);
        cam.setLocation(new Vector3f(0.015041917f, 0.4572918f, 5.2874837f));
        cam.setRotation(new Quaternion(-1.8875003E-4f, 0.99882424f, 0.04832061f, 0.0039016632f));

//        mat.setTexture("ColorRamp", assetManager.loadTexture("Textures/ColorRamp/cloudy.png"));
//
//        mat.setBoolean("VTangent", true);
//        mat.setBoolean("Minnaert", true);
//        mat.setBoolean("WardIso", true);
//        mat.setBoolean("VertexLighting", true);
//        mat.setBoolean("LowQuality", true);
//        mat.setBoolean("HighQuality", true);

        mat.setColor("Ambient",  ColorRGBA.Black);
        mat.setColor("Diffuse",  ColorRGBA.Gray);
        mat.setColor("Specular", ColorRGBA.Gray);
        
        teapot.setMaterial(mat);
        rootNode.attachChild(teapot);

        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);
        pl.setRadius(4f);
        rootNode.addLight(pl);

        DirectionalLight dl = new DirectionalLight();
        dl.setDirection(new Vector3f(-1, -1, -1).normalizeLocal());
        dl.setColor(ColorRGBA.Green);
        rootNode.addLight(dl);
        
        
        MaterialDebugAppState debug = new MaterialDebugAppState();
        debug.registerBinding("Common/ShaderLib/BlinnPhongLighting.glsllib", teapot);
        stateManager.attach(debug);
        setPauseOnLostFocus(false);
        flyCam.setDragToRotate(true);
        
    }
 
Example 19
Source File: TestPostWaterLake.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public void simpleInitApp() {
    File file = new File("wildhouse.zip");
    if (!file.exists()) {
        useHttp = true;
    }
    
    this.flyCam.setMoveSpeed(10);
    cam.setLocation(new Vector3f(-27.0f, 1.0f, 75.0f));
  //  cam.setRotation(new Quaternion(0.03f, 0.9f, 0f, 0.4f));

    // 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");
    rootNode.attachChild(scene);

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

    FilterPostProcessor fpp = new FilterPostProcessor(assetManager);        
    final WaterFilter water = new WaterFilter(rootNode, lightDir);
    water.setWaterHeight(-20);
    water.setUseFoam(false);
    water.setUseRipples(false);
    water.setDeepWaterColor(ColorRGBA.Brown);
    water.setWaterColor(ColorRGBA.Brown.mult(2.0f));
    water.setWaterTransparency(0.2f);
    water.setMaxAmplitude(0.3f);
    water.setWaveScale(0.008f);
    water.setSpeed(0.7f);
    water.setShoreHardness(1.0f);
    water.setRefractionConstant(0.2f);
    water.setShininess(0.3f);
    water.setSunScale(1.0f);
    water.setColorExtinction(new Vector3f(10.0f, 20.0f, 30.0f));
    fpp.addFilter(water);
    viewPort.addProcessor(fpp);

    inputManager.addListener(new ActionListener() {

        @Override
        public void onAction(String name, boolean isPressed, float tpf) {
          if(isPressed){
              if(water.isUseHQShoreline()){
                  water.setUseHQShoreline(false);
              }else{
                  water.setUseHQShoreline(true);
              }
          }
        }
    }, "HQ");

    inputManager.addMapping("HQ", new KeyTrigger(keyInput.KEY_SPACE));
}
 
Example 20
Source File: TestColorApp.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
    public void simpleInitApp() {
        // Lights
        DirectionalLight sun = new DirectionalLight();
        Vector3f sunPosition = new Vector3f(1, -1, 1);
        sun.setDirection(sunPosition);
        sun.setColor(new ColorRGBA(1f,1f,1f,1f));
        rootNode.addLight(sun);
 
        //DirectionalLightShadowFilter sun_renderer = new DirectionalLightShadowFilter(assetManager, 2048, 4);
        DirectionalLightShadowRenderer sun_renderer = new DirectionalLightShadowRenderer(assetManager, 2048, 1);
        sun_renderer.setLight(sun);
        viewPort.addProcessor(sun_renderer);
        
//        FilterPostProcessor fpp = new FilterPostProcessor(assetManager);
//        fpp.addFilter(sun_renderer);
//        viewPort.addProcessor(fpp);
        
        rootNode.setShadowMode(RenderQueue.ShadowMode.CastAndReceive);
 
        // Camera
        viewPort.setBackgroundColor(new ColorRGBA(.6f, .6f, .6f, 1f));
        ChaseCamera chaseCam = new ChaseCamera(cam, inputManager);
 
 
        // Objects
        // Ground Object
        final Geometry groundBoxWhite = new Geometry("Box", new Box(7.5f, 7.5f, .25f));
        float[] f = {-FastMath.PI / 2, 3 * FastMath.PI / 2, 0f};
        groundBoxWhite.setLocalRotation(new Quaternion(f));
        groundBoxWhite.move(7.5f, -.75f, 7.5f);
        final Material groundMaterial = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md");
        groundMaterial.setColor("Diffuse", new ColorRGBA(.9f, .9f, .9f, .9f));
        groundBoxWhite.setMaterial(groundMaterial);
        groundBoxWhite.addControl(chaseCam);
        rootNode.attachChild(groundBoxWhite);
 
        // Planter
        Geometry planterBox = new Geometry("Box", new Box(.5f, .5f, .5f));
        final Material planterMaterial = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md");
        planterMaterial.setTexture("DiffuseMap", assetManager.loadTexture("Textures/Terrain/BrickWall/BrickWall.jpg"));
        planterBox.setMaterial(groundMaterial);
        planterBox.setLocalTranslation(10, 0, 9);
        rootNode.attachChild(planterBox);
 
        // Action!
        inputManager.addMapping("on", new KeyTrigger(KeyInput.KEY_Z));
        inputManager.addMapping("off", new KeyTrigger(KeyInput.KEY_X));
 
        inputManager.addListener(new AnalogListener() {
            @Override
            public void onAnalog(String s, float v, float v1) {
                if (s.equals("on")) {
                    groundBoxWhite.setMaterial(planterMaterial);
                }
                if (s.equals("off")) {
                    groundBoxWhite.setMaterial(groundMaterial);
                }
            }
        }, "on", "off");
 
        inputEnabled = true;
    }