Skip to content

Commit e79acd0

Browse files
authored
Merge pull request #3551 from drelaptop/update-spine-to-3.6.39
Update web spine to 3.6.39
2 parents 369b222 + adeefef commit e79acd0

File tree

6 files changed

+2068
-964
lines changed

6 files changed

+2068
-964
lines changed

Diff for: cocos2d/core/CCDrawingPrimitivesCanvas.js

+5-10
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,9 @@ cc.DrawingPrimitiveCanvas = cc.Class.extend(/** @lends cc.DrawingPrimitiveCanvas
5656
if (!size) {
5757
size = 1;
5858
}
59-
var locScaleX = cc.view.getScaleX(), locScaleY = cc.view.getScaleY();
60-
var newPoint = cc.p(point.x * locScaleX, point.y * locScaleY);
6159
var ctx = this._renderContext.getContext();
6260
ctx.beginPath();
63-
ctx.arc(newPoint.x, -newPoint.y, size * locScaleX, 0, Math.PI * 2, false);
61+
ctx.arc(point.x, -point.y, size, 0, Math.PI * 2, false);
6462
ctx.closePath();
6563
ctx.fill();
6664
},
@@ -79,11 +77,11 @@ cc.DrawingPrimitiveCanvas = cc.Class.extend(/** @lends cc.DrawingPrimitiveCanvas
7977
if (!size) {
8078
size = 1;
8179
}
82-
var locContext = this._renderContext.getContext(),locScaleX = cc.view.getScaleX(), locScaleY = cc.view.getScaleY();
80+
var locContext = this._renderContext.getContext();
8381

8482
locContext.beginPath();
8583
for (var i = 0, len = points.length; i < len; i++)
86-
locContext.arc(points[i].x * locScaleX, -points[i].y * locScaleY, size * locScaleX, 0, Math.PI * 2, false);
84+
locContext.arc(points[i].x, -points[i].y, size, 0, Math.PI * 2, false);
8785
locContext.closePath();
8886
locContext.fill();
8987
},
@@ -95,7 +93,7 @@ cc.DrawingPrimitiveCanvas = cc.Class.extend(/** @lends cc.DrawingPrimitiveCanvas
9593
* @param {cc.Point} destination
9694
*/
9795
drawLine:function (origin, destination) {
98-
var locContext = this._renderContext.getContext(), locScaleX = cc.view.getScaleX(), locScaleY = cc.view.getScaleY();
96+
var locContext = this._renderContext.getContext();
9997
locContext.beginPath();
10098
locContext.moveTo(origin.x , -origin.y );
10199
locContext.lineTo(destination.x, -destination.y );
@@ -151,7 +149,6 @@ cc.DrawingPrimitiveCanvas = cc.Class.extend(/** @lends cc.DrawingPrimitiveCanvas
151149
throw new Error("Polygon's point must greater than 2");
152150

153151
var firstPoint = vertices[0], locContext = this._renderContext.getContext();
154-
var locScaleX = cc.view.getScaleX(), locScaleY = cc.view.getScaleY();
155152
locContext.beginPath();
156153
locContext.moveTo(firstPoint.x , -firstPoint.y );
157154
for (var i = 1, len = vertices.length; i < len; i++)
@@ -189,7 +186,6 @@ cc.DrawingPrimitiveCanvas = cc.Class.extend(/** @lends cc.DrawingPrimitiveCanvas
189186
drawCircle: function (center, radius, angle, segments, drawLineToCenter) {
190187
drawLineToCenter = drawLineToCenter || false;
191188
var locContext = this._renderContext.getContext();
192-
var locScaleX = cc.view.getScaleX(), locScaleY = cc.view.getScaleY();
193189
locContext.beginPath();
194190
var endAngle = angle - Math.PI * 2;
195191
locContext.arc(0 | (center.x ), 0 | -(center.y ), radius , -angle, -endAngle, false);
@@ -379,7 +375,6 @@ cc.DrawingPrimitiveCanvas = cc.Class.extend(/** @lends cc.DrawingPrimitiveCanvas
379375
drawColorBall:function (ctx, radius, color) {
380376
var wrapper = ctx || this._renderContext;
381377
var context = wrapper.getContext();
382-
radius *= cc.view.getScaleX();
383378
var colorStr = "rgba(" +(0|color.r) + "," + (0|color.g) + "," + (0|color.b);
384379
var subRadius = radius / 10;
385380

@@ -432,6 +427,6 @@ cc.DrawingPrimitiveCanvas = cc.Class.extend(/** @lends cc.DrawingPrimitiveCanvas
432427
* @param {Number} width
433428
*/
434429
setLineWidth:function (width) {
435-
this._renderContext.getContext().lineWidth = width * cc.view.getScaleX();
430+
this._renderContext.getContext().lineWidth = width;
436431
}
437432
});

Diff for: cocos2d/core/platform/CCConfig.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
* @type {String}
3232
* @name cc.ENGINE_VERSION
3333
*/
34-
window["CocosEngine"] = cc.ENGINE_VERSION = "Cocos2d-JS v3.16";
34+
window["CocosEngine"] = cc.ENGINE_VERSION = "Cocos2d-JS v3.17";
3535

3636
/**
3737
* <p>

Diff for: extensions/spine/CCSkeleton.js

+6-33
Original file line numberDiff line numberDiff line change
@@ -31,34 +31,6 @@
3131
*/
3232
var sp = sp || {};
3333

34-
/**
35-
* The vertex index of spine.
36-
* @constant
37-
* @type {{X1: number, Y1: number, X2: number, Y2: number, X3: number, Y3: number, X4: number, Y4: number}}
38-
*/
39-
sp.VERTEX_INDEX = {
40-
X1: 0,
41-
Y1: 1,
42-
X2: 2,
43-
Y2: 3,
44-
X3: 4,
45-
Y3: 5,
46-
X4: 6,
47-
Y4: 7
48-
};
49-
50-
/**
51-
* The attachment type of spine. It contains three type: REGION(0), BOUNDING_BOX(1), MESH(2) and SKINNED_MESH.
52-
* @constant
53-
* @type {{REGION: number, BOUNDING_BOX: number, REGION_SEQUENCE: number, MESH: number}}
54-
*/
55-
sp.ATTACHMENT_TYPE = {
56-
REGION: 0,
57-
BOUNDING_BOX: 1,
58-
MESH: 2,
59-
SKINNED_MESH:3
60-
};
61-
6234
var spine = sp.spine;
6335

6436
/**
@@ -228,11 +200,12 @@ sp.Skeleton = cc.Node.extend(/** @lends sp.Skeleton# */{
228200
var attachment = slot.attachment;
229201
if (!attachment || !(attachment instanceof spine.RegionAttachment))
230202
continue;
231-
vertices = attachment.updateWorldVertices(slot, false);
232-
minX = Math.min(minX, vertices[VERTEX.X1] * scaleX, vertices[VERTEX.X4] * scaleX, vertices[VERTEX.X2] * scaleX, vertices[VERTEX.X3] * scaleX);
233-
minY = Math.min(minY, vertices[VERTEX.Y1] * scaleY, vertices[VERTEX.Y4] * scaleY, vertices[VERTEX.Y2] * scaleY, vertices[VERTEX.Y3] * scaleY);
234-
maxX = Math.max(maxX, vertices[VERTEX.X1] * scaleX, vertices[VERTEX.X4] * scaleX, vertices[VERTEX.X2] * scaleX, vertices[VERTEX.X3] * scaleX);
235-
maxY = Math.max(maxY, vertices[VERTEX.Y1] * scaleY, vertices[VERTEX.Y4] * scaleY, vertices[VERTEX.Y2] * scaleY, vertices[VERTEX.Y3] * scaleY);
203+
vertices = spine.Utils.setArraySize(new Array(), 8, 0);
204+
attachment.computeWorldVertices(slot.bone, vertices, 0, 2);
205+
minX = Math.min(minX, vertices[VERTEX.OX1] * scaleX, vertices[VERTEX.OX4] * scaleX, vertices[VERTEX.OX2] * scaleX, vertices[VERTEX.OX3] * scaleX);
206+
minY = Math.min(minY, vertices[VERTEX.OY1] * scaleY, vertices[VERTEX.OY4] * scaleY, vertices[VERTEX.OY2] * scaleY, vertices[VERTEX.OY3] * scaleY);
207+
maxX = Math.max(maxX, vertices[VERTEX.OX1] * scaleX, vertices[VERTEX.OX4] * scaleX, vertices[VERTEX.OX2] * scaleX, vertices[VERTEX.OX3] * scaleX);
208+
maxY = Math.max(maxY, vertices[VERTEX.OY1] * scaleY, vertices[VERTEX.OY4] * scaleY, vertices[VERTEX.OY2] * scaleY, vertices[VERTEX.OY3] * scaleY);
236209
}
237210
var position = this.getPosition();
238211
return cc.rect(position.x + minX, position.y + minY, maxX - minX, maxY - minY);

Diff for: extensions/spine/CCSkeletonCanvasRenderCmd.js

+8-7
Original file line numberDiff line numberDiff line change
@@ -87,12 +87,12 @@ proto.rendering = function (wrapper, scaleX, scaleY) {
8787
}
8888

8989
// Bone origins.
90-
drawingUtil.setPointSize(4);
90+
var pointSize = 4;
9191
drawingUtil.setDrawColor(0, 0, 255, 255); // Root bone is blue.
9292

9393
for (i = 0, n = locSkeleton.bones.length; i < n; i++) {
9494
bone = locSkeleton.bones[i];
95-
drawingUtil.drawPoint({x: bone.worldX, y: bone.worldY});
95+
drawingUtil.drawPoint({x: bone.worldX, y: bone.worldY}, pointSize);
9696
if (i === 0)
9797
drawingUtil.setDrawColor(0, 255, 0, 255);
9898
}
@@ -114,13 +114,14 @@ proto._updateRegionAttachmentSlot = function (attachment, slot, points) {
114114
if (!points)
115115
return;
116116

117-
var vertices = attachment.updateWorldVertices(slot, false);
117+
var vertices = spine.Utils.setArraySize(new Array(), 8, 0);
118+
attachment.computeWorldVertices(slot.bone, vertices, 0, 2);
118119
var VERTEX = spine.RegionAttachment;
119120
points.length = 0;
120-
points.push(cc.p(vertices[VERTEX.X1], vertices[VERTEX.Y1]));
121-
points.push(cc.p(vertices[VERTEX.X4], vertices[VERTEX.Y4]));
122-
points.push(cc.p(vertices[VERTEX.X3], vertices[VERTEX.Y3]));
123-
points.push(cc.p(vertices[VERTEX.X2], vertices[VERTEX.Y2]));
121+
points.push(cc.p(vertices[VERTEX.OX1], vertices[VERTEX.OY1]));
122+
points.push(cc.p(vertices[VERTEX.OX4], vertices[VERTEX.OY4]));
123+
points.push(cc.p(vertices[VERTEX.OX3], vertices[VERTEX.OY3]));
124+
points.push(cc.p(vertices[VERTEX.OX2], vertices[VERTEX.OY2]));
124125
};
125126

126127
proto._createChildFormSkeletonData = function () {

Diff for: extensions/spine/CCSkeletonWebGLRenderCmd.js

+58-22
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,10 @@ proto.uploadData = function (f32buffer, ui32buffer, vertexDataOffset){
9191
this._currTexture = regionTextureAtlas.texture.getRealTexture();
9292
var batchBroken = cc.renderer._updateBatchedInfo(this._currTexture, this._getBlendFunc(slot.data.blendMode, premultiAlpha), this._glProgramState);
9393

94+
// keep the same logic with RendererWebGL.js, avoid vertex data overflow
95+
var uploadAll = vertexDataOffset / 6 + vertCount > (cc.BATCH_VERTEX_COUNT - 200) * 0.5;
9496
// Broken for vertex data overflow
95-
if (!batchBroken && vertexDataOffset + vertCount * 6 > f32buffer.length) {
97+
if (!batchBroken && uploadAll) {
9698
// render the cached data
9799
cc.renderer._batchRendering();
98100
batchBroken = true;
@@ -233,7 +235,25 @@ proto._uploadRegionAttachmentData = function(attachment, slot, premultipliedAlph
233235
nodeG = nodeColor.g,
234236
nodeB = nodeColor.b,
235237
nodeA = this._displayedOpacity;
236-
var vertices = attachment.updateWorldVertices(slot, premultipliedAlpha);
238+
239+
var vertices = spine.Utils.setArraySize(new Array(), 8, 0);
240+
attachment.computeWorldVertices(slot.bone, vertices, 0, 2);
241+
242+
var uvs = attachment.uvs;
243+
244+
// get the colors data
245+
var skeleton = slot.bone.skeleton;
246+
var skeletonColor = skeleton.color;
247+
var slotColor = slot.color;
248+
var regionColor = attachment.color;
249+
var alpha = skeletonColor.a * slotColor.a * regionColor.a;
250+
var multiplier = premultipliedAlpha ? alpha : 1;
251+
var colors = attachment.tempColor;
252+
colors.set(skeletonColor.r * slotColor.r * regionColor.r * multiplier,
253+
skeletonColor.g * slotColor.g * regionColor.g * multiplier,
254+
skeletonColor.b * slotColor.b * regionColor.b * multiplier,
255+
alpha);
256+
237257
var wt = this._worldTransform,
238258
wa = wt.a, wb = wt.b, wc = wt.c, wd = wt.d,
239259
wx = wt.tx, wy = wt.ty,
@@ -244,32 +264,32 @@ proto._uploadRegionAttachmentData = function(attachment, slot, premultipliedAlph
244264
// using two angles : (0, 1, 2) & (0, 2, 3)
245265
for (var i = 0; i < 6; i++) {
246266
var srcIdx = i < 4 ? i % 3 : i - 2;
247-
var vx = vertices[srcIdx * 8],
248-
vy = vertices[srcIdx * 8 + 1];
267+
var vx = vertices[srcIdx * 2],
268+
vy = vertices[srcIdx * 2 + 1];
249269
var x = vx * wa + vy * wc + wx,
250270
y = vx * wb + vy * wd + wy;
251-
var r = vertices[srcIdx * 8 + 2] * nodeR,
252-
g = vertices[srcIdx * 8 + 3] * nodeG,
253-
b = vertices[srcIdx * 8 + 4] * nodeB,
254-
a = vertices[srcIdx * 8 + 5] * nodeA;
271+
var r = colors.r * nodeR,
272+
g = colors.g * nodeG,
273+
b = colors.b * nodeB,
274+
a = colors.a * nodeA;
255275
var color = ((a<<24) | (b<<16) | (g<<8) | r);
256276
f32buffer[offset] = x;
257277
f32buffer[offset + 1] = y;
258278
f32buffer[offset + 2] = z;
259279
ui32buffer[offset + 3] = color;
260-
f32buffer[offset + 4] = vertices[srcIdx * 8 + 6];
261-
f32buffer[offset + 5] = vertices[srcIdx * 8 + 7];
280+
f32buffer[offset + 4] = uvs[srcIdx * 2];
281+
f32buffer[offset + 5] = uvs[srcIdx * 2 + 1];
262282
offset += 6;
263283
}
264284

265285
if (this._node._debugSlots) {
266286
// return the quad points info if debug slot enabled
267287
var VERTEX = spine.RegionAttachment;
268288
return [
269-
cc.p(vertices[VERTEX.X1], vertices[VERTEX.Y1]),
270-
cc.p(vertices[VERTEX.X2], vertices[VERTEX.Y2]),
271-
cc.p(vertices[VERTEX.X3], vertices[VERTEX.Y3]),
272-
cc.p(vertices[VERTEX.X4], vertices[VERTEX.Y4])
289+
cc.p(vertices[VERTEX.OX1], vertices[VERTEX.OY1]),
290+
cc.p(vertices[VERTEX.OX2], vertices[VERTEX.OY2]),
291+
cc.p(vertices[VERTEX.OX3], vertices[VERTEX.OY3]),
292+
cc.p(vertices[VERTEX.OX4], vertices[VERTEX.OY4])
273293
];
274294
}
275295
};
@@ -280,30 +300,46 @@ proto._uploadMeshAttachmentData = function(attachment, slot, premultipliedAlpha,
280300
wx = wt.tx, wy = wt.ty,
281301
z = this._node.vertexZ;
282302
// get the vertex data
283-
var vertices = attachment.updateWorldVertices(slot, premultipliedAlpha);
303+
var verticesLength = attachment.worldVerticesLength;
304+
var vertices = spine.Utils.setArraySize(new Array(), verticesLength, 0);
305+
attachment.computeWorldVertices(slot, 0, verticesLength, vertices, 0, 2);
306+
307+
var uvs = attachment.uvs;
308+
309+
// get the colors data
310+
var skeleton = slot.bone.skeleton;
311+
var skeletonColor = skeleton.color, slotColor = slot.color, meshColor = attachment.color;
312+
var alpha = skeletonColor.a * slotColor.a * meshColor.a;
313+
var multiplier = premultipliedAlpha ? alpha : 1;
314+
var colors = attachment.tempColor;
315+
colors.set(skeletonColor.r * slotColor.r * meshColor.r * multiplier,
316+
skeletonColor.g * slotColor.g * meshColor.g * multiplier,
317+
skeletonColor.b * slotColor.b * meshColor.b * multiplier,
318+
alpha);
319+
284320
var offset = vertexDataOffset;
285321
var nodeColor = this._displayedColor;
286322
var nodeR = nodeColor.r,
287323
nodeG = nodeColor.g,
288324
nodeB = nodeColor.b,
289325
nodeA = this._displayedOpacity;
290-
for (var i = 0, n = vertices.length; i < n; i += 8) {
326+
for (var i = 0, n = vertices.length; i < n; i += 2) {
291327
var vx = vertices[i],
292328
vy = vertices[i + 1];
293329
var x = vx * wa + vy * wb + wx,
294330
y = vx * wc + vy * wd + wy;
295-
var r = vertices[i + 2] * nodeR,
296-
g = vertices[i + 3] * nodeG,
297-
b = vertices[i + 4] * nodeB,
298-
a = vertices[i + 5] * nodeA;
331+
var r = colors.r * nodeR,
332+
g = colors.g * nodeG,
333+
b = colors.b * nodeB,
334+
a = colors.a * nodeA;
299335
var color = ((a<<24) | (b<<16) | (g<<8) | r);
300336

301337
f32buffer[offset] = x;
302338
f32buffer[offset + 1] = y;
303339
f32buffer[offset + 2] = z;
304340
ui32buffer[offset + 3] = color;
305-
f32buffer[offset + 4] = vertices[i + 6];
306-
f32buffer[offset + 5] = vertices[i + 7];
341+
f32buffer[offset + 4] = uvs[i];
342+
f32buffer[offset + 5] = uvs[i + 1];
307343
offset += 6;
308344
}
309345
};

0 commit comments

Comments
 (0)