From fb3ebb56eba4ac8ccfb782f9e2103fa5eae4d1db Mon Sep 17 00:00:00 2001 From: Mario Zechner Date: Thu, 6 Apr 2023 15:41:54 +0200 Subject: [PATCH 1/3] [phaser] More tests, fix make factory, add Alpha mixin --- .../spine-phaser/example/assets/phaser.png | Bin 0 -> 5507 bytes .../spine-phaser/example/basic-example.html | 2 +- .../spine-phaser/example/canvas-test.html | 44 ++++++++ spine-ts/spine-phaser/example/depth-test.html | 48 ++++++++ .../example/extended-class-test.html | 103 ++++++++++++++++++ spine-ts/spine-phaser/example/index.html | 4 + .../example/render-to-texture-test.html | 58 ++++++++++ spine-ts/spine-phaser/src/SpineGameObject.ts | 7 +- spine-ts/spine-phaser/src/SpinePlugin.ts | 7 +- spine-ts/spine-phaser/src/mixins.ts | 3 + 10 files changed, 269 insertions(+), 7 deletions(-) create mode 100644 spine-ts/spine-phaser/example/assets/phaser.png create mode 100644 spine-ts/spine-phaser/example/canvas-test.html create mode 100644 spine-ts/spine-phaser/example/depth-test.html create mode 100644 spine-ts/spine-phaser/example/extended-class-test.html create mode 100644 spine-ts/spine-phaser/example/render-to-texture-test.html diff --git a/spine-ts/spine-phaser/example/assets/phaser.png b/spine-ts/spine-phaser/example/assets/phaser.png new file mode 100644 index 0000000000000000000000000000000000000000..c824db910e96a6c61776e49411722ac4ca999f3d GIT binary patch literal 5507 zcmV-}6@2Q6P)@B#>5nXm_={vokyQbbjCKem$>yW~E)oKPmL!ZTEEdyT12(zwdZYej+l- zPC|$=^H}ezJy)qzDv@cLTu-1sir1w*3{HceSJOgRrP_##EHknc|6Z_S#aXK>ggQGrX>f25?FOBGaD9!9jda2Zv#F`6nZn_a zte1t&f*%+dpk2FmQCC+N<|03!j{#+u0({duIyz|Hym{2x+9KQMvQ`}eeacZ^Umv~q z-g~rX&+ZNgW+~c#Nv|gu3{rc0JDqdRIr7SY=02-QQUb01j3=|CJu5li@$XC~3-AtM z97iY~k4xDEg8^B_s;ekL!Qb+49<#SStFDs$%#@2Ml}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Hr3S!DO|;+EFL4wsqc3C13sG45|$I9CpMl_MYAd*pW5gE z=n1oYpjRH*_}%7>wy-Ug$ZQ)A!TWRX&{r^y9(m?whcl*BeI+ec!(FTg^Z2Vsm%Y9I zMBdp`y;2G7%*9-)(4 zBNZs?9nMQNrg^-p#|@w~tjmLY;b|30M>{SwzF2`#IfyK5gpuL=xY#EG&#bK_M1G&! zyHG}N%A;mjMX>k9S=o!)>rHa+4)69Lv#Rq$W7dYOBe#4`Xo0FP2zxxZC?W!0JmI1N-!QBnxfYNR!~}*M$tn z7*tyu*RNUYS~faa0{b+SHJ#I%Jozlh2&ktXU^kp?i84;uDD5ADjajVJCr+4xOy{VG zI!2;gcgc{jM_XIN@@%xw90qwb1u`8O$yH@=F}9vz02TKC&n{_Dw>O4dIFqLqp(Zc; zvLlPLpvF!g(}?E82dIa_GY-4zDs(d6Pn=Q(igc{&k)1qS<(Ypup zU?0Op#0o^y@cg;A{+mvJ^lJeT)ubGDRb$~KX0$PO1HoN zJ}o};bZO(b1B4cnkZyDF2|u58sI07ROy{1@O>>;5d_LMLJf|@LBRXF`YFaAWW8Nbh zeBfQ00cNE--~(wX`>@h{7|L>kS|>T}RN^_d5v}A6S+GjKddc!H(Vh2iptoU6D?^&E zbrB!Mi+yz6veVQ*Rk{bp^xstgXgukY0%)RjPo&&9(s`)+KRx|gptI6vF=+r=hRgH( zPq#L`_&yDZ$&`==dD;700MLE&FR!9)uf51Wk07@JMA->PqW>SJ17iT?ZRCS=JaPIX z^3GzhAh$Q>==)=K8iJRp8Pko-Sk7WJP4l=2Kf{UlHeuJ?irb&nH%y`}f7(SmdW&)+ zTS0^O%T8_e(UptmP-0jflzSEobm?b-fsUu~rC;-o%Fy5dy|8sN&2A1mdz$i}XYoHg z429{EE1V + + + + + + + + Spine Phaser Example + + +

Canvas test

+ + + \ No newline at end of file diff --git a/spine-ts/spine-phaser/example/depth-test.html b/spine-ts/spine-phaser/example/depth-test.html new file mode 100644 index 000000000..4182b26b1 --- /dev/null +++ b/spine-ts/spine-phaser/example/depth-test.html @@ -0,0 +1,48 @@ + + + + + + + + + Spine Phaser Example + + +

Depth test

+ + + \ No newline at end of file diff --git a/spine-ts/spine-phaser/example/extended-class-test.html b/spine-ts/spine-phaser/example/extended-class-test.html new file mode 100644 index 000000000..8760d5ba2 --- /dev/null +++ b/spine-ts/spine-phaser/example/extended-class-test.html @@ -0,0 +1,103 @@ + + + + + + + + + + Spine Phaser Example + + + +

Extended class

+ + + + \ No newline at end of file diff --git a/spine-ts/spine-phaser/example/index.html b/spine-ts/spine-phaser/example/index.html index 99bbf7a67..72d76b56f 100644 --- a/spine-ts/spine-phaser/example/index.html +++ b/spine-ts/spine-phaser/example/index.html @@ -19,6 +19,10 @@
  • Blend test
  • Camera pipeline test
  • Control bones
  • +
  • Extended class
  • +
  • Canvas test
  • +
  • Depth test
  • +
  • Render to texture test
  • \ No newline at end of file diff --git a/spine-ts/spine-phaser/example/render-to-texture-test.html b/spine-ts/spine-phaser/example/render-to-texture-test.html new file mode 100644 index 000000000..64d331142 --- /dev/null +++ b/spine-ts/spine-phaser/example/render-to-texture-test.html @@ -0,0 +1,58 @@ + + + + + + + + + + Spine Phaser Example + + + +

    Render to texture

    + + + + \ No newline at end of file diff --git a/spine-ts/spine-phaser/src/SpineGameObject.ts b/spine-ts/spine-phaser/src/SpineGameObject.ts index d034922b1..32c60949e 100644 --- a/spine-ts/spine-phaser/src/SpineGameObject.ts +++ b/spine-ts/spine-phaser/src/SpineGameObject.ts @@ -1,8 +1,7 @@ import { SPINE_GAME_OBJECT_TYPE } from "./keys"; import { SpinePlugin } from "./SpinePlugin"; -import { ComputedSizeMixin, DepthMixin, FlipMixin, ScrollFactorMixin, TransformMixin, VisibleMixin } from "./mixins"; +import { ComputedSizeMixin, DepthMixin, FlipMixin, ScrollFactorMixin, TransformMixin, VisibleMixin, AlphaMixin } from "./mixins"; import { AnimationState, AnimationStateData, Bone, MathUtils, Skeleton, Skin, Vector2 } from "@esotericsoftware/spine-core"; -import { Vector3 } from "@esotericsoftware/spine-webgl"; class BaseSpineGameObject extends Phaser.GameObjects.GameObject { constructor (scene: Phaser.Scene, type: string) { @@ -76,7 +75,7 @@ export class SkinsAndAnimationBoundsProvider implements SpineGameObjectBoundsPro } } -export class SpineGameObject extends ComputedSizeMixin(DepthMixin(FlipMixin(ScrollFactorMixin(TransformMixin(VisibleMixin(BaseSpineGameObject)))))) { +export class SpineGameObject extends ComputedSizeMixin(DepthMixin(FlipMixin(ScrollFactorMixin(TransformMixin(VisibleMixin(AlphaMixin(BaseSpineGameObject))))))) { blendMode = -1; skeleton: Skeleton | null = null; animationStateData: AnimationStateData | null = null; @@ -89,7 +88,7 @@ export class SpineGameObject extends ComputedSizeMixin(DepthMixin(FlipMixin(Scro constructor (scene: Phaser.Scene, private plugin: SpinePlugin, x: number, y: number, dataKey: string, atlasKey: string, public boundsProvider: SpineGameObjectBoundsProvider = new SetupPoseBoundsProvider()) { super(scene, SPINE_GAME_OBJECT_TYPE); - this.setPosition(x, y); x + this.setPosition(x, y); this.setSkeleton(dataKey, atlasKey); } diff --git a/spine-ts/spine-phaser/src/SpinePlugin.ts b/spine-ts/spine-phaser/src/SpinePlugin.ts index e9520d7eb..49d96770a 100644 --- a/spine-ts/spine-phaser/src/SpinePlugin.ts +++ b/spine-ts/spine-phaser/src/SpinePlugin.ts @@ -106,13 +106,16 @@ export class SpinePlugin extends Phaser.Plugins.ScenePlugin { }; let makeSpineGameObject = function (this: Phaser.GameObjects.GameObjectFactory, config: any, addToScene: boolean) { + let x = config.x ? config.x : 0; + let y = config.y ? config.y : 0; let dataKey = config.dataKey ? config.dataKey : null; let atlasKey = config.atlasKey ? config.atlasKey : null; - let gameObject = new SpineGameObject(this.scene, self, 0, 0, dataKey, atlasKey); + let boundsProvider = config.boundsProvider ? config.boundsProvider : undefined; + let gameObject = new SpineGameObject(this.scene, self, x, y, dataKey, atlasKey, boundsProvider); if (addToScene !== undefined) { config.add = addToScene; } - Phaser.GameObjects.BuildGameObject(this.scene, gameObject, config); + return Phaser.GameObjects.BuildGameObject(this.scene, gameObject, config); } pluginManager.registerGameObject(SPINE_GAME_OBJECT_TYPE, addSpineGameObject, makeSpineGameObject); } diff --git a/spine-ts/spine-phaser/src/mixins.ts b/spine-ts/spine-phaser/src/mixins.ts index 63ab0810d..f4995daad 100644 --- a/spine-ts/spine-phaser/src/mixins.ts +++ b/spine-ts/spine-phaser/src/mixins.ts @@ -31,6 +31,7 @@ export const Flip = components.Flip; export const ScrollFactor = components.ScrollFactor; export const Transform = components.Transform; export const Visible = components.Visible; +export const Alpha = components.Alpha; export interface Type< T, @@ -75,3 +76,5 @@ export const TransformMixin: TransformMixin = createMixin; export const VisibleMixin: VisibleMixin = createMixin(Visible); +type AlphaMixin = Mixin; +export const AlphaMixin: AlphaMixin = createMixin(Alpha); \ No newline at end of file From 476fb151dd91ad751804f147aacc8e50465436c6 Mon Sep 17 00:00:00 2001 From: Harald Csaszar Date: Fri, 7 Apr 2023 15:32:42 +0200 Subject: [PATCH 2/3] [unity] Fixed skeleton baking when AttachmentTimeline only contains a single frame. Closes #2272. --- .../Editor/Windows/SkeletonBaker.cs | 80 +++++++++---------- 1 file changed, 37 insertions(+), 43 deletions(-) diff --git a/spine-unity/Assets/Spine/Editor/spine-unity/Editor/Windows/SkeletonBaker.cs b/spine-unity/Assets/Spine/Editor/spine-unity/Editor/Windows/SkeletonBaker.cs index 951bc35c2..d0073137e 100644 --- a/spine-unity/Assets/Spine/Editor/spine-unity/Editor/Windows/SkeletonBaker.cs +++ b/spine-unity/Assets/Spine/Editor/spine-unity/Editor/Windows/SkeletonBaker.cs @@ -848,7 +848,7 @@ namespace Spine.Unity.Editor { keys.Add(new Keyframe(0, rotation, 0, 0)); - int listIndex = 1; + int listIndex = 0; float r = rotation; @@ -865,7 +865,7 @@ namespace Spine.Unity.Editor { animation.Apply(skeleton, 0, currentTime, true, null, 1f, MixBlend.Setup, MixDirection.In); skeleton.UpdateWorldTransform(); - int pIndex = listIndex - 1; + int pIndex = listIndex; Keyframe pk = keys[pIndex]; @@ -919,16 +919,16 @@ namespace Spine.Unity.Editor { xKeys.Add(new Keyframe(timeline.Frames[0], timeline.Frames[1] + boneData.X, 0, 0)); yKeys.Add(new Keyframe(timeline.Frames[0], timeline.Frames[2] + boneData.Y, 0, 0)); - int listIndex = 1; - int frameIndex = 1; + int listIndex = 0; + int frameIndex = 0; int f = TranslateTimeline.ENTRIES; float[] frames = timeline.Frames; skeleton.SetToSetupPose(); float lastTime = 0; while (currentTime < endTime) { - int pIndex = listIndex - 1; + int pIndex = listIndex; - float curveType = timeline.GetCurveType(frameIndex - 1); + float curveType = timeline.GetCurveType(frameIndex); if (curveType == 0) { //linear Keyframe px = xKeys[pIndex]; @@ -999,8 +999,8 @@ namespace Spine.Unity.Editor { timeline.Apply(skeleton, lastTime, currentTime, null, 1, MixBlend.Setup, MixDirection.In); - px = xKeys[listIndex - 1]; - py = yKeys[listIndex - 1]; + px = xKeys[listIndex]; + py = yKeys[listIndex]; float xOut = (bone.X - px.value) / (currentTime - px.time); float yOut = (bone.Y - py.value) / (currentTime - py.time); @@ -1011,8 +1011,8 @@ namespace Spine.Unity.Editor { xKeys.Add(new Keyframe(currentTime, bone.X, xOut, 0)); yKeys.Add(new Keyframe(currentTime, bone.Y, yOut, 0)); - xKeys[listIndex - 1] = px; - yKeys[listIndex - 1] = py; + xKeys[listIndex] = px; + yKeys[listIndex] = py; listIndex++; lastTime = currentTime; @@ -1055,16 +1055,16 @@ namespace Spine.Unity.Editor { List keys = new List(); keys.Add(new Keyframe(timeline.Frames[0], timeline.Frames[1] + boneDataOffset, 0, 0)); - int listIndex = 1; - int frameIndex = 1; + int listIndex = 0; + int frameIndex = 0; int f = TranslateXTimeline.ENTRIES; float[] frames = timeline.Frames; skeleton.SetToSetupPose(); float lastTime = 0; while (currentTime < endTime) { - int pIndex = listIndex - 1; + int pIndex = listIndex; - float curveType = timeline.GetCurveType(frameIndex - 1); + float curveType = timeline.GetCurveType(frameIndex); if (curveType == 0) { //linear Keyframe p = keys[pIndex]; @@ -1112,13 +1112,13 @@ namespace Spine.Unity.Editor { timeline.Apply(skeleton, lastTime, currentTime, null, 1, MixBlend.Setup, MixDirection.In); - p = keys[listIndex - 1]; + p = keys[listIndex]; float boneOffset = isXTimeline ? bone.X : bone.Y; float valueOut = (boneOffset - p.value) / (currentTime - p.time); p.outTangent = valueOut; keys.Add(new Keyframe(currentTime, boneOffset, valueOut, 0)); - keys[listIndex - 1] = p; + keys[listIndex] = p; listIndex++; lastTime = currentTime; @@ -1155,15 +1155,15 @@ namespace Spine.Unity.Editor { xKeys.Add(new Keyframe(timeline.Frames[0], timeline.Frames[1] * boneData.ScaleX, 0, 0)); yKeys.Add(new Keyframe(timeline.Frames[0], timeline.Frames[2] * boneData.ScaleY, 0, 0)); - int listIndex = 1; - int frameIndex = 1; + int listIndex = 0; + int frameIndex = 0; int f = ScaleTimeline.ENTRIES; float[] frames = timeline.Frames; skeleton.SetToSetupPose(); float lastTime = 0; while (currentTime < endTime) { - int pIndex = listIndex - 1; - float curveType = timeline.GetCurveType(frameIndex - 1); + int pIndex = listIndex; + float curveType = timeline.GetCurveType(frameIndex); if (curveType == 0) { //linear Keyframe px = xKeys[pIndex]; @@ -1234,8 +1234,8 @@ namespace Spine.Unity.Editor { timeline.Apply(skeleton, lastTime, currentTime, null, 1, MixBlend.Setup, MixDirection.In); - px = xKeys[listIndex - 1]; - py = yKeys[listIndex - 1]; + px = xKeys[listIndex]; + py = yKeys[listIndex]; float xOut = (bone.ScaleX - px.value) / (currentTime - px.time); float yOut = (bone.ScaleY - py.value) / (currentTime - py.time); @@ -1246,8 +1246,8 @@ namespace Spine.Unity.Editor { xKeys.Add(new Keyframe(currentTime, bone.ScaleX, xOut, 0)); yKeys.Add(new Keyframe(currentTime, bone.ScaleY, yOut, 0)); - xKeys[listIndex - 1] = px; - yKeys[listIndex - 1] = py; + xKeys[listIndex] = px; + yKeys[listIndex] = py; listIndex++; lastTime = currentTime; @@ -1286,15 +1286,15 @@ namespace Spine.Unity.Editor { List keys = new List(); keys.Add(new Keyframe(timeline.Frames[0], timeline.Frames[1] * boneDataOffset, 0, 0)); - int listIndex = 1; - int frameIndex = 1; + int listIndex = 0; + int frameIndex = 0; int f = ScaleXTimeline.ENTRIES; float[] frames = timeline.Frames; skeleton.SetToSetupPose(); float lastTime = 0; while (currentTime < endTime) { - int pIndex = listIndex - 1; - float curveType = timeline.GetCurveType(frameIndex - 1); + int pIndex = listIndex; + float curveType = timeline.GetCurveType(frameIndex); if (curveType == 0) { //linear Keyframe p = keys[pIndex]; @@ -1340,14 +1340,14 @@ namespace Spine.Unity.Editor { timeline.Apply(skeleton, lastTime, currentTime, null, 1, MixBlend.Setup, MixDirection.In); - p = keys[listIndex - 1]; + p = keys[listIndex]; float boneScale = isXTimeline ? bone.ScaleX : bone.ScaleY; float valueOut = (boneScale - p.value) / (currentTime - p.time); p.outTangent = valueOut; keys.Add(new Keyframe(currentTime, boneScale, valueOut, 0)); - keys[listIndex - 1] = p; + keys[listIndex] = p; listIndex++; lastTime = currentTime; @@ -1382,16 +1382,16 @@ namespace Spine.Unity.Editor { keys.Add(new Keyframe(timeline.Frames[0], rotation, 0, 0)); - int listIndex = 1; - int frameIndex = 1; + int listIndex = 0; + int frameIndex = 0; int f = 2; float[] frames = timeline.Frames; skeleton.SetToSetupPose(); float lastTime = 0; float angle = rotation; while (currentTime < endTime) { - int pIndex = listIndex - 1; - float curveType = timeline.GetCurveType(frameIndex - 1); + int pIndex = listIndex; + float curveType = timeline.GetCurveType(frameIndex); if (curveType == 0) { //linear @@ -1464,7 +1464,7 @@ namespace Spine.Unity.Editor { timeline.Apply(skeleton, lastTime, currentTime, null, 1, MixBlend.Setup, MixDirection.In); skeleton.UpdateWorldTransform(); - pk = keys[listIndex - 1]; + pk = keys[listIndex]; rotation = bone.Rotation; angle += Mathf.DeltaAngle(angle, rotation); @@ -1476,7 +1476,7 @@ namespace Spine.Unity.Editor { keys.Add(new Keyframe(currentTime, r, rOut, 0)); - keys[listIndex - 1] = pk; + keys[listIndex] = pk; listIndex++; lastTime = currentTime; @@ -1582,10 +1582,7 @@ namespace Spine.Unity.Editor { } } - float currentTime = timeline.Frames[0]; - float endTime = frames[frames.Length - 1]; - int f = 0; - while (currentTime < endTime) { + for (int f = 0, frameCount = frames.Length; f < frameCount; ++f) { float time = frames[f]; int frameIndex = Search(frames, time); @@ -1602,9 +1599,6 @@ namespace Spine.Unity.Editor { } } } - - currentTime = time; - f += 1; } foreach (KeyValuePair pair in curveTable) { From 14219fa60952003ba68f457bf969c7aa12c1ff0a Mon Sep 17 00:00:00 2001 From: Mario Zechner Date: Wed, 12 Apr 2023 15:13:25 +0200 Subject: [PATCH 3/3] [phaser] Fix pack file plugin loading, clipping, demos. --- .../example/arcade-physics-test.html | 80 ++++++------- .../spine-phaser/example/basic-example.html | 56 ++++----- .../spine-phaser/example/batching-test.html | 94 ++++++++-------- spine-ts/spine-phaser/example/blend-test.html | 106 +++++++++--------- .../spine-phaser/example/bounds-test.html | 78 ++++++------- .../example/camera-pipeline-test.html | 11 +- .../spine-phaser/example/canvas-test.html | 56 ++++----- .../example/control-bones-test.html | 97 ++++++++-------- spine-ts/spine-phaser/example/depth-test.html | 64 ++++++----- .../example/extended-class-test.html | 4 +- spine-ts/spine-phaser/example/index.html | 3 + .../example/multi-scene-test.html | 93 +++++++-------- .../example/render-to-texture-test.html | 11 +- .../spine-phaser/example/visibility-test.html | 63 ++++++----- spine-ts/spine-phaser/src/SpinePlugin.ts | 1 + spine-ts/spine-phaser/src/index.ts | 1 + spine-ts/spine-webgl/src/SkeletonRenderer.ts | 2 +- 17 files changed, 422 insertions(+), 398 deletions(-) diff --git a/spine-ts/spine-phaser/example/arcade-physics-test.html b/spine-ts/spine-phaser/example/arcade-physics-test.html index bb585db0f..b15bb72fc 100644 --- a/spine-ts/spine-phaser/example/arcade-physics-test.html +++ b/spine-ts/spine-phaser/example/arcade-physics-test.html @@ -1,59 +1,61 @@ + - Spine Phaser Example +

    Arcade Physics example

    + \ No newline at end of file diff --git a/spine-ts/spine-phaser/example/basic-example.html b/spine-ts/spine-phaser/example/basic-example.html index dc7f667d2..8dd86d943 100644 --- a/spine-ts/spine-phaser/example/basic-example.html +++ b/spine-ts/spine-phaser/example/basic-example.html @@ -1,44 +1,46 @@ + - Spine Phaser Example +

    Basic example

    + \ No newline at end of file diff --git a/spine-ts/spine-phaser/example/batching-test.html b/spine-ts/spine-phaser/example/batching-test.html index 8626d4cd6..488124a57 100644 --- a/spine-ts/spine-phaser/example/batching-test.html +++ b/spine-ts/spine-phaser/example/batching-test.html @@ -1,63 +1,65 @@ + - Spine Phaser Example +

    Batching test

    + \ No newline at end of file diff --git a/spine-ts/spine-phaser/example/blend-test.html b/spine-ts/spine-phaser/example/blend-test.html index 903b8e950..e1f8b4237 100644 --- a/spine-ts/spine-phaser/example/blend-test.html +++ b/spine-ts/spine-phaser/example/blend-test.html @@ -1,70 +1,72 @@ + - Spine Phaser Example +

    Blend test

    + \ No newline at end of file diff --git a/spine-ts/spine-phaser/example/bounds-test.html b/spine-ts/spine-phaser/example/bounds-test.html index 9989adab0..7238a3743 100644 --- a/spine-ts/spine-phaser/example/bounds-test.html +++ b/spine-ts/spine-phaser/example/bounds-test.html @@ -1,56 +1,58 @@ + - Spine Phaser Example +

    Bounds test

    + \ No newline at end of file diff --git a/spine-ts/spine-phaser/example/camera-pipeline-test.html b/spine-ts/spine-phaser/example/camera-pipeline-test.html index c2fc4cb4a..60b0243d4 100644 --- a/spine-ts/spine-phaser/example/camera-pipeline-test.html +++ b/spine-ts/spine-phaser/example/camera-pipeline-test.html @@ -6,7 +6,6 @@ - Spine Phaser Example @@ -22,11 +21,11 @@ scene: { preload: preload, create: create, - }, - plugins: { - scene: [ - { key: "spine.SpinePlugin", plugin: spine.SpinePlugin, mapping: "spine" } - ] + pack: { + files: [ + { type: "scenePlugin", key: "spine.SpinePlugin", url: "../dist/iife/spine-phaser.js", sceneKey: "spine" } + ] + } } }; diff --git a/spine-ts/spine-phaser/example/canvas-test.html b/spine-ts/spine-phaser/example/canvas-test.html index 93be12b27..d78f80a9d 100644 --- a/spine-ts/spine-phaser/example/canvas-test.html +++ b/spine-ts/spine-phaser/example/canvas-test.html @@ -1,44 +1,46 @@ + - Spine Phaser Example +

    Canvas test

    + \ No newline at end of file diff --git a/spine-ts/spine-phaser/example/control-bones-test.html b/spine-ts/spine-phaser/example/control-bones-test.html index 2b9682873..6b935964b 100644 --- a/spine-ts/spine-phaser/example/control-bones-test.html +++ b/spine-ts/spine-phaser/example/control-bones-test.html @@ -1,71 +1,72 @@ + - Spine Phaser Example +

    Control bones

    - + }, this); + } + } + + \ No newline at end of file diff --git a/spine-ts/spine-phaser/example/depth-test.html b/spine-ts/spine-phaser/example/depth-test.html index 4182b26b1..26def5e1b 100644 --- a/spine-ts/spine-phaser/example/depth-test.html +++ b/spine-ts/spine-phaser/example/depth-test.html @@ -1,48 +1,50 @@ + - Spine Phaser Example +

    Depth test

    + \ No newline at end of file diff --git a/spine-ts/spine-phaser/example/extended-class-test.html b/spine-ts/spine-phaser/example/extended-class-test.html index 8760d5ba2..9eec599bb 100644 --- a/spine-ts/spine-phaser/example/extended-class-test.html +++ b/spine-ts/spine-phaser/example/extended-class-test.html @@ -51,10 +51,10 @@ this.scene = scene; this.parent = scene.add.container(0, 0); - this.spine = scene.make.spine({ scene, x, y, dataKey, atlasKey}); + this.spine = scene.make.spine({ scene, x, y, dataKey, atlasKey }); this.spine.animationState.setAnimation(0, animation, loop); this.parent.add(this.spine); - } + } } class Example extends Phaser.Scene { diff --git a/spine-ts/spine-phaser/example/index.html b/spine-ts/spine-phaser/example/index.html index 72d76b56f..cf7041918 100644 --- a/spine-ts/spine-phaser/example/index.html +++ b/spine-ts/spine-phaser/example/index.html @@ -1,5 +1,6 @@ + @@ -7,6 +8,7 @@ Spine Phaser Example +

    Spine Phaser

    + \ No newline at end of file diff --git a/spine-ts/spine-phaser/example/multi-scene-test.html b/spine-ts/spine-phaser/example/multi-scene-test.html index 7c1f74c13..4a574d7a6 100644 --- a/spine-ts/spine-phaser/example/multi-scene-test.html +++ b/spine-ts/spine-phaser/example/multi-scene-test.html @@ -1,5 +1,6 @@ + @@ -8,58 +9,60 @@ Spine Phaser Example +

    Multi-scene test

    + \ No newline at end of file diff --git a/spine-ts/spine-phaser/example/render-to-texture-test.html b/spine-ts/spine-phaser/example/render-to-texture-test.html index 64d331142..ff33a6669 100644 --- a/spine-ts/spine-phaser/example/render-to-texture-test.html +++ b/spine-ts/spine-phaser/example/render-to-texture-test.html @@ -6,7 +6,6 @@ - Spine Phaser Example @@ -22,11 +21,11 @@ scene: { preload: preload, create: create, - }, - plugins: { - scene: [ - { key: "spine.SpinePlugin", plugin: spine.SpinePlugin, mapping: "spine" } - ] + pack: { + files: [ + { type: "scenePlugin", key: "spine.SpinePlugin", url: "../dist/iife/spine-phaser.js", sceneKey: "spine" } + ] + } } }; diff --git a/spine-ts/spine-phaser/example/visibility-test.html b/spine-ts/spine-phaser/example/visibility-test.html index 463b3bd3b..61ce8a3c0 100644 --- a/spine-ts/spine-phaser/example/visibility-test.html +++ b/spine-ts/spine-phaser/example/visibility-test.html @@ -1,5 +1,6 @@ + @@ -8,43 +9,45 @@ Spine Phaser Example +

    Basic example

    + \ No newline at end of file diff --git a/spine-ts/spine-phaser/src/SpinePlugin.ts b/spine-ts/spine-phaser/src/SpinePlugin.ts index 49d96770a..b9952745b 100644 --- a/spine-ts/spine-phaser/src/SpinePlugin.ts +++ b/spine-ts/spine-phaser/src/SpinePlugin.ts @@ -126,6 +126,7 @@ export class SpinePlugin extends Phaser.Plugins.ScenePlugin { if (!this.webGLRenderer) { this.webGLRenderer = new SceneRenderer((this.phaserRenderer! as Phaser.Renderer.WebGL.WebGLRenderer).canvas, this.gl!, true); } + this.onResize(); this.game.scale.on(Phaser.Scale.Events.RESIZE, this.onResize, this); } else { if (!this.canvasRenderer) { diff --git a/spine-ts/spine-phaser/src/index.ts b/spine-ts/spine-phaser/src/index.ts index e5d94836e..be6555a71 100644 --- a/spine-ts/spine-phaser/src/index.ts +++ b/spine-ts/spine-phaser/src/index.ts @@ -6,3 +6,4 @@ export * from "@esotericsoftware/spine-core"; export * from "@esotericsoftware/spine-webgl"; import { SpinePlugin } from "./SpinePlugin"; (window as any).spine = { SpinePlugin: SpinePlugin }; +(window as any)["spine.SpinePlugin"] = SpinePlugin; diff --git a/spine-ts/spine-webgl/src/SkeletonRenderer.ts b/spine-ts/spine-webgl/src/SkeletonRenderer.ts index 2a557b9ba..eeb0ea02c 100644 --- a/spine-ts/spine-webgl/src/SkeletonRenderer.ts +++ b/spine-ts/spine-webgl/src/SkeletonRenderer.ts @@ -176,7 +176,7 @@ export class SkeletonRenderer { clipper.clipTriangles(renderable.vertices, renderable.numFloats, triangles, triangles.length, uvs, finalColor, darkColor, twoColorTint); let clippedVertices = new Float32Array(clipper.clippedVertices); let clippedTriangles = clipper.clippedTriangles; - if (transformer) transformer(renderable.vertices, renderable.numFloats, vertexSize); + if (transformer) transformer(clippedVertices, clippedVertices.length, vertexSize); batcher.draw(texture, clippedVertices, clippedTriangles); } else { let verts = renderable.vertices;