o
odin.langpkg.dev
packages / binding / odin-draco

odin-draco

53672c5binding

Draco glTF decompressor bindings for Odin language

Apache-2.0 · updated 6 months ago

odin-draco

Odin bindings for Google's Draco 3D geometry compression library.

Overview

This package provides Odin bindings for decompressing Draco-compressed mesh data, commonly used in glTF files with the KHR_draco_mesh_compression extension.

Building

Prerequisites (Windows)

  • Just command runner
  • Zig 0.13+ (for zig build)

Build Steps

just

This will:

  • Build the Draco static library with Zig
  • Compile the C wrapper (draco_c_wrapper.cc) with Zig
  • Install the combined draco_wrapper library into lib/draco_wrapper.lib

The built library is committed to the repository for easy use.

Usage

import draco "path/to/odin-draco"

// Create a decoder
decoder := draco.decoder_create()
defer draco.decoder_destroy(decoder)

// Decode mesh from buffer
mesh: draco.Draco_Mesh_Handle
result := draco.decode_mesh_from_buffer(decoder, data, data_size, &mesh)
defer draco.mesh_destroy(mesh)

if result.success {
    // Access mesh data using draco.mesh_get_* functions
    num_points := draco.mesh_get_num_points(mesh)
    // ...
}

See the renderer package in the parent repository for a higher-level wrapper example.

API Reference

Decoder Management

  • decoder_create() / decoder_destroy() - Create/destroy decoder instances
  • get_encoded_geometry_type() - Get geometry type without full decoding

Mesh Decoding

  • decode_mesh_from_buffer() - Decode compressed mesh data
  • mesh_destroy() - Destroy decoded mesh handle

Mesh Statistics

  • mesh_get_num_points() - Get number of vertices/points
  • mesh_get_num_faces() - Get number of triangular faces
  • mesh_get_num_attributes() - Get total number of attributes

Attribute Access

  • mesh_get_attribute_id_by_type() - Find first attribute by type (POSITION, NORMAL, etc.)
  • mesh_get_attribute_id_by_type_index() - Find attribute by type and index (for multiple attributes of same type, e.g., TEXCOORD_0, TEXCOORD_1)
  • mesh_get_num_attributes_by_type() - Count attributes of a specific type
  • mesh_get_attribute_type() - Get attribute type (POSITION, NORMAL, etc.) from attribute ID
  • mesh_get_attribute_num_components() - Get component count (e.g., 3 for vec3, 2 for vec2)
  • mesh_get_attribute_data_type() - Get data type (Float32, UInt8, etc.)
  • mesh_get_attribute_normalized() - Check if attribute values are normalized
  • mesh_get_attribute_data() - Extract attribute data as float32 arrays (currently only supports Float32 attributes)

Face Data

  • mesh_get_face_indices() - Extract triangle face indices

License

Draco is licensed under the Apache License 2.0. See the draco submodule for details.