APIdia Launch Partner
Top Description Inners Fields Constructors Methods
com.badlogic.gdx.graphics.g3d.loader

public Class ObjLoader

Additional top-level class in compilation unit: MtlLoader.

extends ModelLoader<ObjLoader.ObjLoaderParameters>
Class Inheritance
Imports
java.io.BufferedReader, .IOException, .InputStreamReader, com.badlogic.gdx.Gdx, com.badlogic.gdx.assets.AssetManager, com.badlogic.gdx.assets.loaders.FileHandleResolver, .ModelLoader, com.badlogic.gdx.files.FileHandle, com.badlogic.gdx.graphics.Color, .GL20, .VertexAttribute, .VertexAttributes.Usage, com.badlogic.gdx.graphics.g3d.Attributes, .Material, .Model, com.badlogic.gdx.graphics.g3d.model.data.ModelData, .ModelMaterial, .ModelMesh, .ModelMeshPart, .ModelNode, .ModelNodePart, .ModelTexture, com.badlogic.gdx.graphics.glutils.ShaderProgram, com.badlogic.gdx.math.Quaternion, .Vector3, com.badlogic.gdx.utils.Array, .FloatArray

ModelLoader to load Wavefront OBJ files. Only intended for testing basic models/meshes and educational usage. The Wavefront specification is NOT fully implemented, only a subset of the specification is supported. Especially the Material (Attributes), e.g. the color or texture applied, might not or not correctly be loaded.

This ModelLoader can be used to load very basic models without having to convert them to a more suitable format. Therefore it can be used for educational purposes and to quickly test a basic model, but should not be used in production. Instead use G3dModelLoader.

Because of above reasons, when an OBJ file is loaded using this loader, it will log and error. To prevent this error from being logged, set the logWarning flag to false. However, it is advised not to do so.

An OBJ file only contains the mesh (shape). It may link to a separate MTL file, which is used to describe one or more materials. In that case the MTL filename (might be case-sensitive) is expected to be located relative to the OBJ file. The MTL file might reference one or more texture files, in which case those filename(s) are expected to be located relative to the MTL file.

Author
mzechner, espitz, xoppa

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
public static class

Field Summary

Modifier and TypeField and Description
pack-priv final Array<ObjLoader.Group>
public static boolean
logWarning

Set to false to prevent a warning from being logged when this class is used.

pack-priv final FloatArray
pack-priv final FloatArray
pack-priv final FloatArray
Inherited from com.badlogic.gdx.assets.loaders.ModelLoader:
defaultParametersitems

Constructor Summary

AccessConstructor and Description
public
public

Method Summary

Modifier and TypeMethod and Description
private int
getIndex(String index, int size)

public Model
loadModel(final FileHandle fileHandle, boolean flipV)

Overrides com.badlogic.gdx.assets.loaders.ModelLoader.loadModel.

Directly load the model on the calling thread.

public ModelData
loadModelData(FileHandle file, ObjLoader.ObjLoaderParameters parameters)

Implements abstract com.badlogic.gdx.assets.loaders.ModelLoader.loadModelData.

Directly load the raw model data on the calling thread.

protected ModelData
loadModelData(FileHandle file, boolean flipV)

Implements abstract com.badlogic.gdx.assets.loaders.ModelLoader.loadModelData.

Directly load the raw model data on the calling thread.

private ObjLoader.Group
Inherited from com.badlogic.gdx.assets.loaders.ModelLoader:
getDependenciesloadAsyncloadModelloadModelloadModelloadModelDataloadSync

Field Detail

groupsback to summary
pack-priv final Array<ObjLoader.Group> groups
logWarningback to summary
public static boolean logWarning

Set to false to prevent a warning from being logged when this class is used. Do not change this value, unless you are absolutely sure what you are doing. Consult the documentation for more information.

normsback to summary
pack-priv final FloatArray norms
uvsback to summary
pack-priv final FloatArray uvs
vertsback to summary
pack-priv final FloatArray verts

Constructor Detail

ObjLoaderback to summary
public ObjLoader()
ObjLoaderback to summary
public ObjLoader(FileHandleResolver resolver)

Method Detail

getIndexback to summary
private int getIndex(String index, int size)
loadModelback to summary
public Model loadModel(final FileHandle fileHandle, boolean flipV)

Overrides com.badlogic.gdx.assets.loaders.ModelLoader.loadModel.

Directly load the model on the calling thread. The model with not be managed by an AssetManager.

loadModelDataback to summary
public ModelData loadModelData(FileHandle file, ObjLoader.ObjLoaderParameters parameters)

Implements abstract com.badlogic.gdx.assets.loaders.ModelLoader.loadModelData.

Doc from com.badlogic.gdx.assets.loaders.ModelLoader.loadModelData.

Directly load the raw model data on the calling thread.

Annotations
@Override
loadModelDataback to summary
protected ModelData loadModelData(FileHandle file, boolean flipV)

Implements abstract com.badlogic.gdx.assets.loaders.ModelLoader.loadModelData.

Doc from com.badlogic.gdx.assets.loaders.ModelLoader.loadModelData.

Directly load the raw model data on the calling thread.

setActiveGroupback to summary
private ObjLoader.Group setActiveGroup(String name)
com.badlogic.gdx.graphics.g3d.loader back to summary

private Class ObjLoader.Group

extends Object
Class Inheritance

Field Summary

Modifier and TypeField and Description
pack-priv Array<Integer>
pack-priv boolean
pack-priv boolean
pack-priv Material
pack-priv String
pack-priv final String
pack-priv int

Constructor Summary

AccessConstructor and Description
pack-priv
Group(String name)

Method Summary

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

facesback to summary
pack-priv Array<Integer> faces
hasNormsback to summary
pack-priv boolean hasNorms
hasUVsback to summary
pack-priv boolean hasUVs
matback to summary
pack-priv Material mat
materialNameback to summary
pack-priv String materialName
nameback to summary
pack-priv final String name
numFacesback to summary
pack-priv int numFaces

Constructor Detail

Groupback to summary
pack-priv Group(String name)
com.badlogic.gdx.graphics.g3d.loader back to summary

public Class ObjLoader.ObjLoaderParameters

extends ModelParameters
Class Inheritance

Field Summary

Modifier and TypeField and Description
public boolean
Inherited from com.badlogic.gdx.assets.loaders.ModelLoader.ModelParameters:
textureParameter

Constructor Summary

AccessConstructor and Description
public
public
ObjLoaderParameters(boolean flipV)

Field Detail

flipVback to summary
public boolean flipV

Constructor Detail

ObjLoaderParametersback to summary
public ObjLoaderParameters()
ObjLoaderParametersback to summary
public ObjLoaderParameters(boolean flipV)