npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

cgltf.c

v1.15.0

Published

Single-file glTF 2.0 loader and writer written in C99; Johannes Kuhlmann (2018).

Readme

:diamond_shape_with_a_dot_inside: cgltf

Single-file/stb-style C glTF loader and writer, by Johannes Kuhlmann.

Build Status

Used in: bgfx, Filament, gltfpack, raylib, Unigine, and more!

Installation

Run:

$ npm i cgltf.c

And then include cgltf.h as follows:

#include "node_modules/cgltf.c/cgltf.h"
#include "node_modules/cgltf.c/cgltf_write.h"  // If writing support is needed

Usage: Loading

Loading from file:

#define CGLTF_IMPLEMENTATION
#include "cgltf.h"

cgltf_options options = {0};
cgltf_data* data = NULL;
cgltf_result result = cgltf_parse_file(&options, "scene.gltf", &data);
if (result == cgltf_result_success)
{
	/* TODO make awesome stuff */
	cgltf_free(data);
}

Loading from memory:

#define CGLTF_IMPLEMENTATION
#include "cgltf.h"

void* buf; /* Pointer to glb or gltf file data */
size_t size; /* Size of the file data */

cgltf_options options = {0};
cgltf_data* data = NULL;
cgltf_result result = cgltf_parse(&options, buf, size, &data);
if (result == cgltf_result_success)
{
	/* TODO make awesome stuff */
	cgltf_free(data);
}

Note that cgltf does not load the contents of extra files such as buffers or images into memory by default. You'll need to read these files yourself using URIs from data.buffers[] or data.images[] respectively. For buffer data, you can alternatively call cgltf_load_buffers, which will use FILE* APIs to open and read buffer files. This automatically decodes base64 data URIs in buffers. For data URIs in images, you will need to use cgltf_load_buffer_base64.

For more in-depth documentation and a description of the public interface refer to the top of the cgltf.h file.

Usage: Writing

When writing glTF data, you need a valid cgltf_data structure that represents a valid glTF document. You can construct such a structure yourself or load it using the loader functions described above. The writer functions do not deallocate any memory. So, you either have to do it manually or call cgltf_free() if you got the data by loading it from a glTF document.

Writing to file:

#define CGLTF_IMPLEMENTATION
#define CGLTF_WRITE_IMPLEMENTATION
#include "cgltf_write.h"

cgltf_options options = {0};
cgltf_data* data = /* TODO must be valid data */;
cgltf_result result = cgltf_write_file(&options, "out.gltf", data);
if (result != cgltf_result_success)
{
	/* TODO handle error */
}

Writing to memory:

#define CGLTF_IMPLEMENTATION
#define CGLTF_WRITE_IMPLEMENTATION
#include "cgltf_write.h"
cgltf_options options = {0};
cgltf_data* data = /* TODO must be valid data */;

cgltf_size size = cgltf_write(&options, NULL, 0, data);

char* buf = malloc(size);

cgltf_size written = cgltf_write(&options, buf, size, data);
if (written != size)
{
	/* TODO handle error */
}

Note that cgltf does not write the contents of extra files such as buffers or images. You'll need to write this data yourself.

For more in-depth documentation and a description of the public interface refer to the top of the cgltf_write.h file.

Features

cgltf supports core glTF 2.0:

  • glb (binary files) and gltf (JSON files)
  • meshes (including accessors, buffer views, buffers)
  • materials (including textures, samplers, images)
  • scenes and nodes
  • skins
  • animations
  • cameras
  • morph targets
  • extras data

cgltf also supports some glTF extensions:

  • EXT_mesh_gpu_instancing
  • EXT_meshopt_compression
  • EXT_texture_webp
  • KHR_draco_mesh_compression (requires a library like Google's Draco for decompression though)
  • KHR_lights_punctual
  • KHR_materials_anisotropy
  • KHR_materials_clearcoat
  • KHR_materials_diffuse_transmission
  • KHR_materials_dispersion
  • KHR_materials_emissive_strength
  • KHR_materials_ior
  • KHR_materials_iridescence
  • KHR_materials_pbrSpecularGlossiness
  • KHR_materials_sheen
  • KHR_materials_specular
  • KHR_materials_transmission
  • KHR_materials_unlit
  • KHR_materials_variants
  • KHR_materials_volume
  • KHR_texture_basisu (requires a library like Binomial Basisu for transcoding to native compressed texture)
  • KHR_texture_transform

cgltf does not yet support unlisted extensions. However, unlisted extensions can be accessed via "extensions" member on objects.

Building

The easiest approach is to integrate the cgltf.h header file into your project. If you are unfamiliar with single-file C libraries (also known as stb-style libraries), this is how it goes:

  1. Include cgltf.h where you need the functionality.
  2. Have exactly one source file that defines CGLTF_IMPLEMENTATION before including cgltf.h.
  3. Use the cgltf functions as described above.

Support for writing can be found in a separate file called cgltf_write.h (which includes cgltf.h). Building it works analogously using the CGLTF_WRITE_IMPLEMENTATION define.

Contributing

Everyone is welcome to contribute to the library. If you find any problems, you can submit them using GitHub's issue system. If you want to contribute code, you should fork the project and then send a pull request.

Dependencies

None.

C headers being used by the implementation:

#include <stddef.h>
#include <stdint.h>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <limits.h>
#include <assert.h> // If asserts are enabled.

Note, this library has a copy of the JSMN JSON parser embedded in its source.

Testing

There is a Python script in the test/ folder that retrieves the glTF 2.0 sample files from the glTF-Sample-Models repository (https://github.com/KhronosGroup/glTF-Sample-Models/tree/master/2.0) and runs the library against all gltf and glb files.

Here's one way to build and run the test:

cd test ; mkdir build ; cd build ; cmake .. -DCMAKE_BUILD_TYPE=Debug
make -j
cd ..
./test_all.py

There is also a llvm-fuzz test in fuzz/. See http://llvm.org/docs/LibFuzzer.html for more information.

ORG