@loaders.gl/gltf
Advanced tools
Comparing version 0.4.5 to 0.4.6
@@ -10,3 +10,3 @@ "use strict"; | ||
var _unpackBinaryJson = _interopRequireDefault(require("./unpack-binary-json")); | ||
var _unpackBinaryJson = _interopRequireDefault(require("../packed-json/unpack-binary-json")); | ||
@@ -13,0 +13,0 @@ var _core = require("@loaders.gl/core"); |
@@ -60,10 +60,14 @@ "use strict"; | ||
}, { | ||
key: "getAppData", | ||
value: function getAppData(key) { | ||
return this.json.key; | ||
key: "getApplicationData", | ||
value: function getApplicationData(key) { | ||
// TODO - Data is already unpacked by GLBParser | ||
var data = this.json[key]; | ||
return data; | ||
} | ||
}, { | ||
key: "getExtras", | ||
value: function getExtras(json) { | ||
return this.json.extras; | ||
key: "getExtraData", | ||
value: function getExtraData(key) { | ||
// TODO - Data is already unpacked by GLBParser | ||
var extras = this.json.extras || {}; | ||
return extras[key]; | ||
} | ||
@@ -73,2 +77,3 @@ }, { | ||
value: function getExtension(extensionName) { | ||
// TODO - Data is already unpacked by GLBParser | ||
return this.json.extensions[extensionName]; | ||
@@ -75,0 +80,0 @@ } |
@@ -10,3 +10,3 @@ "use strict"; | ||
var _packBinaryJson = _interopRequireDefault(require("../glb-writer/pack-binary-json")); | ||
var _packBinaryJson = _interopRequireDefault(require("../packed-json/pack-binary-json")); | ||
@@ -43,3 +43,4 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
// Soft dependency on DRACO, app needs to import and supply these | ||
this.rootPath = rootPath; // Soft dependency on DRACO, app needs to import and supply these | ||
this.DracoEncoder = options.DracoEncoder; | ||
@@ -49,3 +50,2 @@ this.DracoDecoder = options.DracoDecoder; // Lets us keep track of how large the body will be, as well as the offset for each of the | ||
this.rootPath = rootPath; | ||
this.byteLength = 0; | ||
@@ -101,38 +101,45 @@ this.json = { | ||
// } | ||
// Packs JSON by extracting binary data and replacing it with JSON pointers | ||
// Add an extra application-defined key to the top-level data structure | ||
// By default packs JSON by extracting binary data and replacing it with JSON pointers | ||
}, { | ||
key: "packJSON", | ||
value: function packJSON(json, options) { | ||
return (0, _packBinaryJson.default)(json, this, options); | ||
} // Add an extra key to the top-level data structure | ||
}, { | ||
key: "addApplicationData", | ||
value: function addApplicationData(key, data) { | ||
this.json[key] = data; | ||
var packOptions = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; | ||
var packedJson = !packOptions.nopack && (0, _packBinaryJson.default)(data, this, packOptions); | ||
this.json[key] = packedJson; | ||
} // `extras` - Standard GLTF field for storing application specific data | ||
// By default packs JSON by extracting binary data and replacing it with JSON pointers | ||
}, { | ||
key: "addExtras", | ||
value: function addExtras(data) { | ||
this.json.extras = Object.assign(this.json.extras || {}, data); | ||
key: "addExtraData", | ||
value: function addExtraData(key, data) { | ||
var packOptions = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; | ||
var packedJson = !packOptions.nopack && (0, _packBinaryJson.default)(data, this, packOptions); | ||
this.json.extras = this.json.extras || {}; | ||
this.json.extras[key] = packedJson; | ||
return this; | ||
} // Add to standard GLTF top level extension object, mark as used | ||
// By default packs JSON by extracting binary data and replacing it with JSON pointers | ||
}, { | ||
key: "addExtension", | ||
value: function addExtension(extensionName, extension) { | ||
(0, _core.assert)(extension); | ||
value: function addExtension(extensionName, data) { | ||
var packOptions = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; | ||
(0, _core.assert)(data); | ||
var packedJson = !packOptions.nopack && (0, _packBinaryJson.default)(data, this, packOptions); | ||
this.json.extensions = this.json.extensions || {}; | ||
this.json.extensions[extensionName] = extension; | ||
this.json.extensions[extensionName] = packedJson; | ||
this.registerUsedExtension(extensionName); | ||
return this; | ||
} // Standard GLTF top level extension object, mark as used and required | ||
// By default packs JSON by extracting binary data and replacing it with JSON pointers | ||
}, { | ||
key: "addRequiredExtension", | ||
value: function addRequiredExtension(extensionName, extension) { | ||
(0, _core.assert)(extension); | ||
this.addExtension(extensionName, extension); | ||
value: function addRequiredExtension(extensionName, data) { | ||
var packOptions = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; | ||
(0, _core.assert)(data); | ||
var packedJson = !packOptions.nopack && (0, _packBinaryJson.default)(data, this, packOptions); | ||
this.addExtension(extensionName, packedJson); | ||
this.registerRequiredExtension(extensionName); | ||
@@ -191,8 +198,3 @@ return this; | ||
value: function isImage(imageData) { | ||
try { | ||
(0, _core.getImageSize)(imageData); | ||
return true; | ||
} catch (error) { | ||
return false; | ||
} | ||
return (0, _core.isImage)(imageData); | ||
} // Adds a binary image. Builds glTF "JSON metadata" and saves buffer reference | ||
@@ -199,0 +201,0 @@ // Buffer will be copied into BIN chunk during "pack" |
// Binary container format for glTF | ||
import GLBParser from './glb-parser'; | ||
export function parseGLB(arrayBuffer, options = {}) { | ||
export function parseGLB(arrayBuffer) { | ||
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
return new GLBParser(arrayBuffer).parse(options); | ||
} | ||
export function parseWithMetadata(arrayBuffer, options = {}) { | ||
export function parseWithMetadata(arrayBuffer) { | ||
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
return new GLBParser(arrayBuffer).parseWithMetadata(options); | ||
@@ -8,0 +10,0 @@ } |
/* eslint-disable camelcase, max-statements */ | ||
import unpackGLBBuffers from './unpack-glb-buffers'; | ||
import unpackBinaryJson from './unpack-binary-json'; | ||
import unpackBinaryJson from '../packed-json/unpack-binary-json'; | ||
import { TextDecoder, padTo4Bytes, assert } from '@loaders.gl/core'; | ||
@@ -26,3 +26,4 @@ import { ATTRIBUTE_TYPE_TO_COMPONENTS, ATTRIBUTE_COMPONENT_TYPE_TO_BYTE_SIZE, ATTRIBUTE_COMPONENT_TYPE_TO_ARRAY } from '../utils/gltf-type-utils'; | ||
export default class GLBParser { | ||
constructor(glbArrayBuffer, options = {}) { | ||
constructor(glbArrayBuffer) { | ||
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
// Soft dependency on Draco, needs to be imported and supplied by app | ||
@@ -35,3 +36,4 @@ this.DracoDecoder = options.DracoDecoder; | ||
parseAsJSON(options = {}) { | ||
parseAsJSON() { | ||
let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
return this.parse(options).json; | ||
@@ -41,3 +43,5 @@ } // Return the gltf JSON and the original arrayBuffer | ||
parse(options = {}) { | ||
parse() { | ||
let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
if (this.json === null && this.binaryByteOffset === null) { | ||
@@ -56,3 +60,5 @@ this._parseBinary(this.glbArrayBuffer, options); | ||
parseWithMetadata(options = {}) { | ||
parseWithMetadata() { | ||
let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
if (this.json === null || this.binaryByteOffset === null) { | ||
@@ -69,3 +75,5 @@ this._parseBinary(this.glbArrayBuffer, options); | ||
unpackJSON(appJson, options = {}) { | ||
unpackJSON(appJson) { | ||
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
if (this.json === null || this.binaryByteOffset === null) { | ||
@@ -81,3 +89,4 @@ throw new Error('parse() must be called before the GLBParser can unpackJSON'); | ||
_parseBinary(options = {}) { | ||
_parseBinary() { | ||
let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
const _options$magic = options.magic, | ||
@@ -84,0 +93,0 @@ magic = _options$magic === void 0 ? MAGIC_glTF : _options$magic; // GLB Header |
// Binary container format for glTF | ||
import GLBParser from '../glb-loader/glb-parser'; | ||
import GLTFParser from './gltf-parser'; | ||
export function parseTextGLTF(json, options = {}) { | ||
export function parseTextGLTF(json) { | ||
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
return new GLTFParser(json).parse(options); | ||
} | ||
export function parseBinaryGLTF(glbArrayBuffer, options = {}) { | ||
export function parseBinaryGLTF(glbArrayBuffer) { | ||
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
const _parseWithMetadata = new GLBParser(glbArrayBuffer).parseWithMetadata(options), | ||
@@ -9,0 +12,0 @@ json = _parseWithMetadata.json, |
@@ -16,3 +16,4 @@ import { getBytesFromComponentType, getSizeFromAccessorType } from '../utils/gltf-type-utils'; | ||
parse(options = {}) { | ||
parse() { | ||
let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
// Load all images | ||
@@ -31,11 +32,16 @@ this.out.images = (this.gltf.images || []).map(image => this.parseImage(image)).filter(Boolean); // Parse all scenes | ||
getAppData(key) { | ||
return this.json.key; | ||
getApplicationData(key) { | ||
// TODO - Data is already unpacked by GLBParser | ||
const data = this.json[key]; | ||
return data; | ||
} | ||
getExtras(json) { | ||
return this.json.extras; | ||
getExtraData(key) { | ||
// TODO - Data is already unpacked by GLBParser | ||
const extras = this.json.extras || {}; | ||
return extras[key]; | ||
} | ||
getExtension(extensionName) { | ||
// TODO - Data is already unpacked by GLBParser | ||
return this.json.extensions[extensionName]; | ||
@@ -135,3 +141,4 @@ } | ||
resolve(options = {}) { | ||
resolve() { | ||
let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
const gltf = this.gltf; | ||
@@ -138,0 +145,0 @@ (gltf.bufferViews || []).forEach((bufView, i) => this.resolveBufferView(bufView, i)); |
/* eslint-disable camelcase, max-statements */ | ||
import { assert, getImageSize, padTo4Bytes, copyArrayBuffer, TextEncoder, getAccessorTypeFromSize, getComponentTypeFromArray } from '@loaders.gl/core'; | ||
import packBinaryJson from '../glb-writer/pack-binary-json'; | ||
import { assert, isImage, getImageSize, padTo4Bytes, copyArrayBuffer, TextEncoder, getAccessorTypeFromSize, getComponentTypeFromArray } from '@loaders.gl/core'; | ||
import packBinaryJson from '../packed-json/pack-binary-json'; | ||
const MAGIC_glTF = 0x676c5446; // glTF in Big-Endian ASCII | ||
@@ -16,4 +16,6 @@ | ||
export default class GLTFBuilder { | ||
constructor(rootPath, options = {}) { | ||
// Soft dependency on DRACO, app needs to import and supply these | ||
constructor(rootPath) { | ||
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
this.rootPath = rootPath; // Soft dependency on DRACO, app needs to import and supply these | ||
this.DracoEncoder = options.DracoEncoder; | ||
@@ -23,3 +25,2 @@ this.DracoDecoder = options.DracoDecoder; // Lets us keep track of how large the body will be, as well as the offset for each of the | ||
this.rootPath = rootPath; | ||
this.byteLength = 0; | ||
@@ -48,3 +49,4 @@ this.json = { | ||
encodeAsGLB(options = {}) { | ||
encodeAsGLB() { | ||
let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
return this._createGlbBuffer(options); | ||
@@ -54,3 +56,5 @@ } // Returns an arrayBuffer together with JSON etc data. | ||
encodeAsGLBWithMetadata(options = {}) { | ||
encodeAsGLBWithMetadata() { | ||
let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
const arrayBuffer = this._createGlbBuffer(options); | ||
@@ -70,33 +74,41 @@ | ||
// } | ||
// Packs JSON by extracting binary data and replacing it with JSON pointers | ||
// Add an extra application-defined key to the top-level data structure | ||
// By default packs JSON by extracting binary data and replacing it with JSON pointers | ||
packJSON(json, options) { | ||
return packBinaryJson(json, this, options); | ||
} // Add an extra key to the top-level data structure | ||
addApplicationData(key, data) { | ||
this.json[key] = data; | ||
let packOptions = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; | ||
const packedJson = !packOptions.nopack && packBinaryJson(data, this, packOptions); | ||
this.json[key] = packedJson; | ||
} // `extras` - Standard GLTF field for storing application specific data | ||
// By default packs JSON by extracting binary data and replacing it with JSON pointers | ||
addExtras(data) { | ||
this.json.extras = Object.assign(this.json.extras || {}, data); | ||
addExtraData(key, data) { | ||
let packOptions = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; | ||
const packedJson = !packOptions.nopack && packBinaryJson(data, this, packOptions); | ||
this.json.extras = this.json.extras || {}; | ||
this.json.extras[key] = packedJson; | ||
return this; | ||
} // Add to standard GLTF top level extension object, mark as used | ||
// By default packs JSON by extracting binary data and replacing it with JSON pointers | ||
addExtension(extensionName, extension) { | ||
assert(extension); | ||
addExtension(extensionName, data) { | ||
let packOptions = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; | ||
assert(data); | ||
const packedJson = !packOptions.nopack && packBinaryJson(data, this, packOptions); | ||
this.json.extensions = this.json.extensions || {}; | ||
this.json.extensions[extensionName] = extension; | ||
this.json.extensions[extensionName] = packedJson; | ||
this.registerUsedExtension(extensionName); | ||
return this; | ||
} // Standard GLTF top level extension object, mark as used and required | ||
// By default packs JSON by extracting binary data and replacing it with JSON pointers | ||
addRequiredExtension(extensionName, extension) { | ||
assert(extension); | ||
this.addExtension(extensionName, extension); | ||
addRequiredExtension(extensionName, data) { | ||
let packOptions = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; | ||
assert(data); | ||
const packedJson = !packOptions.nopack && packBinaryJson(data, this, packOptions); | ||
this.addExtension(extensionName, packedJson); | ||
this.registerRequiredExtension(extensionName); | ||
@@ -127,5 +139,7 @@ return this; | ||
addBuffer(sourceBuffer, accessor = { | ||
size: 3 | ||
}) { | ||
addBuffer(sourceBuffer) { | ||
let accessor = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : { | ||
size: 3 | ||
}; | ||
const bufferViewIndex = this._addBufferView(sourceBuffer); // Add an accessor pointing to the new buffer view | ||
@@ -146,8 +160,3 @@ | ||
isImage(imageData) { | ||
try { | ||
getImageSize(imageData); | ||
return true; | ||
} catch (error) { | ||
return false; | ||
} | ||
return isImage(imageData); | ||
} // Adds a binary image. Builds glTF "JSON metadata" and saves buffer reference | ||
@@ -188,3 +197,5 @@ // Buffer will be copied into BIN chunk during "pack" | ||
addMesh(attributes, indices, mode = 4) { | ||
addMesh(attributes, indices) { | ||
let mode = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 4; | ||
const accessors = this._addAttributes(attributes); | ||
@@ -220,3 +231,5 @@ | ||
addCompressedMesh(attributes, indices, mode = 4) { | ||
addCompressedMesh(attributes, indices) { | ||
let mode = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 4; | ||
if (!this.DracoEncoder || !this.DracoDecoder) { | ||
@@ -365,3 +378,5 @@ throw new Error('DracoEncoder/Decoder not available'); | ||
_createGlbBuffer(options = {}) { | ||
_createGlbBuffer() { | ||
let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
// TODO - avoid double array buffer creation | ||
@@ -368,0 +383,0 @@ this._packBinaryChunk(); |
@@ -9,3 +9,3 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
import unpackGLBBuffers from './unpack-glb-buffers'; | ||
import unpackBinaryJson from './unpack-binary-json'; | ||
import unpackBinaryJson from '../packed-json/unpack-binary-json'; | ||
import { TextDecoder, padTo4Bytes, assert } from '@loaders.gl/core'; | ||
@@ -12,0 +12,0 @@ import { ATTRIBUTE_TYPE_TO_COMPONENTS, ATTRIBUTE_COMPONENT_TYPE_TO_BYTE_SIZE, ATTRIBUTE_COMPONENT_TYPE_TO_ARRAY } from '../utils/gltf-type-utils'; |
@@ -50,10 +50,14 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
}, { | ||
key: "getAppData", | ||
value: function getAppData(key) { | ||
return this.json.key; | ||
key: "getApplicationData", | ||
value: function getApplicationData(key) { | ||
// TODO - Data is already unpacked by GLBParser | ||
var data = this.json[key]; | ||
return data; | ||
} | ||
}, { | ||
key: "getExtras", | ||
value: function getExtras(json) { | ||
return this.json.extras; | ||
key: "getExtraData", | ||
value: function getExtraData(key) { | ||
// TODO - Data is already unpacked by GLBParser | ||
var extras = this.json.extras || {}; | ||
return extras[key]; | ||
} | ||
@@ -63,2 +67,3 @@ }, { | ||
value: function getExtension(extensionName) { | ||
// TODO - Data is already unpacked by GLBParser | ||
return this.json.extensions[extensionName]; | ||
@@ -65,0 +70,0 @@ } |
@@ -10,4 +10,4 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } | ||
/* eslint-disable camelcase, max-statements */ | ||
import { assert, getImageSize, padTo4Bytes, copyArrayBuffer, TextEncoder, getAccessorTypeFromSize, getComponentTypeFromArray } from '@loaders.gl/core'; | ||
import packBinaryJson from '../glb-writer/pack-binary-json'; | ||
import { assert, isImage as _isImage, getImageSize, padTo4Bytes, copyArrayBuffer, TextEncoder, getAccessorTypeFromSize, getComponentTypeFromArray } from '@loaders.gl/core'; | ||
import packBinaryJson from '../packed-json/pack-binary-json'; | ||
var MAGIC_glTF = 0x676c5446; // glTF in Big-Endian ASCII | ||
@@ -33,3 +33,4 @@ | ||
// Soft dependency on DRACO, app needs to import and supply these | ||
this.rootPath = rootPath; // Soft dependency on DRACO, app needs to import and supply these | ||
this.DracoEncoder = options.DracoEncoder; | ||
@@ -39,3 +40,2 @@ this.DracoDecoder = options.DracoDecoder; // Lets us keep track of how large the body will be, as well as the offset for each of the | ||
this.rootPath = rootPath; | ||
this.byteLength = 0; | ||
@@ -91,38 +91,45 @@ this.json = { | ||
// } | ||
// Packs JSON by extracting binary data and replacing it with JSON pointers | ||
// Add an extra application-defined key to the top-level data structure | ||
// By default packs JSON by extracting binary data and replacing it with JSON pointers | ||
}, { | ||
key: "packJSON", | ||
value: function packJSON(json, options) { | ||
return packBinaryJson(json, this, options); | ||
} // Add an extra key to the top-level data structure | ||
}, { | ||
key: "addApplicationData", | ||
value: function addApplicationData(key, data) { | ||
this.json[key] = data; | ||
var packOptions = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; | ||
var packedJson = !packOptions.nopack && packBinaryJson(data, this, packOptions); | ||
this.json[key] = packedJson; | ||
} // `extras` - Standard GLTF field for storing application specific data | ||
// By default packs JSON by extracting binary data and replacing it with JSON pointers | ||
}, { | ||
key: "addExtras", | ||
value: function addExtras(data) { | ||
this.json.extras = Object.assign(this.json.extras || {}, data); | ||
key: "addExtraData", | ||
value: function addExtraData(key, data) { | ||
var packOptions = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; | ||
var packedJson = !packOptions.nopack && packBinaryJson(data, this, packOptions); | ||
this.json.extras = this.json.extras || {}; | ||
this.json.extras[key] = packedJson; | ||
return this; | ||
} // Add to standard GLTF top level extension object, mark as used | ||
// By default packs JSON by extracting binary data and replacing it with JSON pointers | ||
}, { | ||
key: "addExtension", | ||
value: function addExtension(extensionName, extension) { | ||
assert(extension); | ||
value: function addExtension(extensionName, data) { | ||
var packOptions = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; | ||
assert(data); | ||
var packedJson = !packOptions.nopack && packBinaryJson(data, this, packOptions); | ||
this.json.extensions = this.json.extensions || {}; | ||
this.json.extensions[extensionName] = extension; | ||
this.json.extensions[extensionName] = packedJson; | ||
this.registerUsedExtension(extensionName); | ||
return this; | ||
} // Standard GLTF top level extension object, mark as used and required | ||
// By default packs JSON by extracting binary data and replacing it with JSON pointers | ||
}, { | ||
key: "addRequiredExtension", | ||
value: function addRequiredExtension(extensionName, extension) { | ||
assert(extension); | ||
this.addExtension(extensionName, extension); | ||
value: function addRequiredExtension(extensionName, data) { | ||
var packOptions = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; | ||
assert(data); | ||
var packedJson = !packOptions.nopack && packBinaryJson(data, this, packOptions); | ||
this.addExtension(extensionName, packedJson); | ||
this.registerRequiredExtension(extensionName); | ||
@@ -181,8 +188,3 @@ return this; | ||
value: function isImage(imageData) { | ||
try { | ||
getImageSize(imageData); | ||
return true; | ||
} catch (error) { | ||
return false; | ||
} | ||
return _isImage(imageData); | ||
} // Adds a binary image. Builds glTF "JSON metadata" and saves buffer reference | ||
@@ -189,0 +191,0 @@ // Buffer will be copied into BIN chunk during "pack" |
{ | ||
"name": "@loaders.gl/gltf", | ||
"version": "0.4.5", | ||
"version": "0.4.6", | ||
"description": "Framework-independent loader for the glTF format", | ||
@@ -43,4 +43,4 @@ "license": "MIT", | ||
"dependencies": { | ||
"@loaders.gl/core": "^0.4.5" | ||
"@loaders.gl/core": "^0.4.6" | ||
} | ||
} |
/* eslint-disable camelcase, max-statements */ | ||
import unpackGLBBuffers from './unpack-glb-buffers'; | ||
import unpackBinaryJson from './unpack-binary-json'; | ||
import unpackBinaryJson from '../packed-json/unpack-binary-json'; | ||
@@ -5,0 +5,0 @@ import {TextDecoder, padTo4Bytes, assert} from '@loaders.gl/core'; |
@@ -35,11 +35,16 @@ import {getBytesFromComponentType, getSizeFromAccessorType} from '../utils/gltf-type-utils'; | ||
getAppData(key) { | ||
return this.json.key; | ||
getApplicationData(key) { | ||
// TODO - Data is already unpacked by GLBParser | ||
const data = this.json[key]; | ||
return data; | ||
} | ||
getExtras(json) { | ||
return this.json.extras; | ||
getExtraData(key) { | ||
// TODO - Data is already unpacked by GLBParser | ||
const extras = this.json.extras || {}; | ||
return extras[key]; | ||
} | ||
getExtension(extensionName) { | ||
// TODO - Data is already unpacked by GLBParser | ||
return this.json.extensions[extensionName]; | ||
@@ -46,0 +51,0 @@ } |
/* eslint-disable camelcase, max-statements */ | ||
import { | ||
assert, | ||
isImage, | ||
getImageSize, | ||
@@ -11,3 +12,3 @@ padTo4Bytes, | ||
} from '@loaders.gl/core'; | ||
import packBinaryJson from '../glb-writer/pack-binary-json'; | ||
import packBinaryJson from '../packed-json/pack-binary-json'; | ||
@@ -28,2 +29,4 @@ const MAGIC_glTF = 0x676c5446; // glTF in Big-Endian ASCII | ||
constructor(rootPath, options = {}) { | ||
this.rootPath = rootPath; | ||
// Soft dependency on DRACO, app needs to import and supply these | ||
@@ -35,3 +38,2 @@ this.DracoEncoder = options.DracoEncoder; | ||
// original buffers. | ||
this.rootPath = rootPath; | ||
this.byteLength = 0; | ||
@@ -83,15 +85,15 @@ | ||
// Packs JSON by extracting binary data and replacing it with JSON pointers | ||
packJSON(json, options) { | ||
return packBinaryJson(json, this, options); | ||
// Add an extra application-defined key to the top-level data structure | ||
// By default packs JSON by extracting binary data and replacing it with JSON pointers | ||
addApplicationData(key, data, packOptions = {}) { | ||
const packedJson = !packOptions.nopack && packBinaryJson(data, this, packOptions); | ||
this.json[key] = packedJson; | ||
} | ||
// Add an extra key to the top-level data structure | ||
addApplicationData(key, data) { | ||
this.json[key] = data; | ||
} | ||
// `extras` - Standard GLTF field for storing application specific data | ||
addExtras(data) { | ||
this.json.extras = Object.assign(this.json.extras || {}, data); | ||
// By default packs JSON by extracting binary data and replacing it with JSON pointers | ||
addExtraData(key, data, packOptions = {}) { | ||
const packedJson = !packOptions.nopack && packBinaryJson(data, this, packOptions); | ||
this.json.extras = this.json.extras || {}; | ||
this.json.extras[key] = packedJson; | ||
return this; | ||
@@ -101,6 +103,8 @@ } | ||
// Add to standard GLTF top level extension object, mark as used | ||
addExtension(extensionName, extension) { | ||
assert(extension); | ||
// By default packs JSON by extracting binary data and replacing it with JSON pointers | ||
addExtension(extensionName, data, packOptions = {}) { | ||
assert(data); | ||
const packedJson = !packOptions.nopack && packBinaryJson(data, this, packOptions); | ||
this.json.extensions = this.json.extensions || {}; | ||
this.json.extensions[extensionName] = extension; | ||
this.json.extensions[extensionName] = packedJson; | ||
this.registerUsedExtension(extensionName); | ||
@@ -111,5 +115,7 @@ return this; | ||
// Standard GLTF top level extension object, mark as used and required | ||
addRequiredExtension(extensionName, extension) { | ||
assert(extension); | ||
this.addExtension(extensionName, extension); | ||
// By default packs JSON by extracting binary data and replacing it with JSON pointers | ||
addRequiredExtension(extensionName, data, packOptions = {}) { | ||
assert(data); | ||
const packedJson = !packOptions.nopack && packBinaryJson(data, this, packOptions); | ||
this.addExtension(extensionName, packedJson); | ||
this.registerRequiredExtension(extensionName); | ||
@@ -156,8 +162,3 @@ return this; | ||
isImage(imageData) { | ||
try { | ||
getImageSize(imageData); | ||
return true; | ||
} catch (error) { | ||
return false; | ||
} | ||
return isImage(imageData); | ||
} | ||
@@ -164,0 +165,0 @@ |
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 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 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 not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
458375
4920
Updated@loaders.gl/core@^0.4.6