How to use draco3d - 6 common examples

To help you get started, we’ve selected a few draco3d examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Reon90 / redcube / src / decoder.ts View on Github external
// import draco3d from 'draco3d';
const draco3d = require('draco3d');

export const decoderModule = draco3d.createDecoderModule({});

export function decodeDracoData(rawBuffer, decoder, offset, length) {
    const buffer = new decoderModule.DecoderBuffer();
    buffer.Init(new Int8Array(rawBuffer, offset, length), rawBuffer.byteLength);

    const dracoGeometry = new decoderModule.Mesh();
    decoder.DecodeBufferToMesh(buffer, dracoGeometry);
    decoderModule.destroy(buffer);

    return dracoGeometry;
}

export function getArray(type, length, decodedGeometry?, attribute?, decoder?) {
    let arr;
    let dracoArr;
    switch (type) {
github AnalyticalGraphicsInc / gltf-pipeline / lib / compressDracoMeshes.js View on Github external
const removeUnusedElements = require('./removeUnusedElements');
const replaceWithDecompressedPrimitive = require('./replaceWithDecompressedPrimitive');
const splitPrimitives = require('./splitPrimitives');

const arrayFill = Cesium.arrayFill;
const Cartesian3 = Cesium.Cartesian3;
const Check = Cesium.Check;
const clone = Cesium.clone;
const ComponentDatatype = Cesium.ComponentDatatype;
const defaultValue = Cesium.defaultValue;
const defined = Cesium.defined;
const RuntimeError = Cesium.RuntimeError;
const WebGLConstants = Cesium.WebGLConstants;

// Prepare encoder for compressing meshes.
const encoderModule = draco3d.createEncoderModule({});

module.exports = compressDracoMeshes;

/**
 * Compresses meshes using Draco compression in the glTF model.
 *
 * @param {Object} gltf A javascript object containing a glTF asset.
 * @param {Object} options The same options object as {@link processGltf}
 * @param {Object} options.dracoOptions Options defining Draco compression settings.
 * @param {Number} [options.dracoOptions.compressionLevel=7] A value between 0 and 10 specifying the quality of the Draco compression. Higher values produce better quality compression but may take longer to decompress. A value of 0 will apply sequential encoding and preserve face order.
 * @param {Number} [options.dracoOptions.quantizePositionBits=14] A value between 0 and 30 specifying the number of bits used for positions. Lower values produce better compression, but will lose precision. A value of 0 does not set quantization.
 * @param {Number} [options.dracoOptions.quantizeNormalBits=10] A value between 0 and 30 specifying the number of bits used for normals. Lower values produce better compression, but will lose precision. A value of 0 does not set quantization.
 * @param {Number} [options.dracoOptions.quantizeTexcoordBits=12] A value between 0 and 30 specifying the number of bits used for texture coordinates. Lower values produce better compression, but will lose precision. A value of 0 does not set quantization.
 * @param {Number} [options.dracoOptions.quantizeColorBits=8] A value between 0 and 30 specifying the number of bits used for color attributes. Lower values produce better compression, but will lose precision. A value of 0 does not set quantization.
 * @param {Number} [options.dracoOptions.quantizeGenericBits=12] A value between 0 and 30 specifying the number of bits used for skinning attributes (joint indices and joint weights) and custom attributes. Lower values produce better compression, but will lose precision. A value of 0 does not set quantization.
 * @param {Boolean} [options.dracoOptions.uncompressedFallback=false] If set, add uncompressed fallback versions of the compressed meshes.
github imodeljs / imodeljs / core / frontend / src / tile / DracoDecoder.ts View on Github external
public static readDracoMesh(mesh: Mesh, _primitive: any, bufferData: Uint8Array): Mesh | undefined {
    if (!DracoDecoder._dracoDecoderModule)
      DracoDecoder._dracoDecoderModule = createDecoderModule(undefined);

    const dracoModule = DracoDecoder._dracoDecoderModule;
    const dracoDecoder = new dracoModule.Decoder();

    const buffer = new dracoModule.DecoderBuffer();
    buffer.Init(bufferData, bufferData.length);

    const geometryType = dracoDecoder.GetEncodedGeometryType(buffer);
    if (geometryType !== dracoModule.TRIANGULAR_MESH)
      return undefined;

    const dracoGeometry = new dracoModule.Mesh();
    const decodingStatus = dracoDecoder.DecodeBufferToMesh(buffer, dracoGeometry);
    dracoModule.destroy(buffer);
    if (!decodingStatus.ok() || dracoGeometry.ptr === 0)
      return undefined;
github uber / luma.gl / modules / loaders.gl / src / draco-loader / draco-decoder.js View on Github external
constructor() {
    this.decoderModule = draco3d.createDecoderModule({});
  }
github AnalyticalGraphicsInc / gltf-pipeline / lib / replaceWithDecompressedPrimitive.js View on Github external
'use strict';
const Cesium = require('cesium');
const draco3d = require('draco3d');
const addBuffer = require('./addBuffer');

const RuntimeError = Cesium.RuntimeError;
const WebGLConstants = Cesium.WebGLConstants;

const decoderModule = draco3d.createDecoderModule({});

module.exports = replaceWithDecompressedPrimitive;

/**
 * Replace the accessor properties of the original primitive with the values from the decompressed primitive.
 *
 * @param {Object} gltf A javascript object containing a glTF asset.
 * @param {Object} primitive A javascript object containing a glTF primitive.
 * @param {Object} dracoEncodedBuffer A javascript object containing a Draco encoded mesh.
 * @param {Number} dracoEncodedBuffer.numberOfPoints Number of points after the mesh is decompressed.
 * @param {Number} dracoEncodedBuffer.numberOfFaces Number of faces after the mesh is decompressed.
 * @param {Buffer} dracoEncodedBuffer.buffer A Buffer object containing a Draco compressed mesh.
 * @param {Boolean} uncompressedFallback If set, replaces the original with the decompressed data.
 * @returns {Object} The glTF asset with the decompressed primitive.
 *
 * @private
github AnalyticalGraphicsInc / 3d-tiles-tools / samples-generator / lib / createPointCloudTile.js View on Github external
var defaultValue = Cesium.defaultValue;
var defined = Cesium.defined;
var Matrix4 = Cesium.Matrix4;
var WebGLConstants = Cesium.WebGLConstants;

module.exports = createPointCloudTile;

var sizeOfUint8 = 1;
var sizeOfUint16 = 2;
var sizeOfUint32 = 4;
var sizeOfFloat32 = 4;

CesiumMath.setRandomNumberSeed(0);
var simplex = new SimplexNoise(CesiumMath.nextRandomNumber);

var encoderModule = draco3d.createEncoderModule({});

/**
 * Creates a pnts tile that represents a point cloud.
 *
 * @param {Object} [options] Object with the following properties:
 * @param {Number} [options.tileWidth=10.0] The width of the tile in meters.
 * @param {Matrix4} [options.transform=Matrix4.IDENTITY] A transform to bake into the tile, for example a transform into WGS84.
 * @param {Number} [options.pointsLength=1000] The number of points in the point cloud.
 * @param {String} [options.colorMode='rgb'] The mode in which colors are saved. Possible values are 'rgb', 'rgba', 'rgb565', 'constant', 'none'.
 * @param {String} [options.color='random'] Determines the method for generating point colors. Possible values are 'random', 'gradient', 'noise'.
 * @param {String} [options.shape='box'] The shape of the point cloud. Possible values are 'sphere', 'box'.
 * @param {Boolean} [options.generateNormals=false] Generate per-point normals.
 * @param {Boolean} [options.draco=false] Use draco encoding.
 * @param {String[]} [options.dracoSemantics] An array of semantics to draco encode. If undefined, all semantics are encoded.
 * @param {Boolean} [options.octEncodeNormals=false] Apply oct16p encoding on the point normals.
 * @param {Boolean} [options.quantizePositions=false] Quantize point positions so each x, y, z takes up 16 bits rather than 32 bits.

draco3d

Draco is a library for compressing and decompressing 3D geometric meshes and point clouds. It is intended to improve the storage and transmission of 3D graphics.

Apache-2.0
Latest version published 3 months ago

Package Health Score

89 / 100
Full package analysis