Search in sources :

Example 21 with Type

use of com.jme3.effect.ParticleMesh.Type in project jmonkeyengine by jMonkeyEngine.

the class ImageTileLoader method getHeightMapAt.

/**
     * Lets you specify the type of images that are being loaded. All images
     * must be the same type.
     * @param imageType eg. BufferedImage.TYPE_USHORT_GRAY
     */
/*public void setImageType(int imageType) {
        this.imageType = imageType;
    }*/
/**
     * The ImageHeightmap that will parse the image type that you 
     * specify with setImageType().
     * @param customImageHeightmap must extend AbstractHeightmap
     */
/*public void setCustomImageHeightmap(ImageHeightmap customImageHeightmap) {
        if (!(customImageHeightmap instanceof AbstractHeightMap)) {
            throw new IllegalArgumentException("customImageHeightmap must be an AbstractHeightMap!");
        }
        this.customImageHeightmap = customImageHeightmap;
    }*/
private HeightMap getHeightMapAt(Vector3f location) {
    // HEIGHTMAP image (for the terrain heightmap)
    int x = (int) location.x;
    int z = (int) location.z;
    AbstractHeightMap heightmap = null;
    //BufferedImage im = null;
    String name = null;
    try {
        name = namer.getName(x, z);
        logger.log(Level.FINE, "Loading heightmap from file: {0}", name);
        final Texture texture = assetManager.loadTexture(new TextureKey(name));
        heightmap = new ImageBasedHeightMap(texture.getImage());
        /*if (assetInfo != null){
                InputStream in = assetInfo.openStream();
                im = ImageIO.read(in);
            } else {
                im = new BufferedImage(patchSize, patchSize, imageType);
                logger.log(Level.WARNING, "File: {0} not found, loading zero heightmap instead", name);
            }*/
        // CREATE HEIGHTMAP
        /*if (imageType == BufferedImage.TYPE_USHORT_GRAY) {
                heightmap = new Grayscale16BitHeightMap(im);
            } else if (imageType == BufferedImage.TYPE_3BYTE_BGR) {
                heightmap = new ImageBasedHeightMap(im);
            } else if (customImageHeightmap != null && customImageHeightmap instanceof AbstractHeightMap) {
                // If it gets here, it means you have specified a different image type, and you must
                // then also supply a custom image heightmap class that can parse that image into
                // a heightmap.
                customImageHeightmap.setImage(im);
                heightmap = (AbstractHeightMap) customImageHeightmap;
            } else {
                // error, no supported image format and no custom image heightmap specified
                if (customImageHeightmap == null)
                    logger.log(Level.SEVERE, "Custom image type specified [{0}] but no customImageHeightmap declared! Use setCustomImageHeightmap()",imageType);
                if (!(customImageHeightmap instanceof AbstractHeightMap))
                    logger.severe("customImageHeightmap must be an AbstractHeightMap!");
                return null;
            }*/
        heightmap.setHeightScale(1);
        heightmap.load();
    //} catch (IOException e) {
    //    e.printStackTrace();
    } catch (AssetNotFoundException e) {
        logger.log(Level.WARNING, "Asset {0} not found, loading zero heightmap instead", name);
    }
    return heightmap;
}
Also used : TextureKey(com.jme3.asset.TextureKey) AssetNotFoundException(com.jme3.asset.AssetNotFoundException) Texture(com.jme3.texture.Texture)

Example 22 with Type

use of com.jme3.effect.ParticleMesh.Type in project jmonkeyengine by jMonkeyEngine.

the class VREnvironment method atttach.

/**
     * Attach the VR environment to the given app state and application. 
     * This method should be called within the {@link AppState#stateAttached(com.jme3.app.state.AppStateManager) stateAttached(com.jme3.app.state.AppStateManager)} method 
     * from the app state.
     * @param appState the app state to attach.
     * @param application the application to attach.
     */
public void atttach(AppState appState, Application application) {
    this.application = application;
    this.app = appState;
    // Instanciate view manager
    if (vrBinding == VRConstants.SETTING_VRAPI_OPENVR_VALUE) {
        viewmanager = new VRViewManagerOpenVR(this);
    } else if (vrBinding == VRConstants.SETTING_VRAPI_OSVR_VALUE) {
        viewmanager = new VRViewManagerOSVR(this);
    } else {
        logger.severe("Cannot instanciate view manager, unknown VRAPI type: " + vrBinding);
    }
}
Also used : VRViewManagerOSVR(com.jme3.util.VRViewManagerOSVR) VRViewManagerOpenVR(com.jme3.util.VRViewManagerOpenVR)

Example 23 with Type

use of com.jme3.effect.ParticleMesh.Type in project jmonkeyengine by jMonkeyEngine.

the class GLRenderer method updateTexImageData.

/**
     * Uploads the given image to the GL driver.
     *
     * @param img The image to upload
     * @param type How the data in the image argument should be interpreted.
     * @param unit The texture slot to be used to upload the image, not important
     * @param scaleToPot If true, the image will be scaled to power-of-2 dimensions
     * before being uploaded.
     */
public void updateTexImageData(Image img, Texture.Type type, int unit, boolean scaleToPot) {
    int texId = img.getId();
    if (texId == -1) {
        // create texture
        gl.glGenTextures(intBuf1);
        texId = intBuf1.get(0);
        img.setId(texId);
        objManager.registerObject(img);
        statistics.onNewTexture();
    }
    // bind texture
    int target = convertTextureType(type, img.getMultiSamples(), -1);
    bindTextureAndUnit(target, img, unit);
    if (!img.hasMipmaps() && img.isGeneratedMipmapsRequired()) {
        if (!caps.contains(Caps.FrameBuffer) && gl2 != null) {
            gl2.glTexParameteri(target, GL2.GL_GENERATE_MIPMAP, GL.GL_TRUE);
            img.setMipmapsGenerated(true);
        } else {
        // For OpenGL3 and up.
        // We'll generate mipmaps via glGenerateMipmapEXT (see below)
        }
    } else if (img.hasMipmaps()) {
        // Image already has mipmaps, set the max level based on the 
        // number of mipmaps we have.
        gl.glTexParameteri(target, GL.GL_TEXTURE_MAX_LEVEL, img.getMipMapSizes().length - 1);
    } else {
        // Image does not have mipmaps and they are not required.
        // Specify that that the texture has no mipmaps.
        gl.glTexParameteri(target, GL.GL_TEXTURE_MAX_LEVEL, 0);
    }
    int imageSamples = img.getMultiSamples();
    if (imageSamples > 1) {
        if (img.getFormat().isDepthFormat()) {
            img.setMultiSamples(Math.min(limits.get(Limits.DepthTextureSamples), imageSamples));
        } else {
            img.setMultiSamples(Math.min(limits.get(Limits.ColorTextureSamples), imageSamples));
        }
    }
    // Check if graphics card doesn't support multisample textures
    if (!caps.contains(Caps.TextureMultisample)) {
        if (img.getMultiSamples() > 1) {
            throw new RendererException("Multisample textures are not supported by the video hardware");
        }
    }
    // Check if graphics card doesn't support depth textures
    if (img.getFormat().isDepthFormat() && !caps.contains(Caps.DepthTexture)) {
        throw new RendererException("Depth textures are not supported by the video hardware");
    }
    if (target == GL.GL_TEXTURE_CUBE_MAP) {
        // Check max texture size before upload
        int cubeSize = limits.get(Limits.CubemapSize);
        if (img.getWidth() > cubeSize || img.getHeight() > cubeSize) {
            throw new RendererException("Cannot upload cubemap " + img + ". The maximum supported cubemap resolution is " + cubeSize);
        }
        if (img.getWidth() != img.getHeight()) {
            throw new RendererException("Cubemaps must have square dimensions");
        }
    } else {
        int texSize = limits.get(Limits.TextureSize);
        if (img.getWidth() > texSize || img.getHeight() > texSize) {
            throw new RendererException("Cannot upload texture " + img + ". The maximum supported texture resolution is " + texSize);
        }
    }
    Image imageForUpload;
    if (scaleToPot) {
        imageForUpload = MipMapGenerator.resizeToPowerOf2(img);
    } else {
        imageForUpload = img;
    }
    if (target == GL.GL_TEXTURE_CUBE_MAP) {
        List<ByteBuffer> data = imageForUpload.getData();
        if (data.size() != 6) {
            logger.log(Level.WARNING, "Invalid texture: {0}\n" + "Cubemap textures must contain 6 data units.", img);
            return;
        }
        for (int i = 0; i < 6; i++) {
            texUtil.uploadTexture(imageForUpload, GL.GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, i, linearizeSrgbImages);
        }
    } else if (target == GLExt.GL_TEXTURE_2D_ARRAY_EXT) {
        if (!caps.contains(Caps.TextureArray)) {
            throw new RendererException("Texture arrays not supported by graphics hardware");
        }
        List<ByteBuffer> data = imageForUpload.getData();
        // -1 index specifies prepare data for 2D Array
        texUtil.uploadTexture(imageForUpload, target, -1, linearizeSrgbImages);
        for (int i = 0; i < data.size(); i++) {
            // upload each slice of 2D array in turn
            // this time with the appropriate index
            texUtil.uploadTexture(imageForUpload, target, i, linearizeSrgbImages);
        }
    } else {
        texUtil.uploadTexture(imageForUpload, target, 0, linearizeSrgbImages);
    }
    if (img.getMultiSamples() != imageSamples) {
        img.setMultiSamples(imageSamples);
    }
    if (caps.contains(Caps.FrameBuffer) || gl2 == null) {
        if (!img.hasMipmaps() && img.isGeneratedMipmapsRequired() && img.getData(0) != null) {
            glfbo.glGenerateMipmapEXT(target);
            img.setMipmapsGenerated(true);
        }
    }
    img.clearUpdateNeeded();
}
Also used : List(java.util.List) Image(com.jme3.texture.Image)

Example 24 with Type

use of com.jme3.effect.ParticleMesh.Type in project jmonkeyengine by jMonkeyEngine.

the class Spatial method write.

public void write(JmeExporter ex) throws IOException {
    OutputCapsule capsule = ex.getCapsule(this);
    capsule.write(name, "name", null);
    capsule.write(worldBound, "world_bound", null);
    capsule.write(cullHint, "cull_mode", CullHint.Inherit);
    capsule.write(batchHint, "batch_hint", BatchHint.Inherit);
    capsule.write(queueBucket, "queue", RenderQueue.Bucket.Inherit);
    capsule.write(shadowMode, "shadow_mode", ShadowMode.Inherit);
    capsule.write(localTransform, "transform", Transform.IDENTITY);
    capsule.write(localLights, "lights", null);
    capsule.writeSavableArrayList(new ArrayList(localOverrides), "overrides", null);
    // Shallow clone the controls array to convert its type.
    capsule.writeSavableArrayList(new ArrayList(controls), "controlsList", null);
    capsule.writeStringSavableMap(userData, "user_data", null);
}
Also used : SafeArrayList(com.jme3.util.SafeArrayList)

Example 25 with Type

use of com.jme3.effect.ParticleMesh.Type in project jmonkeyengine by jMonkeyEngine.

the class MultiPassLightingLogic method render.

@Override
public void render(RenderManager renderManager, Shader shader, Geometry geometry, LightList lights, int lastTexUnit) {
    Renderer r = renderManager.getRenderer();
    Uniform lightDir = shader.getUniform("g_LightDirection");
    Uniform lightColor = shader.getUniform("g_LightColor");
    Uniform lightPos = shader.getUniform("g_LightPosition");
    Uniform ambientColor = shader.getUniform("g_AmbientLightColor");
    boolean isFirstLight = true;
    boolean isSecondLight = false;
    getAmbientColor(lights, false, ambientLightColor);
    for (int i = 0; i < lights.size(); i++) {
        Light l = lights.get(i);
        if (l instanceof AmbientLight) {
            continue;
        }
        if (isFirstLight) {
            // set ambient color for first light only
            ambientColor.setValue(VarType.Vector4, ambientLightColor);
            isFirstLight = false;
            isSecondLight = true;
        } else if (isSecondLight) {
            ambientColor.setValue(VarType.Vector4, ColorRGBA.Black);
            // apply additive blending for 2nd and future lights
            r.applyRenderState(ADDITIVE_LIGHT);
            isSecondLight = false;
        }
        TempVars vars = TempVars.get();
        Quaternion tmpLightDirection = vars.quat1;
        Quaternion tmpLightPosition = vars.quat2;
        ColorRGBA tmpLightColor = vars.color;
        Vector4f tmpVec = vars.vect4f1;
        ColorRGBA color = l.getColor();
        tmpLightColor.set(color);
        tmpLightColor.a = l.getType().getId();
        lightColor.setValue(VarType.Vector4, tmpLightColor);
        switch(l.getType()) {
            case Directional:
                DirectionalLight dl = (DirectionalLight) l;
                Vector3f dir = dl.getDirection();
                //FIXME : there is an inconstency here due to backward
                //compatibility of the lighting shader.
                //The directional light direction is passed in the
                //LightPosition uniform. The lighting shader needs to be
                //reworked though in order to fix this.
                tmpLightPosition.set(dir.getX(), dir.getY(), dir.getZ(), -1);
                lightPos.setValue(VarType.Vector4, tmpLightPosition);
                tmpLightDirection.set(0, 0, 0, 0);
                lightDir.setValue(VarType.Vector4, tmpLightDirection);
                break;
            case Point:
                PointLight pl = (PointLight) l;
                Vector3f pos = pl.getPosition();
                float invRadius = pl.getInvRadius();
                tmpLightPosition.set(pos.getX(), pos.getY(), pos.getZ(), invRadius);
                lightPos.setValue(VarType.Vector4, tmpLightPosition);
                tmpLightDirection.set(0, 0, 0, 0);
                lightDir.setValue(VarType.Vector4, tmpLightDirection);
                break;
            case Spot:
                SpotLight sl = (SpotLight) l;
                Vector3f pos2 = sl.getPosition();
                Vector3f dir2 = sl.getDirection();
                float invRange = sl.getInvSpotRange();
                float spotAngleCos = sl.getPackedAngleCos();
                tmpLightPosition.set(pos2.getX(), pos2.getY(), pos2.getZ(), invRange);
                lightPos.setValue(VarType.Vector4, tmpLightPosition);
                //We transform the spot direction in view space here to save 5 varying later in the lighting shader
                //one vec4 less and a vec4 that becomes a vec3
                //the downside is that spotAngleCos decoding happens now in the frag shader.
                tmpVec.set(dir2.getX(), dir2.getY(), dir2.getZ(), 0);
                renderManager.getCurrentCamera().getViewMatrix().mult(tmpVec, tmpVec);
                tmpLightDirection.set(tmpVec.getX(), tmpVec.getY(), tmpVec.getZ(), spotAngleCos);
                lightDir.setValue(VarType.Vector4, tmpLightDirection);
                break;
            case Probe:
                break;
            default:
                throw new UnsupportedOperationException("Unknown type of light: " + l.getType());
        }
        vars.release();
        r.setShader(shader);
        renderMeshFromGeometry(r, geometry);
    }
    if (isFirstLight) {
        // Either there are no lights at all, or only ambient lights.
        // Render a dummy "normal light" so we can see the ambient color.
        ambientColor.setValue(VarType.Vector4, getAmbientColor(lights, false, ambientLightColor));
        lightColor.setValue(VarType.Vector4, ColorRGBA.BlackNoAlpha);
        lightPos.setValue(VarType.Vector4, NULL_DIR_LIGHT);
        r.setShader(shader);
        renderMeshFromGeometry(r, geometry);
    }
}
Also used : Quaternion(com.jme3.math.Quaternion) Uniform(com.jme3.shader.Uniform) TempVars(com.jme3.util.TempVars) SpotLight(com.jme3.light.SpotLight) ColorRGBA(com.jme3.math.ColorRGBA) Vector4f(com.jme3.math.Vector4f) DirectionalLight(com.jme3.light.DirectionalLight) SpotLight(com.jme3.light.SpotLight) Light(com.jme3.light.Light) PointLight(com.jme3.light.PointLight) AmbientLight(com.jme3.light.AmbientLight) DirectionalLight(com.jme3.light.DirectionalLight) Vector3f(com.jme3.math.Vector3f) Renderer(com.jme3.renderer.Renderer) PointLight(com.jme3.light.PointLight) AmbientLight(com.jme3.light.AmbientLight)

Aggregations

ArrayList (java.util.ArrayList)18 Structure (com.jme3.scene.plugins.blender.file.Structure)12 Vector3f (com.jme3.math.Vector3f)11 Pointer (com.jme3.scene.plugins.blender.file.Pointer)10 IOException (java.io.IOException)10 List (java.util.List)9 ColorRGBA (com.jme3.math.ColorRGBA)8 Texture (com.jme3.texture.Texture)8 Geometry (com.jme3.scene.Geometry)6 Image (com.jme3.texture.Image)6 BoundingBox (com.jme3.bounding.BoundingBox)5 BoundingSphere (com.jme3.bounding.BoundingSphere)5 Light (com.jme3.light.Light)5 TemporalMesh (com.jme3.scene.plugins.blender.meshes.TemporalMesh)5 Uniform (com.jme3.shader.Uniform)5 Material (com.jme3.material.Material)4 Quaternion (com.jme3.math.Quaternion)4 Transform (com.jme3.math.Transform)4 Mesh (com.jme3.scene.Mesh)4 BlenderFileException (com.jme3.scene.plugins.blender.file.BlenderFileException)4