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/assets/phaser.png b/spine-ts/spine-phaser/example/assets/phaser.png new file mode 100644 index 000000000..c824db910 Binary files /dev/null and b/spine-ts/spine-phaser/example/assets/phaser.png differ diff --git a/spine-ts/spine-phaser/example/basic-example.html b/spine-ts/spine-phaser/example/basic-example.html index 0e3b7a75c..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 new file mode 100644 index 000000000..d78f80a9d --- /dev/null +++ b/spine-ts/spine-phaser/example/canvas-test.html @@ -0,0 +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 new file mode 100644 index 000000000..26def5e1b --- /dev/null +++ b/spine-ts/spine-phaser/example/depth-test.html @@ -0,0 +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 new file mode 100644 index 000000000..9eec599bb --- /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..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 new file mode 100644 index 000000000..ff33a6669 --- /dev/null +++ b/spine-ts/spine-phaser/example/render-to-texture-test.html @@ -0,0 +1,57 @@ + + + + + + + + + Spine Phaser Example + + + +

Render to texture

+ + + + \ No newline at end of file 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/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..b9952745b 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); } @@ -123,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-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 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; 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) {