The Go-Draco package provides Go language bindings for 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.
- Mesh decoding
- Mesh inspection
- Pre-compiled static libraries for windows and linux
- gltf extension for qmuntal/gltf
This library can be used without any special setup other than having a CGO toolchain in place.
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)
}
}
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))
}
The CGO bindings uses a C API that is maintained in qmuntal/draco-c, as the Draco team do not have enough bandwidth to support it. See google/draco#467 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
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:
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:
go run -tags customenv ./examples/decode
Builds upon and includes builds of Google's Draco 3D data compression library (released under the terms of Apache License 2.0).