Java Code Examples for com.jme3.texture.Texture#setMinFilter()

The following examples show how to use com.jme3.texture.Texture#setMinFilter() . 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: TestCylinder.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public void simpleInitApp() {
    Cylinder t = new Cylinder(20, 50, 1, 2, true);
    Geometry geom = new Geometry("Cylinder", t);

    Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    TextureKey key = new TextureKey("Interface/Logo/Monkey.jpg", true);
    key.setGenerateMips(true);
    Texture tex = assetManager.loadTexture(key);
    tex.setMinFilter(Texture.MinFilter.Trilinear);
    mat.setTexture("ColorMap", tex);

    geom.setMaterial(mat);
    
    rootNode.attachChild(geom);
}
 
Example 2
Source File: TestAttachDriver.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public void setupFloor() {
    Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    TextureKey key = new TextureKey("Interface/Logo/Monkey.jpg", true);
    key.setGenerateMips(true);
    Texture tex = assetManager.loadTexture(key);
    tex.setMinFilter(Texture.MinFilter.Trilinear);
    mat.setTexture("ColorMap", tex);

    Box floor = new Box(100, 1f, 100);
    Geometry floorGeom = new Geometry("Floor", floor);
    floorGeom.setMaterial(mat);
    floorGeom.setLocalTranslation(new Vector3f(0f, -3, 0f));

    floorGeom.addControl(new RigidBodyControl(new MeshCollisionShape(floorGeom.getMesh()), 0));
    rootNode.attachChild(floorGeom);
    getPhysicsSpace().add(floorGeom);
}
 
Example 3
Source File: TestImageRaster.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private void convertAndPutImage(Image image, float posX, float posY) {
    Texture tex = new Texture2D(image);
    tex.setMagFilter(MagFilter.Nearest);
    tex.setMinFilter(MinFilter.NearestNoMipMaps);
    tex.setAnisotropicFilter(16);
    Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    mat.setTexture("ColorMap", tex);

    Quad q = new Quad(5, 5);
    Geometry g = new Geometry("quad", q);
    g.setLocalTranslation(posX, posY - 5, -0.0001f);
    g.setMaterial(mat);
    rootNode.attachChild(g);

    BitmapFont fnt = assetManager.loadFont("Interface/Fonts/Default.fnt");
    BitmapText txt = new BitmapText(fnt);
    txt.setBox(new Rectangle(0, 0, 5, 5));
    txt.setQueueBucket(RenderQueue.Bucket.Transparent);
    txt.setSize(0.5f);
    txt.setText(image.getFormat().name());
    txt.setLocalTranslation(posX, posY, 0);
    rootNode.attachChild(txt);
}
 
Example 4
Source File: TestCylinder.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Override
public void simpleInitApp() {
    Cylinder t = new Cylinder(20, 50, 1, 2, true);
    Geometry geom = new Geometry("Cylinder", t);

    Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    TextureKey key = new TextureKey("Interface/Logo/Monkey.jpg", true);
    key.setGenerateMips(true);
    Texture tex = assetManager.loadTexture(key);
    tex.setMinFilter(Texture.MinFilter.Trilinear);
    mat.setTexture("ColorMap", tex);

    geom.setMaterial(mat);
    
    rootNode.attachChild(geom);
}
 
Example 5
Source File: TestAttachDriver.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public void setupFloor() {
    Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    TextureKey key = new TextureKey("Interface/Logo/Monkey.jpg", true);
    key.setGenerateMips(true);
    Texture tex = assetManager.loadTexture(key);
    tex.setMinFilter(Texture.MinFilter.Trilinear);
    mat.setTexture("ColorMap", tex);

    Box floor = new Box(Vector3f.ZERO, 100, 1f, 100);
    Geometry floorGeom = new Geometry("Floor", floor);
    floorGeom.setMaterial(mat);
    floorGeom.setLocalTranslation(new Vector3f(0f, -3, 0f));

    floorGeom.addControl(new RigidBodyControl(new MeshCollisionShape(floorGeom.getMesh()), 0));
    rootNode.attachChild(floorGeom);
    getPhysicsSpace().add(floorGeom);
}
 
Example 6
Source File: TestAnisotropicFilter.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private static Material createCheckerBoardMaterial(AssetManager assetManager) {
    Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    Texture tex = createCheckerBoardTexture(); // assetManager.loadTexture("Textures/Terrain/BrickWall/BrickWall.dds");
    tex.setMagFilter(Texture.MagFilter.Bilinear);
    tex.setMinFilter(Texture.MinFilter.Trilinear);
    tex.setWrap(Texture.WrapMode.Repeat);
    mat.setTexture("ColorMap", tex);
    return mat;
}
 
Example 7
Source File: AndroidAssetManager.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * Loads a texture. 
 *
 * @return
 */
@Override
public Texture loadTexture(TextureKey key) {
    Texture tex = (Texture) loadAsset(key);

    // Needed for Android
    tex.setMagFilter(Texture.MagFilter.Nearest);
    tex.setAnisotropicFilter(0);
    if (tex.getMinFilter().usesMipMapLevels()) {
        tex.setMinFilter(Texture.MinFilter.NearestNearestMipMap);
    } else {
        tex.setMinFilter(Texture.MinFilter.NearestNoMipMaps);
    }
    return tex;
}
 
Example 8
Source File: TestMipMapGen.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
    public void simpleInitApp() {
        BitmapText txt = guiFont.createLabel("Left: HW Mips");
        txt.setLocalTranslation(0, settings.getHeight() - txt.getLineHeight() * 4, 0);
        guiNode.attachChild(txt);

        txt = guiFont.createLabel("Right: AWT Mips");
        txt.setLocalTranslation(0, settings.getHeight() - txt.getLineHeight() * 3, 0);
        guiNode.attachChild(txt);

        // create a simple plane/quad
        Quad quadMesh = new Quad(1, 1);
        quadMesh.updateGeometry(1, 1, false);
        quadMesh.updateBound();

        Geometry quad1 = new Geometry("Textured Quad", quadMesh);
        Geometry quad2 = new Geometry("Textured Quad 2", quadMesh);

        Texture tex = assetManager.loadTexture("Interface/Logo/Monkey.png");
        tex.setMinFilter(Texture.MinFilter.Trilinear);

        Texture texCustomMip = tex.clone();
        Image imageCustomMip = texCustomMip.getImage().clone();
        MipMapGenerator.generateMipMaps(imageCustomMip);
        texCustomMip.setImage(imageCustomMip);

        Material mat1 = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
        mat1.setTexture("ColorMap", tex);

        Material mat2 = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
        mat2.setTexture("ColorMap", texCustomMip);

        quad1.setMaterial(mat1);
//        quad1.setLocalTranslation(1, 0, 0);

        quad2.setMaterial(mat2);
        quad2.setLocalTranslation(1, 0, 0);

        rootNode.attachChild(quad1);
        rootNode.attachChild(quad2);
    }
 
Example 9
Source File: TestMaterialWrite.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Test
public void testWriteMat() throws Exception {

    Material mat = new Material(assetManager,"Common/MatDefs/Light/Lighting.j3md");

    mat.setBoolean("UseMaterialColors", true);
    mat.setColor("Diffuse", ColorRGBA.White);
    mat.setColor("Ambient", ColorRGBA.DarkGray);
    mat.setFloat("AlphaDiscardThreshold", 0.5f);

    mat.setFloat("Shininess", 2.5f);

    Texture tex = assetManager.loadTexture("Common/Textures/MissingTexture.png");
    tex.setMagFilter(Texture.MagFilter.Nearest);
    tex.setMinFilter(Texture.MinFilter.BilinearNoMipMaps);
    tex.setWrap(Texture.WrapAxis.S, Texture.WrapMode.Repeat);
    tex.setWrap(Texture.WrapAxis.T, Texture.WrapMode.MirroredRepeat);

    mat.setTexture("DiffuseMap", tex);
    mat.getAdditionalRenderState().setDepthWrite(false);
    mat.getAdditionalRenderState().setDepthTest(false);
    mat.getAdditionalRenderState().setLineWidth(5);
    mat.getAdditionalRenderState().setBlendMode(RenderState.BlendMode.Alpha);

    final ByteArrayOutputStream stream = new ByteArrayOutputStream();

    J3MExporter exporter = new J3MExporter();
    try {
        exporter.save(mat, stream);
    } catch (IOException e) {
        e.printStackTrace();
    }

    System.err.println(stream.toString());

    J3MLoader loader = new J3MLoader();
    AssetInfo info = new AssetInfo(assetManager, new AssetKey("test")) {
        @Override
        public InputStream openStream() {
            return new ByteArrayInputStream(stream.toByteArray());
        }
    };
    Material mat2 = (Material)loader.load(info);

    assertTrue(mat.contentEquals(mat2));
}
 
Example 10
Source File: TextureHelper.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 4 votes vote down vote up
/**
 * This class returns a texture read from the file or from packed blender
 * data. The returned texture has the name set to the value of its blender
 * type.
 * 
 * @param tex
 *            texture structure filled with data
 * @param blenderContext
 *            the blender context
 * @return the texture that can be used by JME engine
 * @throws BlenderFileException
 *             this exception is thrown when the blend file structure is
 *             somehow invalid or corrupted
 */
public Texture getTexture(Structure tex, Structure mTex, BlenderContext blenderContext) throws BlenderFileException {
    Texture result = (Texture) blenderContext.getLoadedFeature(tex.getOldMemoryAddress(), LoadedFeatureDataType.LOADED_FEATURE);
    if (result != null) {
        return result;
    }
    int type = ((Number) tex.getFieldValue("type")).intValue();
    int imaflag = ((Number) tex.getFieldValue("imaflag")).intValue();

    switch (type) {
        case TEX_IMAGE:// (it is first because probably this will be most commonly used)
            Pointer pImage = (Pointer) tex.getFieldValue("ima");
            if (pImage.isNotNull()) {
                Structure image = pImage.fetchData(blenderContext.getInputStream()).get(0);
                Texture loadedTexture = this.loadTexture(image, imaflag, blenderContext);
                if (loadedTexture != null) {
                    result = loadedTexture;
                    this.applyColorbandAndColorFactors(tex, result.getImage(), blenderContext);
                }
            }
            break;
        case TEX_CLOUDS:
        case TEX_WOOD:
        case TEX_MARBLE:
        case TEX_MAGIC:
        case TEX_BLEND:
        case TEX_STUCCI:
        case TEX_NOISE:
        case TEX_MUSGRAVE:
        case TEX_VORONOI:
        case TEX_DISTNOISE:
            result = new GeneratedTexture(tex, mTex, textureGeneratorFactory.createTextureGenerator(type), blenderContext);
            break;
        case TEX_NONE:// No texture, do nothing
            break;
        case TEX_POINTDENSITY:
        case TEX_VOXELDATA:
        case TEX_PLUGIN:
        case TEX_ENVMAP:
            LOGGER.log(Level.WARNING, "Unsupported texture type: {0} for texture: {1}", new Object[] { type, tex.getName() });
            break;
        default:
            throw new BlenderFileException("Unknown texture type: " + type + " for texture: " + tex.getName());
    }
    if (result != null) {
        result.setName(tex.getName());
        result.setWrap(WrapMode.Repeat);

        // decide if the mipmaps will be generated
        switch (blenderContext.getBlenderKey().getMipmapGenerationMethod()) {
            case ALWAYS_GENERATE:
                result.setMinFilter(MinFilter.Trilinear);
                break;
            case NEVER_GENERATE:
                break;
            case GENERATE_WHEN_NEEDED:
                if ((imaflag & 0x04) != 0) {
                    result.setMinFilter(MinFilter.Trilinear);
                }
                break;
            default:
                throw new IllegalStateException("Unknown mipmap generation method: " + blenderContext.getBlenderKey().getMipmapGenerationMethod());
        }

        if (type != TEX_IMAGE) {// only generated textures should have this key
            result.setKey(new GeneratedTextureKey(tex.getName()));
        }

        if (LOGGER.isLoggable(Level.FINE)) {
            LOGGER.log(Level.FINE, "Adding texture {0} to the loaded features with OMA = {1}", new Object[] { result.getName(), tex.getOldMemoryAddress() });
        }
        blenderContext.addLoadedFeatures(tex.getOldMemoryAddress(), tex.getName(), tex, result);
    }
    return result;
}
 
Example 11
Source File: TestMipMapGen.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@Override
    public void simpleInitApp() {
        BitmapText txt = guiFont.createLabel("Left: HW Mips");
        txt.setLocalTranslation(0, settings.getHeight() - txt.getLineHeight() * 4, 0);
        guiNode.attachChild(txt);

        txt = guiFont.createLabel("Right: AWT Mips");
        txt.setLocalTranslation(0, settings.getHeight() - txt.getLineHeight() * 3, 0);
        guiNode.attachChild(txt);

        // create a simple plane/quad
        Quad quadMesh = new Quad(1, 1);
        quadMesh.updateGeometry(1, 1, false);
        quadMesh.updateBound();

        Geometry quad1 = new Geometry("Textured Quad", quadMesh);
        Geometry quad2 = new Geometry("Textured Quad 2", quadMesh);

        Texture tex = assetManager.loadTexture("Interface/Logo/Monkey.png");
        tex.setMinFilter(Texture.MinFilter.Trilinear);

        Texture texCustomMip = tex.clone();
        Image imageCustomMip = texCustomMip.getImage().clone();
        MipMapGenerator.generateMipMaps(imageCustomMip);
        texCustomMip.setImage(imageCustomMip);

        Material mat1 = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
        mat1.setTexture("ColorMap", tex);

        Material mat2 = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
        mat2.setTexture("ColorMap", texCustomMip);

        quad1.setMaterial(mat1);
//        quad1.setLocalTranslation(1, 0, 0);

        quad2.setMaterial(mat2);
        quad2.setLocalTranslation(1, 0, 0);

        rootNode.attachChild(quad1);
        rootNode.attachChild(quad2);
    }
 
Example 12
Source File: J3MLoader.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 2 votes vote down vote up
@Override
public void applyToTexture(final String option, final Texture texture) {
    texture.setMinFilter(Texture.MinFilter.valueOf(option));
}