Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/qmuntal/draco-go

google/draco bindings for Go
https://github.com/qmuntal/draco-go

Last synced: 3 months ago
JSON representation

google/draco bindings for Go

Awesome Lists containing this project

README

        

# Draco Go API

[![Build](https://github.com/qmuntal/draco-go/actions/workflows/test.yml/badge.svg)](https://github.com/qmuntal/draco-go/actions/workflows/test.yml)
[![Go Reference](https://pkg.go.dev/badge/github.com/qmuntal/draco-go/draco.svg)](https://pkg.go.dev/github.com/qmuntal/draco-go/draco)

The Go-Draco package provides Go language bindings for [google/draco](https://github.com/google/draco). Draco is a library for compressing and decompressing 3D geometric meshes and point clouds.

The Go-Draco package supports the latest releases of Draco (v1.5.6) on Linux, macOS, and Windows.

Gopher Draco

## Features

- Mesh decoding
- Mesh inspection
- Pre-compiled static libraries for windows and linux
- gltf extension for [qmuntal/gltf](https://github.com/qmuntal/gltf)

## Usage

This library can be used without any special setup other than having a CGO toolchain in place.

### Decoding

```go
import (
"io/ioutil"
"github.com/qmuntal/draco-go/draco"
)

func main() {
data, _ := ioutil.ReadFile("./testdata/test_nm.obj.edgebreaker.cl4.2.2.drc")
m := draco.NewMesh()
d := draco.NewDecoder()
d.DecodeMesh(data, m)
fmt.Println("nº faces:", m.NumFaces())
fmt.Println("nº points:", m.NumPoints())
faces := m.Faces(nil)
for i, f := range faces {
fmt.Printf("%d: %v\n", i, f)
}
}
```

### glTF decoding

```go
package main

import (
"fmt"
"github.com/qmuntal/gltf"
"github.com/qmuntal/draco-go/gltf/draco"
)

func main() {
doc, _err_ := gltf.Open("testdata/box/Box.gltf")
pd, _ := draco.UnmarshalMesh(doc, doc.BufferViews[0])
p := doc.Meshes[0].Primitives[0]
fmt.Println(pd.ReadIndices(nil))
fmt.Println(pd.ReadAttr(p, "POSITION", nil))
fmt.Println(pd.ReadAttr(p, "NORMAL", nil))
}
```

## Development

The CGO bindings uses a C API that is maintained in [qmuntal/draco-c](https://github.com/qmuntal/draco-c), as the Draco team do not have enough bandwidth to support it. See [google/draco#467](https://github.com/google/draco/pull/663#issuecomment-772802508) for more context.

The libraries in `lib` have been built using: `cmake .. -DDRACO_POINT_CLOUD_COMPRESSION=ON -DDRACO_MESH_COMPRESSION=ON -DDRACO_STANDARD_EDGEBREAKER=ON -DCMAKE_BUILD_TYPE=Release`

## Custom Environment

By default `draco-go` is statically linked against the libraries provided in `/lib`. This behavior can be disabled by supplying -tags customenv when building/running your application. When building with this tag you will need to supply the CGO environment variables yourself.

For example:

```bash
export CGO_LDFLAGS="-L/usr/local/lib -ldraco_c"
```

Please note that you will need to run this line of code one time in your current session in order to build or run the code, in order to setup the needed ENV variables. Once you have done so, you can execute code that uses `draco-go` with your custom environment like this:

```bash
go run -tags customenv ./examples/decode
```

## Third party notice

Builds upon and includes builds of [Google](https://about.google)'s [Draco 3D data compression library](https://google.github.io/draco) (released under the terms of Apache License 2.0).