Draco 3D Compression Library

repository·main·Indexed 27 days ago

https://github.com/google/draco

A library for compressing and decompressing 3D geometric meshes and point clouds to improve storage and transmission efficiency for web browsers, VR, and AR. It provides C++ and JavaScript/WebAssembly APIs, CLI tools (draco_encoder, draco_decoder, draco_transcoder), and NPM packages (draco3d, draco3dgltf) for Node.js and glTF support.

Tokens
31.2K
Snippets
91
Records
167
Agent score
93%

What's inside Draco

  1. Understand the Prediction Decoder logic

    main
    The Prediction Decoder is responsible for reconstructing original attribute values from compressed data using various prediction schemes. It handles different prediction methods such as PREDICTION_DIFFERENCE, MESH_PREDICTION_PARALLELOGRAM, MESH_PREDICTION_CONSTRAINED_MULTI_PARALLELOGRAM, MESH_PREDICTION_TEX_COORDS_PORTABLE, and MESH_PREDICTION_GEOMETRIC_NORMAL. The decoding process typically involves parsing prediction data, decoding transforms, and then computing the original values from the decoded symbols and predicted values.
  2. Understand EdgeBreaker Traversal Prediction Degree

    main
    The EdgeBreaker traversal algorithm uses a prediction degree mechanism to manage the order of corner traversal. This mechanism uses priority-based stacks to decide which corner to visit next, aiming to maintain locality during the traversal of mesh attributes. The traversal is driven by visiting unvisited vertices and faces, using a priority system to favor corners that lead to newly discovered vertices.
  3. Understand the Draco File Format structure

    main

    A Draco encoded mesh file consists of four main sections that must be decoded in a specific order:

    1. Header: Must be decoded first.
    2. Metadata (Optional): Contains metadata elements. Keys within a metadata element must be unique.
    3. Connectivity Data: Contains mesh connectivity information.
    4. Attribute Data: Contains mesh attributes (e.g., positions, normals, texture coordinates).

    Connectivity Formats

    Depending on the encoding used, the connectivity section follows different structures:

    • Sequential Connectivity:
      • Connectivity header
      • Indices data
    • EdgeBreaker Connectivity:
      • Connectivity header
      • Encoded split data
      • Encoded EdgeBreaker symbol data
      • Encoded start face configuration data
      • Attribute connectivity data
    • Valence EdgeBreaker Connectivity (Adds two sections after attribute connectivity):
      • EdgeBreaker valence header
      • Context data for valence prediction

    Attribute Data Structure

    Attribute data contains:

    1. An Attribute header.
    2. One or more Attribute type sections (e.g., positions, normals). Each type section contains one or more unique attributes.
  4. Understand the Sequential Connectivity Decoder specification

    main
    The Sequential Connectivity Decoder defines how Draco parses and decodes mesh connectivity data (faces and vertices). The decoding process follows a hierarchical structure: first parsing connectivity metadata, then selecting a decoding method based on the connectivity_method and the number of points in the mesh.
  5. Understand the Normal Prediction Decoder logic

    main
    The Normal Prediction Decoder is a component used to reconstruct original attribute values (specifically normals) from encoded data. It utilizes geometric prediction based on mesh corners, octahedral coordinate mapping, and quantization to recover the original 3D vectors.
  6. Understand the TexCoords Prediction Decoder logic

    main
    The TexCoords Prediction Decoder is part of the Draco mesh prediction scheme used to reconstruct texture coordinates (UVs). It uses geometric information from the mesh (positions and connectivity) to predict the values of texture coordinates, which are then used in a decoding transform to recover the original values. The process involves calculating predicted values for each corner/entry and applying a decoding transform to the sequence of signed integers.
  7. Understand the Attributes Decoder logic

    main
    The Attributes Decoder is responsible for reconstructing mesh attribute data (like normals or integer attributes) from encoded Draco data. The process involves several stages: parsing decoder metadata, generating traversal sequences (either sequentially or via Edgebreaker methods), decoding portable attributes, and finally transforming them back into their original format (e.g., dequantizing or restoring normals).
  8. Understand the Prediction Normal Transform algorithm

    main

    The Prediction Normal Transform is a decoding process used in Draco for octahedron-based normal prediction. It involves several geometric transformations including diamond inversion, point rotation, and modular maximization to reconstruct original values from predicted and corrected values.

    Key components of the transform include:

    • Diamond Inversion: Used when a predicted point falls outside a specific diamond boundary.
    • Rotation: Normalizing points to a canonical quadrant (bottom-left) using GetRotationCount and RotatePoint.
    • ModMax: A modular arithmetic operation used to wrap values within a quantized range.
    • Canonicalization: Ensuring the decoded values are correctly rotated and inverted back to their original orientation.
  9. Configure Unity Project for Draco

    main

    After adding Draco files to your project, follow these steps to enable decoding:

    1. Enable Unsafe Code: In Unity, go to Project Settings and enable Allow unsafe code.
    2. Setup Scene Objects:
      • Create an empty GameObject.
      • Attach the DracoDecodingObject.cs script to it.
      • Add a Mesh Filter component.
      • Add a Mesh Renderer component.
    3. Setup Camera: Change the Main Camera's position to 0, 0, -1.
    4. Materials & Lighting: Assign a Material to the Mesh Renderer and ensure a Light exists in the scene to see the mesh correctly.
  10. Setup Draco Unity Plugin

    main

    To use Draco in Unity, you must include the platform-specific plugin library in your project's Assets/Plugins/ directory.

    Supported Platform Libraries:

    • macOS: dracodec_unity.bundle
    • Android: libdracodec_unity.so
    • Windows: dracodec_unity.dll

    Important Configuration: You must enable unsafe code in Unity to allow the plugins to load. Open Player Settings and ensure Allow unsafe code is checked.

  11. Build Draco Unity Support for Android

    main

    Building the Android plugin requires setting the DRACO_ANDROID_NDK_PATH environment variable to your local NDK path. You must build both the armeabi-v7a and arm64-v8a architectures separately using the appropriate toolchain files, then archive the resulting .so files.

    # 1. Set NDK path
    export DRACO_ANDROID_NDK_PATH=$HOME/ndks/android-ndk-r20
    
    # 2. Build armv7 plugin
    mkdir armeabi-v7a && cd armeabi-v7a
    cmake ../ \
      -DCMAKE_TOOLCHAIN_FILE=../cmake/toolchains/armv7-android-ndk-libcpp.cmake \
      -DCMAKE_BUILD_TYPE=Release \
      -DDRACO_UNITY_PLUGIN=ON -DCMAKE_INSTALL_PREFIX=. \
      -DDRACO_ANDROID_NDK_PATH=${DRACO_ANDROID_NDK_PATH}
    make -j install
    cd ..
    
    # 3. Build arm64 plugin
    mkdir arm64-v8a && cd arm64-v8a
    cmake ../ \
      -DCMAKE_TOOLCHAIN_FILE=../cmake/toolchains/arm64-android-ndk-libcpp.cmake \
      -DDRACO_UNITY_PLUGIN=ON -DCMAKE_INSTALL_PREFIX=. \
      -DCMAKE_BUILD_TYPE=Release \
      -DDRACO_ANDROID_NDK_PATH=${DRACO_ANDROID_NDK_PATH}
    make -j install
    cd ..
    
    # 4. Archive the plugins
    tar cjvf libdracodec_unity_android.tar.bz \
      armeabi-v7a/libdracodec_unity.so \
      arm64-v8a/libdracodec_unity.so