forked from c-frame/aframe-extras
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fbx-model.js
37 lines (31 loc) · 847 Bytes
/
fbx-model.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
THREE.FBXLoader = require('../../lib/FBXLoader');
/**
* fbx-model
*
* Loader for FBX format. Supports ASCII, but *not* binary, models.
*/
module.exports = AFRAME.registerComponent('fbx-model', {
schema: {
src: { type: 'asset' },
crossorigin: { default: '' }
},
init: function () {
this.model = null;
},
update: function () {
const data = this.data;
if (!data.src) return;
this.remove();
const loader = new THREE.FBXLoader();
if (data.crossorigin) loader.setCrossOrigin(data.crossorigin);
loader.load(data.src, this.load.bind(this));
},
load: function (model) {
this.model = model;
this.el.setObject3D('mesh', model);
this.el.emit('model-loaded', {format: 'fbx', model: model});
},
remove: function () {
if (this.model) this.el.removeObject3D('mesh');
}
});