Java Code Examples for com.jme3.util.TangentBinormalGenerator#generate()

The following examples show how to use com.jme3.util.TangentBinormalGenerator#generate() . 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: TestTangentGen.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
private void addMesh(String name, Mesh mesh, Vector3f translation) {
    TangentBinormalGenerator.generate(mesh);

    Geometry testGeom = new Geometry(name, mesh);
    Material mat = assetManager.loadMaterial("Textures/BumpMapTest/Tangent.j3m");
    testGeom.setMaterial(mat);
    testGeom.getLocalTranslation().set(translation);
    rootNode.attachChild(testGeom);

    Geometry debug = new Geometry(
            "Debug " + name,
            TangentBinormalGenerator.genTbnLines(mesh, 0.08f)
    );
    Material debugMat = assetManager.loadMaterial("Common/Materials/VertexColor.j3m");
    debug.setMaterial(debugMat);
    debug.setCullHint(Spatial.CullHint.Never);
    debug.getLocalTranslation().set(translation);
    rootNode.attachChild(debug);
}
 
Example 2
Source File: TestSpotLight.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public void setupFloor(){
    Material mat = assetManager.loadMaterial("Textures/Terrain/Pond/Pond.j3m");
    mat.getTextureParam("DiffuseMap").getTextureValue().setWrap(WrapMode.Repeat);
    mat.getTextureParam("NormalMap").getTextureValue().setWrap(WrapMode.Repeat);
   // mat.getTextureParam("ParallaxMap").getTextureValue().setWrap(WrapMode.Repeat);
    mat.setFloat("Shininess",3);
  //  mat.setBoolean("VertexLighting", true);
    
    
    Box floor = new Box(Vector3f.ZERO, 50, 1f, 50);
    TangentBinormalGenerator.generate(floor);
    floor.scaleTextureCoordinates(new Vector2f(5, 5));
    Geometry floorGeom = new Geometry("Floor", floor);
    floorGeom.setMaterial(mat);
    floorGeom.setShadowMode(ShadowMode.Receive);
    rootNode.attachChild(floorGeom);
}
 
Example 3
Source File: TestUnshadedModel.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public void simpleInitApp() {
    Sphere sphMesh = new Sphere(32, 32, 1);
    sphMesh.setTextureMode(Sphere.TextureMode.Projected);
    sphMesh.updateGeometry(32, 32, 1, false, false);
    TangentBinormalGenerator.generate(sphMesh);

    Geometry sphere = new Geometry("Rock Ball", sphMesh);
    Material mat = assetManager.loadMaterial("Textures/Terrain/Pond/Pond.j3m");
    mat.setColor("Ambient", ColorRGBA.DarkGray);
    mat.setColor("Diffuse", ColorRGBA.White);
    mat.setBoolean("UseMaterialColors", true);
    sphere.setMaterial(mat);
    rootNode.attachChild(sphere);

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

    AmbientLight al = new AmbientLight();
    al.setColor(ColorRGBA.White);
    rootNode.addLight(al);
}
 
Example 4
Source File: TestSpotLight.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public void setupFloor(){
    Material mat = assetManager.loadMaterial("Textures/Terrain/Pond/Pond.j3m");
    mat.getTextureParam("DiffuseMap").getTextureValue().setWrap(WrapMode.Repeat);
    mat.getTextureParam("NormalMap").getTextureValue().setWrap(WrapMode.Repeat);
   // mat.getTextureParam("ParallaxMap").getTextureValue().setWrap(WrapMode.Repeat);
    mat.setFloat("Shininess",3);
  //  mat.setBoolean("VertexLighting", true);
    
    
    Box floor = new Box(50, 1f, 50);
    TangentBinormalGenerator.generate(floor);
    floor.scaleTextureCoordinates(new Vector2f(5, 5));
    Geometry floorGeom = new Geometry("Floor", floor);
    floorGeom.setMaterial(mat);
    floorGeom.setShadowMode(ShadowMode.Receive);
    rootNode.attachChild(floorGeom);
}
 
Example 5
Source File: TestSpotLightShadows.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public void setupFloor() {
    Material mat = assetManager.loadMaterial("Textures/Terrain/Pond/Pond.j3m");
    mat.getTextureParam("DiffuseMap").getTextureValue().setWrap(WrapMode.Repeat);
    mat.getTextureParam("NormalMap").getTextureValue().setWrap(WrapMode.Repeat);
    mat.setBoolean("UseMaterialColors", true);
    mat.setColor("Diffuse", ColorRGBA.White.clone());
    mat.setColor("Ambient", ColorRGBA.White.clone());
   // mat.setColor("Specular", ColorRGBA.White.clone());
    // mat.getTextureParam("ParallaxMap").getTextureValue().setWrap(WrapMode.Repeat);
    mat.setFloat("Shininess", 0);
    //  mat.setBoolean("VertexLighting", true);


    Box floor = new Box(50, 1f, 50);
    TangentBinormalGenerator.generate(floor);
    floor.scaleTextureCoordinates(new Vector2f(5, 5));
    Geometry floorGeom = new Geometry("Floor", floor);
    floorGeom.setMaterial(mat);
    floorGeom.setShadowMode(ShadowMode.Receive);
    rootNode.attachChild(floorGeom);
}
 
Example 6
Source File: TestNormalMapping.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Override
    public void simpleInitApp() {
        Sphere sphMesh = new Sphere(32, 32, 1);
        sphMesh.setTextureMode(Sphere.TextureMode.Projected);
        sphMesh.updateGeometry(32, 32, 1, false, false);
        TangentBinormalGenerator.generate(sphMesh);

        Geometry sphere = new Geometry("Rock Ball", sphMesh);
        Material mat = assetManager.loadMaterial("Textures/Terrain/Pond/Pond.j3m");
        sphere.setMaterial(mat);
        rootNode.attachChild(sphere);

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

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

//        DirectionalLight dl = new DirectionalLight();
//        dl.setDirection(new Vector3f(1,-1,1).normalizeLocal());
//        dl.setColor(new ColorRGBA(0.22f, 0.15f, 0.1f, 1.0f));
//        rootNode.addLight(dl);
    }
 
Example 7
Source File: TestEverything.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public void setupFloor(){
    Material mat = assetManager.loadMaterial("Textures/Terrain/BrickWall/BrickWall.j3m");
    mat.getTextureParam("DiffuseMap").getTextureValue().setWrap(WrapMode.Repeat);
    mat.getTextureParam("NormalMap").getTextureValue().setWrap(WrapMode.Repeat);
    mat.getTextureParam("ParallaxMap").getTextureValue().setWrap(WrapMode.Repeat);
    
    Box floor = new Box(Vector3f.ZERO, 50, 1f, 50);
    TangentBinormalGenerator.generate(floor);
    floor.scaleTextureCoordinates(new Vector2f(5, 5));
    Geometry floorGeom = new Geometry("Floor", floor);
    floorGeom.setMaterial(mat);
    floorGeom.setShadowMode(ShadowMode.Receive);
    rootNode.attachChild(floorGeom);
}
 
Example 8
Source File: TestParallax.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public void setupSignpost() {
    Spatial signpost = assetManager.loadModel("Models/Sign Post/Sign Post.mesh.xml");
    Material matSp = assetManager.loadMaterial("Models/Sign Post/Sign Post.j3m");
    TangentBinormalGenerator.generate(signpost);
    signpost.setMaterial(matSp);
    signpost.rotate(0, FastMath.HALF_PI, 0);
    signpost.setLocalTranslation(12, 23.5f, 30);
    signpost.setLocalScale(4);
    signpost.setShadowMode(ShadowMode.CastAndReceive);
    rootNode.attachChild(signpost);
}
 
Example 9
Source File: TestEverything.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public void setupFloor(){
    Material mat = assetManager.loadMaterial("Textures/Terrain/BrickWall/BrickWall.j3m");
    Box floor = new Box(50, 1f, 50);
    TangentBinormalGenerator.generate(floor);
    floor.scaleTextureCoordinates(new Vector2f(5, 5));
    Geometry floorGeom = new Geometry("Floor", floor);
    floorGeom.setMaterial(mat);
    floorGeom.setShadowMode(ShadowMode.Receive);
    rootNode.attachChild(floorGeom);
}
 
Example 10
Source File: TestNormalMapping.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public void simpleInitApp() {
    Sphere sphMesh = new Sphere(32, 32, 1);
    sphMesh.setTextureMode(Sphere.TextureMode.Projected);
    sphMesh.updateGeometry(32, 32, 1, false, false);
    TangentBinormalGenerator.generate(sphMesh);

    Geometry sphere = new Geometry("Rock Ball", sphMesh);
    Material mat = assetManager.loadMaterial("Textures/Terrain/Pond/Pond.j3m");
    sphere.setMaterial(mat);
    rootNode.attachChild(sphere);

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

    pl = new PointLight();
    pl.setColor(ColorRGBA.White);
    pl.setPosition(new Vector3f(0f, 0f, 4f));
    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 11
Source File: GenerateTangentsTool.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
protected Object doApplyTool(AbstractSceneExplorerNode rootNode) {
    Geometry geom = rootNode.getLookup().lookup(Geometry.class);
    Mesh mesh = geom.getMesh();
    if (mesh != null) {
        TangentBinormalGenerator.generate(mesh);
    }
    return true;
}
 
Example 12
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 13
Source File: TestSimpleLighting.java    From MikuMikuStudio with BSD 2-Clause "Simplified" 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", 12);
        mat.setBoolean("UseMaterialColors", true);

//        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);
    }
 
Example 14
Source File: TestLightScattering.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(55.35316f, -0.27061665f, 27.092093f));
        cam.setRotation(new Quaternion(0.010414706f, 0.9874893f, 0.13880467f, -0.07409228f));
//        cam.setDirection(new Vector3f(0,-0.5f,1.0f));
//        cam.setLocation(new Vector3f(0, 300, -500));
        //cam.setFrustumFar(1000);
        flyCam.setMoveSpeed(10);
        Material mat = assetManager.loadMaterial("Textures/Terrain/Rocky/Rocky.j3m");
        Spatial scene = assetManager.loadModel("Models/Terrain/Terrain.mesh.xml");
        TangentBinormalGenerator.generate(((Geometry)((Node)scene).getChild(0)).getMesh());
        scene.setMaterial(mat);
        scene.setShadowMode(ShadowMode.CastAndReceive);
        scene.setLocalScale(400);
        scene.setLocalTranslation(0, -10, -120);

        rootNode.attachChild(scene);

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

        DirectionalLight sun = new DirectionalLight();
        Vector3f lightDir = new Vector3f(-0.12f, -0.3729129f, 0.74847335f);
        sun.setDirection(lightDir);
        sun.setColor(ColorRGBA.White.clone().multLocal(2));
        scene.addLight(sun);

        PssmShadowRenderer pssmRenderer = new PssmShadowRenderer(assetManager,1024,4);
        pssmRenderer.setDirection(lightDir);
        pssmRenderer.setShadowIntensity(0.55f);
     //   viewPort.addProcessor(pssmRenderer);

        FilterPostProcessor fpp = new FilterPostProcessor(assetManager);
//        SSAOFilter ssaoFilter= new SSAOFilter(viewPort, new SSAOConfig(0.36f,1.8f,0.84f,0.16f,false,true));
//        fpp.addFilter(ssaoFilter);


//           Material mat2 = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
//        mat2.setTexture("ColorMap", assetManager.loadTexture("Interface/Logo/Monkey.jpg"));
//
//        Sphere lite=new Sphere(8, 8, 10.0f);
//        Geometry lightSphere=new Geometry("lightsphere", lite);
//        lightSphere.setMaterial(mat2);
        Vector3f lightPos = lightDir.multLocal(-3000);
//        lightSphere.setLocalTranslation(lightPos);
        // rootNode.attachChild(lightSphere);
        LightScatteringFilter filter = new LightScatteringFilter(lightPos);
        LightScatteringUI ui = new LightScatteringUI(inputManager, filter);
        fpp.addFilter(filter);
//fpp.setNumSamples(4);
        //fpp.addFilter(new RadialBlurFilter(0.3f,15.0f));
        //    SSAOUI ui=new SSAOUI(inputManager, ssaoFilter.getConfig());

        viewPort.addProcessor(fpp);
    }
 
Example 15
Source File: TestDirectionalLightShadow.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public void loadScene() {
    obj = new Spatial[2];
    // Setup first view


    mat = new Material[2];
    mat[0] = assetManager.loadMaterial("Common/Materials/RedColor.j3m");
    mat[1] = assetManager.loadMaterial("Textures/Terrain/Pond/Pond.j3m");
    mat[1].setBoolean("UseMaterialColors", true);
    mat[1].setColor("Ambient", ColorRGBA.White);
    mat[1].setColor("Diffuse", ColorRGBA.White.clone());


    obj[0] = new Geometry("sphere", new Sphere(30, 30, 2));
    obj[0].setShadowMode(ShadowMode.CastAndReceive);
    obj[1] = new Geometry("cube", new Box(1.0f, 1.0f, 1.0f));
    obj[1].setShadowMode(ShadowMode.CastAndReceive);
    TangentBinormalGenerator.generate(obj[1]);
    TangentBinormalGenerator.generate(obj[0]);

    Spatial t = obj[0].clone(false);
    t.setLocalScale(10f);
    t.setMaterial(mat[1]);
    rootNode.attachChild(t);
    t.setLocalTranslation(0, 25, 0);

    for (int i = 0; i < 60; i++) {
        t = obj[FastMath.nextRandomInt(0, obj.length - 1)].clone(false);
        t.setLocalScale(FastMath.nextRandomFloat() * 10f);
        t.setMaterial(mat[FastMath.nextRandomInt(0, mat.length - 1)]);
        rootNode.attachChild(t);
        t.setLocalTranslation(FastMath.nextRandomFloat() * 200f, FastMath.nextRandomFloat() * 30f + 20, 30f * (i + 2f));
    }

    Box b = new Box(1000, 2, 1000);
    b.scaleTextureCoordinates(new Vector2f(10, 10));
    ground = new Geometry("soil", b);
    ground.setLocalTranslation(0, 10, 550);
    matGroundU = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    matGroundU.setColor("Color", ColorRGBA.Green);


    matGroundL = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md");
    Texture grass = assetManager.loadTexture("Textures/Terrain/splat/grass.jpg");
    grass.setWrap(WrapMode.Repeat);
    matGroundL.setTexture("DiffuseMap", grass);

    ground.setMaterial(matGroundL);

    ground.setShadowMode(ShadowMode.CastAndReceive);
    rootNode.attachChild(ground);

    l = new DirectionalLight();
    //l.setDirection(new Vector3f(0.5973172f, -0.16583486f, 0.7846725f).normalizeLocal());
    l.setDirection(new Vector3f(-1, -1, -1));
    rootNode.addLight(l);


    al = new AmbientLight();
    al.setColor(ColorRGBA.White.mult(0.02f));
    rootNode.addLight(al);

    Spatial sky = SkyFactory.createSky(assetManager,
            "Scenes/Beach/FullskiesSunset0068.dds", EnvMapType.CubeMap);
    sky.setLocalScale(350);

    rootNode.attachChild(sky);
}
 
Example 16
Source File: TestTransparentShadow.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
 public void simpleInitApp() {
     cam.setLocation(new Vector3f(5.700248f, 6.161693f, 5.1404157f));
     cam.setRotation(new Quaternion(-0.09441641f, 0.8993388f, -0.24089815f, -0.35248178f));

     viewPort.setBackgroundColor(ColorRGBA.DarkGray);

     Quad q = new Quad(20, 20);
     q.scaleTextureCoordinates(Vector2f.UNIT_XY.mult(10));
     TangentBinormalGenerator.generate(q);
     Geometry geom = new Geometry("floor", q);
     Material mat = assetManager.loadMaterial("Textures/Terrain/Pond/Pond.j3m");
     geom.setMaterial(mat);

     geom.rotate(-FastMath.HALF_PI, 0, 0);
     geom.center();
     geom.setShadowMode(ShadowMode.CastAndReceive);
     rootNode.attachChild(geom);

     AmbientLight al = new AmbientLight();
     al.setColor(ColorRGBA.White.mult(0.7f));
     rootNode.addLight(al);

     DirectionalLight dl1 = new DirectionalLight();
     dl1.setDirection(new Vector3f(0, -1, 0.5f).normalizeLocal());
     dl1.setColor(ColorRGBA.White.mult(1.5f));
     rootNode.addLight(dl1);
     
     // create the geometry and attach it
     Spatial tree = assetManager.loadModel("Models/Tree/Tree.mesh.j3o");
     tree.setQueueBucket(Bucket.Transparent);
     tree.setShadowMode(ShadowMode.CastAndReceive);

     rootNode.attachChild(tree);

     // Uses Texture from jme3-test-data library!
     ParticleEmitter fire = new ParticleEmitter("Emitter", ParticleMesh.Type.Triangle, 30);
     Material mat_red = new Material(assetManager, "Common/MatDefs/Misc/Particle.j3md");
     mat_red.setTexture("Texture", assetManager.loadTexture("Effects/Explosion/flame.png"));
     fire.setShadowMode(ShadowMode.Cast);
     fire.setMaterial(mat_red);
     fire.setImagesX(2);
     fire.setImagesY(2); // 2x2 texture animation
     fire.setEndColor(new ColorRGBA(1f, 0f, 0f, 1f));   // red
     fire.setStartColor(new ColorRGBA(1f, 1f, 0f, 0.5f)); // yellow
     fire.getParticleInfluencer().setInitialVelocity(new Vector3f(0, 2, 0));
     fire.setStartSize(0.6f);
     fire.setEndSize(0.1f);
     fire.setGravity(0, 0, 0);
     fire.setLowLife(0.5f);
     fire.setHighLife(1.5f);
     fire.getParticleInfluencer().setVelocityVariation(0.3f);
     fire.setLocalTranslation(5.0f, 0, 1.0f);
     fire.setLocalScale(0.3f);
     fire.setQueueBucket(Bucket.Translucent);
     rootNode.attachChild(fire);

     Material mat2 = assetManager.loadMaterial("Common/Materials/RedColor.j3m");

     Geometry ball = new Geometry("sphere", new Sphere(16, 16, 0.5f));
     ball.setMaterial(mat2);
     ball.setShadowMode(ShadowMode.CastAndReceive);
     rootNode.attachChild(ball);
     ball.setLocalTranslation(-1.0f, 1.5f, 1.0f);

     final DirectionalLightShadowRenderer dlsRenderer = new DirectionalLightShadowRenderer(assetManager, 1024, 1);
     dlsRenderer.setLight(dl1);
     dlsRenderer.setLambda(0.55f);
     dlsRenderer.setShadowIntensity(0.8f);
     dlsRenderer.setShadowCompareMode(CompareMode.Software);
     dlsRenderer.setEdgeFilteringMode(EdgeFilteringMode.Nearest);
     dlsRenderer.displayDebug();
     viewPort.addProcessor(dlsRenderer);
     inputManager.addMapping("stabilize", new KeyTrigger(KeyInput.KEY_B));

     inputManager.addListener(new ActionListener() {
         @Override
         public void onAction(String name, boolean isPressed, float tpf) {
             if (name.equals("stabilize") && isPressed) {
                 dlsRenderer.setEnabledStabilization(!dlsRenderer.isEnabledStabilization()) ;
             }
         }
     }, "stabilize");
}
 
Example 17
Source File: HelloMaterial.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@Override
public void simpleInitApp() {

  /** A simple textured cube -- in good MIP map quality. */
  Box boxshape1 = new Box(new Vector3f(-3f,1.1f,0f), 1f,1f,1f);
  Geometry cube = new Geometry("My Textured Box", boxshape1);
  Material mat_stl = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
  Texture tex_ml = assetManager.loadTexture("Interface/Logo/Monkey.jpg");
  mat_stl.setTexture("ColorMap", tex_ml);
  cube.setMaterial(mat_stl);
  rootNode.attachChild(cube);

  /** A translucent/transparent texture, similar to a window frame. */
  Box boxshape3 = new Box(new Vector3f(0f,0f,0f), 1f,1f,0.01f);
  Geometry window_frame = new Geometry("window frame", boxshape3);
  Material mat_tt = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
  mat_tt.setTexture("ColorMap", assetManager.loadTexture("Textures/ColoredTex/Monkey.png"));
  mat_tt.getAdditionalRenderState().setBlendMode(BlendMode.Alpha);  // activate transparency
  window_frame.setQueueBucket(Bucket.Transparent);
  window_frame.setMaterial(mat_tt);
  rootNode.attachChild(window_frame);

  /** A cube with its base color "leaking" through a partially transparent texture */
  Box boxshape4 = new Box(new Vector3f(3f,-1f,0f), 1f,1f,1f);
  Geometry cube_leak = new Geometry("Leak-through color cube", boxshape4);
  Material mat_tl = new Material(assetManager, "Common/MatDefs/Misc/ColoredTextured.j3md");
  mat_tl.setTexture("ColorMap", assetManager.loadTexture("Textures/ColoredTex/Monkey.png"));
  mat_tl.setColor("Color", new ColorRGBA(1f,0f,1f, 1f)); // purple
  cube_leak.setMaterial(mat_tl);
  rootNode.attachChild(cube_leak);
  // cube_leak.setMaterial((Material) assetManager.loadAsset( "Materials/LeakThrough.j3m"));

  /** A bumpy rock with a shiny light effect. To make bumpy objects you must create a NormalMap. */
  Sphere rock = new Sphere(32,32, 2f);
  Geometry shiny_rock = new Geometry("Shiny rock", rock);
  rock.setTextureMode(Sphere.TextureMode.Projected); // better quality on spheres
  TangentBinormalGenerator.generate(rock);           // for lighting effect
  Material mat_lit = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md");
  mat_lit.setTexture("DiffuseMap", assetManager.loadTexture("Textures/Terrain/Pond/Pond.jpg"));
  mat_lit.setTexture("NormalMap", assetManager.loadTexture("Textures/Terrain/Pond/Pond_normal.png"));
  mat_lit.setFloat("Shininess", 5f); // [0,128]
  shiny_rock.setMaterial(mat_lit);
  shiny_rock.setLocalTranslation(0,2,-2); // Move it a bit
  shiny_rock.rotate(1.6f, 0, 0);          // Rotate it a bit
  rootNode.attachChild(shiny_rock);
  /** Must add a light to make the lit object visible! */
  DirectionalLight sun = new DirectionalLight();
  sun.setDirection(new Vector3f(1,0,-2).normalizeLocal());
  sun.setColor(ColorRGBA.White);
  rootNode.addLight(sun);

}
 
Example 18
Source File: TestTangentSpace.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@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);
}
 
Example 19
Source File: TestBatchNode.java    From MikuMikuStudio with BSD 2-Clause "Simplified" 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(Vector3f.ZERO, 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(Vector3f.ZERO, 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, 3, 0);


        dl=new DirectionalLight();
        dl.setColor(ColorRGBA.White.mult(2));
        dl.setDirection(new Vector3f(1, -1, -1));
        rootNode.addLight(dl);
        flyCam.setMoveSpeed(10);
    }
 
Example 20
Source File: TestGeometryBatch.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@Override
    public void simpleInitApp() {
        batch = new GeometryBatch("MyBatch");

        /**
         * A cube with a color "bleeding" through transparent texture. Uses
         * Texture from jme3-test-data library!
         */
        Box boxshape4 = new Box(Vector3f.ZERO, 1f, 1f, 1f);
        Geometry cube = new Geometry("cube1", boxshape4);
        Material mat = assetManager.loadMaterial("Textures/Terrain/Pond/Pond.j3m");        
//        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(Vector3f.ZERO, 1f, 1f, 1f);
        cube2 = new Geometry("cube2", box);
        cube.setLocalTranslation(3, 0, 0);
        cube2.setLocalTranslation(0, 3, 0);
        
        TangentBinormalGenerator.generate(cube);
        TangentBinormalGenerator.generate(cube2);


        batch.batch(cube,cube2);

        batchedCube1 = (BatchedGeometry) batch.getChild("cube1");
        batchedCube2 = (BatchedGeometry) batch.getChild("cube2");

        batch.setMaterial(mat);
        rootNode.attachChild(batch);


         dl=new DirectionalLight();
        dl.setColor(ColorRGBA.White.mult(2));
        dl.setDirection(new Vector3f(1, -1, -1));
        rootNode.addLight(dl);
        flyCam.setMoveSpeed(10);
    }