27
27
* SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28
28
*****************************************************************************/
29
29
30
- import { BoneData , TransformMode } from "./BoneData.js" ;
30
+ import { BoneData , Inherit } from "./BoneData.js" ;
31
31
import { Physics , Skeleton } from "./Skeleton.js" ;
32
32
import { Updatable } from "./Updatable.js" ;
33
33
import { MathUtils , Vector2 } from "./Utils.js" ;
@@ -110,6 +110,8 @@ export class Bone implements Updatable {
110
110
/** The world Y position. If changed, {@link #updateAppliedTransform()} should be called. */
111
111
worldX = 0 ;
112
112
113
+ inherit : Inherit = Inherit . Normal ;
114
+
113
115
sorted = false ;
114
116
active = false ;
115
117
@@ -174,8 +176,8 @@ export class Bone implements Updatable {
174
176
this . worldX = pa * x + pb * y + parent . worldX ;
175
177
this . worldY = pc * x + pd * y + parent . worldY ;
176
178
177
- switch ( this . data . transformMode ) {
178
- case TransformMode . Normal : {
179
+ switch ( this . inherit ) {
180
+ case Inherit . Normal : {
179
181
const rx = ( rotation + shearX ) * MathUtils . degRad ;
180
182
const ry = ( rotation + 90 + shearY ) * MathUtils . degRad ;
181
183
const la = Math . cos ( rx ) * scaleX ;
@@ -188,7 +190,7 @@ export class Bone implements Updatable {
188
190
this . d = pc * lb + pd * ld ;
189
191
return ;
190
192
}
191
- case TransformMode . OnlyTranslation : {
193
+ case Inherit . OnlyTranslation : {
192
194
const rx = ( rotation + shearX ) * MathUtils . degRad ;
193
195
const ry = ( rotation + 90 + shearY ) * MathUtils . degRad ;
194
196
this . a = Math . cos ( rx ) * scaleX ;
@@ -197,7 +199,7 @@ export class Bone implements Updatable {
197
199
this . d = Math . sin ( ry ) * scaleY ;
198
200
break ;
199
201
}
200
- case TransformMode . NoRotationOrReflection : {
202
+ case Inherit . NoRotationOrReflection : {
201
203
let s = pa * pa + pc * pc ;
202
204
let prx = 0 ;
203
205
if ( s > 0.0001 ) {
@@ -224,8 +226,8 @@ export class Bone implements Updatable {
224
226
this . d = pc * lb + pd * ld ;
225
227
break ;
226
228
}
227
- case TransformMode . NoScale :
228
- case TransformMode . NoScaleOrReflection : {
229
+ case Inherit . NoScale :
230
+ case Inherit . NoScaleOrReflection : {
229
231
rotation *= MathUtils . degRad ;
230
232
const cos = Math . cos ( rotation ) , sin = Math . sin ( rotation ) ;
231
233
let za = ( pa * cos + pb * sin ) / this . skeleton . scaleX ;
@@ -235,7 +237,7 @@ export class Bone implements Updatable {
235
237
za *= s ;
236
238
zc *= s ;
237
239
s = Math . sqrt ( za * za + zc * zc ) ;
238
- if ( this . data . transformMode == TransformMode . NoScale
240
+ if ( this . inherit == Inherit . NoScale
239
241
&& ( pa * pd - pb * pc < 0 ) != ( this . skeleton . scaleX < 0 != this . skeleton . scaleY < 0 ) ) s = - s ;
240
242
rotation = Math . PI / 2 + Math . atan2 ( zc , za ) ;
241
243
const zb = Math . cos ( rotation ) * s ;
@@ -269,6 +271,7 @@ export class Bone implements Updatable {
269
271
this . scaleY = data . scaleY ;
270
272
this . shearX = data . shearX ;
271
273
this . shearY = data . shearY ;
274
+ this . inherit = data . inherit ;
272
275
}
273
276
274
277
/** Computes the applied transform values from the world transform.
@@ -299,14 +302,14 @@ export class Bone implements Updatable {
299
302
this . ay = ( dy * id - dx * ic ) ;
300
303
301
304
let ra , rb , rc , rd ;
302
- if ( this . data . transformMode == TransformMode . OnlyTranslation ) {
305
+ if ( this . inherit == Inherit . OnlyTranslation ) {
303
306
ra = this . a ;
304
307
rb = this . b ;
305
308
rc = this . c ;
306
309
rd = this . d ;
307
310
} else {
308
- switch ( this . data . transformMode ) {
309
- case TransformMode . NoRotationOrReflection : {
311
+ switch ( this . inherit ) {
312
+ case Inherit . NoRotationOrReflection : {
310
313
let s = Math . abs ( pa * pd - pb * pc ) / ( pa * pa + pc * pc ) ;
311
314
let sa = pa / this . skeleton . scaleX ;
312
315
let sc = pc / this . skeleton . scaleY ;
@@ -317,8 +320,8 @@ export class Bone implements Updatable {
317
320
ib = pb * pid ;
318
321
break ;
319
322
}
320
- case TransformMode . NoScale :
321
- case TransformMode . NoScaleOrReflection :
323
+ case Inherit . NoScale :
324
+ case Inherit . NoScaleOrReflection :
322
325
let cos = MathUtils . cosDeg ( this . rotation ) , sin = MathUtils . sinDeg ( this . rotation ) ;
323
326
pa = ( pa * cos + pb * sin ) / this . skeleton . scaleX ;
324
327
pc = ( pc * cos + pd * sin ) / this . skeleton . scaleY ;
@@ -327,7 +330,7 @@ export class Bone implements Updatable {
327
330
pa *= s ;
328
331
pc *= s ;
329
332
s = Math . sqrt ( pa * pa + pc * pc ) ;
330
- if ( this . data . transformMode == TransformMode . NoScale && pid < 0 != ( this . skeleton . scaleX < 0 != this . skeleton . scaleY < 0 ) ) s = - s ;
333
+ if ( this . inherit == Inherit . NoScale && pid < 0 != ( this . skeleton . scaleX < 0 != this . skeleton . scaleY < 0 ) ) s = - s ;
331
334
let r = MathUtils . PI / 2 + Math . atan2 ( pc , pa ) ;
332
335
pb = Math . cos ( r ) * s ;
333
336
pd = Math . sin ( r ) * s ;
0 commit comments