GithubHelp home page GithubHelp logo

gltf-renderer's Introduction

Sample glTF renderer

glTF is a new standard 3D transmission format by the Khronos Group. Facebook has recently made sharing 3D content in newsfeed as easy as sharing an image or a video using glTF 2.0.

This demo shows the mechanics of parsing and rendering a sample "Hello World!" glTF file. This code is reference material for the Android Makers Paris 2018 talk titled: "The JPEG of 3D: Bringing 3D scenes and objects into your 2D Android app with glTF".

It provides a straightforward look at how to render a 3D scene using glTF and the OpenGL ES API. This is a good reference for developers who are learning about 3D rendering on Android. This is low level GPU driver API code; you may want to check out the new Sceneform API in the AR Core 1.2 SDK if you want a high-level API that can render glTF, OBJ, and FBX 3D scenes.

The renderer is trivial and will only work with the hello-world.gltf example. It is not intended to be a full glTF renderer but rather a minimal-abstraction view at the basics of how a glTF file is parsed and rendered. In some cases the renderer might be making assumptions for the hello-world.gltf use case that would not be valid for a generic glTF file.

The demo will render the hello-world.gltf scene, a single triangle using the default glTF material (using unlit red for the sample), into the TextureView's SurfaceTexture.

The code will:

  • Create a render thread with a message queue for the TextureView (SampleGLTFView)
  • Once the SurfaceTexture for the TextureView is available, it will initialize the loading of the helloworld.gltf asset
  • SampleGLTFRenderer.createOnGlThread(context, "helloworld.gltf") is called to initialize shader program and use SampleGLTFReader.read(input) to parse the JSON file and generate a "scene graph"
  • SampleGLTFRenderer.createGLTFRenderObjects(gltfScene) is called to create the GPU ready representation of the helloworld.gltf scene
  • Each frame the Choreographer VSYNC triggers SampleGLTFRenderer.draw(viewMatrix, projectionMatrix) which executes OpenGL ES draw commmands using the buffer data from the helloworld.gltf file.

SampleGLTFRenderer will also plug-in to the AR Core SDK hello_ar_java sample (https://github.com/google-ar/arcore-android-sdk/tree/v1.2.1/samples/hello_ar_java); just replace the usage of ObjectRenderer with SampleGLTFRenderer in HelloArActivity so you can render the helloworld.gltf triangle in AR.

In HelloArActivity.onSurfaceCreated(...):

  • sampleGLTFRenderer.createOnGlthread(context, "helloworld.gltf")

In HelloArActivity.onDrawFrame(...):

  • sampleGLTFRenderer.updateModelMatrix(anchorMatrix, scaleMatrix)
  • sampleGLTFRenderer.draw(viewmtx, projmtx)

Visit:

Disclaimer

  • This code is intended as a limited example for learning purposes and is by no means production quality.
  • It may not be entirely stable.
  • It has been tested on limited high end Android devices
  • It's not intended as a demonstration of "the right way" to do things.
  • It will not be supported.

Requirements

Requires Android OS version Marshmallow 6.0 (API 23) or higher

To build you'll need the Android SDK with build tools.

Note: This code was developed on Android Studio 3.1.2

Usage

Open the directory in Android Studio and the gradle project should be imported. Run & Debug options should allow you to build the project.

Command Line

Assure you have a local.properties file in the top level directory with: sdk.dir=/path/to/your/Android/sdk

$ gradlew installDebug
$ adb shell am start -n com.facebook.sample/.SampleGLTFActivity

License

glTF-Renderer is Creative Commons CC BY-NC 4.0 Attribution-NonCommercial licensed, as found in the LICENSE file.

gltf-renderer's People

Contributors

03lafaye 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  avatar  avatar  avatar  avatar  avatar  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  avatar  avatar  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.