@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.
Files changed (80) hide show
  1. package/dist/box2d-wasm/PhysicsComponent.d.ts.map +1 -1
  2. package/dist/box2d-wasm/PhysicsComponent.js +3 -0
  3. package/dist/box2d-wasm/PhysicsSprite.d.ts.map +1 -1
  4. package/dist/box2d-wasm/PhysicsSprite.js +2 -1
  5. package/dist/box2d-wasm/PhysicsSystem.d.ts +1 -0
  6. package/dist/box2d-wasm/PhysicsSystem.d.ts.map +1 -1
  7. package/dist/box2d-wasm/PhysicsSystem.js +20 -16
  8. package/dist/box2d-wasm/debugDraw.d.ts +0 -15
  9. package/dist/box2d-wasm/debugDraw.d.ts.map +1 -1
  10. package/dist/box2d-wasm/debugDraw.js +8 -20
  11. package/dist/box2d-wasm/index.d.ts +19 -1
  12. package/dist/box2d-wasm/index.d.ts.map +1 -1
  13. package/dist/box2d-wasm/index.js +2 -2
  14. package/dist/core/index.d.ts +6 -0
  15. package/dist/core/index.d.ts.map +1 -0
  16. package/dist/core/index.js +5 -0
  17. package/dist/dragonbones/PixiDragonBonesSprite.d.ts +19 -0
  18. package/dist/dragonbones/PixiDragonBonesSprite.d.ts.map +1 -0
  19. package/dist/dragonbones/PixiDragonBonesSprite.js +75 -0
  20. package/dist/dragonbones/db-cocos/CocosFactory.d.ts +2 -3
  21. package/dist/dragonbones/db-cocos/CocosFactory.d.ts.map +1 -1
  22. package/dist/dragonbones/db-cocos/CocosFactory.js +4 -8
  23. package/dist/dragonbones/db-cocos/CocosSlot.d.ts +4 -1
  24. package/dist/dragonbones/db-cocos/CocosSlot.d.ts.map +1 -1
  25. package/dist/dragonbones/db-cocos/CocosSlot.js +35 -38
  26. package/dist/dragonbones/db-cocos/CocosTextureAtlasData.d.ts +1 -1
  27. package/dist/dragonbones/db-cocos/CocosTextureAtlasData.d.ts.map +1 -1
  28. package/dist/dragonbones/db-cocos/CocosTextureAtlasData.js +6 -6
  29. package/dist/dragonbones/db-cocos/SimpleMeshNode.d.ts +36 -0
  30. package/dist/dragonbones/db-cocos/SimpleMeshNode.d.ts.map +1 -0
  31. package/dist/dragonbones/db-cocos/SimpleMeshNode.js +354 -0
  32. package/dist/gworld/EnhancedComponent.d.ts +22 -0
  33. package/dist/gworld/EnhancedComponent.d.ts.map +1 -0
  34. package/dist/gworld/EnhancedComponent.js +44 -0
  35. package/dist/gworld/NodeComp.d.ts +153 -0
  36. package/dist/gworld/NodeComp.d.ts.map +1 -0
  37. package/dist/gworld/NodeComp.js +337 -0
  38. package/dist/gworld/NodePool.d.ts +9 -0
  39. package/dist/gworld/NodePool.d.ts.map +1 -0
  40. package/dist/gworld/NodePool.js +23 -0
  41. package/dist/gworld/Scene.d.ts +5 -0
  42. package/dist/gworld/Scene.d.ts.map +1 -0
  43. package/dist/gworld/Scene.js +14 -0
  44. package/dist/gworld/decorator.d.ts +8 -0
  45. package/dist/gworld/decorator.d.ts.map +1 -0
  46. package/dist/gworld/decorator.js +12 -0
  47. package/dist/gworld/index.d.ts +8 -0
  48. package/dist/gworld/index.d.ts.map +1 -0
  49. package/dist/gworld/index.js +14 -0
  50. package/dist/render/TiledSprite.d.ts +13 -0
  51. package/dist/render/TiledSprite.d.ts.map +1 -0
  52. package/dist/render/TiledSprite.js +69 -0
  53. package/dist/safex.d.ts +10 -0
  54. package/dist/safex.d.ts.map +1 -0
  55. package/dist/safex.js +1 -0
  56. package/dist/spine/CCSkeleton.d.ts +189 -0
  57. package/dist/spine/CCSkeleton.d.ts.map +1 -0
  58. package/dist/spine/CCSkeleton.js +320 -0
  59. package/dist/spine/CCSkeletonAnimation.d.ts +146 -0
  60. package/dist/spine/CCSkeletonAnimation.d.ts.map +1 -0
  61. package/dist/spine/CCSkeletonAnimation.js +311 -0
  62. package/dist/spine/CCSkeletonCanvasRenderCmd.d.ts +2 -0
  63. package/dist/spine/CCSkeletonCanvasRenderCmd.d.ts.map +1 -0
  64. package/dist/spine/CCSkeletonCanvasRenderCmd.js +228 -0
  65. package/dist/spine/CCSkeletonTexture.d.ts +25 -0
  66. package/dist/spine/CCSkeletonTexture.d.ts.map +1 -0
  67. package/dist/spine/CCSkeletonTexture.js +60 -0
  68. package/dist/spine/CCSkeletonWebGLRenderCmd.d.ts +28 -0
  69. package/dist/spine/CCSkeletonWebGLRenderCmd.d.ts.map +1 -0
  70. package/dist/spine/CCSkeletonWebGLRenderCmd.js +277 -0
  71. package/dist/spine/PixiSpineSprite.d.ts +19 -0
  72. package/dist/spine/PixiSpineSprite.d.ts.map +1 -0
  73. package/dist/spine/PixiSpineSprite.js +72 -0
  74. package/dist/spine/spine-cocos/CCSkeletonAnimation.d.ts +2 -1
  75. package/dist/spine/spine-cocos/CCSkeletonAnimation.d.ts.map +1 -1
  76. package/dist/spine/spine-cocos/CCSkeletonAnimation.js +1 -1
  77. package/dist/spine/spine-cocos/CCSkeletonTexture.d.ts +12 -1
  78. package/dist/spine/spine-cocos/CCSkeletonTexture.d.ts.map +1 -1
  79. package/dist/spine/spine-cocos/CCSkeletonTexture.js +18 -19
  80. package/package.json +3 -3
@@ -1,4 +1,3 @@
1
- // @ts-nocheck
2
1
  /**
3
2
  * The MIT License (MIT)
4
3
  *
@@ -28,23 +27,19 @@ export class CocosSlot extends Slot {
28
27
  static toString() {
29
28
  return '[class dragonBones.CocosSlot]';
30
29
  }
30
+ _ccMeshDirty = false;
31
31
  _textureScale;
32
32
  _renderDisplay;
33
+ _geometryData;
34
+ _geometryBones;
33
35
  _onClear() {
34
36
  super._onClear();
35
37
  this._textureScale = 1.0;
36
38
  this._renderDisplay = null;
37
39
  // this._updateTransform = cc[0] === '3' ? this._updateTransformV3 : this._updateTransformV4;
38
40
  }
39
- _initDisplay(value, isRetain) {
40
- // tslint:disable-next-line:no-unused-expression
41
- value;
42
- // tslint:disable-next-line:no-unused-expression
43
- isRetain;
44
- }
41
+ _initDisplay() { }
45
42
  _disposeDisplay(value, isRelease) {
46
- // tslint:disable-next-line:no-unused-expression
47
- value;
48
43
  if (!isRelease) {
49
44
  ;
50
45
  value.release();
@@ -55,18 +50,21 @@ export class CocosSlot extends Slot {
55
50
  }
56
51
  _addDisplay() {
57
52
  const container = this._armature.display;
58
- container.addChild(this._renderDisplay);
53
+ container.addChild(this._renderDisplay, this._zOrder);
59
54
  }
60
55
  _replaceDisplay(value) {
61
56
  const container = this._armature.display;
62
57
  const prevDisplay = value;
63
- container.addChild(this._renderDisplay);
64
- // container.swapChildren(this._renderDisplay, prevDisplay);
65
- container.removeChild(prevDisplay);
58
+ if (this._renderDisplay.parent !== container) {
59
+ container.addChild(this._renderDisplay, prevDisplay.getLocalZOrder());
60
+ }
61
+ // container.removeChild(prevDisplay, false);
62
+ // this._renderDisplay.active = true
63
+ // prevDisplay.active = false
66
64
  this._textureScale = 1.0;
67
65
  }
68
66
  _removeDisplay() {
69
- this._renderDisplay.parent.removeChild(this._renderDisplay);
67
+ this._renderDisplay.parent.removeChild(this._renderDisplay, false);
70
68
  }
71
69
  _updateZOrder() {
72
70
  if (this._renderDisplay.getLocalZOrder() === this._zOrder) {
@@ -81,20 +79,18 @@ export class CocosSlot extends Slot {
81
79
  this._renderDisplay.visible = this._parent.visible && this._visible;
82
80
  }
83
81
  _updateBlendMode() {
84
- if (this._renderDisplay instanceof cc.Sprite) {
82
+ if (this._childArmature) {
83
+ const childSlots = this._childArmature.getSlots();
84
+ for (let i = 0, l = childSlots.length; i < l; i++) {
85
+ const slot = childSlots[i];
86
+ slot._blendMode = this._blendMode;
87
+ slot._updateBlendMode();
88
+ }
85
89
  }
86
- // TODO child armature.
87
90
  }
88
91
  _updateColor() {
89
- const alpha = this._colorTransform.alphaMultiplier * this._globalAlpha;
90
- this._renderDisplay.alpha = alpha;
91
- if (this._renderDisplay instanceof cc.Sprite || this._renderDisplay instanceof Cocos.SimpleMesh) {
92
- const color = (Math.round(this._colorTransform.redMultiplier * 0xff) << 16) +
93
- (Math.round(this._colorTransform.greenMultiplier * 0xff) << 8) +
94
- Math.round(this._colorTransform.blueMultiplier * 0xff);
95
- this._renderDisplay.tint = color;
96
- }
97
- // TODO child armature.
92
+ const color = cc.color(Math.round(this._colorTransform.redMultiplier * 255), Math.round(this._colorTransform.greenMultiplier * 255), Math.round(this._colorTransform.blueMultiplier * 255), Math.round(this._colorTransform.alphaMultiplier * 255));
93
+ this._renderDisplay.color = color;
98
94
  }
99
95
  _updateFrame() {
100
96
  let currentTextureData = this._textureData;
@@ -113,16 +109,16 @@ export class CocosSlot extends Slot {
113
109
  }
114
110
  currentTextureData = currentTextureAtlasData.getTexture(currentTextureData.name);
115
111
  }
116
- const renderTexture = currentTextureData.renderTexture;
112
+ const renderTexture = currentTextureData.spriteFrame;
117
113
  if (renderTexture !== null) {
118
114
  if (this._geometryData) {
119
115
  // Mesh.
120
116
  const data = this._geometryData.data;
121
117
  const intArray = data.intArray;
122
118
  const floatArray = data.floatArray;
123
- const vertexCount = intArray[this._geometryData.offset + BinaryOffset.GeometryVertexCount];
124
- const triangleCount = intArray[this._geometryData.offset + BinaryOffset.GeometryTriangleCount];
125
- let vertexOffset = intArray[this._geometryData.offset + BinaryOffset.GeometryFloatOffset];
119
+ const vertexCount = intArray[this._geometryData.offset + BinaryOffset.MeshVertexCount];
120
+ const triangleCount = intArray[this._geometryData.offset + BinaryOffset.MeshTriangleCount];
121
+ let vertexOffset = intArray[this._geometryData.offset + BinaryOffset.MeshFloatOffset];
126
122
  if (vertexOffset < 0) {
127
123
  vertexOffset += 65536; // Fixed out of bouds bug.
128
124
  }
@@ -136,7 +132,7 @@ export class CocosSlot extends Slot {
136
132
  vertices[i] = floatArray[vertexOffset + i] * scale;
137
133
  }
138
134
  for (let i = 0; i < triangleCount * 3; ++i) {
139
- indices[i] = intArray[this._geometryData.offset + BinaryOffset.GeometryVertexIndices + i];
135
+ indices[i] = intArray[this._geometryData.offset + BinaryOffset.MeshVertexIndices + i];
140
136
  }
141
137
  for (let i = 0, l = vertexCount * 2; i < l; i += 2) {
142
138
  const u = floatArray[uvOffset + i];
@@ -151,10 +147,10 @@ export class CocosSlot extends Slot {
151
147
  }
152
148
  }
153
149
  this._textureScale = 1.0;
154
- meshDisplay.texture = renderTexture;
155
- meshDisplay.vertices = vertices;
156
- meshDisplay.uvBuffer.update(uvs);
157
- meshDisplay.geometry.addIndex(indices);
150
+ meshDisplay.setTexture(renderTexture);
151
+ meshDisplay.setVertices(vertices);
152
+ // meshDisplay.uvBuffer.update(uvs)
153
+ // meshDisplay.geometry.addIndex(indices)
158
154
  const isSkinned = this._geometryData.weight !== null;
159
155
  const isSurface = this._parent._boneData.type !== BoneType.Bone;
160
156
  if (isSkinned || isSurface) {
@@ -165,6 +161,7 @@ export class CocosSlot extends Slot {
165
161
  // Normal texture.
166
162
  this._textureScale = currentTextureData.parent.scale * this._armature._armatureData.scale;
167
163
  const normalDisplay = this._renderDisplay;
164
+ // console.log(normalDisplay, renderTexture)
168
165
  normalDisplay.setSpriteFrame(renderTexture);
169
166
  }
170
167
  this._visibleDirty = true;
@@ -173,7 +170,7 @@ export class CocosSlot extends Slot {
173
170
  }
174
171
  if (this._geometryData) {
175
172
  const meshDisplay = this._renderDisplay;
176
- meshDisplay.texture = null;
173
+ meshDisplay.setTexture(null);
177
174
  meshDisplay.x = 0.0;
178
175
  meshDisplay.y = 0.0;
179
176
  meshDisplay.visible = false;
@@ -194,7 +191,7 @@ export class CocosSlot extends Slot {
194
191
  const bones = this._geometryBones;
195
192
  const geometryData = this._geometryData;
196
193
  const weightData = deformVertices.verticesData.weight;
197
- const hasDeform = deformVertices.length > 0 && deformVertices.verticesData.inheritDeform;
194
+ const hasDeform = deformVertices.vertices.length > 0 && deformVertices.verticesData.inheritDeform;
198
195
  // const meshDisplay = (this._renderDisplay.getComponent(cc.Sprite) as any)._sgNode; // as cc.Scale9Sprite;
199
196
  const polygonInfo = this._meshDisplay._polygonInfo;
200
197
  if (!polygonInfo) {
@@ -295,8 +292,8 @@ export class CocosSlot extends Slot {
295
292
  boundsRect.width -= boundsRect.x;
296
293
  boundsRect.height -= boundsRect.y;
297
294
  polygonInfo.rect = boundsRect;
298
- meshDisplay.setContentSize(cc.size(boundsRect.width, boundsRect.height));
299
- meshDisplay.setMeshPolygonInfo(polygonInfo);
295
+ this.meshDisplay.setContentSize(cc.size(boundsRect.width, boundsRect.height));
296
+ this.meshDisplay.setMeshPolygonInfo(polygonInfo);
300
297
  if (weightData !== null) {
301
298
  this._identityTransform();
302
299
  }
@@ -47,7 +47,7 @@ export declare class CocosTextureAtlasData extends TextureAtlasData {
47
47
  */
48
48
  export declare class CocosTextureData extends TextureData {
49
49
  static toString(): string;
50
- renderTexture: cc.SpriteFrame | null;
50
+ spriteFrame: cc.SpriteFrame | null;
51
51
  protected _onClear(): void;
52
52
  }
53
53
  //# sourceMappingURL=CocosTextureAtlasData.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"CocosTextureAtlasData.d.ts","sourceRoot":"","sources":["../../../src/dragonbones/db-cocos/CocosTextureAtlasData.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEH,OAAO,EAAc,gBAAgB,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAA;AAEjF,qBAAa,qBAAsB,SAAQ,gBAAgB;WAC3C,QAAQ,IAAI,MAAM;IAIhC,OAAO,CAAC,cAAc,CAA4B;IAElD,SAAS,CAAC,QAAQ,IAAI,IAAI;IAS1B;;OAEG;IACI,aAAa,IAAI,WAAW;IAGnC;;;;OAIG;IACH;;;;OAIG;IACH,IAAW,aAAa,IAAI,EAAE,CAAC,SAAS,GAAG,IAAI,CAE9C;IACD,IAAW,aAAa,CAAC,KAAK,EAAE,EAAE,CAAC,SAAS,GAAG,IAAI,EAoDlD;CACF;AACD;;GAEG;AACH,qBAAa,gBAAiB,SAAQ,WAAW;WACjC,QAAQ,IAAI,MAAM;IAIzB,aAAa,EAAE,EAAE,CAAC,WAAW,GAAG,IAAI,CAAO;IAElD,SAAS,CAAC,QAAQ,IAAI,IAAI;CAS3B"}
1
+ {"version":3,"file":"CocosTextureAtlasData.d.ts","sourceRoot":"","sources":["../../../src/dragonbones/db-cocos/CocosTextureAtlasData.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEH,OAAO,EAAc,gBAAgB,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAA;AAEjF,qBAAa,qBAAsB,SAAQ,gBAAgB;WAC3C,QAAQ,IAAI,MAAM;IAIhC,OAAO,CAAC,cAAc,CAA4B;IAElD,SAAS,CAAC,QAAQ,IAAI,IAAI;IAS1B;;OAEG;IACI,aAAa,IAAI,WAAW;IAGnC;;;;OAIG;IACH;;;;OAIG;IACH,IAAW,aAAa,IAAI,EAAE,CAAC,SAAS,GAAG,IAAI,CAE9C;IACD,IAAW,aAAa,CAAC,KAAK,EAAE,EAAE,CAAC,SAAS,GAAG,IAAI,EAoDlD;CACF;AACD;;GAEG;AACH,qBAAa,gBAAiB,SAAQ,WAAW;WACjC,QAAQ,IAAI,MAAM;IAIzB,WAAW,EAAE,EAAE,CAAC,WAAW,GAAG,IAAI,CAAO;IAEhD,SAAS,CAAC,QAAQ,IAAI,IAAI;CAS3B"}
@@ -89,7 +89,7 @@ export class CocosTextureAtlasData extends TextureAtlasData {
89
89
  // sprite
90
90
  const spriteFrame = new cc.SpriteFrame(this._renderTexture, rect, textureData.rotated, offset, originSize);
91
91
  // console.log('sf', sf)
92
- textureData.renderTexture = spriteFrame;
92
+ textureData.spriteFrame = spriteFrame;
93
93
  }
94
94
  }
95
95
  else {
@@ -98,7 +98,7 @@ export class CocosTextureAtlasData extends TextureAtlasData {
98
98
  // if (textureData.renderTexture !== null) {
99
99
  // textureData.renderTexture.destroy();
100
100
  // }
101
- textureData.renderTexture = null;
101
+ textureData.spriteFrame = null;
102
102
  }
103
103
  }
104
104
  }
@@ -110,12 +110,12 @@ export class CocosTextureData extends TextureData {
110
110
  static toString() {
111
111
  return '[class dragonBones.CocosTextureData]';
112
112
  }
113
- renderTexture = null; // Initial value.
113
+ spriteFrame = null; // Initial value.
114
114
  _onClear() {
115
115
  super._onClear();
116
- // if (this.renderTexture !== null) {
117
- // this.renderTexture.destroy();
116
+ // if (this.spriteFrame !== null) {
117
+ // this.spriteFrame.destroy();
118
118
  // }
119
- this.renderTexture = null;
119
+ this.spriteFrame = null;
120
120
  }
121
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
+ }
@@ -0,0 +1,22 @@
1
+ import { Constructor } from 'entityx-ts';
2
+ import { BaseComponentProps } from '../safex';
3
+ import { NodeComp } from './NodeComp';
4
+ export declare class EnhancedComponent<Props = object, N extends NodeComp<any> = NodeComp<any>> {
5
+ static hasRender: boolean;
6
+ props: Props;
7
+ node: N;
8
+ enabled: boolean;
9
+ constructor(data?: BaseComponentProps<EnhancedComponent> & Props);
10
+ init(data?: Props): void;
11
+ addComponent<T extends EnhancedComponent>(instance: T): T;
12
+ getComponent<T extends EnhancedComponent>(component: Constructor<T>): T;
13
+ schedule(callback: (arg: any) => void, interval: number, repeat?: number, delay?: number): void;
14
+ unschedule(callback: (arg: any) => void): void;
15
+ unscheduleAllCallbacks(): void;
16
+ scheduleOnce(callback: (arg: any) => void, delay: number, key?: string): void;
17
+ getComponentsInChildren<T extends ComponentType>(component: Constructor<T>): T[];
18
+ getComponentInChildren<T extends ComponentType>(component: Constructor<T>): T;
19
+ isEqual(other: EnhancedComponent): boolean;
20
+ }
21
+ export type ComponentType = EnhancedComponent | NodeComp;
22
+ //# sourceMappingURL=EnhancedComponent.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"EnhancedComponent.d.ts","sourceRoot":"","sources":["../../src/gworld/EnhancedComponent.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAA;AAExC,OAAO,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAA;AAC7C,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAA;AAErC,qBAAa,iBAAiB,CAAC,KAAK,GAAG,MAAM,EAAE,CAAC,SAAS,QAAQ,CAAC,GAAG,CAAC,GAAG,QAAQ,CAAC,GAAG,CAAC;IACpF,MAAM,CAAC,SAAS,UAAO;IACvB,KAAK,EAAE,KAAK,CAAY;IACxB,IAAI,EAAE,CAAC,CAAA;IACP,OAAO,UAAO;gBACF,IAAI,CAAC,EAAE,kBAAkB,CAAC,iBAAiB,CAAC,GAAG,KAAK;IAGhE,IAAI,CAAC,IAAI,CAAC,EAAE,KAAK;IASjB,YAAY,CAAC,CAAC,SAAS,iBAAiB,EAAE,QAAQ,EAAE,CAAC,GAAG,CAAC;IAGzD,YAAY,CAAC,CAAC,SAAS,iBAAiB,EAAE,SAAS,EAAE,WAAW,CAAC,CAAC,CAAC,GAAG,CAAC;IAGvE,QAAQ,CAAC,QAAQ,EAAE,CAAC,GAAG,EAAE,GAAG,KAAK,IAAI,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,GAAE,MAAgC,EAAE,KAAK,SAAI;IAG5G,UAAU,CAAC,QAAQ,EAAE,CAAC,GAAG,EAAE,GAAG,KAAK,IAAI;IAGvC,sBAAsB;IAGtB,YAAY,CAAC,QAAQ,EAAE,CAAC,GAAG,EAAE,GAAG,KAAK,IAAI,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,CAAC,EAAE,MAAM;IAGtE,uBAAuB,CAAC,CAAC,SAAS,aAAa,EAAE,SAAS,EAAE,WAAW,CAAC,CAAC,CAAC,GAAG,CAAC,EAAE;IAGhF,sBAAsB,CAAC,CAAC,SAAS,aAAa,EAAE,SAAS,EAAE,WAAW,CAAC,CAAC,CAAC,GAAG,CAAC;IAG7E,OAAO,CAAC,KAAK,EAAE,iBAAiB;CAGjC;AAED,MAAM,MAAM,aAAa,GAAG,iBAAiB,GAAG,QAAQ,CAAA"}