Search in sources :

Example 1 with RenderManager

use of com.jme3.renderer.RenderManager in project jmonkeyengine by jMonkeyEngine.

the class LegacyApplication method initCamera.

/**
     * Creates the camera to use for rendering. Default values are perspective
     * projection with 45° field of view, with near and far values 1 and 1000
     * units respectively.
     */
private void initCamera() {
    cam = new Camera(settings.getWidth(), settings.getHeight());
    cam.setFrustumPerspective(45f, (float) cam.getWidth() / cam.getHeight(), 1f, 1000f);
    cam.setLocation(new Vector3f(0f, 0f, 10f));
    cam.lookAt(new Vector3f(0f, 0f, 0f), Vector3f.UNIT_Y);
    renderManager = new RenderManager(renderer);
    //Remy - 09/14/2010 setted the timer in the renderManager
    renderManager.setTimer(timer);
    if (prof != null) {
        renderManager.setAppProfiler(prof);
    }
    viewPort = renderManager.createMainView("Default", cam);
    viewPort.setClearFlags(true, true, true);
    // Create a new cam for the gui
    Camera guiCam = new Camera(settings.getWidth(), settings.getHeight());
    guiViewPort = renderManager.createPostView("Gui Default", guiCam);
    guiViewPort.setClearFlags(false, false, false);
}
Also used : Vector3f(com.jme3.math.Vector3f) Camera(com.jme3.renderer.Camera) RenderManager(com.jme3.renderer.RenderManager)

Example 2 with RenderManager

use of com.jme3.renderer.RenderManager in project jmonkeyengine by jMonkeyEngine.

the class AudioListenerState method render.

@Override
public void render(RenderManager rm) {
    if (!isEnabled() || listener == null) {
        return;
    }
    Vector3f lastLocation = listener.getLocation();
    Vector3f currentLocation = camera.getLocation();
    Vector3f velocity = listener.getVelocity();
    if (!lastLocation.equals(currentLocation)) {
        velocity.set(currentLocation).subtractLocal(lastLocation);
        velocity.multLocal(1f / lastTpf);
        listener.setLocation(currentLocation);
        listener.setVelocity(velocity);
    } else if (!velocity.equals(Vector3f.ZERO)) {
        listener.setVelocity(Vector3f.ZERO);
    }
    Quaternion lastRotation = listener.getRotation();
    Quaternion currentRotation = camera.getRotation();
    if (!lastRotation.equals(currentRotation)) {
        listener.setRotation(currentRotation);
    }
}
Also used : Quaternion(com.jme3.math.Quaternion) Vector3f(com.jme3.math.Vector3f)

Example 3 with RenderManager

use of com.jme3.renderer.RenderManager in project jmonkeyengine by jMonkeyEngine.

the class OpaqueComparatorTest method testSortByAll.

@Test
public void testSortByAll() {
    Material matBase1 = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md");
    Material matBase2 = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    Texture texBase = createTexture("BASE");
    texBase.getImage().setId(1);
    Texture tex1 = createTexture("1");
    tex1.getImage().setId(2);
    Texture tex2 = createTexture("2");
    tex2.getImage().setId(3);
    matBase1.setName("BASE");
    matBase1.selectTechnique(TechniqueDef.DEFAULT_TECHNIQUE_NAME, renderManager);
    matBase1.setBoolean("UseVertexColor", true);
    matBase1.setTexture("DiffuseMap", texBase);
    Material mat1100 = matBase1.clone();
    mat1100.setName("1100");
    mat1100.selectTechnique("PreShadow", renderManager);
    Material mat1101 = matBase1.clone();
    mat1101.setName("1101");
    mat1101.selectTechnique("PreShadow", renderManager);
    mat1101.setTexture("DiffuseMap", tex1);
    Material mat1102 = matBase1.clone();
    mat1102.setName("1102");
    mat1102.selectTechnique("PreShadow", renderManager);
    mat1102.setTexture("DiffuseMap", tex2);
    Material mat1110 = matBase1.clone();
    mat1110.setName("1110");
    mat1110.selectTechnique("PreShadow", renderManager);
    mat1110.setFloat("AlphaDiscardThreshold", 2f);
    Material mat1120 = matBase1.clone();
    mat1120.setName("1120");
    mat1120.selectTechnique("PreShadow", renderManager);
    mat1120.setBoolean("UseInstancing", true);
    Material mat1121 = matBase1.clone();
    mat1121.setName("1121");
    mat1121.selectTechnique("PreShadow", renderManager);
    mat1121.setBoolean("UseInstancing", true);
    mat1121.setTexture("DiffuseMap", tex1);
    Material mat1122 = matBase1.clone();
    mat1122.setName("1122");
    mat1122.selectTechnique("PreShadow", renderManager);
    mat1122.setBoolean("UseInstancing", true);
    mat1122.setTexture("DiffuseMap", tex2);
    Material mat1140 = matBase1.clone();
    mat1140.setName("1140");
    mat1140.selectTechnique("PreShadow", renderManager);
    mat1140.setFloat("AlphaDiscardThreshold", 2f);
    mat1140.setBoolean("UseInstancing", true);
    Material mat1200 = matBase1.clone();
    mat1200.setName("1200");
    mat1200.selectTechnique("PostShadow", renderManager);
    Material mat1210 = matBase1.clone();
    mat1210.setName("1210");
    mat1210.selectTechnique("PostShadow", renderManager);
    mat1210.setFloat("AlphaDiscardThreshold", 2f);
    Material mat1220 = matBase1.clone();
    mat1220.setName("1220");
    mat1220.selectTechnique("PostShadow", renderManager);
    mat1220.setBoolean("UseInstancing", true);
    Material mat2000 = matBase2.clone();
    mat2000.setName("2000");
    testSort(mat1100, mat1101, mat1102, mat1110, mat1120, mat1121, mat1122, mat1140, mat1200, mat1210, mat1220, mat2000);
}
Also used : Material(com.jme3.material.Material) Texture(com.jme3.texture.Texture) Test(org.junit.Test)

Example 4 with RenderManager

use of com.jme3.renderer.RenderManager in project jmonkeyengine by jMonkeyEngine.

the class OpaqueComparatorTest method testSort.

/**
     * Given a correctly sorted list of materials, check if the 
     * opaque comparator can sort a reversed list of them.
     * 
     * Each material will be cloned so that none of them will be equal to each other
     * in reference, forcing the comparator to compare the material sort ID.
     * 
     * E.g. for a list of materials A, B, C, the following list will be generated:
     * <pre>C, B, A, C, B, A, C, B, A</pre>, it should result in
     * <pre>A, A, A, B, B, B, C, C, C</pre>.
     * 
     * @param materials The pre-sorted list of materials to check sorting for.
     */
private void testSort(Material... materials) {
    GeometryList gl = new GeometryList(comparator);
    for (int g = 0; g < 5; g++) {
        for (int i = materials.length - 1; i >= 0; i--) {
            Geometry geom = new Geometry("geom", mesh);
            Material clonedMaterial = materials[i].clone();
            if (materials[i].getActiveTechnique() != null) {
                String techniqueName = materials[i].getActiveTechnique().getDef().getName();
                clonedMaterial.selectTechnique(techniqueName, renderManager);
            } else {
                clonedMaterial.selectTechnique(TechniqueDef.DEFAULT_TECHNIQUE_NAME, renderManager);
            }
            geom.setMaterial(clonedMaterial);
            gl.add(geom);
        }
    }
    gl.sort();
    for (int i = 0; i < gl.size(); i++) {
        Material mat = gl.get(i).getMaterial();
        String sortId = Integer.toHexString(mat.getSortId()).toUpperCase();
        System.out.print(sortId + "\t");
        System.out.println(mat);
    }
    Set<String> alreadySeen = new HashSet<String>();
    Material current = null;
    for (int i = 0; i < gl.size(); i++) {
        Material mat = gl.get(i).getMaterial();
        if (current == null) {
            current = mat;
        } else if (!current.getName().equals(mat.getName())) {
            assert !alreadySeen.contains(mat.getName());
            alreadySeen.add(current.getName());
            current = mat;
        }
    }
    for (int i = 0; i < materials.length; i++) {
        for (int g = 0; g < 5; g++) {
            int index = i * 5 + g;
            Material mat1 = gl.get(index).getMaterial();
            Material mat2 = materials[i];
            assert mat1.getName().equals(mat2.getName()) : mat1.getName() + " != " + mat2.getName() + " for index " + index;
        }
    }
}
Also used : Geometry(com.jme3.scene.Geometry) GeometryList(com.jme3.renderer.queue.GeometryList) Material(com.jme3.material.Material) HashSet(java.util.HashSet)

Example 5 with RenderManager

use of com.jme3.renderer.RenderManager in project jmonkeyengine by jMonkeyEngine.

the class LoadJ3mdTest method testShaderNodesMaterialDefLoading.

@Test
public void testShaderNodesMaterialDefLoading() {
    supportGlsl(100);
    material("testMatDef.j3md");
    material.selectTechnique("Default", renderManager);
    assertEquals(material.getActiveTechnique().getDef().getShaderNodes().size(), 2);
    Shader s = material.getActiveTechnique().getDef().getShader(TestUtil.createAssetManager(), myCaps, material.getActiveTechnique().getDynamicDefines());
    assertEquals(s.getSources().size(), 2);
}
Also used : Shader(com.jme3.shader.Shader) Test(org.junit.Test)

Aggregations

Material (com.jme3.material.Material)25 Camera (com.jme3.renderer.Camera)15 Renderer (com.jme3.renderer.Renderer)11 Vector3f (com.jme3.math.Vector3f)8 Texture2D (com.jme3.texture.Texture2D)5 DirectionalLight (com.jme3.light.DirectionalLight)4 Geometry (com.jme3.scene.Geometry)4 Picture (com.jme3.ui.Picture)4 TempVars (com.jme3.util.TempVars)4 Light (com.jme3.light.Light)3 PointLight (com.jme3.light.PointLight)3 SpotLight (com.jme3.light.SpotLight)3 Pass (com.jme3.post.Filter.Pass)3 RenderManager (com.jme3.renderer.RenderManager)3 Spatial (com.jme3.scene.Spatial)3 Shader (com.jme3.shader.Shader)3 FrameBuffer (com.jme3.texture.FrameBuffer)3 Texture (com.jme3.texture.Texture)3 Test (org.junit.Test)3 Technique (com.jme3.material.Technique)2