Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bump Three.js to r84 #2456

Merged
merged 4 commits into from
Mar 6, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"present": "0.0.6",
"promise-polyfill": "^3.1.0",
"style-attr": "^1.0.2",
"three": "^0.83.0",
"three": "^0.84.0",
"three-bmfont-text": "^2.1.0",
"tween.js": "^15.0.0",
"webvr-polyfill": "dmarcos/webvr-polyfill#a02a8089b"
Expand Down
24 changes: 23 additions & 1 deletion src/core/a-assets.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,8 @@ registerElement('a-asset-item', {
value: function () {
var self = this;
var src = this.getAttribute('src');
fileLoader.setResponseType(this.getAttribute('response-type') || 'text');
fileLoader.setResponseType(
this.getAttribute('response-type') || inferResponseType(src));
fileLoader.load(src, function handleOnLoad (response) {
self.data = response;
/*
Expand Down Expand Up @@ -225,3 +226,24 @@ function extractDomain (url) {
// Find and remove port number.
return domain.split(':')[0];
}

/**
* Infer response-type attribute from src.
* Default is text(default XMLHttpRequest.responseType)
* but we use arraybuffer for .gltf and .glb files
* because of THREE.GLTFLoader specification.
*
* @param {string} src
* @returns {string}
*/
function inferResponseType (src) {
var dotLastIndex = src.lastIndexOf('.');
if (dotLastIndex >= 0) {
var extension = src.slice(dotLastIndex, src.length);
if (extension === '.gltf' || extension === '.glb') {
return 'arraybuffer';
}
}
return 'text';
}
module.exports.inferResponseType = inferResponseType;
File renamed without changes.
1 change: 1 addition & 0 deletions tests/assets/dummy/dummy.gltf
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dummy file for a-assets.test.js
1 change: 1 addition & 0 deletions tests/assets/dummy/dummy.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dummy file for a-assets.test.js
32 changes: 31 additions & 1 deletion tests/core/a-assets.test.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
/* global assert, setup, suite, test */
var THREE = require('lib/three');

var inferResponseType = require('core/a-assets').inferResponseType;

// Empty src will not trigger load events in Chrome.
// Use data URI where a load event is needed.
var IMG_SRC = 'data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7';

var XHR_SRC = '/base/tests/assets/dummy.txt';
var XHR_SRC = '/base/tests/assets/dummy/dummy.txt';
var XHR_SRC_GLTF = '/base/tests/assets/dummy/dummy.gltf';
var XHR_SRC_GLB = '/base/tests/assets/dummy/dummy.glb';

suite('a-assets', function () {
setup(function () {
Expand Down Expand Up @@ -284,4 +288,30 @@ suite('a-asset-item', function () {
this.assetsEl.appendChild(assetItem);
document.body.appendChild(this.sceneEl);
});

test('loads .gltf file as arraybuffer without response-type attribute', function (done) {
var assetItem = document.createElement('a-asset-item');
assetItem.setAttribute('src', XHR_SRC_GLTF);
assetItem.addEventListener('loaded', function (evt) {
assert.ok(assetItem.data !== null);
assert.ok(assetItem.data instanceof ArrayBuffer);
done();
});
this.assetsEl.appendChild(assetItem);
document.body.appendChild(this.sceneEl);
});

suite('inferResponseType', function () {
test('returns text as default', function () {
assert.equal(inferResponseType(XHR_SRC), 'text');
});

test('returns arraybuffer for .gltf file', function () {
assert.equal(inferResponseType(XHR_SRC_GLTF), 'arraybuffer');
});

test('returns arraybuffer for .glb file', function () {
assert.equal(inferResponseType(XHR_SRC_GLB), 'arraybuffer');
});
});
});