Search in sources :

Example 71 with Camera

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

the class WaterFilter method initFilter.

@Override
protected void initFilter(AssetManager manager, RenderManager renderManager, ViewPort vp, int w, int h) {
    if (reflectionScene == null) {
        reflectionScene = vp.getScenes().get(0);
        DirectionalLight l = findLight((Node) reflectionScene);
        if (l != null) {
            lightDirection = l.getDirection();
        }
    }
    this.renderManager = renderManager;
    this.viewPort = vp;
    reflectionPass = new Pass();
    reflectionPass.init(renderManager.getRenderer(), reflectionMapSize, reflectionMapSize, Format.RGBA8, Format.Depth);
    reflectionCam = new Camera(reflectionMapSize, reflectionMapSize);
    reflectionView = new ViewPort("reflectionView", reflectionCam);
    reflectionView.setClearFlags(true, true, true);
    reflectionView.attachScene(reflectionScene);
    reflectionView.setOutputFrameBuffer(reflectionPass.getRenderFrameBuffer());
    plane = new Plane(Vector3f.UNIT_Y, new Vector3f(0, waterHeight, 0).dot(Vector3f.UNIT_Y));
    reflectionProcessor = new ReflectionProcessor(reflectionCam, reflectionPass.getRenderFrameBuffer(), plane);
    reflectionProcessor.setReflectionClipPlane(plane);
    reflectionView.addProcessor(reflectionProcessor);
    normalTexture = (Texture2D) manager.loadTexture("Common/MatDefs/Water/Textures/water_normalmap.dds");
    if (foamTexture == null) {
        foamTexture = (Texture2D) manager.loadTexture("Common/MatDefs/Water/Textures/foam.jpg");
    }
    if (causticsTexture == null) {
        causticsTexture = (Texture2D) manager.loadTexture("Common/MatDefs/Water/Textures/caustics.jpg");
    }
    heightTexture = (Texture2D) manager.loadTexture("Common/MatDefs/Water/Textures/heightmap.jpg");
    normalTexture.setWrap(WrapMode.Repeat);
    foamTexture.setWrap(WrapMode.Repeat);
    causticsTexture.setWrap(WrapMode.Repeat);
    heightTexture.setWrap(WrapMode.Repeat);
    material = new Material(manager, "Common/MatDefs/Water/Water.j3md");
    material.setTexture("HeightMap", heightTexture);
    material.setTexture("CausticsMap", causticsTexture);
    material.setTexture("FoamMap", foamTexture);
    material.setTexture("NormalMap", normalTexture);
    material.setTexture("ReflectionMap", reflectionPass.getRenderedTexture());
    material.setFloat("WaterTransparency", waterTransparency);
    material.setFloat("NormalScale", normalScale);
    material.setFloat("R0", refractionConstant);
    material.setFloat("MaxAmplitude", maxAmplitude);
    material.setVector3("LightDir", lightDirection);
    material.setColor("LightColor", lightColor);
    material.setFloat("ShoreHardness", shoreHardness);
    material.setFloat("RefractionStrength", refractionStrength);
    material.setFloat("WaveScale", waveScale);
    material.setVector3("FoamExistence", foamExistence);
    material.setFloat("SunScale", sunScale);
    material.setVector3("ColorExtinction", colorExtinction);
    material.setFloat("Shininess", shininess);
    material.setColor("WaterColor", waterColor);
    material.setColor("DeepWaterColor", deepWaterColor);
    material.setVector2("WindDirection", windDirection);
    material.setFloat("FoamHardness", foamHardness);
    material.setBoolean("UseRipples", useRipples);
    material.setBoolean("UseHQShoreline", useHQShoreline);
    material.setBoolean("UseSpecular", useSpecular);
    material.setBoolean("UseFoam", useFoam);
    material.setBoolean("UseCaustics", useCaustics);
    material.setBoolean("UseRefraction", useRefraction);
    material.setFloat("ReflectionDisplace", reflectionDisplace);
    material.setFloat("FoamIntensity", foamIntensity);
    material.setFloat("UnderWaterFogDistance", underWaterFogDistance);
    material.setFloat("CausticsIntensity", causticsIntensity);
    if (center != null) {
        material.setVector3("Center", center);
        material.setFloat("Radius", radius * radius);
        material.setBoolean("SquareArea", shapeType == AreaShape.Square);
    }
    material.setFloat("WaterHeight", waterHeight);
}
Also used : Pass(com.jme3.post.Filter.Pass) DirectionalLight(com.jme3.light.DirectionalLight) ViewPort(com.jme3.renderer.ViewPort) Material(com.jme3.material.Material) Camera(com.jme3.renderer.Camera)

Example 72 with Camera

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

the class WaterUtils method updateReflectionCam.

public static void updateReflectionCam(Camera reflectionCam, Plane plane, Camera sceneCam) {
    TempVars vars = TempVars.get();
    //Temp vects for reflection cam orientation calculation
    Vector3f sceneTarget = vars.vect1;
    Vector3f reflectDirection = vars.vect2;
    Vector3f reflectUp = vars.vect3;
    Vector3f reflectLeft = vars.vect4;
    Vector3f camLoc = vars.vect5;
    camLoc = plane.reflect(sceneCam.getLocation(), camLoc);
    reflectionCam.setLocation(camLoc);
    reflectionCam.setFrustum(sceneCam.getFrustumNear(), sceneCam.getFrustumFar(), sceneCam.getFrustumLeft(), sceneCam.getFrustumRight(), sceneCam.getFrustumTop(), sceneCam.getFrustumBottom());
    reflectionCam.setParallelProjection(sceneCam.isParallelProjection());
    sceneTarget.set(sceneCam.getLocation()).addLocal(sceneCam.getDirection(vars.vect6));
    reflectDirection = plane.reflect(sceneTarget, reflectDirection);
    reflectDirection.subtractLocal(camLoc);
    sceneTarget.set(sceneCam.getLocation()).subtractLocal(sceneCam.getUp(vars.vect6));
    reflectUp = plane.reflect(sceneTarget, reflectUp);
    reflectUp.subtractLocal(camLoc);
    sceneTarget.set(sceneCam.getLocation()).addLocal(sceneCam.getLeft(vars.vect6));
    reflectLeft = plane.reflect(sceneTarget, reflectLeft);
    reflectLeft.subtractLocal(camLoc);
    reflectionCam.setAxes(reflectLeft, reflectUp, reflectDirection);
    vars.release();
}
Also used : Vector3f(com.jme3.math.Vector3f) TempVars(com.jme3.util.TempVars)

Example 73 with Camera

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

the class ObjectHelper method toObject.

/**
     * This method reads the given structure and createn an object that
     * represents the data.
     * 
     * @param objectStructure
     *            the object's structure
     * @param blenderContext
     *            the blender context
     * @return blener's object representation or null if its type is excluded from loading
     * @throws BlenderFileException
     *             an exception is thrown when the given data is inapropriate
     */
public Object toObject(Structure objectStructure, BlenderContext blenderContext) throws BlenderFileException {
    Object loadedResult = blenderContext.getLoadedFeature(objectStructure.getOldMemoryAddress(), LoadedDataType.FEATURE);
    if (loadedResult != null) {
        return loadedResult;
    }
    LOGGER.fine("Loading blender object.");
    if ("ID".equals(objectStructure.getType())) {
        Node object = (Node) this.loadLibrary(objectStructure);
        if (object.getParent() != null) {
            LOGGER.log(Level.FINEST, "Detaching object {0}, loaded from external file, from its parent.", object);
            object.getParent().detachChild(object);
        }
        return object;
    }
    int type = ((Number) objectStructure.getFieldValue("type")).intValue();
    ObjectType objectType = ObjectType.valueOf(type);
    LOGGER.log(Level.FINE, "Type of the object: {0}.", objectType);
    int lay = ((Number) objectStructure.getFieldValue("lay")).intValue();
    if ((lay & blenderContext.getBlenderKey().getLayersToLoad()) == 0) {
        LOGGER.fine("The layer this object is located in is not included in loading.");
        return null;
    }
    blenderContext.pushParent(objectStructure);
    String name = objectStructure.getName();
    LOGGER.log(Level.FINE, "Loading obejct: {0}", name);
    int restrictflag = ((Number) objectStructure.getFieldValue("restrictflag")).intValue();
    boolean visible = (restrictflag & 0x01) != 0;
    Pointer pParent = (Pointer) objectStructure.getFieldValue("parent");
    Object parent = blenderContext.getLoadedFeature(pParent.getOldMemoryAddress(), LoadedDataType.FEATURE);
    if (parent == null && pParent.isNotNull()) {
        Structure parentStructure = pParent.fetchData().get(0);
        parent = this.toObject(parentStructure, blenderContext);
    }
    Transform t = this.getTransformation(objectStructure, blenderContext);
    LOGGER.log(Level.FINE, "Importing object of type: {0}", objectType);
    Node result = null;
    try {
        switch(objectType) {
            case LATTICE:
            case METABALL:
            case TEXT:
            case WAVE:
                LOGGER.log(Level.WARNING, "{0} type is not supported but the node will be returned in order to keep parent - child relationship.", objectType);
            case EMPTY:
            case ARMATURE:
                // need to use an empty node to properly create
                // parent-children relationships between nodes
                result = new Node(name);
                break;
            case MESH:
                result = new Node(name);
                MeshHelper meshHelper = blenderContext.getHelper(MeshHelper.class);
                Pointer pMesh = (Pointer) objectStructure.getFieldValue("data");
                List<Structure> meshesArray = pMesh.fetchData();
                TemporalMesh temporalMesh = meshHelper.toTemporalMesh(meshesArray.get(0), blenderContext);
                if (temporalMesh != null) {
                    result.attachChild(temporalMesh);
                }
                break;
            case SURF:
            case CURVE:
                result = new Node(name);
                Pointer pCurve = (Pointer) objectStructure.getFieldValue("data");
                if (pCurve.isNotNull()) {
                    CurvesHelper curvesHelper = blenderContext.getHelper(CurvesHelper.class);
                    Structure curveData = pCurve.fetchData().get(0);
                    TemporalMesh curvesTemporalMesh = curvesHelper.toCurve(curveData, blenderContext);
                    if (curvesTemporalMesh != null) {
                        result.attachChild(curvesTemporalMesh);
                    }
                }
                break;
            case LAMP:
                Pointer pLamp = (Pointer) objectStructure.getFieldValue("data");
                if (pLamp.isNotNull()) {
                    LightHelper lightHelper = blenderContext.getHelper(LightHelper.class);
                    List<Structure> lampsArray = pLamp.fetchData();
                    Light light = lightHelper.toLight(lampsArray.get(0), blenderContext);
                    if (light == null) {
                        // probably some light type is not supported, just create a node so that we can maintain child-parent relationship for nodes
                        result = new Node(name);
                    } else {
                        result = new LightNode(name, light);
                    }
                }
                break;
            case CAMERA:
                Pointer pCamera = (Pointer) objectStructure.getFieldValue("data");
                if (pCamera.isNotNull()) {
                    CameraHelper cameraHelper = blenderContext.getHelper(CameraHelper.class);
                    List<Structure> camerasArray = pCamera.fetchData();
                    Camera camera = cameraHelper.toCamera(camerasArray.get(0), blenderContext);
                    if (camera == null) {
                        // just create a node so that we can maintain child-parent relationship for nodes
                        result = new Node(name);
                    } else {
                        result = new CameraNode(name, camera);
                    }
                }
                break;
            default:
                LOGGER.log(Level.WARNING, "Unsupported object type: {0}", type);
        }
        if (result != null) {
            LOGGER.fine("Storing loaded feature in blender context and applying markers (those will be removed before the final result is released).");
            Long oma = objectStructure.getOldMemoryAddress();
            blenderContext.addLoadedFeatures(oma, LoadedDataType.STRUCTURE, objectStructure);
            blenderContext.addLoadedFeatures(oma, LoadedDataType.FEATURE, result);
            blenderContext.addMarker(OMA_MARKER, result, objectStructure.getOldMemoryAddress());
            if (objectType == ObjectType.ARMATURE) {
                blenderContext.addMarker(ARMATURE_NODE_MARKER, result, Boolean.TRUE);
            }
            result.setLocalTransform(t);
            result.setCullHint(visible ? CullHint.Always : CullHint.Inherit);
            if (parent instanceof Node) {
                ((Node) parent).attachChild(result);
            }
            LOGGER.fine("Reading and applying object's modifiers.");
            ModifierHelper modifierHelper = blenderContext.getHelper(ModifierHelper.class);
            Collection<Modifier> modifiers = modifierHelper.readModifiers(objectStructure, blenderContext);
            for (Modifier modifier : modifiers) {
                modifier.apply(result, blenderContext);
            }
            if (result.getChildren() != null && result.getChildren().size() > 0) {
                if (result.getChildren().size() == 1 && result.getChild(0) instanceof TemporalMesh) {
                    LOGGER.fine("Converting temporal mesh into jme geometries.");
                    ((TemporalMesh) result.getChild(0)).toGeometries();
                }
                LOGGER.fine("Applying proper scale to the geometries.");
                for (Spatial child : result.getChildren()) {
                    if (child instanceof Geometry) {
                        this.flipMeshIfRequired((Geometry) child, child.getWorldScale());
                    }
                }
            }
            // I prefer do compute bounding box here than read it from the file
            result.updateModelBound();
            LOGGER.fine("Applying animations to the object if such are defined.");
            AnimationHelper animationHelper = blenderContext.getHelper(AnimationHelper.class);
            animationHelper.applyAnimations(result, blenderContext.getBlenderKey().getAnimationMatchMethod());
            LOGGER.fine("Loading constraints connected with this object.");
            ConstraintHelper constraintHelper = blenderContext.getHelper(ConstraintHelper.class);
            constraintHelper.loadConstraints(objectStructure, blenderContext);
            LOGGER.fine("Loading custom properties.");
            if (blenderContext.getBlenderKey().isLoadObjectProperties()) {
                Properties properties = this.loadProperties(objectStructure, blenderContext);
                // each value and set it to Spatial
                if (properties != null && properties.getValue() != null) {
                    this.applyProperties(result, properties);
                }
            }
        }
    } finally {
        blenderContext.popParent();
    }
    return result;
}
Also used : LightNode(com.jme3.scene.LightNode) Node(com.jme3.scene.Node) CameraNode(com.jme3.scene.CameraNode) CameraNode(com.jme3.scene.CameraNode) Pointer(com.jme3.scene.plugins.blender.file.Pointer) ModifierHelper(com.jme3.scene.plugins.blender.modifiers.ModifierHelper) LightNode(com.jme3.scene.LightNode) Light(com.jme3.light.Light) Camera(com.jme3.renderer.Camera) Structure(com.jme3.scene.plugins.blender.file.Structure) Modifier(com.jme3.scene.plugins.blender.modifiers.Modifier) CameraHelper(com.jme3.scene.plugins.blender.cameras.CameraHelper) AnimationHelper(com.jme3.scene.plugins.blender.animations.AnimationHelper) ConstraintHelper(com.jme3.scene.plugins.blender.constraints.ConstraintHelper) CullHint(com.jme3.scene.Spatial.CullHint) TemporalMesh(com.jme3.scene.plugins.blender.meshes.TemporalMesh) Geometry(com.jme3.scene.Geometry) Spatial(com.jme3.scene.Spatial) CurvesHelper(com.jme3.scene.plugins.blender.curves.CurvesHelper) Transform(com.jme3.math.Transform) LightHelper(com.jme3.scene.plugins.blender.lights.LightHelper) MeshHelper(com.jme3.scene.plugins.blender.meshes.MeshHelper)

Example 74 with Camera

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

the class LightProbeFactory method generatePbrMaps.

/**
     * Internally called to generate the maps.
     * This method will spawn 7 thread (one for the IrradianceMap, and one for each face of the prefiltered env map).
     * Those threads will be executed in a ScheduledThreadPoolExecutor that will be shutdown when the genration is done.
     * 
     * @param envMap the raw env map rendered by the env camera
     * @param probe the LigthProbe to generate maps for
     * @param app the Application
     * @param listener a progress listener. (can be null if no progress reporting is needed)
     */
private static void generatePbrMaps(TextureCubeMap envMap, final LightProbe probe, Application app, final JobProgressListener<LightProbe> listener) {
    IrradianceMapGenerator irrMapGenerator;
    PrefilteredEnvMapFaceGenerator[] pemGenerators = new PrefilteredEnvMapFaceGenerator[6];
    final JobState jobState = new JobState(new ScheduledThreadPoolExecutor(7));
    irrMapGenerator = new IrradianceMapGenerator(app, new JobListener(listener, jobState, probe, 6));
    int size = envMap.getImage().getWidth();
    irrMapGenerator.setGenerationParam(EnvMapUtils.duplicateCubeMap(envMap), size, EnvMapUtils.FixSeamsMethod.Wrap, probe.getIrradianceMap());
    jobState.executor.execute(irrMapGenerator);
    for (int i = 0; i < pemGenerators.length; i++) {
        pemGenerators[i] = new PrefilteredEnvMapFaceGenerator(app, i, new JobListener(listener, jobState, probe, i));
        pemGenerators[i].setGenerationParam(EnvMapUtils.duplicateCubeMap(envMap), size, EnvMapUtils.FixSeamsMethod.Wrap, probe.getPrefilteredEnvMap());
        jobState.executor.execute(pemGenerators[i]);
    }
}
Also used : IrradianceMapGenerator(com.jme3.environment.generation.IrradianceMapGenerator) ScheduledThreadPoolExecutor(java.util.concurrent.ScheduledThreadPoolExecutor) PrefilteredEnvMapFaceGenerator(com.jme3.environment.generation.PrefilteredEnvMapFaceGenerator)

Example 75 with Camera

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

the class EnvironmentCamera method createOffCamera.

/**
     * Creates an off camera
     *
     * @param mapSize the size
     * @param worldPos the position
     * @param axisX the x axis
     * @param axisY the y axis
     * @param axisZ tha z axis
     * @return
     */
protected Camera createOffCamera(final int mapSize, final Vector3f worldPos, final Vector3f axisX, final Vector3f axisY, final Vector3f axisZ) {
    final Camera offCamera = new Camera(mapSize, mapSize);
    offCamera.setLocation(worldPos);
    offCamera.setAxes(axisX, axisY, axisZ);
    offCamera.setFrustumPerspective(90f, 1f, 1, 1000);
    offCamera.setLocation(position);
    return offCamera;
}
Also used : Camera(com.jme3.renderer.Camera)

Aggregations

Camera (com.jme3.renderer.Camera)63 Vector3f (com.jme3.math.Vector3f)51 Material (com.jme3.material.Material)26 Geometry (com.jme3.scene.Geometry)26 Quaternion (com.jme3.math.Quaternion)23 Spatial (com.jme3.scene.Spatial)19 TempVars (com.jme3.util.TempVars)16 Box (com.jme3.scene.shape.Box)13 ViewPort (com.jme3.renderer.ViewPort)11 Node (com.jme3.scene.Node)11 DirectionalLight (com.jme3.light.DirectionalLight)10 FrameBuffer (com.jme3.texture.FrameBuffer)10 Texture (com.jme3.texture.Texture)10 FilterPostProcessor (com.jme3.post.FilterPostProcessor)9 Texture2D (com.jme3.texture.Texture2D)9 ArrayList (java.util.ArrayList)9 TerrainQuad (com.jme3.terrain.geomipmap.TerrainQuad)8 AbstractHeightMap (com.jme3.terrain.heightmap.AbstractHeightMap)8 ImageBasedHeightMap (com.jme3.terrain.heightmap.ImageBasedHeightMap)8 CameraNode (com.jme3.scene.CameraNode)7