/
skel2Json.js
793 lines (780 loc) · 27.8 KB
/
skel2Json.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
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
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
const BlendMode = ['normal', 'additive', 'multiply', 'screen'];
const TransformMode = ['normal', 'onlyTranslation', 'noRotationOrReflection', 'noScale', 'noScaleOrReflection'];
const PositionMode = ['fixed', 'percent'];
const SpacingMode = ['length', 'fixed', 'percent'];
const RotateMode = ['tangent', 'chain', 'chainScale'];
const AttachmentType = ['region', 'boundingbox', 'mesh', 'linkedmesh', 'path', 'point', 'clipping'];
function SkeletonBinary() {
this.data = null;
this.scale = 1;
this.json = {};
this.nextNum = 0;
this.chars = null;
}
SkeletonBinary.prototype = {
data: null,
scale: 0x1,
json: {},
nextNum: 0x0,
chars: null,
readByte: function () {
return this.nextNum < this.data.length ? this.data[this.nextNum++] : null;
},
readBoolean: function () {
return this.readByte() != 0x0;
},
readShort: function () {
return this.readByte() << 0x8 | this.readByte();
},
readInt: function (optimizePositive) {
if (typeof optimizePositive === 'undefined') {
return this.readByte() << 0x18 | this.readByte() << 0x10 | this.readByte() << 0x8 | this.readByte();
}
let b = this.readByte();
let result = b & 0x7f;
if ((b & 0x80) != 0x0) {
b = this.readByte();
result |= (b & 0x7f) << 0x7;
if ((b & 0x80) != 0x0) {
b = this.readByte();
result |= (b & 0x7f) << 0xe;
if ((b & 0x80) != 0x0) {
b = this.readByte();
result |= (b & 0x7f) << 0x15;
if ((b & 0x80) != 0x0) {
b = this.readByte();
result |= (b & 0x7f) << 0x1c;
}
}
}
}
return optimizePositive ? result : result >> 0x1 ^ -(result & 0x1);
},
bytes2Float32: function (bytes) {
let sign = bytes & 0x80000000 ? -0x1 : 0x1;
let exponent = (bytes >> 0x17 & 0xff) - 0x7f;
let significand = bytes & ~(-0x1 << 0x17);
if (exponent == 0x80)
return sign * (significand ? Number.NaN : Number.POSITIVE_INFINITY);
if (exponent == -0x7f) {
if (significand == 0x0)
return sign * 0x0;
exponent = -0x7e;
significand /= 0x1 << 0x16;
} else
significand = (significand | 0x1 << 0x17) / (0x1 << 0x17);
return sign * significand * Math.pow(0x2, exponent);
},
readFloat: function () {
return this.bytes2Float32((this.readByte() << 0x18) + (this.readByte() << 0x10) + (this.readByte() << 0x8) + (this.readByte() << 0x0));
},
readVertices: function (vertexCount) {
let verticesLength = vertexCount << 0x1;
if (!this.readBoolean()) {
return this.readFloatArray(verticesLength, this.scale);
}
let bonesArray = new Array();
for (let i = 0x0; i < vertexCount; i++) {
let dataLength = this.readInt(!![]);
bonesArray.push(dataLength);
for (let j = 0x0; j < dataLength; j++) {
bonesArray.push(this.readInt(!![]));
bonesArray.push(this.readFloat() * this.scale);
bonesArray.push(this.readFloat() * this.scale);
bonesArray.push(this.readFloat());
}
}
return bonesArray;
},
readFloatArray: function (length, scale) {
let array = new Array(length);
if (scale == 0x1) {
for (let i = 0x0; i < length; i++) {
array[i] = this.readFloat();
}
} else {
for (let i = 0x0; i < length; i++) {
array[i] = this.readFloat() * scale;
}
}
return array;
},
readShortArray: function () {
let n = this.readInt(!![]);
let array = new Array(n);
for (let i = 0x0; i < n; i++) {
array[i] = this.readShort();
}
return array;
},
readIntArray: function () {
let n = this.readInt(!![]);
let array = new Array(n);
for (let i = 0x0; i < n; i++)
array[i] = this.readInt(!![]);
return array;
},
readHex: function () {
let hex = this.readByte().toString(0x10);
return hex.length == 0x2 ? hex : '0' + hex;
},
readColor: function () {
return this.readHex() + this.readHex() + this.readHex() + this.readHex();
},
readString: function () {
let charCount = this.readInt(this, !![]);
switch (charCount) {
case 0x0:
return null;
case 0x1:
return '';
}
charCount--;
this.chars = '';
let charIndex = 0x0;
for (let i = 0x0; i < charCount;) {
charIndex = this.readByte();
switch (charIndex >> 0x4) {
case 0xc:
case 0xd:
this.chars += String.fromCharCode((charIndex & 0x1f) << 0x6 | this.readByte() & 0x3f);
i += 0x2;
break;
case 0xe:
this.chars += String.fromCharCode((charIndex & 0xf) << 0xc | (this.readByte() & 0x3f) << 0x6 | this.readByte() & 0x3f);
i += 0x3;
break;
default:
this.chars += String.fromCharCode(charIndex);
i++;
}
}
return this.chars;
},
initJson: function () {
this.json.skeleton = {};
let skeleton = this.json.skeleton;
skeleton.hash = this.readString();
if (skeleton.hash.length == 0x0)
skeleton.hash = null;
skeleton.spine = this.readString();
if (skeleton.spine.length == 0x0)
skeleton.spine = null;
skeleton.width = this.readFloat();
skeleton.height = this.readFloat();
let nonessential = this.readBoolean();
if (nonessential) {
skeleton.fps = this.readFloat();
skeleton.images = this.readString();
if (skeleton.images.length == 0x0)
skeleton.images = null;
}
this.json.bones = new Array(this.readInt(!![]));
let bones = this.json.bones;
for (let i = 0x0; i < bones.length; i++) {
let boneData = {};
boneData.name = this.readString();
boneData.parent = null;
if (i != 0x0) {
const nonessential = this.readInt(!![]);
boneData.parent = bones[nonessential].name;
}
boneData.rotation = this.readFloat();
boneData['x'] = this.readFloat() * this.scale;
boneData['y'] = this.readFloat() * this.scale;
boneData.scaleX = this.readFloat();
boneData.scaleY = this.readFloat();
boneData.shearX = this.readFloat();
boneData.shearY = this.readFloat();
boneData.length = this.readFloat() * this.scale;
boneData.transform = TransformMode[this.readInt(!![])];
if (nonessential) {
boneData.color = this.readColor();
}
bones[i] = boneData;
}
this.json.slots = new Array(this.readInt(!![]));
let slots = this.json.slots;
for (let i = 0x0; i < slots.length; i++) {
let slotData = {};
slotData.name = this.readString();
const boneData = this.json.bones[this.readInt(!![])];
slotData.bone = boneData.name;
slotData.color = this.readColor();
slotData.attachment = this.readString();
slotData.blend = BlendMode[this.readInt(!![])];
slots[i] = slotData;
}
this.json['ik'] = new Array(this.readInt(!![]));
let ik = this.json['ik'];
for (let i = 0x0; i < ik.length; i++) {
let ikConstraints = {};
ikConstraints.name = this.readString();
ikConstraints.order = this.readInt(!![]);
ikConstraints.bones = new Array(this.readInt(!![]));
for (let j = 0x0; j < ikConstraints.bones.length; j++) {
ikConstraints.bones[j] = this.json.bones[this.readInt(!![])].name;
}
ikConstraints.target = this.json.bones[this.readInt(!![])].name;
ikConstraints.mix = this.readFloat();
ikConstraints.bendPositive = this.readByte() != 0xff;
ik[i] = ikConstraints;
}
this.json.transform = new Array(this.readInt(!![]));
let transform = this.json.transform;
for (let i = 0x0; i < transform.length; i++) {
let transformData = {};
transformData.name = this.readString();
transformData.order = this.readInt(!![]);
const bones = new Array(this.readInt(!![]));
for (let j = 0x0, len = bones.length; j < len; j++) {
bones[j] = this.json.bones[this.readInt(!![])].name;
}
transformData.bones = bones;
transformData.target = this.json.bones[this.readInt(!![])].name;
transformData.rotation = this.readFloat();
transformData['x'] = this.readFloat() * this.scale;
transformData['y'] = this.readFloat() * this.scale;
transformData.scaleX = this.readFloat();
transformData.scaleY = this.readFloat();
transformData.shearY = this.readFloat();
transformData.rotateMix = this.readFloat();
transformData.translateMix = this.readFloat();
transformData.scaleMix = this.readFloat();
transformData.shearMix = this.readFloat();
transform[i] = transformData;
}
this.json.path = new Array(this.readInt(!![]));
let path = this.json.path;
for (let i = 0x0; i < path.length; i++) {
let pathData = {};
pathData.name = this.readString();
pathData.order = this.readInt(!![]);
pathData.bones = new Array(this.readInt(!![]));
for (let j = 0x0, len = pathData.bones.length; j < len; j++) {
pathData.bones[j] = this.json.bones[this.readInt(!![])].name;
}
pathData.target = this.json.slots[this.readInt(!![])].name;
pathData.positionMode = PositionMode[this.readInt(!![])];
pathData.spacingMode = SpacingMode[this.readInt(!![])];
pathData.rotateMode = RotateMode[this.readInt(!![])];
pathData.rotation = this.readFloat();
pathData.position = this.readFloat();
if (pathData.positionMode == 'fixed') {
pathData.position *= this.scale;
}
pathData.spacing = this.readFloat();
if (pathData.spacingMode == 'length' || pathData.spacingMode == 'fixed') {
pathData.spacing *= this.scale;
}
pathData.rotateMix = this.readFloat();
pathData.translateMix = this.readFloat();
path[i] = pathData;
}
this.json.skins = {};
this.json.skinsName = new Array();
let skins = this.json.skins;
let skinData = this.readSkin('default', nonessential);
if (skinData != null) {
skins.default = skinData;
this.json.skinsName.push('default');
}
for (let i = 0x0, len = this.readInt(!![]); i < len; i++) {
let skinName = this.readString();
let skin = this.readSkin(skinName, nonessential);
skins[skinName] = skin;
this.json.skinsName.push(skinName);
}
this.json.events = [];
this.json.eventsName = [];
let events = this.json.events;
for (let i = 0x0, len = this.readInt(!![]); i < len; i++) {
let eventName = this.readString();
let event = {};
event.int = this.readInt(![]);
event.float = this.readFloat();
event.string = this.readString();
events[eventName] = event;
this.json.eventsName[i] = eventName;
}
this.json.animations = {};
let animations = this.json.animations;
for (let i = 0x0, len = this.readInt(!![]); i < len; i++) {
let animationName = this.readString();
let animation = this.readAnimation(animationName);
animations[animationName] = animation;
}
},
readSkin(slotIndex, nonessential) {
let slotCount = this.readInt(!![]);
if (slotCount == 0x0)
return null;
let skin = {};
for (let i = 0x0; i < slotCount; i++) {
const slotIndex = this.readInt(!![]);
const slot = {};
for (let j = 0x0, n = this.readInt(!![]); j < n; j++) {
let name = this.readString();
let attachment = this.readAttachment(name, nonessential);
if (attachment != null) {
slot[name] = attachment;
}
}
skin[this.json.slots[slotIndex].name] = slot;
}
return skin;
},
readAttachment(attachmentName, nonessential) {
let scale = this.scale;
let name = this.readString();
if (name == null)
name = attachmentName;
let path, n, region = {}, box = {}, mesh = {}, linkdeMesh = {};
let array;
let point = {};
let clipping = {};
switch (AttachmentType[this.readByte()]) {
case 'region':
path = this.readString();
if (path == null)
path = name;
region.type = 'region';
region.name = name;
region.path = path.trim();
region.rotation = this.readFloat();
region['x'] = this.readFloat() * scale;
region['y'] = this.readFloat() * scale;
region.scaleX = this.readFloat();
region.scaleY = this.readFloat();
region.width = this.readFloat() * scale;
region.height = this.readFloat() * scale;
region.color = this.readColor();
return region;
case 'boundingbox':
box.type = 'boundingbox';
box.name = name;
n = this.readInt(!![]);
box.vertexCount = n;
box.vertices = this.readVertices(n);
if (this.nonessential) {
box.color = this.readColor();
}
return box;
case 'mesh':
path = this.readString();
if (path == null)
path = name;
mesh.type = 'mesh';
mesh.name = name;
mesh.path = path;
mesh.color = this.readColor();
n = this.readInt(!![]);
mesh.uvs = this.readFloatArray(n << 0x1, 0x1);
mesh.triangles = this.readShortArray();
mesh.vertices = this.readVertices(n);
mesh.hull = this.readInt(!![]) << 0x1;
if (nonessential) {
mesh.edges = this.readShortArray();
mesh.width = this.readFloat() * scale;
mesh.height = this.readFloat() * scale;
}
return mesh;
case 'linkedmesh':
path = this.readString();
if (path == null)
path = name;
linkdeMesh.type = 'linkedmesh';
linkdeMesh.name = name;
linkdeMesh.path = path;
linkdeMesh.color = this.readColor();
linkdeMesh.skin = this.readString();
linkdeMesh.parent = this.readString();
linkdeMesh.deform = this.readBoolean();
if (nonessential) {
linkdeMesh.width = this.readFloat() * scale;
linkdeMesh.height = this.readFloat() * scale;
}
return linkdeMesh;
case 'path':
path = {};
path.type = 'path';
path.name = name;
path.closed = this.readBoolean();
path.constantSpeed = this.readBoolean();
n = this.readInt(!![]);
path.vertexCount = n;
path.vertices = this.readVertices(n);
array = array = new Array(n / 0x3);
for (let i = 0x0; i < array.length; i++) {
array[i] = this.readFloat() * scale;
}
path.lengths = array;
if (nonessential) {
path.color = this.readColor();
}
return path;
case 'point':
point.type = 'point';
point.name = name;
point.rotation = this.readFloat();
point['x'] = this.readFloat() * scale;
point['y'] = this.readFloat() * scale;
if (nonessential) {
path.color = this.readColor();
}
return point;
case 'clipping':
clipping.type = 'clipping';
clipping.name = name;
clipping.end = this.readInt(!![]);
n = this.readInt(!![]);
clipping.vertexCount = n;
clipping.vertices = this.readVertices(n);
if (nonessential) {
clipping.color = this.readColor();
}
return clipping;
}
return null;
},
readCurve(frameIndex, timeline) {
let cx1, cy1, cx2, cy2;
switch (this.readByte()) {
case 0x0:
timeline[frameIndex].curve = 'linear';
break;
case 0x1:
timeline[frameIndex].curve = 'stepped';
break;
case 0x2:
cx1 = this.readFloat();
cy1 = this.readFloat();
cx2 = this.readFloat();
cy2 = this.readFloat();
timeline[frameIndex].curve = [cx1, cy1, cx2, cy2];
}
},
readAnimation(name) {
let animation = {};
let scale = this.scale;
let duration = 0x0;
let slots = {};
for (let i = 0x0, nn = this.readInt(!![]); i < nn; i++) {
let slotIndex = this.readInt(!![]);
let slotMap = {};
let timeCount = this.readInt(!![]);
for (let ii = 0x0; ii < timeCount; ii++) {
let timelineType = this.readByte();
let frameCount = this.readInt(!![]);
let timeline;
switch (timelineType) {
case 0x0:
timeline = new Array(frameCount);
for (let frameIndex = 0x0; frameIndex < frameCount; frameIndex++) {
let time = this.readFloat();
let color = this.readString();
timeline[frameIndex] = {};
timeline[frameIndex].time = time;
timeline[frameIndex].name = color;
}
slotMap.attachment = timeline;
duration = Math.max(duration, timeline[frameCount - 0x1].time);
break;
case 0x1:
timeline = new Array(frameCount);
for (let frameIndex = 0x0; frameIndex < frameCount; frameIndex++) {
const time = this.readFloat();
const color = this.readColor();
timeline[frameIndex] = {};
timeline[frameIndex].time = time;
timeline[frameIndex].color = color;
if (frameIndex < frameCount - 0x1) {
this.readCurve(frameIndex, timeline); //let curve
}
}
slotMap.color = timeline;
duration = Math.max(duration, timeline[frameCount - 0x1].time);
break;
case 0x2:
timeline = new Array(frameCount);
for (let frameIndex = 0x0; frameIndex < frameCount; frameIndex++) {
const time = this.readFloat();
let lightColor = this.readColor();
let darkColor = this.readColor();
timeline[frameIndex] = {};
timeline[frameIndex].time = time;
timeline[frameIndex].light = lightColor;
timeline[frameIndex].dark = darkColor;
if (frameIndex < frameCount - 0x1) {
this.readCurve(frameIndex, timeline);// let curve
}
}
slotMap.twoColor = timeline;
duration = Math.max(duration, timeline[frameCount - 0x1].time);
break;
}
}
slots[this.json.slots[slotIndex].name] = slotMap;
}
animation.slots = slots;
let bones = {};
for (let i = 0x0, n = this.readInt(!![]); i < n; i++) {
let boneIndex = this.readInt(!![]);
let boneMap = {};
for (let ii = 0x0, nn = this.readInt(!![]); ii < nn; ii++) {
const timelineType = this.readByte();
const frameCount = this.readInt(!![]);
let timeline;
let timelineScale = 0x1;
switch (timelineType) {
case 0x0:
timeline = new Array(frameCount);
for (let frameIndex = 0x0; frameIndex < frameCount; frameIndex++) {
const time = this.readFloat();
const tlangle = this.readFloat();
timeline[frameIndex] = {};
timeline[frameIndex].time = time;
timeline[frameIndex].angle = tlangle;
if (frameIndex < frameCount - 0x1) {
this.readCurve(frameIndex, timeline);
}
}
boneMap.rotate = timeline;
duration = Math.max(duration, timeline[frameCount - 0x1].time);
break;
case 0x1:
case 0x2:
case 0x3:
timeline = new Array(frameCount);
if (timelineType == 0x1) {
timelineScale = scale;
}
for (let frameIndex = 0x0; frameIndex < frameCount; frameIndex++) {
let tltime = this.readFloat();
let tlx = this.readFloat();
let tly = this.readFloat();
timeline[frameIndex] = {};
timeline[frameIndex].time = tltime;
timeline[frameIndex]['x'] = tlx * timelineScale;
timeline[frameIndex]['y'] = tly * timelineScale;
if (frameIndex < frameCount - 0x1) {
this.readCurve(frameIndex, timeline);
}
}
if (timelineType == 0x1) {
boneMap.translate = timeline;
} else if (timelineType == 0x2) {
boneMap.scale = timeline;
} else {
boneMap.shear = timeline;
}
duration = Math.max(duration, timeline[frameCount - 0x1].time);
break;
}
}
bones[this.json.bones[boneIndex].name] = boneMap;
}
animation.bones = bones;
let ik = {};
for (let i = 0x0, nn = this.readInt(!![]); i < nn; i++) {
const ikIndex = this.readInt(!![]);
const frameCount = this.readInt(!![]);
const timeline = new Array(frameCount);
for (let frameIndex = 0x0; frameIndex < frameCount; frameIndex++) {
const time = this.readFloat();
const mix = this.readFloat();
const bendPositive = this.readByte() != 0xff;
timeline[frameIndex] = {};
timeline[frameIndex].time = time;
timeline[frameIndex].mix = mix;
timeline[frameIndex].bendPositive = bendPositive;
if (frameIndex < frameCount - 0x1) {
this.readCurve(frameIndex, timeline);
}
}
ik[this.json['ik'][ikIndex].name] = timeline;
duration = Math.max(duration, timeline[frameCount - 0x1].time);
}
animation['ik'] = ik;
let ffd = {};
for (let i = 0x0, nn = this.readInt(!![]); i < nn; i++) {
const slotIndex = this.readInt(!![]);
const frameCount = this.readInt(!![]);
const timeline = new Array(frameCount);
for (let frameIndex = 0x0; frameIndex < frameCount; frameIndex++) {
timeline[frameIndex] = {};
timeline[frameIndex].time = this.readFloat();
timeline[frameIndex].rotateMix = this.readFloat();
timeline[frameIndex].translateMix = this.readFloat();
timeline[frameIndex].scaleMix = this.readFloat();
timeline[frameIndex].shearMix = this.readFloat();
if (frameIndex < frameCount - 0x1) {
this.readCurve(frameIndex, timeline);
}
}
ffd[this.json.transform[slotIndex].name] = timeline;
duration = Math.max(duration, timeline[frameCount - 0x1].time);
}
animation.transform = ffd;
let path = {};
for (let i = 0x0, n = this.readInt(!![]); i < n; i++) {
let pathOrder = this.readInt(!![]);
let pathData = this.json.path[pathOrder];
let data = {};
for (let ii = 0x0, nn = this.readInt(!![]); ii < nn; ii++) {
const timelineType = this.readByte();
const frameCount = this.readInt(!![]);
let timeline, time, timelineScale;
switch (timelineType) {
case 0x0:
case 0x1:
timeline = new Array(frameCount);
timelineScale = 0x1;
if (timelineType == 0x1) {
if (pathData.spacingMode == 'length' || pathData.spacingMode == 'fixed') {
timelineScale = this.scale;
}
} else {
if (pathData.positionMode == 'fixed') {
timelineScale = this.scale;
}
}
for (let frameIndex = 0x0; frameIndex < frameCount; frameIndex++) {
time = this.readFloat();
let _0xebc795 = this.readFloat();
timeline[frameIndex] = {};
timeline[frameIndex].time = time;
if (timelineType == 0x0) {
timeline[frameIndex].position = _0xebc795 * timelineScale;
} else {
timeline[frameIndex].spacing = _0xebc795 * timelineScale;
}
if (frameIndex < frameCount - 0x1)
this.readCurve(frameIndex, timeline);
}
if (timelineType == 0x0) {
data.position = timeline;
} else {
data.spacing = timeline;
}
duration = Math.max(duration, timeline[frameCount - 0x1].time);
break;
case 0x2:
timeline = new Array(frameCount);
for (let frameIndex = 0x0; frameIndex < frameCount; frameIndex++) {
time = this.readFloat();
let _0x47f0f0 = this.readFloat();
let _0x1bb1d7 = this.readFloat();
timeline[frameIndex] = {};
timeline[frameIndex].time = time;
timeline[frameIndex].rotateMix = _0x47f0f0;
timeline[frameIndex].translateMix = _0x1bb1d7;
if (frameIndex < frameCount - 0x1)
this.readCurve(frameIndex, timeline);
}
data.mix = timeline;
duration = Math.max(duration, timeline[frameCount - 0x1].time);
break;
}
}
path[this.json.path[pathOrder].name] = data;
}
animation.paths = path;
// 变量名可能不对
let deform = {};
for (let i = 0x0, n = this.readInt(!![]); i < n; i++) {
let index = this.readInt(!![]);
let skinName = this.json.skinsName[index];
let deformData = {};
for (let ii = 0x0, nn = this.readInt(!![]); ii < nn; ii++) {
const slotIndex = this.readInt(!![]);
const slot = this.json.slots[slotIndex];
const attachment = {};
for (let iii = 0x0, nnn = this.readInt(!![]); iii < nnn; iii++) {
const name = this.readString();
const frameCount = this.readInt(!![]);
const timeline = new Array(frameCount);
for (let frameIndex = 0x0; frameIndex < frameCount; frameIndex++) {
const time = this.readFloat();
const end = this.readInt(!![]);
timeline[frameIndex] = {};
timeline[frameIndex].time = time;
if (end != 0x0) {
let vertices = new Array(end);
let start = this.readInt(!![]);
if (this.scale == 0x1) {
for (let i = 0x0; i < end; i++) {
vertices[i] = this.readFloat();
}
} else {
for (let i = 0x0; i < end; i++) {
vertices[i] = this.readFloat() * this.scale;
}
}
timeline[frameIndex].offset = start;
timeline[frameIndex].vertices = vertices;
}
if (frameIndex < frameCount - 0x1)
this.readCurve(frameIndex, timeline);
}
attachment[name] = timeline;
duration = Math.max(duration, timeline[frameCount - 0x1].time);
}
deformData[slot.name] = attachment;
}
deform[skinName] = deformData;
}
animation.deform = deform;
let drawOrderCount = this.readInt(!![]);
if (drawOrderCount > 0x0) {
let drawOrders = new Array(drawOrderCount);
for (let i = 0x0; i < drawOrderCount; i++) {
const drawOrderMap = {};
const time = this.readFloat();
const offsetCount = this.readInt(!![]);
const offsets = new Array(offsetCount);
for (let ii = 0x0; ii < offsetCount; ii++) {
const offsetMap = {};
const slotIndex = this.readInt(!![]);
offsetMap.slot = this.json.slots[slotIndex].name;
let dooffset = this.readInt(!![]);
offsetMap.offset = dooffset;
offsets[ii] = offsetMap;
}
drawOrderMap.offsets = offsets;
drawOrderMap.time = time;
drawOrders[i] = drawOrderMap;
}
duration = Math.max(duration, drawOrders[drawOrderCount - 0x1].time);
animation.drawOrder = drawOrders;
}
let eventCount = this.readInt(!![]);
if (eventCount > 0x0) {
let events = new Array(eventCount);
for (let i = 0x0; i < eventCount; i++) {
const time = this.readFloat();
const name = this.json.eventsName[this.readInt(!![])];
const eventData = this.json.events[name];
const e = {};
e.name = name;
e.int = this.readInt(![]);
e.float = this.readFloat();
e.string = this.readBoolean() ? this.readString() : eventData.string;
e.time = time;
events[i] = e;
}
duration = Math.max(duration, events[eventCount - 0x1].time);
animation.events = events;
}
return animation;
}
};
const skel2Json = binary => {
const skel_bin = new SkeletonBinary();
skel_bin.data = new Uint8Array(binary);
skel_bin.initJson();
return skel_bin.json;
};
export {
skel2Json
}