Giter VIP home page Giter VIP logo

org.obj2openjl's Introduction

org.obj2openjl

A Java implementation of the infamous Obj2OpenGL python script. It lets you load Wavefront Object files (.obj) and convert them to arrays of indices, vertices, normals and texture coordinates as they are required by Kronos OpenGL libraries.

The project AugmentedBizz is a sample project in which the library has been used. The AugmentedBizz server loads OBJ model data into some cloud storage, from which the corresponding Android client loads the models in order to display them in augmented reality scenarios. See the RenderManager native class for some hints on how to use it with JNI.

Use Obj2OpenJL like so:

RawOpenGLModel openGLModel = new Obj2OpenJL().convert("path/to/file");

The path does not necessarily have a file ending. Obj2OpenJL automatically looks for files ending with .wvo and .obj, which are both the same file format, just with different file extensions. The RawOpenGLModel returned is special in that it contains the raw model data and allows applying transformations to it prior to using it in your application. For instance,

OpenGLModelData openGLModelData = openGLModel.normalize().center().getDataForGLDrawElements();

would shrink or expand the model vertices such that the longest edge of the model bounding box is of length 1 (normalize()) and translate all vertices so that the bounding box is centered in the coordinate system origin (center()). The instance returned by these calls is the same object for fluent interface, which means you could split the above call across multiple lines. Finally, getDataForGLDrawElements() converts the raw model to the data format you would need for the Kronos OpenGL C libraries.

There are also more complex operations you may run on the data, which result in duplication of the original vertices. For instance,

List<ArrayTransformation> transformations = new ArrayList<ArrayTransformation>();
transformations.add(new TranslationTransformation(2, 1.f, 0.f, 0.f));
transformations.add(new TranslationTransformation(2, 0.f, 1.f, 0.f));
transformations.add(new RotationTransformation(2, 360.f, 0.f, 0.f, 1.f));
CombineTransformation transformation = new CombineTransformation(transformations);
openGLModel.setTransformation(transformation);

produces a combined transformation that replicates vertices in the process. The model is translated and copied twice by 1.0 along the x-axis (TranslationTransformation(2, 1.f, 0.f, 0.f)), then the whole result is translated and copied twice by 1.0 along the y axis (TranslationTransformation(2, 0.f, 1.f, 0.f)). Finally, all these vertices are then rotated by 360 degrees in two steps along the arbitrary axis (0, 0, 1) (RotationTransformation(2, 360.f, 0.f, 0.f, 1.f)).

All that transformation is optional, however. The converted data can be retrieved from the OpenGLModelData instance via

openGLModelData.getVertices();
openGLModelData.getNormals();
openGLModelData.getTextureCoordinates();
openGLModelData.getIndices();

Note that the data returned is intended to be used with the GL_TRIANGLES rendering mode. The project org.obj2openjl.ui contains a simple Java2D viewer I used for testing which you may want to check out to get an impression if this library would work for you. It depends on this project, though, so that you will want to clone both and adjust the class plath dependency as necessary.

org.obj2openjl's People

Contributors

1193561652 avatar miffels avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

org.obj2openjl's Issues

Where is the Java2D viewer?

In the README.MD, you mention a project org.obj2openjl.ui that contains a simple Java2D viewer, however I cannot find it.

Please, can you add it?

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.