New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@loaders.gl/draco

Package Overview
Dependencies
Maintainers
8
Versions
339
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@loaders.gl/draco - npm Package Compare versions

Comparing version 0.8.0 to 1.0.0-alpha.1

dist/es5/draco-writer.js

73

dist/es5/draco-decoder.js

@@ -14,13 +14,10 @@ "use strict";

var _core = require("@loaders.gl/core");
var _gltfAttributeUtils = require("./gltf-attribute-utils");
// DRACO decompressor
var draco3d = require('draco3d'); // const assert = require('assert');
var draco3d = require('draco3d');
var GEOMETRY_TYPE = {
TRIANGULAR_MESH: 0,
POINT_CLOUD: 1
}; // Native Draco attribute names to GLTF attribute names.
};
var DRACO_TO_GLTF_ATTRIBUTE_NAME_MAP = {

@@ -42,5 +39,3 @@ POSITION: 'POSITION',

var DRACODecoder =
/*#__PURE__*/
function () {
var DRACODecoder = function () {
function DRACODecoder() {

@@ -53,4 +48,3 @@ (0, _classCallCheck2.default)(this, DRACODecoder);

key: "destroy",
value: function destroy() {// this.decoderModule.destroy();
}
value: function destroy() {}
}, {

@@ -62,4 +56,3 @@ key: "destroyGeometry",

}
} // NOTE: caller must call `destroyGeometry` on the return value after using it
}
}, {

@@ -113,3 +106,3 @@ key: "decode",

if (!dracoStatus.ok() || !dracoGeometry.ptr) {
var message = "DRACO decompression failed: ".concat(dracoStatus.error_msg()); // console.error(message);
var message = "DRACO decompression failed: ".concat(dracoStatus.error_msg());

@@ -134,5 +127,2 @@ if (dracoGeometry) {

value: function extractDRACOGeometry(decoder, dracoGeometry, geometry, geometryType) {
// const numPoints = dracoGeometry.num_points();
// const numAttributes = dracoGeometry.num_attributes();
// Structure for converting to WebGL framework specific attributes later
var attributes = this.getAttributes(decoder, dracoGeometry);

@@ -145,15 +135,13 @@ var positionAttribute = attributes.POSITION;

this.getPositionAttributeMetadata(positionAttribute); // For meshes, we need indices to define the faces.
this.getPositionAttributeMetadata(positionAttribute);
if (geometryType === this.decoderModule.TRIANGULAR_MESH) {
attributes.indices = this.drawMode === 'TRIANGLE_STRIP' ? this.getMeshStripIndices(decoder, dracoGeometry) : this.getMeshFaceIndices(decoder, dracoGeometry);
geometry.mode = this.drawMode === 'TRIANGLE_STRIP' ? 5 : // GL.TRIANGLE_STRIP
4; // GL.TRIANGLES
geometry.mode = this.drawMode === 'TRIANGLE_STRIP' ? 5 : 4;
} else {
geometry.mode = 0; // GL.POINTS
geometry.mode = 0;
}
geometry.indices = (0, _core.getGLTFIndices)(attributes);
geometry.attributes = (0, _core.getGLTFAccessors)(attributes);
geometry.glTFAttributeMap = (0, _core.getGLTFAttributeMap)(attributes);
geometry.indices = (0, _gltfAttributeUtils.getGLTFIndices)(attributes);
geometry.attributes = (0, _gltfAttributeUtils.getGLTFAccessors)(attributes);
return geometry;

@@ -169,3 +157,2 @@ }

if (posTransform.InitFromAttribute(positionAttribute)) {
// Quantized attribute. Store the quantization parameters into the attribute
this.metadata.attributes.position.isQuantized = true;

@@ -187,9 +174,5 @@ this.metadata.attributes.position.maxRange = posTransform.range();

var attributes = {};
var numPoints = dracoGeometry.num_points(); // const attributeUniqueIdMap = {};
// Add native Draco attribute type to geometry.
var numPoints = dracoGeometry.num_points();
for (var attributeName in DRACO_TO_GLTF_ATTRIBUTE_NAME_MAP) {
// The native attribute type is only used when no unique Id is provided.
// For example, loading .drc files.
// if (attributeUniqueIdMap[attributeName] === undefined) {
var attributeType = this.decoderModule[attributeName];

@@ -208,20 +191,10 @@ var attributeId = decoder.GetAttributeId(dracoGeometry, attributeType);

};
} // }
}
}
} // // Add attributes of user specified unique id. E.g. GLTF models.
// for (const attributeName in attributeUniqueIdMap) {
// const attributeType = attributeTypeMap[attributeName] || Float32Array;
// const attributeId = attributeUniqueIdMap[attributeName];
// const attribute = decoder.GetAttributeByUniqueId(dracoGeometry, attributeId);
// this.getAttributeTypedArray(decoder, dracoGeometry, attribute,attributeName,attributeType);
// }
return attributes;
} // For meshes, we need indices to define the faces.
}
}, {
key: "getMeshFaceIndices",
value: function getMeshFaceIndices(decoder, dracoGeometry) {
// Example on how to retrieve mesh and attributes.
var numFaces = dracoGeometry.num_faces();

@@ -242,4 +215,3 @@ var numIndices = numFaces * 3;

return indices;
} // For meshes, we need indices to define the faces.
}
}, {

@@ -249,4 +221,2 @@ key: "getMeshStripIndices",

var dracoArray = new this.decoderModule.DracoInt32Array();
/* const numStrips = */
decoder.GetTriangleStripsFromMesh(dracoGeometry, dracoArray);

@@ -266,4 +236,3 @@ var indices = new Uint32Array(dracoArray.size());

if (dracoAttribute.ptr === 0) {
var message = "DRACO decode bad attribute ".concat(attributeName); // console.error(message);
var message = "DRACO decode bad attribute ".concat(attributeName);
throw new Error(message);

@@ -323,8 +292,6 @@ }

default:
var errorMsg = 'DRACO decoder: unexpected attribute type.'; // console.error(errorMsg);
var errorMsg = 'DRACO decoder: unexpected attribute type.';
throw new Error(errorMsg);
} // Copy data from decoder.
}
for (var i = 0; i < numValues; i++) {

@@ -331,0 +298,0 @@ typedArray[i] = dracoArray.GetValue(i);

@@ -16,17 +16,2 @@ "use strict";

// This code is based on example code from the DRACO repository
// Copyright 2017 The Draco Authors.
//
// Licensed under the Apache License, Version 2.0 (the 'License');
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an 'AS IS' BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
var draco3d = require('draco3d');

@@ -41,6 +26,11 @@

};
var GLTF_TO_DRACO_ATTRIBUTE_NAME_MAP = {
POSITION: 'POSITION',
NORMAL: 'NORMAL',
COLOR_0: 'COLOR',
TEXCOORD_0: 'TEX_COORD'
};
function noop() {} // Copy encoded data to buffer
function noop() {}
function dracoInt8ArrayToArrayBuffer(dracoData) {

@@ -57,12 +47,4 @@ var byteLength = dracoData.size();

}
/* Encoder API:
https://github.com/google/draco/blob/master/src/draco/javascript/emscripten/draco_web_encoder.idl
Example:
https://github.com/google/draco/blob/master/javascript/npm/draco3d/draco_nodejs_example.js
*/
var DRACOEncoder =
/*#__PURE__*/
function () {
var DRACOEncoder = function () {
function DRACOEncoder() {

@@ -93,4 +75,3 @@ var opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};

}
} // Set encoding options.
}
}, {

@@ -108,4 +89,3 @@ key: "setOptions",

if ('method' in opts) {
var dracoMethod = this.dracoEncoderModule[opts.method]; // if (dracoMethod === undefined) {}
var dracoMethod = this.dracoEncoderModule[opts.method];
this.dracoEncoder.SetEncodingMethod(dracoMethod);

@@ -125,3 +105,2 @@ }

value: function encodePointCloud(attributes) {
// Build a `DracoPointCloud` from the input data
var dracoPointCloud = this._createDracoPointCloud(attributes);

@@ -148,3 +127,2 @@

value: function encodeMesh(attributes) {
// Build a `DracoMesh` from the input data
var dracoMesh = this._createDracoMesh(attributes);

@@ -184,2 +162,3 @@

var attribute = attributes[attributeName];
attributeName = GLTF_TO_DRACO_ATTRIBUTE_NAME_MAP[attributeName] || attributeName;

@@ -211,2 +190,3 @@ this._addAttributeToMesh(dracoMesh, attributeName, attribute, vertexCount);

var attribute = attributes[attributeName];
attributeName = GLTF_TO_DRACO_ATTRIBUTE_NAME_MAP[attributeName] || attributeName;

@@ -272,5 +252,3 @@ this._addAttributeToMesh(dracoPointCloud, attributeName, attribute, vertexCount);

}
} // DRACO can compress attributes of know type better
// TODO - expose an attribute type map?
}
}, {

@@ -277,0 +255,0 @@ key: "_getDracoAttributeType",

@@ -1,12 +0,9 @@

// DRACO decompressor
import { getGLTFAccessors, getGLTFIndices, getGLTFAttributeMap } from '@loaders.gl/core';
import { getGLTFAccessors, getGLTFIndices } from './gltf-attribute-utils';
const draco3d = require('draco3d'); // const assert = require('assert');
const draco3d = require('draco3d');
const GEOMETRY_TYPE = {
TRIANGULAR_MESH: 0,
POINT_CLOUD: 1
}; // Native Draco attribute names to GLTF attribute names.
};
const DRACO_TO_GLTF_ATTRIBUTE_NAME_MAP = {

@@ -32,4 +29,3 @@ POSITION: 'POSITION',

destroy() {// this.decoderModule.destroy();
}
destroy() {}

@@ -40,5 +36,4 @@ destroyGeometry(dracoGeometry) {

}
} // NOTE: caller must call `destroyGeometry` on the return value after using it
}
decode(arrayBuffer) {

@@ -90,3 +85,3 @@ const buffer = new this.decoderModule.DecoderBuffer();

if (!dracoStatus.ok() || !dracoGeometry.ptr) {
const message = `DRACO decompression failed: ${dracoStatus.error_msg()}`; // console.error(message);
const message = `DRACO decompression failed: ${dracoStatus.error_msg()}`;

@@ -110,5 +105,2 @@ if (dracoGeometry) {

extractDRACOGeometry(decoder, dracoGeometry, geometry, geometryType) {
// const numPoints = dracoGeometry.num_points();
// const numAttributes = dracoGeometry.num_attributes();
// Structure for converting to WebGL framework specific attributes later
const attributes = this.getAttributes(decoder, dracoGeometry);

@@ -121,10 +113,9 @@ const positionAttribute = attributes.POSITION;

this.getPositionAttributeMetadata(positionAttribute); // For meshes, we need indices to define the faces.
this.getPositionAttributeMetadata(positionAttribute);
if (geometryType === this.decoderModule.TRIANGULAR_MESH) {
attributes.indices = this.drawMode === 'TRIANGLE_STRIP' ? this.getMeshStripIndices(decoder, dracoGeometry) : this.getMeshFaceIndices(decoder, dracoGeometry);
geometry.mode = this.drawMode === 'TRIANGLE_STRIP' ? 5 : // GL.TRIANGLE_STRIP
4; // GL.TRIANGLES
geometry.mode = this.drawMode === 'TRIANGLE_STRIP' ? 5 : 4;
} else {
geometry.mode = 0; // GL.POINTS
geometry.mode = 0;
}

@@ -134,3 +125,2 @@

geometry.attributes = getGLTFAccessors(attributes);
geometry.glTFAttributeMap = getGLTFAttributeMap(attributes);
return geometry;

@@ -145,3 +135,2 @@ }

if (posTransform.InitFromAttribute(positionAttribute)) {
// Quantized attribute. Store the quantization parameters into the attribute
this.metadata.attributes.position.isQuantized = true;

@@ -162,9 +151,5 @@ this.metadata.attributes.position.maxRange = posTransform.range();

const attributes = {};
const numPoints = dracoGeometry.num_points(); // const attributeUniqueIdMap = {};
// Add native Draco attribute type to geometry.
const numPoints = dracoGeometry.num_points();
for (const attributeName in DRACO_TO_GLTF_ATTRIBUTE_NAME_MAP) {
// The native attribute type is only used when no unique Id is provided.
// For example, loading .drc files.
// if (attributeUniqueIdMap[attributeName] === undefined) {
const attributeType = this.decoderModule[attributeName];

@@ -183,19 +168,9 @@ const attributeId = decoder.GetAttributeId(dracoGeometry, attributeType);

};
} // }
}
}
} // // Add attributes of user specified unique id. E.g. GLTF models.
// for (const attributeName in attributeUniqueIdMap) {
// const attributeType = attributeTypeMap[attributeName] || Float32Array;
// const attributeId = attributeUniqueIdMap[attributeName];
// const attribute = decoder.GetAttributeByUniqueId(dracoGeometry, attributeId);
// this.getAttributeTypedArray(decoder, dracoGeometry, attribute,attributeName,attributeType);
// }
return attributes;
} // For meshes, we need indices to define the faces.
}
getMeshFaceIndices(decoder, dracoGeometry) {
// Example on how to retrieve mesh and attributes.
const numFaces = dracoGeometry.num_faces();

@@ -216,9 +191,6 @@ const numIndices = numFaces * 3;

return indices;
} // For meshes, we need indices to define the faces.
}
getMeshStripIndices(decoder, dracoGeometry) {
const dracoArray = new this.decoderModule.DracoInt32Array();
/* const numStrips = */
decoder.GetTriangleStripsFromMesh(dracoGeometry, dracoArray);

@@ -237,4 +209,3 @@ const indices = new Uint32Array(dracoArray.size());

if (dracoAttribute.ptr === 0) {
const message = `DRACO decode bad attribute ${attributeName}`; // console.error(message);
const message = `DRACO decode bad attribute ${attributeName}`;
throw new Error(message);

@@ -294,8 +265,6 @@ }

default:
const errorMsg = 'DRACO decoder: unexpected attribute type.'; // console.error(errorMsg);
const errorMsg = 'DRACO decoder: unexpected attribute type.';
throw new Error(errorMsg);
} // Copy data from decoder.
}
for (let i = 0; i < numValues; i++) {

@@ -302,0 +271,0 @@ typedArray[i] = dracoArray.GetValue(i);

@@ -1,16 +0,1 @@

// This code is based on example code from the DRACO repository
// Copyright 2017 The Draco Authors.
//
// Licensed under the Apache License, Version 2.0 (the 'License');
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an 'AS IS' BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
const draco3d = require('draco3d');

@@ -25,6 +10,11 @@

};
const GLTF_TO_DRACO_ATTRIBUTE_NAME_MAP = {
POSITION: 'POSITION',
NORMAL: 'NORMAL',
COLOR_0: 'COLOR',
TEXCOORD_0: 'TEX_COORD'
};
function noop() {} // Copy encoded data to buffer
function noop() {}
function dracoInt8ArrayToArrayBuffer(dracoData) {

@@ -41,9 +31,3 @@ const byteLength = dracoData.size();

}
/* Encoder API:
https://github.com/google/draco/blob/master/src/draco/javascript/emscripten/draco_web_encoder.idl
Example:
https://github.com/google/draco/blob/master/javascript/npm/draco3d/draco_nodejs_example.js
*/
export default class DRACOEncoder {

@@ -71,5 +55,4 @@ constructor() {

}
} // Set encoding options.
}
setOptions() {

@@ -83,4 +66,3 @@ let opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};

if ('method' in opts) {
const dracoMethod = this.dracoEncoderModule[opts.method]; // if (dracoMethod === undefined) {}
const dracoMethod = this.dracoEncoderModule[opts.method];
this.dracoEncoder.SetEncodingMethod(dracoMethod);

@@ -99,3 +81,2 @@ }

encodePointCloud(attributes) {
// Build a `DracoPointCloud` from the input data
const dracoPointCloud = this._createDracoPointCloud(attributes);

@@ -122,3 +103,2 @@

encodeMesh(attributes) {
// Build a `DracoMesh` from the input data
const dracoMesh = this._createDracoMesh(attributes);

@@ -156,4 +136,5 @@

for (const attributeName in attributes) {
for (let attributeName in attributes) {
const attribute = attributes[attributeName];
attributeName = GLTF_TO_DRACO_ATTRIBUTE_NAME_MAP[attributeName] || attributeName;

@@ -182,4 +163,5 @@ this._addAttributeToMesh(dracoMesh, attributeName, attribute, vertexCount);

for (const attributeName in attributes) {
for (let attributeName in attributes) {
const attribute = attributes[attributeName];
attributeName = GLTF_TO_DRACO_ATTRIBUTE_NAME_MAP[attributeName] || attributeName;

@@ -244,6 +226,4 @@ this._addAttributeToMesh(dracoPointCloud, attributeName, attribute, vertexCount);

}
} // DRACO can compress attributes of know type better
// TODO - expose an attribute type map?
}
_getDracoAttributeType(attributeName, attribute) {

@@ -250,0 +230,0 @@ switch (attributeName.toLowerCase()) {

import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
import _createClass from "@babel/runtime/helpers/esm/createClass";
// DRACO decompressor
import { getGLTFAccessors, getGLTFIndices, getGLTFAttributeMap } from '@loaders.gl/core';
import { getGLTFAccessors, getGLTFIndices } from './gltf-attribute-utils';
var draco3d = require('draco3d'); // const assert = require('assert');
var draco3d = require('draco3d');
var GEOMETRY_TYPE = {
TRIANGULAR_MESH: 0,
POINT_CLOUD: 1
}; // Native Draco attribute names to GLTF attribute names.
};
var DRACO_TO_GLTF_ATTRIBUTE_NAME_MAP = {

@@ -30,5 +27,3 @@ POSITION: 'POSITION',

var DRACODecoder =
/*#__PURE__*/
function () {
var DRACODecoder = function () {
function DRACODecoder() {

@@ -42,4 +37,3 @@ _classCallCheck(this, DRACODecoder);

key: "destroy",
value: function destroy() {// this.decoderModule.destroy();
}
value: function destroy() {}
}, {

@@ -51,4 +45,3 @@ key: "destroyGeometry",

}
} // NOTE: caller must call `destroyGeometry` on the return value after using it
}
}, {

@@ -102,3 +95,3 @@ key: "decode",

if (!dracoStatus.ok() || !dracoGeometry.ptr) {
var message = "DRACO decompression failed: ".concat(dracoStatus.error_msg()); // console.error(message);
var message = "DRACO decompression failed: ".concat(dracoStatus.error_msg());

@@ -123,5 +116,2 @@ if (dracoGeometry) {

value: function extractDRACOGeometry(decoder, dracoGeometry, geometry, geometryType) {
// const numPoints = dracoGeometry.num_points();
// const numAttributes = dracoGeometry.num_attributes();
// Structure for converting to WebGL framework specific attributes later
var attributes = this.getAttributes(decoder, dracoGeometry);

@@ -134,10 +124,9 @@ var positionAttribute = attributes.POSITION;

this.getPositionAttributeMetadata(positionAttribute); // For meshes, we need indices to define the faces.
this.getPositionAttributeMetadata(positionAttribute);
if (geometryType === this.decoderModule.TRIANGULAR_MESH) {
attributes.indices = this.drawMode === 'TRIANGLE_STRIP' ? this.getMeshStripIndices(decoder, dracoGeometry) : this.getMeshFaceIndices(decoder, dracoGeometry);
geometry.mode = this.drawMode === 'TRIANGLE_STRIP' ? 5 : // GL.TRIANGLE_STRIP
4; // GL.TRIANGLES
geometry.mode = this.drawMode === 'TRIANGLE_STRIP' ? 5 : 4;
} else {
geometry.mode = 0; // GL.POINTS
geometry.mode = 0;
}

@@ -147,3 +136,2 @@

geometry.attributes = getGLTFAccessors(attributes);
geometry.glTFAttributeMap = getGLTFAttributeMap(attributes);
return geometry;

@@ -159,3 +147,2 @@ }

if (posTransform.InitFromAttribute(positionAttribute)) {
// Quantized attribute. Store the quantization parameters into the attribute
this.metadata.attributes.position.isQuantized = true;

@@ -177,9 +164,5 @@ this.metadata.attributes.position.maxRange = posTransform.range();

var attributes = {};
var numPoints = dracoGeometry.num_points(); // const attributeUniqueIdMap = {};
// Add native Draco attribute type to geometry.
var numPoints = dracoGeometry.num_points();
for (var attributeName in DRACO_TO_GLTF_ATTRIBUTE_NAME_MAP) {
// The native attribute type is only used when no unique Id is provided.
// For example, loading .drc files.
// if (attributeUniqueIdMap[attributeName] === undefined) {
var attributeType = this.decoderModule[attributeName];

@@ -198,20 +181,10 @@ var attributeId = decoder.GetAttributeId(dracoGeometry, attributeType);

};
} // }
}
}
} // // Add attributes of user specified unique id. E.g. GLTF models.
// for (const attributeName in attributeUniqueIdMap) {
// const attributeType = attributeTypeMap[attributeName] || Float32Array;
// const attributeId = attributeUniqueIdMap[attributeName];
// const attribute = decoder.GetAttributeByUniqueId(dracoGeometry, attributeId);
// this.getAttributeTypedArray(decoder, dracoGeometry, attribute,attributeName,attributeType);
// }
return attributes;
} // For meshes, we need indices to define the faces.
}
}, {
key: "getMeshFaceIndices",
value: function getMeshFaceIndices(decoder, dracoGeometry) {
// Example on how to retrieve mesh and attributes.
var numFaces = dracoGeometry.num_faces();

@@ -232,4 +205,3 @@ var numIndices = numFaces * 3;

return indices;
} // For meshes, we need indices to define the faces.
}
}, {

@@ -239,4 +211,2 @@ key: "getMeshStripIndices",

var dracoArray = new this.decoderModule.DracoInt32Array();
/* const numStrips = */
decoder.GetTriangleStripsFromMesh(dracoGeometry, dracoArray);

@@ -256,4 +226,3 @@ var indices = new Uint32Array(dracoArray.size());

if (dracoAttribute.ptr === 0) {
var message = "DRACO decode bad attribute ".concat(attributeName); // console.error(message);
var message = "DRACO decode bad attribute ".concat(attributeName);
throw new Error(message);

@@ -313,8 +282,6 @@ }

default:
var errorMsg = 'DRACO decoder: unexpected attribute type.'; // console.error(errorMsg);
var errorMsg = 'DRACO decoder: unexpected attribute type.';
throw new Error(errorMsg);
} // Copy data from decoder.
}
for (var i = 0; i < numValues; i++) {

@@ -321,0 +288,0 @@ typedArray[i] = dracoArray.GetValue(i);

@@ -5,17 +5,2 @@ import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";

// This code is based on example code from the DRACO repository
// Copyright 2017 The Draco Authors.
//
// Licensed under the Apache License, Version 2.0 (the 'License');
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an 'AS IS' BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
var draco3d = require('draco3d');

@@ -30,6 +15,11 @@

};
var GLTF_TO_DRACO_ATTRIBUTE_NAME_MAP = {
POSITION: 'POSITION',
NORMAL: 'NORMAL',
COLOR_0: 'COLOR',
TEXCOORD_0: 'TEX_COORD'
};
function noop() {} // Copy encoded data to buffer
function noop() {}
function dracoInt8ArrayToArrayBuffer(dracoData) {

@@ -46,12 +36,4 @@ var byteLength = dracoData.size();

}
/* Encoder API:
https://github.com/google/draco/blob/master/src/draco/javascript/emscripten/draco_web_encoder.idl
Example:
https://github.com/google/draco/blob/master/javascript/npm/draco3d/draco_nodejs_example.js
*/
var DRACOEncoder =
/*#__PURE__*/
function () {
var DRACOEncoder = function () {
function DRACOEncoder() {

@@ -84,4 +66,3 @@ var opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};

}
} // Set encoding options.
}
}, {

@@ -99,4 +80,3 @@ key: "setOptions",

if ('method' in opts) {
var dracoMethod = this.dracoEncoderModule[opts.method]; // if (dracoMethod === undefined) {}
var dracoMethod = this.dracoEncoderModule[opts.method];
this.dracoEncoder.SetEncodingMethod(dracoMethod);

@@ -116,3 +96,2 @@ }

value: function encodePointCloud(attributes) {
// Build a `DracoPointCloud` from the input data
var dracoPointCloud = this._createDracoPointCloud(attributes);

@@ -139,3 +118,2 @@

value: function encodeMesh(attributes) {
// Build a `DracoMesh` from the input data
var dracoMesh = this._createDracoMesh(attributes);

@@ -175,2 +153,3 @@

var attribute = attributes[attributeName];
attributeName = GLTF_TO_DRACO_ATTRIBUTE_NAME_MAP[attributeName] || attributeName;

@@ -202,2 +181,3 @@ this._addAttributeToMesh(dracoMesh, attributeName, attribute, vertexCount);

var attribute = attributes[attributeName];
attributeName = GLTF_TO_DRACO_ATTRIBUTE_NAME_MAP[attributeName] || attributeName;

@@ -263,5 +243,3 @@ this._addAttributeToMesh(dracoPointCloud, attributeName, attribute, vertexCount);

}
} // DRACO can compress attributes of know type better
// TODO - expose an attribute type map?
}
}, {

@@ -268,0 +246,0 @@ key: "_getDracoAttributeType",

{
"name": "@loaders.gl/draco",
"version": "0.8.0",
"version": "1.0.0-alpha.1",
"description": "Framework-independent loader and writer for Draco compressed meshes and point clouds",

@@ -29,8 +29,7 @@ "license": "MIT",

],
"browser": {
"fs": false
},
"scripts": {
"clean": "rm -fr dist && mkdir -p dist",
"build": "npm run clean && npm run build-worker && npm run build-es6 && npm run build-esm && npm run build-es5",
"build-es6": "BABEL_ENV=es6 babel src --config-file ../../babel.config.js --out-dir dist/es6 --source-maps --ignore 'node_modules/'",
"build-esm": "BABEL_ENV=esm babel src --config-file ../../babel.config.js --out-dir dist/esm --source-maps --ignore 'node_modules/'",
"build-es5": "BABEL_ENV=es5 babel src --config-file ../../babel.config.js --out-dir dist/es5 --source-maps --ignore 'node_modules/'",
"pre-build": "npm run build-worker",
"build-worker": "webpack --entry ./src/draco-loader.worker.js --output ./dist/draco-loader.worker.js --config ../../scripts/worker-webpack-config.js"

@@ -41,5 +40,5 @@ },

"@babel/runtime": "^7.3.1",
"@loaders.gl/core": "^0.8.0",
"@loaders.gl/core": "1.0.0-alpha.1",
"draco3d": "^1.3.4"
}
}

@@ -5,2 +5,2 @@ # @loaders.gl/draco

This module contains loader and writer for Draco compressed meshes and point clouds.
This module contains loader and writer for Draco compressed meshes and point clouds.
// DRACO decompressor
import {getGLTFAccessors, getGLTFIndices, getGLTFAttributeMap} from '@loaders.gl/core';
import {getGLTFAccessors, getGLTFIndices} from './gltf-attribute-utils';

@@ -60,26 +60,25 @@ const draco3d = require('draco3d');

switch (geometryType) {
case this.decoderModule.TRIANGULAR_MESH:
dracoGeometry = new this.decoderModule.Mesh();
dracoStatus = decoder.DecodeBufferToMesh(buffer, dracoGeometry);
header = {
type: GEOMETRY_TYPE.TRIANGULAR_MESH,
faceCount: dracoGeometry.num_faces(),
attributeCount: dracoGeometry.num_attributes(),
vertexCount: dracoGeometry.num_points()
};
break;
case this.decoderModule.TRIANGULAR_MESH:
dracoGeometry = new this.decoderModule.Mesh();
dracoStatus = decoder.DecodeBufferToMesh(buffer, dracoGeometry);
header = {
type: GEOMETRY_TYPE.TRIANGULAR_MESH,
faceCount: dracoGeometry.num_faces(),
attributeCount: dracoGeometry.num_attributes(),
vertexCount: dracoGeometry.num_points()
};
break;
case this.decoderModule.POINT_CLOUD:
dracoGeometry = new this.decoderModule.PointCloud();
dracoStatus = decoder.DecodeBufferToPointCloud(buffer, dracoGeometry);
header = {
type: GEOMETRY_TYPE.POINT_CLOUD,
attributeCount: dracoGeometry.num_attributes(),
vertexCount: dracoGeometry.num_points()
};
break;
case this.decoderModule.POINT_CLOUD:
dracoGeometry = new this.decoderModule.PointCloud();
dracoStatus = decoder.DecodeBufferToPointCloud(buffer, dracoGeometry);
header = {
type: GEOMETRY_TYPE.POINT_CLOUD,
attributeCount: dracoGeometry.num_attributes(),
vertexCount: dracoGeometry.num_points()
};
break;
default:
throw new Error('Unknown DRACO geometry type.');
default:
throw new Error('Unknown DRACO geometry type.');
}

@@ -102,3 +101,2 @@

this.extractDRACOGeometry(decoder, dracoGeometry, data, geometryType);
} finally {

@@ -128,8 +126,10 @@ this.decoderModule.destroy(decoder);

if (geometryType === this.decoderModule.TRIANGULAR_MESH) {
attributes.indices = this.drawMode === 'TRIANGLE_STRIP' ?
this.getMeshStripIndices(decoder, dracoGeometry) :
this.getMeshFaceIndices(decoder, dracoGeometry);
geometry.mode = this.drawMode === 'TRIANGLE_STRIP' ?
5 : // GL.TRIANGLE_STRIP
4; // GL.TRIANGLES
attributes.indices =
this.drawMode === 'TRIANGLE_STRIP'
? this.getMeshStripIndices(decoder, dracoGeometry)
: this.getMeshFaceIndices(decoder, dracoGeometry);
geometry.mode =
this.drawMode === 'TRIANGLE_STRIP'
? 5 // GL.TRIANGLE_STRIP
: 4; // GL.TRIANGLES
} else {

@@ -141,3 +141,2 @@ geometry.mode = 0; // GL.POINTS

geometry.attributes = getGLTFAccessors(attributes);
geometry.glTFAttributeMap = getGLTFAttributeMap(attributes);

@@ -181,3 +180,6 @@ return geometry;

const {typedArray} = this.getAttributeTypedArray(
decoder, dracoGeometry, dracoAttribute, attributeName
decoder,
dracoGeometry,
dracoAttribute,
attributeName
);

@@ -251,50 +253,48 @@ attributes[DRACO_TO_GLTF_ATTRIBUTE_NAME_MAP[attributeName]] = {

switch (attributeType) {
case Float32Array:
dracoArray = new this.decoderModule.DracoFloat32Array();
decoder.GetAttributeFloatForAllPoints(dracoGeometry, dracoAttribute, dracoArray);
typedArray = new Float32Array(numValues);
break;
case Float32Array:
dracoArray = new this.decoderModule.DracoFloat32Array();
decoder.GetAttributeFloatForAllPoints(dracoGeometry, dracoAttribute, dracoArray);
typedArray = new Float32Array(numValues);
break;
case Int8Array:
dracoArray = new this.decoderModule.DracoInt8Array();
decoder.GetAttributeInt8ForAllPoints(dracoGeometry, dracoAttribute, dracoArray);
typedArray = new Int8Array(numValues);
break;
case Int8Array:
dracoArray = new this.decoderModule.DracoInt8Array();
decoder.GetAttributeInt8ForAllPoints(dracoGeometry, dracoAttribute, dracoArray);
typedArray = new Int8Array(numValues);
break;
case Int16Array:
dracoArray = new this.decoderModule.DracoInt16Array();
decoder.GetAttributeInt16ForAllPoints(dracoGeometry, dracoAttribute, dracoArray);
typedArray = new Int16Array(numValues);
break;
case Int16Array:
dracoArray = new this.decoderModule.DracoInt16Array();
decoder.GetAttributeInt16ForAllPoints(dracoGeometry, dracoAttribute, dracoArray);
typedArray = new Int16Array(numValues);
break;
case Int32Array:
dracoArray = new this.decoderModule.DracoInt32Array();
decoder.GetAttributeInt32ForAllPoints(dracoGeometry, dracoAttribute, dracoArray);
typedArray = new Int32Array(numValues);
break;
case Int32Array:
dracoArray = new this.decoderModule.DracoInt32Array();
decoder.GetAttributeInt32ForAllPoints(dracoGeometry, dracoAttribute, dracoArray);
typedArray = new Int32Array(numValues);
break;
case Uint8Array:
dracoArray = new this.decoderModule.DracoUInt8Array();
decoder.GetAttributeUInt8ForAllPoints(dracoGeometry, dracoAttribute, dracoArray);
typedArray = new Uint8Array(numValues);
break;
case Uint8Array:
dracoArray = new this.decoderModule.DracoUInt8Array();
decoder.GetAttributeUInt8ForAllPoints(dracoGeometry, dracoAttribute, dracoArray);
typedArray = new Uint8Array(numValues);
break;
case Uint16Array:
dracoArray = new this.decoderModule.DracoUInt16Array();
decoder.GetAttributeUInt16ForAllPoints(dracoGeometry, dracoAttribute, dracoArray);
typedArray = new Uint16Array(numValues);
break;
case Uint16Array:
dracoArray = new this.decoderModule.DracoUInt16Array();
decoder.GetAttributeUInt16ForAllPoints(dracoGeometry, dracoAttribute, dracoArray);
typedArray = new Uint16Array(numValues);
break;
case Uint32Array:
dracoArray = new this.decoderModule.DracoUInt32Array();
decoder.GetAttributeUInt32ForAllPoints(dracoGeometry, dracoAttribute, dracoArray);
typedArray = new Uint32Array(numValues);
break;
case Uint32Array:
dracoArray = new this.decoderModule.DracoUInt32Array();
decoder.GetAttributeUInt32ForAllPoints(dracoGeometry, dracoAttribute, dracoArray);
typedArray = new Uint32Array(numValues);
break;
default:
const errorMsg = 'DRACO decoder: unexpected attribute type.';
// console.error(errorMsg);
throw new Error(errorMsg);
default:
const errorMsg = 'DRACO decoder: unexpected attribute type.';
// console.error(errorMsg);
throw new Error(errorMsg);
}

@@ -301,0 +301,0 @@

@@ -28,2 +28,10 @@ // This code is based on example code from the DRACO repository

// Native Draco attribute names to GLTF attribute names.
const GLTF_TO_DRACO_ATTRIBUTE_NAME_MAP = {
POSITION: 'POSITION',
NORMAL: 'NORMAL',
COLOR_0: 'COLOR',
TEXCOORD_0: 'TEX_COORD'
};
function noop() {}

@@ -97,4 +105,7 @@

try {
const encodedLen =
this.dracoEncoder.EncodePointCloudToDracoBuffer(dracoPointCloud, false, dracoData);
const encodedLen = this.dracoEncoder.EncodePointCloudToDracoBuffer(
dracoPointCloud,
false,
dracoData
);

@@ -109,3 +120,2 @@ if (!(encodedLen > 0)) {

return dracoInt8ArrayToArrayBuffer(dracoData);
} finally {

@@ -133,3 +143,2 @@ this.destroyEncodedObject(dracoData);

return dracoInt8ArrayToArrayBuffer(dracoData);
} finally {

@@ -151,7 +160,7 @@ this.destroyEncodedObject(dracoData);

for (const attributeName in attributes) {
for (let attributeName in attributes) {
const attribute = attributes[attributeName];
attributeName = GLTF_TO_DRACO_ATTRIBUTE_NAME_MAP[attributeName] || attributeName;
this._addAttributeToMesh(dracoMesh, attributeName, attribute, vertexCount);
}
} catch (error) {

@@ -175,7 +184,7 @@ this.destroyEncodedObject(dracoMesh);

for (const attributeName in attributes) {
for (let attributeName in attributes) {
const attribute = attributes[attributeName];
attributeName = GLTF_TO_DRACO_ATTRIBUTE_NAME_MAP[attributeName] || attributeName;
this._addAttributeToMesh(dracoPointCloud, attributeName, attribute, vertexCount);
}
} catch (error) {

@@ -207,44 +216,72 @@ this.destroyEncodedObject(dracoPointCloud);

switch (attribute.constructor.name) {
case 'Int8Array':
this.dracoMeshBuilder.AddInt8Attribute(
dracoMesh, dracoAttributeType, vertexCount, size, attribute
);
break;
case 'Int8Array':
this.dracoMeshBuilder.AddInt8Attribute(
dracoMesh,
dracoAttributeType,
vertexCount,
size,
attribute
);
break;
case 'Int16Array':
this.dracoMeshBuilder.AddInt16Attribute(
dracoMesh, dracoAttributeType, vertexCount, size, attribute
);
break;
case 'Int16Array':
this.dracoMeshBuilder.AddInt16Attribute(
dracoMesh,
dracoAttributeType,
vertexCount,
size,
attribute
);
break;
case 'Int32Array':
this.dracoMeshBuilder.AddInt32Attribute(
dracoMesh, dracoAttributeType, vertexCount, size, attribute
);
break;
case 'Int32Array':
this.dracoMeshBuilder.AddInt32Attribute(
dracoMesh,
dracoAttributeType,
vertexCount,
size,
attribute
);
break;
case 'Uint8Array':
case 'Uint8ClampedArray':
this.dracoMeshBuilder.AddUInt8Attribute(
dracoMesh, dracoAttributeType, vertexCount, size, attribute
);
break;
case 'Uint8Array':
case 'Uint8ClampedArray':
this.dracoMeshBuilder.AddUInt8Attribute(
dracoMesh,
dracoAttributeType,
vertexCount,
size,
attribute
);
break;
case 'Uint16Array':
this.dracoMeshBuilder.AddUInt16Attribute(
dracoMesh, dracoAttributeType, vertexCount, size, attribute
);
break;
case 'Uint16Array':
this.dracoMeshBuilder.AddUInt16Attribute(
dracoMesh,
dracoAttributeType,
vertexCount,
size,
attribute
);
break;
case 'Uint32Array':
this.dracoMeshBuilder.AddUInt32Attribute(
dracoMesh, dracoAttributeType, vertexCount, size, attribute
);
break;
case 'Uint32Array':
this.dracoMeshBuilder.AddUInt32Attribute(
dracoMesh,
dracoAttributeType,
vertexCount,
size,
attribute
);
break;
case 'Float32Array':
default:
this.dracoMeshBuilder.AddFloatAttribute(
dracoMesh, dracoAttributeType, vertexCount, size, attribute
);
case 'Float32Array':
default:
this.dracoMeshBuilder.AddFloatAttribute(
dracoMesh,
dracoAttributeType,
vertexCount,
size,
attribute
);
}

@@ -257,19 +294,19 @@ }

switch (attributeName.toLowerCase()) {
case 'indices':
return 'indices';
case 'position':
case 'positions':
case 'vertices':
return this.dracoEncoderModule.POSITION;
case 'normal':
case 'normals':
return this.dracoEncoderModule.NORMAL;
case 'color':
case 'colors':
return this.dracoEncoderModule.COLOR;
case 'texCoord':
case 'texCoords':
return this.dracoEncoderModule.TEX_COORD;
default:
return this.dracoEncoderModule.GENERIC;
case 'indices':
return 'indices';
case 'position':
case 'positions':
case 'vertices':
return this.dracoEncoderModule.POSITION;
case 'normal':
case 'normals':
return this.dracoEncoderModule.NORMAL;
case 'color':
case 'colors':
return this.dracoEncoderModule.COLOR;
case 'texCoord':
case 'texCoords':
return this.dracoEncoderModule.TEX_COORD;
default:
return this.dracoEncoderModule.GENERIC;
}

@@ -276,0 +313,0 @@ }

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc