A small library for fast Wavefront .obj and .mtl files loading. As .obj parser was used this fantastic library https://github.com/syoyo/tinyobjloader
These instructions will help you to install the package and use it.
Using gradle:
implementation 'com.riseapps.marusyaobjloader:marusyaobjloader:1.0.0'Using maven:
<dependency> <groupId>com.riseapps.marusyaobjloader</groupId> <artifactId>marusyaobjloader</artifactId> <version>1.0.0</version> <type>pom</type> </dependency>Or download it as a file here
Use this code for the minimum functionality:
import com.riseapps.marusyaobjloader.MarusyaObjLoader; import com.riseapps.marusyaobjloader.MarusyaObjLoaderImpl; import com.riseapps.marusyaobjloader.model.ResultModel; import java.io.File; import java.io.FileNotFoundException; private static final File FILES_PATH = new File(Environment.getExternalStorageDirectory(), "jni_test"); private static final File OBJ = new File(FILES_PATH, "luxury_house_interior.obj"); private static final File MTL = new File(FILES_PATH, "luxury_house_interior.mtl"); public void load() { final MarusyaObjLoader marusyaObjLoader = new MarusyaObjLoaderImpl(); ResultModel resultModel = null; try { resultModel = marusyaObjLoader.load( OBJ, MTL, 1.0f, true); } catch (FileNotFoundException e) { e.printStackTrace(); } } }The full example of using is located here
ResultModel load(File obj, boolean flipTextureCoordinates) throws FileNotFoundException;obj - .obj file in a storage
flipTextureCoordinates - reverse a texture or not
ResultModel - an object which contains shapes, materials, error and warning messages
ResultModel load(File obj, File mtl, boolean flipTextureCoordinates) throws FileNotFoundException;obj - .obj file in a storage
mtl - .mtl file in a storage
flipTextureCoordinates - reverse a texture or not
ResultModel - an object which contains shapes, materials, error and warning messages
ResultModel load(File obj, float normalizeCoefficient, boolean flipTextureCoordinates) throws FileNotFoundException;obj - .obj file in a storage
normalizeCoefficient - allows normalizing vertices
flipTextureCoordinates - reverse a texture or not
ResultModel - an object which contains shapes, materials, error and warning messages
ResultModel load(File obj, File mtl, float normalizeCoefficient, boolean flipTextureCoordinates) throws FileNotFoundException;obj - .obj file in a storage
mtl - .mtl file in a storage
normalizeCoefficient - allows normalizing vertices
flipTextureCoordinates - reverse a texture or not
ResultModel - an object which contains shapes, materials, error and warning messages
void enableLog();You will see a log like this:
D/MarusyaObjLoader: *********************************************************************************** D/MarusyaObjLoader: Start parsing -> obj: /storage/emulated/0/jni_test/luxury_house_interior.obj, mtl: /storage/emulated/0/jni_test/luxury_house_interior.mtl D/MarusyaObjLoader: End parsing -> /storage/emulated/0/jni_test/luxury_house_interior.obj D/MarusyaObjLoader: shapes size -> 116 D/MarusyaObjLoader: materials size -> 25 D/MarusyaObjLoader: vertices size -> 390021 D/MarusyaObjLoader: normals size -> 392763 D/MarusyaObjLoader: texcoords size -> 130796 D/MarusyaObjLoader: colors size -> 390021 D/MarusyaObjLoader: indices size -> 773121 D/MarusyaObjLoader: Time to parse -> 1364 ms D/MarusyaObjLoader: *********************************************************************************** void disableLog();For the performance tests were read 50 3-D models of .obj format. It was done using pure Java and JNI. For pure Java was used this cool library https://github.com/javagl/Obj. The table below shows gain in speed for devices with different power when reading 3-D models of .obj format using pure Java and JNI.
On average, the download speed using JNI is 4.71 times higher.
This project is licensed under the Apache 2.0 License - see the LICENSE file for details.







