/
AnimationKeyframe.js
93 lines (74 loc) · 1.91 KB
/
AnimationKeyframe.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
"use strict";
function AnimationKeyframe(parent, editor, trackEditor, track, index)
{
Element.call(this, parent);
this.element.style.cursor = "pointer";
this.element.style.backgroundColor = track.color;
this.trackEditor = trackEditor;
this.editor = editor;
this.track = track;
this.index = index;
var self = this;
this.element.ondblclick = function(event)
{
var time = self.track.times[self.index];
self.editor.mixer.setTime(time);
};
//this.elementframe context menu
this.element.oncontextmenu = function(event)
{
var context = new ContextMenu();
context.size.set(150, 20);
context.position.set(event.clientX, event.clientY);
context.addOption("Delete", function()
{
if(!Editor.confirm("Delete keyframe?"))
{
return;
}
if(self.track.times.length === 1)
{
Editor.alert("Track needs to have at least one keyframe!");
return;
}
var times = [];
for(var i = 0; i < self.track.times.length; i++)
{
if(i !== self.index)
{
times.push(self.track.times[i]);
}
}
var values = [];
var valueSize = self.track.getValueSize();
var min = self.index * valueSize;
var max = min + valueSize - 1;
for(var i = 0; i < self.track.values.length; i++)
{
if(i < min || i > max)
{
values.push(self.track.values[i]);
}
}
self.track.times = new Float32Array(times);
self.track.values = new Float32Array(values);
self.trackEditor.updateKeyframes();
self.editor.createAnimationMixer();
});
context.addOption("Move", function()
{
var time = Number.parseFloat(prompt("Keyframe time"));
if(isNaN(time))
{
Editor.alert("Invalid time value!");
return;
}
self.track.times[self.index] = time;
self.track.sort();
self.trackEditor.updateKeyframes();
self.editor.createAnimationMixer();
});
context.updateInterface();
};
}
AnimationKeyframe.prototype = Object.create(Element.prototype);