Coder Social home page Coder Social logo

dmitsuki / gltf2 Goto Github PK

View Code? Open in Web Editor NEW

This project forked from pawel82s/gltf2

0.0 0.0 0.0 4.49 MB

Native Odin implementation of glTF2 loading file format as described by khronos: https://registry.khronos.org/glTF/specs/2.0/glTF-2.0.html

License: MIT License

Odin 100.00%

gltf2's Introduction

Why another glTF2 library?

  1. I want to learn Odin because I like philosophy behind it and syntax. I also tried Zig for few weeks, but it's syntax is not compelling to me.
  2. I don't like cgltf implementation in vendor:cgltf and it doesn't work on *Nix based systems (for now), only on Windows.
  3. Odin has built-in many great native packages like core/encoding/json so why not write glTF file format package that uses Odin types and remove C hint fields from cgltf wrapper?
  4. Learning how to implement specification document into working code. In this case it's glTF2
  5. Because it's fun.

Progress

✔️ - fully implemented ➕ - partially implemented ❌ - not implemented

Type Status Details Specification URL
Accessors ✔️ https://registry.khronos.org/glTF/specs/2.0/glTF-2.0.html#reference-accessor
Animations ✔️ https://registry.khronos.org/glTF/specs/2.0/glTF-2.0.html#reference-animation
Asset ✔️ https://registry.khronos.org/glTF/specs/2.0/glTF-2.0.html#reference-asset
Buffers ✔️ https://registry.khronos.org/glTF/specs/2.0/glTF-2.0.html#reference-buffer
Buffer Views ✔️ https://registry.khronos.org/glTF/specs/2.0/glTF-2.0.html#reference-bufferview
Cameras ✔️ https://registry.khronos.org/glTF/specs/2.0/glTF-2.0.html#reference-camera
Images ✔️ https://registry.khronos.org/glTF/specs/2.0/glTF-2.0.html#reference-image
Materials ✔️ https://registry.khronos.org/glTF/specs/2.0/glTF-2.0.html#reference-material
Meshes Missing mesh primitive targets https://registry.khronos.org/glTF/specs/2.0/glTF-2.0.html#reference-mesh
Nodes ✔️ https://registry.khronos.org/glTF/specs/2.0/glTF-2.0.html#reference-node
Samplers ✔️ https://registry.khronos.org/glTF/specs/2.0/glTF-2.0.html#reference-sampler
Scene ✔️ It's just an integer
Scenes ✔️ https://registry.khronos.org/glTF/specs/2.0/glTF-2.0.html#reference-scene
Skins ✔️ https://registry.khronos.org/glTF/specs/2.0/glTF-2.0.html#reference-skin
Textures ✔️ https://registry.khronos.org/glTF/specs/2.0/glTF-2.0.html#reference-texture
Extensions ✔️ Represented as JSON.Value https://registry.khronos.org/glTF/specs/2.0/glTF-2.0.html#reference-extension
Extensions Used ✔️ Array of strings
Extensions Required ✔️ Array of strings
Extras ✔️ Represented as JSON.Value https://registry.khronos.org/glTF/specs/2.0/glTF-2.0.html#reference-extras

How to use it

  1. Download glTF2 package from github and put in your source folder.
  2. Load entire glTF2 file into memory (simplest way).
import "gltf2"

main :: proc() {
    // This procedure sets file format from file extension [gltf/glb]
    data, error := gltf2.load_from_file("file_name.[gltf/glb]")
    switch err in error {
    case gltf2.JSON_Error: // handle json parsing errors
    case gltf2.GLTF_Error: // handle gltf2 parsing errors
    }
    // if there are no errors we want to free memory when we are done with processing gltf/glb file.
    defer gltf2.unload(data)

    // do stuff with 'data'
    ...

    // Iterate over buffer elements using accessor:
    for it := gltf2.buf_iter_make([3]f32, &data.accessors[0], data); it.idx < it.count; it.idx += 1 {
        fmt.printf("Index: %v = %v\n", it.idx, gltf2.buf_iter_elem(&it))
    }
}
  1. Load parts of file into memory and parse itself. It can be handy if you can't load entire file into memory.
import "gltf2"

main :: proc () {
    // Set options for gltf2 parser.
    // is_glb must be set to true if file is in binary format. Most likely it will have "*.glb" suffix. By default it's gltf or JSON file format.
    // delete_content set to true will delete bytes provided in procedure call. This is what 'load_from_file' does.
    // parse_uris will try to parse all URI links, this will take CPU time to do so it's not default option.
    options := gltf2.Options{ is_glb = [true/false(default)], delete_content = [true/false(default)], parse_uris = [true/false(default)] }

    // Load some part of file that is valid JSON object
    data, error := gltf2.parse(bytes, options)
    switch err in error {
    case gltf2.JSON_Error: // Handle JSON parsing errors
    case gltf2.GLTF_Error: // Handle GLTF2 parsing errors
    }
    // If there are no errors we want to free memory when we are done with processing gltf/glb file.
    defer gltf2.unload(data)
}

How You can help.

  1. Implement missing functionality (package is still missing some stuff).
  2. Remove bugs (they are for sure).
  3. Optimize code.

gltf2's People

Contributors

pawel82s 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.