-
Notifications
You must be signed in to change notification settings - Fork 6
/
index.js
53 lines (39 loc) · 1 KB
/
index.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
50
51
52
53
AFRAME.registerComponent('sprite', {
schema: {
src: {
default: ''
},
resize:{
default: '1 1 1'
}
},
init: function()
{
this.textureLoader = new THREE.TextureLoader();
},
play: function()
{
console.log( this.data.src );
this.map = this.textureLoader.load(this.data.src);
this.material = new THREE.SpriteMaterial({
map: this.map
});
this.sprite = new THREE.Sprite(this.material);
resizeData = this.data.resize.split(' ');
this.sprite.scale.set( resizeData[0], resizeData[1], resizeData[2] );
this.el.setObject3D('mesh', this.sprite);
},
remove: function() {
console.log('remove sprite');
if (this.mesh) this.el.removeObject3D('mesh');
}
});
AFRAME.registerPrimitive('a-sprite', {
defaultComponents: {
sprite: {}
},
mappings: {
src: 'sprite.src',
resize: 'sprite.resize'
}
});