@loaders.gl/gltf
Advanced tools
Comparing version 0.6.1 to 0.6.2
@@ -84,4 +84,4 @@ "use strict"; | ||
var packOptions = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; | ||
var packedJson = !packOptions.nopack && (0, _packBinaryJson.default)(data, this, packOptions); | ||
this.json[key] = packedJson; | ||
var jsonData = packOptions.nopack ? data : (0, _packBinaryJson.default)(data, this, packOptions); | ||
this.json[key] = jsonData; | ||
return this; | ||
@@ -105,28 +105,5 @@ } // Add a binary buffer. Builds glTF "JSON metadata" and saves buffer reference | ||
return this.addAccessor(bufferViewIndex, Object.assign(accessorDefaults, accessor)); | ||
} // Adds a binary image. Builds glTF "JSON metadata" and saves buffer reference | ||
// Buffer will be copied into BIN chunk during "pack" | ||
// Currently encodes as glTF image | ||
}, { | ||
key: "addImageData", | ||
value: function addImageData(imageData) { | ||
var bufferViewIndex = this.addBufferView(imageData); // Get the properties of the image to add as metadata. | ||
var sizeAndType = (0, _core.getImageSize)(imageData) || {}; | ||
if (sizeAndType) { | ||
var mimeType = sizeAndType.mimeType, | ||
width = sizeAndType.width, | ||
height = sizeAndType.height; | ||
this.addImageObject(bufferViewIndex, { | ||
mimeType: mimeType, | ||
width: width, | ||
height: height | ||
}); | ||
} else { | ||
this.addImageObject(bufferViewIndex, {}); | ||
} | ||
} // Basic glTF adders: basic memory buffer/image type fields | ||
// Scenegraph specific adders are placed in glTFBuilder | ||
// TODO: These should be moved to glTFBuilder once addBuffer and addImageData | ||
// TODO: These should be moved to glTFBuilder once addBuffer | ||
// have been rewritten to not depend on these. | ||
@@ -166,26 +143,2 @@ // Add one untyped source buffer, create a matching glTF `bufferView`, and return its index | ||
return this.json.accessors.length - 1; | ||
} // Adds a binary image. Builds glTF "JSON metadata" and saves buffer reference | ||
// Buffer will be copied into BIN chunk during "pack" | ||
// TODO - this method should be renamed addImage | ||
}, { | ||
key: "addImage", | ||
value: function addImage(bufferViewIndex, _ref) { | ||
var mimeType = _ref.mimeType, | ||
width = _ref.width, | ||
height = _ref.height; | ||
// DEPRECATED: We have renamed the addImage method, this is backwars compatibility | ||
if (ArrayBuffer.isView(bufferViewIndex)) { | ||
this.log.warn('GLBBuilder.addImage(): renamed to GLBBuilder.addImageData()'); | ||
return this.addImage.apply(this, arguments); | ||
} | ||
this.json.images.push({ | ||
bufferView: bufferViewIndex, | ||
mimeType: mimeType, | ||
width: width, | ||
height: height | ||
}); | ||
return this.json.images.length - 1; | ||
} // PRIVATE | ||
@@ -192,0 +145,0 @@ // For testing |
@@ -139,3 +139,3 @@ "use strict"; | ||
value: function getImage(glTFImage) { | ||
/* global window, Blob, Image */ | ||
/* global self, Blob, Image */ | ||
var arrayBufferView = this.getBufferView(glTFImage.bufferView); | ||
@@ -146,3 +146,3 @@ var mimeType = glTFImage.mimeType || 'image/jpeg'; | ||
}); | ||
var urlCreator = window.URL || window.webkitURL; | ||
var urlCreator = self.URL || self.webkitURL; | ||
var imageUrl = urlCreator.createObjectURL(blob); | ||
@@ -158,3 +158,3 @@ var img = new Image(); | ||
/* global window, Blob, Image */ | ||
/* global self, Blob, Image */ | ||
return new Promise(function (resolve) { | ||
@@ -167,3 +167,3 @@ var arrayBufferView = _this.getBufferView(glTFImage.bufferView); | ||
}); | ||
var urlCreator = window.URL || window.webkitURL; | ||
var urlCreator = self.URL || self.webkitURL; | ||
var imageUrl = urlCreator.createObjectURL(blob); | ||
@@ -170,0 +170,0 @@ var img = new Image(); |
@@ -78,4 +78,4 @@ "use strict"; | ||
var packOptions = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; | ||
var packedJson = !packOptions.nopack && (0, _packBinaryJson.default)(data, this, packOptions); | ||
this.json[key] = packedJson; | ||
var jsonData = packOptions.nopack ? data : (0, _packBinaryJson.default)(data, this, packOptions); | ||
this.json[key] = jsonData; | ||
return this; | ||
@@ -246,2 +246,34 @@ } // `extras` - Standard GLTF field for storing application specific data | ||
return this.json.meshes.length - 1; | ||
} // Adds a binary image. Builds glTF "JSON metadata" and saves buffer reference | ||
// Buffer will be copied into BIN chunk during "pack" | ||
// Currently encodes as glTF image | ||
}, { | ||
key: "addImage", | ||
value: function addImage(imageData) { | ||
var bufferViewIndex = this.addBufferView(imageData); // Get the properties of the image to add as metadata. | ||
var sizeAndType = (0, _core.getImageSize)(imageData) || {}; | ||
if (sizeAndType) { | ||
// width and height are non-spec fields | ||
var mimeType = sizeAndType.mimeType, | ||
width = sizeAndType.width, | ||
height = sizeAndType.height; | ||
this.json.images.push({ | ||
bufferView: bufferViewIndex, | ||
mimeType: mimeType, | ||
width: width, | ||
height: height | ||
}); | ||
} else { | ||
// TODO: Spec violation, if we are using a bufferView, mimeType must be defined | ||
// https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#images | ||
// "a reference to a bufferView; in that case mimeType must be defined." | ||
this.json.images.push({ | ||
bufferView: bufferViewIndex | ||
}); | ||
} | ||
return this.json.images.length - 1; | ||
} | ||
@@ -248,0 +280,0 @@ }]); |
@@ -10,4 +10,2 @@ "use strict"; | ||
var _glbParser = _interopRequireDefault(require("../glb/glb-parser")); | ||
var _gltfParser = _interopRequireDefault(require("./gltf-parser")); | ||
@@ -20,3 +18,3 @@ | ||
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
return new _gltfParser.default(json).parse(options); | ||
return new _gltfParser.default().parse(json, options); | ||
} | ||
@@ -26,8 +24,3 @@ | ||
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
var _parse = new _glbParser.default(glbArrayBuffer).parse(options), | ||
json = _parse.json, | ||
arrayBuffer = _parse.arrayBuffer; | ||
return new _gltfParser.default(json, arrayBuffer).parse(options); | ||
return new _gltfParser.default().parse(glbArrayBuffer, options); | ||
} | ||
@@ -34,0 +27,0 @@ |
/* eslint-disable camelcase, max-statements */ | ||
import { isImage, getImageSize, padTo4Bytes, copyArrayBuffer, copyToArray, TextEncoder, getAccessorTypeFromSize, getComponentTypeFromArray } from '@loaders.gl/core'; | ||
import { isImage, padTo4Bytes, copyArrayBuffer, copyToArray, TextEncoder, getAccessorTypeFromSize, getComponentTypeFromArray } from '@loaders.gl/core'; | ||
import packBinaryJson from '../packed-json/pack-binary-json'; | ||
@@ -57,4 +57,4 @@ const MAGIC_glTF = 0x676c5446; // glTF in Big-Endian ASCII | ||
let packOptions = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; | ||
const packedJson = !packOptions.nopack && packBinaryJson(data, this, packOptions); | ||
this.json[key] = packedJson; | ||
const jsonData = packOptions.nopack ? data : packBinaryJson(data, this, packOptions); | ||
this.json[key] = jsonData; | ||
return this; | ||
@@ -77,27 +77,5 @@ } // Add a binary buffer. Builds glTF "JSON metadata" and saves buffer reference | ||
return this.addAccessor(bufferViewIndex, Object.assign(accessorDefaults, accessor)); | ||
} // Adds a binary image. Builds glTF "JSON metadata" and saves buffer reference | ||
// Buffer will be copied into BIN chunk during "pack" | ||
// Currently encodes as glTF image | ||
addImageData(imageData) { | ||
const bufferViewIndex = this.addBufferView(imageData); // Get the properties of the image to add as metadata. | ||
const sizeAndType = getImageSize(imageData) || {}; | ||
if (sizeAndType) { | ||
const mimeType = sizeAndType.mimeType, | ||
width = sizeAndType.width, | ||
height = sizeAndType.height; | ||
this.addImageObject(bufferViewIndex, { | ||
mimeType, | ||
width, | ||
height | ||
}); | ||
} else { | ||
this.addImageObject(bufferViewIndex, {}); | ||
} | ||
} // Basic glTF adders: basic memory buffer/image type fields | ||
// Scenegraph specific adders are placed in glTFBuilder | ||
// TODO: These should be moved to glTFBuilder once addBuffer and addImageData | ||
// TODO: These should be moved to glTFBuilder once addBuffer | ||
// have been rewritten to not depend on these. | ||
@@ -135,25 +113,2 @@ // Add one untyped source buffer, create a matching glTF `bufferView`, and return its index | ||
return this.json.accessors.length - 1; | ||
} // Adds a binary image. Builds glTF "JSON metadata" and saves buffer reference | ||
// Buffer will be copied into BIN chunk during "pack" | ||
// TODO - this method should be renamed addImage | ||
addImage(bufferViewIndex, _ref) { | ||
let mimeType = _ref.mimeType, | ||
width = _ref.width, | ||
height = _ref.height; | ||
// DEPRECATED: We have renamed the addImage method, this is backwars compatibility | ||
if (ArrayBuffer.isView(bufferViewIndex)) { | ||
this.log.warn('GLBBuilder.addImage(): renamed to GLBBuilder.addImageData()'); | ||
return this.addImage(...arguments); | ||
} | ||
this.json.images.push({ | ||
bufferView: bufferViewIndex, | ||
mimeType, | ||
width, | ||
height | ||
}); | ||
return this.json.images.length - 1; | ||
} // PRIVATE | ||
@@ -160,0 +115,0 @@ // For testing |
@@ -107,3 +107,3 @@ /* eslint-disable camelcase, max-statements */ | ||
getImage(glTFImage) { | ||
/* global window, Blob, Image */ | ||
/* global self, Blob, Image */ | ||
const arrayBufferView = this.getBufferView(glTFImage.bufferView); | ||
@@ -114,3 +114,3 @@ const mimeType = glTFImage.mimeType || 'image/jpeg'; | ||
}); | ||
const urlCreator = window.URL || window.webkitURL; | ||
const urlCreator = self.URL || self.webkitURL; | ||
const imageUrl = urlCreator.createObjectURL(blob); | ||
@@ -123,3 +123,3 @@ const img = new Image(); | ||
getImageAsync(glTFImage) { | ||
/* global window, Blob, Image */ | ||
/* global self, Blob, Image */ | ||
return new Promise(resolve => { | ||
@@ -131,3 +131,3 @@ const arrayBufferView = this.getBufferView(glTFImage.bufferView); | ||
}); | ||
const urlCreator = window.URL || window.webkitURL; | ||
const urlCreator = self.URL || self.webkitURL; | ||
const imageUrl = urlCreator.createObjectURL(blob); | ||
@@ -134,0 +134,0 @@ const img = new Image(); |
/* eslint-disable camelcase, max-statements */ | ||
import GLBBuilder from '../glb/glb-builder'; | ||
import packBinaryJson from '../packed-json/pack-binary-json'; | ||
import { assert } from '@loaders.gl/core'; // Ideally we should just use KHR_draco_mesh_compression, but it requires saving uncompressed data? | ||
import { assert, getImageSize } from '@loaders.gl/core'; // Ideally we should just use KHR_draco_mesh_compression, but it requires saving uncompressed data? | ||
// TODO: until the ideal, we need to export these | ||
@@ -34,4 +34,4 @@ | ||
let packOptions = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; | ||
const packedJson = !packOptions.nopack && packBinaryJson(data, this, packOptions); | ||
this.json[key] = packedJson; | ||
const jsonData = packOptions.nopack ? data : packBinaryJson(data, this, packOptions); | ||
this.json[key] = jsonData; | ||
return this; | ||
@@ -193,2 +193,33 @@ } // `extras` - Standard GLTF field for storing application specific data | ||
return this.json.meshes.length - 1; | ||
} // Adds a binary image. Builds glTF "JSON metadata" and saves buffer reference | ||
// Buffer will be copied into BIN chunk during "pack" | ||
// Currently encodes as glTF image | ||
addImage(imageData) { | ||
const bufferViewIndex = this.addBufferView(imageData); // Get the properties of the image to add as metadata. | ||
const sizeAndType = getImageSize(imageData) || {}; | ||
if (sizeAndType) { | ||
// width and height are non-spec fields | ||
const mimeType = sizeAndType.mimeType, | ||
width = sizeAndType.width, | ||
height = sizeAndType.height; | ||
this.json.images.push({ | ||
bufferView: bufferViewIndex, | ||
mimeType, | ||
width, | ||
height | ||
}); | ||
} else { | ||
// TODO: Spec violation, if we are using a bufferView, mimeType must be defined | ||
// https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#images | ||
// "a reference to a bufferView; in that case mimeType must be defined." | ||
this.json.images.push({ | ||
bufferView: bufferViewIndex | ||
}); | ||
} | ||
return this.json.images.length - 1; | ||
} | ||
@@ -195,0 +226,0 @@ |
// Binary container format for glTF | ||
import GLBParser from '../glb/glb-parser'; | ||
import GLTFParser from './gltf-parser'; | ||
export function parseTextGLTF(json) { | ||
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
return new GLTFParser(json).parse(options); | ||
return new GLTFParser().parse(json, options); | ||
} | ||
export function parseBinaryGLTF(glbArrayBuffer) { | ||
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
const _parse = new GLBParser(glbArrayBuffer).parse(options), | ||
json = _parse.json, | ||
arrayBuffer = _parse.arrayBuffer; | ||
return new GLTFParser(json, arrayBuffer).parse(options); | ||
return new GLTFParser().parse(glbArrayBuffer, options); | ||
} | ||
@@ -17,0 +11,0 @@ export default { |
@@ -8,3 +8,3 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
/* eslint-disable camelcase, max-statements */ | ||
import { isImage as _isImage, getImageSize, padTo4Bytes, copyArrayBuffer, copyToArray, TextEncoder, getAccessorTypeFromSize, getComponentTypeFromArray } from '@loaders.gl/core'; | ||
import { isImage as _isImage, padTo4Bytes, copyArrayBuffer, copyToArray, TextEncoder, getAccessorTypeFromSize, getComponentTypeFromArray } from '@loaders.gl/core'; | ||
import packBinaryJson from '../packed-json/pack-binary-json'; | ||
@@ -75,4 +75,4 @@ var MAGIC_glTF = 0x676c5446; // glTF in Big-Endian ASCII | ||
var packOptions = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; | ||
var packedJson = !packOptions.nopack && packBinaryJson(data, this, packOptions); | ||
this.json[key] = packedJson; | ||
var jsonData = packOptions.nopack ? data : packBinaryJson(data, this, packOptions); | ||
this.json[key] = jsonData; | ||
return this; | ||
@@ -96,28 +96,5 @@ } // Add a binary buffer. Builds glTF "JSON metadata" and saves buffer reference | ||
return this.addAccessor(bufferViewIndex, Object.assign(accessorDefaults, accessor)); | ||
} // Adds a binary image. Builds glTF "JSON metadata" and saves buffer reference | ||
// Buffer will be copied into BIN chunk during "pack" | ||
// Currently encodes as glTF image | ||
}, { | ||
key: "addImageData", | ||
value: function addImageData(imageData) { | ||
var bufferViewIndex = this.addBufferView(imageData); // Get the properties of the image to add as metadata. | ||
var sizeAndType = getImageSize(imageData) || {}; | ||
if (sizeAndType) { | ||
var mimeType = sizeAndType.mimeType, | ||
width = sizeAndType.width, | ||
height = sizeAndType.height; | ||
this.addImageObject(bufferViewIndex, { | ||
mimeType: mimeType, | ||
width: width, | ||
height: height | ||
}); | ||
} else { | ||
this.addImageObject(bufferViewIndex, {}); | ||
} | ||
} // Basic glTF adders: basic memory buffer/image type fields | ||
// Scenegraph specific adders are placed in glTFBuilder | ||
// TODO: These should be moved to glTFBuilder once addBuffer and addImageData | ||
// TODO: These should be moved to glTFBuilder once addBuffer | ||
// have been rewritten to not depend on these. | ||
@@ -157,26 +134,2 @@ // Add one untyped source buffer, create a matching glTF `bufferView`, and return its index | ||
return this.json.accessors.length - 1; | ||
} // Adds a binary image. Builds glTF "JSON metadata" and saves buffer reference | ||
// Buffer will be copied into BIN chunk during "pack" | ||
// TODO - this method should be renamed addImage | ||
}, { | ||
key: "addImage", | ||
value: function addImage(bufferViewIndex, _ref) { | ||
var mimeType = _ref.mimeType, | ||
width = _ref.width, | ||
height = _ref.height; | ||
// DEPRECATED: We have renamed the addImage method, this is backwars compatibility | ||
if (ArrayBuffer.isView(bufferViewIndex)) { | ||
this.log.warn('GLBBuilder.addImage(): renamed to GLBBuilder.addImageData()'); | ||
return this.addImage.apply(this, arguments); | ||
} | ||
this.json.images.push({ | ||
bufferView: bufferViewIndex, | ||
mimeType: mimeType, | ||
width: width, | ||
height: height | ||
}); | ||
return this.json.images.length - 1; | ||
} // PRIVATE | ||
@@ -183,0 +136,0 @@ // For testing |
@@ -127,3 +127,3 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
value: function getImage(glTFImage) { | ||
/* global window, Blob, Image */ | ||
/* global self, Blob, Image */ | ||
var arrayBufferView = this.getBufferView(glTFImage.bufferView); | ||
@@ -134,3 +134,3 @@ var mimeType = glTFImage.mimeType || 'image/jpeg'; | ||
}); | ||
var urlCreator = window.URL || window.webkitURL; | ||
var urlCreator = self.URL || self.webkitURL; | ||
var imageUrl = urlCreator.createObjectURL(blob); | ||
@@ -146,3 +146,3 @@ var img = new Image(); | ||
/* global window, Blob, Image */ | ||
/* global self, Blob, Image */ | ||
return new Promise(function (resolve) { | ||
@@ -155,3 +155,3 @@ var arrayBufferView = _this.getBufferView(glTFImage.bufferView); | ||
}); | ||
var urlCreator = window.URL || window.webkitURL; | ||
var urlCreator = self.URL || self.webkitURL; | ||
var imageUrl = urlCreator.createObjectURL(blob); | ||
@@ -158,0 +158,0 @@ var img = new Image(); |
@@ -24,3 +24,3 @@ function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } | ||
import packBinaryJson from '../packed-json/pack-binary-json'; | ||
import { assert } from '@loaders.gl/core'; // Ideally we should just use KHR_draco_mesh_compression, but it requires saving uncompressed data? | ||
import { assert, getImageSize } from '@loaders.gl/core'; // Ideally we should just use KHR_draco_mesh_compression, but it requires saving uncompressed data? | ||
// TODO: until the ideal, we need to export these | ||
@@ -68,4 +68,4 @@ | ||
var packOptions = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; | ||
var packedJson = !packOptions.nopack && packBinaryJson(data, this, packOptions); | ||
this.json[key] = packedJson; | ||
var jsonData = packOptions.nopack ? data : packBinaryJson(data, this, packOptions); | ||
this.json[key] = jsonData; | ||
return this; | ||
@@ -236,2 +236,34 @@ } // `extras` - Standard GLTF field for storing application specific data | ||
return this.json.meshes.length - 1; | ||
} // Adds a binary image. Builds glTF "JSON metadata" and saves buffer reference | ||
// Buffer will be copied into BIN chunk during "pack" | ||
// Currently encodes as glTF image | ||
}, { | ||
key: "addImage", | ||
value: function addImage(imageData) { | ||
var bufferViewIndex = this.addBufferView(imageData); // Get the properties of the image to add as metadata. | ||
var sizeAndType = getImageSize(imageData) || {}; | ||
if (sizeAndType) { | ||
// width and height are non-spec fields | ||
var mimeType = sizeAndType.mimeType, | ||
width = sizeAndType.width, | ||
height = sizeAndType.height; | ||
this.json.images.push({ | ||
bufferView: bufferViewIndex, | ||
mimeType: mimeType, | ||
width: width, | ||
height: height | ||
}); | ||
} else { | ||
// TODO: Spec violation, if we are using a bufferView, mimeType must be defined | ||
// https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#images | ||
// "a reference to a bufferView; in that case mimeType must be defined." | ||
this.json.images.push({ | ||
bufferView: bufferViewIndex | ||
}); | ||
} | ||
return this.json.images.length - 1; | ||
} | ||
@@ -238,0 +270,0 @@ }]); |
// Binary container format for glTF | ||
import GLBParser from '../glb/glb-parser'; | ||
import GLTFParser from './gltf-parser'; | ||
export function parseTextGLTF(json) { | ||
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
return new GLTFParser(json).parse(options); | ||
return new GLTFParser().parse(json, options); | ||
} | ||
export function parseBinaryGLTF(glbArrayBuffer) { | ||
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
var _parse = new GLBParser(glbArrayBuffer).parse(options), | ||
json = _parse.json, | ||
arrayBuffer = _parse.arrayBuffer; | ||
return new GLTFParser(json, arrayBuffer).parse(options); | ||
return new GLTFParser().parse(glbArrayBuffer, options); | ||
} | ||
@@ -17,0 +11,0 @@ export default { |
@@ -81,3 +81,3 @@ "use strict"; | ||
var arrayBuffer = toArrayBuffer(binary); | ||
var data = new GLBParser(arrayBuffer).parse({ | ||
var data = new GLBParser().parse(arrayBuffer, { | ||
ignoreMagic: true | ||
@@ -136,4 +136,4 @@ }).getJSON(); | ||
function dumpGLTFScenes(data) { | ||
var gltfParser = new GLTFParser(data); | ||
var gltf = gltfParser.resolve(); | ||
var gltfParser = new GLTFParser(); | ||
var gltf = gltfParser.parse(data); | ||
@@ -140,0 +140,0 @@ if (gltf.asset) { |
{ | ||
"name": "@loaders.gl/gltf", | ||
"version": "0.6.1", | ||
"version": "0.6.2", | ||
"description": "Framework-independent loader for the glTF format", | ||
@@ -43,4 +43,5 @@ "license": "MIT", | ||
"dependencies": { | ||
"@loaders.gl/core": "^0.6.1" | ||
} | ||
"@loaders.gl/core": "^0.6.2" | ||
}, | ||
"gitHead": "20239ab03aa5b01cdc23d705a1da11e91a253b58" | ||
} |
/* eslint-disable camelcase, max-statements */ | ||
import { | ||
isImage, | ||
getImageSize, | ||
padTo4Bytes, | ||
@@ -71,4 +70,4 @@ copyArrayBuffer, | ||
addApplicationData(key, data, packOptions = {}) { | ||
const packedJson = !packOptions.nopack && packBinaryJson(data, this, packOptions); | ||
this.json[key] = packedJson; | ||
const jsonData = packOptions.nopack ? data : packBinaryJson(data, this, packOptions); | ||
this.json[key] = jsonData; | ||
return this; | ||
@@ -92,21 +91,5 @@ } | ||
// Adds a binary image. Builds glTF "JSON metadata" and saves buffer reference | ||
// Buffer will be copied into BIN chunk during "pack" | ||
// Currently encodes as glTF image | ||
addImageData(imageData) { | ||
const bufferViewIndex = this.addBufferView(imageData); | ||
// Get the properties of the image to add as metadata. | ||
const sizeAndType = getImageSize(imageData) || {}; | ||
if (sizeAndType) { | ||
const {mimeType, width, height} = sizeAndType; | ||
this.addImageObject(bufferViewIndex, {mimeType, width, height}); | ||
} else { | ||
this.addImageObject(bufferViewIndex, {}); | ||
} | ||
} | ||
// Basic glTF adders: basic memory buffer/image type fields | ||
// Scenegraph specific adders are placed in glTFBuilder | ||
// TODO: These should be moved to glTFBuilder once addBuffer and addImageData | ||
// TODO: These should be moved to glTFBuilder once addBuffer | ||
// have been rewritten to not depend on these. | ||
@@ -150,22 +133,2 @@ | ||
// Adds a binary image. Builds glTF "JSON metadata" and saves buffer reference | ||
// Buffer will be copied into BIN chunk during "pack" | ||
// TODO - this method should be renamed addImage | ||
addImage(bufferViewIndex, {mimeType, width, height}) { | ||
// DEPRECATED: We have renamed the addImage method, this is backwars compatibility | ||
if (ArrayBuffer.isView(bufferViewIndex)) { | ||
this.log.warn('GLBBuilder.addImage(): renamed to GLBBuilder.addImageData()'); | ||
return this.addImage(...arguments); | ||
} | ||
this.json.images.push({ | ||
bufferView: bufferViewIndex, | ||
mimeType, | ||
width, | ||
height | ||
}); | ||
return this.json.images.length - 1; | ||
} | ||
// PRIVATE | ||
@@ -172,0 +135,0 @@ |
@@ -114,7 +114,7 @@ /* eslint-disable camelcase, max-statements */ | ||
getImage(glTFImage) { | ||
/* global window, Blob, Image */ | ||
/* global self, Blob, Image */ | ||
const arrayBufferView = this.getBufferView(glTFImage.bufferView); | ||
const mimeType = glTFImage.mimeType || 'image/jpeg'; | ||
const blob = new Blob([arrayBufferView], {type: mimeType}); | ||
const urlCreator = window.URL || window.webkitURL; | ||
const urlCreator = self.URL || self.webkitURL; | ||
const imageUrl = urlCreator.createObjectURL(blob); | ||
@@ -127,3 +127,3 @@ const img = new Image(); | ||
getImageAsync(glTFImage) { | ||
/* global window, Blob, Image */ | ||
/* global self, Blob, Image */ | ||
return new Promise(resolve => { | ||
@@ -133,3 +133,3 @@ const arrayBufferView = this.getBufferView(glTFImage.bufferView); | ||
const blob = new Blob([arrayBufferView], {type: mimeType}); | ||
const urlCreator = window.URL || window.webkitURL; | ||
const urlCreator = self.URL || self.webkitURL; | ||
const imageUrl = urlCreator.createObjectURL(blob); | ||
@@ -136,0 +136,0 @@ const img = new Image(); |
/* eslint-disable camelcase, max-statements */ | ||
import GLBBuilder from '../glb/glb-builder'; | ||
import packBinaryJson from '../packed-json/pack-binary-json'; | ||
import {assert} from '@loaders.gl/core'; | ||
import { | ||
assert, | ||
getImageSize | ||
} from '@loaders.gl/core'; | ||
@@ -39,4 +42,4 @@ // Ideally we should just use KHR_draco_mesh_compression, but it requires saving uncompressed data? | ||
addApplicationData(key, data, packOptions = {}) { | ||
const packedJson = !packOptions.nopack && packBinaryJson(data, this, packOptions); | ||
this.json[key] = packedJson; | ||
const jsonData = packOptions.nopack ? data : packBinaryJson(data, this, packOptions); | ||
this.json[key] = jsonData; | ||
return this; | ||
@@ -204,2 +207,31 @@ } | ||
} | ||
// Adds a binary image. Builds glTF "JSON metadata" and saves buffer reference | ||
// Buffer will be copied into BIN chunk during "pack" | ||
// Currently encodes as glTF image | ||
addImage(imageData) { | ||
const bufferViewIndex = this.addBufferView(imageData); | ||
// Get the properties of the image to add as metadata. | ||
const sizeAndType = getImageSize(imageData) || {}; | ||
if (sizeAndType) { | ||
// width and height are non-spec fields | ||
const {mimeType, width, height} = sizeAndType; | ||
this.json.images.push({ | ||
bufferView: bufferViewIndex, | ||
mimeType, | ||
width, | ||
height | ||
}); | ||
} else { | ||
// TODO: Spec violation, if we are using a bufferView, mimeType must be defined | ||
// https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#images | ||
// "a reference to a bufferView; in that case mimeType must be defined." | ||
this.json.images.push({ | ||
bufferView: bufferViewIndex | ||
}); | ||
} | ||
return this.json.images.length - 1; | ||
} | ||
} |
// Binary container format for glTF | ||
import GLBParser from '../glb/glb-parser'; | ||
import GLTFParser from './gltf-parser'; | ||
export function parseTextGLTF(json, options = {}) { | ||
return new GLTFParser(json).parse(options); | ||
return new GLTFParser().parse(json, options); | ||
} | ||
export function parseBinaryGLTF(glbArrayBuffer, options = {}) { | ||
const {json, arrayBuffer} = new GLBParser(glbArrayBuffer).parse(options); | ||
return new GLTFParser(json, arrayBuffer).parse(options); | ||
return new GLTFParser().parse(glbArrayBuffer, options); | ||
} | ||
@@ -14,0 +12,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
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
82
501430
5331
Updated@loaders.gl/core@^0.6.2