Ejemplo n.º 1
0
        /**
         * Indicates the <i>texture</i> specified by this <i>effect</i>. The texture is specified by the <i>diffuse</i>
         * field of the shader specified by the <i>profile_COMMON</i> element.
         *
         * @return The texture specified by this effect, or null if the texture cannot be resolved.
         */
        public ColladaTexture getTexture()
        {
            ColladaProfileCommon profile = this.getProfileCommon();

            if (profile == null)
            {
                return(null);
            }

            ColladaTechnique technique = profile.getTechnique();

            if (technique == null)
            {
                return(null);
            }

            ColladaAbstractShader shader = technique.getShader();

            if (shader == null)
            {
                return(null);
            }

            ColladaTextureOrColor diffuse = shader.getDiffuse();

            if (diffuse == null)
            {
                return(null);
            }

            return(diffuse.getTexture());
        }
        protected void initializeParsers(String ns)
        {
            this.parsers.put(new QName(ns, "unit"), new ColladaUnit(ns));
            this.parsers.put(new QName(ns, "material"), new ColladaMaterial(ns));
            this.parsers.put(new QName(ns, "technique"), new ColladaTechnique(ns));
            this.parsers.put(new QName(ns, "surface"), new ColladaSurface(ns));
            this.parsers.put(new QName(ns, "format"), new ColladaFormat(ns));
            this.parsers.put(new QName(ns, "sampler2D"), new ColladaSampler2D(ns));
            this.parsers.put(new QName(ns, "source"), new ColladaSource(ns));
            this.parsers.put(new QName(ns, "param"), new ColladaParam(ns));
            this.parsers.put(new QName(ns, "float_array"), new ColladaFloatArray(ns));
            this.parsers.put(new QName(ns, "input"), new ColladaInput(ns));
            this.parsers.put(new QName(ns, "effect"), new ColladaEffect(ns));
            this.parsers.put(new QName(ns, "profile_COMMON"), new ColladaProfileCommon(ns));
            this.parsers.put(new QName(ns, "newparam"), new ColladaNewParam(ns));
            this.parsers.put(new QName(ns, "phong"), new ColladaPhong(ns));
            this.parsers.put(new QName(ns, "lambert"), new ColladaLambert(ns));
            this.parsers.put(new QName(ns, "mesh"), new ColladaMesh(ns));
            this.parsers.put(new QName(ns, "technique_COMMON"), new ColladaTechniqueCommon(ns));
            this.parsers.put(new QName(ns, "technique_common"), new ColladaTechniqueCommon(ns));
            this.parsers.put(new QName(ns, "accessor"), new ColladaAccessor(ns));
            this.parsers.put(new QName(ns, "p"), new ColladaP(ns));
            this.parsers.put(new QName(ns, "texture"), new ColladaTexture(ns));
            this.parsers.put(new QName(ns, "color"), new ColladaColor(ns));
            this.parsers.put(new QName(ns, "geometry"), new ColladaGeometry(ns));
            this.parsers.put(new QName(ns, "vertices"), new ColladaVertices(ns));
            this.parsers.put(new QName(ns, "bind"), new ColladaBind(ns));
            this.parsers.put(new QName(ns, "node"), new ColladaNode(ns));
            this.parsers.put(new QName(ns, "matrix"), new ColladaMatrix(ns));
            this.parsers.put(new QName(ns, "bind_material"), new ColladaBindMaterial(ns));
            this.parsers.put(new QName(ns, "bind_vertex_input"), new ColladaBindVertexInput(ns));
            this.parsers.put(new QName(ns, "scene"), new ColladaScene(ns));

            XMLEventParser parser = new ColladaTextureOrColor(ns);

            this.parsers.put(new QName(ns, "emission"), parser);
            this.parsers.put(new QName(ns, "ambient"), parser);
            this.parsers.put(new QName(ns, "diffuse"), parser);
            this.parsers.put(new QName(ns, "specular"), parser);
            this.parsers.put(new QName(ns, "transparent"), parser);

            parser = new ColladaFloatOrParam(ns);
            this.parsers.put(new QName(ns, "shininess"), parser);
            this.parsers.put(new QName(ns, "reflectivity"), parser);
            this.parsers.put(new QName(ns, "transparency"), parser);
            this.parsers.put(new QName(ns, "index_of_refraction"), parser);

            this.parsers.put(new QName(ns, "image"), new ColladaImage(ns));
            this.parsers.put(new QName(ns, "asset"), new ColladaAsset(ns));
            this.parsers.put(new QName(ns, "contributor"), new ColladaContributor(ns));

            this.parsers.put(new QName(ns, "library_geometries"), new ColladaLibrary <ColladaGeometry>(ns));
            this.parsers.put(new QName(ns, "library_effects"), new ColladaLibrary <ColladaEffect>(ns));
            this.parsers.put(new QName(ns, "library_images"), new ColladaLibrary <ColladaImage>(ns));
            this.parsers.put(new QName(ns, "library_materials"), new ColladaLibrary <ColladaMaterial>(ns));
            this.parsers.put(new QName(ns, "library_visual_scenes"), new ColladaLibrary <ColladaVisualScene>(ns));
            this.parsers.put(new QName(ns, "library_nodes"), new ColladaLibrary <ColladaNode>(ns));

            this.parsers.put(new QName(ns, "instance_visual_scene"), new ColladaInstanceVisualScene(ns));
            this.parsers.put(new QName(ns, "instance_geometry"), new ColladaInstanceGeometry(ns));
            this.parsers.put(new QName(ns, "instance_material"), new ColladaInstanceMaterial(ns));
            this.parsers.put(new QName(ns, "instance_effect"), new ColladaInstanceEffect(ns));
            this.parsers.put(new QName(ns, "instance_node"), new ColladaInstanceNode(ns));

            this.parsers.put(new QName(ns, "visual_scene"), new ColladaVisualScene(ns));
            this.parsers.put(new QName(ns, "triangles"), new ColladaTriangles(ns));
            this.parsers.put(new QName(ns, "lines"), new ColladaLines(ns));
            this.parsers.put(new QName(ns, "extra"), new ColladaExtra(ns));

            // The following elements are valid COLLADA markup, but are not used by World Wind.
            parser = new ColladaUnsupported(ns);
            this.parsers.put(new QName(ns, "library_cameras"), parser);
            this.parsers.put(new QName(ns, "instance_camera"), parser);
            this.parsers.put(new QName(ns, "camera"), parser);
            this.parsers.put(new QName(ns, "lookat"), parser);
            this.parsers.put(new QName(ns, "optics"), parser);
            this.parsers.put(new QName(ns, "perspective"), parser);
            this.parsers.put(new QName(ns, "orthographic"), parser);
            this.parsers.put(new QName(ns, "znear"), parser);
            this.parsers.put(new QName(ns, "zfar"), parser);
            this.parsers.put(new QName(ns, "xfov"), parser);
            this.parsers.put(new QName(ns, "yfov"), parser);
            this.parsers.put(new QName(ns, "aspect_ratio"), parser);

            this.addStringParsers(ns, StringFields);
            this.addDoubleParsers(ns, DoubleFields);
            this.addIntegerParsers(ns, IntegerFields);
            this.addBooleanParsers(ns, BooleanFields);
        }
Ejemplo n.º 3
0
        /**
         * Indicates the material specified by this effect. Material is specified by the shader in the <i>profile_COMMON</i>
         * element.
         *
         * @return The material for this effect, or null if the material cannot be resolved.
         */
        public Material getMaterial()
        {
            ColladaProfileCommon profile = this.getProfileCommon();

            if (profile == null)
            {
                return(null);
            }

            ColladaTechnique technique = profile.getTechnique();

            if (technique == null)
            {
                return(null);
            }

            ColladaAbstractShader shader = technique.getShader();

            if (shader == null)
            {
                return(null);
            }

            Color emission = null;
            Color ambient  = null;
            Color diffuse  = null;
            Color specular = null;

            ColladaTextureOrColor textureOrColor = shader.getEmission();

            if (textureOrColor != null)
            {
                emission = textureOrColor.getColor();
            }

            textureOrColor = shader.getAmbient();
            if (textureOrColor != null)
            {
                ambient = textureOrColor.getColor();
            }

            textureOrColor = shader.getSpecular();
            if (textureOrColor != null)
            {
                specular = textureOrColor.getColor();
            }

            textureOrColor = shader.getDiffuse();
            if (textureOrColor != null)
            {
                diffuse = textureOrColor.getColor();
            }

            // TODO what should be we do with materials that don't have Diffuse?
            if (diffuse == null)
            {
                return(null);
            }

            if (emission == null)
            {
                emission = new Color(0, 0, 0, diffuse.getAlpha());
            }
            if (ambient == null)
            {
                ambient = diffuse;
            }
            if (specular == null)
            {
                specular = new Color(255, 255, 255, diffuse.getAlpha());
            }

            return(new Material(specular, diffuse, ambient, emission, 1f));
        }