-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbatch_tween_scale.js
More file actions
60 lines (53 loc) · 1.86 KB
/
batch_tween_scale.js
File metadata and controls
60 lines (53 loc) · 1.86 KB
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
54
55
56
57
58
59
60
pc.script.attribute('from', 'vector', [1,1,1]);
pc.script.attribute('to', 'vector', [1,1,1]);
pc.script.attribute('duration', 'number', 1);
pc.script.attribute('easing', 'string', 'Quadratic.InOut');
pc.script.create('batch_tween_scale', function (context) {
var Batch_tween_scale = function (entity) {
this.entity = entity;
this.entities = [];
};
Batch_tween_scale.prototype = {
registerEntity: function (entity) {
this.entities.push({
entity: entity,
scale: entity.getLocalScale().clone()
});
},
initialize: function () {
this.startTween(this.from, this.to);
},
startTween: function (from, to) {
var self = this;
var easingParts = this.easing.split('.');
this.tween = new TWEEN.Tween({
x: from.x,
y: from.y,
z: from.z
}).to({
x: to.x,
y: to.y,
z: to.z
}, self.duration * 1000).easing(
TWEEN.Easing[easingParts[0]][easingParts[1]]
).onUpdate(function () {
var i=self.entities.length;
while(i--) {
var item = self.entities[i];
if (item.entity.getParent()) {
var scale = item.entity.getLocalScale().copy(item.scale);
scale.x *= this.x;
scale.y *= this.y
scale.z *= this.z;
item.entity.setLocalScale(scale);
} else {
self.entities.splice(i,1);
}
}
}).onComplete(function () {
self.startTween(to, from);
}).start();
}
};
return Batch_tween_scale;
});