soiz1 commited on
Commit
cce5302
·
verified ·
1 Parent(s): 7601fb6

Create src/extensions copy/scratch3_posenet2scratch/index.js

Browse files
local-scratch-vm/src/extensions copy/scratch3_posenet2scratch/index.js ADDED
@@ -0,0 +1,945 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 const BlockType = require('../../extension-support/block-type');
3
+ const Cast = require('../../util/cast');
4
+ const ml5 = require('ml5');
5
+ const formatMessage = require('format-message');
6
+ const blockIconURI = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACgAAAAoCAYAAACM/rhtAAAABGdBTUEAALGPC/xhBQAAACBjSFJNAAB6JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAAACXBIWXMAAAsTAAALEwEAmpwYAAABWWlUWHRYTUw6Y29tLmFkb2JlLnhtcAAAAAAAPHg6eG1wbWV0YSB4bWxuczp4PSJhZG9iZTpuczptZXRhLyIgeDp4bXB0az0iWE1QIENvcmUgNS40LjAiPgogICA8cmRmOlJERiB4bWxuczpyZGY9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkvMDIvMjItcmRmLXN5bnRheC1ucyMiPgogICAgICA8cmRmOkRlc2NyaXB0aW9uIHJkZjphYm91dD0iIgogICAgICAgICAgICB4bWxuczp0aWZmPSJodHRwOi8vbnMuYWRvYmUuY29tL3RpZmYvMS4wLyI+CiAgICAgICAgIDx0aWZmOk9yaWVudGF0aW9uPjE8L3RpZmY6T3JpZW50YXRpb24+CiAgICAgIDwvcmRmOkRlc2NyaXB0aW9uPgogICA8L3JkZjpSREY+CjwveDp4bXBtZXRhPgpMwidZAAAKPElEQVRYCa1YaWyU1xU9M56xx/syZjAYjA02mN0UHAtCA5RGKa2oKApVk7TNIlWg0hYi0UhJFbVR+oOKJkWNokCUlLYkoqJLSEkaQgs0JECK2QRmszHe8Ib38Trjree8mXGAjD+PZO7oW+Z977537vLuve/Z0o68Moz7SEMcyxa87sew9vsxiMaQlAKWaYtCDJ+Dwf98jIvuC8CQxvS87PfCS7gCOcBLbeOhcQOU5mTWWELx87lr2nLMsDvROjyMNJvdgByPD0UMUCD6eUkrevqpJbWlEESW3YHagR58KzYNG/NXYUvGAgz01JtvE/k9zoAfHnEDskVMjrF6ykQClGaz8YoyoMQjcJLuwkAv/xD2oB9PTF6o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ja-Hira': 'のxざひょう',
12
+ 'en': ' x'
13
+ },
14
+ y: {
15
+ 'ja': 'のy座標',
16
+ 'ja-Hira': 'のyざひょう',
17
+ 'en': ' y'
18
+ },
19
+ peopleCount: {
20
+ 'ja': '人数',
21
+ 'ja-Hira': 'にんずう',
22
+ 'en': 'people count'
23
+ },
24
+ nose: {
25
+ 'ja': '鼻',
26
+ 'ja-Hira': 'はな',
27
+ 'en': 'nose'
28
+ },
29
+ leftEye: {
30
+ 'ja': '左目',
31
+ 'ja-Hira': 'ひだりめ',
32
+ 'en': 'left eye'
33
+ },
34
+ rightEye: {
35
+ 'ja': '右目',
36
+ 'ja-Hira': 'みぎめ',
37
+ 'en': 'right eye'
38
+ },
39
+ leftEar: {
40
+ 'ja': '左耳',
41
+ 'ja-Hira': 'ひだりみ���',
42
+ 'en': 'left ear'
43
+ },
44
+ rightEar: {
45
+ 'ja': '右耳',
46
+ 'ja-Hira': 'みぎみみ',
47
+ 'en': 'right ear'
48
+ },
49
+ leftShoulder: {
50
+ 'ja': '左肩',
51
+ 'ja-Hira': 'ひだりかた',
52
+ 'en': 'left shoulder'
53
+ },
54
+ rightShoulder: {
55
+ 'ja': '右肩',
56
+ 'ja-Hira': 'みぎかた',
57
+ 'en': 'right shoulder'
58
+ },
59
+ leftElbow: {
60
+ 'ja': '左ひじ',
61
+ 'ja-Hira': 'ひだりひじ',
62
+ 'en': 'left elbow'
63
+ },
64
+ rightElbow: {
65
+ 'ja': '右ひじ',
66
+ 'ja-Hira': 'みぎひじ',
67
+ 'en': 'right elbow'
68
+ },
69
+ leftWrist: {
70
+ 'ja': '左手首',
71
+ 'ja-Hira': 'ひだりてくび',
72
+ 'en': 'left wrist'
73
+ },
74
+ rightWrist: {
75
+ 'ja': '右手首',
76
+ 'ja-Hira': 'みぎてくび',
77
+ 'en': 'right wrist'
78
+ },
79
+ leftHip: {
80
+ 'ja': '左腰',
81
+ 'ja-Hira': 'ひだりこし',
82
+ 'en': 'left hip'
83
+ },
84
+ rightHip: {
85
+ 'ja': '右腰',
86
+ 'ja-Hira': 'みぎこし',
87
+ 'en': 'right hip'
88
+ },
89
+ leftKnee: {
90
+ 'ja': '左ひざ',
91
+ 'ja-Hira': 'ひだりひざ',
92
+ 'en': 'left knee'
93
+ },
94
+ rightKnee: {
95
+ 'ja': '右ひざ',
96
+ 'ja-Hira': 'みぎひざ',
97
+ 'en': 'right knee'
98
+ },
99
+ leftAnkle: {
100
+ 'ja': '左足首',
101
+ 'ja-Hira': 'ひだりあしくび',
102
+ 'en': 'left ankle'
103
+ },
104
+ rightAnkle: {
105
+ 'ja': '右足首',
106
+ 'ja-Hira': 'みぎあしくび',
107
+ 'en': 'right ankle'
108
+ },
109
+ getX: {
110
+ 'ja': '[PERSON_NUMBER] 人目の [PART] のx座標',
111
+ 'ja-Hira': '[PERSON_NUMBER] にんめの [PART] のxざひょう',
112
+ 'en': '[PART] x of person no. [PERSON_NUMBER]'
113
+ },
114
+ getY: {
115
+ 'ja': '[PERSON_NUMBER] 人目の [PART] のy座標',
116
+ 'ja-Hira': '[PERSON_NUMBER] にんめの [PART] のyざひょう',
117
+ 'en': '[PART] y of person no. [PERSON_NUMBER]'
118
+ },
119
+ videoToggle: {
120
+ 'ja': 'ビデオを[VIDEO_STATE]にする',
121
+ 'ja-Hira': 'ビデオを[VIDEO_STATE]にする',
122
+ 'en': 'turn video [VIDEO_STATE]'
123
+ },
124
+ on: {
125
+ 'ja': '入',
126
+ 'ja-Hira': 'いり',
127
+ 'en': 'on'
128
+ },
129
+ off: {
130
+ 'ja': '切',
131
+ 'ja-Hira': 'きり',
132
+ 'en': 'off'
133
+ },
134
+ video_on_flipped: {
135
+ 'ja': '左右反転',
136
+ 'ja-Hira': 'さゆうはんてん',
137
+ 'en': 'on flipped',
138
+ },
139
+ }
140
+ const AvailableLocales = ['en', 'ja', 'ja-Hira'];
141
+
142
+ class Scratch3Posenet2ScratchBlocks {
143
+ get PERSON_NUMBERS_MENU () {
144
+ return [
145
+ {
146
+ text: '1',
147
+ value: '1'
148
+ },
149
+ {
150
+ text: '2',
151
+ value: '2'
152
+ },
153
+ {
154
+ text: '3',
155
+ value: '3'
156
+ },
157
+ {
158
+ text: '4',
159
+ value: '4'
160
+ },
161
+ {
162
+ text: '5',
163
+ value: '5'
164
+ },
165
+ {
166
+ text: '6',
167
+ value: '6'
168
+ },
169
+ {
170
+ text: '7',
171
+ value: '7'
172
+ },
173
+ {
174
+ text: '8',
175
+ value: '8'
176
+ },
177
+ {
178
+ text: '9',
179
+ value: '9'
180
+ },
181
+ {
182
+ text: '10',
183
+ value: '10'
184
+ }
185
+ ]
186
+ }
187
+
188
+ get PARTS_MENU () {
189
+ return [
190
+ {
191
+ text: Message.nose[this._locale],
192
+ value: '0'
193
+ },
194
+ {
195
+ text: Message.leftEye[this._locale],
196
+ value: '1'
197
+ },
198
+ {
199
+ text: Message.rightEye[this._locale],
200
+ value: '2'
201
+ },
202
+ {
203
+ text: Message.leftEar[this._locale],
204
+ value: '3'
205
+ },
206
+ {
207
+ text: Message.rightEar[this._locale],
208
+ value: '4'
209
+ },
210
+ {
211
+ text: Message.leftShoulder[this._locale],
212
+ value: '5'
213
+ },
214
+ {
215
+ text: Message.rightShoulder[this._locale],
216
+ value: '6'
217
+ },
218
+ {
219
+ text: Message.leftElbow[this._locale],
220
+ value: '7'
221
+ },
222
+ {
223
+ text: Message.rightElbow[this._locale],
224
+ value: '8'
225
+ },
226
+ {
227
+ text: Message.leftWrist[this._locale],
228
+ value: '9'
229
+ },
230
+ {
231
+ text: Message.rightWrist[this._locale],
232
+ value: '10'
233
+ },
234
+ {
235
+ text: Message.leftHip[this._locale],
236
+ value: '11'
237
+ },
238
+ {
239
+ text: Message.rightHip[this._locale],
240
+ value: '12'
241
+ },
242
+ {
243
+ text: Message.leftKnee[this._locale],
244
+ value: '13'
245
+ },
246
+ {
247
+ text: Message.rightKnee[this._locale],
248
+ value: '14'
249
+ },
250
+ {
251
+ text: Message.leftAnkle[this._locale],
252
+ value: '15'
253
+ },
254
+ {
255
+ text: Message.rightAnkle[this._locale],
256
+ value: '16'
257
+ }
258
+ ]
259
+ }
260
+
261
+ get VIDEO_MENU () {
262
+ return [
263
+ {
264
+ text: Message.off[this._locale],
265
+ value: 'off'
266
+ },
267
+ {
268
+ text: Message.on[this._locale],
269
+ value: 'on'
270
+ },
271
+ {
272
+ text: Message.video_on_flipped[this._locale],
273
+ value: 'on-flipped'
274
+ }
275
+ ]
276
+ }
277
+
278
+ constructor (runtime) {
279
+ this.runtime = runtime;
280
+
281
+ this.poses = [];
282
+ this.keypoints = [];
283
+
284
+ let video = document.createElement("video");
285
+ video.width = 480;
286
+ video.height = 360;
287
+ video.autoplay = true;
288
+ video.style.display = "none";
289
+
290
+ let media = navigator.mediaDevices.getUserMedia({
291
+ video: true,
292
+ audio: false
293
+ });
294
+
295
+ media.then((stream) => {
296
+ video.srcObject = stream;
297
+ });
298
+
299
+ let poseNet = ml5.poseNet(video, ()=>{
300
+ console.log('Model Loaded!');
301
+ });
302
+
303
+ poseNet.on('pose', (poses)=>{
304
+ if (poses.length > 0) {
305
+ this.poses = poses;
306
+ this.keypoints = poses[0].pose.keypoints;
307
+ } else {
308
+ this.poses = [];
309
+ this.keypoints = [];
310
+ }
311
+ });
312
+
313
+ this.runtime.ioDevices.video.enableVideo();
314
+ }
315
+
316
+ getInfo () {
317
+ this._locale = this.setLocale();
318
+ return {
319
+ id: 'posenet2scratch',
320
+ name: 'Posenet2Scratch',
321
+ blockIconURI: blockIconURI,
322
+ blocks: [
323
+ {
324
+ opcode: 'getX',
325
+ blockType: BlockType.REPORTER,
326
+ text: Message.getX[this._locale],
327
+ arguments: {
328
+ PERSON_NUMBER: {
329
+ type: ArgumentType.STRING,
330
+ menu: 'personNumbers',
331
+ defaultValue: '1'
332
+ },
333
+ PART: {
334
+ type: ArgumentType.STRING,
335
+ menu: 'parts',
336
+ defaultValue: '0'
337
+ }
338
+ }
339
+ },
340
+ {
341
+ opcode: 'getY',
342
+ blockType: BlockType.REPORTER,
343
+ text: Message.getY[this._locale],
344
+ arguments: {
345
+ PERSON_NUMBER: {
346
+ type: ArgumentType.STRING,
347
+ menu: 'personNumbers',
348
+ defaultValue: '1'
349
+ },
350
+ PART: {
351
+ type: ArgumentType.STRING,
352
+ menu: 'parts',
353
+ defaultValue: '0'
354
+ }
355
+ }
356
+ },
357
+ { opcode: 'getPeopleCount',
358
+ blockType: BlockType.REPORTER,
359
+ text: Message.peopleCount[this._locale]
360
+ },
361
+ {
362
+ opcode: 'getNoseX',
363
+ blockType: BlockType.REPORTER,
364
+ text: Message.nose[this._locale] + Message.x[this._locale]
365
+ },
366
+ {
367
+ opcode: 'getNoseY',
368
+ blockType: BlockType.REPORTER,
369
+ text: Message.nose[this._locale] + Message.y[this._locale]
370
+ },
371
+ {
372
+ opcode: 'getLeftEyeX',
373
+ blockType: BlockType.REPORTER,
374
+ text: Message.leftEye[this._locale] + Message.x[this._locale]
375
+ },
376
+ {
377
+ opcode: 'getLeftEyeY',
378
+ blockType: BlockType.REPORTER,
379
+ text: Message.leftEye[this._locale] + Message.y[this._locale]
380
+ },
381
+ {
382
+ opcode: 'getRightEyeX',
383
+ blockType: BlockType.REPORTER,
384
+ text: Message.rightEye[this._locale] + Message.x[this._locale]
385
+ },
386
+ {
387
+ opcode: 'getRightEyeY',
388
+ blockType: BlockType.REPORTER,
389
+ text: Message.rightEye[this._locale] + Message.y[this._locale]
390
+ },
391
+ {
392
+ opcode: 'getLeftEarX',
393
+ blockType: BlockType.REPORTER,
394
+ text: Message.leftEar[this._locale] + Message.x[this._locale]
395
+ },
396
+ {
397
+ opcode: 'getLeftEarY',
398
+ blockType: BlockType.REPORTER,
399
+ text: Message.leftEar[this._locale] + Message.y[this._locale]
400
+ },
401
+ {
402
+ opcode: 'getRightEarX',
403
+ blockType: BlockType.REPORTER,
404
+ text: Message.rightEar[this._locale] + Message.x[this._locale]
405
+ },
406
+ {
407
+ opcode: 'getRightEarY',
408
+ blockType: BlockType.REPORTER,
409
+ text: Message.rightEar[this._locale] + Message.y[this._locale]
410
+ },
411
+ {
412
+ opcode: 'getLeftShoulderX',
413
+ blockType: BlockType.REPORTER,
414
+ text: Message.leftShoulder[this._locale] + Message.x[this._locale]
415
+ },
416
+ {
417
+ opcode: 'getLeftShoulderY',
418
+ blockType: BlockType.REPORTER,
419
+ text: Message.leftShoulder[this._locale] + Message.y[this._locale]
420
+ },
421
+ {
422
+ opcode: 'getRightShoulderX',
423
+ blockType: BlockType.REPORTER,
424
+ text: Message.rightShoulder[this._locale] + Message.x[this._locale]
425
+ },
426
+ {
427
+ opcode: 'getRightShoulderY',
428
+ blockType: BlockType.REPORTER,
429
+ text: Message.rightShoulder[this._locale] + Message.y[this._locale]
430
+ },
431
+ {
432
+ opcode: 'getLeftElbowX',
433
+ blockType: BlockType.REPORTER,
434
+ text: Message.leftElbow[this._locale] + Message.x[this._locale]
435
+ },
436
+ {
437
+ opcode: 'getLeftElbowY',
438
+ blockType: BlockType.REPORTER,
439
+ text: Message.leftElbow[this._locale] + Message.y[this._locale]
440
+ },
441
+ {
442
+ opcode: 'getRightElbowX',
443
+ blockType: BlockType.REPORTER,
444
+ text: Message.rightElbow[this._locale] + Message.x[this._locale]
445
+ },
446
+ {
447
+ opcode: 'getRightElbowY',
448
+ blockType: BlockType.REPORTER,
449
+ text: Message.rightElbow[this._locale] + Message.y[this._locale]
450
+ },
451
+ {
452
+ opcode: 'getLeftWristX',
453
+ blockType: BlockType.REPORTER,
454
+ text: Message.leftWrist[this._locale] + Message.x[this._locale]
455
+ },
456
+ {
457
+ opcode: 'getLeftWristY',
458
+ blockType: BlockType.REPORTER,
459
+ text: Message.leftWrist[this._locale] + Message.y[this._locale]
460
+ },
461
+ {
462
+ opcode: 'getRightWristX',
463
+ blockType: BlockType.REPORTER,
464
+ text: Message.rightWrist[this._locale] + Message.x[this._locale]
465
+ },
466
+ {
467
+ opcode: 'getRightWristY',
468
+ blockType: BlockType.REPORTER,
469
+ text: Message.rightWrist[this._locale] + Message.y[this._locale]
470
+ },
471
+ {
472
+ opcode: 'getLeftHipX',
473
+ blockType: BlockType.REPORTER,
474
+ text: Message.leftHip[this._locale] + Message.x[this._locale]
475
+ },
476
+ {
477
+ opcode: 'getLeftHipY',
478
+ blockType: BlockType.REPORTER,
479
+ text: Message.leftHip[this._locale] + Message.y[this._locale]
480
+ },
481
+ {
482
+ opcode: 'getRightHipX',
483
+ blockType: BlockType.REPORTER,
484
+ text: Message.rightHip[this._locale] + Message.x[this._locale]
485
+ },
486
+ {
487
+ opcode: 'getRightHipY',
488
+ blockType: BlockType.REPORTER,
489
+ text: Message.rightHip[this._locale] + Message.y[this._locale]
490
+ },
491
+ {
492
+ opcode: 'getLeftKneeX',
493
+ blockType: BlockType.REPORTER,
494
+ text: Message.leftKnee[this._locale] + Message.x[this._locale]
495
+ },
496
+ {
497
+ opcode: 'getLeftKneeY',
498
+ blockType: BlockType.REPORTER,
499
+ text: Message.leftKnee[this._locale] + Message.y[this._locale]
500
+ },
501
+ {
502
+ opcode: 'getRightKneeX',
503
+ blockType: BlockType.REPORTER,
504
+ text: Message.rightKnee[this._locale] + Message.x[this._locale]
505
+ },
506
+ {
507
+ opcode: 'getRightKneeY',
508
+ blockType: BlockType.REPORTER,
509
+ text: Message.rightKnee[this._locale] + Message.y[this._locale]
510
+ },
511
+ {
512
+ opcode: 'getLeftAnkleX',
513
+ blockType: BlockType.REPORTER,
514
+ text: Message.leftAnkle[this._locale] + Message.x[this._locale]
515
+ },
516
+ {
517
+ opcode: 'getLeftAnkleY',
518
+ blockType: BlockType.REPORTER,
519
+ text: Message.leftAnkle[this._locale] + Message.y[this._locale]
520
+ },
521
+ {
522
+ opcode: 'getRightAnkleX',
523
+ blockType: BlockType.REPORTER,
524
+ text: Message.rightAnkle[this._locale] + Message.x[this._locale]
525
+ },
526
+ {
527
+ opcode: 'getRightAnkleY',
528
+ blockType: BlockType.REPORTER,
529
+ text: Message.rightAnkle[this._locale] + Message.y[this._locale]
530
+ },
531
+ {
532
+ opcode: 'videoToggle',
533
+ blockType: BlockType.COMMAND,
534
+ text: Message.videoToggle[this._locale],
535
+ arguments: {
536
+ VIDEO_STATE: {
537
+ type: ArgumentType.STRING,
538
+ menu: 'videoMenu',
539
+ defaultValue: 'off'
540
+ }
541
+ }
542
+ }
543
+ ],
544
+ menus: {
545
+ personNumbers: {
546
+ acceptReporters: true,
547
+ items: this.PERSON_NUMBERS_MENU
548
+ },
549
+ parts: {
550
+ acceptReporters: true,
551
+ items: this.PARTS_MENU
552
+ },
553
+ videoMenu: {
554
+ acceptReporters: false,
555
+ items: this.VIDEO_MENU
556
+ }
557
+ }
558
+ };
559
+ }
560
+
561
+ getX (args) {
562
+ if (this.poses[parseInt(args.PERSON_NUMBER, 10) - 1] && this.poses[parseInt(args.PERSON_NUMBER, 10) - 1].pose.keypoints[parseInt(args.PART, 10)]) {
563
+ if (this.runtime.ioDevices.video.mirror === false) {
564
+ return -1 * (240 - this.poses[parseInt(args.PERSON_NUMBER, 10) - 1].pose.keypoints[parseInt(args.PART, 10)].position.x);
565
+ } else {
566
+ return 240 - this.poses[parseInt(args.PERSON_NUMBER, 10) - 1].pose.keypoints[parseInt(args.PART, 10)].position.x;
567
+ }
568
+ } else {
569
+ return "";
570
+ }
571
+ }
572
+
573
+ getY (args) {
574
+ if (this.poses[parseInt(args.PERSON_NUMBER, 10) - 1] && this.poses[parseInt(args.PERSON_NUMBER, 10) - 1].pose.keypoints[parseInt(args.PART, 10)]) {
575
+ return 180 - this.poses[parseInt(args.PERSON_NUMBER, 10) - 1].pose.keypoints[parseInt(args.PART, 10)].position.y;
576
+ } else {
577
+ return "";
578
+ }
579
+ }
580
+
581
+ getPeopleCount () {
582
+ return this.poses.length;
583
+ }
584
+
585
+ getNoseX () {
586
+ if (this.keypoints[0]) {
587
+ if (this.runtime.ioDevices.video.mirror === false) {
588
+ return -1 * (240 - this.keypoints[0].position.x);
589
+ } else {
590
+ return 240 - this.keypoints[0].position.x;
591
+ }
592
+ } else {
593
+ return "";
594
+ }
595
+ }
596
+
597
+ getNoseY () {
598
+ if (this.keypoints[0]) {
599
+ return 180 - this.keypoints[0].position.y;
600
+ } else {
601
+ return "";
602
+ }
603
+ }
604
+
605
+ getLeftEyeX () {
606
+ if (this.keypoints[1]) {
607
+ if (this.runtime.ioDevices.video.mirror === false) {
608
+ return -1 * (240 - this.keypoints[1].position.x);
609
+ } else {
610
+ return 240 - this.keypoints[1].position.x;
611
+ }
612
+ } else {
613
+ return "";
614
+ }
615
+ }
616
+
617
+ getLeftEyeY () {
618
+ if (this.keypoints[1]) {
619
+ return 180 - this.keypoints[1].position.y;
620
+ } else {
621
+ return "";
622
+ }
623
+ }
624
+
625
+ getRightEyeX () {
626
+ if (this.keypoints[2]) {
627
+ if (this.runtime.ioDevices.video.mirror === false) {
628
+ return -1 * (240 - this.keypoints[2].position.x);
629
+ } else {
630
+ return 240 - this.keypoints[2].position.x;
631
+ }
632
+ } else {
633
+ return "";
634
+ }
635
+ }
636
+
637
+ getRightEyeY () {
638
+ if (this.keypoints[2]) {
639
+ return 180 - this.keypoints[2].position.y;
640
+ } else {
641
+ return "";
642
+ }
643
+ }
644
+
645
+ getLeftEarX () {
646
+ if (this.keypoints[3]) {
647
+ if (this.runtime.ioDevices.video.mirror === false) {
648
+ return -1 * (240 - this.keypoints[3].position.x);
649
+ } else {
650
+ return 240 - this.keypoints[3].position.x;
651
+ }
652
+ } else {
653
+ return "";
654
+ }
655
+ }
656
+
657
+ getLeftEarY () {
658
+ if (this.keypoints[3]) {
659
+ return 180 - this.keypoints[3].position.y;
660
+ } else {
661
+ return "";
662
+ }
663
+ }
664
+
665
+ getRightEarX () {
666
+ if (this.keypoints[4]) {
667
+ if (this.runtime.ioDevices.video.mirror === false) {
668
+ return -1 * (240 - this.keypoints[4].position.x);
669
+ } else {
670
+ return 240 - this.keypoints[4].position.x;
671
+ }
672
+ } else {
673
+ return "";
674
+ }
675
+ }
676
+
677
+ getRightEarY () {
678
+ if (this.keypoints[4]) {
679
+ return 180 - this.keypoints[4].position.y;
680
+ } else {
681
+ return "";
682
+ }
683
+ }
684
+
685
+ getLeftShoulderX () {
686
+ if (this.keypoints[5]) {
687
+ if (this.runtime.ioDevices.video.mirror === false) {
688
+ return -1 * (240 - this.keypoints[5].position.x);
689
+ } else {
690
+ return 240 - this.keypoints[5].position.x;
691
+ }
692
+ } else {
693
+ return "";
694
+ }
695
+ }
696
+
697
+ getLeftShoulderY () {
698
+ if (this.keypoints[5]) {
699
+ return 180 - this.keypoints[5].position.y;
700
+ } else {
701
+ return "";
702
+ }
703
+ }
704
+
705
+ getRightShoulderX () {
706
+ if (this.keypoints[6]) {
707
+ if (this.runtime.ioDevices.video.mirror === false) {
708
+ return -1 * (240 - this.keypoints[6].position.x);
709
+ } else {
710
+ return 240 - this.keypoints[6].position.x;
711
+ }
712
+ } else {
713
+ return "";
714
+ }
715
+ }
716
+
717
+ getRightShoulderY () {
718
+ if (this.keypoints[6]) {
719
+ return 180 - this.keypoints[6].position.y;
720
+ } else {
721
+ return "";
722
+ }
723
+ }
724
+
725
+ getLeftElbowX () {
726
+ if (this.keypoints[7]) {
727
+ if (this.runtime.ioDevices.video.mirror === false) {
728
+ return -1 * (240 - this.keypoints[7].position.x);
729
+ } else {
730
+ return 240 - this.keypoints[7].position.x;
731
+ }
732
+ } else {
733
+ return "";
734
+ }
735
+ }
736
+
737
+ getLeftElbowY () {
738
+ if (this.keypoints[7]) {
739
+ return 180 - this.keypoints[7].position.y;
740
+ } else {
741
+ return "";
742
+ }
743
+ }
744
+
745
+ getRightElbowX () {
746
+ if (this.keypoints[8]) {
747
+ if (this.runtime.ioDevices.video.mirror === false) {
748
+ return -1 * (240 - this.keypoints[8].position.x);
749
+ } else {
750
+ return 240 - this.keypoints[8].position.x;
751
+ }
752
+ } else {
753
+ return "";
754
+ }
755
+ }
756
+
757
+ getRightElbowY () {
758
+ if (this.keypoints[8]) {
759
+ return 180 - this.keypoints[8].position.y;
760
+ } else {
761
+ return "";
762
+ }
763
+ }
764
+
765
+ getLeftWristX () {
766
+ if (this.keypoints[9]) {
767
+ if (this.runtime.ioDevices.video.mirror === false) {
768
+ return -1 * (240 - this.keypoints[9].position.x);
769
+ } else {
770
+ return 240 - this.keypoints[9].position.x;
771
+ }
772
+ } else {
773
+ return "";
774
+ }
775
+ }
776
+
777
+ getLeftWristY () {
778
+ if (this.keypoints[9]) {
779
+ return 180 - this.keypoints[9].position.y;
780
+ } else {
781
+ return "";
782
+ }
783
+ }
784
+
785
+ getRightWristX () {
786
+ if (this.keypoints[10]) {
787
+ if (this.runtime.ioDevices.video.mirror === false) {
788
+ return -1 * (240 - this.keypoints[10].position.x);
789
+ } else {
790
+ return 240 - this.keypoints[10].position.x;
791
+ }
792
+ } else {
793
+ return "";
794
+ }
795
+ }
796
+
797
+ getRightWristY () {
798
+ if (this.keypoints[10]) {
799
+ return 180 - this.keypoints[10].position.y;
800
+ } else {
801
+ return "";
802
+ }
803
+ }
804
+
805
+ getLeftHipX () {
806
+ if (this.keypoints[11]) {
807
+ if (this.runtime.ioDevices.video.mirror === false) {
808
+ return -1 * (240 - this.keypoints[11].position.x);
809
+ } else {
810
+ return 240 - this.keypoints[11].position.x;
811
+ }
812
+ } else {
813
+ return "";
814
+ }
815
+ }
816
+
817
+ getLeftHipY () {
818
+ if (this.keypoints[11]) {
819
+ return 180 - this.keypoints[11].position.y;
820
+ } else {
821
+ return "";
822
+ }
823
+ }
824
+
825
+ getRightHipX () {
826
+ if (this.keypoints[12]) {
827
+ if (this.runtime.ioDevices.video.mirror === false) {
828
+ return -1 * (240 - this.keypoints[12].position.x);
829
+ } else {
830
+ return 240 - this.keypoints[12].position.x;
831
+ }
832
+ } else {
833
+ return "";
834
+ }
835
+ }
836
+
837
+ getRightHipY () {
838
+ if (this.keypoints[12]) {
839
+ return 180 - this.keypoints[12].position.y;
840
+ } else {
841
+ return "";
842
+ }
843
+ }
844
+
845
+ getLeftKneeX () {
846
+ if (this.keypoints[13]) {
847
+ if (this.runtime.ioDevices.video.mirror === false) {
848
+ return -1 * (240 - this.keypoints[13].position.x);
849
+ } else {
850
+ return 240 - this.keypoints[13].position.x;
851
+ }
852
+ } else {
853
+ return "";
854
+ }
855
+ }
856
+
857
+ getLeftKneeY () {
858
+ if (this.keypoints[13]) {
859
+ return 180 - this.keypoints[13].position.y;
860
+ } else {
861
+ return "";
862
+ }
863
+ }
864
+
865
+ getRightKneeX () {
866
+ if (this.keypoints[14]) {
867
+ if (this.runtime.ioDevices.video.mirror === false) {
868
+ return -1 * (240 - this.keypoints[14].position.x);
869
+ } else {
870
+ return 240 - this.keypoints[14].position.x;
871
+ }
872
+ } else {
873
+ return "";
874
+ }
875
+ }
876
+
877
+ getRightKneeY () {
878
+ if (this.keypoints[14]) {
879
+ return 180 - this.keypoints[14].position.y;
880
+ } else {
881
+ return "";
882
+ }
883
+ }
884
+
885
+ getLeftAnkleX () {
886
+ if (this.keypoints[15]) {
887
+ if (this.runtime.ioDevices.video.mirror === false) {
888
+ return -1 * (240 - this.keypoints[15].position.x);
889
+ } else {
890
+ return 240 - this.keypoints[15].position.x;
891
+ }
892
+ } else {
893
+ return "";
894
+ }
895
+ }
896
+
897
+ getLeftAnkleY () {
898
+ if (this.keypoints[15]) {
899
+ return 180 - this.keypoints[15].position.y;
900
+ } else {
901
+ return "";
902
+ }
903
+ }
904
+
905
+ getRightAnkleX () {
906
+ if (this.keypoints[16]) {
907
+ if (this.runtime.ioDevices.video.mirror === false) {
908
+ return -1 * (240 - this.keypoints[16].position.x);
909
+ } else {
910
+ return 240 - this.keypoints[16].position.x;
911
+ }
912
+ } else {
913
+ return "";
914
+ }
915
+ }
916
+
917
+ getRightAnkleY () {
918
+ if (this.keypoints[16]) {
919
+ return 180 - this.keypoints[16].position.y;
920
+ } else {
921
+ return "";
922
+ }
923
+ }
924
+
925
+ videoToggle (args) {
926
+ let state = args.VIDEO_STATE;
927
+ if (state === 'off') {
928
+ this.runtime.ioDevices.video.disableVideo();
929
+ } else {
930
+ this.runtime.ioDevices.video.enableVideo();
931
+ this.runtime.ioDevices.video.mirror = state === "on";
932
+ }
933
+ }
934
+
935
+ setLocale() {
936
+ let locale = formatMessage.setup().locale;
937
+ if (AvailableLocales.includes(locale)) {
938
+ return locale;
939
+ } else {
940
+ return 'en';
941
+ }
942
+ }
943
+ }
944
+
945
+ module.exports = Scratch3Posenet2ScratchBlocks;