All Projects â†’ jkuhlmann â†’ Cgltf

jkuhlmann / Cgltf

Licence: mit
💠 Single-file glTF 2.0 loader and writer written in C99

Programming Languages

c
50402 projects - #5 most used programming language
c99
33 projects

Labels

Projects that are alternatives of or similar to Cgltf

Building Server
A server to stream PostGIS 3D objects to the web
Stars: ✭ 11 (-98.25%)
Mutual labels:  3d, gltf
Clay Viewer
3D model viewer with high quality rendering and glTF2.0/GLB export
Stars: ✭ 558 (-11.15%)
Mutual labels:  3d, gltf
Egjs View3d
Fast & customizable 3D model viewer for everyone
Stars: ✭ 34 (-94.59%)
Mutual labels:  3d, gltf
Ueviewer
Viewer and exporter for Unreal Engine 1-4 assets (UE Viewer).
Stars: ✭ 1,083 (+72.45%)
Mutual labels:  3d, gltf
Gltf Transform
glTF 2.0 SDK for JavaScript, TypeScript, and Node.js.
Stars: ✭ 174 (-72.29%)
Mutual labels:  3d, gltf
Cesium
An open-source JavaScript library for world-class 3D globes and maps 🌎
Stars: ✭ 8,095 (+1189.01%)
Mutual labels:  3d, gltf
Assetkit
🎨 Modern 2D/3D - Importer • Exporter • Util - Library, also called (AssetIO)
Stars: ✭ 97 (-84.55%)
Mutual labels:  3d, gltf
Xeogl
A WebGL-based 3D engine for technical visualization. Not actively maintained.
Stars: ✭ 920 (+46.5%)
Mutual labels:  3d, gltf
Sharpgltf
glTF reader and writer for .NET Standard
Stars: ✭ 159 (-74.68%)
Mutual labels:  3d, gltf
Gltfast
glTF runtime loading library for Unity
Stars: ✭ 156 (-75.16%)
Mutual labels:  3d, gltf
Model viewer.dart
A Flutter widget for rendering interactive 3D models in the glTF and GLB formats.
Stars: ✭ 134 (-78.66%)
Mutual labels:  3d, gltf
Gltf
A crate for loading glTF 2.0
Stars: ✭ 224 (-64.33%)
Mutual labels:  3d, gltf
Claygl
A WebGL graphic library for building scalable Web3D applications
Stars: ✭ 2,365 (+276.59%)
Mutual labels:  3d, gltf
Model Viewer
Easily display interactive 3D models on the web and in AR!
Stars: ✭ 3,751 (+497.29%)
Mutual labels:  3d, gltf
Worldwindjava
The NASA WorldWind Java SDK (WWJ) is for building cross-platform 3D geospatial desktop applications in Java.
Stars: ✭ 526 (-16.24%)
Mutual labels:  3d
Cilantro
A lean C++ library for working with point cloud data
Stars: ✭ 577 (-8.12%)
Mutual labels:  3d
Hedera
paint 3D ivy in the Unity Editor, watch procedurally generated meshes simulate growth and clinging in real-time
Stars: ✭ 526 (-16.24%)
Mutual labels:  3d
Itowns
A Three.js-based framework written in Javascript/WebGL for visualizing 3D geospatial data
Stars: ✭ 517 (-17.68%)
Mutual labels:  3d
Blender
Mirror of the official Blender Git repository. Updated every hour.
Stars: ✭ 609 (-3.03%)
Mutual labels:  3d
3dmatch Toolbox
3DMatch - a 3D ConvNet-based local geometric descriptor for aligning 3D meshes and point clouds.
Stars: ✭ 571 (-9.08%)
Mutual labels:  3d

💠 cgltf

Single-file/stb-style C glTF loader and writer

Build Status

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

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.

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.

Writing does not yet support "extras" data.

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_meshopt_compression
  • KHR_draco_mesh_compression (requires a library like Google's Draco for decompression though)
  • KHR_lights_punctual
  • KHR_materials_clearcoat
  • KHR_materials_ior
  • KHR_materials_pbrSpecularGlossiness
  • KHR_materials_sheen
  • KHR_materials_specular
  • KHR_materials_transmission
  • KHR_materials_unlit
  • KHR_materials_variants
  • KHR_materials_volume
  • 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 implementation:

#include <stddef.h>
#include <stdint.h>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <limits.h>

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.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].