-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathpickable.js
47 lines (37 loc) · 1.4 KB
/
pickable.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
pc.script.create('pickable', function (context) {
var Pickable = function (entity) {
this.entity = entity;
};
Pickable.prototype = {
initialize: function () {
this.model = this.entity.findByName('model');
this.glow = this.entity.findByName('glow');
this.aura = this.entity.findByName('aura');
// this._culled = false;
// this._hidden = false;
// this.sphere = new pc.shape.Sphere(this.entity.position, 1);
var self = this;
this.entity.on('culled', function(state) {
self.hidden(state);
});
},
update: function (dt) {
if (! this._hidden) {
var t = Math.sin(Date.now() / 400);
this.model.rotate(0, 180 * dt, 0);
this.model.setLocalPosition(0, .7 + t * .2, 0);
var scale = 1.5 + t * .5;
this.glow.setLocalScale(scale, 1, scale);
}
},
hidden: function(state) {
if (this._hidden === state)
return;
this._hidden = state;
this.model.enabled = ! this._hidden;
this.glow.enabled = ! this._hidden;
this.aura.enabled = ! this._hidden;
}
};
return Pickable;
});