@safe-engine/cocos 2.3.4 → 2.3.5
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/dist/box2d-wasm/PhysicsComponent.d.ts.map +1 -1
- package/dist/box2d-wasm/PhysicsComponent.js +3 -0
- package/dist/box2d-wasm/PhysicsSprite.d.ts.map +1 -1
- package/dist/box2d-wasm/PhysicsSprite.js +2 -1
- package/dist/box2d-wasm/PhysicsSystem.d.ts +1 -0
- package/dist/box2d-wasm/PhysicsSystem.d.ts.map +1 -1
- package/dist/box2d-wasm/PhysicsSystem.js +20 -16
- package/dist/box2d-wasm/debugDraw.d.ts +0 -15
- package/dist/box2d-wasm/debugDraw.d.ts.map +1 -1
- package/dist/box2d-wasm/debugDraw.js +8 -20
- package/dist/box2d-wasm/index.d.ts +19 -1
- package/dist/box2d-wasm/index.d.ts.map +1 -1
- package/dist/box2d-wasm/index.js +2 -2
- package/dist/core/index.d.ts +6 -0
- package/dist/core/index.d.ts.map +1 -0
- package/dist/core/index.js +5 -0
- package/dist/dragonbones/PixiDragonBonesSprite.d.ts +19 -0
- package/dist/dragonbones/PixiDragonBonesSprite.d.ts.map +1 -0
- package/dist/dragonbones/PixiDragonBonesSprite.js +75 -0
- package/dist/dragonbones/db-cocos/CocosFactory.d.ts +2 -3
- package/dist/dragonbones/db-cocos/CocosFactory.d.ts.map +1 -1
- package/dist/dragonbones/db-cocos/CocosFactory.js +4 -8
- package/dist/dragonbones/db-cocos/CocosSlot.d.ts +4 -1
- package/dist/dragonbones/db-cocos/CocosSlot.d.ts.map +1 -1
- package/dist/dragonbones/db-cocos/CocosSlot.js +35 -38
- package/dist/dragonbones/db-cocos/CocosTextureAtlasData.d.ts +1 -1
- package/dist/dragonbones/db-cocos/CocosTextureAtlasData.d.ts.map +1 -1
- package/dist/dragonbones/db-cocos/CocosTextureAtlasData.js +6 -6
- package/dist/dragonbones/db-cocos/SimpleMeshNode.d.ts +36 -0
- package/dist/dragonbones/db-cocos/SimpleMeshNode.d.ts.map +1 -0
- package/dist/dragonbones/db-cocos/SimpleMeshNode.js +354 -0
- package/dist/gworld/EnhancedComponent.d.ts +22 -0
- package/dist/gworld/EnhancedComponent.d.ts.map +1 -0
- package/dist/gworld/EnhancedComponent.js +44 -0
- package/dist/gworld/NodeComp.d.ts +153 -0
- package/dist/gworld/NodeComp.d.ts.map +1 -0
- package/dist/gworld/NodeComp.js +337 -0
- package/dist/gworld/NodePool.d.ts +9 -0
- package/dist/gworld/NodePool.d.ts.map +1 -0
- package/dist/gworld/NodePool.js +23 -0
- package/dist/gworld/Scene.d.ts +5 -0
- package/dist/gworld/Scene.d.ts.map +1 -0
- package/dist/gworld/Scene.js +14 -0
- package/dist/gworld/decorator.d.ts +8 -0
- package/dist/gworld/decorator.d.ts.map +1 -0
- package/dist/gworld/decorator.js +12 -0
- package/dist/gworld/index.d.ts +8 -0
- package/dist/gworld/index.d.ts.map +1 -0
- package/dist/gworld/index.js +14 -0
- package/dist/render/TiledSprite.d.ts +13 -0
- package/dist/render/TiledSprite.d.ts.map +1 -0
- package/dist/render/TiledSprite.js +69 -0
- package/dist/safex.d.ts +10 -0
- package/dist/safex.d.ts.map +1 -0
- package/dist/safex.js +1 -0
- package/dist/spine/CCSkeleton.d.ts +189 -0
- package/dist/spine/CCSkeleton.d.ts.map +1 -0
- package/dist/spine/CCSkeleton.js +320 -0
- package/dist/spine/CCSkeletonAnimation.d.ts +146 -0
- package/dist/spine/CCSkeletonAnimation.d.ts.map +1 -0
- package/dist/spine/CCSkeletonAnimation.js +311 -0
- package/dist/spine/CCSkeletonCanvasRenderCmd.d.ts +2 -0
- package/dist/spine/CCSkeletonCanvasRenderCmd.d.ts.map +1 -0
- package/dist/spine/CCSkeletonCanvasRenderCmd.js +228 -0
- package/dist/spine/CCSkeletonTexture.d.ts +25 -0
- package/dist/spine/CCSkeletonTexture.d.ts.map +1 -0
- package/dist/spine/CCSkeletonTexture.js +60 -0
- package/dist/spine/CCSkeletonWebGLRenderCmd.d.ts +28 -0
- package/dist/spine/CCSkeletonWebGLRenderCmd.d.ts.map +1 -0
- package/dist/spine/CCSkeletonWebGLRenderCmd.js +277 -0
- package/dist/spine/PixiSpineSprite.d.ts +19 -0
- package/dist/spine/PixiSpineSprite.d.ts.map +1 -0
- package/dist/spine/PixiSpineSprite.js +72 -0
- package/dist/spine/spine-cocos/CCSkeletonAnimation.d.ts +2 -1
- package/dist/spine/spine-cocos/CCSkeletonAnimation.d.ts.map +1 -1
- package/dist/spine/spine-cocos/CCSkeletonAnimation.js +1 -1
- package/dist/spine/spine-cocos/CCSkeletonTexture.d.ts +12 -1
- package/dist/spine/spine-cocos/CCSkeletonTexture.d.ts.map +1 -1
- package/dist/spine/spine-cocos/CCSkeletonTexture.js +18 -19
- package/package.json +3 -3
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { Application, Assets, Texture, TilingSprite } from 'pixi.js';
|
|
2
|
+
export class TiledSprite extends cc.Sprite {
|
|
3
|
+
_tilingSprite;
|
|
4
|
+
_canvas;
|
|
5
|
+
_pixiApp;
|
|
6
|
+
_texture;
|
|
7
|
+
constructor(config) {
|
|
8
|
+
super();
|
|
9
|
+
super.ctor();
|
|
10
|
+
this._canvas = document.createElement('canvas');
|
|
11
|
+
this._canvas.width = config.width || 1024;
|
|
12
|
+
this._canvas.height = config.height || 1024;
|
|
13
|
+
this._pixiApp = new Application();
|
|
14
|
+
this._pixiApp
|
|
15
|
+
.init({
|
|
16
|
+
view: this._canvas,
|
|
17
|
+
width: this._canvas.width,
|
|
18
|
+
height: this._canvas.height,
|
|
19
|
+
backgroundAlpha: 0, // nền trong suốt
|
|
20
|
+
// transparent: true, // bắt buộc để alpha hoạt động
|
|
21
|
+
clearBeforeRender: true, // xoá trước khi vẽ frame mới
|
|
22
|
+
preserveDrawingBuffer: true, // giúp lấy ảnh từ canvas
|
|
23
|
+
antialias: true,
|
|
24
|
+
})
|
|
25
|
+
.then(() => {
|
|
26
|
+
Assets.load(config.texture).then(() => {
|
|
27
|
+
const texture = Texture.from(config.texture);
|
|
28
|
+
const { width, height } = config;
|
|
29
|
+
this._tilingSprite = new TilingSprite({ texture, width, height });
|
|
30
|
+
this._pixiApp.stage.addChild(this._tilingSprite);
|
|
31
|
+
this._updateRepeat();
|
|
32
|
+
});
|
|
33
|
+
});
|
|
34
|
+
this._texture = new cc.Texture2D();
|
|
35
|
+
this._texture.initWithElement(this._canvas);
|
|
36
|
+
this._texture.handleLoadedTexture();
|
|
37
|
+
this.initWithTexture(this._texture);
|
|
38
|
+
// this.schedule(this._updateRepeat, 1, Infinity, 0)
|
|
39
|
+
}
|
|
40
|
+
setContentSize(size, height) {
|
|
41
|
+
// console.log('setContentSize', size, height)
|
|
42
|
+
super.setContentSize(size, height);
|
|
43
|
+
this._updateRepeat();
|
|
44
|
+
}
|
|
45
|
+
setScale(scaleX, scaleY) {
|
|
46
|
+
super.setScale(scaleX, scaleY);
|
|
47
|
+
this._updateRepeat();
|
|
48
|
+
}
|
|
49
|
+
_updateRepeat() {
|
|
50
|
+
if (this._tilingSprite && this._pixiApp.renderer) {
|
|
51
|
+
this._tilingSprite.width = this.width;
|
|
52
|
+
this._tilingSprite.height = this.height;
|
|
53
|
+
this._canvas.width = this.width;
|
|
54
|
+
this._canvas.height = this.height;
|
|
55
|
+
// console.log('_updateRepeat', this._pixiApp, this._tilingSprite)
|
|
56
|
+
this._pixiApp.renderer.render(this._pixiApp.stage);
|
|
57
|
+
this._texture.initWithElement(this._canvas);
|
|
58
|
+
this._texture.handleLoadedTexture();
|
|
59
|
+
// console.log('_texture', this._texture, this)
|
|
60
|
+
this.setTexture(this._texture);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
onExit() {
|
|
64
|
+
this.unschedule(this._updateRepeat);
|
|
65
|
+
this._pixiApp.destroy(true, { children: true });
|
|
66
|
+
this._canvas.remove();
|
|
67
|
+
super.onExit();
|
|
68
|
+
}
|
|
69
|
+
}
|
package/dist/safex.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Color4B, NodeComp } from '.';
|
|
2
|
+
export type ColorSource = ReturnType<typeof Color4B>;
|
|
3
|
+
export interface BaseComponentProps<T> {
|
|
4
|
+
$ref?: T;
|
|
5
|
+
$push?: T[];
|
|
6
|
+
$refNode?: NodeComp;
|
|
7
|
+
$pushNode?: NodeComp[];
|
|
8
|
+
node?: Partial<NodeComp>;
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=safex.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"safex.d.ts","sourceRoot":"","sources":["../src/safex.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,GAAG,CAAA;AAErC,MAAM,MAAM,WAAW,GAAG,UAAU,CAAC,OAAO,OAAO,CAAC,CAAA;AAEpD,MAAM,WAAW,kBAAkB,CAAC,CAAC;IACnC,IAAI,CAAC,EAAE,CAAC,CAAA;IACR,KAAK,CAAC,EAAE,CAAC,EAAE,CAAA;IACX,QAAQ,CAAC,EAAE,QAAQ,CAAA;IACnB,SAAS,CAAC,EAAE,QAAQ,EAAE,CAAA;IACtB,IAAI,CAAC,EAAE,OAAO,CAAC,QAAQ,CAAC,CAAA;CAEzB"}
|
package/dist/safex.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
/****************************************************************************
|
|
2
|
+
Copyright (c) 2011-2012 cocos2d-x.org
|
|
3
|
+
Copyright (c) 2013-2014 Chukong Technologies Inc.
|
|
4
|
+
Copyright (c) 2014 Shengxiang Chen (Nero Chan)
|
|
5
|
+
|
|
6
|
+
http://www.cocos2d-x.org
|
|
7
|
+
|
|
8
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
9
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
10
|
+
in the Software without restriction, including without limitation the rights
|
|
11
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
12
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
13
|
+
furnished to do so, subject to the following conditions:
|
|
14
|
+
|
|
15
|
+
The above copyright notice and this permission notice shall be included in
|
|
16
|
+
all copies or substantial portions of the Software.
|
|
17
|
+
|
|
18
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
19
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
20
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
21
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
22
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
23
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
24
|
+
THE SOFTWARE.
|
|
25
|
+
****************************************************************************/
|
|
26
|
+
/**
|
|
27
|
+
* The main namespace of Spine, all classes, functions, properties and constants of Spine are defined in this namespace
|
|
28
|
+
* @namespace
|
|
29
|
+
* @name
|
|
30
|
+
*/
|
|
31
|
+
/**
|
|
32
|
+
* <p>
|
|
33
|
+
* The skeleton of Spine. <br/>
|
|
34
|
+
* Skeleton has a reference to a SkeletonData and stores the state for skeleton instance,
|
|
35
|
+
* which consists of the current pose's bone SRT, slot colors, and which slot attachments are visible. <br/>
|
|
36
|
+
* Multiple skeletons can use the same SkeletonData (which includes all animations, skins, and attachments). <br/>
|
|
37
|
+
* </p>
|
|
38
|
+
* @class
|
|
39
|
+
* @extends cc.Node
|
|
40
|
+
*/
|
|
41
|
+
export declare class Skeleton extends cc.Node {
|
|
42
|
+
_skeleton: any;
|
|
43
|
+
_rootBone: any;
|
|
44
|
+
_timeScale: number;
|
|
45
|
+
_debugSlots: boolean;
|
|
46
|
+
_debugBones: boolean;
|
|
47
|
+
_premultipliedAlpha: any;
|
|
48
|
+
_ownsSkeletonData: any;
|
|
49
|
+
_atlas: any;
|
|
50
|
+
constructor(skeletonDataFile?: string, atlasFile?: string, scale?: number);
|
|
51
|
+
_createRenderCmd(): any;
|
|
52
|
+
onEnter(): void;
|
|
53
|
+
onExit(): void;
|
|
54
|
+
/**
|
|
55
|
+
* Sets whether open debug slots.
|
|
56
|
+
* @param {boolean} enable true to open, false to close.
|
|
57
|
+
*/
|
|
58
|
+
setDebugSolots(enable: boolean): void;
|
|
59
|
+
/**
|
|
60
|
+
* Sets whether open debug bones.
|
|
61
|
+
* @param {boolean} enable
|
|
62
|
+
*/
|
|
63
|
+
setDebugBones(enable: boolean): void;
|
|
64
|
+
/**
|
|
65
|
+
* Sets whether open debug slots.
|
|
66
|
+
* @param {boolean} enabled true to open, false to close.
|
|
67
|
+
*/
|
|
68
|
+
setDebugSlotsEnabled(enabled: boolean): void;
|
|
69
|
+
/**
|
|
70
|
+
* Gets whether open debug slots.
|
|
71
|
+
* @returns {boolean} true to open, false to close.
|
|
72
|
+
*/
|
|
73
|
+
getDebugSlotsEnabled(): boolean;
|
|
74
|
+
/**
|
|
75
|
+
* Sets whether open debug bones.
|
|
76
|
+
* @param {boolean} enabled
|
|
77
|
+
*/
|
|
78
|
+
setDebugBonesEnabled(enabled: boolean): void;
|
|
79
|
+
/**
|
|
80
|
+
* Gets whether open debug bones.
|
|
81
|
+
* @returns {boolean} true to open, false to close.
|
|
82
|
+
*/
|
|
83
|
+
getDebugBonesEnabled(): boolean;
|
|
84
|
+
/**
|
|
85
|
+
* Sets the time scale of Skeleton.
|
|
86
|
+
* @param {Number} scale
|
|
87
|
+
*/
|
|
88
|
+
setTimeScale(scale: number): void;
|
|
89
|
+
getTimeScale(): number;
|
|
90
|
+
/**
|
|
91
|
+
* Initializes Skeleton with Data.
|
|
92
|
+
* @param {.spine.SkeletonData|String} skeletonDataFile
|
|
93
|
+
* @param {String|spine.Atlas|spine.SkeletonData} atlasFile atlas filename or atlas data or owns SkeletonData
|
|
94
|
+
* @param {Number} [scale] scale can be specified on the JSON or binary loader which will scale the bone positions, image sizes, and animation translations.
|
|
95
|
+
*/
|
|
96
|
+
initWithArgs(skeletonDataFile: string, atlasFile: string, scale?: number): void;
|
|
97
|
+
/**
|
|
98
|
+
* Returns the bounding box of Skeleton.
|
|
99
|
+
* @returns {cc.Rect}
|
|
100
|
+
*/
|
|
101
|
+
getBoundingBox(): cc.Rect;
|
|
102
|
+
/**
|
|
103
|
+
* Computes the world SRT from the local SRT for each bone.
|
|
104
|
+
*/
|
|
105
|
+
updateWorldTransform(): void;
|
|
106
|
+
/**
|
|
107
|
+
* Sets the bones and slots to the setup pose.
|
|
108
|
+
*/
|
|
109
|
+
setToSetupPose(): void;
|
|
110
|
+
/**
|
|
111
|
+
* Sets the bones to the setup pose, using the values from the `BoneData` list in the `SkeletonData`.
|
|
112
|
+
*/
|
|
113
|
+
setBonesToSetupPose(): void;
|
|
114
|
+
/**
|
|
115
|
+
* Sets the slots to the setup pose, using the values from the `SlotData` list in the `SkeletonData`.
|
|
116
|
+
*/
|
|
117
|
+
setSlotsToSetupPose(): void;
|
|
118
|
+
/**
|
|
119
|
+
* Finds a bone by name. This does a string comparison for every bone.
|
|
120
|
+
* @param {String} boneName
|
|
121
|
+
* @returns {.spine.Bone}
|
|
122
|
+
*/
|
|
123
|
+
findBone(boneName: string): any;
|
|
124
|
+
/**
|
|
125
|
+
* Finds a slot by name. This does a string comparison for every slot.
|
|
126
|
+
* @param {String} slotName
|
|
127
|
+
* @returns {.spine.Slot}
|
|
128
|
+
*/
|
|
129
|
+
findSlot(slotName: string): any;
|
|
130
|
+
/**
|
|
131
|
+
* Finds a skin by name and makes it the active skin. This does a string comparison for every skin. Note that setting the skin does not change which attachments are visible.
|
|
132
|
+
* @param {string} skinName
|
|
133
|
+
* @returns {.spine.Skin}
|
|
134
|
+
*/
|
|
135
|
+
setSkin(skinName: string): any;
|
|
136
|
+
/**
|
|
137
|
+
* Returns the attachment for the slot and attachment name. The skeleton looks first in its skin, then in the skeleton data’s default skin.
|
|
138
|
+
* @param {String} slotName
|
|
139
|
+
* @param {String} attachmentName
|
|
140
|
+
* @returns {.spine.Attachment}
|
|
141
|
+
*/
|
|
142
|
+
getAttachment(slotName: string, attachmentName: string): any;
|
|
143
|
+
/**
|
|
144
|
+
* Sets the attachment for the slot and attachment name. The skeleton looks first in its skin, then in the skeleton data’s default skin.
|
|
145
|
+
* @param {String} slotName
|
|
146
|
+
* @param {String} attachmentName
|
|
147
|
+
*/
|
|
148
|
+
setAttachment(slotName: string, attachmentName: string): void;
|
|
149
|
+
/**
|
|
150
|
+
* Sets the premultiplied alpha value to Skeleton.
|
|
151
|
+
* @param {Number} alpha
|
|
152
|
+
*/
|
|
153
|
+
setPremultipliedAlpha(premultiplied: boolean): void;
|
|
154
|
+
/**
|
|
155
|
+
* Returns whether to enable premultiplied alpha.
|
|
156
|
+
* @returns {boolean}
|
|
157
|
+
*/
|
|
158
|
+
isPremultipliedAlpha(): boolean;
|
|
159
|
+
/**
|
|
160
|
+
* Sets skeleton data to Skeleton.
|
|
161
|
+
* @param {.spine.SkeletonData} skeletonData
|
|
162
|
+
* @param {.spine.SkeletonData} ownsSkeletonData
|
|
163
|
+
*/
|
|
164
|
+
setSkeletonData(skeletonData: any, ownsSkeletonData: any): void;
|
|
165
|
+
/**
|
|
166
|
+
* Return the renderer of attachment.
|
|
167
|
+
* @param {.spine.RegionAttachment|.spine.BoundingBoxAttachment} regionAttachment
|
|
168
|
+
* @returns {.spine.TextureAtlasRegion}
|
|
169
|
+
*/
|
|
170
|
+
getTextureAtlas(regionAttachment: any): any;
|
|
171
|
+
/**
|
|
172
|
+
* Returns the blendFunc of Skeleton.
|
|
173
|
+
* @returns {cc.BlendFunc}
|
|
174
|
+
*/
|
|
175
|
+
getBlendFunc(): any;
|
|
176
|
+
/**
|
|
177
|
+
* Sets the blendFunc of Skeleton, it won't have any effect for skeleton, skeleton is using slot's data to determine the blend function.
|
|
178
|
+
* @param {cc.BlendFunc|Number} src
|
|
179
|
+
* @param {Number} [dst]
|
|
180
|
+
*/
|
|
181
|
+
setBlendFunc(src: any, dst?: any): any;
|
|
182
|
+
/**
|
|
183
|
+
* Update will be called automatically every frame if "scheduleUpdate" is called when the node is "live".
|
|
184
|
+
* @param {Number} dt Delta time since last update
|
|
185
|
+
*/
|
|
186
|
+
update(dt: number): void;
|
|
187
|
+
static create(skeletonDataFile: string, atlasFile: string, scale?: number): Skeleton;
|
|
188
|
+
}
|
|
189
|
+
//# sourceMappingURL=CCSkeleton.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CCSkeleton.d.ts","sourceRoot":"","sources":["../../src/spine/CCSkeleton.ts"],"names":[],"mappings":"AAMA;;;;;;;;;;;;;;;;;;;;;;;;8EAwB8E;AAE9E;;;;GAIG;AACH;;;;;;;;;GASG;AACH,qBAAa,QAAS,SAAQ,EAAE,CAAC,IAAI;IACnC,SAAS,MAAO;IAChB,SAAS,MAAO;IAChB,UAAU,SAAI;IACd,WAAW,UAAQ;IACnB,WAAW,UAAQ;IACnB,mBAAmB,MAAA;IACnB,iBAAiB,MAAO;IACxB,MAAM,MAAO;gBAED,gBAAgB,CAAC,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM;IAOzE,gBAAgB;IAKhB,OAAO;IAKP,MAAM;IAKN;;;OAGG;IACH,cAAc,CAAC,MAAM,EAAE,OAAO;IAI9B;;;OAGG;IACH,aAAa,CAAC,MAAM,EAAE,OAAO;IAI7B;;;OAGG;IACH,oBAAoB,CAAC,OAAO,EAAE,OAAO;IAIrC;;;OAGG;IACH,oBAAoB,IAAI,OAAO;IAI/B;;;OAGG;IACH,oBAAoB,CAAC,OAAO,EAAE,OAAO;IAIrC;;;OAGG;IACH,oBAAoB,IAAI,OAAO;IAI/B;;;OAGG;IACH,YAAY,CAAC,KAAK,EAAE,MAAM;IAI1B,YAAY,IAAI,MAAM;IAItB;;;;;OAKG;IACH,YAAY,CAAC,gBAAgB,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM;IAiCxE;;;OAGG;IACH,cAAc;IAkDd;;OAEG;IACH,oBAAoB;IAIpB;;OAEG;IACH,cAAc;IAId;;OAEG;IACH,mBAAmB;IAInB;;OAEG;IACH,mBAAmB;IAInB;;;;OAIG;IACH,QAAQ,CAAC,QAAQ,EAAE,MAAM;IAIzB;;;;OAIG;IACH,QAAQ,CAAC,QAAQ,EAAE,MAAM;IAIzB;;;;OAIG;IACH,OAAO,CAAC,QAAQ,EAAE,MAAM;IAIxB;;;;;OAKG;IACH,aAAa,CAAC,QAAQ,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM;IAItD;;;;OAIG;IACH,aAAa,CAAC,QAAQ,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM;IAItD;;;OAGG;IACH,qBAAqB,CAAC,aAAa,EAAE,OAAO;IAI5C;;;OAGG;IACH,oBAAoB,IAAI,OAAO;IAI/B;;;;OAIG;IACH,eAAe,CAAC,YAAY,EAAE,GAAG,EAAE,gBAAgB,EAAE,GAAG;IAcxD;;;;OAIG;IACH,eAAe,CAAC,gBAAgB,EAAE,GAAG;IAIrC;;;OAGG;IACH,YAAY,IAAI,GAAG;IAUnB;;;;OAIG;IACH,YAAY,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,EAAE,GAAG;IAKhC;;;OAGG;IACH,MAAM,CAAC,EAAE,EAAE,MAAM;IAKjB,MAAM,CAAC,MAAM,CAAC,gBAAgB,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM;CAG1E"}
|
|
@@ -0,0 +1,320 @@
|
|
|
1
|
+
import * as spine from '@esotericsoftware/spine-core';
|
|
2
|
+
import { AtlasAttachmentLoader, SkeletonJson, TextureAtlas } from '@esotericsoftware/spine-core';
|
|
3
|
+
import { _atlasLoader } from './CCSkeletonAnimation';
|
|
4
|
+
import { CanvasRenderCmd } from './CCSkeletonCanvasRenderCmd';
|
|
5
|
+
import { WebGLRenderCmd } from './CCSkeletonWebGLRenderCmd';
|
|
6
|
+
/****************************************************************************
|
|
7
|
+
Copyright (c) 2011-2012 cocos2d-x.org
|
|
8
|
+
Copyright (c) 2013-2014 Chukong Technologies Inc.
|
|
9
|
+
Copyright (c) 2014 Shengxiang Chen (Nero Chan)
|
|
10
|
+
|
|
11
|
+
http://www.cocos2d-x.org
|
|
12
|
+
|
|
13
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
14
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
15
|
+
in the Software without restriction, including without limitation the rights
|
|
16
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
17
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
18
|
+
furnished to do so, subject to the following conditions:
|
|
19
|
+
|
|
20
|
+
The above copyright notice and this permission notice shall be included in
|
|
21
|
+
all copies or substantial portions of the Software.
|
|
22
|
+
|
|
23
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
24
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
25
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
26
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
27
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
28
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
29
|
+
THE SOFTWARE.
|
|
30
|
+
****************************************************************************/
|
|
31
|
+
/**
|
|
32
|
+
* The main namespace of Spine, all classes, functions, properties and constants of Spine are defined in this namespace
|
|
33
|
+
* @namespace
|
|
34
|
+
* @name
|
|
35
|
+
*/
|
|
36
|
+
/**
|
|
37
|
+
* <p>
|
|
38
|
+
* The skeleton of Spine. <br/>
|
|
39
|
+
* Skeleton has a reference to a SkeletonData and stores the state for skeleton instance,
|
|
40
|
+
* which consists of the current pose's bone SRT, slot colors, and which slot attachments are visible. <br/>
|
|
41
|
+
* Multiple skeletons can use the same SkeletonData (which includes all animations, skins, and attachments). <br/>
|
|
42
|
+
* </p>
|
|
43
|
+
* @class
|
|
44
|
+
* @extends cc.Node
|
|
45
|
+
*/
|
|
46
|
+
export class Skeleton extends cc.Node {
|
|
47
|
+
_skeleton = null;
|
|
48
|
+
_rootBone = null;
|
|
49
|
+
_timeScale = 1;
|
|
50
|
+
_debugSlots = false;
|
|
51
|
+
_debugBones = false;
|
|
52
|
+
_premultipliedAlpha;
|
|
53
|
+
_ownsSkeletonData = null;
|
|
54
|
+
_atlas = null;
|
|
55
|
+
constructor(skeletonDataFile, atlasFile, scale) {
|
|
56
|
+
super();
|
|
57
|
+
super.init();
|
|
58
|
+
this._premultipliedAlpha = cc._renderType === cc.game.RENDER_TYPE_WEBGL && cc.OPTIMIZE_BLEND_FUNC_FOR_PREMULTIPLIED_ALPHA;
|
|
59
|
+
this.initWithArgs(skeletonDataFile, atlasFile, scale);
|
|
60
|
+
}
|
|
61
|
+
_createRenderCmd() {
|
|
62
|
+
if (cc._renderType === cc.game.RENDER_TYPE_CANVAS)
|
|
63
|
+
return new CanvasRenderCmd(this);
|
|
64
|
+
else
|
|
65
|
+
return new WebGLRenderCmd(this);
|
|
66
|
+
}
|
|
67
|
+
onEnter() {
|
|
68
|
+
super.onEnter();
|
|
69
|
+
this.scheduleUpdate();
|
|
70
|
+
}
|
|
71
|
+
onExit() {
|
|
72
|
+
this.unscheduleUpdate();
|
|
73
|
+
super.onExit();
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Sets whether open debug slots.
|
|
77
|
+
* @param {boolean} enable true to open, false to close.
|
|
78
|
+
*/
|
|
79
|
+
setDebugSolots(enable) {
|
|
80
|
+
this._debugSlots = enable;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Sets whether open debug bones.
|
|
84
|
+
* @param {boolean} enable
|
|
85
|
+
*/
|
|
86
|
+
setDebugBones(enable) {
|
|
87
|
+
this._debugBones = enable;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Sets whether open debug slots.
|
|
91
|
+
* @param {boolean} enabled true to open, false to close.
|
|
92
|
+
*/
|
|
93
|
+
setDebugSlotsEnabled(enabled) {
|
|
94
|
+
this._debugSlots = enabled;
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Gets whether open debug slots.
|
|
98
|
+
* @returns {boolean} true to open, false to close.
|
|
99
|
+
*/
|
|
100
|
+
getDebugSlotsEnabled() {
|
|
101
|
+
return this._debugSlots;
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Sets whether open debug bones.
|
|
105
|
+
* @param {boolean} enabled
|
|
106
|
+
*/
|
|
107
|
+
setDebugBonesEnabled(enabled) {
|
|
108
|
+
this._debugBones = enabled;
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Gets whether open debug bones.
|
|
112
|
+
* @returns {boolean} true to open, false to close.
|
|
113
|
+
*/
|
|
114
|
+
getDebugBonesEnabled() {
|
|
115
|
+
return this._debugBones;
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Sets the time scale of Skeleton.
|
|
119
|
+
* @param {Number} scale
|
|
120
|
+
*/
|
|
121
|
+
setTimeScale(scale) {
|
|
122
|
+
this._timeScale = scale;
|
|
123
|
+
}
|
|
124
|
+
getTimeScale() {
|
|
125
|
+
return this._timeScale;
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Initializes Skeleton with Data.
|
|
129
|
+
* @param {.spine.SkeletonData|String} skeletonDataFile
|
|
130
|
+
* @param {String|spine.Atlas|spine.SkeletonData} atlasFile atlas filename or atlas data or owns SkeletonData
|
|
131
|
+
* @param {Number} [scale] scale can be specified on the JSON or binary loader which will scale the bone positions, image sizes, and animation translations.
|
|
132
|
+
*/
|
|
133
|
+
initWithArgs(skeletonDataFile, atlasFile, scale) {
|
|
134
|
+
const argSkeletonFile = skeletonDataFile, argAtlasFile = atlasFile;
|
|
135
|
+
let skeletonData, atlas, ownsSkeletonData;
|
|
136
|
+
if (cc.isString(argSkeletonFile)) {
|
|
137
|
+
if (cc.isString(argAtlasFile)) {
|
|
138
|
+
const data = cc.loader.getRes(argAtlasFile);
|
|
139
|
+
_atlasLoader.setAtlasFile(argAtlasFile);
|
|
140
|
+
atlas = new TextureAtlas(data);
|
|
141
|
+
for (const page of atlas.pages) {
|
|
142
|
+
const texture = _atlasLoader.load(page.name);
|
|
143
|
+
page.setTexture(texture);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
scale = scale || 1 / cc.director.getContentScaleFactor();
|
|
147
|
+
const attachmentLoader = new AtlasAttachmentLoader(atlas);
|
|
148
|
+
const skeletonJsonReader = new SkeletonJson(attachmentLoader);
|
|
149
|
+
skeletonJsonReader.scale = scale;
|
|
150
|
+
const skeletonJson = cc.loader.getRes(argSkeletonFile);
|
|
151
|
+
skeletonData = skeletonJsonReader.readSkeletonData(skeletonJson);
|
|
152
|
+
atlas.dispose(skeletonJsonReader);
|
|
153
|
+
ownsSkeletonData = true;
|
|
154
|
+
}
|
|
155
|
+
else {
|
|
156
|
+
skeletonData = skeletonDataFile;
|
|
157
|
+
ownsSkeletonData = atlasFile;
|
|
158
|
+
}
|
|
159
|
+
this.setSkeletonData(skeletonData, ownsSkeletonData);
|
|
160
|
+
this.init();
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* Returns the bounding box of Skeleton.
|
|
164
|
+
* @returns {cc.Rect}
|
|
165
|
+
*/
|
|
166
|
+
getBoundingBox() {
|
|
167
|
+
let minX = cc.FLT_MAX, minY = cc.FLT_MAX, maxX = cc.FLT_MIN, maxY = cc.FLT_MIN;
|
|
168
|
+
const scaleX = this.getScaleX(), scaleY = this.getScaleY(), slots = this._skeleton.slots, VERTEX = spine.RegionAttachment;
|
|
169
|
+
let vertices;
|
|
170
|
+
for (let i = 0, slotCount = slots.length; i < slotCount; ++i) {
|
|
171
|
+
const slot = slots[i];
|
|
172
|
+
const attachment = slot.attachment;
|
|
173
|
+
if (!attachment || !(attachment instanceof spine.RegionAttachment))
|
|
174
|
+
continue;
|
|
175
|
+
vertices = spine.Utils.setArraySize([], 8, 0);
|
|
176
|
+
attachment.computeWorldVertices(slot, vertices, 0, 2);
|
|
177
|
+
minX = Math.min(minX, vertices[VERTEX.X1] * scaleX, vertices[VERTEX.X4] * scaleX, vertices[VERTEX.X2] * scaleX, vertices[VERTEX.X3] * scaleX);
|
|
178
|
+
minY = Math.min(minY, vertices[VERTEX.Y1] * scaleY, vertices[VERTEX.Y4] * scaleY, vertices[VERTEX.Y2] * scaleY, vertices[VERTEX.Y3] * scaleY);
|
|
179
|
+
maxX = Math.max(maxX, vertices[VERTEX.X1] * scaleX, vertices[VERTEX.X4] * scaleX, vertices[VERTEX.X2] * scaleX, vertices[VERTEX.X3] * scaleX);
|
|
180
|
+
maxY = Math.max(maxY, vertices[VERTEX.Y1] * scaleY, vertices[VERTEX.Y4] * scaleY, vertices[VERTEX.Y2] * scaleY, vertices[VERTEX.Y3] * scaleY);
|
|
181
|
+
}
|
|
182
|
+
const position = this.getPosition();
|
|
183
|
+
return cc.rect(position.x + minX, position.y + minY, maxX - minX, maxY - minY);
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* Computes the world SRT from the local SRT for each bone.
|
|
187
|
+
*/
|
|
188
|
+
updateWorldTransform() {
|
|
189
|
+
this._skeleton.updateWorldTransform(true);
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* Sets the bones and slots to the setup pose.
|
|
193
|
+
*/
|
|
194
|
+
setToSetupPose() {
|
|
195
|
+
this._skeleton.setToSetupPose();
|
|
196
|
+
}
|
|
197
|
+
/**
|
|
198
|
+
* Sets the bones to the setup pose, using the values from the `BoneData` list in the `SkeletonData`.
|
|
199
|
+
*/
|
|
200
|
+
setBonesToSetupPose() {
|
|
201
|
+
this._skeleton.setBonesToSetupPose();
|
|
202
|
+
}
|
|
203
|
+
/**
|
|
204
|
+
* Sets the slots to the setup pose, using the values from the `SlotData` list in the `SkeletonData`.
|
|
205
|
+
*/
|
|
206
|
+
setSlotsToSetupPose() {
|
|
207
|
+
this._skeleton.setSlotsToSetupPose();
|
|
208
|
+
}
|
|
209
|
+
/**
|
|
210
|
+
* Finds a bone by name. This does a string comparison for every bone.
|
|
211
|
+
* @param {String} boneName
|
|
212
|
+
* @returns {.spine.Bone}
|
|
213
|
+
*/
|
|
214
|
+
findBone(boneName) {
|
|
215
|
+
return this._skeleton.findBone(boneName);
|
|
216
|
+
}
|
|
217
|
+
/**
|
|
218
|
+
* Finds a slot by name. This does a string comparison for every slot.
|
|
219
|
+
* @param {String} slotName
|
|
220
|
+
* @returns {.spine.Slot}
|
|
221
|
+
*/
|
|
222
|
+
findSlot(slotName) {
|
|
223
|
+
return this._skeleton.findSlot(slotName);
|
|
224
|
+
}
|
|
225
|
+
/**
|
|
226
|
+
* Finds a skin by name and makes it the active skin. This does a string comparison for every skin. Note that setting the skin does not change which attachments are visible.
|
|
227
|
+
* @param {string} skinName
|
|
228
|
+
* @returns {.spine.Skin}
|
|
229
|
+
*/
|
|
230
|
+
setSkin(skinName) {
|
|
231
|
+
return this._skeleton.setSkinByName(skinName);
|
|
232
|
+
}
|
|
233
|
+
/**
|
|
234
|
+
* Returns the attachment for the slot and attachment name. The skeleton looks first in its skin, then in the skeleton data’s default skin.
|
|
235
|
+
* @param {String} slotName
|
|
236
|
+
* @param {String} attachmentName
|
|
237
|
+
* @returns {.spine.Attachment}
|
|
238
|
+
*/
|
|
239
|
+
getAttachment(slotName, attachmentName) {
|
|
240
|
+
return this._skeleton.getAttachmentByName(slotName, attachmentName);
|
|
241
|
+
}
|
|
242
|
+
/**
|
|
243
|
+
* Sets the attachment for the slot and attachment name. The skeleton looks first in its skin, then in the skeleton data’s default skin.
|
|
244
|
+
* @param {String} slotName
|
|
245
|
+
* @param {String} attachmentName
|
|
246
|
+
*/
|
|
247
|
+
setAttachment(slotName, attachmentName) {
|
|
248
|
+
this._skeleton.setAttachment(slotName, attachmentName);
|
|
249
|
+
}
|
|
250
|
+
/**
|
|
251
|
+
* Sets the premultiplied alpha value to Skeleton.
|
|
252
|
+
* @param {Number} alpha
|
|
253
|
+
*/
|
|
254
|
+
setPremultipliedAlpha(premultiplied) {
|
|
255
|
+
this._premultipliedAlpha = premultiplied;
|
|
256
|
+
}
|
|
257
|
+
/**
|
|
258
|
+
* Returns whether to enable premultiplied alpha.
|
|
259
|
+
* @returns {boolean}
|
|
260
|
+
*/
|
|
261
|
+
isPremultipliedAlpha() {
|
|
262
|
+
return this._premultipliedAlpha;
|
|
263
|
+
}
|
|
264
|
+
/**
|
|
265
|
+
* Sets skeleton data to Skeleton.
|
|
266
|
+
* @param {.spine.SkeletonData} skeletonData
|
|
267
|
+
* @param {.spine.SkeletonData} ownsSkeletonData
|
|
268
|
+
*/
|
|
269
|
+
setSkeletonData(skeletonData, ownsSkeletonData) {
|
|
270
|
+
if (skeletonData.width != null && skeletonData.height != null)
|
|
271
|
+
this.setContentSize(skeletonData.width / cc.director.getContentScaleFactor(), skeletonData.height / cc.director.getContentScaleFactor());
|
|
272
|
+
this._skeleton = new spine.Skeleton(skeletonData);
|
|
273
|
+
this._skeleton.updateWorldTransform(true);
|
|
274
|
+
this._rootBone = this._skeleton.getRootBone();
|
|
275
|
+
this._ownsSkeletonData = ownsSkeletonData;
|
|
276
|
+
this._renderCmd._createChildFormSkeletonData();
|
|
277
|
+
}
|
|
278
|
+
/**
|
|
279
|
+
* Return the renderer of attachment.
|
|
280
|
+
* @param {.spine.RegionAttachment|.spine.BoundingBoxAttachment} regionAttachment
|
|
281
|
+
* @returns {.spine.TextureAtlasRegion}
|
|
282
|
+
*/
|
|
283
|
+
getTextureAtlas(regionAttachment) {
|
|
284
|
+
return regionAttachment.region;
|
|
285
|
+
}
|
|
286
|
+
/**
|
|
287
|
+
* Returns the blendFunc of Skeleton.
|
|
288
|
+
* @returns {cc.BlendFunc}
|
|
289
|
+
*/
|
|
290
|
+
getBlendFunc() {
|
|
291
|
+
const slot = this._skeleton.drawOrder[0];
|
|
292
|
+
if (slot) {
|
|
293
|
+
const blend = this._renderCmd._getBlendFunc(slot.data.blendMode, this._premultipliedAlpha);
|
|
294
|
+
return blend;
|
|
295
|
+
}
|
|
296
|
+
else {
|
|
297
|
+
return {};
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
setBlendFunc() {
|
|
301
|
+
return;
|
|
302
|
+
}
|
|
303
|
+
/**
|
|
304
|
+
* Update will be called automatically every frame if "scheduleUpdate" is called when the node is "live".
|
|
305
|
+
* @param {Number} dt Delta time since last update
|
|
306
|
+
*/
|
|
307
|
+
update(dt) {
|
|
308
|
+
this._skeleton.update(dt);
|
|
309
|
+
}
|
|
310
|
+
// Static create method
|
|
311
|
+
static create(skeletonDataFile, atlasFile, scale) {
|
|
312
|
+
return new Skeleton(skeletonDataFile, atlasFile, scale);
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
cc.defineGetterSetter(Skeleton.prototype, 'opacityModifyRGB', Skeleton.prototype.isOpacityModifyRGB);
|
|
316
|
+
// For renderer webgl to identify skeleton's default texture and blend function
|
|
317
|
+
cc.defineGetterSetter(Skeleton.prototype, '_blendFunc', Skeleton.prototype.getBlendFunc);
|
|
318
|
+
cc.defineGetterSetter(Skeleton.prototype, '_texture', function () {
|
|
319
|
+
return this._renderCmd._currTexture;
|
|
320
|
+
});
|