@safe-engine/pixi 8.8.1 → 8.8.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/app.d.ts +1 -0
- package/dist/app.d.ts.map +1 -1
- package/dist/app.js +20 -1
- package/dist/core/NodePool.d.ts +1 -1
- package/dist/core/Size.d.ts +0 -1
- package/dist/core/Size.d.ts.map +1 -1
- package/dist/dragonbones/DragonBonesComponent.d.ts +1 -1
- package/dist/dragonbones/DragonBonesComponent.d.ts.map +1 -1
- package/dist/dragonbones/DragonBonesComponent.js +1 -1
- package/dist/dragonbones/DragonBonesSystem.d.ts.map +1 -1
- package/dist/dragonbones/DragonBonesSystem.js +1 -1
- package/dist/dragonbones/db-pixi/PixiArmatureDisplay.d.ts +59 -0
- package/dist/dragonbones/db-pixi/PixiArmatureDisplay.d.ts.map +1 -0
- package/dist/dragonbones/db-pixi/PixiArmatureDisplay.js +180 -0
- package/dist/dragonbones/db-pixi/PixiFactory.d.ts +87 -0
- package/dist/dragonbones/db-pixi/PixiFactory.d.ts.map +1 -0
- package/dist/dragonbones/db-pixi/PixiFactory.js +159 -0
- package/dist/dragonbones/db-pixi/PixiSlot.d.ts +31 -0
- package/dist/dragonbones/db-pixi/PixiSlot.d.ts.map +1 -0
- package/dist/dragonbones/db-pixi/PixiSlot.js +332 -0
- package/dist/dragonbones/db-pixi/PixiTextureAtlasData.d.ts +38 -0
- package/dist/dragonbones/db-pixi/PixiTextureAtlasData.d.ts.map +1 -0
- package/dist/dragonbones/db-pixi/PixiTextureAtlasData.js +85 -0
- package/dist/dragonbones/db-pixi/index.d.ts +5 -0
- package/dist/dragonbones/db-pixi/index.d.ts.map +1 -0
- package/dist/dragonbones/db-pixi/index.js +4 -0
- package/dist/dragonbones/dragonBones/animation/Animation.d.ts +241 -0
- package/dist/dragonbones/dragonBones/animation/Animation.d.ts.map +1 -0
- package/dist/dragonbones/dragonBones/animation/Animation.js +692 -0
- package/dist/dragonbones/dragonBones/animation/AnimationState.d.ts +323 -0
- package/dist/dragonbones/dragonBones/animation/AnimationState.d.ts.map +1 -0
- package/dist/dragonbones/dragonBones/animation/AnimationState.js +1161 -0
- package/dist/dragonbones/dragonBones/animation/BaseTimelineState.d.ts +100 -0
- package/dist/dragonbones/dragonBones/animation/BaseTimelineState.d.ts.map +1 -0
- package/dist/dragonbones/dragonBones/animation/BaseTimelineState.js +479 -0
- package/dist/dragonbones/dragonBones/animation/IAnimatable.d.ts +38 -0
- package/dist/dragonbones/dragonBones/animation/IAnimatable.d.ts.map +1 -0
- package/dist/dragonbones/dragonBones/animation/IAnimatable.js +9 -0
- package/dist/dragonbones/dragonBones/animation/TimelineState.d.ts +159 -0
- package/dist/dragonbones/dragonBones/animation/TimelineState.d.ts.map +1 -0
- package/dist/dragonbones/dragonBones/animation/TimelineState.js +998 -0
- package/dist/dragonbones/dragonBones/animation/WorldClock.d.ts +74 -0
- package/dist/dragonbones/dragonBones/animation/WorldClock.d.ts.map +1 -0
- package/dist/dragonbones/dragonBones/animation/WorldClock.js +162 -0
- package/dist/dragonbones/dragonBones/armature/Armature.d.ts +314 -0
- package/dist/dragonbones/dragonBones/armature/Armature.d.ts.map +1 -0
- package/dist/dragonbones/dragonBones/armature/Armature.js +650 -0
- package/dist/dragonbones/dragonBones/armature/Bone.d.ts +123 -0
- package/dist/dragonbones/dragonBones/armature/Bone.d.ts.map +1 -0
- package/dist/dragonbones/dragonBones/armature/Bone.js +438 -0
- package/dist/dragonbones/dragonBones/armature/Constraint.d.ts +99 -0
- package/dist/dragonbones/dragonBones/armature/Constraint.d.ts.map +1 -0
- package/dist/dragonbones/dragonBones/armature/Constraint.js +672 -0
- package/dist/dragonbones/dragonBones/armature/IArmatureProxy.d.ts +47 -0
- package/dist/dragonbones/dragonBones/armature/IArmatureProxy.d.ts.map +1 -0
- package/dist/dragonbones/dragonBones/armature/IArmatureProxy.js +1 -0
- package/dist/dragonbones/dragonBones/armature/Slot.d.ts +357 -0
- package/dist/dragonbones/dragonBones/armature/Slot.d.ts.map +1 -0
- package/dist/dragonbones/dragonBones/armature/Slot.js +1009 -0
- package/dist/dragonbones/dragonBones/armature/Surface.d.ts +41 -0
- package/dist/dragonbones/dragonBones/armature/Surface.d.ts.map +1 -0
- package/dist/dragonbones/dragonBones/armature/Surface.js +463 -0
- package/dist/dragonbones/dragonBones/armature/TransformObject.d.ts +80 -0
- package/dist/dragonbones/dragonBones/armature/TransformObject.d.ts.map +1 -0
- package/dist/dragonbones/dragonBones/armature/TransformObject.js +77 -0
- package/dist/dragonbones/dragonBones/core/BaseObject.d.ts +53 -0
- package/dist/dragonbones/dragonBones/core/BaseObject.d.ts.map +1 -0
- package/dist/dragonbones/dragonBones/core/BaseObject.js +130 -0
- package/dist/dragonbones/dragonBones/core/DragonBones.d.ts +236 -0
- package/dist/dragonbones/dragonBones/core/DragonBones.d.ts.map +1 -0
- package/dist/dragonbones/dragonBones/core/DragonBones.js +61 -0
- package/dist/dragonbones/dragonBones/event/EventObject.d.ts +143 -0
- package/dist/dragonbones/dragonBones/event/EventObject.d.ts.map +1 -0
- package/dist/dragonbones/dragonBones/event/EventObject.js +99 -0
- package/dist/dragonbones/dragonBones/event/IEventDispatcher.d.ts +48 -0
- package/dist/dragonbones/dragonBones/event/IEventDispatcher.d.ts.map +1 -0
- package/dist/dragonbones/dragonBones/event/IEventDispatcher.js +1 -0
- package/dist/dragonbones/dragonBones/factory/BaseFactory.d.ts +292 -0
- package/dist/dragonbones/dragonBones/factory/BaseFactory.d.ts.map +1 -0
- package/dist/dragonbones/dragonBones/factory/BaseFactory.js +735 -0
- package/dist/dragonbones/dragonBones/geom/ColorTransform.d.ts +17 -0
- package/dist/dragonbones/dragonBones/geom/ColorTransform.d.ts.map +1 -0
- package/dist/dragonbones/dragonBones/geom/ColorTransform.js +33 -0
- package/dist/dragonbones/dragonBones/geom/Curve.d.ts +10 -0
- package/dist/dragonbones/dragonBones/geom/Curve.d.ts.map +1 -0
- package/dist/dragonbones/dragonBones/geom/Curve.js +26 -0
- package/dist/dragonbones/dragonBones/geom/Matrix.d.ts +105 -0
- package/dist/dragonbones/dragonBones/geom/Matrix.d.ts.map +1 -0
- package/dist/dragonbones/dragonBones/geom/Matrix.js +207 -0
- package/dist/dragonbones/dragonBones/geom/Point.d.ts +38 -0
- package/dist/dragonbones/dragonBones/geom/Point.d.ts.map +1 -0
- package/dist/dragonbones/dragonBones/geom/Point.js +31 -0
- package/dist/dragonbones/dragonBones/geom/Rectangle.d.ts +53 -0
- package/dist/dragonbones/dragonBones/geom/Rectangle.d.ts.map +1 -0
- package/dist/dragonbones/dragonBones/geom/Rectangle.js +37 -0
- package/dist/dragonbones/dragonBones/geom/Transform.d.ts +102 -0
- package/dist/dragonbones/dragonBones/geom/Transform.d.ts.map +1 -0
- package/dist/dragonbones/dragonBones/geom/Transform.js +170 -0
- package/dist/dragonbones/dragonBones/index.d.ts +37 -0
- package/dist/dragonbones/dragonBones/index.d.ts.map +1 -0
- package/dist/dragonbones/dragonBones/index.js +36 -0
- package/dist/dragonbones/dragonBones/model/AnimationConfig.d.ts +162 -0
- package/dist/dragonbones/dragonBones/model/AnimationConfig.d.ts.map +1 -0
- package/dist/dragonbones/dragonBones/model/AnimationConfig.js +81 -0
- package/dist/dragonbones/dragonBones/model/AnimationData.d.ts +174 -0
- package/dist/dragonbones/dragonBones/model/AnimationData.d.ts.map +1 -0
- package/dist/dragonbones/dragonBones/model/AnimationData.js +256 -0
- package/dist/dragonbones/dragonBones/model/ArmatureData.d.ts +319 -0
- package/dist/dragonbones/dragonBones/model/ArmatureData.d.ts.map +1 -0
- package/dist/dragonbones/dragonBones/model/ArmatureData.js +450 -0
- package/dist/dragonbones/dragonBones/model/BoundingBoxData.d.ts +188 -0
- package/dist/dragonbones/dragonBones/model/BoundingBoxData.d.ts.map +1 -0
- package/dist/dragonbones/dragonBones/model/BoundingBoxData.js +500 -0
- package/dist/dragonbones/dragonBones/model/CanvasData.d.ts +15 -0
- package/dist/dragonbones/dragonBones/model/CanvasData.d.ts.map +1 -0
- package/dist/dragonbones/dragonBones/model/CanvasData.js +17 -0
- package/dist/dragonbones/dragonBones/model/ConstraintData.d.ts +46 -0
- package/dist/dragonbones/dragonBones/model/ConstraintData.d.ts.map +1 -0
- package/dist/dragonbones/dragonBones/model/ConstraintData.js +57 -0
- package/dist/dragonbones/dragonBones/model/DisplayData.d.ts +98 -0
- package/dist/dragonbones/dragonBones/model/DisplayData.d.ts.map +1 -0
- package/dist/dragonbones/dragonBones/model/DisplayData.js +174 -0
- package/dist/dragonbones/dragonBones/model/DragonBonesData.d.ts +108 -0
- package/dist/dragonbones/dragonBones/model/DragonBonesData.d.ts.map +1 -0
- package/dist/dragonbones/dragonBones/model/DragonBonesData.js +86 -0
- package/dist/dragonbones/dragonBones/model/SkinData.d.ts +40 -0
- package/dist/dragonbones/dragonBones/model/SkinData.d.ts.map +1 -0
- package/dist/dragonbones/dragonBones/model/SkinData.js +68 -0
- package/dist/dragonbones/dragonBones/model/TextureAtlasData.d.ts +73 -0
- package/dist/dragonbones/dragonBones/model/TextureAtlasData.d.ts.map +1 -0
- package/dist/dragonbones/dragonBones/model/TextureAtlasData.js +102 -0
- package/dist/dragonbones/dragonBones/model/UserData.d.ts +73 -0
- package/dist/dragonbones/dragonBones/model/UserData.d.ts.map +1 -0
- package/dist/dragonbones/dragonBones/model/UserData.js +101 -0
- package/dist/dragonbones/dragonBones/parser/BinaryDataParser.d.ts +29 -0
- package/dist/dragonbones/dragonBones/parser/BinaryDataParser.d.ts.map +1 -0
- package/dist/dragonbones/dragonBones/parser/BinaryDataParser.js +356 -0
- package/dist/dragonbones/dragonBones/parser/DataParser.d.ts +153 -0
- package/dist/dragonbones/dragonBones/parser/DataParser.d.ts.map +1 -0
- package/dist/dragonbones/dragonBones/parser/DataParser.js +283 -0
- package/dist/dragonbones/dragonBones/parser/ObjectDataParser.d.ts +130 -0
- package/dist/dragonbones/dragonBones/parser/ObjectDataParser.d.ts.map +1 -0
- package/dist/dragonbones/dragonBones/parser/ObjectDataParser.js +2098 -0
- package/dist/dragonbones/index.js +1 -1
- package/dist/helper/utils.js +1 -1
- package/package.json +3 -4
|
@@ -0,0 +1,2098 @@
|
|
|
1
|
+
import { BaseObject } from "../core/BaseObject";
|
|
2
|
+
import { ColorTransform } from "../geom/ColorTransform";
|
|
3
|
+
import { AnimationData, TimelineData, AnimationTimelineData } from "../model/AnimationData";
|
|
4
|
+
import { BoneData, ArmatureData, SlotData, SurfaceData } from "../model/ArmatureData";
|
|
5
|
+
import { RectangleBoundingBoxData, EllipseBoundingBoxData, PolygonBoundingBoxData } from "../model/BoundingBoxData";
|
|
6
|
+
import { CanvasData } from "../model/CanvasData";
|
|
7
|
+
import { IKConstraintData, PathConstraintData } from "../model/ConstraintData";
|
|
8
|
+
import { MeshDisplayData, PathDisplayData, ImageDisplayData, ArmatureDisplayData, BoundingBoxDisplayData, WeightData } from "../model/DisplayData";
|
|
9
|
+
import { DragonBonesData } from "../model/DragonBonesData";
|
|
10
|
+
import { SkinData } from "../model/SkinData";
|
|
11
|
+
import { TextureData } from "../model/TextureAtlasData";
|
|
12
|
+
import { ActionData, UserData } from "../model/UserData";
|
|
13
|
+
import { DataParser } from "./DataParser";
|
|
14
|
+
import { Matrix } from "../geom/Matrix";
|
|
15
|
+
import { Transform } from "../geom/Transform";
|
|
16
|
+
import { Point } from "../geom/Point";
|
|
17
|
+
/**
|
|
18
|
+
* @private
|
|
19
|
+
*/
|
|
20
|
+
export class ObjectDataParser extends DataParser {
|
|
21
|
+
constructor() {
|
|
22
|
+
super(...arguments);
|
|
23
|
+
this._rawTextureAtlasIndex = 0;
|
|
24
|
+
this._rawBones = [];
|
|
25
|
+
this._data = null; //
|
|
26
|
+
this._armature = null; //
|
|
27
|
+
this._bone = null; //
|
|
28
|
+
this._geometry = null; //
|
|
29
|
+
this._slot = null; //
|
|
30
|
+
this._skin = null; //
|
|
31
|
+
this._mesh = null; //
|
|
32
|
+
this._animation = null; //
|
|
33
|
+
this._timeline = null; //
|
|
34
|
+
this._rawTextureAtlases = null;
|
|
35
|
+
this._frameValueType = 0 /* FrameValueType.Step */;
|
|
36
|
+
this._defaultColorOffset = -1;
|
|
37
|
+
this._prevClockwise = 0;
|
|
38
|
+
this._prevRotation = 0.0;
|
|
39
|
+
this._frameDefaultValue = 0.0;
|
|
40
|
+
this._frameValueScale = 1.0;
|
|
41
|
+
this._helpMatrixA = new Matrix();
|
|
42
|
+
this._helpMatrixB = new Matrix();
|
|
43
|
+
this._helpTransform = new Transform();
|
|
44
|
+
this._helpColorTransform = new ColorTransform();
|
|
45
|
+
this._helpPoint = new Point();
|
|
46
|
+
this._helpArray = [];
|
|
47
|
+
this._intArray = [];
|
|
48
|
+
this._floatArray = [];
|
|
49
|
+
this._frameIntArray = [];
|
|
50
|
+
this._frameFloatArray = [];
|
|
51
|
+
this._frameArray = [];
|
|
52
|
+
this._timelineArray = [];
|
|
53
|
+
this._colorArray = [];
|
|
54
|
+
this._cacheRawMeshes = [];
|
|
55
|
+
this._cacheMeshes = [];
|
|
56
|
+
this._actionFrames = [];
|
|
57
|
+
this._weightSlotPose = {};
|
|
58
|
+
this._weightBonePoses = {};
|
|
59
|
+
this._cacheBones = {};
|
|
60
|
+
this._slotChildActions = {};
|
|
61
|
+
}
|
|
62
|
+
static _getBoolean(rawData, key, defaultValue) {
|
|
63
|
+
if (key in rawData) {
|
|
64
|
+
const value = rawData[key];
|
|
65
|
+
const type = typeof value;
|
|
66
|
+
if (type === "boolean") {
|
|
67
|
+
return value;
|
|
68
|
+
}
|
|
69
|
+
else if (type === "string") {
|
|
70
|
+
switch (value) {
|
|
71
|
+
case "0":
|
|
72
|
+
case "NaN":
|
|
73
|
+
case "":
|
|
74
|
+
case "false":
|
|
75
|
+
case "null":
|
|
76
|
+
case "undefined":
|
|
77
|
+
return false;
|
|
78
|
+
default:
|
|
79
|
+
return true;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
else {
|
|
83
|
+
return !!value;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
return defaultValue;
|
|
87
|
+
}
|
|
88
|
+
static _getNumber(rawData, key, defaultValue) {
|
|
89
|
+
if (key in rawData) {
|
|
90
|
+
const value = rawData[key];
|
|
91
|
+
if (value === null || value === "NaN") {
|
|
92
|
+
return defaultValue;
|
|
93
|
+
}
|
|
94
|
+
return +value || 0;
|
|
95
|
+
}
|
|
96
|
+
return defaultValue;
|
|
97
|
+
}
|
|
98
|
+
static _getString(rawData, key, defaultValue) {
|
|
99
|
+
if (key in rawData) {
|
|
100
|
+
const value = rawData[key];
|
|
101
|
+
const type = typeof value;
|
|
102
|
+
if (type === "string") {
|
|
103
|
+
return value;
|
|
104
|
+
}
|
|
105
|
+
return String(value);
|
|
106
|
+
}
|
|
107
|
+
return defaultValue;
|
|
108
|
+
}
|
|
109
|
+
_getCurvePoint(x1, y1, x2, y2, x3, y3, x4, y4, t, result) {
|
|
110
|
+
const l_t = 1.0 - t;
|
|
111
|
+
const powA = l_t * l_t;
|
|
112
|
+
const powB = t * t;
|
|
113
|
+
const kA = l_t * powA;
|
|
114
|
+
const kB = 3.0 * t * powA;
|
|
115
|
+
const kC = 3.0 * l_t * powB;
|
|
116
|
+
const kD = t * powB;
|
|
117
|
+
result.x = kA * x1 + kB * x2 + kC * x3 + kD * x4;
|
|
118
|
+
result.y = kA * y1 + kB * y2 + kC * y3 + kD * y4;
|
|
119
|
+
}
|
|
120
|
+
_samplingEasingCurve(curve, samples) {
|
|
121
|
+
const curveCount = curve.length;
|
|
122
|
+
if (curveCount % 3 === 1) {
|
|
123
|
+
let stepIndex = -2;
|
|
124
|
+
for (let i = 0, l = samples.length; i < l; ++i) {
|
|
125
|
+
let t = (i + 1) / (l + 1); // float
|
|
126
|
+
while ((stepIndex + 6 < curveCount ? curve[stepIndex + 6] : 1) < t) {
|
|
127
|
+
// stepIndex + 3 * 2
|
|
128
|
+
stepIndex += 6;
|
|
129
|
+
}
|
|
130
|
+
const isInCurve = stepIndex >= 0 && stepIndex + 6 < curveCount;
|
|
131
|
+
const x1 = isInCurve ? curve[stepIndex] : 0.0;
|
|
132
|
+
const y1 = isInCurve ? curve[stepIndex + 1] : 0.0;
|
|
133
|
+
const x2 = curve[stepIndex + 2];
|
|
134
|
+
const y2 = curve[stepIndex + 3];
|
|
135
|
+
const x3 = curve[stepIndex + 4];
|
|
136
|
+
const y3 = curve[stepIndex + 5];
|
|
137
|
+
const x4 = isInCurve ? curve[stepIndex + 6] : 1.0;
|
|
138
|
+
const y4 = isInCurve ? curve[stepIndex + 7] : 1.0;
|
|
139
|
+
let lower = 0.0;
|
|
140
|
+
let higher = 1.0;
|
|
141
|
+
while (higher - lower > 0.0001) {
|
|
142
|
+
const percentage = (higher + lower) * 0.5;
|
|
143
|
+
this._getCurvePoint(x1, y1, x2, y2, x3, y3, x4, y4, percentage, this._helpPoint);
|
|
144
|
+
if (t - this._helpPoint.x > 0.0) {
|
|
145
|
+
lower = percentage;
|
|
146
|
+
}
|
|
147
|
+
else {
|
|
148
|
+
higher = percentage;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
samples[i] = this._helpPoint.y;
|
|
152
|
+
}
|
|
153
|
+
return true;
|
|
154
|
+
}
|
|
155
|
+
else {
|
|
156
|
+
let stepIndex = 0;
|
|
157
|
+
for (let i = 0, l = samples.length; i < l; ++i) {
|
|
158
|
+
let t = (i + 1) / (l + 1); // float
|
|
159
|
+
while (curve[stepIndex + 6] < t) {
|
|
160
|
+
// stepIndex + 3 * 2
|
|
161
|
+
stepIndex += 6;
|
|
162
|
+
}
|
|
163
|
+
const x1 = curve[stepIndex];
|
|
164
|
+
const y1 = curve[stepIndex + 1];
|
|
165
|
+
const x2 = curve[stepIndex + 2];
|
|
166
|
+
const y2 = curve[stepIndex + 3];
|
|
167
|
+
const x3 = curve[stepIndex + 4];
|
|
168
|
+
const y3 = curve[stepIndex + 5];
|
|
169
|
+
const x4 = curve[stepIndex + 6];
|
|
170
|
+
const y4 = curve[stepIndex + 7];
|
|
171
|
+
let lower = 0.0;
|
|
172
|
+
let higher = 1.0;
|
|
173
|
+
while (higher - lower > 0.0001) {
|
|
174
|
+
const percentage = (higher + lower) * 0.5;
|
|
175
|
+
this._getCurvePoint(x1, y1, x2, y2, x3, y3, x4, y4, percentage, this._helpPoint);
|
|
176
|
+
if (t - this._helpPoint.x > 0.0) {
|
|
177
|
+
lower = percentage;
|
|
178
|
+
}
|
|
179
|
+
else {
|
|
180
|
+
higher = percentage;
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
samples[i] = this._helpPoint.y;
|
|
184
|
+
}
|
|
185
|
+
return false;
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
_parseActionDataInFrame(rawData, frameStart, bone, slot) {
|
|
189
|
+
if (DataParser.EVENT in rawData) {
|
|
190
|
+
this._mergeActionFrame(rawData[DataParser.EVENT], frameStart, 10 /* ActionType.Frame */, bone, slot);
|
|
191
|
+
}
|
|
192
|
+
if (DataParser.SOUND in rawData) {
|
|
193
|
+
this._mergeActionFrame(rawData[DataParser.SOUND], frameStart, 11 /* ActionType.Sound */, bone, slot);
|
|
194
|
+
}
|
|
195
|
+
if (DataParser.ACTION in rawData) {
|
|
196
|
+
this._mergeActionFrame(rawData[DataParser.ACTION], frameStart, 0 /* ActionType.Play */, bone, slot);
|
|
197
|
+
}
|
|
198
|
+
if (DataParser.EVENTS in rawData) {
|
|
199
|
+
this._mergeActionFrame(rawData[DataParser.EVENTS], frameStart, 10 /* ActionType.Frame */, bone, slot);
|
|
200
|
+
}
|
|
201
|
+
if (DataParser.ACTIONS in rawData) {
|
|
202
|
+
this._mergeActionFrame(rawData[DataParser.ACTIONS], frameStart, 0 /* ActionType.Play */, bone, slot);
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
_mergeActionFrame(rawData, frameStart, type, bone, slot) {
|
|
206
|
+
const actionOffset = this._armature.actions.length;
|
|
207
|
+
const actions = this._parseActionData(rawData, type, bone, slot);
|
|
208
|
+
let frameIndex = 0;
|
|
209
|
+
let frame = null;
|
|
210
|
+
for (const action of actions) {
|
|
211
|
+
this._armature.addAction(action, false);
|
|
212
|
+
}
|
|
213
|
+
if (this._actionFrames.length === 0) {
|
|
214
|
+
// First frame.
|
|
215
|
+
frame = new ActionFrame();
|
|
216
|
+
frame.frameStart = 0;
|
|
217
|
+
this._actionFrames.push(frame);
|
|
218
|
+
frame = null;
|
|
219
|
+
}
|
|
220
|
+
for (const eachFrame of this._actionFrames) {
|
|
221
|
+
// Get same frame.
|
|
222
|
+
if (eachFrame.frameStart === frameStart) {
|
|
223
|
+
frame = eachFrame;
|
|
224
|
+
break;
|
|
225
|
+
}
|
|
226
|
+
else if (eachFrame.frameStart > frameStart) {
|
|
227
|
+
break;
|
|
228
|
+
}
|
|
229
|
+
frameIndex++;
|
|
230
|
+
}
|
|
231
|
+
if (frame === null) {
|
|
232
|
+
// Create and cache frame.
|
|
233
|
+
frame = new ActionFrame();
|
|
234
|
+
frame.frameStart = frameStart;
|
|
235
|
+
this._actionFrames.splice(frameIndex, 0, frame);
|
|
236
|
+
}
|
|
237
|
+
for (let i = 0; i < actions.length; ++i) {
|
|
238
|
+
// Cache action offsets.
|
|
239
|
+
frame.actions.push(actionOffset + i);
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
_parseArmature(rawData, scale) {
|
|
243
|
+
const armature = BaseObject.borrowObject(ArmatureData);
|
|
244
|
+
armature.name = ObjectDataParser._getString(rawData, DataParser.NAME, "");
|
|
245
|
+
armature.frameRate = ObjectDataParser._getNumber(rawData, DataParser.FRAME_RATE, this._data.frameRate);
|
|
246
|
+
armature.scale = scale;
|
|
247
|
+
if (DataParser.TYPE in rawData &&
|
|
248
|
+
typeof rawData[DataParser.TYPE] === "string") {
|
|
249
|
+
armature.type = DataParser._getArmatureType(rawData[DataParser.TYPE]);
|
|
250
|
+
}
|
|
251
|
+
else {
|
|
252
|
+
armature.type = ObjectDataParser._getNumber(rawData, DataParser.TYPE, 0 /* ArmatureType.Armature */);
|
|
253
|
+
}
|
|
254
|
+
if (armature.frameRate === 0) {
|
|
255
|
+
// Data error.
|
|
256
|
+
armature.frameRate = 24;
|
|
257
|
+
}
|
|
258
|
+
this._armature = armature;
|
|
259
|
+
if (DataParser.CANVAS in rawData) {
|
|
260
|
+
const rawCanvas = rawData[DataParser.CANVAS];
|
|
261
|
+
const canvas = BaseObject.borrowObject(CanvasData);
|
|
262
|
+
if (DataParser.COLOR in rawCanvas) {
|
|
263
|
+
canvas.hasBackground = true;
|
|
264
|
+
}
|
|
265
|
+
else {
|
|
266
|
+
canvas.hasBackground = false;
|
|
267
|
+
}
|
|
268
|
+
canvas.color = ObjectDataParser._getNumber(rawCanvas, DataParser.COLOR, 0);
|
|
269
|
+
canvas.x =
|
|
270
|
+
ObjectDataParser._getNumber(rawCanvas, DataParser.X, 0) *
|
|
271
|
+
armature.scale;
|
|
272
|
+
canvas.y =
|
|
273
|
+
ObjectDataParser._getNumber(rawCanvas, DataParser.Y, 0) *
|
|
274
|
+
armature.scale;
|
|
275
|
+
canvas.width =
|
|
276
|
+
ObjectDataParser._getNumber(rawCanvas, DataParser.WIDTH, 0) *
|
|
277
|
+
armature.scale;
|
|
278
|
+
canvas.height =
|
|
279
|
+
ObjectDataParser._getNumber(rawCanvas, DataParser.HEIGHT, 0) *
|
|
280
|
+
armature.scale;
|
|
281
|
+
armature.canvas = canvas;
|
|
282
|
+
}
|
|
283
|
+
if (DataParser.AABB in rawData) {
|
|
284
|
+
const rawAABB = rawData[DataParser.AABB];
|
|
285
|
+
armature.aabb.x =
|
|
286
|
+
ObjectDataParser._getNumber(rawAABB, DataParser.X, 0.0) *
|
|
287
|
+
armature.scale;
|
|
288
|
+
armature.aabb.y =
|
|
289
|
+
ObjectDataParser._getNumber(rawAABB, DataParser.Y, 0.0) *
|
|
290
|
+
armature.scale;
|
|
291
|
+
armature.aabb.width =
|
|
292
|
+
ObjectDataParser._getNumber(rawAABB, DataParser.WIDTH, 0.0) *
|
|
293
|
+
armature.scale;
|
|
294
|
+
armature.aabb.height =
|
|
295
|
+
ObjectDataParser._getNumber(rawAABB, DataParser.HEIGHT, 0.0) *
|
|
296
|
+
armature.scale;
|
|
297
|
+
}
|
|
298
|
+
if (DataParser.BONE in rawData) {
|
|
299
|
+
const rawBones = rawData[DataParser.BONE];
|
|
300
|
+
for (const rawBone of rawBones) {
|
|
301
|
+
const parentName = ObjectDataParser._getString(rawBone, DataParser.PARENT, "");
|
|
302
|
+
const bone = this._parseBone(rawBone);
|
|
303
|
+
if (parentName.length > 0) {
|
|
304
|
+
// Get bone parent.
|
|
305
|
+
const parent = armature.getBone(parentName);
|
|
306
|
+
if (parent !== null) {
|
|
307
|
+
bone.parent = parent;
|
|
308
|
+
}
|
|
309
|
+
else {
|
|
310
|
+
// Cache.
|
|
311
|
+
if (!(parentName in this._cacheBones)) {
|
|
312
|
+
this._cacheBones[parentName] = [];
|
|
313
|
+
}
|
|
314
|
+
this._cacheBones[parentName].push(bone);
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
if (bone.name in this._cacheBones) {
|
|
318
|
+
for (const child of this._cacheBones[bone.name]) {
|
|
319
|
+
child.parent = bone;
|
|
320
|
+
}
|
|
321
|
+
delete this._cacheBones[bone.name];
|
|
322
|
+
}
|
|
323
|
+
armature.addBone(bone);
|
|
324
|
+
this._rawBones.push(bone); // Cache raw bones sort.
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
if (DataParser.IK in rawData) {
|
|
328
|
+
const rawIKS = rawData[DataParser.IK];
|
|
329
|
+
for (const rawIK of rawIKS) {
|
|
330
|
+
const constraint = this._parseIKConstraint(rawIK);
|
|
331
|
+
if (constraint) {
|
|
332
|
+
armature.addConstraint(constraint);
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
armature.sortBones();
|
|
337
|
+
if (DataParser.SLOT in rawData) {
|
|
338
|
+
let zOrder = 0;
|
|
339
|
+
const rawSlots = rawData[DataParser.SLOT];
|
|
340
|
+
for (const rawSlot of rawSlots) {
|
|
341
|
+
armature.addSlot(this._parseSlot(rawSlot, zOrder++));
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
if (DataParser.SKIN in rawData) {
|
|
345
|
+
const rawSkins = rawData[DataParser.SKIN];
|
|
346
|
+
for (const rawSkin of rawSkins) {
|
|
347
|
+
armature.addSkin(this._parseSkin(rawSkin));
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
if (DataParser.PATH_CONSTRAINT in rawData) {
|
|
351
|
+
const rawPaths = rawData[DataParser.PATH_CONSTRAINT];
|
|
352
|
+
for (const rawPath of rawPaths) {
|
|
353
|
+
const constraint = this._parsePathConstraint(rawPath);
|
|
354
|
+
if (constraint) {
|
|
355
|
+
armature.addConstraint(constraint);
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
for (let i = 0, l = this._cacheRawMeshes.length; i < l; ++i) {
|
|
360
|
+
// Link mesh.
|
|
361
|
+
const rawData = this._cacheRawMeshes[i];
|
|
362
|
+
const shareName = ObjectDataParser._getString(rawData, DataParser.SHARE, "");
|
|
363
|
+
if (shareName.length === 0) {
|
|
364
|
+
continue;
|
|
365
|
+
}
|
|
366
|
+
let skinName = ObjectDataParser._getString(rawData, DataParser.SKIN, DataParser.DEFAULT_NAME);
|
|
367
|
+
if (skinName.length === 0) {
|
|
368
|
+
//
|
|
369
|
+
skinName = DataParser.DEFAULT_NAME;
|
|
370
|
+
}
|
|
371
|
+
const shareMesh = armature.getMesh(skinName, "", shareName); // TODO slot;
|
|
372
|
+
if (shareMesh === null) {
|
|
373
|
+
continue; // Error.
|
|
374
|
+
}
|
|
375
|
+
const mesh = this._cacheMeshes[i];
|
|
376
|
+
mesh.geometry.shareFrom(shareMesh.geometry);
|
|
377
|
+
}
|
|
378
|
+
if (DataParser.ANIMATION in rawData) {
|
|
379
|
+
const rawAnimations = rawData[DataParser.ANIMATION];
|
|
380
|
+
for (const rawAnimation of rawAnimations) {
|
|
381
|
+
const animation = this._parseAnimation(rawAnimation);
|
|
382
|
+
armature.addAnimation(animation);
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
if (DataParser.DEFAULT_ACTIONS in rawData) {
|
|
386
|
+
const actions = this._parseActionData(rawData[DataParser.DEFAULT_ACTIONS], 0 /* ActionType.Play */, null, null);
|
|
387
|
+
for (const action of actions) {
|
|
388
|
+
armature.addAction(action, true);
|
|
389
|
+
if (action.type === 0 /* ActionType.Play */) {
|
|
390
|
+
// Set default animation from default action.
|
|
391
|
+
const animation = armature.getAnimation(action.name);
|
|
392
|
+
if (animation !== null) {
|
|
393
|
+
armature.defaultAnimation = animation;
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
if (DataParser.ACTIONS in rawData) {
|
|
399
|
+
const actions = this._parseActionData(rawData[DataParser.ACTIONS], 0 /* ActionType.Play */, null, null);
|
|
400
|
+
for (const action of actions) {
|
|
401
|
+
armature.addAction(action, false);
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
// Clear helper.
|
|
405
|
+
this._rawBones.length = 0;
|
|
406
|
+
this._cacheRawMeshes.length = 0;
|
|
407
|
+
this._cacheMeshes.length = 0;
|
|
408
|
+
this._armature = null;
|
|
409
|
+
for (let k in this._weightSlotPose) {
|
|
410
|
+
delete this._weightSlotPose[k];
|
|
411
|
+
}
|
|
412
|
+
for (let k in this._weightBonePoses) {
|
|
413
|
+
delete this._weightBonePoses[k];
|
|
414
|
+
}
|
|
415
|
+
for (let k in this._cacheBones) {
|
|
416
|
+
delete this._cacheBones[k];
|
|
417
|
+
}
|
|
418
|
+
for (let k in this._slotChildActions) {
|
|
419
|
+
delete this._slotChildActions[k];
|
|
420
|
+
}
|
|
421
|
+
return armature;
|
|
422
|
+
}
|
|
423
|
+
_parseBone(rawData) {
|
|
424
|
+
let type = 0 /* BoneType.Bone */;
|
|
425
|
+
if (DataParser.TYPE in rawData &&
|
|
426
|
+
typeof rawData[DataParser.TYPE] === "string") {
|
|
427
|
+
type = DataParser._getBoneType(rawData[DataParser.TYPE]);
|
|
428
|
+
}
|
|
429
|
+
else {
|
|
430
|
+
type = ObjectDataParser._getNumber(rawData, DataParser.TYPE, 0 /* BoneType.Bone */);
|
|
431
|
+
}
|
|
432
|
+
if (type === 0 /* BoneType.Bone */) {
|
|
433
|
+
const scale = this._armature.scale;
|
|
434
|
+
const bone = BaseObject.borrowObject(BoneData);
|
|
435
|
+
bone.inheritTranslation = ObjectDataParser._getBoolean(rawData, DataParser.INHERIT_TRANSLATION, true);
|
|
436
|
+
bone.inheritRotation = ObjectDataParser._getBoolean(rawData, DataParser.INHERIT_ROTATION, true);
|
|
437
|
+
bone.inheritScale = ObjectDataParser._getBoolean(rawData, DataParser.INHERIT_SCALE, true);
|
|
438
|
+
bone.inheritReflection = ObjectDataParser._getBoolean(rawData, DataParser.INHERIT_REFLECTION, true);
|
|
439
|
+
bone.length =
|
|
440
|
+
ObjectDataParser._getNumber(rawData, DataParser.LENGTH, 0) * scale;
|
|
441
|
+
bone.alpha = ObjectDataParser._getNumber(rawData, DataParser.ALPHA, 1.0);
|
|
442
|
+
bone.name = ObjectDataParser._getString(rawData, DataParser.NAME, "");
|
|
443
|
+
if (DataParser.TRANSFORM in rawData) {
|
|
444
|
+
this._parseTransform(rawData[DataParser.TRANSFORM], bone.transform, scale);
|
|
445
|
+
}
|
|
446
|
+
return bone;
|
|
447
|
+
}
|
|
448
|
+
const surface = BaseObject.borrowObject(SurfaceData);
|
|
449
|
+
surface.alpha = ObjectDataParser._getNumber(rawData, DataParser.ALPHA, 1.0);
|
|
450
|
+
surface.name = ObjectDataParser._getString(rawData, DataParser.NAME, "");
|
|
451
|
+
surface.segmentX = ObjectDataParser._getNumber(rawData, DataParser.SEGMENT_X, 0);
|
|
452
|
+
surface.segmentY = ObjectDataParser._getNumber(rawData, DataParser.SEGMENT_Y, 0);
|
|
453
|
+
this._parseGeometry(rawData, surface.geometry);
|
|
454
|
+
return surface;
|
|
455
|
+
}
|
|
456
|
+
_parseIKConstraint(rawData) {
|
|
457
|
+
const bone = this._armature.getBone(ObjectDataParser._getString(rawData, DataParser.BONE, ""));
|
|
458
|
+
if (bone === null) {
|
|
459
|
+
return null;
|
|
460
|
+
}
|
|
461
|
+
const target = this._armature.getBone(ObjectDataParser._getString(rawData, DataParser.TARGET, ""));
|
|
462
|
+
if (target === null) {
|
|
463
|
+
return null;
|
|
464
|
+
}
|
|
465
|
+
const chain = ObjectDataParser._getNumber(rawData, DataParser.CHAIN, 0);
|
|
466
|
+
const constraint = BaseObject.borrowObject(IKConstraintData);
|
|
467
|
+
constraint.scaleEnabled = ObjectDataParser._getBoolean(rawData, DataParser.SCALE, false);
|
|
468
|
+
constraint.bendPositive = ObjectDataParser._getBoolean(rawData, DataParser.BEND_POSITIVE, true);
|
|
469
|
+
constraint.weight = ObjectDataParser._getNumber(rawData, DataParser.WEIGHT, 1.0);
|
|
470
|
+
constraint.name = ObjectDataParser._getString(rawData, DataParser.NAME, "");
|
|
471
|
+
constraint.type = 0 /* ConstraintType.IK */;
|
|
472
|
+
constraint.target = target;
|
|
473
|
+
if (chain > 0 && bone.parent !== null) {
|
|
474
|
+
constraint.root = bone.parent;
|
|
475
|
+
constraint.bone = bone;
|
|
476
|
+
}
|
|
477
|
+
else {
|
|
478
|
+
constraint.root = bone;
|
|
479
|
+
constraint.bone = null;
|
|
480
|
+
}
|
|
481
|
+
return constraint;
|
|
482
|
+
}
|
|
483
|
+
_parsePathConstraint(rawData) {
|
|
484
|
+
const target = this._armature.getSlot(ObjectDataParser._getString(rawData, DataParser.TARGET, ""));
|
|
485
|
+
if (target === null) {
|
|
486
|
+
return null;
|
|
487
|
+
}
|
|
488
|
+
const defaultSkin = this._armature.defaultSkin;
|
|
489
|
+
if (defaultSkin === null) {
|
|
490
|
+
return null;
|
|
491
|
+
}
|
|
492
|
+
//TODO
|
|
493
|
+
const targetDisplay = defaultSkin.getDisplay(target.name, ObjectDataParser._getString(rawData, DataParser.TARGET_DISPLAY, target.name));
|
|
494
|
+
if (targetDisplay === null || !(targetDisplay instanceof PathDisplayData)) {
|
|
495
|
+
return null;
|
|
496
|
+
}
|
|
497
|
+
const bones = rawData[DataParser.BONES];
|
|
498
|
+
if (bones === null || bones.length === 0) {
|
|
499
|
+
return null;
|
|
500
|
+
}
|
|
501
|
+
const constraint = BaseObject.borrowObject(PathConstraintData);
|
|
502
|
+
constraint.name = ObjectDataParser._getString(rawData, DataParser.NAME, "");
|
|
503
|
+
constraint.type = 1 /* ConstraintType.Path */;
|
|
504
|
+
constraint.pathSlot = target;
|
|
505
|
+
constraint.pathDisplayData = targetDisplay;
|
|
506
|
+
constraint.target = target.parent;
|
|
507
|
+
constraint.positionMode = DataParser._getPositionMode(ObjectDataParser._getString(rawData, DataParser.POSITION_MODE, ""));
|
|
508
|
+
constraint.spacingMode = DataParser._getSpacingMode(ObjectDataParser._getString(rawData, DataParser.SPACING_MODE, ""));
|
|
509
|
+
constraint.rotateMode = DataParser._getRotateMode(ObjectDataParser._getString(rawData, DataParser.ROTATE_MODE, ""));
|
|
510
|
+
constraint.position = ObjectDataParser._getNumber(rawData, DataParser.POSITION, 0);
|
|
511
|
+
constraint.spacing = ObjectDataParser._getNumber(rawData, DataParser.SPACING, 0);
|
|
512
|
+
constraint.rotateOffset = ObjectDataParser._getNumber(rawData, DataParser.ROTATE_OFFSET, 0);
|
|
513
|
+
constraint.rotateMix = ObjectDataParser._getNumber(rawData, DataParser.ROTATE_MIX, 1);
|
|
514
|
+
constraint.translateMix = ObjectDataParser._getNumber(rawData, DataParser.TRANSLATE_MIX, 1);
|
|
515
|
+
//
|
|
516
|
+
for (var boneName of bones) {
|
|
517
|
+
const bone = this._armature.getBone(boneName);
|
|
518
|
+
if (bone !== null) {
|
|
519
|
+
constraint.AddBone(bone);
|
|
520
|
+
if (constraint.root === null) {
|
|
521
|
+
constraint.root = bone;
|
|
522
|
+
}
|
|
523
|
+
}
|
|
524
|
+
}
|
|
525
|
+
return constraint;
|
|
526
|
+
}
|
|
527
|
+
_parseSlot(rawData, zOrder) {
|
|
528
|
+
const slot = BaseObject.borrowObject(SlotData);
|
|
529
|
+
slot.displayIndex = ObjectDataParser._getNumber(rawData, DataParser.DISPLAY_INDEX, 0);
|
|
530
|
+
slot.zOrder = zOrder;
|
|
531
|
+
slot.zIndex = ObjectDataParser._getNumber(rawData, DataParser.Z_INDEX, 0);
|
|
532
|
+
slot.alpha = ObjectDataParser._getNumber(rawData, DataParser.ALPHA, 1.0);
|
|
533
|
+
slot.name = ObjectDataParser._getString(rawData, DataParser.NAME, "");
|
|
534
|
+
slot.parent = this._armature.getBone(ObjectDataParser._getString(rawData, DataParser.PARENT, "")); //
|
|
535
|
+
if (DataParser.BLEND_MODE in rawData &&
|
|
536
|
+
typeof rawData[DataParser.BLEND_MODE] === "string") {
|
|
537
|
+
slot.blendMode = DataParser._getBlendMode(rawData[DataParser.BLEND_MODE]);
|
|
538
|
+
}
|
|
539
|
+
else {
|
|
540
|
+
slot.blendMode = ObjectDataParser._getNumber(rawData, DataParser.BLEND_MODE, 0 /* BlendMode.Normal */);
|
|
541
|
+
}
|
|
542
|
+
if (DataParser.COLOR in rawData) {
|
|
543
|
+
slot.color = SlotData.createColor();
|
|
544
|
+
this._parseColorTransform(rawData[DataParser.COLOR], slot.color);
|
|
545
|
+
}
|
|
546
|
+
else {
|
|
547
|
+
slot.color = SlotData.DEFAULT_COLOR;
|
|
548
|
+
}
|
|
549
|
+
if (DataParser.ACTIONS in rawData) {
|
|
550
|
+
this._slotChildActions[slot.name] = this._parseActionData(rawData[DataParser.ACTIONS], 0 /* ActionType.Play */, null, null);
|
|
551
|
+
}
|
|
552
|
+
return slot;
|
|
553
|
+
}
|
|
554
|
+
_parseSkin(rawData) {
|
|
555
|
+
const skin = BaseObject.borrowObject(SkinData);
|
|
556
|
+
skin.name = ObjectDataParser._getString(rawData, DataParser.NAME, DataParser.DEFAULT_NAME);
|
|
557
|
+
if (skin.name.length === 0) {
|
|
558
|
+
skin.name = DataParser.DEFAULT_NAME;
|
|
559
|
+
}
|
|
560
|
+
if (DataParser.SLOT in rawData) {
|
|
561
|
+
const rawSlots = rawData[DataParser.SLOT];
|
|
562
|
+
this._skin = skin;
|
|
563
|
+
for (const rawSlot of rawSlots) {
|
|
564
|
+
const slotName = ObjectDataParser._getString(rawSlot, DataParser.NAME, "");
|
|
565
|
+
const slot = this._armature.getSlot(slotName);
|
|
566
|
+
if (slot !== null) {
|
|
567
|
+
this._slot = slot;
|
|
568
|
+
if (DataParser.DISPLAY in rawSlot) {
|
|
569
|
+
const rawDisplays = rawSlot[DataParser.DISPLAY];
|
|
570
|
+
for (const rawDisplay of rawDisplays) {
|
|
571
|
+
if (rawDisplay) {
|
|
572
|
+
skin.addDisplay(slotName, this._parseDisplay(rawDisplay));
|
|
573
|
+
}
|
|
574
|
+
else {
|
|
575
|
+
skin.addDisplay(slotName, null);
|
|
576
|
+
}
|
|
577
|
+
}
|
|
578
|
+
}
|
|
579
|
+
this._slot = null; //
|
|
580
|
+
}
|
|
581
|
+
}
|
|
582
|
+
this._skin = null; //
|
|
583
|
+
}
|
|
584
|
+
return skin;
|
|
585
|
+
}
|
|
586
|
+
_parseDisplay(rawData) {
|
|
587
|
+
const name = ObjectDataParser._getString(rawData, DataParser.NAME, "");
|
|
588
|
+
const path = ObjectDataParser._getString(rawData, DataParser.PATH, "");
|
|
589
|
+
let type = 0 /* DisplayType.Image */;
|
|
590
|
+
let display = null;
|
|
591
|
+
if (DataParser.TYPE in rawData &&
|
|
592
|
+
typeof rawData[DataParser.TYPE] === "string") {
|
|
593
|
+
type = DataParser._getDisplayType(rawData[DataParser.TYPE]);
|
|
594
|
+
}
|
|
595
|
+
else {
|
|
596
|
+
type = ObjectDataParser._getNumber(rawData, DataParser.TYPE, type);
|
|
597
|
+
}
|
|
598
|
+
switch (type) {
|
|
599
|
+
case 0 /* DisplayType.Image */: {
|
|
600
|
+
const imageDisplay = (display =
|
|
601
|
+
BaseObject.borrowObject(ImageDisplayData));
|
|
602
|
+
imageDisplay.name = name;
|
|
603
|
+
imageDisplay.path = path.length > 0 ? path : name;
|
|
604
|
+
this._parsePivot(rawData, imageDisplay);
|
|
605
|
+
break;
|
|
606
|
+
}
|
|
607
|
+
case 1 /* DisplayType.Armature */: {
|
|
608
|
+
const armatureDisplay = (display =
|
|
609
|
+
BaseObject.borrowObject(ArmatureDisplayData));
|
|
610
|
+
armatureDisplay.name = name;
|
|
611
|
+
armatureDisplay.path = path.length > 0 ? path : name;
|
|
612
|
+
armatureDisplay.inheritAnimation = true;
|
|
613
|
+
if (DataParser.ACTIONS in rawData) {
|
|
614
|
+
const actions = this._parseActionData(rawData[DataParser.ACTIONS], 0 /* ActionType.Play */, null, null);
|
|
615
|
+
for (const action of actions) {
|
|
616
|
+
armatureDisplay.addAction(action);
|
|
617
|
+
}
|
|
618
|
+
}
|
|
619
|
+
else if (this._slot.name in this._slotChildActions) {
|
|
620
|
+
const displays = this._skin.getDisplays(this._slot.name);
|
|
621
|
+
if (displays === null
|
|
622
|
+
? this._slot.displayIndex === 0
|
|
623
|
+
: this._slot.displayIndex === displays.length) {
|
|
624
|
+
for (const action of this._slotChildActions[this._slot.name]) {
|
|
625
|
+
armatureDisplay.addAction(action);
|
|
626
|
+
}
|
|
627
|
+
delete this._slotChildActions[this._slot.name];
|
|
628
|
+
}
|
|
629
|
+
}
|
|
630
|
+
break;
|
|
631
|
+
}
|
|
632
|
+
case 2 /* DisplayType.Mesh */: {
|
|
633
|
+
const meshDisplay = (display =
|
|
634
|
+
BaseObject.borrowObject(MeshDisplayData));
|
|
635
|
+
meshDisplay.geometry.inheritDeform = ObjectDataParser._getBoolean(rawData, DataParser.INHERIT_DEFORM, true);
|
|
636
|
+
meshDisplay.name = name;
|
|
637
|
+
meshDisplay.path = path.length > 0 ? path : name;
|
|
638
|
+
if (DataParser.SHARE in rawData) {
|
|
639
|
+
meshDisplay.geometry.data = this._data;
|
|
640
|
+
this._cacheRawMeshes.push(rawData);
|
|
641
|
+
this._cacheMeshes.push(meshDisplay);
|
|
642
|
+
}
|
|
643
|
+
else {
|
|
644
|
+
this._parseMesh(rawData, meshDisplay);
|
|
645
|
+
}
|
|
646
|
+
break;
|
|
647
|
+
}
|
|
648
|
+
case 3 /* DisplayType.BoundingBox */: {
|
|
649
|
+
const boundingBox = this._parseBoundingBox(rawData);
|
|
650
|
+
if (boundingBox !== null) {
|
|
651
|
+
const boundingBoxDisplay = (display = BaseObject.borrowObject(BoundingBoxDisplayData));
|
|
652
|
+
boundingBoxDisplay.name = name;
|
|
653
|
+
boundingBoxDisplay.path = path.length > 0 ? path : name;
|
|
654
|
+
boundingBoxDisplay.boundingBox = boundingBox;
|
|
655
|
+
}
|
|
656
|
+
break;
|
|
657
|
+
}
|
|
658
|
+
case 4 /* DisplayType.Path */: {
|
|
659
|
+
const rawCurveLengths = rawData[DataParser.LENGTHS];
|
|
660
|
+
const pathDisplay = (display =
|
|
661
|
+
BaseObject.borrowObject(PathDisplayData));
|
|
662
|
+
pathDisplay.closed = ObjectDataParser._getBoolean(rawData, DataParser.CLOSED, false);
|
|
663
|
+
pathDisplay.constantSpeed = ObjectDataParser._getBoolean(rawData, DataParser.CONSTANT_SPEED, false);
|
|
664
|
+
pathDisplay.name = name;
|
|
665
|
+
pathDisplay.path = path.length > 0 ? path : name;
|
|
666
|
+
pathDisplay.curveLengths.length = rawCurveLengths.length;
|
|
667
|
+
for (let i = 0, l = rawCurveLengths.length; i < l; ++i) {
|
|
668
|
+
pathDisplay.curveLengths[i] = rawCurveLengths[i];
|
|
669
|
+
}
|
|
670
|
+
this._parsePath(rawData, pathDisplay);
|
|
671
|
+
break;
|
|
672
|
+
}
|
|
673
|
+
}
|
|
674
|
+
if (display !== null && DataParser.TRANSFORM in rawData) {
|
|
675
|
+
this._parseTransform(rawData[DataParser.TRANSFORM], display.transform, this._armature.scale);
|
|
676
|
+
}
|
|
677
|
+
return display;
|
|
678
|
+
}
|
|
679
|
+
_parsePath(rawData, display) {
|
|
680
|
+
this._parseGeometry(rawData, display.geometry);
|
|
681
|
+
}
|
|
682
|
+
_parsePivot(rawData, display) {
|
|
683
|
+
if (DataParser.PIVOT in rawData) {
|
|
684
|
+
const rawPivot = rawData[DataParser.PIVOT];
|
|
685
|
+
display.pivot.x = ObjectDataParser._getNumber(rawPivot, DataParser.X, 0.0);
|
|
686
|
+
display.pivot.y = ObjectDataParser._getNumber(rawPivot, DataParser.Y, 0.0);
|
|
687
|
+
}
|
|
688
|
+
else {
|
|
689
|
+
display.pivot.x = 0.5;
|
|
690
|
+
display.pivot.y = 0.5;
|
|
691
|
+
}
|
|
692
|
+
}
|
|
693
|
+
_parseMesh(rawData, mesh) {
|
|
694
|
+
this._parseGeometry(rawData, mesh.geometry);
|
|
695
|
+
if (DataParser.WEIGHTS in rawData) {
|
|
696
|
+
// Cache pose data.
|
|
697
|
+
const rawSlotPose = rawData[DataParser.SLOT_POSE];
|
|
698
|
+
const rawBonePoses = rawData[DataParser.BONE_POSE];
|
|
699
|
+
const meshName = this._skin.name + "_" + this._slot.name + "_" + mesh.name;
|
|
700
|
+
this._weightSlotPose[meshName] = rawSlotPose;
|
|
701
|
+
this._weightBonePoses[meshName] = rawBonePoses;
|
|
702
|
+
}
|
|
703
|
+
}
|
|
704
|
+
_parseBoundingBox(rawData) {
|
|
705
|
+
let boundingBox = null;
|
|
706
|
+
let type = 0 /* BoundingBoxType.Rectangle */;
|
|
707
|
+
if (DataParser.SUB_TYPE in rawData &&
|
|
708
|
+
typeof rawData[DataParser.SUB_TYPE] === "string") {
|
|
709
|
+
type = DataParser._getBoundingBoxType(rawData[DataParser.SUB_TYPE]);
|
|
710
|
+
}
|
|
711
|
+
else {
|
|
712
|
+
type = ObjectDataParser._getNumber(rawData, DataParser.SUB_TYPE, type);
|
|
713
|
+
}
|
|
714
|
+
switch (type) {
|
|
715
|
+
case 0 /* BoundingBoxType.Rectangle */:
|
|
716
|
+
boundingBox = BaseObject.borrowObject(RectangleBoundingBoxData);
|
|
717
|
+
break;
|
|
718
|
+
case 1 /* BoundingBoxType.Ellipse */:
|
|
719
|
+
boundingBox = BaseObject.borrowObject(EllipseBoundingBoxData);
|
|
720
|
+
break;
|
|
721
|
+
case 2 /* BoundingBoxType.Polygon */:
|
|
722
|
+
boundingBox = this._parsePolygonBoundingBox(rawData);
|
|
723
|
+
break;
|
|
724
|
+
}
|
|
725
|
+
if (boundingBox !== null) {
|
|
726
|
+
boundingBox.color = ObjectDataParser._getNumber(rawData, DataParser.COLOR, 0x000000);
|
|
727
|
+
if (boundingBox.type === 0 /* BoundingBoxType.Rectangle */ ||
|
|
728
|
+
boundingBox.type === 1 /* BoundingBoxType.Ellipse */) {
|
|
729
|
+
boundingBox.width = ObjectDataParser._getNumber(rawData, DataParser.WIDTH, 0.0);
|
|
730
|
+
boundingBox.height = ObjectDataParser._getNumber(rawData, DataParser.HEIGHT, 0.0);
|
|
731
|
+
}
|
|
732
|
+
}
|
|
733
|
+
return boundingBox;
|
|
734
|
+
}
|
|
735
|
+
_parsePolygonBoundingBox(rawData) {
|
|
736
|
+
const polygonBoundingBox = BaseObject.borrowObject(PolygonBoundingBoxData);
|
|
737
|
+
if (DataParser.VERTICES in rawData) {
|
|
738
|
+
const scale = this._armature.scale;
|
|
739
|
+
const rawVertices = rawData[DataParser.VERTICES];
|
|
740
|
+
const vertices = polygonBoundingBox.vertices;
|
|
741
|
+
vertices.length = rawVertices.length;
|
|
742
|
+
for (let i = 0, l = rawVertices.length; i < l; i += 2) {
|
|
743
|
+
const x = rawVertices[i] * scale;
|
|
744
|
+
const y = rawVertices[i + 1] * scale;
|
|
745
|
+
vertices[i] = x;
|
|
746
|
+
vertices[i + 1] = y;
|
|
747
|
+
// AABB.
|
|
748
|
+
if (i === 0) {
|
|
749
|
+
polygonBoundingBox.x = x;
|
|
750
|
+
polygonBoundingBox.y = y;
|
|
751
|
+
polygonBoundingBox.width = x;
|
|
752
|
+
polygonBoundingBox.height = y;
|
|
753
|
+
}
|
|
754
|
+
else {
|
|
755
|
+
if (x < polygonBoundingBox.x) {
|
|
756
|
+
polygonBoundingBox.x = x;
|
|
757
|
+
}
|
|
758
|
+
else if (x > polygonBoundingBox.width) {
|
|
759
|
+
polygonBoundingBox.width = x;
|
|
760
|
+
}
|
|
761
|
+
if (y < polygonBoundingBox.y) {
|
|
762
|
+
polygonBoundingBox.y = y;
|
|
763
|
+
}
|
|
764
|
+
else if (y > polygonBoundingBox.height) {
|
|
765
|
+
polygonBoundingBox.height = y;
|
|
766
|
+
}
|
|
767
|
+
}
|
|
768
|
+
}
|
|
769
|
+
polygonBoundingBox.width -= polygonBoundingBox.x;
|
|
770
|
+
polygonBoundingBox.height -= polygonBoundingBox.y;
|
|
771
|
+
}
|
|
772
|
+
else {
|
|
773
|
+
console.warn("Data error.\n Please reexport DragonBones Data to fixed the bug.");
|
|
774
|
+
}
|
|
775
|
+
return polygonBoundingBox;
|
|
776
|
+
}
|
|
777
|
+
_parseAnimation(rawData) {
|
|
778
|
+
const animation = BaseObject.borrowObject(AnimationData);
|
|
779
|
+
animation.blendType = DataParser._getAnimationBlendType(ObjectDataParser._getString(rawData, DataParser.BLEND_TYPE, ""));
|
|
780
|
+
animation.frameCount = ObjectDataParser._getNumber(rawData, DataParser.DURATION, 0);
|
|
781
|
+
animation.playTimes = ObjectDataParser._getNumber(rawData, DataParser.PLAY_TIMES, 1);
|
|
782
|
+
animation.duration = animation.frameCount / this._armature.frameRate; // float
|
|
783
|
+
animation.fadeInTime = ObjectDataParser._getNumber(rawData, DataParser.FADE_IN_TIME, 0.0);
|
|
784
|
+
animation.scale = ObjectDataParser._getNumber(rawData, DataParser.SCALE, 1.0);
|
|
785
|
+
animation.name = ObjectDataParser._getString(rawData, DataParser.NAME, DataParser.DEFAULT_NAME);
|
|
786
|
+
if (animation.name.length === 0) {
|
|
787
|
+
animation.name = DataParser.DEFAULT_NAME;
|
|
788
|
+
}
|
|
789
|
+
animation.frameIntOffset = this._frameIntArray.length;
|
|
790
|
+
animation.frameFloatOffset = this._frameFloatArray.length;
|
|
791
|
+
animation.frameOffset = this._frameArray.length;
|
|
792
|
+
this._animation = animation;
|
|
793
|
+
if (DataParser.FRAME in rawData) {
|
|
794
|
+
const rawFrames = rawData[DataParser.FRAME];
|
|
795
|
+
const keyFrameCount = rawFrames.length;
|
|
796
|
+
if (keyFrameCount > 0) {
|
|
797
|
+
for (let i = 0, frameStart = 0; i < keyFrameCount; ++i) {
|
|
798
|
+
const rawFrame = rawFrames[i];
|
|
799
|
+
this._parseActionDataInFrame(rawFrame, frameStart, null, null);
|
|
800
|
+
frameStart += ObjectDataParser._getNumber(rawFrame, DataParser.DURATION, 1);
|
|
801
|
+
}
|
|
802
|
+
}
|
|
803
|
+
}
|
|
804
|
+
if (DataParser.Z_ORDER in rawData) {
|
|
805
|
+
this._animation.zOrderTimeline = this._parseTimeline(rawData[DataParser.Z_ORDER], null, DataParser.FRAME, 1 /* TimelineType.ZOrder */, 0 /* FrameValueType.Step */, 0, this._parseZOrderFrame);
|
|
806
|
+
}
|
|
807
|
+
if (DataParser.BONE in rawData) {
|
|
808
|
+
const rawTimelines = rawData[DataParser.BONE];
|
|
809
|
+
for (const rawTimeline of rawTimelines) {
|
|
810
|
+
this._parseBoneTimeline(rawTimeline);
|
|
811
|
+
}
|
|
812
|
+
}
|
|
813
|
+
if (DataParser.SLOT in rawData) {
|
|
814
|
+
const rawTimelines = rawData[DataParser.SLOT];
|
|
815
|
+
for (const rawTimeline of rawTimelines) {
|
|
816
|
+
this._parseSlotTimeline(rawTimeline);
|
|
817
|
+
}
|
|
818
|
+
}
|
|
819
|
+
if (DataParser.FFD in rawData) {
|
|
820
|
+
const rawTimelines = rawData[DataParser.FFD];
|
|
821
|
+
for (const rawTimeline of rawTimelines) {
|
|
822
|
+
let skinName = ObjectDataParser._getString(rawTimeline, DataParser.SKIN, DataParser.DEFAULT_NAME);
|
|
823
|
+
const slotName = ObjectDataParser._getString(rawTimeline, DataParser.SLOT, "");
|
|
824
|
+
const displayName = ObjectDataParser._getString(rawTimeline, DataParser.NAME, "");
|
|
825
|
+
if (skinName.length === 0) {
|
|
826
|
+
//
|
|
827
|
+
skinName = DataParser.DEFAULT_NAME;
|
|
828
|
+
}
|
|
829
|
+
this._slot = this._armature.getSlot(slotName);
|
|
830
|
+
this._mesh = this._armature.getMesh(skinName, slotName, displayName);
|
|
831
|
+
if (this._slot === null || this._mesh === null) {
|
|
832
|
+
continue;
|
|
833
|
+
}
|
|
834
|
+
const timeline = this._parseTimeline(rawTimeline, null, DataParser.FRAME, 22 /* TimelineType.SlotDeform */, 2 /* FrameValueType.Float */, 0, this._parseSlotDeformFrame);
|
|
835
|
+
if (timeline !== null) {
|
|
836
|
+
this._animation.addSlotTimeline(slotName, timeline);
|
|
837
|
+
}
|
|
838
|
+
this._slot = null; //
|
|
839
|
+
this._mesh = null; //
|
|
840
|
+
}
|
|
841
|
+
}
|
|
842
|
+
if (DataParser.IK in rawData) {
|
|
843
|
+
const rawTimelines = rawData[DataParser.IK];
|
|
844
|
+
for (const rawTimeline of rawTimelines) {
|
|
845
|
+
const constraintName = ObjectDataParser._getString(rawTimeline, DataParser.NAME, "");
|
|
846
|
+
const constraint = this._armature.getConstraint(constraintName);
|
|
847
|
+
if (constraint === null) {
|
|
848
|
+
continue;
|
|
849
|
+
}
|
|
850
|
+
const timeline = this._parseTimeline(rawTimeline, null, DataParser.FRAME, 30 /* TimelineType.IKConstraint */, 1 /* FrameValueType.Int */, 2, this._parseIKConstraintFrame);
|
|
851
|
+
if (timeline !== null) {
|
|
852
|
+
this._animation.addConstraintTimeline(constraintName, timeline);
|
|
853
|
+
}
|
|
854
|
+
}
|
|
855
|
+
}
|
|
856
|
+
if (this._actionFrames.length > 0) {
|
|
857
|
+
this._animation.actionTimeline = this._parseTimeline(null, this._actionFrames, "", 0 /* TimelineType.Action */, 0 /* FrameValueType.Step */, 0, this._parseActionFrame);
|
|
858
|
+
this._actionFrames.length = 0;
|
|
859
|
+
}
|
|
860
|
+
if (DataParser.TIMELINE in rawData) {
|
|
861
|
+
const rawTimelines = rawData[DataParser.TIMELINE];
|
|
862
|
+
for (const rawTimeline of rawTimelines) {
|
|
863
|
+
const timelineType = ObjectDataParser._getNumber(rawTimeline, DataParser.TYPE, 0 /* TimelineType.Action */);
|
|
864
|
+
const timelineName = ObjectDataParser._getString(rawTimeline, DataParser.NAME, "");
|
|
865
|
+
let timeline = null;
|
|
866
|
+
switch (timelineType) {
|
|
867
|
+
case 0 /* TimelineType.Action */:
|
|
868
|
+
// TODO
|
|
869
|
+
break;
|
|
870
|
+
case 20 /* TimelineType.SlotDisplay */: // TODO
|
|
871
|
+
case 23 /* TimelineType.SlotZIndex */:
|
|
872
|
+
case 60 /* TimelineType.BoneAlpha */:
|
|
873
|
+
case 24 /* TimelineType.SlotAlpha */:
|
|
874
|
+
case 40 /* TimelineType.AnimationProgress */:
|
|
875
|
+
case 41 /* TimelineType.AnimationWeight */:
|
|
876
|
+
if (timelineType === 20 /* TimelineType.SlotDisplay */) {
|
|
877
|
+
this._frameValueType = 0 /* FrameValueType.Step */;
|
|
878
|
+
this._frameValueScale = 1.0;
|
|
879
|
+
}
|
|
880
|
+
else {
|
|
881
|
+
this._frameValueType = 1 /* FrameValueType.Int */;
|
|
882
|
+
if (timelineType === 23 /* TimelineType.SlotZIndex */) {
|
|
883
|
+
this._frameValueScale = 1.0;
|
|
884
|
+
}
|
|
885
|
+
else if (timelineType === 40 /* TimelineType.AnimationProgress */ ||
|
|
886
|
+
timelineType === 41 /* TimelineType.AnimationWeight */) {
|
|
887
|
+
this._frameValueScale = 10000.0;
|
|
888
|
+
}
|
|
889
|
+
else {
|
|
890
|
+
this._frameValueScale = 100.0;
|
|
891
|
+
}
|
|
892
|
+
}
|
|
893
|
+
if (timelineType === 60 /* TimelineType.BoneAlpha */ ||
|
|
894
|
+
timelineType === 24 /* TimelineType.SlotAlpha */ ||
|
|
895
|
+
timelineType === 41 /* TimelineType.AnimationWeight */) {
|
|
896
|
+
this._frameDefaultValue = 1.0;
|
|
897
|
+
}
|
|
898
|
+
else {
|
|
899
|
+
this._frameDefaultValue = 0.0;
|
|
900
|
+
}
|
|
901
|
+
if (timelineType === 40 /* TimelineType.AnimationProgress */ &&
|
|
902
|
+
animation.blendType !== 0 /* AnimationBlendType.None */) {
|
|
903
|
+
timeline = BaseObject.borrowObject(AnimationTimelineData);
|
|
904
|
+
const animaitonTimeline = timeline;
|
|
905
|
+
animaitonTimeline.x = ObjectDataParser._getNumber(rawTimeline, DataParser.X, 0.0);
|
|
906
|
+
animaitonTimeline.y = ObjectDataParser._getNumber(rawTimeline, DataParser.Y, 0.0);
|
|
907
|
+
}
|
|
908
|
+
timeline = this._parseTimeline(rawTimeline, null, DataParser.FRAME, timelineType, this._frameValueType, 1, this._parseSingleValueFrame, timeline);
|
|
909
|
+
break;
|
|
910
|
+
case 11 /* TimelineType.BoneTranslate */:
|
|
911
|
+
case 12 /* TimelineType.BoneRotate */:
|
|
912
|
+
case 13 /* TimelineType.BoneScale */:
|
|
913
|
+
case 30 /* TimelineType.IKConstraint */:
|
|
914
|
+
case 42 /* TimelineType.AnimationParameter */:
|
|
915
|
+
if (timelineType === 30 /* TimelineType.IKConstraint */ ||
|
|
916
|
+
timelineType === 42 /* TimelineType.AnimationParameter */) {
|
|
917
|
+
this._frameValueType = 1 /* FrameValueType.Int */;
|
|
918
|
+
if (timelineType === 42 /* TimelineType.AnimationParameter */) {
|
|
919
|
+
this._frameValueScale = 10000.0;
|
|
920
|
+
}
|
|
921
|
+
else {
|
|
922
|
+
this._frameValueScale = 100.0;
|
|
923
|
+
}
|
|
924
|
+
}
|
|
925
|
+
else {
|
|
926
|
+
if (timelineType === 12 /* TimelineType.BoneRotate */) {
|
|
927
|
+
this._frameValueScale = Transform.DEG_RAD;
|
|
928
|
+
}
|
|
929
|
+
else {
|
|
930
|
+
this._frameValueScale = 1.0;
|
|
931
|
+
}
|
|
932
|
+
this._frameValueType = 2 /* FrameValueType.Float */;
|
|
933
|
+
}
|
|
934
|
+
if (timelineType === 13 /* TimelineType.BoneScale */ ||
|
|
935
|
+
timelineType === 30 /* TimelineType.IKConstraint */) {
|
|
936
|
+
this._frameDefaultValue = 1.0;
|
|
937
|
+
}
|
|
938
|
+
else {
|
|
939
|
+
this._frameDefaultValue = 0.0;
|
|
940
|
+
}
|
|
941
|
+
timeline = this._parseTimeline(rawTimeline, null, DataParser.FRAME, timelineType, this._frameValueType, 2, this._parseDoubleValueFrame);
|
|
942
|
+
break;
|
|
943
|
+
case 1 /* TimelineType.ZOrder */:
|
|
944
|
+
// TODO
|
|
945
|
+
break;
|
|
946
|
+
case 50 /* TimelineType.Surface */: {
|
|
947
|
+
const surface = this._armature.getBone(timelineName);
|
|
948
|
+
if (surface === null) {
|
|
949
|
+
continue;
|
|
950
|
+
}
|
|
951
|
+
this._geometry = surface.geometry;
|
|
952
|
+
timeline = this._parseTimeline(rawTimeline, null, DataParser.FRAME, timelineType, 2 /* FrameValueType.Float */, 0, this._parseDeformFrame);
|
|
953
|
+
this._geometry = null; //
|
|
954
|
+
break;
|
|
955
|
+
}
|
|
956
|
+
case 22 /* TimelineType.SlotDeform */: {
|
|
957
|
+
this._geometry = null; //
|
|
958
|
+
for (const skinName in this._armature.skins) {
|
|
959
|
+
const skin = this._armature.skins[skinName];
|
|
960
|
+
for (const slontName in skin.displays) {
|
|
961
|
+
const displays = skin.displays[slontName];
|
|
962
|
+
for (const display of displays) {
|
|
963
|
+
if (display !== null && display.name === timelineName) {
|
|
964
|
+
this._geometry = display.geometry;
|
|
965
|
+
break;
|
|
966
|
+
}
|
|
967
|
+
}
|
|
968
|
+
}
|
|
969
|
+
}
|
|
970
|
+
if (this._geometry === null) {
|
|
971
|
+
continue;
|
|
972
|
+
}
|
|
973
|
+
timeline = this._parseTimeline(rawTimeline, null, DataParser.FRAME, timelineType, 2 /* FrameValueType.Float */, 0, this._parseDeformFrame);
|
|
974
|
+
this._geometry = null; //
|
|
975
|
+
break;
|
|
976
|
+
}
|
|
977
|
+
case 21 /* TimelineType.SlotColor */:
|
|
978
|
+
timeline = this._parseTimeline(rawTimeline, null, DataParser.FRAME, timelineType, 1 /* FrameValueType.Int */, 1, this._parseSlotColorFrame);
|
|
979
|
+
break;
|
|
980
|
+
}
|
|
981
|
+
if (timeline !== null) {
|
|
982
|
+
switch (timelineType) {
|
|
983
|
+
case 0 /* TimelineType.Action */:
|
|
984
|
+
// TODO
|
|
985
|
+
break;
|
|
986
|
+
case 1 /* TimelineType.ZOrder */:
|
|
987
|
+
// TODO
|
|
988
|
+
break;
|
|
989
|
+
case 11 /* TimelineType.BoneTranslate */:
|
|
990
|
+
case 12 /* TimelineType.BoneRotate */:
|
|
991
|
+
case 13 /* TimelineType.BoneScale */:
|
|
992
|
+
case 50 /* TimelineType.Surface */:
|
|
993
|
+
case 60 /* TimelineType.BoneAlpha */:
|
|
994
|
+
this._animation.addBoneTimeline(timelineName, timeline);
|
|
995
|
+
break;
|
|
996
|
+
case 20 /* TimelineType.SlotDisplay */:
|
|
997
|
+
case 21 /* TimelineType.SlotColor */:
|
|
998
|
+
case 22 /* TimelineType.SlotDeform */:
|
|
999
|
+
case 23 /* TimelineType.SlotZIndex */:
|
|
1000
|
+
case 24 /* TimelineType.SlotAlpha */:
|
|
1001
|
+
this._animation.addSlotTimeline(timelineName, timeline);
|
|
1002
|
+
break;
|
|
1003
|
+
case 30 /* TimelineType.IKConstraint */:
|
|
1004
|
+
this._animation.addConstraintTimeline(timelineName, timeline);
|
|
1005
|
+
break;
|
|
1006
|
+
case 40 /* TimelineType.AnimationProgress */:
|
|
1007
|
+
case 41 /* TimelineType.AnimationWeight */:
|
|
1008
|
+
case 42 /* TimelineType.AnimationParameter */:
|
|
1009
|
+
this._animation.addAnimationTimeline(timelineName, timeline);
|
|
1010
|
+
break;
|
|
1011
|
+
}
|
|
1012
|
+
}
|
|
1013
|
+
}
|
|
1014
|
+
}
|
|
1015
|
+
this._animation = null; //
|
|
1016
|
+
return animation;
|
|
1017
|
+
}
|
|
1018
|
+
_parseTimeline(rawData, rawFrames, framesKey, timelineType, frameValueType, frameValueCount, frameParser, timeline = null) {
|
|
1019
|
+
if (rawData !== null && framesKey.length > 0 && framesKey in rawData) {
|
|
1020
|
+
rawFrames = rawData[framesKey];
|
|
1021
|
+
}
|
|
1022
|
+
if (rawFrames === null) {
|
|
1023
|
+
return null;
|
|
1024
|
+
}
|
|
1025
|
+
const keyFrameCount = rawFrames.length;
|
|
1026
|
+
if (keyFrameCount === 0) {
|
|
1027
|
+
return null;
|
|
1028
|
+
}
|
|
1029
|
+
const frameIntArrayLength = this._frameIntArray.length;
|
|
1030
|
+
const frameFloatArrayLength = this._frameFloatArray.length;
|
|
1031
|
+
const timelineOffset = this._timelineArray.length;
|
|
1032
|
+
if (timeline === null) {
|
|
1033
|
+
timeline = BaseObject.borrowObject(TimelineData);
|
|
1034
|
+
}
|
|
1035
|
+
timeline.type = timelineType;
|
|
1036
|
+
timeline.offset = timelineOffset;
|
|
1037
|
+
this._frameValueType = frameValueType;
|
|
1038
|
+
this._timeline = timeline;
|
|
1039
|
+
this._timelineArray.length += 1 + 1 + 1 + 1 + 1 + keyFrameCount;
|
|
1040
|
+
if (rawData !== null) {
|
|
1041
|
+
this._timelineArray[timelineOffset + 0 /* BinaryOffset.TimelineScale */] =
|
|
1042
|
+
Math.round(ObjectDataParser._getNumber(rawData, DataParser.SCALE, 1.0) * 100);
|
|
1043
|
+
this._timelineArray[timelineOffset + 1 /* BinaryOffset.TimelineOffset */] =
|
|
1044
|
+
Math.round(ObjectDataParser._getNumber(rawData, DataParser.OFFSET, 0.0) * 100);
|
|
1045
|
+
}
|
|
1046
|
+
else {
|
|
1047
|
+
this._timelineArray[timelineOffset + 0 /* BinaryOffset.TimelineScale */] = 100;
|
|
1048
|
+
this._timelineArray[timelineOffset + 1 /* BinaryOffset.TimelineOffset */] = 0;
|
|
1049
|
+
}
|
|
1050
|
+
this._timelineArray[timelineOffset + 2 /* BinaryOffset.TimelineKeyFrameCount */] =
|
|
1051
|
+
keyFrameCount;
|
|
1052
|
+
this._timelineArray[timelineOffset + 3 /* BinaryOffset.TimelineFrameValueCount */] =
|
|
1053
|
+
frameValueCount;
|
|
1054
|
+
switch (this._frameValueType) {
|
|
1055
|
+
case 0 /* FrameValueType.Step */:
|
|
1056
|
+
this._timelineArray[timelineOffset + 4 /* BinaryOffset.TimelineFrameValueOffset */] = 0;
|
|
1057
|
+
break;
|
|
1058
|
+
case 1 /* FrameValueType.Int */:
|
|
1059
|
+
this._timelineArray[timelineOffset + 4 /* BinaryOffset.TimelineFrameValueOffset */] = frameIntArrayLength - this._animation.frameIntOffset;
|
|
1060
|
+
break;
|
|
1061
|
+
case 2 /* FrameValueType.Float */:
|
|
1062
|
+
this._timelineArray[timelineOffset + 4 /* BinaryOffset.TimelineFrameValueOffset */] = frameFloatArrayLength - this._animation.frameFloatOffset;
|
|
1063
|
+
break;
|
|
1064
|
+
}
|
|
1065
|
+
if (keyFrameCount === 1) {
|
|
1066
|
+
// Only one frame.
|
|
1067
|
+
timeline.frameIndicesOffset = -1;
|
|
1068
|
+
this._timelineArray[timelineOffset + 5 /* BinaryOffset.TimelineFrameOffset */ + 0] =
|
|
1069
|
+
frameParser.call(this, rawFrames[0], 0, 0) -
|
|
1070
|
+
this._animation.frameOffset;
|
|
1071
|
+
}
|
|
1072
|
+
else {
|
|
1073
|
+
const totalFrameCount = this._animation.frameCount + 1; // One more frame than animation.
|
|
1074
|
+
const frameIndices = this._data.frameIndices;
|
|
1075
|
+
const frameIndicesOffset = frameIndices.length;
|
|
1076
|
+
frameIndices.length += totalFrameCount;
|
|
1077
|
+
timeline.frameIndicesOffset = frameIndicesOffset;
|
|
1078
|
+
for (let i = 0, iK = 0, frameStart = 0, frameCount = 0; i < totalFrameCount; ++i) {
|
|
1079
|
+
if (frameStart + frameCount <= i && iK < keyFrameCount) {
|
|
1080
|
+
const rawFrame = rawFrames[iK];
|
|
1081
|
+
frameStart = i; // frame.frameStart;
|
|
1082
|
+
if (iK === keyFrameCount - 1) {
|
|
1083
|
+
frameCount = this._animation.frameCount - frameStart;
|
|
1084
|
+
}
|
|
1085
|
+
else {
|
|
1086
|
+
if (rawFrame instanceof ActionFrame) {
|
|
1087
|
+
frameCount = this._actionFrames[iK + 1].frameStart - frameStart;
|
|
1088
|
+
}
|
|
1089
|
+
else {
|
|
1090
|
+
frameCount = ObjectDataParser._getNumber(rawFrame, DataParser.DURATION, 1);
|
|
1091
|
+
}
|
|
1092
|
+
}
|
|
1093
|
+
this._timelineArray[timelineOffset + 5 /* BinaryOffset.TimelineFrameOffset */ + iK] =
|
|
1094
|
+
frameParser.call(this, rawFrame, frameStart, frameCount) -
|
|
1095
|
+
this._animation.frameOffset;
|
|
1096
|
+
iK++;
|
|
1097
|
+
}
|
|
1098
|
+
frameIndices[frameIndicesOffset + i] = iK - 1;
|
|
1099
|
+
}
|
|
1100
|
+
}
|
|
1101
|
+
this._timeline = null; //
|
|
1102
|
+
return timeline;
|
|
1103
|
+
}
|
|
1104
|
+
_parseBoneTimeline(rawData) {
|
|
1105
|
+
const bone = this._armature.getBone(ObjectDataParser._getString(rawData, DataParser.NAME, ""));
|
|
1106
|
+
if (bone === null) {
|
|
1107
|
+
return;
|
|
1108
|
+
}
|
|
1109
|
+
this._bone = bone;
|
|
1110
|
+
this._slot = this._armature.getSlot(this._bone.name);
|
|
1111
|
+
if (DataParser.TRANSLATE_FRAME in rawData) {
|
|
1112
|
+
this._frameDefaultValue = 0.0;
|
|
1113
|
+
this._frameValueScale = 1.0;
|
|
1114
|
+
const timeline = this._parseTimeline(rawData, null, DataParser.TRANSLATE_FRAME, 11 /* TimelineType.BoneTranslate */, 2 /* FrameValueType.Float */, 2, this._parseDoubleValueFrame);
|
|
1115
|
+
if (timeline !== null) {
|
|
1116
|
+
this._animation.addBoneTimeline(bone.name, timeline);
|
|
1117
|
+
}
|
|
1118
|
+
}
|
|
1119
|
+
if (DataParser.ROTATE_FRAME in rawData) {
|
|
1120
|
+
this._frameDefaultValue = 0.0;
|
|
1121
|
+
this._frameValueScale = 1.0;
|
|
1122
|
+
const timeline = this._parseTimeline(rawData, null, DataParser.ROTATE_FRAME, 12 /* TimelineType.BoneRotate */, 2 /* FrameValueType.Float */, 2, this._parseBoneRotateFrame);
|
|
1123
|
+
if (timeline !== null) {
|
|
1124
|
+
this._animation.addBoneTimeline(bone.name, timeline);
|
|
1125
|
+
}
|
|
1126
|
+
}
|
|
1127
|
+
if (DataParser.SCALE_FRAME in rawData) {
|
|
1128
|
+
this._frameDefaultValue = 1.0;
|
|
1129
|
+
this._frameValueScale = 1.0;
|
|
1130
|
+
const timeline = this._parseTimeline(rawData, null, DataParser.SCALE_FRAME, 13 /* TimelineType.BoneScale */, 2 /* FrameValueType.Float */, 2, this._parseBoneScaleFrame);
|
|
1131
|
+
if (timeline !== null) {
|
|
1132
|
+
this._animation.addBoneTimeline(bone.name, timeline);
|
|
1133
|
+
}
|
|
1134
|
+
}
|
|
1135
|
+
if (DataParser.FRAME in rawData) {
|
|
1136
|
+
const timeline = this._parseTimeline(rawData, null, DataParser.FRAME, 10 /* TimelineType.BoneAll */, 2 /* FrameValueType.Float */, 6, this._parseBoneAllFrame);
|
|
1137
|
+
if (timeline !== null) {
|
|
1138
|
+
this._animation.addBoneTimeline(bone.name, timeline);
|
|
1139
|
+
}
|
|
1140
|
+
}
|
|
1141
|
+
this._bone = null; //
|
|
1142
|
+
this._slot = null; //
|
|
1143
|
+
}
|
|
1144
|
+
_parseSlotTimeline(rawData) {
|
|
1145
|
+
const slot = this._armature.getSlot(ObjectDataParser._getString(rawData, DataParser.NAME, ""));
|
|
1146
|
+
if (slot === null) {
|
|
1147
|
+
return;
|
|
1148
|
+
}
|
|
1149
|
+
let displayTimeline = null;
|
|
1150
|
+
let colorTimeline = null;
|
|
1151
|
+
this._slot = slot;
|
|
1152
|
+
if (DataParser.DISPLAY_FRAME in rawData) {
|
|
1153
|
+
displayTimeline = this._parseTimeline(rawData, null, DataParser.DISPLAY_FRAME, 20 /* TimelineType.SlotDisplay */, 0 /* FrameValueType.Step */, 0, this._parseSlotDisplayFrame);
|
|
1154
|
+
}
|
|
1155
|
+
else {
|
|
1156
|
+
displayTimeline = this._parseTimeline(rawData, null, DataParser.FRAME, 20 /* TimelineType.SlotDisplay */, 0 /* FrameValueType.Step */, 0, this._parseSlotDisplayFrame);
|
|
1157
|
+
}
|
|
1158
|
+
if (DataParser.COLOR_FRAME in rawData) {
|
|
1159
|
+
colorTimeline = this._parseTimeline(rawData, null, DataParser.COLOR_FRAME, 21 /* TimelineType.SlotColor */, 1 /* FrameValueType.Int */, 1, this._parseSlotColorFrame);
|
|
1160
|
+
}
|
|
1161
|
+
else {
|
|
1162
|
+
colorTimeline = this._parseTimeline(rawData, null, DataParser.FRAME, 21 /* TimelineType.SlotColor */, 1 /* FrameValueType.Int */, 1, this._parseSlotColorFrame);
|
|
1163
|
+
}
|
|
1164
|
+
if (displayTimeline !== null) {
|
|
1165
|
+
this._animation.addSlotTimeline(slot.name, displayTimeline);
|
|
1166
|
+
}
|
|
1167
|
+
if (colorTimeline !== null) {
|
|
1168
|
+
this._animation.addSlotTimeline(slot.name, colorTimeline);
|
|
1169
|
+
}
|
|
1170
|
+
this._slot = null; //
|
|
1171
|
+
}
|
|
1172
|
+
_parseFrame(rawData, frameStart, frameCount) {
|
|
1173
|
+
// tslint:disable-next-line:no-unused-expression
|
|
1174
|
+
rawData;
|
|
1175
|
+
// tslint:disable-next-line:no-unused-expression
|
|
1176
|
+
frameCount;
|
|
1177
|
+
const frameOffset = this._frameArray.length;
|
|
1178
|
+
this._frameArray.length += 1;
|
|
1179
|
+
this._frameArray[frameOffset + 0 /* BinaryOffset.FramePosition */] = frameStart;
|
|
1180
|
+
return frameOffset;
|
|
1181
|
+
}
|
|
1182
|
+
_parseTweenFrame(rawData, frameStart, frameCount) {
|
|
1183
|
+
const frameOffset = this._parseFrame(rawData, frameStart, frameCount);
|
|
1184
|
+
if (frameCount > 0) {
|
|
1185
|
+
if (DataParser.CURVE in rawData) {
|
|
1186
|
+
const sampleCount = frameCount + 1;
|
|
1187
|
+
this._helpArray.length = sampleCount;
|
|
1188
|
+
const isOmited = this._samplingEasingCurve(rawData[DataParser.CURVE], this._helpArray);
|
|
1189
|
+
this._frameArray.length += 1 + 1 + this._helpArray.length;
|
|
1190
|
+
this._frameArray[frameOffset + 1 /* BinaryOffset.FrameTweenType */] =
|
|
1191
|
+
2 /* TweenType.Curve */;
|
|
1192
|
+
this._frameArray[frameOffset + 2 /* BinaryOffset.FrameTweenEasingOrCurveSampleCount */] = isOmited ? sampleCount : -sampleCount;
|
|
1193
|
+
for (let i = 0; i < sampleCount; ++i) {
|
|
1194
|
+
this._frameArray[frameOffset + 3 /* BinaryOffset.FrameCurveSamples */ + i] =
|
|
1195
|
+
Math.round(this._helpArray[i] * 10000.0);
|
|
1196
|
+
}
|
|
1197
|
+
}
|
|
1198
|
+
else {
|
|
1199
|
+
const noTween = -2.0;
|
|
1200
|
+
let tweenEasing = noTween;
|
|
1201
|
+
if (DataParser.TWEEN_EASING in rawData) {
|
|
1202
|
+
tweenEasing = ObjectDataParser._getNumber(rawData, DataParser.TWEEN_EASING, noTween);
|
|
1203
|
+
}
|
|
1204
|
+
if (tweenEasing === noTween) {
|
|
1205
|
+
this._frameArray.length += 1;
|
|
1206
|
+
this._frameArray[frameOffset + 1 /* BinaryOffset.FrameTweenType */] =
|
|
1207
|
+
0 /* TweenType.None */;
|
|
1208
|
+
}
|
|
1209
|
+
else if (tweenEasing === 0.0) {
|
|
1210
|
+
this._frameArray.length += 1;
|
|
1211
|
+
this._frameArray[frameOffset + 1 /* BinaryOffset.FrameTweenType */] =
|
|
1212
|
+
1 /* TweenType.Line */;
|
|
1213
|
+
}
|
|
1214
|
+
else if (tweenEasing < 0.0) {
|
|
1215
|
+
this._frameArray.length += 1 + 1;
|
|
1216
|
+
this._frameArray[frameOffset + 1 /* BinaryOffset.FrameTweenType */] =
|
|
1217
|
+
3 /* TweenType.QuadIn */;
|
|
1218
|
+
this._frameArray[frameOffset + 2 /* BinaryOffset.FrameTweenEasingOrCurveSampleCount */] = Math.round(-tweenEasing * 100.0);
|
|
1219
|
+
}
|
|
1220
|
+
else if (tweenEasing <= 1.0) {
|
|
1221
|
+
this._frameArray.length += 1 + 1;
|
|
1222
|
+
this._frameArray[frameOffset + 1 /* BinaryOffset.FrameTweenType */] =
|
|
1223
|
+
4 /* TweenType.QuadOut */;
|
|
1224
|
+
this._frameArray[frameOffset + 2 /* BinaryOffset.FrameTweenEasingOrCurveSampleCount */] = Math.round(tweenEasing * 100.0);
|
|
1225
|
+
}
|
|
1226
|
+
else {
|
|
1227
|
+
this._frameArray.length += 1 + 1;
|
|
1228
|
+
this._frameArray[frameOffset + 1 /* BinaryOffset.FrameTweenType */] =
|
|
1229
|
+
5 /* TweenType.QuadInOut */;
|
|
1230
|
+
this._frameArray[frameOffset + 2 /* BinaryOffset.FrameTweenEasingOrCurveSampleCount */] = Math.round(tweenEasing * 100.0 - 100.0);
|
|
1231
|
+
}
|
|
1232
|
+
}
|
|
1233
|
+
}
|
|
1234
|
+
else {
|
|
1235
|
+
this._frameArray.length += 1;
|
|
1236
|
+
this._frameArray[frameOffset + 1 /* BinaryOffset.FrameTweenType */] =
|
|
1237
|
+
0 /* TweenType.None */;
|
|
1238
|
+
}
|
|
1239
|
+
return frameOffset;
|
|
1240
|
+
}
|
|
1241
|
+
_parseSingleValueFrame(rawData, frameStart, frameCount) {
|
|
1242
|
+
let frameOffset = 0;
|
|
1243
|
+
switch (this._frameValueType) {
|
|
1244
|
+
case 0: {
|
|
1245
|
+
frameOffset = this._parseFrame(rawData, frameStart, frameCount);
|
|
1246
|
+
this._frameArray.length += 1;
|
|
1247
|
+
this._frameArray[frameOffset + 1] = ObjectDataParser._getNumber(rawData, DataParser.VALUE, this._frameDefaultValue);
|
|
1248
|
+
break;
|
|
1249
|
+
}
|
|
1250
|
+
case 1: {
|
|
1251
|
+
frameOffset = this._parseTweenFrame(rawData, frameStart, frameCount);
|
|
1252
|
+
const frameValueOffset = this._frameIntArray.length;
|
|
1253
|
+
this._frameIntArray.length += 1;
|
|
1254
|
+
this._frameIntArray[frameValueOffset] = Math.round(ObjectDataParser._getNumber(rawData, DataParser.VALUE, this._frameDefaultValue) * this._frameValueScale);
|
|
1255
|
+
break;
|
|
1256
|
+
}
|
|
1257
|
+
case 2: {
|
|
1258
|
+
frameOffset = this._parseTweenFrame(rawData, frameStart, frameCount);
|
|
1259
|
+
const frameValueOffset = this._frameFloatArray.length;
|
|
1260
|
+
this._frameFloatArray.length += 1;
|
|
1261
|
+
this._frameFloatArray[frameValueOffset] =
|
|
1262
|
+
ObjectDataParser._getNumber(rawData, DataParser.VALUE, this._frameDefaultValue) * this._frameValueScale;
|
|
1263
|
+
break;
|
|
1264
|
+
}
|
|
1265
|
+
}
|
|
1266
|
+
return frameOffset;
|
|
1267
|
+
}
|
|
1268
|
+
_parseDoubleValueFrame(rawData, frameStart, frameCount) {
|
|
1269
|
+
let frameOffset = 0;
|
|
1270
|
+
switch (this._frameValueType) {
|
|
1271
|
+
case 0: {
|
|
1272
|
+
frameOffset = this._parseFrame(rawData, frameStart, frameCount);
|
|
1273
|
+
this._frameArray.length += 2;
|
|
1274
|
+
this._frameArray[frameOffset + 1] = ObjectDataParser._getNumber(rawData, DataParser.X, this._frameDefaultValue);
|
|
1275
|
+
this._frameArray[frameOffset + 2] = ObjectDataParser._getNumber(rawData, DataParser.Y, this._frameDefaultValue);
|
|
1276
|
+
break;
|
|
1277
|
+
}
|
|
1278
|
+
case 1: {
|
|
1279
|
+
frameOffset = this._parseTweenFrame(rawData, frameStart, frameCount);
|
|
1280
|
+
const frameValueOffset = this._frameIntArray.length;
|
|
1281
|
+
this._frameIntArray.length += 2;
|
|
1282
|
+
this._frameIntArray[frameValueOffset] = Math.round(ObjectDataParser._getNumber(rawData, DataParser.X, this._frameDefaultValue) * this._frameValueScale);
|
|
1283
|
+
this._frameIntArray[frameValueOffset + 1] = Math.round(ObjectDataParser._getNumber(rawData, DataParser.Y, this._frameDefaultValue) * this._frameValueScale);
|
|
1284
|
+
break;
|
|
1285
|
+
}
|
|
1286
|
+
case 2: {
|
|
1287
|
+
frameOffset = this._parseTweenFrame(rawData, frameStart, frameCount);
|
|
1288
|
+
const frameValueOffset = this._frameFloatArray.length;
|
|
1289
|
+
this._frameFloatArray.length += 2;
|
|
1290
|
+
this._frameFloatArray[frameValueOffset] =
|
|
1291
|
+
ObjectDataParser._getNumber(rawData, DataParser.X, this._frameDefaultValue) * this._frameValueScale;
|
|
1292
|
+
this._frameFloatArray[frameValueOffset + 1] =
|
|
1293
|
+
ObjectDataParser._getNumber(rawData, DataParser.Y, this._frameDefaultValue) * this._frameValueScale;
|
|
1294
|
+
break;
|
|
1295
|
+
}
|
|
1296
|
+
}
|
|
1297
|
+
return frameOffset;
|
|
1298
|
+
}
|
|
1299
|
+
_parseActionFrame(frame, frameStart, frameCount) {
|
|
1300
|
+
// tslint:disable-next-line:no-unused-expression
|
|
1301
|
+
frameCount;
|
|
1302
|
+
const frameOffset = this._frameArray.length;
|
|
1303
|
+
const actionCount = frame.actions.length;
|
|
1304
|
+
this._frameArray.length += 1 + 1 + actionCount;
|
|
1305
|
+
this._frameArray[frameOffset + 0 /* BinaryOffset.FramePosition */] = frameStart;
|
|
1306
|
+
this._frameArray[frameOffset + 0 /* BinaryOffset.FramePosition */ + 1] =
|
|
1307
|
+
actionCount; // Action count.
|
|
1308
|
+
for (let i = 0; i < actionCount; ++i) {
|
|
1309
|
+
// Action offsets.
|
|
1310
|
+
this._frameArray[frameOffset + 0 /* BinaryOffset.FramePosition */ + 2 + i] =
|
|
1311
|
+
frame.actions[i];
|
|
1312
|
+
}
|
|
1313
|
+
return frameOffset;
|
|
1314
|
+
}
|
|
1315
|
+
_parseZOrderFrame(rawData, frameStart, frameCount) {
|
|
1316
|
+
const frameOffset = this._parseFrame(rawData, frameStart, frameCount);
|
|
1317
|
+
if (DataParser.Z_ORDER in rawData) {
|
|
1318
|
+
const rawZOrder = rawData[DataParser.Z_ORDER];
|
|
1319
|
+
if (rawZOrder.length > 0) {
|
|
1320
|
+
const slotCount = this._armature.sortedSlots.length;
|
|
1321
|
+
const unchanged = new Array(slotCount - rawZOrder.length / 2);
|
|
1322
|
+
const zOrders = new Array(slotCount);
|
|
1323
|
+
for (let i = 0; i < unchanged.length; ++i) {
|
|
1324
|
+
unchanged[i] = 0;
|
|
1325
|
+
}
|
|
1326
|
+
for (let i = 0; i < slotCount; ++i) {
|
|
1327
|
+
zOrders[i] = -1;
|
|
1328
|
+
}
|
|
1329
|
+
let originalIndex = 0;
|
|
1330
|
+
let unchangedIndex = 0;
|
|
1331
|
+
for (let i = 0, l = rawZOrder.length; i < l; i += 2) {
|
|
1332
|
+
const slotIndex = rawZOrder[i];
|
|
1333
|
+
const zOrderOffset = rawZOrder[i + 1];
|
|
1334
|
+
while (originalIndex !== slotIndex) {
|
|
1335
|
+
unchanged[unchangedIndex++] = originalIndex++;
|
|
1336
|
+
}
|
|
1337
|
+
const index = originalIndex + zOrderOffset;
|
|
1338
|
+
zOrders[index] = originalIndex++;
|
|
1339
|
+
}
|
|
1340
|
+
while (originalIndex < slotCount) {
|
|
1341
|
+
unchanged[unchangedIndex++] = originalIndex++;
|
|
1342
|
+
}
|
|
1343
|
+
this._frameArray.length += 1 + slotCount;
|
|
1344
|
+
this._frameArray[frameOffset + 1] = slotCount;
|
|
1345
|
+
let i = slotCount;
|
|
1346
|
+
while (i--) {
|
|
1347
|
+
if (zOrders[i] === -1) {
|
|
1348
|
+
this._frameArray[frameOffset + 2 + i] =
|
|
1349
|
+
unchanged[--unchangedIndex] || 0;
|
|
1350
|
+
}
|
|
1351
|
+
else {
|
|
1352
|
+
this._frameArray[frameOffset + 2 + i] = zOrders[i] || 0;
|
|
1353
|
+
}
|
|
1354
|
+
}
|
|
1355
|
+
return frameOffset;
|
|
1356
|
+
}
|
|
1357
|
+
}
|
|
1358
|
+
this._frameArray.length += 1;
|
|
1359
|
+
this._frameArray[frameOffset + 1] = 0;
|
|
1360
|
+
return frameOffset;
|
|
1361
|
+
}
|
|
1362
|
+
_parseBoneAllFrame(rawData, frameStart, frameCount) {
|
|
1363
|
+
this._helpTransform.identity();
|
|
1364
|
+
if (DataParser.TRANSFORM in rawData) {
|
|
1365
|
+
this._parseTransform(rawData[DataParser.TRANSFORM], this._helpTransform, 1.0);
|
|
1366
|
+
}
|
|
1367
|
+
// Modify rotation.
|
|
1368
|
+
let rotation = this._helpTransform.rotation;
|
|
1369
|
+
if (frameStart !== 0) {
|
|
1370
|
+
if (this._prevClockwise === 0) {
|
|
1371
|
+
rotation =
|
|
1372
|
+
this._prevRotation +
|
|
1373
|
+
Transform.normalizeRadian(rotation - this._prevRotation);
|
|
1374
|
+
}
|
|
1375
|
+
else {
|
|
1376
|
+
if (this._prevClockwise > 0
|
|
1377
|
+
? rotation >= this._prevRotation
|
|
1378
|
+
: rotation <= this._prevRotation) {
|
|
1379
|
+
this._prevClockwise =
|
|
1380
|
+
this._prevClockwise > 0
|
|
1381
|
+
? this._prevClockwise - 1
|
|
1382
|
+
: this._prevClockwise + 1;
|
|
1383
|
+
}
|
|
1384
|
+
rotation =
|
|
1385
|
+
this._prevRotation +
|
|
1386
|
+
rotation -
|
|
1387
|
+
this._prevRotation +
|
|
1388
|
+
Transform.PI_D * this._prevClockwise;
|
|
1389
|
+
}
|
|
1390
|
+
}
|
|
1391
|
+
this._prevClockwise = ObjectDataParser._getNumber(rawData, DataParser.TWEEN_ROTATE, 0.0);
|
|
1392
|
+
this._prevRotation = rotation;
|
|
1393
|
+
//
|
|
1394
|
+
const frameOffset = this._parseTweenFrame(rawData, frameStart, frameCount);
|
|
1395
|
+
let frameFloatOffset = this._frameFloatArray.length;
|
|
1396
|
+
this._frameFloatArray.length += 6;
|
|
1397
|
+
this._frameFloatArray[frameFloatOffset++] = this._helpTransform.x;
|
|
1398
|
+
this._frameFloatArray[frameFloatOffset++] = this._helpTransform.y;
|
|
1399
|
+
this._frameFloatArray[frameFloatOffset++] = rotation;
|
|
1400
|
+
this._frameFloatArray[frameFloatOffset++] = this._helpTransform.skew;
|
|
1401
|
+
this._frameFloatArray[frameFloatOffset++] = this._helpTransform.scaleX;
|
|
1402
|
+
this._frameFloatArray[frameFloatOffset++] = this._helpTransform.scaleY;
|
|
1403
|
+
this._parseActionDataInFrame(rawData, frameStart, this._bone, this._slot);
|
|
1404
|
+
return frameOffset;
|
|
1405
|
+
}
|
|
1406
|
+
_parseBoneTranslateFrame(rawData, frameStart, frameCount) {
|
|
1407
|
+
const frameOffset = this._parseTweenFrame(rawData, frameStart, frameCount);
|
|
1408
|
+
let frameFloatOffset = this._frameFloatArray.length;
|
|
1409
|
+
this._frameFloatArray.length += 2;
|
|
1410
|
+
this._frameFloatArray[frameFloatOffset++] = ObjectDataParser._getNumber(rawData, DataParser.X, 0.0);
|
|
1411
|
+
this._frameFloatArray[frameFloatOffset++] = ObjectDataParser._getNumber(rawData, DataParser.Y, 0.0);
|
|
1412
|
+
return frameOffset;
|
|
1413
|
+
}
|
|
1414
|
+
_parseBoneRotateFrame(rawData, frameStart, frameCount) {
|
|
1415
|
+
// Modify rotation.
|
|
1416
|
+
let rotation = ObjectDataParser._getNumber(rawData, DataParser.ROTATE, 0.0) *
|
|
1417
|
+
Transform.DEG_RAD;
|
|
1418
|
+
if (frameStart !== 0) {
|
|
1419
|
+
if (this._prevClockwise === 0) {
|
|
1420
|
+
rotation =
|
|
1421
|
+
this._prevRotation +
|
|
1422
|
+
Transform.normalizeRadian(rotation - this._prevRotation);
|
|
1423
|
+
}
|
|
1424
|
+
else {
|
|
1425
|
+
if (this._prevClockwise > 0
|
|
1426
|
+
? rotation >= this._prevRotation
|
|
1427
|
+
: rotation <= this._prevRotation) {
|
|
1428
|
+
this._prevClockwise =
|
|
1429
|
+
this._prevClockwise > 0
|
|
1430
|
+
? this._prevClockwise - 1
|
|
1431
|
+
: this._prevClockwise + 1;
|
|
1432
|
+
}
|
|
1433
|
+
rotation =
|
|
1434
|
+
this._prevRotation +
|
|
1435
|
+
rotation -
|
|
1436
|
+
this._prevRotation +
|
|
1437
|
+
Transform.PI_D * this._prevClockwise;
|
|
1438
|
+
}
|
|
1439
|
+
}
|
|
1440
|
+
this._prevClockwise = ObjectDataParser._getNumber(rawData, DataParser.CLOCK_WISE, 0);
|
|
1441
|
+
this._prevRotation = rotation;
|
|
1442
|
+
//
|
|
1443
|
+
const frameOffset = this._parseTweenFrame(rawData, frameStart, frameCount);
|
|
1444
|
+
let frameFloatOffset = this._frameFloatArray.length;
|
|
1445
|
+
this._frameFloatArray.length += 2;
|
|
1446
|
+
this._frameFloatArray[frameFloatOffset++] = rotation;
|
|
1447
|
+
this._frameFloatArray[frameFloatOffset++] =
|
|
1448
|
+
ObjectDataParser._getNumber(rawData, DataParser.SKEW, 0.0) *
|
|
1449
|
+
Transform.DEG_RAD;
|
|
1450
|
+
return frameOffset;
|
|
1451
|
+
}
|
|
1452
|
+
_parseBoneScaleFrame(rawData, frameStart, frameCount) {
|
|
1453
|
+
const frameOffset = this._parseTweenFrame(rawData, frameStart, frameCount);
|
|
1454
|
+
let frameFloatOffset = this._frameFloatArray.length;
|
|
1455
|
+
this._frameFloatArray.length += 2;
|
|
1456
|
+
this._frameFloatArray[frameFloatOffset++] = ObjectDataParser._getNumber(rawData, DataParser.X, 1.0);
|
|
1457
|
+
this._frameFloatArray[frameFloatOffset++] = ObjectDataParser._getNumber(rawData, DataParser.Y, 1.0);
|
|
1458
|
+
return frameOffset;
|
|
1459
|
+
}
|
|
1460
|
+
_parseSlotDisplayFrame(rawData, frameStart, frameCount) {
|
|
1461
|
+
const frameOffset = this._parseFrame(rawData, frameStart, frameCount);
|
|
1462
|
+
this._frameArray.length += 1;
|
|
1463
|
+
if (DataParser.VALUE in rawData) {
|
|
1464
|
+
this._frameArray[frameOffset + 1] = ObjectDataParser._getNumber(rawData, DataParser.VALUE, 0);
|
|
1465
|
+
}
|
|
1466
|
+
else {
|
|
1467
|
+
this._frameArray[frameOffset + 1] = ObjectDataParser._getNumber(rawData, DataParser.DISPLAY_INDEX, 0);
|
|
1468
|
+
}
|
|
1469
|
+
this._parseActionDataInFrame(rawData, frameStart, this._slot.parent, this._slot);
|
|
1470
|
+
return frameOffset;
|
|
1471
|
+
}
|
|
1472
|
+
_parseSlotColorFrame(rawData, frameStart, frameCount) {
|
|
1473
|
+
const frameOffset = this._parseTweenFrame(rawData, frameStart, frameCount);
|
|
1474
|
+
let colorOffset = -1;
|
|
1475
|
+
if (DataParser.VALUE in rawData || DataParser.COLOR in rawData) {
|
|
1476
|
+
const rawColor = DataParser.VALUE in rawData
|
|
1477
|
+
? rawData[DataParser.VALUE]
|
|
1478
|
+
: rawData[DataParser.COLOR];
|
|
1479
|
+
for (let k in rawColor) {
|
|
1480
|
+
// Detects the presence of color.
|
|
1481
|
+
// tslint:disable-next-line:no-unused-expression
|
|
1482
|
+
k;
|
|
1483
|
+
this._parseColorTransform(rawColor, this._helpColorTransform);
|
|
1484
|
+
colorOffset = this._colorArray.length;
|
|
1485
|
+
this._colorArray.length += 8;
|
|
1486
|
+
this._colorArray[colorOffset++] = Math.round(this._helpColorTransform.alphaMultiplier * 100);
|
|
1487
|
+
this._colorArray[colorOffset++] = Math.round(this._helpColorTransform.redMultiplier * 100);
|
|
1488
|
+
this._colorArray[colorOffset++] = Math.round(this._helpColorTransform.greenMultiplier * 100);
|
|
1489
|
+
this._colorArray[colorOffset++] = Math.round(this._helpColorTransform.blueMultiplier * 100);
|
|
1490
|
+
this._colorArray[colorOffset++] = Math.round(this._helpColorTransform.alphaOffset);
|
|
1491
|
+
this._colorArray[colorOffset++] = Math.round(this._helpColorTransform.redOffset);
|
|
1492
|
+
this._colorArray[colorOffset++] = Math.round(this._helpColorTransform.greenOffset);
|
|
1493
|
+
this._colorArray[colorOffset++] = Math.round(this._helpColorTransform.blueOffset);
|
|
1494
|
+
colorOffset -= 8;
|
|
1495
|
+
break;
|
|
1496
|
+
}
|
|
1497
|
+
}
|
|
1498
|
+
if (colorOffset < 0) {
|
|
1499
|
+
if (this._defaultColorOffset < 0) {
|
|
1500
|
+
this._defaultColorOffset = colorOffset = this._colorArray.length;
|
|
1501
|
+
this._colorArray.length += 8;
|
|
1502
|
+
this._colorArray[colorOffset++] = 100;
|
|
1503
|
+
this._colorArray[colorOffset++] = 100;
|
|
1504
|
+
this._colorArray[colorOffset++] = 100;
|
|
1505
|
+
this._colorArray[colorOffset++] = 100;
|
|
1506
|
+
this._colorArray[colorOffset++] = 0;
|
|
1507
|
+
this._colorArray[colorOffset++] = 0;
|
|
1508
|
+
this._colorArray[colorOffset++] = 0;
|
|
1509
|
+
this._colorArray[colorOffset++] = 0;
|
|
1510
|
+
}
|
|
1511
|
+
colorOffset = this._defaultColorOffset;
|
|
1512
|
+
}
|
|
1513
|
+
const frameIntOffset = this._frameIntArray.length;
|
|
1514
|
+
this._frameIntArray.length += 1;
|
|
1515
|
+
this._frameIntArray[frameIntOffset] = colorOffset;
|
|
1516
|
+
return frameOffset;
|
|
1517
|
+
}
|
|
1518
|
+
_parseSlotDeformFrame(rawData, frameStart, frameCount) {
|
|
1519
|
+
const frameFloatOffset = this._frameFloatArray.length;
|
|
1520
|
+
const frameOffset = this._parseTweenFrame(rawData, frameStart, frameCount);
|
|
1521
|
+
const rawVertices = DataParser.VERTICES in rawData
|
|
1522
|
+
? rawData[DataParser.VERTICES]
|
|
1523
|
+
: null;
|
|
1524
|
+
const offset = ObjectDataParser._getNumber(rawData, DataParser.OFFSET, 0); // uint
|
|
1525
|
+
const vertexCount = this._intArray[this._mesh.geometry.offset + 0 /* BinaryOffset.GeometryVertexCount */];
|
|
1526
|
+
const meshName = this._mesh.parent.name + "_" + this._slot.name + "_" + this._mesh.name;
|
|
1527
|
+
const weight = this._mesh.geometry.weight;
|
|
1528
|
+
let x = 0.0;
|
|
1529
|
+
let y = 0.0;
|
|
1530
|
+
let iB = 0;
|
|
1531
|
+
let iV = 0;
|
|
1532
|
+
if (weight !== null) {
|
|
1533
|
+
const rawSlotPose = this._weightSlotPose[meshName];
|
|
1534
|
+
this._helpMatrixA.copyFromArray(rawSlotPose, 0);
|
|
1535
|
+
this._frameFloatArray.length += weight.count * 2;
|
|
1536
|
+
iB = weight.offset + 2 /* BinaryOffset.WeigthBoneIndices */ + weight.bones.length;
|
|
1537
|
+
}
|
|
1538
|
+
else {
|
|
1539
|
+
this._frameFloatArray.length += vertexCount * 2;
|
|
1540
|
+
}
|
|
1541
|
+
for (let i = 0; i < vertexCount * 2; i += 2) {
|
|
1542
|
+
if (rawVertices === null) {
|
|
1543
|
+
// Fill 0.
|
|
1544
|
+
x = 0.0;
|
|
1545
|
+
y = 0.0;
|
|
1546
|
+
}
|
|
1547
|
+
else {
|
|
1548
|
+
if (i < offset || i - offset >= rawVertices.length) {
|
|
1549
|
+
x = 0.0;
|
|
1550
|
+
}
|
|
1551
|
+
else {
|
|
1552
|
+
x = rawVertices[i - offset];
|
|
1553
|
+
}
|
|
1554
|
+
if (i + 1 < offset || i + 1 - offset >= rawVertices.length) {
|
|
1555
|
+
y = 0.0;
|
|
1556
|
+
}
|
|
1557
|
+
else {
|
|
1558
|
+
y = rawVertices[i + 1 - offset];
|
|
1559
|
+
}
|
|
1560
|
+
}
|
|
1561
|
+
if (weight !== null) {
|
|
1562
|
+
// If mesh is skinned, transform point by bone bind pose.
|
|
1563
|
+
const rawBonePoses = this._weightBonePoses[meshName];
|
|
1564
|
+
const vertexBoneCount = this._intArray[iB++];
|
|
1565
|
+
this._helpMatrixA.transformPoint(x, y, this._helpPoint, true);
|
|
1566
|
+
x = this._helpPoint.x;
|
|
1567
|
+
y = this._helpPoint.y;
|
|
1568
|
+
for (let j = 0; j < vertexBoneCount; ++j) {
|
|
1569
|
+
const boneIndex = this._intArray[iB++];
|
|
1570
|
+
this._helpMatrixB.copyFromArray(rawBonePoses, boneIndex * 7 + 1);
|
|
1571
|
+
this._helpMatrixB.invert();
|
|
1572
|
+
this._helpMatrixB.transformPoint(x, y, this._helpPoint, true);
|
|
1573
|
+
this._frameFloatArray[frameFloatOffset + iV++] = this._helpPoint.x;
|
|
1574
|
+
this._frameFloatArray[frameFloatOffset + iV++] = this._helpPoint.y;
|
|
1575
|
+
}
|
|
1576
|
+
}
|
|
1577
|
+
else {
|
|
1578
|
+
this._frameFloatArray[frameFloatOffset + i] = x;
|
|
1579
|
+
this._frameFloatArray[frameFloatOffset + i + 1] = y;
|
|
1580
|
+
}
|
|
1581
|
+
}
|
|
1582
|
+
if (frameStart === 0) {
|
|
1583
|
+
const frameIntOffset = this._frameIntArray.length;
|
|
1584
|
+
this._frameIntArray.length += 1 + 1 + 1 + 1 + 1;
|
|
1585
|
+
this._frameIntArray[frameIntOffset + 0 /* BinaryOffset.DeformVertexOffset */] =
|
|
1586
|
+
this._mesh.geometry.offset;
|
|
1587
|
+
this._frameIntArray[frameIntOffset + 1 /* BinaryOffset.DeformCount */] =
|
|
1588
|
+
this._frameFloatArray.length - frameFloatOffset;
|
|
1589
|
+
this._frameIntArray[frameIntOffset + 2 /* BinaryOffset.DeformValueCount */] =
|
|
1590
|
+
this._frameFloatArray.length - frameFloatOffset;
|
|
1591
|
+
this._frameIntArray[frameIntOffset + 3 /* BinaryOffset.DeformValueOffset */] = 0;
|
|
1592
|
+
this._frameIntArray[frameIntOffset + 4 /* BinaryOffset.DeformFloatOffset */] =
|
|
1593
|
+
frameFloatOffset - this._animation.frameFloatOffset;
|
|
1594
|
+
this._timelineArray[this._timeline.offset + 3 /* BinaryOffset.TimelineFrameValueCount */] = frameIntOffset - this._animation.frameIntOffset;
|
|
1595
|
+
}
|
|
1596
|
+
return frameOffset;
|
|
1597
|
+
}
|
|
1598
|
+
_parseIKConstraintFrame(rawData, frameStart, frameCount) {
|
|
1599
|
+
const frameOffset = this._parseTweenFrame(rawData, frameStart, frameCount);
|
|
1600
|
+
let frameIntOffset = this._frameIntArray.length;
|
|
1601
|
+
this._frameIntArray.length += 2;
|
|
1602
|
+
this._frameIntArray[frameIntOffset++] = ObjectDataParser._getBoolean(rawData, DataParser.BEND_POSITIVE, true)
|
|
1603
|
+
? 1
|
|
1604
|
+
: 0;
|
|
1605
|
+
this._frameIntArray[frameIntOffset++] = Math.round(ObjectDataParser._getNumber(rawData, DataParser.WEIGHT, 1.0) * 100.0);
|
|
1606
|
+
return frameOffset;
|
|
1607
|
+
}
|
|
1608
|
+
_parseActionData(rawData, type, bone, slot) {
|
|
1609
|
+
const actions = new Array();
|
|
1610
|
+
if (typeof rawData === "string") {
|
|
1611
|
+
const action = BaseObject.borrowObject(ActionData);
|
|
1612
|
+
action.type = type;
|
|
1613
|
+
action.name = rawData;
|
|
1614
|
+
action.bone = bone;
|
|
1615
|
+
action.slot = slot;
|
|
1616
|
+
actions.push(action);
|
|
1617
|
+
}
|
|
1618
|
+
else if (rawData instanceof Array) {
|
|
1619
|
+
for (const rawAction of rawData) {
|
|
1620
|
+
const action = BaseObject.borrowObject(ActionData);
|
|
1621
|
+
if (DataParser.GOTO_AND_PLAY in rawAction) {
|
|
1622
|
+
action.type = 0 /* ActionType.Play */;
|
|
1623
|
+
action.name = ObjectDataParser._getString(rawAction, DataParser.GOTO_AND_PLAY, "");
|
|
1624
|
+
}
|
|
1625
|
+
else {
|
|
1626
|
+
if (DataParser.TYPE in rawAction &&
|
|
1627
|
+
typeof rawAction[DataParser.TYPE] === "string") {
|
|
1628
|
+
action.type = DataParser._getActionType(rawAction[DataParser.TYPE]);
|
|
1629
|
+
}
|
|
1630
|
+
else {
|
|
1631
|
+
action.type = ObjectDataParser._getNumber(rawAction, DataParser.TYPE, type);
|
|
1632
|
+
}
|
|
1633
|
+
action.name = ObjectDataParser._getString(rawAction, DataParser.NAME, "");
|
|
1634
|
+
}
|
|
1635
|
+
if (DataParser.BONE in rawAction) {
|
|
1636
|
+
const boneName = ObjectDataParser._getString(rawAction, DataParser.BONE, "");
|
|
1637
|
+
action.bone = this._armature.getBone(boneName);
|
|
1638
|
+
}
|
|
1639
|
+
else {
|
|
1640
|
+
action.bone = bone;
|
|
1641
|
+
}
|
|
1642
|
+
if (DataParser.SLOT in rawAction) {
|
|
1643
|
+
const slotName = ObjectDataParser._getString(rawAction, DataParser.SLOT, "");
|
|
1644
|
+
action.slot = this._armature.getSlot(slotName);
|
|
1645
|
+
}
|
|
1646
|
+
else {
|
|
1647
|
+
action.slot = slot;
|
|
1648
|
+
}
|
|
1649
|
+
let userData = null;
|
|
1650
|
+
if (DataParser.INTS in rawAction) {
|
|
1651
|
+
if (userData === null) {
|
|
1652
|
+
userData = BaseObject.borrowObject(UserData);
|
|
1653
|
+
}
|
|
1654
|
+
const rawInts = rawAction[DataParser.INTS];
|
|
1655
|
+
for (const rawValue of rawInts) {
|
|
1656
|
+
userData.addInt(rawValue);
|
|
1657
|
+
}
|
|
1658
|
+
}
|
|
1659
|
+
if (DataParser.FLOATS in rawAction) {
|
|
1660
|
+
if (userData === null) {
|
|
1661
|
+
userData = BaseObject.borrowObject(UserData);
|
|
1662
|
+
}
|
|
1663
|
+
const rawFloats = rawAction[DataParser.FLOATS];
|
|
1664
|
+
for (const rawValue of rawFloats) {
|
|
1665
|
+
userData.addFloat(rawValue);
|
|
1666
|
+
}
|
|
1667
|
+
}
|
|
1668
|
+
if (DataParser.STRINGS in rawAction) {
|
|
1669
|
+
if (userData === null) {
|
|
1670
|
+
userData = BaseObject.borrowObject(UserData);
|
|
1671
|
+
}
|
|
1672
|
+
const rawStrings = rawAction[DataParser.STRINGS];
|
|
1673
|
+
for (const rawValue of rawStrings) {
|
|
1674
|
+
userData.addString(rawValue);
|
|
1675
|
+
}
|
|
1676
|
+
}
|
|
1677
|
+
action.data = userData;
|
|
1678
|
+
actions.push(action);
|
|
1679
|
+
}
|
|
1680
|
+
}
|
|
1681
|
+
return actions;
|
|
1682
|
+
}
|
|
1683
|
+
_parseDeformFrame(rawData, frameStart, frameCount) {
|
|
1684
|
+
const frameFloatOffset = this._frameFloatArray.length;
|
|
1685
|
+
const frameOffset = this._parseTweenFrame(rawData, frameStart, frameCount);
|
|
1686
|
+
const rawVertices = DataParser.VERTICES in rawData
|
|
1687
|
+
? rawData[DataParser.VERTICES]
|
|
1688
|
+
: DataParser.VALUE in rawData
|
|
1689
|
+
? rawData[DataParser.VALUE]
|
|
1690
|
+
: null;
|
|
1691
|
+
const offset = ObjectDataParser._getNumber(rawData, DataParser.OFFSET, 0); // uint
|
|
1692
|
+
const vertexCount = this._intArray[this._geometry.offset + 0 /* BinaryOffset.GeometryVertexCount */];
|
|
1693
|
+
const weight = this._geometry.weight;
|
|
1694
|
+
let x = 0.0;
|
|
1695
|
+
let y = 0.0;
|
|
1696
|
+
if (weight !== null) {
|
|
1697
|
+
// TODO
|
|
1698
|
+
}
|
|
1699
|
+
else {
|
|
1700
|
+
this._frameFloatArray.length += vertexCount * 2;
|
|
1701
|
+
for (let i = 0; i < vertexCount * 2; i += 2) {
|
|
1702
|
+
if (rawVertices !== null) {
|
|
1703
|
+
if (i < offset || i - offset >= rawVertices.length) {
|
|
1704
|
+
x = 0.0;
|
|
1705
|
+
}
|
|
1706
|
+
else {
|
|
1707
|
+
x = rawVertices[i - offset];
|
|
1708
|
+
}
|
|
1709
|
+
if (i + 1 < offset || i + 1 - offset >= rawVertices.length) {
|
|
1710
|
+
y = 0.0;
|
|
1711
|
+
}
|
|
1712
|
+
else {
|
|
1713
|
+
y = rawVertices[i + 1 - offset];
|
|
1714
|
+
}
|
|
1715
|
+
}
|
|
1716
|
+
else {
|
|
1717
|
+
x = 0.0;
|
|
1718
|
+
y = 0.0;
|
|
1719
|
+
}
|
|
1720
|
+
this._frameFloatArray[frameFloatOffset + i] = x;
|
|
1721
|
+
this._frameFloatArray[frameFloatOffset + i + 1] = y;
|
|
1722
|
+
}
|
|
1723
|
+
}
|
|
1724
|
+
if (frameStart === 0) {
|
|
1725
|
+
const frameIntOffset = this._frameIntArray.length;
|
|
1726
|
+
this._frameIntArray.length += 1 + 1 + 1 + 1 + 1;
|
|
1727
|
+
this._frameIntArray[frameIntOffset + 0 /* BinaryOffset.DeformVertexOffset */] =
|
|
1728
|
+
this._geometry.offset;
|
|
1729
|
+
this._frameIntArray[frameIntOffset + 1 /* BinaryOffset.DeformCount */] =
|
|
1730
|
+
this._frameFloatArray.length - frameFloatOffset;
|
|
1731
|
+
this._frameIntArray[frameIntOffset + 2 /* BinaryOffset.DeformValueCount */] =
|
|
1732
|
+
this._frameFloatArray.length - frameFloatOffset;
|
|
1733
|
+
this._frameIntArray[frameIntOffset + 3 /* BinaryOffset.DeformValueOffset */] = 0;
|
|
1734
|
+
this._frameIntArray[frameIntOffset + 4 /* BinaryOffset.DeformFloatOffset */] =
|
|
1735
|
+
frameFloatOffset - this._animation.frameFloatOffset;
|
|
1736
|
+
this._timelineArray[this._timeline.offset + 3 /* BinaryOffset.TimelineFrameValueCount */] = frameIntOffset - this._animation.frameIntOffset;
|
|
1737
|
+
}
|
|
1738
|
+
return frameOffset;
|
|
1739
|
+
}
|
|
1740
|
+
_parseTransform(rawData, transform, scale) {
|
|
1741
|
+
transform.x =
|
|
1742
|
+
ObjectDataParser._getNumber(rawData, DataParser.X, 0.0) * scale;
|
|
1743
|
+
transform.y =
|
|
1744
|
+
ObjectDataParser._getNumber(rawData, DataParser.Y, 0.0) * scale;
|
|
1745
|
+
if (DataParser.ROTATE in rawData || DataParser.SKEW in rawData) {
|
|
1746
|
+
transform.rotation = Transform.normalizeRadian(ObjectDataParser._getNumber(rawData, DataParser.ROTATE, 0.0) *
|
|
1747
|
+
Transform.DEG_RAD);
|
|
1748
|
+
transform.skew = Transform.normalizeRadian(ObjectDataParser._getNumber(rawData, DataParser.SKEW, 0.0) *
|
|
1749
|
+
Transform.DEG_RAD);
|
|
1750
|
+
}
|
|
1751
|
+
else if (DataParser.SKEW_X in rawData || DataParser.SKEW_Y in rawData) {
|
|
1752
|
+
transform.rotation = Transform.normalizeRadian(ObjectDataParser._getNumber(rawData, DataParser.SKEW_Y, 0.0) *
|
|
1753
|
+
Transform.DEG_RAD);
|
|
1754
|
+
transform.skew =
|
|
1755
|
+
Transform.normalizeRadian(ObjectDataParser._getNumber(rawData, DataParser.SKEW_X, 0.0) *
|
|
1756
|
+
Transform.DEG_RAD) - transform.rotation;
|
|
1757
|
+
}
|
|
1758
|
+
transform.scaleX = ObjectDataParser._getNumber(rawData, DataParser.SCALE_X, 1.0);
|
|
1759
|
+
transform.scaleY = ObjectDataParser._getNumber(rawData, DataParser.SCALE_Y, 1.0);
|
|
1760
|
+
}
|
|
1761
|
+
_parseColorTransform(rawData, color) {
|
|
1762
|
+
color.alphaMultiplier =
|
|
1763
|
+
ObjectDataParser._getNumber(rawData, DataParser.ALPHA_MULTIPLIER, 100) *
|
|
1764
|
+
0.01;
|
|
1765
|
+
color.redMultiplier =
|
|
1766
|
+
ObjectDataParser._getNumber(rawData, DataParser.RED_MULTIPLIER, 100) *
|
|
1767
|
+
0.01;
|
|
1768
|
+
color.greenMultiplier =
|
|
1769
|
+
ObjectDataParser._getNumber(rawData, DataParser.GREEN_MULTIPLIER, 100) *
|
|
1770
|
+
0.01;
|
|
1771
|
+
color.blueMultiplier =
|
|
1772
|
+
ObjectDataParser._getNumber(rawData, DataParser.BLUE_MULTIPLIER, 100) *
|
|
1773
|
+
0.01;
|
|
1774
|
+
color.alphaOffset = ObjectDataParser._getNumber(rawData, DataParser.ALPHA_OFFSET, 0);
|
|
1775
|
+
color.redOffset = ObjectDataParser._getNumber(rawData, DataParser.RED_OFFSET, 0);
|
|
1776
|
+
color.greenOffset = ObjectDataParser._getNumber(rawData, DataParser.GREEN_OFFSET, 0);
|
|
1777
|
+
color.blueOffset = ObjectDataParser._getNumber(rawData, DataParser.BLUE_OFFSET, 0);
|
|
1778
|
+
}
|
|
1779
|
+
_parseGeometry(rawData, geometry) {
|
|
1780
|
+
const rawVertices = rawData[DataParser.VERTICES];
|
|
1781
|
+
const vertexCount = Math.floor(rawVertices.length / 2); // uint
|
|
1782
|
+
let triangleCount = 0;
|
|
1783
|
+
const geometryOffset = this._intArray.length;
|
|
1784
|
+
const verticesOffset = this._floatArray.length;
|
|
1785
|
+
//
|
|
1786
|
+
geometry.offset = geometryOffset;
|
|
1787
|
+
geometry.data = this._data;
|
|
1788
|
+
//
|
|
1789
|
+
this._intArray.length += 1 + 1 + 1 + 1;
|
|
1790
|
+
this._intArray[geometryOffset + 0 /* BinaryOffset.GeometryVertexCount */] =
|
|
1791
|
+
vertexCount;
|
|
1792
|
+
this._intArray[geometryOffset + 2 /* BinaryOffset.GeometryFloatOffset */] =
|
|
1793
|
+
verticesOffset;
|
|
1794
|
+
this._intArray[geometryOffset + 3 /* BinaryOffset.GeometryWeightOffset */] = -1; //
|
|
1795
|
+
//
|
|
1796
|
+
this._floatArray.length += vertexCount * 2;
|
|
1797
|
+
for (let i = 0, l = vertexCount * 2; i < l; ++i) {
|
|
1798
|
+
this._floatArray[verticesOffset + i] = rawVertices[i];
|
|
1799
|
+
}
|
|
1800
|
+
if (DataParser.TRIANGLES in rawData) {
|
|
1801
|
+
const rawTriangles = rawData[DataParser.TRIANGLES];
|
|
1802
|
+
triangleCount = Math.floor(rawTriangles.length / 3); // uint
|
|
1803
|
+
//
|
|
1804
|
+
this._intArray.length += triangleCount * 3;
|
|
1805
|
+
for (let i = 0, l = triangleCount * 3; i < l; ++i) {
|
|
1806
|
+
this._intArray[geometryOffset + 4 /* BinaryOffset.GeometryVertexIndices */ + i] = rawTriangles[i];
|
|
1807
|
+
}
|
|
1808
|
+
}
|
|
1809
|
+
// Fill triangle count.
|
|
1810
|
+
this._intArray[geometryOffset + 1 /* BinaryOffset.GeometryTriangleCount */] =
|
|
1811
|
+
triangleCount;
|
|
1812
|
+
if (DataParser.UVS in rawData) {
|
|
1813
|
+
const rawUVs = rawData[DataParser.UVS];
|
|
1814
|
+
const uvOffset = verticesOffset + vertexCount * 2;
|
|
1815
|
+
this._floatArray.length += vertexCount * 2;
|
|
1816
|
+
for (let i = 0, l = vertexCount * 2; i < l; ++i) {
|
|
1817
|
+
this._floatArray[uvOffset + i] = rawUVs[i];
|
|
1818
|
+
}
|
|
1819
|
+
}
|
|
1820
|
+
if (DataParser.WEIGHTS in rawData) {
|
|
1821
|
+
const rawWeights = rawData[DataParser.WEIGHTS];
|
|
1822
|
+
const weightCount = Math.floor(rawWeights.length - vertexCount) / 2; // uint
|
|
1823
|
+
const weightOffset = this._intArray.length;
|
|
1824
|
+
const floatOffset = this._floatArray.length;
|
|
1825
|
+
let weightBoneCount = 0;
|
|
1826
|
+
const sortedBones = this._armature.sortedBones;
|
|
1827
|
+
const weight = BaseObject.borrowObject(WeightData);
|
|
1828
|
+
weight.count = weightCount;
|
|
1829
|
+
weight.offset = weightOffset;
|
|
1830
|
+
this._intArray.length +=
|
|
1831
|
+
1 + 1 + weightBoneCount + vertexCount + weightCount;
|
|
1832
|
+
this._intArray[weightOffset + 1 /* BinaryOffset.WeigthFloatOffset */] =
|
|
1833
|
+
floatOffset;
|
|
1834
|
+
if (DataParser.BONE_POSE in rawData) {
|
|
1835
|
+
const rawSlotPose = rawData[DataParser.SLOT_POSE];
|
|
1836
|
+
const rawBonePoses = rawData[DataParser.BONE_POSE];
|
|
1837
|
+
const weightBoneIndices = new Array();
|
|
1838
|
+
weightBoneCount = Math.floor(rawBonePoses.length / 7); // uint
|
|
1839
|
+
weightBoneIndices.length = weightBoneCount;
|
|
1840
|
+
for (let i = 0; i < weightBoneCount; ++i) {
|
|
1841
|
+
const rawBoneIndex = rawBonePoses[i * 7]; // uint
|
|
1842
|
+
const bone = this._rawBones[rawBoneIndex];
|
|
1843
|
+
weight.addBone(bone);
|
|
1844
|
+
weightBoneIndices[i] = rawBoneIndex;
|
|
1845
|
+
this._intArray[weightOffset + 2 /* BinaryOffset.WeigthBoneIndices */ + i] =
|
|
1846
|
+
sortedBones.indexOf(bone);
|
|
1847
|
+
}
|
|
1848
|
+
this._floatArray.length += weightCount * 3;
|
|
1849
|
+
this._helpMatrixA.copyFromArray(rawSlotPose, 0);
|
|
1850
|
+
for (let i = 0, iW = 0, iB = weightOffset + 2 /* BinaryOffset.WeigthBoneIndices */ + weightBoneCount, iV = floatOffset; i < vertexCount; ++i) {
|
|
1851
|
+
const iD = i * 2;
|
|
1852
|
+
const vertexBoneCount = (this._intArray[iB++] = rawWeights[iW++]); // uint
|
|
1853
|
+
let x = this._floatArray[verticesOffset + iD];
|
|
1854
|
+
let y = this._floatArray[verticesOffset + iD + 1];
|
|
1855
|
+
this._helpMatrixA.transformPoint(x, y, this._helpPoint);
|
|
1856
|
+
x = this._helpPoint.x;
|
|
1857
|
+
y = this._helpPoint.y;
|
|
1858
|
+
for (let j = 0; j < vertexBoneCount; ++j) {
|
|
1859
|
+
const rawBoneIndex = rawWeights[iW++]; // uint
|
|
1860
|
+
const boneIndex = weightBoneIndices.indexOf(rawBoneIndex);
|
|
1861
|
+
this._helpMatrixB.copyFromArray(rawBonePoses, boneIndex * 7 + 1);
|
|
1862
|
+
this._helpMatrixB.invert();
|
|
1863
|
+
this._helpMatrixB.transformPoint(x, y, this._helpPoint);
|
|
1864
|
+
this._intArray[iB++] = boneIndex;
|
|
1865
|
+
this._floatArray[iV++] = rawWeights[iW++];
|
|
1866
|
+
this._floatArray[iV++] = this._helpPoint.x;
|
|
1867
|
+
this._floatArray[iV++] = this._helpPoint.y;
|
|
1868
|
+
}
|
|
1869
|
+
}
|
|
1870
|
+
}
|
|
1871
|
+
else {
|
|
1872
|
+
const rawBones = rawData[DataParser.BONES];
|
|
1873
|
+
weightBoneCount = rawBones.length;
|
|
1874
|
+
for (let i = 0; i < weightBoneCount; i++) {
|
|
1875
|
+
const rawBoneIndex = rawBones[i];
|
|
1876
|
+
const bone = this._rawBones[rawBoneIndex];
|
|
1877
|
+
weight.addBone(bone);
|
|
1878
|
+
this._intArray[weightOffset + 2 /* BinaryOffset.WeigthBoneIndices */ + i] =
|
|
1879
|
+
sortedBones.indexOf(bone);
|
|
1880
|
+
}
|
|
1881
|
+
this._floatArray.length += weightCount * 3;
|
|
1882
|
+
for (let i = 0, iW = 0, iV = 0, iB = weightOffset + 2 /* BinaryOffset.WeigthBoneIndices */ + weightBoneCount, iF = floatOffset; i < weightCount; i++) {
|
|
1883
|
+
const vertexBoneCount = rawWeights[iW++];
|
|
1884
|
+
this._intArray[iB++] = vertexBoneCount;
|
|
1885
|
+
for (let j = 0; j < vertexBoneCount; j++) {
|
|
1886
|
+
const boneIndex = rawWeights[iW++];
|
|
1887
|
+
const boneWeight = rawWeights[iW++];
|
|
1888
|
+
const x = rawVertices[iV++];
|
|
1889
|
+
const y = rawVertices[iV++];
|
|
1890
|
+
this._intArray[iB++] = rawBones.indexOf(boneIndex);
|
|
1891
|
+
this._floatArray[iF++] = boneWeight;
|
|
1892
|
+
this._floatArray[iF++] = x;
|
|
1893
|
+
this._floatArray[iF++] = y;
|
|
1894
|
+
}
|
|
1895
|
+
}
|
|
1896
|
+
}
|
|
1897
|
+
geometry.weight = weight;
|
|
1898
|
+
}
|
|
1899
|
+
}
|
|
1900
|
+
_parseArray(rawData) {
|
|
1901
|
+
// tslint:disable-next-line:no-unused-expression
|
|
1902
|
+
rawData;
|
|
1903
|
+
this._intArray.length = 0;
|
|
1904
|
+
this._floatArray.length = 0;
|
|
1905
|
+
this._frameIntArray.length = 0;
|
|
1906
|
+
this._frameFloatArray.length = 0;
|
|
1907
|
+
this._frameArray.length = 0;
|
|
1908
|
+
this._timelineArray.length = 0;
|
|
1909
|
+
this._colorArray.length = 0;
|
|
1910
|
+
}
|
|
1911
|
+
_modifyArray() {
|
|
1912
|
+
// Align.
|
|
1913
|
+
if (this._intArray.length % Int16Array.BYTES_PER_ELEMENT !== 0) {
|
|
1914
|
+
this._intArray.push(0);
|
|
1915
|
+
}
|
|
1916
|
+
if (this._frameIntArray.length % Int16Array.BYTES_PER_ELEMENT !== 0) {
|
|
1917
|
+
this._frameIntArray.push(0);
|
|
1918
|
+
}
|
|
1919
|
+
if (this._frameArray.length % Int16Array.BYTES_PER_ELEMENT !== 0) {
|
|
1920
|
+
this._frameArray.push(0);
|
|
1921
|
+
}
|
|
1922
|
+
if (this._timelineArray.length % Uint16Array.BYTES_PER_ELEMENT !== 0) {
|
|
1923
|
+
this._timelineArray.push(0);
|
|
1924
|
+
}
|
|
1925
|
+
if (this._timelineArray.length % Int16Array.BYTES_PER_ELEMENT !== 0) {
|
|
1926
|
+
this._colorArray.push(0);
|
|
1927
|
+
}
|
|
1928
|
+
const l1 = this._intArray.length * Int16Array.BYTES_PER_ELEMENT;
|
|
1929
|
+
const l2 = this._floatArray.length * Float32Array.BYTES_PER_ELEMENT;
|
|
1930
|
+
const l3 = this._frameIntArray.length * Int16Array.BYTES_PER_ELEMENT;
|
|
1931
|
+
const l4 = this._frameFloatArray.length * Float32Array.BYTES_PER_ELEMENT;
|
|
1932
|
+
const l5 = this._frameArray.length * Int16Array.BYTES_PER_ELEMENT;
|
|
1933
|
+
const l6 = this._timelineArray.length * Uint16Array.BYTES_PER_ELEMENT;
|
|
1934
|
+
const l7 = this._colorArray.length * Int16Array.BYTES_PER_ELEMENT;
|
|
1935
|
+
const lTotal = l1 + l2 + l3 + l4 + l5 + l6 + l7;
|
|
1936
|
+
//
|
|
1937
|
+
const binary = new ArrayBuffer(lTotal);
|
|
1938
|
+
const intArray = new Uint16Array(binary, 0, this._intArray.length);
|
|
1939
|
+
const floatArray = new Float32Array(binary, l1, this._floatArray.length);
|
|
1940
|
+
const frameIntArray = new Int16Array(binary, l1 + l2, this._frameIntArray.length);
|
|
1941
|
+
const frameFloatArray = new Float32Array(binary, l1 + l2 + l3, this._frameFloatArray.length);
|
|
1942
|
+
const frameArray = new Int16Array(binary, l1 + l2 + l3 + l4, this._frameArray.length);
|
|
1943
|
+
const timelineArray = new Uint16Array(binary, l1 + l2 + l3 + l4 + l5, this._timelineArray.length);
|
|
1944
|
+
const colorArray = new Uint16Array(binary, l1 + l2 + l3 + l4 + l5 + l6, this._colorArray.length);
|
|
1945
|
+
for (let i = 0, l = this._intArray.length; i < l; ++i) {
|
|
1946
|
+
intArray[i] = this._intArray[i];
|
|
1947
|
+
}
|
|
1948
|
+
for (let i = 0, l = this._floatArray.length; i < l; ++i) {
|
|
1949
|
+
floatArray[i] = this._floatArray[i];
|
|
1950
|
+
}
|
|
1951
|
+
for (let i = 0, l = this._frameIntArray.length; i < l; ++i) {
|
|
1952
|
+
frameIntArray[i] = this._frameIntArray[i];
|
|
1953
|
+
}
|
|
1954
|
+
for (let i = 0, l = this._frameFloatArray.length; i < l; ++i) {
|
|
1955
|
+
frameFloatArray[i] = this._frameFloatArray[i];
|
|
1956
|
+
}
|
|
1957
|
+
for (let i = 0, l = this._frameArray.length; i < l; ++i) {
|
|
1958
|
+
frameArray[i] = this._frameArray[i];
|
|
1959
|
+
}
|
|
1960
|
+
for (let i = 0, l = this._timelineArray.length; i < l; ++i) {
|
|
1961
|
+
timelineArray[i] = this._timelineArray[i];
|
|
1962
|
+
}
|
|
1963
|
+
for (let i = 0, l = this._colorArray.length; i < l; ++i) {
|
|
1964
|
+
colorArray[i] = this._colorArray[i];
|
|
1965
|
+
}
|
|
1966
|
+
this._data.binary = binary;
|
|
1967
|
+
this._data.intArray = intArray;
|
|
1968
|
+
this._data.floatArray = floatArray;
|
|
1969
|
+
this._data.frameIntArray = frameIntArray;
|
|
1970
|
+
this._data.frameFloatArray = frameFloatArray;
|
|
1971
|
+
this._data.frameArray = frameArray;
|
|
1972
|
+
this._data.timelineArray = timelineArray;
|
|
1973
|
+
this._data.colorArray = colorArray;
|
|
1974
|
+
this._defaultColorOffset = -1;
|
|
1975
|
+
}
|
|
1976
|
+
parseDragonBonesData(rawData, scale = 1) {
|
|
1977
|
+
console.assert(rawData !== null && rawData !== undefined, "Data error.");
|
|
1978
|
+
const version = ObjectDataParser._getString(rawData, DataParser.VERSION, "");
|
|
1979
|
+
const compatibleVersion = ObjectDataParser._getString(rawData, DataParser.COMPATIBLE_VERSION, "");
|
|
1980
|
+
if (DataParser.DATA_VERSIONS.indexOf(version) >= 0 ||
|
|
1981
|
+
DataParser.DATA_VERSIONS.indexOf(compatibleVersion) >= 0) {
|
|
1982
|
+
const data = BaseObject.borrowObject(DragonBonesData);
|
|
1983
|
+
data.version = version;
|
|
1984
|
+
data.name = ObjectDataParser._getString(rawData, DataParser.NAME, "");
|
|
1985
|
+
data.frameRate = ObjectDataParser._getNumber(rawData, DataParser.FRAME_RATE, 24);
|
|
1986
|
+
if (data.frameRate === 0) {
|
|
1987
|
+
// Data error.
|
|
1988
|
+
data.frameRate = 24;
|
|
1989
|
+
}
|
|
1990
|
+
if (DataParser.ARMATURE in rawData) {
|
|
1991
|
+
this._data = data;
|
|
1992
|
+
this._parseArray(rawData);
|
|
1993
|
+
const rawArmatures = rawData[DataParser.ARMATURE];
|
|
1994
|
+
for (const rawArmature of rawArmatures) {
|
|
1995
|
+
data.addArmature(this._parseArmature(rawArmature, scale));
|
|
1996
|
+
}
|
|
1997
|
+
if (!this._data.binary) {
|
|
1998
|
+
// DragonBones.webAssembly ? 0 : null;
|
|
1999
|
+
this._modifyArray();
|
|
2000
|
+
}
|
|
2001
|
+
if (DataParser.STAGE in rawData) {
|
|
2002
|
+
data.stage = data.getArmature(ObjectDataParser._getString(rawData, DataParser.STAGE, ""));
|
|
2003
|
+
}
|
|
2004
|
+
else if (data.armatureNames.length > 0) {
|
|
2005
|
+
data.stage = data.getArmature(data.armatureNames[0]);
|
|
2006
|
+
}
|
|
2007
|
+
this._data = null;
|
|
2008
|
+
}
|
|
2009
|
+
if (DataParser.TEXTURE_ATLAS in rawData) {
|
|
2010
|
+
this._rawTextureAtlases = rawData[DataParser.TEXTURE_ATLAS];
|
|
2011
|
+
}
|
|
2012
|
+
return data;
|
|
2013
|
+
}
|
|
2014
|
+
else {
|
|
2015
|
+
console.assert(false, "Nonsupport data version: " +
|
|
2016
|
+
version +
|
|
2017
|
+
"\n" +
|
|
2018
|
+
"Please convert DragonBones data to support version.\n" +
|
|
2019
|
+
"Read more: https://github.com/DragonBones/Tools/");
|
|
2020
|
+
}
|
|
2021
|
+
return null;
|
|
2022
|
+
}
|
|
2023
|
+
parseTextureAtlasData(rawData, textureAtlasData, scale = 1.0) {
|
|
2024
|
+
console.assert(rawData !== undefined);
|
|
2025
|
+
if (rawData === null) {
|
|
2026
|
+
if (this._rawTextureAtlases === null ||
|
|
2027
|
+
this._rawTextureAtlases.length === 0) {
|
|
2028
|
+
return false;
|
|
2029
|
+
}
|
|
2030
|
+
const rawTextureAtlas = this._rawTextureAtlases[this._rawTextureAtlasIndex++];
|
|
2031
|
+
this.parseTextureAtlasData(rawTextureAtlas, textureAtlasData, scale);
|
|
2032
|
+
if (this._rawTextureAtlasIndex >= this._rawTextureAtlases.length) {
|
|
2033
|
+
this._rawTextureAtlasIndex = 0;
|
|
2034
|
+
this._rawTextureAtlases = null;
|
|
2035
|
+
}
|
|
2036
|
+
return true;
|
|
2037
|
+
}
|
|
2038
|
+
// Texture format.
|
|
2039
|
+
textureAtlasData.width = ObjectDataParser._getNumber(rawData, DataParser.WIDTH, 0);
|
|
2040
|
+
textureAtlasData.height = ObjectDataParser._getNumber(rawData, DataParser.HEIGHT, 0);
|
|
2041
|
+
textureAtlasData.scale =
|
|
2042
|
+
scale === 1.0
|
|
2043
|
+
? 1.0 / ObjectDataParser._getNumber(rawData, DataParser.SCALE, 1.0)
|
|
2044
|
+
: scale;
|
|
2045
|
+
textureAtlasData.name = ObjectDataParser._getString(rawData, DataParser.NAME, "");
|
|
2046
|
+
textureAtlasData.imagePath = ObjectDataParser._getString(rawData, DataParser.IMAGE_PATH, "");
|
|
2047
|
+
if (DataParser.SUB_TEXTURE in rawData) {
|
|
2048
|
+
const rawTextures = rawData[DataParser.SUB_TEXTURE];
|
|
2049
|
+
for (let i = 0, l = rawTextures.length; i < l; ++i) {
|
|
2050
|
+
const rawTexture = rawTextures[i];
|
|
2051
|
+
const frameWidth = ObjectDataParser._getNumber(rawTexture, DataParser.FRAME_WIDTH, -1.0);
|
|
2052
|
+
const frameHeight = ObjectDataParser._getNumber(rawTexture, DataParser.FRAME_HEIGHT, -1.0);
|
|
2053
|
+
const textureData = textureAtlasData.createTexture();
|
|
2054
|
+
textureData.rotated = ObjectDataParser._getBoolean(rawTexture, DataParser.ROTATED, false);
|
|
2055
|
+
textureData.name = ObjectDataParser._getString(rawTexture, DataParser.NAME, "");
|
|
2056
|
+
textureData.region.x = ObjectDataParser._getNumber(rawTexture, DataParser.X, 0.0);
|
|
2057
|
+
textureData.region.y = ObjectDataParser._getNumber(rawTexture, DataParser.Y, 0.0);
|
|
2058
|
+
textureData.region.width = ObjectDataParser._getNumber(rawTexture, DataParser.WIDTH, 0.0);
|
|
2059
|
+
textureData.region.height = ObjectDataParser._getNumber(rawTexture, DataParser.HEIGHT, 0.0);
|
|
2060
|
+
if (frameWidth > 0.0 && frameHeight > 0.0) {
|
|
2061
|
+
textureData.frame = TextureData.createRectangle();
|
|
2062
|
+
textureData.frame.x = ObjectDataParser._getNumber(rawTexture, DataParser.FRAME_X, 0.0);
|
|
2063
|
+
textureData.frame.y = ObjectDataParser._getNumber(rawTexture, DataParser.FRAME_Y, 0.0);
|
|
2064
|
+
textureData.frame.width = frameWidth;
|
|
2065
|
+
textureData.frame.height = frameHeight;
|
|
2066
|
+
}
|
|
2067
|
+
textureAtlasData.addTexture(textureData);
|
|
2068
|
+
}
|
|
2069
|
+
}
|
|
2070
|
+
return true;
|
|
2071
|
+
}
|
|
2072
|
+
/**
|
|
2073
|
+
* - Deprecated, please refer to {@link dragonBones.BaseFactory#parseDragonBonesData()}.
|
|
2074
|
+
* @deprecated
|
|
2075
|
+
* @language en_US
|
|
2076
|
+
*/
|
|
2077
|
+
/**
|
|
2078
|
+
* - 已废弃,请参考 {@link dragonBones.BaseFactory#parseDragonBonesData()}。
|
|
2079
|
+
* @deprecated
|
|
2080
|
+
* @language zh_CN
|
|
2081
|
+
*/
|
|
2082
|
+
static getInstance() {
|
|
2083
|
+
if (ObjectDataParser._objectDataParserInstance === null) {
|
|
2084
|
+
ObjectDataParser._objectDataParserInstance = new ObjectDataParser();
|
|
2085
|
+
}
|
|
2086
|
+
return ObjectDataParser._objectDataParserInstance;
|
|
2087
|
+
}
|
|
2088
|
+
}
|
|
2089
|
+
ObjectDataParser._objectDataParserInstance = null;
|
|
2090
|
+
/**
|
|
2091
|
+
* @private
|
|
2092
|
+
*/
|
|
2093
|
+
export class ActionFrame {
|
|
2094
|
+
constructor() {
|
|
2095
|
+
this.frameStart = 0;
|
|
2096
|
+
this.actions = [];
|
|
2097
|
+
}
|
|
2098
|
+
}
|