@galacean/engine-spine 0.0.0-experimental-engine-spine-20240821 → 0.0.0-experimental-engine-spine-20241104

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,21 +1,25 @@
1
1
  {
2
- "version": "0.0.0-experimental-engine-spine-20240821",
2
+ "version": "0.0.0-experimental-engine-spine-20241104",
3
3
  "description": "galacean spine runtime",
4
4
  "name": "@galacean/engine-spine",
5
5
  "main": "dist/main.js",
6
6
  "browser": "dist/browser.js",
7
7
  "module": "dist/module.js",
8
+ "dependencies": {
9
+ "@esotericsoftware/spine-core": "~4.2.1"
10
+ },
8
11
  "peerDependencies": {
9
- "@galacean/engine": ">=1.3.0-alpha.0"
12
+ "@galacean/engine": ">=1.3.0"
10
13
  },
11
14
  "devDependencies": {
12
15
  "@babel/core": "^7.22.5",
13
16
  "@babel/plugin-proposal-class-properties": "^7.12.1",
14
17
  "@babel/plugin-proposal-decorators": "^7.12.1",
15
18
  "@babel/plugin-proposal-optional-chaining": "^7.12.1",
19
+ "@babel/plugin-transform-class-properties": "^7.24.7",
16
20
  "@babel/plugin-transform-object-assign": "^7.12.1",
17
- "@babel/preset-env": "^7.12.1",
18
- "@babel/preset-typescript": "^7.12.1",
21
+ "@babel/preset-env": "^7.24.8",
22
+ "@babel/preset-typescript": "^7.24.7",
19
23
  "@galacean/engine": "^1.3.0-alpha.3",
20
24
  "@galacean/engine-toolkit": "beta",
21
25
  "@rollup/plugin-babel": "^5.2.1",
@@ -26,10 +30,26 @@
26
30
  "@rollup/plugin-terser": "^0.4.3",
27
31
  "@swc/core": "^1.3.32",
28
32
  "@swc/helpers": "^0.5",
29
- "cross-env": "^5.2.0",
33
+ "@types/chai": "^4.3.16",
34
+ "@types/jest": "^29.5.12",
35
+ "@types/node": "^20.14.10",
36
+ "@vitejs/plugin-basic-ssl": "^1.1.0",
37
+ "babel-core": "^6.26.3",
38
+ "babel-jest": "^29.7.0",
39
+ "chai": "^4.3.6",
40
+ "chai-spies": "^1.0.0",
41
+ "cross-env": "^5.2.1",
42
+ "cypress": "^13.13.0",
43
+ "cypress-recurse": "^1.35.3",
30
44
  "dat.gui": "^0.7.9",
45
+ "jest": "^29.7.0",
46
+ "jest-environment-jsdom": "^29.7.0",
47
+ "jest-webgl-canvas-mock": "^2.5.3",
48
+ "nock": "^13.5.4",
49
+ "odiff-bin": "^3.0.1",
31
50
  "react": "^16.14.0",
32
51
  "react-dom": "^16.14.0",
52
+ "regenerator-runtime": "^0.14.1",
33
53
  "rollup": "^2.32.0",
34
54
  "rollup-plugin-glslify": "^1.2.0",
35
55
  "rollup-plugin-modify": "^3.0.0",
@@ -37,8 +57,13 @@
37
57
  "rollup-plugin-swc3": "^0.8.0",
38
58
  "rollup-plugin-terser": "^7.0.2",
39
59
  "rollup-plugin-version-injector": "^1.3.3",
40
- "typescript": "^4.8.4",
41
- "vite": "^4.3.9"
60
+ "sass": "^1.77.8",
61
+ "sinon": "^18.0.0",
62
+ "ts-jest": "^29.2.2",
63
+ "ts-node": "^10.9.2",
64
+ "tsconfig-paths": "^4.2.0",
65
+ "typescript": "^5.5.3",
66
+ "vite": "^5.3.4"
42
67
  },
43
68
  "ci": {
44
69
  "type": "aci",
@@ -48,10 +73,39 @@
48
73
  "types",
49
74
  "dist"
50
75
  ],
76
+ "jest": {
77
+ "runner": "jest-runner",
78
+ "testEnvironment": "jsdom",
79
+ "testEnvironmentOptions": {
80
+ "url": "https://mdn.alipayobjects.com/",
81
+ "userAgent": "Agent/007"
82
+ },
83
+ "preset": "ts-jest",
84
+ "collectCoverage": true,
85
+ "testRegex": "(/tests/.*\\.(test|spec))\\.ts?$",
86
+ "collectCoverageFrom": [
87
+ "src/**/*.ts"
88
+ ],
89
+ "transform": {
90
+ "^.+\\.js$": "babel-jest",
91
+ "^.+\\.ts$": "ts-jest"
92
+ },
93
+ "transformIgnorePatterns": [
94
+ "node_modules/(?!(.*@esotericsoftware/spine-core.*))"
95
+ ],
96
+ "setupFilesAfterEnv": [
97
+ "./jest.setup.ts",
98
+ "jest-webgl-canvas-mock"
99
+ ]
100
+ },
51
101
  "scripts": {
52
102
  "example": "vite",
53
103
  "test": "jest",
54
- "test-cov": "jest --coverage",
104
+ "test:cov": "jest --coverage",
105
+ "test:debug": "cross-env DEBUG_MODE=1 jest",
106
+ "e2e:case": "vite serve ./e2e/.dev --config ./e2e/.dev/vite.config.js",
107
+ "e2e": "cypress run --browser chrome --headless",
108
+ "e2e:debug": "cypress open",
55
109
  "dev": "rollup -cw",
56
110
  "build": "npm run b:types && cross-env BUILD_TYPE=ALL rollup -c",
57
111
  "build:watch": "npm run b:types && cross-env BUILD_TYPE=ALL rollup -c --watch",
@@ -60,5 +114,9 @@
60
114
  "b:types": "tsc --emitDeclarationOnly"
61
115
  },
62
116
  "types": "types/index.d.ts",
63
- "repository": "https://github.com/johanzhu/engine-spine.git"
117
+ "repository": "https://github.com/johanzhu/engine-spine.git",
118
+ "publishConfig": {
119
+ "access": "public",
120
+ "registry": "https://registry.npmjs.org"
121
+ }
64
122
  }
@@ -1,6 +1,6 @@
1
- import { Skeleton, SkeletonData, AnimationState, AnimationStateData } from "./spine-core";
1
+ import { Skeleton, AnimationState } from "@esotericsoftware/spine-core";
2
2
  import { Buffer, Renderer, Entity, Material, Engine, BoundingBox, Primitive, SubPrimitive } from "@galacean/engine";
3
- import { SkeletonDataResource } from "./loader/SkeletonDataResource";
3
+ import { SpineResource } from "./loader/SpineResource";
4
4
  /**
5
5
  * Spine animation renderer, capable of rendering spine animations and providing functions for animation and skeleton manipulation.
6
6
  */
@@ -13,17 +13,20 @@ export declare class SpineAnimationRenderer extends Renderer {
13
13
  /** @internal */
14
14
  static _materialCache: Map<string, Material>;
15
15
  /** @internal */
16
- static _animationDataCache: Map<SkeletonData, AnimationStateData>;
17
- /** @internal */
18
16
  static _getDefaultMaterial(engine: Engine): Material;
19
- /** Render setting for spine rendering. */
20
- setting: SpineRenderSetting;
17
+ /**
18
+ * The spacing between z layers.
19
+ */
20
+ zSpacing: number;
21
+ /**
22
+ * Whether to premultiplied alpha for texture.
23
+ */
24
+ premultipliedAlpha: boolean;
21
25
  /**
22
26
  * Default state for spine animation.
23
- * Contains the default animation name to be played, whether this animation should loop,
24
- * the default skin name, and the default scale of the skeleton.
27
+ * Contains the default animation name to be played, whether this animation should loop, the default skin name.
25
28
  */
26
- defaultState: DefaultState;
29
+ readonly defaultConfig: SpineAnimationDefaultConfig;
27
30
  /** @internal */
28
31
  _primitive: Primitive;
29
32
  /** @internal */
@@ -41,22 +44,18 @@ export declare class SpineAnimationRenderer extends Renderer {
41
44
  /** @internal */
42
45
  _vertexCount: number;
43
46
  /** @internal */
44
- _resource: SkeletonDataResource;
47
+ _resource: SpineResource;
45
48
  private _skeleton;
46
49
  private _state;
50
+ private _needsInitialize;
47
51
  /**
48
- * Spine resource of current spine animation.This property allows you to switch between different animations at runtime.
49
- */
50
- get resource(): SkeletonDataResource;
51
- set resource(value: SkeletonDataResource);
52
- /**
53
- * Provides access to `AnimationState` which controls animation playback on a skeleton.
54
- * You can use its API to manage, blend, and transition between multiple simultaneous animations effectively.
52
+ * The Spine.AnimationState object of this SpineAnimationRenderer.
53
+ * Manage, blend, and transition between multiple simultaneous animations effectively.
55
54
  */
56
55
  get state(): AnimationState;
57
56
  /**
58
- * Provides access to `Skeleton`, which defines the structure of a Spine model.
59
- * Through its API, users can manipulate bone positions, rotations, scaling
57
+ * The Spine.Skeleton object of this SpineAnimationRenderer.
58
+ * Manipulate bone positions, rotations, scaling
60
59
  * and change spine attachment to customize character appearances dynamically during runtime.
61
60
  */
62
61
  get skeleton(): Skeleton;
@@ -64,10 +63,6 @@ export declare class SpineAnimationRenderer extends Renderer {
64
63
  * @internal
65
64
  */
66
65
  constructor(entity: Entity);
67
- /**
68
- * Separate slot by slot name. This will add a new sub primitive, and new materials.
69
- */
70
- addSeparateSlot(slotName: string): void;
71
66
  /**
72
67
  * @internal
73
68
  */
@@ -88,6 +83,14 @@ export declare class SpineAnimationRenderer extends Renderer {
88
83
  * @internal
89
84
  */
90
85
  _calculateGeneratorBounds(worldBounds: BoundingBox): void;
86
+ /**
87
+ * @internal
88
+ */
89
+ _setSkeleton(skeleton: Skeleton): void;
90
+ /**
91
+ * @internal
92
+ */
93
+ _setState(state: AnimationState): void;
91
94
  /**
92
95
  * @internal
93
96
  */
@@ -99,7 +102,7 @@ export declare class SpineAnimationRenderer extends Renderer {
99
102
  /**
100
103
  * @internal
101
104
  */
102
- _createBuffer(vertexCount: number): void;
105
+ _createAndBindBuffer(vertexCount: number): void;
103
106
  /**
104
107
  * @internal
105
108
  */
@@ -120,10 +123,23 @@ export declare class SpineAnimationRenderer extends Renderer {
120
123
  * @internal
121
124
  */
122
125
  _onWorldVolumeChanged(): void;
126
+ private _initialize;
123
127
  private _onAnimationStart;
124
128
  private _onAnimationComplete;
125
129
  private _clearMaterialCache;
126
- private _initializeDefaultState;
130
+ private _applyDefaultConfig;
131
+ /**
132
+ * * @deprecated This property is deprecated and will be removed in future releases.
133
+ * Spine resource of current spine animation.
134
+ */
135
+ get resource(): SpineResource;
136
+ /**
137
+ * * @deprecated This property is deprecated and will be removed in future releases.
138
+ * Sets the Spine resource for the current animation. This property allows switching to a different `SpineResource`.
139
+ *
140
+ * @param value - The new `SpineResource` to be used for the current animation
141
+ */
142
+ set resource(value: SpineResource);
127
143
  }
128
144
  /**
129
145
  * @internal
@@ -143,41 +159,12 @@ export declare enum RendererUpdateFlags {
143
159
  /** Include world position and world bounds. */
144
160
  WorldVolume = 1
145
161
  }
146
- /**
147
- * Render setting for spine rendering.
148
- */
149
- export declare class SpineRenderSetting {
150
- /**
151
- * The spacing between z layers @defaultValue `0.01`
152
- */
153
- zSpacing: number;
154
- /**
155
- * Whether to use clipping @defaultValue `true`
156
- */
157
- useClipping: boolean;
158
- /**
159
- * Creates an instance of SpineRenderSetting.
160
- */
161
- constructor(
162
- /**
163
- * The spacing between z layers @defaultValue `0.01`
164
- */
165
- zSpacing?: number,
166
- /**
167
- * Whether to use clipping @defaultValue `true`
168
- */
169
- useClipping?: boolean);
170
- }
171
162
  /**
172
163
  * Default state for spine animation.
173
164
  * Contains the default animation name to be played, whether this animation should loop,
174
165
  * the default skin name, and the default scale of the skeleton.
175
166
  */
176
- export declare class DefaultState {
177
- /**
178
- * The default scale of the animation @defaultValue `1`
179
- */
180
- scale: number;
167
+ export declare class SpineAnimationDefaultConfig {
181
168
  /**
182
169
  * Whether the default animation should loop @defaultValue `true. The default animation should loop`
183
170
  */
@@ -191,13 +178,9 @@ export declare class DefaultState {
191
178
  */
192
179
  skinName: string;
193
180
  /**
194
- * Creates an instance of DefaultState
181
+ * Creates an instance of default config
195
182
  */
196
183
  constructor(
197
- /**
198
- * The default scale of the animation @defaultValue `1`
199
- */
200
- scale?: number,
201
184
  /**
202
185
  * Whether the default animation should loop @defaultValue `true. The default animation should loop`
203
186
  */
@@ -1,5 +1,5 @@
1
1
  import { Texture2D, SubPrimitive, BoundingBox } from "@galacean/engine";
2
- import { Skeleton, Color, BlendMode, SkeletonData } from "./spine-core";
2
+ import { Skeleton, Color, BlendMode } from "@esotericsoftware/spine-core";
3
3
  import { SpineAnimationRenderer } from "./SpineAnimationRenderer";
4
4
  import { AdaptiveTexture } from "./loader/LoaderUtils";
5
5
  import { ReturnablePool } from "./util/ReturnablePool";
@@ -26,13 +26,10 @@ export declare class SpineGenerator {
26
26
  private _subRenderItems;
27
27
  private _separateSlots;
28
28
  private _separateSlotTextureMap;
29
- getMaxVertexCount(skeletonData: SkeletonData): number;
30
29
  buildPrimitive(skeleton: Skeleton, renderer: SpineAnimationRenderer): void;
31
30
  addSeparateSlot(slotName: string): void;
32
31
  addSeparateSlotTexture(slotName: string, texture: Texture2D): void;
33
32
  private _createMaterialForTexture;
34
33
  private _expandByPoint;
35
- private _collectUniqueAttachments;
36
- private _calculateTotalVertexCount;
37
34
  }
38
35
  export {};
package/types/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import "./loader/SpineLoader";
2
2
  import "./loader/EditorSpineAtlasLoader";
3
3
  export { SpineAnimationRenderer } from "./SpineAnimationRenderer";
4
- export { SkeletonDataResource } from "./loader/SkeletonDataResource";
4
+ export { SpineResource } from "./loader/SpineResource";
5
5
  export { createTextureAtlas } from "./loader/LoaderUtils";
6
- export * from "../src/spine-core";
6
+ export * from "@esotericsoftware/spine-core";
7
7
  export declare const version = "__buildVersion";
@@ -1,5 +1,5 @@
1
1
  import { AssetPromise, Loader, ResourceManager, LoadItem } from "@galacean/engine";
2
- import { TextureAtlas } from "../spine-core";
2
+ import { TextureAtlas } from "@esotericsoftware/spine-core";
3
3
  declare class EditorSpineAtlasLoader extends Loader<TextureAtlas> {
4
4
  load(item: LoadItem, resourceManager: ResourceManager): AssetPromise<TextureAtlas>;
5
5
  }
@@ -1,5 +1,5 @@
1
1
  import { AssetPromise, Engine, Texture2D } from "@galacean/engine";
2
- import { TextureAtlas, SkeletonData, Texture, TextureFilter, TextureWrap } from "../spine-core";
2
+ import { TextureAtlas, SkeletonData, Texture, TextureFilter, TextureWrap } from "@esotericsoftware/spine-core";
3
3
  export declare function createSkeletonData(textureAtlas: TextureAtlas, skeletonTextData: string | ArrayBuffer, skeletonFileType: 'json' | 'skel'): SkeletonData;
4
4
  export declare function loadTexturesByPath(imagePaths: string[], imageExtensions: string[], engine: Engine): Promise<Texture2D[]>;
5
5
  export declare function loadTextureAtlas(atlasPath: string, engine: Engine): Promise<TextureAtlas>;
@@ -1,5 +1,5 @@
1
1
  import { AssetPromise, Loader, LoadItem, ResourceManager } from "@galacean/engine";
2
- import { SkeletonDataResource } from "./SkeletonDataResource";
2
+ import { SpineResource } from "./SpineResource";
3
3
  export type SpineAssetBundle = {
4
4
  skeletonPath: string;
5
5
  skeletonExtension: string;
@@ -14,14 +14,14 @@ type SpineLoaderParams = {
14
14
  type SpineLoadItem = LoadItem & {
15
15
  params?: SpineLoaderParams;
16
16
  };
17
- export declare class SpineLoader extends Loader<SkeletonDataResource> {
17
+ export declare class SpineLoader extends Loader<SpineResource> {
18
18
  static imageExtensions: string[];
19
19
  static skeletonExtensions: string[];
20
20
  static parseAndAssignSpineAsset(url: string, fileExtension: string | null, bundle: SpineAssetBundle): void;
21
21
  static deriveAndAssignSpineAsset(url: string, fileExtension: string | null, bundle: SpineAssetBundle): void;
22
22
  static verifyFileExtensions(fileExtensions: string | string[], expectArray: boolean): string | string[] | null;
23
23
  static getUrlExtension(url: string, fileExtension: string): string | null;
24
- load(item: SpineLoadItem, resourceManager: ResourceManager): AssetPromise<SkeletonDataResource>;
24
+ load(item: SpineLoadItem, resourceManager: ResourceManager): AssetPromise<SpineResource>;
25
25
  private _handleEditorAsset;
26
26
  private _handleOriginAsset;
27
27
  private _determineSkeletonDataType;
@@ -0,0 +1,33 @@
1
+ import { AnimationStateData, SkeletonData } from "@esotericsoftware/spine-core";
2
+ import { Engine, Entity, ReferResource } from "@galacean/engine";
3
+ /**
4
+ * Represents a resource that manages Spine animation data, textures, and entity templates for the Galacean engine.
5
+ *
6
+ */
7
+ export declare class SpineResource extends ReferResource {
8
+ /** The url of skeletonData. */
9
+ readonly url: string;
10
+ private _texturesInSpineAtlas;
11
+ private _skeletonData;
12
+ private _stateData;
13
+ private _template;
14
+ constructor(engine: Engine, skeletonData: SkeletonData, url?: string);
15
+ /**
16
+ * The skeleton data associated with this Spine resource.
17
+ */
18
+ get skeletonData(): SkeletonData;
19
+ /**
20
+ * The animation state data associated with this Spine resource.
21
+ */
22
+ get stateData(): AnimationStateData;
23
+ /**
24
+ * Creates and returns a new instance of the spine entity template.
25
+ * @returns A instance of the spine entity template
26
+ */
27
+ instantiate(): Entity;
28
+ protected _onDestroy(): void;
29
+ private _createTemplate;
30
+ private _associationTextureInSkeletonData;
31
+ private _disassociationSuperResource;
32
+ private _extractFileName;
33
+ }
@@ -1,4 +1,4 @@
1
- import { BlendMode } from "../spine-core";
1
+ import { BlendMode } from "@esotericsoftware/spine-core";
2
2
  import { Material } from "@galacean/engine";
3
- export declare function setBlendMode(material: Material, blendMode: BlendMode): void;
3
+ export declare function setBlendMode(material: Material, blendMode: BlendMode, premultipliedAlpha: boolean): void;
4
4
  export declare function getBlendMode(material: Material): BlendMode;