Java 类com.badlogic.gdx.graphics.g3d.model.data.ModelMaterial 实例源码

项目:libgdxcn    文件:ModelLoader.java   
@Override
public Array<AssetDescriptor> getDependencies (String fileName, FileHandle file, P parameters) {
    final Array<AssetDescriptor> deps = new Array();
    ModelData data = loadModelData(file, parameters);
    if (data == null) return deps;

    ObjectMap.Entry<String, ModelData> item = new ObjectMap.Entry<String, ModelData>();
    item.key = fileName;
    item.value = data;
    synchronized (items) {
        items.add(item);
    }

    TextureLoader.TextureParameter textureParameter = (parameters != null)
            ? parameters.textureParameter
            : defaultParameters.textureParameter;

    for (final ModelMaterial modelMaterial : data.materials) {
        if (modelMaterial.textures != null) {
            for (final ModelTexture modelTexture : modelMaterial.textures)
                deps.add(new AssetDescriptor(modelTexture.fileName, Texture.class, textureParameter));
        }
    }
    return deps;
}
项目:nhglib    文件:NhgModelLoader.java   
@Override
public Array<AssetDescriptor> getDependencies(String fileName, FileHandle file, P parameters) {
    final Array<AssetDescriptor> deps = new Array();
    ModelData data = loadModelData(file, parameters);
    if (data == null) return deps;

    ObjectMap.Entry<String, ModelData> item = new ObjectMap.Entry<String, ModelData>();
    item.key = fileName;
    item.value = data;

    synchronized (items) {
        items.add(item);
    }

    TextureLoader.TextureParameter textureParameter = (parameters != null)
            ? parameters.textureParameter
            : defaultParameters.textureParameter;

    for (final ModelMaterial modelMaterial : data.materials) {
        if (modelMaterial.textures != null) {
            for (final ModelTexture modelTexture : modelMaterial.textures) {
                String fName = modelTexture.fileName;

                if (fName.contains("/")) {
                    fName = fName.substring(fName.lastIndexOf("/") + 1);
                }

                deps.add(new AssetDescriptor(currentAsset.dependenciesPath + fName, Texture.class, textureParameter));
            }
        }
    }

    return deps;
}
项目:libgdxcn    文件:ObjLoader.java   
public ModelMaterial getMaterial (final String name) {
    for (final ModelMaterial m : materials)
        if (m.id.equals(name)) return m;
    ModelMaterial mat = new ModelMaterial();
    mat.id = name;
    mat.diffuse = new Color(Color.WHITE);
    materials.add(mat);
    return mat;
}
项目:gaiasky    文件:ObjLoader.java   
public ModelMaterial getMaterial(final String name) {
    for (final ModelMaterial m : materials)
        if (m.id.equals(name))
            return m;
    ModelMaterial mat = new ModelMaterial();
    mat.id = name;
    mat.diffuse = new Color(Color.WHITE);
    materials.add(mat);
    return mat;
}
项目:Mundus    文件:MG3dModelLoader.java   
private void parseMaterials(ModelData model, JsonValue json, String materialDir) {
    JsonValue materials = json.get("materials");
    if (materials == null) {
        // we should probably create some default material in this case
    } else {
        model.materials.ensureCapacity(materials.size);
        for (JsonValue material = materials.child; material != null; material = material.next) {
            ModelMaterial jsonMaterial = new ModelMaterial();

            String id = material.getString("id", null);
            if (id == null) throw new GdxRuntimeException("Material needs an id.");

            jsonMaterial.id = id;

            // Read material colors
            final JsonValue diffuse = material.get("diffuse");
            if (diffuse != null) jsonMaterial.diffuse = parseColor(diffuse);
            final JsonValue ambient = material.get("ambient");
            if (ambient != null) jsonMaterial.ambient = parseColor(ambient);
            final JsonValue emissive = material.get("emissive");
            if (emissive != null) jsonMaterial.emissive = parseColor(emissive);
            final JsonValue specular = material.get("specular");
            if (specular != null) jsonMaterial.specular = parseColor(specular);
            final JsonValue reflection = material.get("reflection");
            if (reflection != null) jsonMaterial.reflection = parseColor(reflection);
            // Read shininess
            jsonMaterial.shininess = material.getFloat("shininess", 0.0f);
            // Read opacity
            jsonMaterial.opacity = material.getFloat("opacity", 1.0f);

            // Read textures
            // JsonValue textures = material.get("textures");
            // if (textures != null) {
            // for (JsonValue texture = textures.child; texture != null;
            // texture = texture.next) {
            // ModelTexture jsonTexture = new ModelTexture();
            //
            // String textureId = texture.getString("id", null);
            // if (textureId == null) throw new GdxRuntimeException("Texture
            // has no id.");
            // jsonTexture.id = textureId;
            //
            // String fileName = texture.getString("filename", null);
            // if (fileName == null) throw new GdxRuntimeException("Texture
            // needs filename.");
            // jsonTexture.fileName = materialDir + (materialDir.length() ==
            // 0 || materialDir.endsWith("/") ? "" : "/")
            // + fileName;
            //
            // jsonTexture.uvTranslation =
            // readVector2(texture.get("uvTranslation"), 0f, 0f);
            // jsonTexture.uvScaling = readVector2(texture.get("uvScaling"),
            // 1f, 1f);
            //
            // String textureType = texture.getString("type", null);
            // if (textureType == null) throw new
            // GdxRuntimeException("Texture needs type.");
            //
            // jsonTexture.usage = parseTextureUsage(textureType);
            //
            // if (jsonMaterial.textures == null) jsonMaterial.textures =
            // new Array<ModelTexture>();
            // jsonMaterial.textures.add(jsonTexture);
            // }
            // }

            model.materials.add(jsonMaterial);
        }
    }
}
项目:libgdxcn    文件:G3dModelLoader.java   
private void parseMaterials (ModelData model, JsonValue json, String materialDir) {
    JsonValue materials = json.get("materials");
    if (materials == null) {
        // we should probably create some default material in this case
    } else {
        model.materials.ensureCapacity(materials.size);
        for (JsonValue material = materials.child; material != null; material = material.next) {
            ModelMaterial jsonMaterial = new ModelMaterial();

            String id = material.getString("id", null);
            if (id == null) throw new GdxRuntimeException("Material needs an id.");

            jsonMaterial.id = id;

            // Read material colors
            final JsonValue diffuse = material.get("diffuse");
            if (diffuse != null) jsonMaterial.diffuse = parseColor(diffuse);
            final JsonValue ambient = material.get("ambient");
            if (ambient != null) jsonMaterial.ambient = parseColor(ambient);
            final JsonValue emissive = material.get("emissive");
            if (emissive != null) jsonMaterial.emissive = parseColor(emissive);
            final JsonValue specular = material.get("specular");
            if (specular != null) jsonMaterial.specular = parseColor(specular);
            final JsonValue reflection = material.get("reflection");
            if (reflection != null) jsonMaterial.reflection = parseColor(reflection);
            // Read shininess
            jsonMaterial.shininess = material.getFloat("shininess", 0.0f);
            // Read opacity
            jsonMaterial.opacity = material.getFloat("opacity", 1.0f);

            // Read textures
            JsonValue textures = material.get("textures");
            if (textures != null) {
                for (JsonValue texture = textures.child; texture != null; texture = texture.next) {
                    ModelTexture jsonTexture = new ModelTexture();

                    String textureId = texture.getString("id", null);
                    if (textureId == null) throw new GdxRuntimeException("Texture has no id.");
                    jsonTexture.id = textureId;

                    String fileName = texture.getString("filename", null);
                    if (fileName == null) throw new GdxRuntimeException("Texture needs filename.");
                    jsonTexture.fileName = materialDir + (materialDir.length() == 0 || materialDir.endsWith("/") ? "" : "/")
                        + fileName;

                    jsonTexture.uvTranslation = readVector2(texture.get("uvTranslation"), 0f, 0f);
                    jsonTexture.uvScaling = readVector2(texture.get("uvScaling"), 1f, 1f);

                    String textureType = texture.getString("type", null);
                    if (textureType == null) throw new GdxRuntimeException("Texture needs type.");

                    jsonTexture.usage = parseTextureUsage(textureType);

                    if (jsonMaterial.textures == null) jsonMaterial.textures = new Array<ModelTexture>();
                    jsonMaterial.textures.add(jsonTexture);
                }
            }

            model.materials.add(jsonMaterial);
        }
    }
}
项目:libgdxcn    文件:Model.java   
private void loadMaterials (Iterable<ModelMaterial> modelMaterials, TextureProvider textureProvider) {
    for (ModelMaterial mtl : modelMaterials) {
        this.materials.add(convertMaterial(mtl, textureProvider));
    }
}
项目:libgdxcn    文件:Model.java   
private Material convertMaterial (ModelMaterial mtl, TextureProvider textureProvider) {
    Material result = new Material();
    result.id = mtl.id;
    if (mtl.ambient != null) result.set(new ColorAttribute(ColorAttribute.Ambient, mtl.ambient));
    if (mtl.diffuse != null) result.set(new ColorAttribute(ColorAttribute.Diffuse, mtl.diffuse));
    if (mtl.specular != null) result.set(new ColorAttribute(ColorAttribute.Specular, mtl.specular));
    if (mtl.emissive != null) result.set(new ColorAttribute(ColorAttribute.Emissive, mtl.emissive));
    if (mtl.reflection != null) result.set(new ColorAttribute(ColorAttribute.Reflection, mtl.reflection));
    if (mtl.shininess > 0f) result.set(new FloatAttribute(FloatAttribute.Shininess, mtl.shininess));
    if (mtl.opacity != 1.f) result.set(new BlendingAttribute(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA, mtl.opacity));

    ObjectMap<String, Texture> textures = new ObjectMap<String, Texture>();

    // FIXME uvScaling/uvTranslation totally ignored
    if (mtl.textures != null) {
        for (ModelTexture tex : mtl.textures) {
            Texture texture;
            if (textures.containsKey(tex.fileName)) {
                texture = textures.get(tex.fileName);
            } else {
                texture = textureProvider.load(tex.fileName);
                textures.put(tex.fileName, texture);
                disposables.add(texture);
            }

            TextureDescriptor descriptor = new TextureDescriptor(texture);
            descriptor.minFilter = texture.getMinFilter();
            descriptor.magFilter = texture.getMagFilter();
            descriptor.uWrap = texture.getUWrap();
            descriptor.vWrap = texture.getVWrap();

            float offsetU = tex.uvTranslation == null ? 0f : tex.uvTranslation.x;
            float offsetV = tex.uvTranslation == null ? 0f : tex.uvTranslation.y;
            float scaleU = tex.uvScaling == null ? 1f : tex.uvScaling.x;
            float scaleV = tex.uvScaling == null ? 1f : tex.uvScaling.y;

            switch (tex.usage) {
            case ModelTexture.USAGE_DIFFUSE:
                result.set(new TextureAttribute(TextureAttribute.Diffuse, descriptor, offsetU, offsetV, scaleU, scaleV));
                break;
            case ModelTexture.USAGE_SPECULAR:
                result.set(new TextureAttribute(TextureAttribute.Specular, descriptor, offsetU, offsetV, scaleU, scaleV));
                break;
            case ModelTexture.USAGE_BUMP:
                result.set(new TextureAttribute(TextureAttribute.Bump, descriptor, offsetU, offsetV, scaleU, scaleV));
                break;
            case ModelTexture.USAGE_NORMAL:
                result.set(new TextureAttribute(TextureAttribute.Normal, descriptor, offsetU, offsetV, scaleU, scaleV));
                break;
            case ModelTexture.USAGE_AMBIENT:
                result.set(new TextureAttribute(TextureAttribute.Ambient, descriptor, offsetU, offsetV, scaleU, scaleV));
                break;
            case ModelTexture.USAGE_EMISSIVE:
                result.set(new TextureAttribute(TextureAttribute.Emissive, descriptor, offsetU, offsetV, scaleU, scaleV));
                break;
            case ModelTexture.USAGE_REFLECTION:
                result.set(new TextureAttribute(TextureAttribute.Reflection, descriptor, offsetU, offsetV, scaleU, scaleV));
                break;
            }
        }
    }

    return result;
}