Package com.ardor3d.image

Examples of com.ardor3d.image.Texture


    @Override
    protected void initExample() {
        _canvas.setTitle("TestExportImport");

        final Texture bg = TextureManager.load("images/ardor3d_white_256.jpg", Texture.MinificationFilter.Trilinear,
                true);
        final TextureState bgts = new TextureState();
        bgts.setTexture(bg);
        bgts.setEnabled(true);

        final TextureState ts = new TextureState();
        final Texture t0 = TextureManager.load("images/ardor3d_white_256.jpg", Texture.MinificationFilter.Trilinear,
                true);
        final Texture t1 = TextureManager.load("images/flaresmall.jpg", Texture.MinificationFilter.Trilinear, true);
        t1.setEnvironmentalMapMode(Texture.EnvironmentalMapMode.SphereMap);
        ts.setTexture(t0, 0);
        ts.setTexture(t1, 1);
        ts.setEnabled(true);

        final Torus torus = new Torus("Torus", 50, 50, 10, 25);
View Full Code Here


                    mInfo.setTechnique(type);
                }
                final MaterialState mState = new MaterialState();

                // TODO: implement proper transparency handling
                Texture diffuseTexture = null;
                ColorRGBA transparent = new ColorRGBA(1.0f, 1.0f, 1.0f, 1.0f);
                float transparency = 1.0f;
                boolean useTransparency = false;
                String opaqueMode = "A_ONE";

                /*
                 * place holder for current property, we import material properties in fixed order (for texture order)
                 */
                Element property = null;
                /* Diffuse property */
                property = blinnPhongLambert.getChild("diffuse");
                if (property != null) {
                    final Element propertyValue = property.getChildren().get(0);
                    if ("color".equals(propertyValue.getName())) {
                        final ColorRGBA color = _colladaDOMUtil.getColor(propertyValue.getText());
                        mState.setDiffuse(MaterialFace.FrontAndBack, color);
                    } else if ("texture".equals(propertyValue.getName()) && _loadTextures) {
                        diffuseTexture = populateTextureState(mesh, propertyValue, effect, loadedTextures, mInfo,
                                "diffuse");
                    }
                }
                /* Ambient property */
                property = blinnPhongLambert.getChild("ambient");
                if (property != null) {
                    final Element propertyValue = property.getChildren().get(0);
                    if ("color".equals(propertyValue.getName())) {
                        final ColorRGBA color = _colladaDOMUtil.getColor(propertyValue.getText());
                        mState.setAmbient(MaterialFace.FrontAndBack, color);
                    } else if ("texture".equals(propertyValue.getName()) && _loadTextures) {
                        populateTextureState(mesh, propertyValue, effect, loadedTextures, mInfo, "ambient");
                    }
                }
                /* Transparent property */
                property = blinnPhongLambert.getChild("transparent");
                if (property != null) {
                    final Element propertyValue = property.getChildren().get(0);
                    if ("color".equals(propertyValue.getName())) {
                        transparent = _colladaDOMUtil.getColor(propertyValue.getText());
                        // TODO: use this
                        useTransparency = true;
                    } else if ("texture".equals(propertyValue.getName()) && _loadTextures) {
                        populateTextureState(mesh, propertyValue, effect, loadedTextures, mInfo, "transparent");
                    }
                    opaqueMode = property.getAttributeValue("opaque", "A_ONE");
                }
                /* Transparency property */
                property = blinnPhongLambert.getChild("transparency");
                if (property != null) {
                    final Element propertyValue = property.getChildren().get(0);
                    if ("float".equals(propertyValue.getName())) {
                        transparency = Float.parseFloat(propertyValue.getText().replace(",", "."));
                        // TODO: use this
                        if (_flipTransparency) {
                            transparency = 1f - transparency;
                        }
                        useTransparency = true;
                    } else if ("texture".equals(propertyValue.getName()) && _loadTextures) {
                        populateTextureState(mesh, propertyValue, effect, loadedTextures, mInfo, "transparency");
                    }
                }
                /* Emission property */
                property = blinnPhongLambert.getChild("emission");
                if (property != null) {
                    final Element propertyValue = property.getChildren().get(0);
                    if ("color".equals(propertyValue.getName())) {
                        mState.setEmissive(MaterialFace.FrontAndBack, _colladaDOMUtil.getColor(propertyValue.getText()));
                    } else if ("texture".equals(propertyValue.getName()) && _loadTextures) {
                        populateTextureState(mesh, propertyValue, effect, loadedTextures, mInfo, "emissive");
                    }
                }
                /* Specular property */
                property = blinnPhongLambert.getChild("specular");
                if (property != null) {
                    final Element propertyValue = property.getChildren().get(0);
                    if ("color".equals(propertyValue.getName())) {
                        mState.setSpecular(MaterialFace.FrontAndBack, _colladaDOMUtil.getColor(propertyValue.getText()));
                    } else if ("texture".equals(propertyValue.getName()) && _loadTextures) {
                        populateTextureState(mesh, propertyValue, effect, loadedTextures, mInfo, "specular");
                    }
                }
                /* Shininess property */
                property = blinnPhongLambert.getChild("shininess");
                if (property != null) {
                    final Element propertyValue = property.getChildren().get(0);
                    if ("float".equals(propertyValue.getName())) {
                        float shininess = Float.parseFloat(propertyValue.getText().replace(",", "."));
                        if (shininess >= 0.0f && shininess <= 1.0f) {
                            final float oldShininess = shininess;
                            shininess *= 128;
                            logger.finest("Shininess - " + oldShininess
                                    + " - was in the [0,1] range. Scaling to [0, 128] - " + shininess);
                        } else if (shininess < 0 || shininess > 128) {
                            final float oldShininess = shininess;
                            shininess = MathUtils.clamp(shininess, 0, 128);
                            logger.warning("Shininess must be between 0 and 128. Shininess " + oldShininess
                                    + " was clamped to " + shininess);
                        }
                        mState.setShininess(MaterialFace.FrontAndBack, shininess);
                    } else if ("texture".equals(propertyValue.getName()) && _loadTextures) {
                        populateTextureState(mesh, propertyValue, effect, loadedTextures, mInfo, "shininess");
                    }
                }
                /* Reflectivity property */
                float reflectivity = 1.0f;
                property = blinnPhongLambert.getChild("reflectivity");
                if (property != null) {
                    final Element propertyValue = property.getChildren().get(0);
                    if ("float".equals(propertyValue.getName())) {
                        reflectivity = Float.parseFloat(propertyValue.getText().replace(",", "."));
                    }
                }
                /* Reflective property. Texture only */
                property = blinnPhongLambert.getChild("reflective");
                if (property != null) {
                    final Element propertyValue = property.getChildren().get(0);
                    if ("texture".equals(propertyValue.getName()) && _loadTextures) {
                        final Texture reflectiveTexture = populateTextureState(mesh, propertyValue, effect,
                                loadedTextures, mInfo, "reflective");

                        reflectiveTexture.setEnvironmentalMapMode(Texture.EnvironmentalMapMode.SphereMap);
                        reflectiveTexture.setApply(ApplyMode.Combine);

                        reflectiveTexture.setCombineFuncRGB(CombinerFunctionRGB.Interpolate);
                        // color 1
                        reflectiveTexture.setCombineSrc0RGB(CombinerSource.CurrentTexture);
                        reflectiveTexture.setCombineOp0RGB(CombinerOperandRGB.SourceColor);
                        // color 2
                        reflectiveTexture.setCombineSrc1RGB(CombinerSource.Previous);
                        reflectiveTexture.setCombineOp1RGB(CombinerOperandRGB.SourceColor);
                        // interpolate param will come from alpha of constant color
                        reflectiveTexture.setCombineSrc2RGB(CombinerSource.Constant);
                        reflectiveTexture.setCombineOp2RGB(CombinerOperandRGB.SourceAlpha);

                        reflectiveTexture.setConstantColor(new ColorRGBA(1, 1, 1, reflectivity));
                    }
                }

                /*
                 * An extra tag defines some materials not part of the collada standard. Since we're not able to parse
View Full Code Here

            textureSlot = textureReference;
        }

        /* only add the texture to the state once */
        if (loadedTextures.containsKey(textureReference)) {
            final Texture tex = loadedTextures.get(textureReference);
            if (info != null) {
                info.setTextureSlot(textureSlot, textureReference, tex, null);
            }
            return tex;
        }

        Element node = _colladaDOMUtil.findTargetWithSid(textureReference);
        if (node == null) {
            // Not sure if this is quite right, but spec seems to indicate looking for global id
            node = _colladaDOMUtil.findTargetWithId("#" + textureReference);
        }

        if ("newparam".equals(node.getName())) {
            node = node.getChildren().get(0);
        }

        Element sampler = null;
        Element surface = null;
        Element image = null;

        Texture.MinificationFilter min = Texture.MinificationFilter.BilinearNoMipMaps;
        if ("sampler2D".equals(node.getName())) {
            sampler = node;
            if (sampler.getChild("minfilter") != null) {
                final String minfilter = sampler.getChild("minfilter").getText();
                min = Enum.valueOf(SamplerTypes.MinFilterType.class, minfilter).getArdor3dFilter();
            }
            // Use sampler to get correct surface
            node = _colladaDOMUtil.findTargetWithSid(sampler.getChild("source").getText());
            // node = resolveSid(effect, sampler.getSource());
        }

        if ("newparam".equals(node.getName())) {
            node = node.getChildren().get(0);
        }

        if ("surface".equals(node.getName())) {
            surface = node;
            // image(s) will come from surface.
        } else if ("image".equals(node.getName())) {
            image = node;
        }

        // Ok, a few possibilities here...
        Texture texture = null;
        String fileName = null;
        if (surface == null && image != null) {
            // Only an image found (no sampler). Assume 2d texture. Load.
            fileName = image.getChild("init_from").getText();
            texture = loadTexture2D(fileName, min);
View Full Code Here

    private Texture loadTexture2D(final String path, final Texture.MinificationFilter minFilter) {
        if (_dataCache.containsTexture(path)) {
            return _dataCache.getTexture(path);
        }

        final Texture texture;
        if (_importer.getTextureLocator() == null) {
            texture = TextureManager.load(path, minFilter, _compressTextures ? TextureStoreFormat.GuessCompressedFormat
                    : TextureStoreFormat.GuessNoCompressedFormat, true);
        } else {
            final ResourceSource source = _importer.getTextureLocator().locateResource(path);
View Full Code Here

TOP

Related Classes of com.ardor3d.image.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.