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.
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.
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.
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.
PlyFormatAscii_1_0 format = new PlyFormatAscii_1_0();
try {
Mesh mesh = format.read(inputStream);
} catch (MeshIOException e) {
e.printStackTrace();
}
PlyFormatAscii_1_0 format = new PlyFormatAscii_1_0();
try {
format.write(mesh, outputStream);
} catch (MeshIOException e) {
e.printStackTrace();
}
Mesh vertices and indices can be retrieved in the form of ByteBuffers.
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 require a MeshType - Lines or Triangles; and an IndicesDataType - Byte, Short or Int.
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.