1- import type { AnimationState , AnimationStateListener , AssetLoader , Bone , C3Matrix , C3RendererRuntime , Event , NumberArrayLike , RegionAttachment , Skeleton , Skin , Slot , TextureAtlas , } from "@esotericsoftware/spine-construct3-lib" ;
1+ import type { AnimationState , AnimationStateListener , AssetLoader , Bone , C3Matrix , C3RendererRuntime , Event , NumberArrayLike , RegionAttachment , Skeleton , Skin , Slot , SpineBoundsProvider , SpineBoundsProviderType , TextureAtlas , } from "@esotericsoftware/spine-construct3-lib" ;
22
33const C3 = globalThis . C3 ;
44const spine = globalThis . spine ;
@@ -17,9 +17,10 @@ class SpineC3Instance extends globalThis.ISDKWorldInstanceBase {
1717 propScaleX = 1 ;
1818 propScaleY = 1 ;
1919 propDebugSkeleton = false ;
20+ propBoundsProvider : SpineBoundsProviderType = "setup" ;
2021
2122 isFlippedX = false ;
22- isPlaying = false ;
23+ isPlaying = true ;
2324 animationSpeed = 1.0 ;
2425 physicsMode = spine . Physics . update ;
2526 customSkins : Record < string , Skin > = { } ;
@@ -43,6 +44,13 @@ class SpineC3Instance extends globalThis.ISDKWorldInstanceBase {
4344 private matrix : C3Matrix ;
4445 private requestRedraw = false ;
4546
47+ private spineBounds = {
48+ x : 0 ,
49+ y : 0 ,
50+ width : 200 ,
51+ height : 200 ,
52+ } ;
53+
4654 private verticesTemp = spine . Utils . newFloatArray ( 2 * 1024 ) ;
4755
4856 private boneFollowers = new Map < string , { uid : number , offsetX : number , offsetY : number , offsetAngle : number } > ( ) ;
@@ -71,7 +79,9 @@ class SpineC3Instance extends globalThis.ISDKWorldInstanceBase {
7179 this . propSkin = skinProp === "" ? [ ] : skinProp . split ( "," ) ;
7280 this . propAnimation = properties [ 4 ] as string ;
7381 this . propDebugSkeleton = properties [ 5 ] as boolean ;
74-
82+ const boundsProviderIndex = properties [ 6 ] as number ;
83+ this . propBoundsProvider = boundsProviderIndex === 0 ? "setup" : "animation-skin" ;
84+ // properties[7] is PROP_BOUNDS_PROVIDER_MOVE
7585 this . propOffsetX = properties [ 8 ] as number ;
7686 this . propOffsetY = properties [ 9 ] as number ;
7787 this . propOffsetAngle = properties [ 10 ] as number ;
@@ -115,7 +125,9 @@ class SpineC3Instance extends globalThis.ISDKWorldInstanceBase {
115125 this . matrix . update (
116126 this . x + this . propOffsetX ,
117127 this . y + this . propOffsetY ,
118- this . angle + this . propOffsetAngle ) ;
128+ this . angle + this . propOffsetAngle ,
129+ this . width / this . spineBounds . width * this . propScaleX * ( this . isFlippedX ? - 1 : 1 ) ,
130+ this . height / this . spineBounds . height * this . propScaleY ) ;
119131
120132 if ( this . isPlaying ) this . update ( this . dt ) ;
121133 }
@@ -266,8 +278,8 @@ class SpineC3Instance extends globalThis.ISDKWorldInstanceBase {
266278 pose . y = y ;
267279 } else {
268280 const { x, y } = matrix . gameToSkeleton ( touchX - handleObject . offsetX , touchY - handleObject . offsetY ) ;
269- pose . x = x / skeleton . scaleX ;
270- pose . y = - y / skeleton . scaleY * spine . Skeleton . yDir ;
281+ pose . x = x ;
282+ pose . y = - y * spine . Skeleton . yDir ;
271283 }
272284 } else if ( ! this . prevLeftClickDown ) {
273285 const applied = bone . applied ;
@@ -422,15 +434,36 @@ class SpineC3Instance extends globalThis.ISDKWorldInstanceBase {
422434
423435 this . _setSkin ( ) ;
424436
425- this . skeleton . scaleX = this . isFlippedX ? - this . propScaleX : this . propScaleX ;
426- this . skeleton . scaleY = this . propScaleY ;
437+ this . calculateBounds ( ) ;
427438
428439 this . update ( 0 ) ;
429440
430441 this . skeletonLoaded = true ;
431442 this . _trigger ( C3 . Plugins . EsotericSoftware_SpineConstruct3 . Cnds . OnSkeletonLoaded ) ;
432443 }
433444 }
445+
446+ private calculateBounds ( ) {
447+ const { skeleton } = this ;
448+ if ( ! skeleton ) return ;
449+
450+ let boundsProvider : SpineBoundsProvider ;
451+ console . log ( this . propBoundsProvider ) ;
452+ if ( this . propBoundsProvider === "animation-skin" ) {
453+ const { propSkin, propAnimation } = this ;
454+ if ( ( propSkin && propSkin . length > 0 ) || propAnimation ) {
455+ boundsProvider = new spine . SkinsAndAnimationBoundsProvider ( propAnimation , propSkin ) ;
456+ } else {
457+ boundsProvider = new spine . SetupPoseBoundsProvider ( ) ;
458+ }
459+ } else if ( this . propBoundsProvider === "setup" ) {
460+ boundsProvider = new spine . SetupPoseBoundsProvider ( ) ;
461+ } else {
462+ boundsProvider = new spine . AABBRectangleBoundsProvider ( 0 , 0 , 100 , 100 ) ;
463+ }
464+
465+ this . spineBounds = boundsProvider . calculateBounds ( this ) ;
466+ }
434467 /**********/
435468
436469 /*
@@ -742,7 +775,6 @@ class SpineC3Instance extends globalThis.ISDKWorldInstanceBase {
742775 const { x, y } = matrix . boneToGame ( bone ) ;
743776 const boneRotation = bone . applied . getWorldRotationX ( ) ;
744777
745- // Apply rotation to offset
746778 const rotationRadians = boneRotation * Math . PI / 180 ;
747779 const cos = Math . cos ( rotationRadians ) ;
748780 const sin = Math . sin ( rotationRadians ) ;
@@ -912,11 +944,6 @@ class SpineC3Instance extends globalThis.ISDKWorldInstanceBase {
912944
913945 public flipX ( isFlippedX : boolean ) {
914946 this . isFlippedX = isFlippedX ;
915-
916- const { skeleton } = this ;
917- if ( skeleton ) {
918- skeleton . scaleX = isFlippedX ? - this . propScaleX : this . propScaleX ;
919- }
920947 }
921948
922949 public setPhysicsMode ( mode : 0 | 1 | 2 | 3 ) {
0 commit comments