Dive into secure and efficient coding practices with our curated list of the top 10 examples showcasing 'draco3d' in functional components in JavaScript. Our advanced machine learning engine meticulously scans each line of code, cross-referencing millions of open source libraries to ensure your implementation is not just functional, but also robust and secure. Elevate your React applications to new heights by mastering the art of handling side effects, API calls, and asynchronous operations with confidence and precision.
// 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) {
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.
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;
constructor() {
this.decoderModule = draco3d.createDecoderModule({});
}
'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
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.