-
Notifications
You must be signed in to change notification settings - Fork 4
/
TranslationSettings.ts
218 lines (143 loc) · 3.41 KB
/
TranslationSettings.ts
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
import { EventDispatcher, Vector3 } from "three";
import { SettingsEventMap } from "./SettingsEventMap.js";
/**
* Translation settings.
*
* @group Settings
*/
export class TranslationSettings extends EventDispatcher<SettingsEventMap> {
/**
* Triggers when the settings are changed.
*
* @event
*/
static readonly EVENT_CHANGE = "change";
/**
* @see {@link enabled}
*/
private _enabled: boolean;
/**
* @see {@link sensitivity}
*/
private _sensitivity: number;
/**
* @see {@link boostMultiplier}
*/
private _boostMultiplier: number;
/**
* @see {@link axisModifier}
*/
private _axisWeights: Vector3;
/**
* @see {@link damping}
*/
private _damping: number;
/**
* Constructs new translation settings.
*/
constructor() {
super();
this._enabled = true;
this._sensitivity = 1.0;
this._boostMultiplier = 2.0;
this._axisWeights = new Vector3(1, 1, 1);
this._damping = 0.0;
}
/**
* Indicates whether positional translation is enabled.
*/
get enabled(): boolean {
return this._enabled;
}
set enabled(value: boolean) {
this._enabled = value;
this.dispatchEvent({ type: TranslationSettings.EVENT_CHANGE });
}
/**
* The translation sensitivity.
*/
get sensitivity(): number {
return this._sensitivity;
}
set sensitivity(value: number) {
this._sensitivity = value;
this.dispatchEvent({ type: TranslationSettings.EVENT_CHANGE });
}
/**
* The translation boost multiplier.
*/
get boostMultiplier(): number {
return this._boostMultiplier;
}
set boostMultiplier(value: number) {
this._boostMultiplier = Math.max(value, 1.0);
this.dispatchEvent({ type: TranslationSettings.EVENT_CHANGE });
}
/**
* Weights that influence movement along each axis.
*/
get axisWeights(): Vector3 {
return this._axisWeights;
}
set axisWeights(value: Vector3) {
this._axisWeights = value;
this.dispatchEvent({ type: TranslationSettings.EVENT_CHANGE });
}
/**
* The damping factor. Range is [0.0, +Infinity]. Set to 0 to disable.
*/
get damping(): number {
return this._damping;
}
set damping(value: number) {
this._damping = value;
this.dispatchEvent({ type: TranslationSettings.EVENT_CHANGE });
}
/**
* Copies the given translation settings.
*
* @param settings - Translation settings.
* @return This instance.
*/
copy(settings: TranslationSettings): TranslationSettings {
this.enabled = settings.enabled;
this.sensitivity = settings.sensitivity;
this.boostMultiplier = settings.boostMultiplier;
this.damping = settings.damping;
return this;
}
/**
* Clones this translation settings instance.
*
* @return The cloned translation settings.
*/
clone(): TranslationSettings {
const clone = new TranslationSettings();
return clone.copy(this);
}
/**
* Copies the given JSON data.
*
* @param json - The JSON data.
* @return This instance.
*/
fromJSON(json: TranslationSettings): TranslationSettings {
this.enabled = json.enabled;
this.sensitivity = json.sensitivity;
this.boostMultiplier = json.boostMultiplier;
this.damping = json.damping;
if(json.axisWeights !== undefined) {
this.axisWeights.copy(json.axisWeights);
}
return this;
}
toJSON(): Record<string, unknown> {
return {
enabled: this.enabled,
sensitivity: this.sensitivity,
boostMultiplier: this.boostMultiplier,
axisWeights: this.axisWeights,
damping: this.damping
};
}
}