Merge branch '4.1' into 4.2-beta

This commit is contained in:
Mario Zechner 2023-01-16 14:00:14 +01:00
commit 1891d00025
10 changed files with 54 additions and 34 deletions

View File

@ -11,7 +11,7 @@ jobs:
- name: Install OS dependencies (needed for act on ubuntu-latest) - name: Install OS dependencies (needed for act on ubuntu-latest)
run: | run: |
sudo apt update sudo apt update
sudo apt install -y --force-yes curl xz-utils libicu-dev git dos2unix sudo apt install -y --force-yes curl xz-utils libicu-dev git dos2unix libncurses5
- uses: actions/checkout@v1 - uses: actions/checkout@v1

View File

@ -286,7 +286,7 @@ float *spPathConstraint_computeWorldPositions(spPathConstraint *self, spPathAtta
float *lengths = path->lengths; float *lengths = path->lengths;
curveCount -= closed ? 1 : 2; curveCount -= closed ? 1 : 2;
pathLength = lengths[curveCount]; pathLength = lengths[curveCount];
if (self->data->positionMode == SP_POSITION_MODE_PERCENT) position += pathLength; if (self->data->positionMode == SP_POSITION_MODE_PERCENT) position *= pathLength;
switch (self->data->spacingMode) { switch (self->data->spacingMode) {
case SP_SPACING_MODE_PERCENT: case SP_SPACING_MODE_PERCENT:
multiplier = pathLength; multiplier = pathLength;

View File

@ -106,7 +106,8 @@ static void toColor2(spColor *color, const char *value, int /*bool*/ hasAlpha) {
color->g = toColor(value, 1); color->g = toColor(value, 1);
color->b = toColor(value, 2); color->b = toColor(value, 2);
if (hasAlpha) color->a = toColor(value, 3); if (hasAlpha) color->a = toColor(value, 3);
else color->a =1.0f; else
color->a = 1.0f;
} }
static void static void

View File

@ -2,7 +2,7 @@ group = "com.esotericsoftware.spine"
version = "4.1.0" version = "4.1.0"
ext { ext {
libgdxVersion = "1.10.1-SNAPSHOT" libgdxVersion = "1.11.1-SNAPSHOT"
javaVersion = 8 javaVersion = 8
} }

View File

@ -83,13 +83,13 @@ export class Skeleton {
/** Scales the entire skeleton on the Y axis. This affects all bones, even if the bone's transform mode disallows scale /** Scales the entire skeleton on the Y axis. This affects all bones, even if the bone's transform mode disallows scale
* inheritance. */ * inheritance. */
private _scaleY = 1; private _scaleY = 1;
public get scaleY() { public get scaleY () {
return Skeleton.yDown ? -this._scaleY : this._scaleY; return Skeleton.yDown ? -this._scaleY : this._scaleY;
} }
public set scaleY(scaleY: number) { public set scaleY (scaleY: number) {
this._scaleY = scaleY; this._scaleY = scaleY;
} }

View File

@ -5,17 +5,17 @@ import { AnimationState, AnimationStateData, Bone, MathUtils, Skeleton, Skin, Ve
import { Vector3 } from "@esotericsoftware/spine-webgl"; import { Vector3 } from "@esotericsoftware/spine-webgl";
class BaseSpineGameObject extends Phaser.GameObjects.GameObject { class BaseSpineGameObject extends Phaser.GameObjects.GameObject {
constructor(scene: Phaser.Scene, type: string) { constructor (scene: Phaser.Scene, type: string) {
super(scene, type); super(scene, type);
} }
} }
export interface SpineGameObjectBoundsProvider { export interface SpineGameObjectBoundsProvider {
calculateBounds(gameObject: SpineGameObject): { x: number, y: number, width: number, height: number }; calculateBounds (gameObject: SpineGameObject): { x: number, y: number, width: number, height: number };
} }
export class SetupPoseBoundsProvider implements SpineGameObjectBoundsProvider { export class SetupPoseBoundsProvider implements SpineGameObjectBoundsProvider {
calculateBounds(gameObject: SpineGameObject) { calculateBounds (gameObject: SpineGameObject) {
if (!gameObject.skeleton) return { x: 0, y: 0, width: 0, height: 0 }; if (!gameObject.skeleton) return { x: 0, y: 0, width: 0, height: 0 };
// Make a copy of animation state and skeleton as this might be called while // Make a copy of animation state and skeleton as this might be called while
// the skeleton in the GameObject has already been heavily modified. We can not // the skeleton in the GameObject has already been heavily modified. We can not
@ -28,11 +28,11 @@ export class SetupPoseBoundsProvider implements SpineGameObjectBoundsProvider {
} }
export class SkinsAndAnimationBoundsProvider implements SpineGameObjectBoundsProvider { export class SkinsAndAnimationBoundsProvider implements SpineGameObjectBoundsProvider {
constructor(private animation: string, private skins: string[] = [], private timeStep: number = 0.05) { constructor (private animation: string, private skins: string[] = [], private timeStep: number = 0.05) {
} }
calculateBounds(gameObject: SpineGameObject): { x: number; y: number; width: number; height: number; } { calculateBounds (gameObject: SpineGameObject): { x: number; y: number; width: number; height: number; } {
if (!gameObject.skeleton || !gameObject.animationState) return { x: 0, y: 0, width: 0, height: 0 }; if (!gameObject.skeleton || !gameObject.animationState) return { x: 0, y: 0, width: 0, height: 0 };
// Make a copy of animation state and skeleton as this might be called while // Make a copy of animation state and skeleton as this might be called while
// the skeleton in the GameObject has already been heavily modified. We can not // the skeleton in the GameObject has already been heavily modified. We can not
@ -87,13 +87,13 @@ export class SpineGameObject extends ComputedSizeMixin(DepthMixin(FlipMixin(Scro
private _scaleX = 1; private _scaleX = 1;
private _scaleY = 1; private _scaleY = 1;
constructor(scene: Phaser.Scene, private plugin: SpinePlugin, x: number, y: number, dataKey: string, atlasKey: string, public boundsProvider: SpineGameObjectBoundsProvider = new SetupPoseBoundsProvider()) { 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); super(scene, SPINE_GAME_OBJECT_TYPE);
this.setPosition(x, y); x this.setPosition(x, y); x
this.setSkeleton(dataKey, atlasKey); this.setSkeleton(dataKey, atlasKey);
} }
setSkeleton(dataKey: string, atlasKey: string) { setSkeleton (dataKey: string, atlasKey: string) {
if (dataKey && atlasKey) { if (dataKey && atlasKey) {
this.premultipliedAlpha = this.plugin.isAtlasPremultiplied(atlasKey); this.premultipliedAlpha = this.plugin.isAtlasPremultiplied(atlasKey);
this.skeleton = this.plugin.createSkeleton(dataKey, atlasKey); this.skeleton = this.plugin.createSkeleton(dataKey, atlasKey);
@ -107,41 +107,41 @@ export class SpineGameObject extends ComputedSizeMixin(DepthMixin(FlipMixin(Scro
} }
} }
public get displayOriginX() { public get displayOriginX () {
return this._displayOriginX; return this._displayOriginX;
} }
public set displayOriginX(value: number) { public set displayOriginX (value: number) {
this._displayOriginX = value; this._displayOriginX = value;
} }
public get displayOriginY() { public get displayOriginY () {
return this._displayOriginY; return this._displayOriginY;
} }
public set displayOriginY(value: number) { public set displayOriginY (value: number) {
this._displayOriginY = value; this._displayOriginY = value;
} }
public get scaleX() { public get scaleX () {
return this._scaleX; return this._scaleX;
} }
public set scaleX(value: number) { public set scaleX (value: number) {
this._scaleX = value; this._scaleX = value;
this.updateSize(); this.updateSize();
} }
public get scaleY() { public get scaleY () {
return this._scaleY; return this._scaleY;
} }
public set scaleY(value: number) { public set scaleY (value: number) {
this._scaleY = value; this._scaleY = value;
this.updateSize(); this.updateSize();
} }
updateSize() { updateSize () {
if (!this.skeleton) return; if (!this.skeleton) return;
let bounds = this.boundsProvider.calculateBounds(this); let bounds = this.boundsProvider.calculateBounds(this);
// For some reason the TS compiler and the ComputedSize mixin don't work well together... // For some reason the TS compiler and the ComputedSize mixin don't work well together...
@ -152,7 +152,7 @@ export class SpineGameObject extends ComputedSizeMixin(DepthMixin(FlipMixin(Scro
this.displayOriginY = -bounds.y; this.displayOriginY = -bounds.y;
} }
skeletonToPhaserWorldCoordinates(point: {x: number, y: number}) { skeletonToPhaserWorldCoordinates (point: { x: number, y: number }) {
let transform = this.getWorldTransformMatrix(); let transform = this.getWorldTransformMatrix();
let a = transform.a, b = transform.b, c = transform.c, d = transform.d, tx = transform.tx, ty = transform.ty; let a = transform.a, b = transform.b, c = transform.c, d = transform.d, tx = transform.tx, ty = transform.ty;
let x = point.x let x = point.x
@ -161,7 +161,7 @@ export class SpineGameObject extends ComputedSizeMixin(DepthMixin(FlipMixin(Scro
point.y = x * b + y * d + ty; point.y = x * b + y * d + ty;
} }
phaserWorldCoordinatesToSkeleton(point: {x: number, y: number}) { phaserWorldCoordinatesToSkeleton (point: { x: number, y: number }) {
let transform = this.getWorldTransformMatrix(); let transform = this.getWorldTransformMatrix();
transform = transform.invert(); transform = transform.invert();
let a = transform.a, b = transform.b, c = transform.c, d = transform.d, tx = transform.tx, ty = transform.ty; let a = transform.a, b = transform.b, c = transform.c, d = transform.d, tx = transform.tx, ty = transform.ty;
@ -171,7 +171,7 @@ export class SpineGameObject extends ComputedSizeMixin(DepthMixin(FlipMixin(Scro
point.y = x * b + y * d + ty; point.y = x * b + y * d + ty;
} }
phaserWorldCoordinatesToBone(point: {x: number, y: number}, bone: Bone) { phaserWorldCoordinatesToBone (point: { x: number, y: number }, bone: Bone) {
this.phaserWorldCoordinatesToSkeleton(point); this.phaserWorldCoordinatesToSkeleton(point);
if (bone.parent) { if (bone.parent) {
bone.parent.worldToLocal(point as Vector2); bone.parent.worldToLocal(point as Vector2);
@ -180,7 +180,7 @@ export class SpineGameObject extends ComputedSizeMixin(DepthMixin(FlipMixin(Scro
} }
} }
preUpdate(time: number, delta: number) { preUpdate (time: number, delta: number) {
if (!this.skeleton || !this.animationState) return; if (!this.skeleton || !this.animationState) return;
this.animationState.update(delta / 1000); this.animationState.update(delta / 1000);
@ -188,13 +188,13 @@ export class SpineGameObject extends ComputedSizeMixin(DepthMixin(FlipMixin(Scro
this.skeleton.updateWorldTransform(); this.skeleton.updateWorldTransform();
} }
preDestroy() { preDestroy () {
this.skeleton = null; this.skeleton = null;
this.animationState = null; this.animationState = null;
// FIXME tear down any event emitters // FIXME tear down any event emitters
} }
willRender(camera: Phaser.Cameras.Scene2D.Camera) { willRender (camera: Phaser.Cameras.Scene2D.Camera) {
if (!this.visible) return false; if (!this.visible) return false;
var GameObjectRenderMask = 0xf; var GameObjectRenderMask = 0xf;
@ -203,7 +203,7 @@ export class SpineGameObject extends ComputedSizeMixin(DepthMixin(FlipMixin(Scro
return result; return result;
} }
renderWebGL(renderer: Phaser.Renderer.WebGL.WebGLRenderer, src: SpineGameObject, camera: Phaser.Cameras.Scene2D.Camera, parentMatrix: Phaser.GameObjects.Components.TransformMatrix) { renderWebGL (renderer: Phaser.Renderer.WebGL.WebGLRenderer, src: SpineGameObject, camera: Phaser.Cameras.Scene2D.Camera, parentMatrix: Phaser.GameObjects.Components.TransformMatrix) {
if (!this.skeleton || !this.animationState || !this.plugin.webGLRenderer) return; if (!this.skeleton || !this.animationState || !this.plugin.webGLRenderer) return;
let sceneRenderer = this.plugin.webGLRenderer; let sceneRenderer = this.plugin.webGLRenderer;
@ -230,7 +230,7 @@ export class SpineGameObject extends ComputedSizeMixin(DepthMixin(FlipMixin(Scro
} }
} }
renderCanvas(renderer: Phaser.Renderer.Canvas.CanvasRenderer, src: SpineGameObject, camera: Phaser.Cameras.Scene2D.Camera, parentMatrix: Phaser.GameObjects.Components.TransformMatrix) { renderCanvas (renderer: Phaser.Renderer.Canvas.CanvasRenderer, src: SpineGameObject, camera: Phaser.Cameras.Scene2D.Camera, parentMatrix: Phaser.GameObjects.Components.TransformMatrix) {
if (!this.skeleton || !this.animationState || !this.plugin.canvasRenderer) return; if (!this.skeleton || !this.animationState || !this.plugin.canvasRenderer) return;
let context = renderer.currentContext; let context = renderer.currentContext;

View File

@ -168,7 +168,7 @@ export class SpinePlugin extends Phaser.Plugins.ScenePlugin {
if (this.webGLRenderer) this.webGLRenderer.dispose(); if (this.webGLRenderer) this.webGLRenderer.dispose();
} }
isAtlasPremultiplied(atlasKey: string) { isAtlasPremultiplied (atlasKey: string) {
let atlasFile = this.game.cache.text.get(atlasKey); let atlasFile = this.game.cache.text.get(atlasKey);
if (!atlasFile) return false; if (!atlasFile) return false;
return atlasFile.premultipliedAlpha; return atlasFile.premultipliedAlpha;
@ -305,7 +305,7 @@ export class SpineAtlasFile extends Phaser.Loader.MultiFile {
} else { } else {
file.data = { file.data = {
data: file.data, data: file.data,
premultipliedAlpha: this.premultipliedAlpha || file.data.indexOf("pma: true") >= 0 premultipliedAlpha: this.premultipliedAlpha || file.data.indexOf("pma: true") >= 0
}; };
file.addToCache(); file.addToCache();
} }

View File

@ -86,7 +86,7 @@ export class SceneRenderer implements Disposable {
this.enableRenderer(this.batcher); this.enableRenderer(this.batcher);
} }
drawSkeleton (skeleton: Skeleton, premultipliedAlpha = false, slotRangeStart = -1, slotRangeEnd = -1, transform: VertexTransformer | null = null) { drawSkeleton (skeleton: Skeleton, premultipliedAlpha = false, slotRangeStart = -1, slotRangeEnd = -1, transform: VertexTransformer | null = null) {
this.enableRenderer(this.batcher); this.enableRenderer(this.batcher);
this.skeletonRenderer.premultipliedAlpha = premultipliedAlpha; this.skeletonRenderer.premultipliedAlpha = premultipliedAlpha;
this.skeletonRenderer.draw(this.batcher, skeleton, slotRangeStart, slotRangeEnd, transform); this.skeletonRenderer.draw(this.batcher, skeleton, slotRangeStart, slotRangeEnd, transform);

View File

@ -51,6 +51,10 @@
#define PROBLEMATIC_PACKAGE_ASSET_MODIFICATION #define PROBLEMATIC_PACKAGE_ASSET_MODIFICATION
#endif #endif
#if UNITY_2019_2_OR_NEWER
#define HAS_PACKAGE_INFO
#endif
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
@ -114,6 +118,17 @@ namespace Spine.Unity.Editor {
} }
} }
public static bool AssetCanBeModified (string assetPath) {
#if HAS_PACKAGE_INFO
UnityEditor.PackageManager.PackageInfo packageInfo = UnityEditor.PackageManager.PackageInfo.FindForAssetPath(assetPath);
return (packageInfo == null ||
packageInfo.source == UnityEditor.PackageManager.PackageSource.Embedded ||
packageInfo.source == UnityEditor.PackageManager.PackageSource.Local);
#else
return assetPath.StartsWith("Assets");
#endif
}
#region Match SkeletonData with Atlases #region Match SkeletonData with Atlases
static readonly AttachmentType[] AtlasTypes = { AttachmentType.Region, AttachmentType.Linkedmesh, AttachmentType.Mesh }; static readonly AttachmentType[] AtlasTypes = { AttachmentType.Region, AttachmentType.Linkedmesh, AttachmentType.Mesh };

View File

@ -91,6 +91,8 @@ namespace Spine.Unity.Editor {
string[] prefabAssets = AssetDatabase.FindAssets("t:Prefab"); string[] prefabAssets = AssetDatabase.FindAssets("t:Prefab");
foreach (string asset in prefabAssets) { foreach (string asset in prefabAssets) {
string assetPath = AssetDatabase.GUIDToAssetPath(asset); string assetPath = AssetDatabase.GUIDToAssetPath(asset);
if (!AssetUtility.AssetCanBeModified(assetPath)) continue;
GameObject prefabGameObject = AssetDatabase.LoadAssetAtPath<GameObject>(assetPath); GameObject prefabGameObject = AssetDatabase.LoadAssetAtPath<GameObject>(assetPath);
if (SpineEditorUtilities.CleanupSpinePrefabMesh(prefabGameObject)) { if (SpineEditorUtilities.CleanupSpinePrefabMesh(prefabGameObject)) {
#if HAS_SAVE_ASSET_IF_DIRTY #if HAS_SAVE_ASSET_IF_DIRTY
@ -139,6 +141,8 @@ namespace Spine.Unity.Editor {
string[] spriteAtlasAssets = AssetDatabase.FindAssets("t:SpineSpriteAtlasAsset"); string[] spriteAtlasAssets = AssetDatabase.FindAssets("t:SpineSpriteAtlasAsset");
foreach (string asset in spriteAtlasAssets) { foreach (string asset in spriteAtlasAssets) {
string assetPath = AssetDatabase.GUIDToAssetPath(asset); string assetPath = AssetDatabase.GUIDToAssetPath(asset);
if (!AssetUtility.AssetCanBeModified(assetPath)) continue;
SpineSpriteAtlasAsset atlasAsset = AssetDatabase.LoadAssetAtPath<SpineSpriteAtlasAsset>(assetPath); SpineSpriteAtlasAsset atlasAsset = AssetDatabase.LoadAssetAtPath<SpineSpriteAtlasAsset>(assetPath);
if (atlasAsset && atlasAsset.materials.Length > 0) { if (atlasAsset && atlasAsset.materials.Length > 0) {
spriteAtlasTexturesToRestore[assetPath] = AssetDatabase.GetAssetPath(atlasAsset.materials[0].mainTexture); spriteAtlasTexturesToRestore[assetPath] = AssetDatabase.GetAssetPath(atlasAsset.materials[0].mainTexture);