Class GltfLoader
Loads a Mesh from a glTF 2.0 model so applications can render real authored
geometry rather than only the built in Primitives. Both the binary
container (.glb) and the JSON form (.gltf) are supported; for the JSON
form, buffers must be embedded as data: URIs (external .bin side files are
not fetched). The first triangle primitive of the first mesh is read.
The loader produces the engine's standard
VertexFormat.POSITION_NORMAL_TEXCOORD layout so the result drops straight
into any built in Material:
POSITION(required) is read as the vertex position.NORMALis read when present; otherwise flat per-triangle normals are computed so lit materials still shade correctly.TEXCOORD_0is read when present; otherwise zero texture coordinates are written.
Materials, textures, skinning and animation in the glTF are ignored -- this
is a geometry loader. Apply a Material (and a Texture loaded via the
device) to the returned mesh as usual.
Example:
byte[] glb = ...; // bytes of a .glb model
Mesh mesh = GltfLoader.load(device, glb);
Material material = new Material(Material.Type.PHONG).setTexture(texture);
device.draw(mesh, material, modelMatrix);
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classA loaded glTF model in device-free form: its geometry plus the decoded base-color image extracted from the model's first material, if any.static final classA loaded glTF model: its geometry plus the base-color texture extracted from the model's first material, if any. -
Method Summary
Modifier and TypeMethodDescriptionstatic Meshload(byte[] data) Loads a model from in-memory.glbor.gltfbytes without aGraphicsDevice, allocating the buffers directly.static Meshload(GraphicsDevice device, byte[] data) Loads a model from in-memory.glbor.gltfbytes.static Meshload(GraphicsDevice device, InputStream in) Reads all bytes from the stream and loads the model.static Meshload(InputStream in) Reads all bytes from the stream and loads the model without aGraphicsDevice.static GltfLoader.GltfImageModelloadImageModel(byte[] data) Loads a model together with its base-color image from in-memory.glbor.gltfbytes without aGraphicsDevice.static GltfLoader.GltfImageModelReads all bytes from the stream and loads the model with its base-color image without aGraphicsDevice.static GltfLoader.GltfModelloadModel(GraphicsDevice device, byte[] data) Loads a model together with its base-color texture from in-memory.glbor.gltfbytes.static GltfLoader.GltfModelloadModel(GraphicsDevice device, InputStream in) Reads all bytes from the stream and loads the model with its base-color texture.
-
Method Details
-
load
Reads all bytes from the stream and loads the model. The stream is closed.
Parameters
-
device: the device that allocates the mesh buffers -
in: a stream over.glbor.gltfbytes
Returns
the loaded mesh
- Throws:
IOException
-
-
load
Loads a model from in-memory
.glbor.gltfbytes.Parameters
-
device: the device that allocates the mesh buffers -
data: the raw model bytes (binary.glbor JSON.gltf)
Returns
the loaded mesh
-
-
load
Loads a model from in-memory
.glbor.gltfbytes without aGraphicsDevice, allocating the buffers directly. Behaves exactly likeload(GraphicsDevice, byte[]); useful for parsing geometry off the render thread or handing meshes to non GPU consumers such as the AR content pipeline.Parameters
data: the raw model bytes (binary.glbor JSON.gltf)
Returns
the loaded mesh
-
load
Reads all bytes from the stream and loads the model without a
GraphicsDevice. The stream is closed.Parameters
in: a stream over.glbor.gltfbytes
Returns
the loaded mesh
- Throws:
IOException
-
loadModel
Loads a model together with its base-color texture from in-memory
.glbor.gltfbytes. Use this (rather thanload) when the model carries its own texture and you want it applied automatically.Parameters
-
device: the device that allocates the mesh buffers and texture -
data: the raw model bytes
Returns
the loaded mesh plus its base-color texture (null texture if the model has none)
-
-
loadModel
public static GltfLoader.GltfModel loadModel(GraphicsDevice device, InputStream in) throws IOException Reads all bytes from the stream and loads the model with its base-color texture. The stream is closed.- Throws:
IOException
-
loadImageModel
Loads a model together with its base-color image from in-memory
.glbor.gltfbytes without aGraphicsDevice. The image is decoded but not uploaded to the GPU, so this works off the render thread and on non GPU consumers such as the AR content pipeline.Parameters
data: the raw model bytes
Returns
the loaded mesh plus its decoded base-color image (null image if the model has none)
-
loadImageModel
Reads all bytes from the stream and loads the model with its base-color image without aGraphicsDevice. The stream is closed.- Throws:
IOException
-