Skip to content

Update web spine to 3.6.39 #3551

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Apr 16, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 5 additions & 10 deletions cocos2d/core/CCDrawingPrimitivesCanvas.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,9 @@ cc.DrawingPrimitiveCanvas = cc.Class.extend(/** @lends cc.DrawingPrimitiveCanvas
if (!size) {
size = 1;
}
var locScaleX = cc.view.getScaleX(), locScaleY = cc.view.getScaleY();
var newPoint = cc.p(point.x * locScaleX, point.y * locScaleY);
var ctx = this._renderContext.getContext();
ctx.beginPath();
ctx.arc(newPoint.x, -newPoint.y, size * locScaleX, 0, Math.PI * 2, false);
ctx.arc(point.x, -point.y, size, 0, Math.PI * 2, false);
ctx.closePath();
ctx.fill();
},
Expand All @@ -79,11 +77,11 @@ cc.DrawingPrimitiveCanvas = cc.Class.extend(/** @lends cc.DrawingPrimitiveCanvas
if (!size) {
size = 1;
}
var locContext = this._renderContext.getContext(),locScaleX = cc.view.getScaleX(), locScaleY = cc.view.getScaleY();
var locContext = this._renderContext.getContext();

locContext.beginPath();
for (var i = 0, len = points.length; i < len; i++)
locContext.arc(points[i].x * locScaleX, -points[i].y * locScaleY, size * locScaleX, 0, Math.PI * 2, false);
locContext.arc(points[i].x, -points[i].y, size, 0, Math.PI * 2, false);
locContext.closePath();
locContext.fill();
},
Expand All @@ -95,7 +93,7 @@ cc.DrawingPrimitiveCanvas = cc.Class.extend(/** @lends cc.DrawingPrimitiveCanvas
* @param {cc.Point} destination
*/
drawLine:function (origin, destination) {
var locContext = this._renderContext.getContext(), locScaleX = cc.view.getScaleX(), locScaleY = cc.view.getScaleY();
var locContext = this._renderContext.getContext();
locContext.beginPath();
locContext.moveTo(origin.x , -origin.y );
locContext.lineTo(destination.x, -destination.y );
Expand Down Expand Up @@ -151,7 +149,6 @@ cc.DrawingPrimitiveCanvas = cc.Class.extend(/** @lends cc.DrawingPrimitiveCanvas
throw new Error("Polygon's point must greater than 2");

var firstPoint = vertices[0], locContext = this._renderContext.getContext();
var locScaleX = cc.view.getScaleX(), locScaleY = cc.view.getScaleY();
locContext.beginPath();
locContext.moveTo(firstPoint.x , -firstPoint.y );
for (var i = 1, len = vertices.length; i < len; i++)
Expand Down Expand Up @@ -189,7 +186,6 @@ cc.DrawingPrimitiveCanvas = cc.Class.extend(/** @lends cc.DrawingPrimitiveCanvas
drawCircle: function (center, radius, angle, segments, drawLineToCenter) {
drawLineToCenter = drawLineToCenter || false;
var locContext = this._renderContext.getContext();
var locScaleX = cc.view.getScaleX(), locScaleY = cc.view.getScaleY();
locContext.beginPath();
var endAngle = angle - Math.PI * 2;
locContext.arc(0 | (center.x ), 0 | -(center.y ), radius , -angle, -endAngle, false);
Expand Down Expand Up @@ -379,7 +375,6 @@ cc.DrawingPrimitiveCanvas = cc.Class.extend(/** @lends cc.DrawingPrimitiveCanvas
drawColorBall:function (ctx, radius, color) {
var wrapper = ctx || this._renderContext;
var context = wrapper.getContext();
radius *= cc.view.getScaleX();
var colorStr = "rgba(" +(0|color.r) + "," + (0|color.g) + "," + (0|color.b);
var subRadius = radius / 10;

Expand Down Expand Up @@ -432,6 +427,6 @@ cc.DrawingPrimitiveCanvas = cc.Class.extend(/** @lends cc.DrawingPrimitiveCanvas
* @param {Number} width
*/
setLineWidth:function (width) {
this._renderContext.getContext().lineWidth = width * cc.view.getScaleX();
this._renderContext.getContext().lineWidth = width;
}
});
2 changes: 1 addition & 1 deletion cocos2d/core/platform/CCConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
* @type {String}
* @name cc.ENGINE_VERSION
*/
window["CocosEngine"] = cc.ENGINE_VERSION = "Cocos2d-JS v3.16";
window["CocosEngine"] = cc.ENGINE_VERSION = "Cocos2d-JS v3.17";

/**
* <p>
Expand Down
39 changes: 6 additions & 33 deletions extensions/spine/CCSkeleton.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,34 +31,6 @@
*/
var sp = sp || {};

/**
* The vertex index of spine.
* @constant
* @type {{X1: number, Y1: number, X2: number, Y2: number, X3: number, Y3: number, X4: number, Y4: number}}
*/
sp.VERTEX_INDEX = {
X1: 0,
Y1: 1,
X2: 2,
Y2: 3,
X3: 4,
Y3: 5,
X4: 6,
Y4: 7
};

/**
* The attachment type of spine. It contains three type: REGION(0), BOUNDING_BOX(1), MESH(2) and SKINNED_MESH.
* @constant
* @type {{REGION: number, BOUNDING_BOX: number, REGION_SEQUENCE: number, MESH: number}}
*/
sp.ATTACHMENT_TYPE = {
REGION: 0,
BOUNDING_BOX: 1,
MESH: 2,
SKINNED_MESH:3
};

var spine = sp.spine;

/**
Expand Down Expand Up @@ -228,11 +200,12 @@ sp.Skeleton = cc.Node.extend(/** @lends sp.Skeleton# */{
var attachment = slot.attachment;
if (!attachment || !(attachment instanceof spine.RegionAttachment))
continue;
vertices = attachment.updateWorldVertices(slot, false);
minX = Math.min(minX, vertices[VERTEX.X1] * scaleX, vertices[VERTEX.X4] * scaleX, vertices[VERTEX.X2] * scaleX, vertices[VERTEX.X3] * scaleX);
minY = Math.min(minY, vertices[VERTEX.Y1] * scaleY, vertices[VERTEX.Y4] * scaleY, vertices[VERTEX.Y2] * scaleY, vertices[VERTEX.Y3] * scaleY);
maxX = Math.max(maxX, vertices[VERTEX.X1] * scaleX, vertices[VERTEX.X4] * scaleX, vertices[VERTEX.X2] * scaleX, vertices[VERTEX.X3] * scaleX);
maxY = Math.max(maxY, vertices[VERTEX.Y1] * scaleY, vertices[VERTEX.Y4] * scaleY, vertices[VERTEX.Y2] * scaleY, vertices[VERTEX.Y3] * scaleY);
vertices = spine.Utils.setArraySize(new Array(), 8, 0);
attachment.computeWorldVertices(slot.bone, vertices, 0, 2);
minX = Math.min(minX, vertices[VERTEX.OX1] * scaleX, vertices[VERTEX.OX4] * scaleX, vertices[VERTEX.OX2] * scaleX, vertices[VERTEX.OX3] * scaleX);
minY = Math.min(minY, vertices[VERTEX.OY1] * scaleY, vertices[VERTEX.OY4] * scaleY, vertices[VERTEX.OY2] * scaleY, vertices[VERTEX.OY3] * scaleY);
maxX = Math.max(maxX, vertices[VERTEX.OX1] * scaleX, vertices[VERTEX.OX4] * scaleX, vertices[VERTEX.OX2] * scaleX, vertices[VERTEX.OX3] * scaleX);
maxY = Math.max(maxY, vertices[VERTEX.OY1] * scaleY, vertices[VERTEX.OY4] * scaleY, vertices[VERTEX.OY2] * scaleY, vertices[VERTEX.OY3] * scaleY);
}
var position = this.getPosition();
return cc.rect(position.x + minX, position.y + minY, maxX - minX, maxY - minY);
Expand Down
15 changes: 8 additions & 7 deletions extensions/spine/CCSkeletonCanvasRenderCmd.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,12 @@ proto.rendering = function (wrapper, scaleX, scaleY) {
}

// Bone origins.
drawingUtil.setPointSize(4);
var pointSize = 4;
drawingUtil.setDrawColor(0, 0, 255, 255); // Root bone is blue.

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

var vertices = attachment.updateWorldVertices(slot, false);
var vertices = spine.Utils.setArraySize(new Array(), 8, 0);
attachment.computeWorldVertices(slot.bone, vertices, 0, 2);
var VERTEX = spine.RegionAttachment;
points.length = 0;
points.push(cc.p(vertices[VERTEX.X1], vertices[VERTEX.Y1]));
points.push(cc.p(vertices[VERTEX.X4], vertices[VERTEX.Y4]));
points.push(cc.p(vertices[VERTEX.X3], vertices[VERTEX.Y3]));
points.push(cc.p(vertices[VERTEX.X2], vertices[VERTEX.Y2]));
points.push(cc.p(vertices[VERTEX.OX1], vertices[VERTEX.OY1]));
points.push(cc.p(vertices[VERTEX.OX4], vertices[VERTEX.OY4]));
points.push(cc.p(vertices[VERTEX.OX3], vertices[VERTEX.OY3]));
points.push(cc.p(vertices[VERTEX.OX2], vertices[VERTEX.OY2]));
};

proto._createChildFormSkeletonData = function () {
Expand Down
80 changes: 58 additions & 22 deletions extensions/spine/CCSkeletonWebGLRenderCmd.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,10 @@ proto.uploadData = function (f32buffer, ui32buffer, vertexDataOffset){
this._currTexture = regionTextureAtlas.texture.getRealTexture();
var batchBroken = cc.renderer._updateBatchedInfo(this._currTexture, this._getBlendFunc(slot.data.blendMode, premultiAlpha), this._glProgramState);

// keep the same logic with RendererWebGL.js, avoid vertex data overflow
var uploadAll = vertexDataOffset / 6 + vertCount > (cc.BATCH_VERTEX_COUNT - 200) * 0.5;
// Broken for vertex data overflow
if (!batchBroken && vertexDataOffset + vertCount * 6 > f32buffer.length) {
if (!batchBroken && uploadAll) {
// render the cached data
cc.renderer._batchRendering();
batchBroken = true;
Expand Down Expand Up @@ -233,7 +235,25 @@ proto._uploadRegionAttachmentData = function(attachment, slot, premultipliedAlph
nodeG = nodeColor.g,
nodeB = nodeColor.b,
nodeA = this._displayedOpacity;
var vertices = attachment.updateWorldVertices(slot, premultipliedAlpha);

var vertices = spine.Utils.setArraySize(new Array(), 8, 0);
attachment.computeWorldVertices(slot.bone, vertices, 0, 2);

var uvs = attachment.uvs;

// get the colors data
var skeleton = slot.bone.skeleton;
var skeletonColor = skeleton.color;
var slotColor = slot.color;
var regionColor = attachment.color;
var alpha = skeletonColor.a * slotColor.a * regionColor.a;
var multiplier = premultipliedAlpha ? alpha : 1;
var colors = attachment.tempColor;
colors.set(skeletonColor.r * slotColor.r * regionColor.r * multiplier,
skeletonColor.g * slotColor.g * regionColor.g * multiplier,
skeletonColor.b * slotColor.b * regionColor.b * multiplier,
alpha);

var wt = this._worldTransform,
wa = wt.a, wb = wt.b, wc = wt.c, wd = wt.d,
wx = wt.tx, wy = wt.ty,
Expand All @@ -244,32 +264,32 @@ proto._uploadRegionAttachmentData = function(attachment, slot, premultipliedAlph
// using two angles : (0, 1, 2) & (0, 2, 3)
for (var i = 0; i < 6; i++) {
var srcIdx = i < 4 ? i % 3 : i - 2;
var vx = vertices[srcIdx * 8],
vy = vertices[srcIdx * 8 + 1];
var vx = vertices[srcIdx * 2],
vy = vertices[srcIdx * 2 + 1];
var x = vx * wa + vy * wc + wx,
y = vx * wb + vy * wd + wy;
var r = vertices[srcIdx * 8 + 2] * nodeR,
g = vertices[srcIdx * 8 + 3] * nodeG,
b = vertices[srcIdx * 8 + 4] * nodeB,
a = vertices[srcIdx * 8 + 5] * nodeA;
var r = colors.r * nodeR,
g = colors.g * nodeG,
b = colors.b * nodeB,
a = colors.a * nodeA;
var color = ((a<<24) | (b<<16) | (g<<8) | r);
f32buffer[offset] = x;
f32buffer[offset + 1] = y;
f32buffer[offset + 2] = z;
ui32buffer[offset + 3] = color;
f32buffer[offset + 4] = vertices[srcIdx * 8 + 6];
f32buffer[offset + 5] = vertices[srcIdx * 8 + 7];
f32buffer[offset + 4] = uvs[srcIdx * 2];
f32buffer[offset + 5] = uvs[srcIdx * 2 + 1];
offset += 6;
}

if (this._node._debugSlots) {
// return the quad points info if debug slot enabled
var VERTEX = spine.RegionAttachment;
return [
cc.p(vertices[VERTEX.X1], vertices[VERTEX.Y1]),
cc.p(vertices[VERTEX.X2], vertices[VERTEX.Y2]),
cc.p(vertices[VERTEX.X3], vertices[VERTEX.Y3]),
cc.p(vertices[VERTEX.X4], vertices[VERTEX.Y4])
cc.p(vertices[VERTEX.OX1], vertices[VERTEX.OY1]),
cc.p(vertices[VERTEX.OX2], vertices[VERTEX.OY2]),
cc.p(vertices[VERTEX.OX3], vertices[VERTEX.OY3]),
cc.p(vertices[VERTEX.OX4], vertices[VERTEX.OY4])
];
}
};
Expand All @@ -280,30 +300,46 @@ proto._uploadMeshAttachmentData = function(attachment, slot, premultipliedAlpha,
wx = wt.tx, wy = wt.ty,
z = this._node.vertexZ;
// get the vertex data
var vertices = attachment.updateWorldVertices(slot, premultipliedAlpha);
var verticesLength = attachment.worldVerticesLength;
var vertices = spine.Utils.setArraySize(new Array(), verticesLength, 0);
attachment.computeWorldVertices(slot, 0, verticesLength, vertices, 0, 2);

var uvs = attachment.uvs;

// get the colors data
var skeleton = slot.bone.skeleton;
var skeletonColor = skeleton.color, slotColor = slot.color, meshColor = attachment.color;
var alpha = skeletonColor.a * slotColor.a * meshColor.a;
var multiplier = premultipliedAlpha ? alpha : 1;
var colors = attachment.tempColor;
colors.set(skeletonColor.r * slotColor.r * meshColor.r * multiplier,
skeletonColor.g * slotColor.g * meshColor.g * multiplier,
skeletonColor.b * slotColor.b * meshColor.b * multiplier,
alpha);

var offset = vertexDataOffset;
var nodeColor = this._displayedColor;
var nodeR = nodeColor.r,
nodeG = nodeColor.g,
nodeB = nodeColor.b,
nodeA = this._displayedOpacity;
for (var i = 0, n = vertices.length; i < n; i += 8) {
for (var i = 0, n = vertices.length; i < n; i += 2) {
var vx = vertices[i],
vy = vertices[i + 1];
var x = vx * wa + vy * wb + wx,
y = vx * wc + vy * wd + wy;
var r = vertices[i + 2] * nodeR,
g = vertices[i + 3] * nodeG,
b = vertices[i + 4] * nodeB,
a = vertices[i + 5] * nodeA;
var r = colors.r * nodeR,
g = colors.g * nodeG,
b = colors.b * nodeB,
a = colors.a * nodeA;
var color = ((a<<24) | (b<<16) | (g<<8) | r);

f32buffer[offset] = x;
f32buffer[offset + 1] = y;
f32buffer[offset + 2] = z;
ui32buffer[offset + 3] = color;
f32buffer[offset + 4] = vertices[i + 6];
f32buffer[offset + 5] = vertices[i + 7];
f32buffer[offset + 4] = uvs[i];
f32buffer[offset + 5] = uvs[i + 1];
offset += 6;
}
};
Expand Down
Loading