Skip to content

A library that allows polygon meshes to be loaded and saved with any format and with any user-defined mesh object

License

Notifications You must be signed in to change notification settings

NathanJAdams/MeshIO

Repository files navigation

MeshIO

Licence

MIT Licence

CircleCI Status

CircleCI

Usage

View this project on mvnrepository.com or maven.org

To use as a dependency in a Maven project, add the following into your pom file dependencies:

<dependency>
  <groupId>com.ripplargames</groupId>
  <artifactId>meshio</artifactId>
  <version>2.1.2</version>
</dependency>

For other build tools, view it on mvnrepository.com or maven.org.

The purpose of this library is two-fold.

  • To easily save a polygon mesh to file or an output stream in a format.
  • To load a polygon mesh from file or an input stream into ByteBuffers with any user defined vertex/indice formats.
The main way of doing this is to instantiate an object of the class [MeshIO](src/com/ripplargames/meshio/MeshIO.java). Meshes can then be loaded and saved via it's read() and write() methods.
Read with MeshIO

To read a mesh call the meshIO.read() method passing in the file path to read from. If unsuccessful, a MeshIOException is thrown.

MeshIO meshIO = new MeshIO();
try {
    Mesh mesh = meshIO.read(filePath);
} catch (MeshIOException e) {
    e.printStackTrace();
}

The method attempts to read the format from the file extension. If the format is recognised and the file is valid, the mesh will be created.

Write with MeshIO

Writing an object is done in a similar way, call the meshIO.write() method passing in the mesh and the file path to save to. If unsuccessful, a MeshIOException is thrown.

MeshIO meshIO = new MeshIO();
try {
    meshIO.write(mesh, filePath);
} catch (MeshIOException e) {
    e.printStackTrace();
}

This method also attempts to read the format from the file extension. If the format is recognised and the file is valid, the mesh will be saved to file.

Using Formats directly

Mesh formats can be instantiated and used directly by implementing the IMeshFormat interface. The format read() and write() methods are similar to the above methods but use an input or output stream instead of a file path. Helper methods that use formats directly are in MeshIO.

Read with format
PlyFormatAscii_1_0 format = new PlyFormatAscii_1_0();
try {
    Mesh mesh = format.read(inputStream);
} catch (MeshIOException e) {
    e.printStackTrace();
}
Write with format
PlyFormatAscii_1_0 format = new PlyFormatAscii_1_0();
try {
    format.write(mesh, outputStream);
} catch (MeshIOException e) {
    e.printStackTrace();
}

Retrieving data

Mesh vertices and indices can be retrieved in the form of ByteBuffers.

Vertices

Vertices require a VertexFormat to be created. These are created from at least one VertexFormatPart. An example part would be one with a VertexType of Position_X and a VertexDataType type of float. This will produce a ByteBuffer filled with all the x positions of the vertices in 32 bit floats.

Indices

Indices require a MeshType - Lines or Triangles; and an IndicesDataType - Byte, Short or Int.

Formats

Currently the only supported formats are PLY, OBJ and MBMSH, support for further formats will follow. Additional formats can be created and used by either implementing the IMeshFormat interface or extending the AMeshFormat abstract class. The new format will then need to be registered via the MeshIO.registerMeshFormat() method.

About

A library that allows polygon meshes to be loaded and saved with any format and with any user-defined mesh object

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages