Giter Club home page Giter Club logo

gltf_parser's Introduction

glTF parser for Jai codebase

Note: Jai beta 0.1.087 is required.

This project is a glTF 2.0 parser written in Jai, aiming to replace the use of some C/C++ libraries. All glTF types are fully documented, so it comes nicely with IDE autocompletion, reducing back and forth with the specification.

This library intends to mimic the glTF file structure in memory. Thereby it's designed around arrays and indexes instead of pointers as you may see in cgltf or other libraries. Also, it's the user's responsibility to load glTF files and their related binaries in memory; nevertheless, this library also provides a way to load files and buffers into memory.

Note: It's almost as complete as the glTF specification (see features), but because it's straightforward to add new parsed fields, we'll get new stuff incrementally and on-demand.

If you would like to contribute, don't hesitate! :)

Examples

You just need to import module.jai in your project, also this library has two dependencies: jason and unicode_utils; so those two modules needs to be found somewhere.


#import "gltf_parser";

main :: () {
  gltf := gltf_parse_file("./path-to-gltf-or-glb-file");
  defer gltf_free(*gltf);

  gltf_debug_print(gltf);

  gltf_load_buffers(*gltf);

  vertices: [..]float;
  read_buffer_from_accessor(*data, data.accessors[0], *vertices);
}

All examples could be found in example.jai. Also, if you want to run the tests and examples, run jai example.jai -import_dir ./modules.

General Interfaces

  • gltf_parse_string :: (buffer: string) -> GLTF_Data
  • gltf_parse_file :: (gltf_filepath: string) -> GLTF_Data
  • gltf_free :: (gltf_data: *GLTF_Data)

Helpers

For ease, I provide a procedure to load buffer in memory. Using it, you'll get the underlying data in GLTF_Buffer:

  • gltf_load_buffers :: (gltf_data: *GLTF_Data)

If you want to easily copy the underlying data from an accessor, this procedure will get the job done. You just need to provide an array of your type from which the data will be copied. Also, gltf_load_buffers must be call first. If the type of your array doesn't match the type of the accessor's component, a cast will be made (see data_read_tests example):

  • read_buffer_from_accessor :: (gltf: *GLTF_Data, accessor: GLTF_Accessor, list: *[..] $T)

A tiny utility that gives you the size, count and stride of the underlying accessor's data:

  • get_component_info :: (gltf_accessor: GLTF_Accessor) -> GLTF_Component_Info

Being able to easily print information could save you lot of debug times, this procedure gives you general informations about it (animations names, nodes counts, etc...):

  • gltf_debug_print :: (gltf_data: GLTF_Data)

Features

  • glTF 2.0 json file
  • Scenes
  • Nodes
  • Buffers
  • BufferViews
  • Meshes
  • Textures
  • Images
  • Materials
  • Animations
  • Skins
  • Cameras
  • Parse glb files
  • Morth targets
  • Extras data

Also, we supports some glTF extensions:

  • khr_lights_punctual
  • khr_materials_emissive_strength
  • khr_materials_ior
  • khr_materials_transmission
  • khr_texture_transform

Thanks

This library is using Raphael Luba's jason module to parse JSON strings, so thanks to him! :)

Contributing to the project

Don’t be shy about shooting any questions you may have. If you are a beginner/junior, don’t hesitate, I will always encourage you. It’s a safe place here. Also, I would be very happy to receive any kind of pull requests, you will have (at least) some feedback/guidance rapidly.

Behind screens, there are human beings, living any sort of story. So be always kind and respectful, because we all sheer to learn new things.

gltf_parser's People

Contributors

kooparse avatar ostef avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

ostef

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.