Package com.jme3.texture

Examples of com.jme3.texture.Texture


        mesh.updateBound();
        geom.setMesh(mesh);

        Material mat = new Material(mgr, "Common/MatDefs/Light/Lighting.j3md");
        mat.getAdditionalRenderState().setAlphaTest(true);
        Texture diffuseMap = atlas.getAtlasTexture("DiffuseMap");
        Texture normalMap = atlas.getAtlasTexture("NormalMap");
        Texture specularMap = atlas.getAtlasTexture("SpecularMap");
        if (diffuseMap != null) {
            mat.setTexture("DiffuseMap", diffuseMap);
        }
        if (normalMap != null) {
            mat.setTexture("NormalMap", normalMap);
View Full Code Here


        Material mat = geometry.getMaterial();
        if (mat == null || mat.getParam(mapName) == null || !(mat.getParam(mapName) instanceof MatParamTexture)) {
            return null;
        }
        MatParamTexture param = (MatParamTexture) mat.getParam(mapName);
        Texture texture = param.getTextureValue();
        if (texture == null) {
            return null;
        }
        return texture;
View Full Code Here

       
        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);
View Full Code Here

            String jmeParamName = matExt.getTextureMapping(aliasName);

            TextureKey texKey = new TextureKey(texturePath, false);
            texKey.setGenerateMips(true);
            texKey.setAsCube(false);
            Texture tex;
           
            try {
                tex = assetManager.loadTexture(texKey);
                tex.setWrap(WrapMode.Repeat);
            } catch (AssetNotFoundException ex){
                logger.log(Level.WARNING, "Cannot locate {0} for material {1}", new Object[]{texKey, key});
                tex = new Texture2D( PlaceholderAssets.getPlaceholderImage() );
                tex.setWrap(WrapMode.Repeat);
                tex.setKey(texKey);
            }
           
            material.setTexture(jmeParamName, tex);
        }
    }
View Full Code Here

        TextureKey texKey = new TextureKey(folderName + path, false);
        texKey.setGenerateMips(genMips);
        texKey.setAsCube(cubic);

        try {
            Texture loadedTexture = assetManager.loadTexture(texKey);
           
            textures[texUnit].setImage(loadedTexture.getImage());
            textures[texUnit].setMinFilter(loadedTexture.getMinFilter());
            textures[texUnit].setKey(loadedTexture.getKey());

            // XXX: Is this really neccessary?
            textures[texUnit].setWrap(WrapMode.Repeat);
            if (texName != null){
                textures[texUnit].setName(texName);
View Full Code Here

     * @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().get(0);
                    Texture loadedTexture = this.loadTexture(image, imaflag, blenderContext);
                    if (loadedTexture != null) {
                        result = loadedTexture;
                        this.applyColorbandAndColorFactors(tex, result.getImage(), blenderContext);
                    }
                }
View Full Code Here

     *             this exception is thrown when the blend file structure is
     *             somehow invalid or corrupted
     */
    protected Texture loadTexture(Structure imageStructure, int imaflag, BlenderContext blenderContext) throws BlenderFileException {
        LOGGER.log(Level.FINE, "Fetching texture with OMA = {0}", imageStructure.getOldMemoryAddress());
        Texture result = null;
        Image im = (Image) blenderContext.getLoadedFeature(imageStructure.getOldMemoryAddress(), LoadedFeatureDataType.LOADED_FEATURE);
        if (im == null) {
            String texturePath = imageStructure.getFieldValue("name").toString();
            Pointer pPackedFile = (Pointer) imageStructure.getFieldValue("packedfile");
            if (pPackedFile.isNull()) {
View Full Code Here

                throw new IllegalStateException("Unknown mipmap generation method: " + blenderContext.getBlenderKey().getMipmapGenerationMethod());
        }

        AssetManager assetManager = blenderContext.getAssetManager();
        name = name.replace('\\', '/');
        Texture result = null;

        if (name.startsWith("//")) {
            // This is a relative path, so try to find it relative to the .blend file
            String relativePath = name.substring(2);
            // Augument the path with blender key path
            BlenderKey blenderKey = blenderContext.getBlenderKey();
            int idx = blenderKey.getName().lastIndexOf('/');
            String blenderAssetFolder = blenderKey.getName().substring(0, idx != -1 ? idx : 0);
            String absoluteName = blenderAssetFolder + '/' + relativePath;
            // Directly try to load texture so AssetManager can report missing textures
            try {
                TextureKey key = new TextureKey(absoluteName);
                key.setAsCube(false);
                key.setFlipY(true);
                key.setGenerateMips(generateMipmaps);
                result = assetManager.loadTexture(key);
                result.setKey(key);
            } catch (AssetNotFoundException e) {
                LOGGER.fine(e.getLocalizedMessage());
            }
        } else {
            // This is a full path, try to truncate it until the file can be found
            // this works as the assetManager root is most probably a part of the
            // image path. E.g. AssetManager has a locator at c:/Files/ and the
            // texture path is c:/Files/Textures/Models/Image.jpg.
            // For this we create a list with every possible full path name from
            // the asset name to the root. Image.jpg, Models/Image.jpg,
            // Textures/Models/Image.jpg (bingo) etc.
            List<String> assetNames = new ArrayList<String>();
            String[] paths = name.split("\\/");
            StringBuilder sb = new StringBuilder(paths[paths.length - 1]);// the asset name
            assetNames.add(paths[paths.length - 1]);

            for (int i = paths.length - 2; i >= 0; --i) {
                sb.insert(0, '/');
                sb.insert(0, paths[i]);
                assetNames.add(0, sb.toString());
            }
            // Now try to locate the asset
            for (String assetName : assetNames) {
                try {
                    TextureKey key = new TextureKey(assetName);
                    key.setAsCube(false);
                    key.setFlipY(true);
                    key.setGenerateMips(generateMipmaps);
                    AssetInfo info = assetManager.locateAsset(key);
                    if (info != null) {
                        Texture texture = assetManager.loadTexture(key);
                        result = texture;
                        // Set key explicitly here if other ways fail
                        texture.setKey(key);
                        // If texture is found return it;
                        return result;
                    }
                } catch (AssetNotFoundException e) {
                    LOGGER.fine(e.getLocalizedMessage());
View Full Code Here

                if (entry.getValue().size() > 0) {
                    CombinedTexture combinedTexture = new CombinedTexture(entry.getKey().intValue(), !skyTexture);
                    for (TextureData textureData : entry.getValue()) {
                        int texflag = ((Number) textureData.mtex.getFieldValue("texflag")).intValue();
                        boolean negateTexture = (texflag & 0x04) != 0;
                        Texture texture = this.getTexture(textureData.textureStructure, textureData.mtex, blenderContext);
                        if (texture != null) {
                            int blendType = ((Number) textureData.mtex.getFieldValue("blendtype")).intValue();
                            float[] color = new float[] { ((Number) textureData.mtex.getFieldValue("r")).floatValue(), ((Number) textureData.mtex.getFieldValue("g")).floatValue(), ((Number) textureData.mtex.getFieldValue("b")).floatValue() };
                            float colfac = ((Number) textureData.mtex.getFieldValue("colfac")).floatValue();
                            TextureBlender textureBlender = TextureBlenderFactory.createTextureBlender(texture.getImage().getFormat(), texflag, negateTexture, blendType, diffuseColorArray, color, colfac);
                            combinedTexture.add(texture, textureBlender, textureData.uvCoordinatesType, textureData.projectionType, textureData.textureStructure, textureData.uvCoordinatesName, blenderContext);
                        }
                    }
                    if (combinedTexture.getTexturesCount() > 0) {
                        loadedTextures.add(combinedTexture);
                    }
                }
            }
        } else {
            LOGGER.fine("No textures optimisation applied.");
            int[] mappings = new int[] { MaterialContext.MTEX_COL, MaterialContext.MTEX_NOR, MaterialContext.MTEX_EMIT, MaterialContext.MTEX_SPEC, MaterialContext.MTEX_ALPHA, MaterialContext.MTEX_AMB };
            for (TextureData textureData : texturesList) {
                Texture texture = this.getTexture(textureData.textureStructure, textureData.mtex, blenderContext);
                if (texture != null) {
                    Number mapto = (Number) textureData.mtex.getFieldValue("mapto");
                    int texflag = ((Number) textureData.mtex.getFieldValue("texflag")).intValue();
                    boolean negateTexture = (texflag & 0x04) != 0;

                    for (int i = 0; i < mappings.length; ++i) {
                        if ((mappings[i] & mapto.intValue()) != 0) {
                            CombinedTexture combinedTexture = new CombinedTexture(mappings[i], !skyTexture);
                            int blendType = ((Number) textureData.mtex.getFieldValue("blendtype")).intValue();
                            float[] color = new float[] { ((Number) textureData.mtex.getFieldValue("r")).floatValue(), ((Number) textureData.mtex.getFieldValue("g")).floatValue(), ((Number) textureData.mtex.getFieldValue("b")).floatValue() };
                            float colfac = ((Number) textureData.mtex.getFieldValue("colfac")).floatValue();
                            TextureBlender textureBlender = TextureBlenderFactory.createTextureBlender(texture.getImage().getFormat(), texflag, negateTexture, blendType, diffuseColorArray, color, colfac);
                            combinedTexture.add(texture, textureBlender, textureData.uvCoordinatesType, textureData.projectionType, textureData.textureStructure, textureData.uvCoordinatesName, blenderContext);
                            if (combinedTexture.getTexturesCount() > 0) {// the added texture might not have been accepted (if for example loading generated textures is disabled)
                                loadedTextures.add(combinedTexture);
                            }
                        }
View Full Code Here

     *            the blender context
     */
    @SuppressWarnings("unchecked")
    public void flatten(Geometry geometry, Long geometriesOMA, LinkedHashMap<String, List<Vector2f>> userDefinedUVCoordinates, BlenderContext blenderContext) {
        Mesh mesh = geometry.getMesh();
        Texture previousTexture = null;
        UVCoordinatesType masterUVCoordinatesType = null;
        String masterUserUVSetName = null;
        for (TextureData textureData : textureDatas) {
            // decompress compressed textures (all will be merged into one texture anyway)
            if (textureDatas.size() > 1 && textureData.texture.getImage().getFormat().isCompressed()) {
View Full Code Here

TOP

Related Classes of com.jme3.texture.Texture

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.