Giter Club home page Giter Club logo

marusyaobjloader's Introduction

MarusyaObjLoader

A small library for fast Wavefront .obj and .mtl files loading. As .obj parser was used this fantastic library https://github.com/syoyo/tinyobjloader

Getting Started

These instructions will help you to install the package and use it.

Installing

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

Usage

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();
      }
    }
}

Example

The full example of using is located here

Documentation

Method

ResultModel load(File obj, boolean flipTextureCoordinates) throws FileNotFoundException;

Arguments

obj - .obj file in a storage

flipTextureCoordinates - reverse a texture or not

Return

ResultModel - an object which contains shapes, materials, error and warning messages

Method

ResultModel load(File obj, File mtl, boolean flipTextureCoordinates) throws FileNotFoundException;

Arguments

obj - .obj file in a storage

mtl - .mtl file in a storage

flipTextureCoordinates - reverse a texture or not

Return

ResultModel - an object which contains shapes, materials, error and warning messages

Method

ResultModel load(File obj, float normalizeCoefficient, boolean flipTextureCoordinates) throws FileNotFoundException;

Arguments

obj - .obj file in a storage

normalizeCoefficient - allows normalizing vertices

flipTextureCoordinates - reverse a texture or not

Return

ResultModel - an object which contains shapes, materials, error and warning messages

Method

ResultModel load(File obj, File mtl, float normalizeCoefficient, boolean flipTextureCoordinates) throws FileNotFoundException;

Arguments

obj - .obj file in a storage

mtl - .mtl file in a storage

normalizeCoefficient - allows normalizing vertices

flipTextureCoordinates - reverse a texture or not

Return

ResultModel - an object which contains shapes, materials, error and warning messages

Method

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: ***********************************************************************************

Method

void disableLog();

Performance

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.

Device File size versus read time
Google Pixel 2 Qualcom Snapdragon 835 (4x2.35 GGz + 4x1.9 GGz), RAM 4 GB
Huawei HRY - LX1 HiSiliconKirin 710 (4x2.2 GGz + 4x1.7 GGz), RAM 3 GB)
LGE Nexus 5X Qualcom Snapdragon 808 (2x1.44 GGz + 2x1.82 GGz), RAM 2 GB)
Samsung SM - G930F Samsung Exynos 9 Octa 8890 (8x2.3 GGz), RAM 4 GB)
Samsung SM - N950F Samsung Exynos 9 Octa 8895 (4x2.3 GGz + 4x1.7 ГГц), RAM 6 GB)
Samsung SM - T820 Qualcomm Snapdragon 820 (2x2.15 GGz + 2x1.6 GGz), RAM 4 GB)
Xiaomi Mi A1 Qualcomm Snapdragon 625 (4x2.0 GGz), RAM 4 GB)
Xiaomi Redmi Note 5 Qualcom Snapdragon 636 (8x1.8 GGz), RAM 3 GB)

On average, the download speed using JNI is 4.71 times higher.

License

This project is licensed under the Apache 2.0 License - see the LICENSE file for details.

marusyaobjloader's People

Contributors

dmitryusik avatar dmitryusikriseapps avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.