-
Notifications
You must be signed in to change notification settings - Fork 193
/
Copy pathGLTFAsset.js
49 lines (40 loc) · 1.6 KB
/
GLTFAsset.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
var Promise = require('bluebird');
var GLTFAssetBase = require('./GLTFAsset.autogen');
var widgets = require('@jupyter-widgets/base');
// HACK: examples expect THREE in globals
global.THREE = require('three');
require('three/examples/js/loaders/GLTFLoader.js');
var THREE = require('three');
var GLTFAssetModel = GLTFAssetBase.GLTFAssetModel.extend({
constructThreeObjectAsync: function() {
var manager = THREE.DefaultLoadingManager;
var loader = new THREE.GLTFLoader(manager);
// Ensure we resolve any local paths according to current notebook location:
var gltfUriPromise = this.widget_manager.resolveUrl(this.get('gltfUri'));
var p = new Promise(function(resolve, reject) {
gltfUriPromise.then(function (gltfUri) {
loader.load(
gltfUri,
function(gltf) {
console.debug('Successfully loaded ' + gltfUri);
return resolve(gltf);
},
function(xhr) {
console.debug(gltfUri + ': ' + (xhr.loaded / xhr.total * 100) + '%');
},
function(xhr) {
console.log('Error loading GLTF: ' + gltfUri);
return reject(new Error(xhr));
}
);
}, reject);
});
return p.bind(this).then(function(gltf) {
this.set({ scene: gltf.scene }, 'pushFromThree');
return gltf;
});
},
});
module.exports = {
GLTFAssetModel: GLTFAssetModel,
};