@safe-engine/cocos 2.2.8 → 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/@types/index.d.ts +0 -59
- package/dist/app.d.ts +1 -1
- package/dist/app.d.ts.map +1 -1
- package/dist/app.js +25 -23
- 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/collider/CollideComponent.d.ts +21 -3
- package/dist/collider/CollideComponent.d.ts.map +1 -1
- package/dist/core/NodeComp.d.ts +1 -1
- package/dist/core/NodeComp.d.ts.map +1 -1
- package/dist/dragonbones/DragonBonesComp.d.ts +4 -6
- package/dist/dragonbones/DragonBonesComp.d.ts.map +1 -1
- package/dist/dragonbones/DragonBonesComp.js +15 -13
- package/dist/dragonbones/DragonBonesSystem.d.ts +1 -1
- package/dist/dragonbones/DragonBonesSystem.d.ts.map +1 -1
- package/dist/dragonbones/DragonBonesSystem.js +42 -35
- package/dist/dragonbones/db-cocos/CocosArmatureDisplay.d.ts +87 -0
- package/dist/dragonbones/db-cocos/CocosArmatureDisplay.d.ts.map +1 -0
- package/dist/dragonbones/db-cocos/CocosArmatureDisplay.js +240 -0
- package/dist/dragonbones/db-cocos/CocosFactory.d.ts +127 -0
- package/dist/dragonbones/db-cocos/CocosFactory.d.ts.map +1 -0
- package/dist/dragonbones/db-cocos/CocosFactory.js +186 -0
- package/dist/dragonbones/db-cocos/CocosSlot.d.ts +52 -0
- package/dist/dragonbones/db-cocos/CocosSlot.d.ts.map +1 -0
- package/dist/dragonbones/db-cocos/CocosSlot.js +365 -0
- package/dist/dragonbones/db-cocos/CocosTextureAtlasData.d.ts +53 -0
- package/dist/dragonbones/db-cocos/CocosTextureAtlasData.d.ts.map +1 -0
- package/dist/dragonbones/db-cocos/CocosTextureAtlasData.js +121 -0
- 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/dragonbones/index.d.ts +0 -1
- package/dist/dragonbones/index.d.ts.map +1 -1
- package/dist/dragonbones/index.js +0 -1
- package/dist/polyfills.d.ts +1 -1
- package/dist/polyfills.d.ts.map +1 -1
- package/dist/polyfills.js +1 -2
- package/dist/render/RenderComponent.d.ts.map +1 -1
- package/dist/render/RenderComponent.js +1 -0
- package/dist/render/RenderSystem.d.ts.map +1 -1
- package/dist/render/RenderSystem.js +34 -2
- package/dist/richtext/RichTextComp.js +1 -1
- package/dist/spine/SpineSkeleton.d.ts +5 -3
- package/dist/spine/SpineSkeleton.d.ts.map +1 -1
- package/dist/spine/SpineSkeleton.js +12 -5
- package/dist/spine/SpineSystem.d.ts +1 -2
- package/dist/spine/SpineSystem.d.ts.map +1 -1
- package/dist/spine/SpineSystem.js +22 -24
- package/dist/spine/index.d.ts +0 -1
- package/dist/spine/index.d.ts.map +1 -1
- package/dist/spine/index.js +14 -2
- package/dist/spine/spine-cocos/CCSkeleton.d.ts +86 -0
- package/dist/spine/spine-cocos/CCSkeleton.d.ts.map +1 -0
- package/dist/spine/spine-cocos/CCSkeleton.js +231 -0
- package/dist/spine/spine-cocos/CCSkeletonAnimation.d.ts +88 -0
- package/dist/spine/spine-cocos/CCSkeletonAnimation.d.ts.map +1 -0
- package/dist/spine/spine-cocos/CCSkeletonAnimation.js +251 -0
- package/dist/spine/spine-cocos/CCSkeletonCanvasRenderCmd.d.ts +28 -0
- package/dist/spine/spine-cocos/CCSkeletonCanvasRenderCmd.d.ts.map +1 -0
- package/dist/spine/spine-cocos/CCSkeletonCanvasRenderCmd.js +224 -0
- package/dist/spine/spine-cocos/CCSkeletonTexture.d.ts +36 -0
- package/dist/spine/spine-cocos/CCSkeletonTexture.d.ts.map +1 -0
- package/dist/spine/spine-cocos/CCSkeletonTexture.js +59 -0
- package/dist/spine/spine-cocos/CCSkeletonWebGLRenderCmd.d.ts +28 -0
- package/dist/spine/spine-cocos/CCSkeletonWebGLRenderCmd.d.ts.map +1 -0
- package/dist/spine/spine-cocos/CCSkeletonWebGLRenderCmd.js +277 -0
- package/package.json +6 -7
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The MIT License (MIT)
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) 2012-2018 DragonBones team and other contributors
|
|
5
|
+
*
|
|
6
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
7
|
+
* this software and associated documentation files (the "Software"), to deal in
|
|
8
|
+
* the Software without restriction, including without limitation the rights to
|
|
9
|
+
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
|
10
|
+
* the Software, and to permit persons to whom the Software is furnished to do so,
|
|
11
|
+
* subject to the following conditions:
|
|
12
|
+
*
|
|
13
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
14
|
+
* copies or substantial portions of the Software.
|
|
15
|
+
*
|
|
16
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
|
18
|
+
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
|
19
|
+
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
|
20
|
+
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
21
|
+
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
22
|
+
*/
|
|
23
|
+
import { BaseObject, TextureAtlasData, TextureData } from '@cocos/dragonbones-js';
|
|
24
|
+
export class CocosTextureAtlasData extends TextureAtlasData {
|
|
25
|
+
static toString() {
|
|
26
|
+
return '[class dragonBones.CocosTextureAtlasData]';
|
|
27
|
+
}
|
|
28
|
+
_renderTexture = null; // Initial value.
|
|
29
|
+
_onClear() {
|
|
30
|
+
super._onClear();
|
|
31
|
+
if (this._renderTexture !== null) {
|
|
32
|
+
// this._renderTexture.dispose();
|
|
33
|
+
}
|
|
34
|
+
this._renderTexture = null;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* @inheritDoc
|
|
38
|
+
*/
|
|
39
|
+
createTexture() {
|
|
40
|
+
return BaseObject.borrowObject(CocosTextureData);
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* - The CocosJS texture.
|
|
44
|
+
* @version DragonBones 3.0
|
|
45
|
+
* @language en_US
|
|
46
|
+
*/
|
|
47
|
+
/**
|
|
48
|
+
* - CocosJS 贴图。
|
|
49
|
+
* @version DragonBones 3.0
|
|
50
|
+
* @language zh_CN
|
|
51
|
+
*/
|
|
52
|
+
get renderTexture() {
|
|
53
|
+
return this._renderTexture;
|
|
54
|
+
}
|
|
55
|
+
set renderTexture(value) {
|
|
56
|
+
if (this._renderTexture === value) {
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
this._renderTexture = value;
|
|
60
|
+
if (this._renderTexture !== null) {
|
|
61
|
+
for (const k in this.textures) {
|
|
62
|
+
const textureData = this.textures[k];
|
|
63
|
+
// if (textureData.renderTexture !== null) {
|
|
64
|
+
// textureData.renderTexture.destroy();
|
|
65
|
+
// }
|
|
66
|
+
// console.log('textureData', this._renderTexture, textureData)
|
|
67
|
+
// console.log('this._renderTexture', this._renderTexture)
|
|
68
|
+
const x = textureData.region.x;
|
|
69
|
+
const y = textureData.region.y;
|
|
70
|
+
const rotated = textureData.rotated;
|
|
71
|
+
const width = rotated ? textureData.region.height : textureData.region.width;
|
|
72
|
+
const height = rotated ? textureData.region.width : textureData.region.height;
|
|
73
|
+
const rect = cc.rect(x, y, width, height);
|
|
74
|
+
const offset = cc.p(0, 0);
|
|
75
|
+
const originSize = cc.size(width, height);
|
|
76
|
+
if (textureData.frame) {
|
|
77
|
+
const px = -textureData.frame.x;
|
|
78
|
+
const py = -textureData.frame.y;
|
|
79
|
+
originSize.width = textureData.frame.width;
|
|
80
|
+
originSize.height = textureData.frame.height;
|
|
81
|
+
// offset = sprite center - trimed texture center
|
|
82
|
+
const cx1 = px + rect.width / 2;
|
|
83
|
+
const cy1 = originSize.height - py - rect.height / 2;
|
|
84
|
+
const cx2 = originSize.width / 2;
|
|
85
|
+
const cy2 = originSize.height / 2;
|
|
86
|
+
offset.x = cx2 - cx1;
|
|
87
|
+
offset.y = cy2 - cy1;
|
|
88
|
+
}
|
|
89
|
+
// sprite
|
|
90
|
+
const spriteFrame = new cc.SpriteFrame(this._renderTexture, rect, textureData.rotated, offset, originSize);
|
|
91
|
+
// console.log('sf', sf)
|
|
92
|
+
textureData.spriteFrame = spriteFrame;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
else {
|
|
96
|
+
for (const k in this.textures) {
|
|
97
|
+
const textureData = this.textures[k];
|
|
98
|
+
// if (textureData.renderTexture !== null) {
|
|
99
|
+
// textureData.renderTexture.destroy();
|
|
100
|
+
// }
|
|
101
|
+
textureData.spriteFrame = null;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* @internal
|
|
108
|
+
*/
|
|
109
|
+
export class CocosTextureData extends TextureData {
|
|
110
|
+
static toString() {
|
|
111
|
+
return '[class dragonBones.CocosTextureData]';
|
|
112
|
+
}
|
|
113
|
+
spriteFrame = null; // Initial value.
|
|
114
|
+
_onClear() {
|
|
115
|
+
super._onClear();
|
|
116
|
+
// if (this.spriteFrame !== null) {
|
|
117
|
+
// this.spriteFrame.destroy();
|
|
118
|
+
// }
|
|
119
|
+
this.spriteFrame = null;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
export declare class SimpleMeshNode extends cc.Node {
|
|
2
|
+
_texture: any;
|
|
3
|
+
_vertices: Float32Array | null;
|
|
4
|
+
_uvs: Float32Array | null;
|
|
5
|
+
_indices: Uint16Array | null;
|
|
6
|
+
_gl: WebGLRenderingContext | null;
|
|
7
|
+
_program: WebGLProgram | null;
|
|
8
|
+
_vbo: WebGLBuffer | null;
|
|
9
|
+
_uvbo: WebGLBuffer | null;
|
|
10
|
+
_ibo: WebGLBuffer | null;
|
|
11
|
+
_needsUpload: boolean;
|
|
12
|
+
_alpha: number;
|
|
13
|
+
_fallbackDraw: cc.DrawNode;
|
|
14
|
+
_useWebGL: boolean;
|
|
15
|
+
constructor(texture?: cc.Texture2D, vertices?: Float32Array, uvs?: Float32Array, indices?: Uint16Array);
|
|
16
|
+
_updateContentSizeFromVertices(): void;
|
|
17
|
+
setVertices(verts: Float32Array): void;
|
|
18
|
+
setUVs(uvs: Float32Array): void;
|
|
19
|
+
setIndices(inds: Uint16Array): void;
|
|
20
|
+
setTexture(tex: cc.Texture2D): void;
|
|
21
|
+
setSpriteFrame(renderTexture: any): void;
|
|
22
|
+
visit(ctx?: unknown): void;
|
|
23
|
+
_drawMesh(): void;
|
|
24
|
+
_ensureGL(): void;
|
|
25
|
+
_computeModelMatrixFromNode(): Float32Array;
|
|
26
|
+
_drawMeshWebGL(): void;
|
|
27
|
+
_drawMeshCanvasFallback(): void;
|
|
28
|
+
setAlpha(a: number): void;
|
|
29
|
+
static createQuad(x: number, y: number, w: number, h: number, u0: number, v0: number, uw: number, vh: number): {
|
|
30
|
+
vertices: Float32Array<ArrayBuffer>;
|
|
31
|
+
uvs: Float32Array<ArrayBuffer>;
|
|
32
|
+
indices: Uint16Array<ArrayBuffer>;
|
|
33
|
+
};
|
|
34
|
+
onExit(): void;
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=SimpleMeshNode.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SimpleMeshNode.d.ts","sourceRoot":"","sources":["../../../src/dragonbones/db-cocos/SimpleMeshNode.ts"],"names":[],"mappings":"AAOA,qBAAa,cAAe,SAAQ,EAAE,CAAC,IAAI;IAEzC,QAAQ,EAAE,GAAG,CAAO;IACpB,SAAS,EAAE,YAAY,GAAG,IAAI,CAAO;IACrC,IAAI,EAAE,YAAY,GAAG,IAAI,CAAO;IAChC,QAAQ,EAAE,WAAW,GAAG,IAAI,CAAO;IAGnC,GAAG,EAAE,qBAAqB,GAAG,IAAI,CAAO;IACxC,QAAQ,EAAE,YAAY,GAAG,IAAI,CAAO;IACpC,IAAI,EAAE,WAAW,GAAG,IAAI,CAAO;IAC/B,KAAK,EAAE,WAAW,GAAG,IAAI,CAAO;IAChC,IAAI,EAAE,WAAW,GAAG,IAAI,CAAO;IAC/B,YAAY,UAAO;IACnB,MAAM,SAAM;IAGZ,aAAa,EAAE,EAAE,CAAC,QAAQ,CAAO;IACjC,SAAS,UAAO;gBAEJ,OAAO,CAAC,EAAE,EAAE,CAAC,SAAS,EAAE,QAAQ,CAAC,EAAE,YAAY,EAAE,GAAG,CAAC,EAAE,YAAY,EAAE,OAAO,CAAC,EAAE,WAAW;IAiBtG,8BAA8B,IAAI,IAAI;IAmBtC,WAAW,CAAC,KAAK,EAAE,YAAY,GAAG,IAAI;IAMtC,MAAM,CAAC,GAAG,EAAE,YAAY,GAAG,IAAI;IAK/B,UAAU,CAAC,IAAI,EAAE,WAAW,GAAG,IAAI;IAKnC,UAAU,CAAC,GAAG,EAAE,EAAE,CAAC,SAAS,GAAG,IAAI;IAGnC,cAAc,CAAC,aAAa,KAAA;IAK5B,KAAK,CAAC,GAAG,CAAC,EAAE,OAAO,GAAG,IAAI;IAU1B,SAAS,IAAI,IAAI;IAQjB,SAAS,IAAI,IAAI;IAuEjB,2BAA2B,IAAI,YAAY;IA0D3C,cAAc,IAAI,IAAI;IAkGtB,uBAAuB,IAAI,IAAI;IAuB/B,QAAQ,CAAC,CAAC,EAAE,MAAM,GAAG,IAAI;IAKzB,MAAM,CAAC,UAAU,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM;;;;;IAU5G,MAAM,IAAI,IAAI;CAcf"}
|
|
@@ -0,0 +1,354 @@
|
|
|
1
|
+
// cc.SimpleMeshNode.ts
|
|
2
|
+
// SimpleMesh as a cc.Node for Cocos2d-html5 (WebGL primary).
|
|
3
|
+
// Converted to ES6/TypeScript class from legacy Cocos-style object literal.
|
|
4
|
+
// Usage:
|
|
5
|
+
// const node = new SimpleMeshNode(texture, verts, uvs, inds);
|
|
6
|
+
// node.setPosition(x,y); node.setRotation(angleDeg); node.setScale(s);
|
|
7
|
+
export class SimpleMeshNode extends cc.Node {
|
|
8
|
+
// public mesh data (Float32Array / Uint16Array)
|
|
9
|
+
_texture = null;
|
|
10
|
+
_vertices = null;
|
|
11
|
+
_uvs = null;
|
|
12
|
+
_indices = null;
|
|
13
|
+
// GL internals
|
|
14
|
+
_gl = null;
|
|
15
|
+
_program = null;
|
|
16
|
+
_vbo = null;
|
|
17
|
+
_uvbo = null;
|
|
18
|
+
_ibo = null;
|
|
19
|
+
_needsUpload = true;
|
|
20
|
+
_alpha = 1.0;
|
|
21
|
+
// fallback drawnode for Canvas or debug
|
|
22
|
+
_fallbackDraw = null;
|
|
23
|
+
_useWebGL = true;
|
|
24
|
+
constructor(texture, vertices, uvs, indices) {
|
|
25
|
+
super();
|
|
26
|
+
super.ctor();
|
|
27
|
+
this._texture = texture || null;
|
|
28
|
+
this._vertices = vertices || new Float32Array(0);
|
|
29
|
+
this._uvs = uvs || new Float32Array(0);
|
|
30
|
+
this._indices = indices || new Uint16Array(0);
|
|
31
|
+
this._fallbackDraw = new cc.DrawNode();
|
|
32
|
+
this._useWebGL = !!cc._renderContext;
|
|
33
|
+
// size/anchor auto-estimate from vertex bounds (optional)
|
|
34
|
+
this._updateContentSizeFromVertices();
|
|
35
|
+
}
|
|
36
|
+
// helper to estimate contentSize and anchor if needed
|
|
37
|
+
_updateContentSizeFromVertices() {
|
|
38
|
+
if (!this._vertices || this._vertices.length < 2)
|
|
39
|
+
return;
|
|
40
|
+
let minX = Number.POSITIVE_INFINITY, minY = Number.POSITIVE_INFINITY;
|
|
41
|
+
let maxX = Number.NEGATIVE_INFINITY, maxY = Number.NEGATIVE_INFINITY;
|
|
42
|
+
for (let i = 0; i < this._vertices.length; i += 2) {
|
|
43
|
+
const x = this._vertices[i], y = this._vertices[i + 1];
|
|
44
|
+
if (x < minX)
|
|
45
|
+
minX = x;
|
|
46
|
+
if (y < minY)
|
|
47
|
+
minY = y;
|
|
48
|
+
if (x > maxX)
|
|
49
|
+
maxX = x;
|
|
50
|
+
if (y > maxY)
|
|
51
|
+
maxY = y;
|
|
52
|
+
}
|
|
53
|
+
if (minX === Infinity)
|
|
54
|
+
return;
|
|
55
|
+
this.setContentSize(maxX - minX, maxY - minY);
|
|
56
|
+
// set anchor relative to local coordinates (default 0,0), keep at 0,0 for compatibility
|
|
57
|
+
}
|
|
58
|
+
setVertices(verts) {
|
|
59
|
+
this._vertices = verts;
|
|
60
|
+
this._needsUpload = true;
|
|
61
|
+
this._updateContentSizeFromVertices();
|
|
62
|
+
}
|
|
63
|
+
setUVs(uvs) {
|
|
64
|
+
this._uvs = uvs;
|
|
65
|
+
this._needsUpload = true;
|
|
66
|
+
}
|
|
67
|
+
setIndices(inds) {
|
|
68
|
+
this._indices = inds;
|
|
69
|
+
this._needsUpload = true;
|
|
70
|
+
}
|
|
71
|
+
setTexture(tex) {
|
|
72
|
+
this._texture = tex;
|
|
73
|
+
}
|
|
74
|
+
setSpriteFrame(renderTexture) {
|
|
75
|
+
this._texture = renderTexture._texture;
|
|
76
|
+
}
|
|
77
|
+
// override visit to draw mesh at correct point in scene graph
|
|
78
|
+
visit(ctx) {
|
|
79
|
+
// normal visit to draw children etc.
|
|
80
|
+
super.visit(ctx);
|
|
81
|
+
// draw our mesh after node's transform is applied (so position/rotation/scale are final)
|
|
82
|
+
// Note: calling AFTER visit ensures it's rendered on top of children; change if you want otherwise.
|
|
83
|
+
this._drawMesh();
|
|
84
|
+
}
|
|
85
|
+
// core drawing function
|
|
86
|
+
_drawMesh() {
|
|
87
|
+
if (this._useWebGL && cc._renderContext) {
|
|
88
|
+
this._drawMeshWebGL();
|
|
89
|
+
}
|
|
90
|
+
else {
|
|
91
|
+
this._drawMeshCanvasFallback();
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
_ensureGL() {
|
|
95
|
+
if (this._gl && this._program)
|
|
96
|
+
return;
|
|
97
|
+
const gl = cc._renderContext;
|
|
98
|
+
if (!gl) {
|
|
99
|
+
this._useWebGL = false;
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
this._gl = gl;
|
|
103
|
+
const vsSrc = [
|
|
104
|
+
'attribute vec2 a_position;',
|
|
105
|
+
'attribute vec2 a_texcoord;',
|
|
106
|
+
'uniform mat3 u_model;',
|
|
107
|
+
'uniform vec2 u_resolution;',
|
|
108
|
+
'varying vec2 v_uv;',
|
|
109
|
+
'void main() {',
|
|
110
|
+
' vec2 pos = (u_model * vec3(a_position, 1.0)).xy;',
|
|
111
|
+
' vec2 zeroToOne = pos / u_resolution;',
|
|
112
|
+
' vec2 zeroToTwo = zeroToOne * 2.0;',
|
|
113
|
+
' vec2 clipSpace = zeroToTwo - 1.0;',
|
|
114
|
+
' gl_Position = vec4(clipSpace * vec2(1.0, -1.0), 0.0, 1.0);',
|
|
115
|
+
' v_uv = a_texcoord;',
|
|
116
|
+
'}',
|
|
117
|
+
].join('\n');
|
|
118
|
+
const fsSrc = [
|
|
119
|
+
'precision mediump float;',
|
|
120
|
+
'varying vec2 v_uv;',
|
|
121
|
+
'uniform sampler2D u_texture;',
|
|
122
|
+
'uniform float u_alpha;',
|
|
123
|
+
'void main() {',
|
|
124
|
+
' vec4 c = texture2D(u_texture, v_uv);',
|
|
125
|
+
' gl_FragColor = vec4(c.rgb, c.a * u_alpha);',
|
|
126
|
+
'}',
|
|
127
|
+
].join('\n');
|
|
128
|
+
const compileShader = function (gl, src, type) {
|
|
129
|
+
const s = gl.createShader(type);
|
|
130
|
+
if (!s)
|
|
131
|
+
return null;
|
|
132
|
+
gl.shaderSource(s, src);
|
|
133
|
+
gl.compileShader(s);
|
|
134
|
+
if (!gl.getShaderParameter(s, gl.COMPILE_STATUS)) {
|
|
135
|
+
cc.log(`SimpleMesh shader compile error:\n${gl.getShaderInfoLog(s)}`);
|
|
136
|
+
gl.deleteShader(s);
|
|
137
|
+
return null;
|
|
138
|
+
}
|
|
139
|
+
return s;
|
|
140
|
+
};
|
|
141
|
+
const vs = compileShader(gl, vsSrc, gl.VERTEX_SHADER);
|
|
142
|
+
const fs = compileShader(gl, fsSrc, gl.FRAGMENT_SHADER);
|
|
143
|
+
if (!vs || !fs)
|
|
144
|
+
return;
|
|
145
|
+
const prog = gl.createProgram();
|
|
146
|
+
if (!prog)
|
|
147
|
+
return;
|
|
148
|
+
gl.attachShader(prog, vs);
|
|
149
|
+
gl.attachShader(prog, fs);
|
|
150
|
+
gl.linkProgram(prog);
|
|
151
|
+
if (!gl.getProgramParameter(prog, gl.LINK_STATUS)) {
|
|
152
|
+
cc.log(`SimpleMesh program link error:\n${gl.getProgramInfoLog(prog)}`);
|
|
153
|
+
gl.deleteProgram(prog);
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
this._program = prog;
|
|
157
|
+
// buffers
|
|
158
|
+
this._vbo = gl.createBuffer();
|
|
159
|
+
this._uvbo = gl.createBuffer();
|
|
160
|
+
this._ibo = gl.createBuffer();
|
|
161
|
+
}
|
|
162
|
+
// compute model matrix using node's transform: we want map local mesh coords (as-specified) through node's world transform
|
|
163
|
+
_computeModelMatrixFromNode() {
|
|
164
|
+
// get node world transform: use node's nodeToWorldAffine / getNodeToParentTransform?
|
|
165
|
+
// Simpler: use node.getNodeToWorldTransform() if available to get 4x4 matrix,
|
|
166
|
+
// but to keep it engine-agnostic we build 2D model from node's world position/rotation/scale.
|
|
167
|
+
const worldRotation = this.getNodeToWorldTransform
|
|
168
|
+
? (function () {
|
|
169
|
+
try {
|
|
170
|
+
const t = this.getNodeToWorldTransform();
|
|
171
|
+
const a = t.a, b = t.b, c = t.c, d = t.d, tx = t.tx, ty = t.ty;
|
|
172
|
+
const rot = (Math.atan2(b, a) * 180) / Math.PI;
|
|
173
|
+
const sx = Math.sqrt(a * a + b * b);
|
|
174
|
+
const sy = Math.sqrt(c * c + d * d);
|
|
175
|
+
return { rot: rot, sx: sx, sy: sy, tx: tx, ty: ty };
|
|
176
|
+
}
|
|
177
|
+
catch {
|
|
178
|
+
return null;
|
|
179
|
+
}
|
|
180
|
+
})()
|
|
181
|
+
: null;
|
|
182
|
+
let tx, ty, rotDeg, sx, sy;
|
|
183
|
+
if (worldRotation) {
|
|
184
|
+
tx = worldRotation.tx;
|
|
185
|
+
ty = worldRotation.ty;
|
|
186
|
+
rotDeg = worldRotation.rot;
|
|
187
|
+
sx = worldRotation.sx;
|
|
188
|
+
sy = worldRotation.sy;
|
|
189
|
+
}
|
|
190
|
+
else {
|
|
191
|
+
const worldPt = this.convertToWorldSpaceAR ? this.convertToWorldSpaceAR(cc.p(0, 0)) : { x: 0, y: 0 };
|
|
192
|
+
tx = worldPt.x;
|
|
193
|
+
ty = worldPt.y;
|
|
194
|
+
rotDeg = this.getRotation ? this.getRotation() : this.rotation || 0;
|
|
195
|
+
sx = this.getScaleX ? this.getScaleX() : this.scaleX || 1;
|
|
196
|
+
sy = this.getScaleY ? this.getScaleY() : this.scaleY || 1;
|
|
197
|
+
}
|
|
198
|
+
const rad = ((rotDeg || 0) * Math.PI) / 180.0;
|
|
199
|
+
const cos = Math.cos(rad), sin = Math.sin(rad);
|
|
200
|
+
const a = cos * sx;
|
|
201
|
+
const b = sin * sx;
|
|
202
|
+
const c = -sin * sy;
|
|
203
|
+
const d = cos * sy;
|
|
204
|
+
const anchor = this.getAnchorPoint ? this.getAnchorPoint() : { x: 0, y: 0 };
|
|
205
|
+
const aw = anchor.x * this.width;
|
|
206
|
+
const ah = anchor.y * this.height;
|
|
207
|
+
const e = tx - (a * aw + c * ah);
|
|
208
|
+
const f = ty - (b * aw + d * ah);
|
|
209
|
+
return new Float32Array([a, b, 0, c, d, 0, e, f, 1]);
|
|
210
|
+
}
|
|
211
|
+
_drawMeshWebGL() {
|
|
212
|
+
const gl = cc._renderContext;
|
|
213
|
+
if (!gl) {
|
|
214
|
+
this._useWebGL = false;
|
|
215
|
+
return;
|
|
216
|
+
}
|
|
217
|
+
this._ensureGL();
|
|
218
|
+
if (!this._program)
|
|
219
|
+
return;
|
|
220
|
+
if (!this._vertices || !this._uvs || !this._indices)
|
|
221
|
+
return;
|
|
222
|
+
if (this._vertices.length / 2 !== this._uvs.length / 2)
|
|
223
|
+
return;
|
|
224
|
+
gl.useProgram(this._program);
|
|
225
|
+
// upload if needed
|
|
226
|
+
if (this._needsUpload) {
|
|
227
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, this._vbo);
|
|
228
|
+
gl.bufferData(gl.ARRAY_BUFFER, this._vertices, gl.DYNAMIC_DRAW);
|
|
229
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, this._uvbo);
|
|
230
|
+
gl.bufferData(gl.ARRAY_BUFFER, this._uvs, gl.STATIC_DRAW);
|
|
231
|
+
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, this._ibo);
|
|
232
|
+
gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, this._indices, gl.STATIC_DRAW);
|
|
233
|
+
this._needsUpload = false;
|
|
234
|
+
}
|
|
235
|
+
else {
|
|
236
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, this._vbo);
|
|
237
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, this._uvbo);
|
|
238
|
+
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, this._ibo);
|
|
239
|
+
}
|
|
240
|
+
const aPosLoc = gl.getAttribLocation(this._program, 'a_position');
|
|
241
|
+
const aUVLoc = gl.getAttribLocation(this._program, 'a_texcoord');
|
|
242
|
+
// vertices
|
|
243
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, this._vbo);
|
|
244
|
+
gl.enableVertexAttribArray(aPosLoc);
|
|
245
|
+
gl.vertexAttribPointer(aPosLoc, 2, gl.FLOAT, false, 0, 0);
|
|
246
|
+
// uvs
|
|
247
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, this._uvbo);
|
|
248
|
+
gl.enableVertexAttribArray(aUVLoc);
|
|
249
|
+
gl.vertexAttribPointer(aUVLoc, 2, gl.FLOAT, false, 0, 0);
|
|
250
|
+
// bind texture
|
|
251
|
+
if (this._texture) {
|
|
252
|
+
gl.activeTexture(gl.TEXTURE0);
|
|
253
|
+
const webTex = this._texture._webTextureObj || (this._texture.getTexture ? this._texture.getTexture() : null);
|
|
254
|
+
// console.log(gl.TEXTURE_2D, webTex)
|
|
255
|
+
if (webTex) {
|
|
256
|
+
gl.bindTexture(gl.TEXTURE_2D, webTex._webTextureObj);
|
|
257
|
+
}
|
|
258
|
+
else {
|
|
259
|
+
const img = this._texture.getHtmlElementObj ? this._texture.getHtmlElementObj() : this._texture;
|
|
260
|
+
if (img) {
|
|
261
|
+
const tmp = gl.createTexture();
|
|
262
|
+
gl.bindTexture(gl.TEXTURE_2D, tmp);
|
|
263
|
+
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, img);
|
|
264
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR);
|
|
265
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
const uTexLoc = gl.getUniformLocation(this._program, 'u_texture');
|
|
269
|
+
gl.uniform1i(uTexLoc, 0);
|
|
270
|
+
}
|
|
271
|
+
else {
|
|
272
|
+
gl.bindTexture(gl.TEXTURE_2D, null);
|
|
273
|
+
}
|
|
274
|
+
// resolution
|
|
275
|
+
const uResLoc = gl.getUniformLocation(this._program, 'u_resolution');
|
|
276
|
+
const viewAny = cc.view;
|
|
277
|
+
const sz = viewAny.getFrameSize
|
|
278
|
+
? viewAny.getFrameSize()
|
|
279
|
+
: { width: cc.director.getWinSize().width, height: cc.director.getWinSize().height };
|
|
280
|
+
gl.uniform2f(uResLoc, sz.width, sz.height);
|
|
281
|
+
// model matrix from node
|
|
282
|
+
const uModelLoc = gl.getUniformLocation(this._program, 'u_model');
|
|
283
|
+
const modelMat = this._computeModelMatrixFromNode();
|
|
284
|
+
gl.uniformMatrix3fv(uModelLoc, false, modelMat);
|
|
285
|
+
// alpha
|
|
286
|
+
const uAlphaLoc = gl.getUniformLocation(this._program, 'u_alpha');
|
|
287
|
+
gl.uniform1f(uAlphaLoc, this._alpha || 1.0);
|
|
288
|
+
// blending
|
|
289
|
+
gl.enable(gl.BLEND);
|
|
290
|
+
gl.blendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA);
|
|
291
|
+
// draw
|
|
292
|
+
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, this._ibo);
|
|
293
|
+
gl.drawElements(gl.TRIANGLES, this._indices.length, gl.UNSIGNED_SHORT, 0);
|
|
294
|
+
// cleanup
|
|
295
|
+
gl.disableVertexAttribArray(aPosLoc);
|
|
296
|
+
gl.disableVertexAttribArray(aUVLoc);
|
|
297
|
+
}
|
|
298
|
+
// simple canvas fallback: just draw bounding box for visibility
|
|
299
|
+
_drawMeshCanvasFallback() {
|
|
300
|
+
if (!this._fallbackDraw.parent) {
|
|
301
|
+
this.addChild(this._fallbackDraw);
|
|
302
|
+
}
|
|
303
|
+
this._fallbackDraw.clear();
|
|
304
|
+
if (!this._vertices || this._vertices.length < 2)
|
|
305
|
+
return;
|
|
306
|
+
let minX = Number.POSITIVE_INFINITY, minY = Number.POSITIVE_INFINITY;
|
|
307
|
+
let maxX = Number.NEGATIVE_INFINITY, maxY = Number.NEGATIVE_INFINITY;
|
|
308
|
+
for (let i = 0; i < this._vertices.length; i += 2) {
|
|
309
|
+
const x = this._vertices[i], y = this._vertices[i + 1];
|
|
310
|
+
if (x < minX)
|
|
311
|
+
minX = x;
|
|
312
|
+
if (y < minY)
|
|
313
|
+
minY = y;
|
|
314
|
+
if (x > maxX)
|
|
315
|
+
maxX = x;
|
|
316
|
+
if (y > maxY)
|
|
317
|
+
maxY = y;
|
|
318
|
+
}
|
|
319
|
+
const rect = [cc.p(minX, minY), cc.p(maxX, minY), cc.p(maxX, maxY), cc.p(minX, maxY)];
|
|
320
|
+
this._fallbackDraw.drawPoly(rect, null, 1, cc.color(255, 0, 0, 255));
|
|
321
|
+
}
|
|
322
|
+
// set alpha multiplier
|
|
323
|
+
setAlpha(a) {
|
|
324
|
+
this._alpha = a;
|
|
325
|
+
}
|
|
326
|
+
// convenience static to create a quad mesh
|
|
327
|
+
static createQuad(x, y, w, h, u0, v0, uw, vh) {
|
|
328
|
+
const verts = new Float32Array([x, y, x + w, y, x + w, y + h, x, y + h]);
|
|
329
|
+
const u1 = u0 + uw, v1 = v0 + vh;
|
|
330
|
+
const uvs = new Float32Array([u0, v0, u1, v0, u1, v1, u0, v1]);
|
|
331
|
+
const inds = new Uint16Array([0, 1, 2, 0, 2, 3]);
|
|
332
|
+
return { vertices: verts, uvs: uvs, indices: inds };
|
|
333
|
+
}
|
|
334
|
+
// cleanup GL buffers on exit
|
|
335
|
+
onExit() {
|
|
336
|
+
super.onExit();
|
|
337
|
+
if (this._gl) {
|
|
338
|
+
try {
|
|
339
|
+
if (this._vbo)
|
|
340
|
+
this._gl.deleteBuffer(this._vbo);
|
|
341
|
+
if (this._uvbo)
|
|
342
|
+
this._gl.deleteBuffer(this._uvbo);
|
|
343
|
+
if (this._ibo)
|
|
344
|
+
this._gl.deleteBuffer(this._ibo);
|
|
345
|
+
if (this._program)
|
|
346
|
+
this._gl.deleteProgram(this._program);
|
|
347
|
+
}
|
|
348
|
+
catch (e) {
|
|
349
|
+
console.log('onExit', e);
|
|
350
|
+
}
|
|
351
|
+
this._gl = null;
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/dragonbones/index.ts"],"names":[],"mappings":"AAGA,cAAc,mBAAmB,CAAA;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/dragonbones/index.ts"],"names":[],"mappings":"AAGA,cAAc,mBAAmB,CAAA;AAEjC,wBAAgB,gBAAgB,SAE/B"}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { GameWorld } from '../gworld';
|
|
2
2
|
import { DragonBonesSystem } from './DragonBonesSystem';
|
|
3
3
|
export * from './DragonBonesComp';
|
|
4
|
-
export * from './PixiDragonBonesSprite';
|
|
5
4
|
export function setupDragonBones() {
|
|
6
5
|
GameWorld.Instance.addSystemAndUpdate(DragonBonesSystem);
|
|
7
6
|
}
|
package/dist/polyfills.d.ts
CHANGED
|
@@ -22,7 +22,7 @@ declare class _Vec2 {
|
|
|
22
22
|
export type Vec2 = _Vec2;
|
|
23
23
|
export declare function Vec2(x?: number | object, y?: number): Vec2;
|
|
24
24
|
export declare namespace Vec2 {
|
|
25
|
-
var ZERO:
|
|
25
|
+
var ZERO: any;
|
|
26
26
|
}
|
|
27
27
|
export declare enum SpriteType {
|
|
28
28
|
SIMPLE = 0,
|
package/dist/polyfills.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"polyfills.d.ts","sourceRoot":"","sources":["../src/polyfills.ts"],"names":[],"mappings":"AAOA,cAAM,KAAK;IACT,CAAC,EAAE,MAAM,CAAA;IACT,CAAC,EAAE,MAAM,CAAA;IACT,MAAM,CAAC,IAAI,MAAA;gBACC,CAAC,GAAE,MAAM,GAAG,MAAU,EAAE,CAAC,SAAI;IAazC,MAAM,CAAC,KAAK,EAAE,KAAK;IAInB,GAAG,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,GAAG,IAAI,GAAG,KAAK;IAIlC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,GAAG,IAAI,GAAG,KAAK;IAOtC,GAAG,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,GAAG,IAAI,GAAG,KAAK;IAIlC,GAAG,CAAC,QAAQ,EAAE,MAAM,GAAG,KAAK;IAI5B,OAAO,CAAC,QAAQ,EAAE,MAAM,GAAG,KAAK;IAOhC,GAAG,IAAI,MAAM;IAIb,aAAa,IAAI,KAAK;IAOtB,SAAS,IAAI,KAAK;IAIX,KAAK,CAAC,KAAK,EAAE,IAAI;IAGjB,SAAS,CAAC,KAAK,EAAE,IAAI;IAIrB,SAAS;IAGT,GAAG,CAAC,KAAK,EAAE,IAAI;IAGf,KAAK,CAAC,KAAK,EAAE,IAAI;IAcjB,QAAQ,CAAC,KAAK,EAAE,KAAK;CAG7B;AACD,MAAM,MAAM,IAAI,GAAG,KAAK,CAAA;AACxB,wBAAgB,IAAI,CAAC,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC,CAAC,EAAE,MAAM,GAAG,IAAI,CAE1D;yBAFe,IAAI;;;
|
|
1
|
+
{"version":3,"file":"polyfills.d.ts","sourceRoot":"","sources":["../src/polyfills.ts"],"names":[],"mappings":"AAOA,cAAM,KAAK;IACT,CAAC,EAAE,MAAM,CAAA;IACT,CAAC,EAAE,MAAM,CAAA;IACT,MAAM,CAAC,IAAI,MAAA;gBACC,CAAC,GAAE,MAAM,GAAG,MAAU,EAAE,CAAC,SAAI;IAazC,MAAM,CAAC,KAAK,EAAE,KAAK;IAInB,GAAG,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,GAAG,IAAI,GAAG,KAAK;IAIlC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,GAAG,IAAI,GAAG,KAAK;IAOtC,GAAG,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,GAAG,IAAI,GAAG,KAAK;IAIlC,GAAG,CAAC,QAAQ,EAAE,MAAM,GAAG,KAAK;IAI5B,OAAO,CAAC,QAAQ,EAAE,MAAM,GAAG,KAAK;IAOhC,GAAG,IAAI,MAAM;IAIb,aAAa,IAAI,KAAK;IAOtB,SAAS,IAAI,KAAK;IAIX,KAAK,CAAC,KAAK,EAAE,IAAI;IAGjB,SAAS,CAAC,KAAK,EAAE,IAAI;IAIrB,SAAS;IAGT,GAAG,CAAC,KAAK,EAAE,IAAI;IAGf,KAAK,CAAC,KAAK,EAAE,IAAI;IAcjB,QAAQ,CAAC,KAAK,EAAE,KAAK;CAG7B;AACD,MAAM,MAAM,IAAI,GAAG,KAAK,CAAA;AACxB,wBAAgB,IAAI,CAAC,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC,CAAC,EAAE,MAAM,GAAG,IAAI,CAE1D;yBAFe,IAAI;;;AAKpB,oBAAY,UAAU;IACpB,MAAM,IAAA;IACN,MAAM,IAAA;IACN,KAAK,IAAA;IACL,MAAM,IAAA;IACN,IAAI,IAAA;CACL;AAED,eAAO,MAAM,GAAG,UAA0B,CAAA;AAC1C,eAAO,MAAM,KAAK,UAAwB,CAAA;AAC1C,eAAO,MAAM,KAAK,UAA8B,CAAA;AAChD,eAAO,MAAM,KAAK,UAA0B,CAAA;AAC5C,eAAO,MAAM,IAAI,UAA0B,CAAA;AAY3C,wBAAgB,OAAO,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,YAEjE;AACD,MAAM,MAAM,OAAO,GAAG,UAAU,CAAC,OAAO,OAAO,CAAC,CAAA;AAEhD,cAAM,KAAK;IACT,KAAK,EAAE,MAAM,CAAA;IACb,MAAM,EAAE,MAAM,CAAA;IACd,MAAM,CAAC,IAAI,MAAA;gBACC,KAAK,SAAI,EAAE,MAAM,SAAI;CAWlC;AAED,MAAM,MAAM,IAAI,GAAG,KAAK,CAAA;AACxB,wBAAgB,IAAI,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC,EAAE,MAAM,GAAG,IAAI,CAEjD;AAED,qBAAa,KAAM,SAAQ,EAAE,CAAC,KAAK;IACzB,WAAW,EAAE,MAAM,IAAI,CAAA;IACvB,QAAQ,EAAE,MAAM,IAAI,CAAA;IACpB,mBAAmB,EAAE,MAAM,IAAI,CAAA;IAC/B,gBAAgB,EAAE,MAAM,IAAI,CAAA;IAC5B,iBAAiB,EAAE,MAAM,IAAI,CAAA;CACtC;AAED,wBAAgB,UAAU,IAAI,IAAI,CAEjC"}
|
package/dist/polyfills.js
CHANGED
|
@@ -87,8 +87,7 @@ class _Vec2 {
|
|
|
87
87
|
export function Vec2(x, y) {
|
|
88
88
|
return new _Vec2(x, y);
|
|
89
89
|
}
|
|
90
|
-
|
|
91
|
-
Vec2.ZERO = cc.Vec2.ZERO = Object.freeze(Vec2(0, 0));
|
|
90
|
+
Vec2.ZERO = Vec2.ZERO = Object.freeze(Vec2(0, 0));
|
|
92
91
|
export var SpriteType;
|
|
93
92
|
(function (SpriteType) {
|
|
94
93
|
SpriteType[SpriteType["SIMPLE"] = 0] = "SIMPLE";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RenderComponent.d.ts","sourceRoot":"","sources":["../../src/render/RenderComponent.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,WAAW,EAAE,MAAM,IAAI,CAAA;AACpD,OAAO,EAAE,UAAU,EAAU,MAAM,mBAAmB,CAAA;AACtD,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,cAAc,CAAA;AAElD,qBAAa,UAAW,SAAQ,UAAU;IACxC,QAAQ,EAAE,MAAM,CAAA;CACjB;AASD,UAAU,iBAAiB;IACzB,WAAW,EAAE,MAAM,CAAA;IAEnB,SAAS,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAA;IAC5C,SAAS,CAAC,EAAE,IAAI,CAAA;CACjB;AAED,qBAAa,YAAa,SAAQ,UAAU,CAAC,iBAAiB,GAAG,kBAAkB,CAAC,YAAY,CAAC,EAAE,EAAE,CAAC,MAAM,CAAC;IAC3G,IAAI,WAAW,WAEd;IAED,IAAI,WAAW,CAAC,KAAK,QAAA,EAKpB;IACD,WAAW;
|
|
1
|
+
{"version":3,"file":"RenderComponent.d.ts","sourceRoot":"","sources":["../../src/render/RenderComponent.ts"],"names":[],"mappings":"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"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RenderSystem.d.ts","sourceRoot":"","sources":["../../src/render/RenderSystem.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,YAAY,EAAoC,MAAM,EAAE,MAAM,YAAY,CAAA;
|
|
1
|
+
{"version":3,"file":"RenderSystem.d.ts","sourceRoot":"","sources":["../../src/render/RenderSystem.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,YAAY,EAAoC,MAAM,EAAE,MAAM,YAAY,CAAA;AAMlG,oBAAY,WAAW;IACrB,MAAM,IAAA;IACN,MAAM,IAAA;IACN,KAAK,IAAA;IACL,MAAM,IAAA;IACN,IAAI,IAAA;IACJ,SAAS,IAAA;CACV;AA2CD,qBAAa,YAAa,YAAW,MAAM;IACzC,SAAS,CAAC,aAAa,EAAE,YAAY;IAWrC,OAAO,CAAC,eAAe,CAKtB;IAED,OAAO,CAAC,iBAAiB,CAgBxB;IAED,OAAO,CAAC,eAAe,CAWtB;IAED,OAAO,CAAC,mBAAmB,CAQ1B;IAED,OAAO,CAAC,iBAAiB,CAKxB;IAED,OAAO,CAAC,aAAa,CAKpB;IAED,OAAO,CAAC,iBAAiB,CAUxB;IAED,OAAO,CAAC,iBAAiB,CAKxB;IAED,MAAM,CAAC,QAAQ,EAAE,aAAa,EAAE,MAAM,EAAE,YAAY,EAAE,EAAE,EAAE,MAAM;CAIjE"}
|
|
@@ -2,7 +2,6 @@ import { EventTypes } from 'entityx-ts';
|
|
|
2
2
|
import { NodeComp } from '../core/NodeComp';
|
|
3
3
|
import { BLUE, RED } from '../polyfills';
|
|
4
4
|
import { GraphicsRender, MaskRender, MotionStreakComp, NodeRender, ParticleComp, SpriteRender, TiledMap } from './RenderComponent';
|
|
5
|
-
import { TiledSprite } from './TiledSprite';
|
|
6
5
|
export var SpriteTypes;
|
|
7
6
|
(function (SpriteTypes) {
|
|
8
7
|
SpriteTypes[SpriteTypes["SIMPLE"] = 0] = "SIMPLE";
|
|
@@ -12,6 +11,39 @@ export var SpriteTypes;
|
|
|
12
11
|
SpriteTypes[SpriteTypes["MESH"] = 4] = "MESH";
|
|
13
12
|
SpriteTypes[SpriteTypes["ANIMATION"] = 5] = "ANIMATION";
|
|
14
13
|
})(SpriteTypes || (SpriteTypes = {}));
|
|
14
|
+
function createTiledSprite(src, totalW, totalH) {
|
|
15
|
+
// tạo sprite từ input
|
|
16
|
+
const tileSprite = new cc.Sprite(src);
|
|
17
|
+
// lấy kích thước gốc của texture
|
|
18
|
+
const frame = tileSprite.getSpriteFrame();
|
|
19
|
+
const tileW = frame ? frame.getRect().width : tileSprite.getContentSize().width;
|
|
20
|
+
const tileH = frame ? frame.getRect().height : tileSprite.getContentSize().height;
|
|
21
|
+
// tạo renderTexture với kích thước cần phủ
|
|
22
|
+
const rt = new cc.RenderTexture(totalW, totalH);
|
|
23
|
+
rt.beginWithClear(0, 0, 0, 0);
|
|
24
|
+
const drawSprite = new cc.Sprite(tileSprite.getTexture());
|
|
25
|
+
// if (frame) {
|
|
26
|
+
// drawSprite.setSpriteFrame(frame)
|
|
27
|
+
// }
|
|
28
|
+
drawSprite.setAnchorPoint(0, 0);
|
|
29
|
+
// số tile theo trục x,y
|
|
30
|
+
const cols = Math.ceil(totalW / tileW);
|
|
31
|
+
const rows = Math.ceil(totalH / tileH);
|
|
32
|
+
for (let r = 0; r < rows; r++) {
|
|
33
|
+
for (let c = 0; c < cols; c++) {
|
|
34
|
+
const s = new cc.Sprite(frame);
|
|
35
|
+
s.setAnchorPoint(0, 0);
|
|
36
|
+
s.setPosition(c * tileW, r * tileH);
|
|
37
|
+
s.visit(rt);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
rt.end();
|
|
41
|
+
const finalSprite = rt.sprite;
|
|
42
|
+
finalSprite.setFlippedY(true); // RenderTexture bị lật
|
|
43
|
+
finalSprite.setAnchorPoint(0, 0);
|
|
44
|
+
finalSprite.setContentSize(cc.size(totalW, totalH));
|
|
45
|
+
return new cc.Sprite(finalSprite.texture);
|
|
46
|
+
}
|
|
15
47
|
export class RenderSystem {
|
|
16
48
|
configure(event_manager) {
|
|
17
49
|
event_manager.subscribe(EventTypes.ComponentAdded, NodeRender, this.onAddNodeRender);
|
|
@@ -35,7 +67,7 @@ export class RenderSystem {
|
|
|
35
67
|
// console.log('frame', spriteFrame, frame)
|
|
36
68
|
let node;
|
|
37
69
|
if (tiledSize) {
|
|
38
|
-
node =
|
|
70
|
+
node = createTiledSprite(spriteFrame, tiledSize.width, tiledSize.height);
|
|
39
71
|
}
|
|
40
72
|
else if (capInsets) {
|
|
41
73
|
const rect = cc.rect(...capInsets);
|
|
@@ -22,7 +22,7 @@ export class RichTextComp extends ComponentX {
|
|
|
22
22
|
// console.log('richText', richText, (ccui as any).RichElementCustomNode)
|
|
23
23
|
const label = new ccui.Text(text, fontName, fontSize);
|
|
24
24
|
label.enableOutline(cc.hexToColor(style.outline.color), style.outline.width || 3);
|
|
25
|
-
const customElem =
|
|
25
|
+
const customElem = ccui.RichElementCustomNode.create(1, cc.color(255, 0, 0), 255, label);
|
|
26
26
|
this.node.instance.pushBackElement(customElem);
|
|
27
27
|
}
|
|
28
28
|
else {
|