• 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏吧

Java ModelMaterial类的典型用法和代码示例

java 2次浏览

本文整理汇总了Java中com.badlogic.gdx.graphics.g3d.model.data.ModelMaterial的典型用法代码示例。如果您正苦于以下问题:Java ModelMaterial类的具体用法?Java ModelMaterial怎么用?Java ModelMaterial使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。

ModelMaterial类属于com.badlogic.gdx.graphics.g3d.model.data包,在下文中一共展示了ModelMaterial类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: getDependencies

点赞 3

import com.badlogic.gdx.graphics.g3d.model.data.ModelMaterial; //导入依赖的package包/类
@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;
}
 

开发者ID:basherone,
项目名称:libgdxcn,
代码行数:26,
代码来源:ModelLoader.java

示例2: getDependencies

点赞 2

import com.badlogic.gdx.graphics.g3d.model.data.ModelMaterial; //导入依赖的package包/类
@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;
}
 

开发者ID:MovementSpeed,
项目名称:nhglib,
代码行数:35,
代码来源:NhgModelLoader.java

示例3: getMaterial

点赞 2

import com.badlogic.gdx.graphics.g3d.model.data.ModelMaterial; //导入依赖的package包/类
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;
}
 

开发者ID:basherone,
项目名称:libgdxcn,
代码行数:10,
代码来源:ObjLoader.java

示例4: getMaterial

点赞 2

import com.badlogic.gdx.graphics.g3d.model.data.ModelMaterial; //导入依赖的package包/类
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;
}
 

开发者ID:langurmonkey,
项目名称:gaiasky,
代码行数:11,
代码来源:ObjLoader.java

示例5: parseMaterials

点赞 2

import com.badlogic.gdx.graphics.g3d.model.data.ModelMaterial; //导入依赖的package包/类
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);
        }
    }
}
 

开发者ID:mbrlabs,
项目名称:Mundus,
代码行数:71,
代码来源:MG3dModelLoader.java

示例6: parseMaterials

点赞 2

import com.badlogic.gdx.graphics.g3d.model.data.ModelMaterial; //导入依赖的package包/类
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);
		}
	}
}
 

开发者ID:basherone,
项目名称:libgdxcn,
代码行数:63,
代码来源:G3dModelLoader.java

示例7: loadMaterials

点赞 2

import com.badlogic.gdx.graphics.g3d.model.data.ModelMaterial; //导入依赖的package包/类
private void loadMaterials (Iterable<ModelMaterial> modelMaterials, TextureProvider textureProvider) {
	for (ModelMaterial mtl : modelMaterials) {
		this.materials.add(convertMaterial(mtl, textureProvider));
	}
}
 

开发者ID:basherone,
项目名称:libgdxcn,
代码行数:6,
代码来源:Model.java

示例8: convertMaterial

点赞 2

import com.badlogic.gdx.graphics.g3d.model.data.ModelMaterial; //导入依赖的package包/类
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;
}
 

开发者ID:basherone,
项目名称:libgdxcn,
代码行数:65,
代码来源:Model.java


版权声明:本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系管理员进行删除。
喜欢 (0)