draco_decode {dracor}R Documentation

Decode Draco encoded raw bytes containing mesh or point cloud data

Description

Decode Draco encoded raw bytes containing mesh or point cloud data

Usage

draco_decode(data, mesh3d = TRUE, ...)

Arguments

data

raw bytes containing Draco data e.g. as read by readBin OR a character vector containing a URL or a path to a file on disk.

mesh3d

Whether to return rgl::mesh3d object (when TRUE, the default) or something as close as possible to what is provided by the Draco library (when FALSE).

...

Additional arguments passed to download.file when data is a URL (e.g. quiet=TRUE or method)

Details

Note that the Draco library returns 0-based indices for the faces whereas R in general and rgl::mesh3d in particular expect 1-based indices. When mesh3d=FALSE, the result will have 0-based indices as returned by the Draco library.

If data is an http/https URL it will be downloaded to a temporary location on disk (using download.file). If data is a character vector that does not look like a URL then it is assumed to refer to a file on disk (which will be read with readBin.

Value

a rgl::mesh3d object or a list containing elements points and (for meshes). faces.

Examples


# fetch test data
# originally downloaded from:
carurl='https://github.com/google/draco/blob/master/testdata/car.drc?raw=true'
## Not run: 
car.m=draco_decode(carurl)

## End(Not run)
# use cached version in package for example
car.m=draco_decode(system.file('draco/car.drc', package = 'dracor'))
str(car.m)

## show the result
if(requireNamespace("rgl", quietly=TRUE)) {
rgl::shade3d(car.m, col='red')

## demonstrate conversion of raw form to rgl::mesh3d object
car.raw=draco_decode(carurl, mesh3d=FALSE)
str(car.raw)
car.m2 = rgl::tmesh3d(
  vertices = car.raw$points,
  indices = car.raw$faces + 1,
  homogeneous = FALSE)
}


[Package dracor version 0.2.4 Index]