|
@@ -62,7 +62,7 @@ static const int quadTriangles[6] = {0, 1, 2, 2, 3, 0};
|
|
|
- (void) initialize:(spSkeletonData*)skeletonData ownsSkeletonData:(bool)ownsSkeletonData {
|
|
|
_ownsSkeletonData = ownsSkeletonData;
|
|
|
|
|
|
- worldVertices = MALLOC(float, 1000); // Max number of vertices per mesh.
|
|
|
+ _worldVertices = MALLOC(float, 1000); // Max number of vertices per mesh.
|
|
|
|
|
|
_skeleton = spSkeleton_create(skeletonData);
|
|
|
_rootBone = _skeleton->bones[0];
|
|
@@ -74,6 +74,12 @@ static const int quadTriangles[6] = {0, 1, 2, 2, 3, 0};
|
|
|
[self addChild:_drawNode];
|
|
|
|
|
|
[self setShader:[CCShader positionTextureColorShader]];
|
|
|
+
|
|
|
+ _premultipliedAlpha = true;
|
|
|
+ screenMode = [CCBlendMode blendModeWithOptions:@{
|
|
|
+ CCBlendFuncSrcColor: @(GL_ONE),
|
|
|
+ CCBlendFuncDstColor: @(GL_ONE_MINUS_SRC_COLOR)}
|
|
|
+ ];
|
|
|
}
|
|
|
|
|
|
- (id) initWithData:(spSkeletonData*)skeletonData ownsSkeletonData:(bool)ownsSkeletonData {
|
|
@@ -127,7 +133,7 @@ static const int quadTriangles[6] = {0, 1, 2, 2, 3, 0};
|
|
|
if (_ownsSkeletonData) spSkeletonData_dispose(_skeleton->data);
|
|
|
if (_atlas) spAtlas_dispose(_atlas);
|
|
|
spSkeleton_dispose(_skeleton);
|
|
|
- FREE(worldVertices);
|
|
|
+ FREE(_worldVertices);
|
|
|
[super dealloc];
|
|
|
}
|
|
|
|
|
@@ -138,7 +144,7 @@ static const int quadTriangles[6] = {0, 1, 2, 2, 3, 0};
|
|
|
_skeleton->b = nodeColor.blue;
|
|
|
_skeleton->a = self.displayedOpacity;
|
|
|
|
|
|
- int additive = -1;
|
|
|
+ int blendMode = -1;
|
|
|
const float* uvs = 0;
|
|
|
int verticesCount = 0;
|
|
|
const int* triangles = 0;
|
|
@@ -151,7 +157,7 @@ static const int quadTriangles[6] = {0, 1, 2, 2, 3, 0};
|
|
|
switch (slot->attachment->type) {
|
|
|
case SP_ATTACHMENT_REGION: {
|
|
|
spRegionAttachment* attachment = (spRegionAttachment*)slot->attachment;
|
|
|
- spRegionAttachment_computeWorldVertices(attachment, slot->bone, worldVertices);
|
|
|
+ spRegionAttachment_computeWorldVertices(attachment, slot->bone, _worldVertices);
|
|
|
texture = [self getTextureForRegion:attachment];
|
|
|
uvs = attachment->uvs;
|
|
|
verticesCount = 8;
|
|
@@ -165,7 +171,7 @@ static const int quadTriangles[6] = {0, 1, 2, 2, 3, 0};
|
|
|
}
|
|
|
case SP_ATTACHMENT_MESH: {
|
|
|
spMeshAttachment* attachment = (spMeshAttachment*)slot->attachment;
|
|
|
- spMeshAttachment_computeWorldVertices(attachment, slot, worldVertices);
|
|
|
+ spMeshAttachment_computeWorldVertices(attachment, slot, _worldVertices);
|
|
|
texture = [self getTextureForMesh:attachment];
|
|
|
uvs = attachment->uvs;
|
|
|
verticesCount = attachment->verticesCount;
|
|
@@ -179,7 +185,7 @@ static const int quadTriangles[6] = {0, 1, 2, 2, 3, 0};
|
|
|
}
|
|
|
case SP_ATTACHMENT_SKINNED_MESH: {
|
|
|
spSkinnedMeshAttachment* attachment = (spSkinnedMeshAttachment*)slot->attachment;
|
|
|
- spSkinnedMeshAttachment_computeWorldVertices(attachment, slot, worldVertices);
|
|
|
+ spSkinnedMeshAttachment_computeWorldVertices(attachment, slot, _worldVertices);
|
|
|
texture = [self getTextureForSkinnedMesh:attachment];
|
|
|
uvs = attachment->uvs;
|
|
|
verticesCount = attachment->uvsCount;
|
|
@@ -194,22 +200,34 @@ static const int quadTriangles[6] = {0, 1, 2, 2, 3, 0};
|
|
|
default: ;
|
|
|
}
|
|
|
if (texture) {
|
|
|
- if (slot->data->additiveBlending != additive) {
|
|
|
- [self setBlendMode:[CCBlendMode blendModeWithOptions:@{CCBlendFuncSrcColor: @(_blendFunc.src),CCBlendFuncDstColor: @(slot->data->additiveBlending ? GL_ONE : _blendFunc.dst)}]];
|
|
|
- additive = slot->data->additiveBlending;
|
|
|
+ if (slot->data->blendMode != blendMode) {
|
|
|
+ blendMode = slot->data->blendMode;
|
|
|
+ switch (slot->data->blendMode) {
|
|
|
+ case SP_BLEND_MODE_ADDITIVE:
|
|
|
+ [self setBlendMode:[CCBlendMode addMode]];
|
|
|
+ break;
|
|
|
+ case SP_BLEND_MODE_MULTIPLY:
|
|
|
+ [self setBlendMode:[CCBlendMode multiplyMode]];
|
|
|
+ break;
|
|
|
+ case SP_BLEND_MODE_SCREEN:
|
|
|
+ [self setBlendMode:screenMode];
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ [self setBlendMode:_premultipliedAlpha ? [CCBlendMode premultipliedAlphaMode] : [CCBlendMode alphaMode]];
|
|
|
+ }
|
|
|
}
|
|
|
if (_premultipliedAlpha) {
|
|
|
- a *= _skeleton->a * slot->a;
|
|
|
- r *= _skeleton->r * slot->r * a;
|
|
|
- g *= _skeleton->g * slot->g * a;
|
|
|
- b *= _skeleton->b * slot->b * a;
|
|
|
- } else {
|
|
|
- a *= _skeleton->a * slot->a;
|
|
|
- r *= _skeleton->r * slot->r;
|
|
|
- g *= _skeleton->g * slot->g;
|
|
|
- b *= _skeleton->b * slot->b;
|
|
|
+ a *= _skeleton->a * slot->a;
|
|
|
+ r *= _skeleton->r * slot->r * a;
|
|
|
+ g *= _skeleton->g * slot->g * a;
|
|
|
+ b *= _skeleton->b * slot->b * a;
|
|
|
+ } else {
|
|
|
+ a *= _skeleton->a * slot->a;
|
|
|
+ r *= _skeleton->r * slot->r;
|
|
|
+ g *= _skeleton->g * slot->g;
|
|
|
+ b *= _skeleton->b * slot->b;
|
|
|
}
|
|
|
- self.texture = texture;
|
|
|
+ self.texture = texture;
|
|
|
CGSize size = texture.contentSize;
|
|
|
GLKVector2 center = GLKVector2Make(size.width / 2.0, size.height / 2.0);
|
|
|
GLKVector2 extents = GLKVector2Make(size.width / 2.0, size.height / 2.0);
|
|
@@ -217,7 +235,7 @@ static const int quadTriangles[6] = {0, 1, 2, 2, 3, 0};
|
|
|
CCRenderBuffer buffer = [renderer enqueueTriangles:(trianglesCount / 3) andVertexes:verticesCount withState:self.renderState globalSortOrder:0];
|
|
|
for (int i = 0; i * 2 < verticesCount; ++i) {
|
|
|
CCVertex vertex;
|
|
|
- vertex.position = GLKVector4Make(worldVertices[i * 2], worldVertices[i * 2 + 1], 0.0, 1.0);
|
|
|
+ vertex.position = GLKVector4Make(_worldVertices[i * 2], _worldVertices[i * 2 + 1], 0.0, 1.0);
|
|
|
vertex.color = GLKVector4Make(r, g, b, a);
|
|
|
vertex.texCoord1 = GLKVector2Make(uvs[i * 2], 1 - uvs[i * 2 + 1]);
|
|
|
CCRenderBufferSetVertex(buffer, i, CCVertexApplyTransform(vertex, transform));
|
|
@@ -236,11 +254,11 @@ static const int quadTriangles[6] = {0, 1, 2, 2, 3, 0};
|
|
|
spSlot* slot = _skeleton->drawOrder[i];
|
|
|
if (!slot->attachment || slot->attachment->type != SP_ATTACHMENT_REGION) continue;
|
|
|
spRegionAttachment* attachment = (spRegionAttachment*)slot->attachment;
|
|
|
- spRegionAttachment_computeWorldVertices(attachment, slot->bone, worldVertices);
|
|
|
- points[0] = ccp(worldVertices[0], worldVertices[1]);
|
|
|
- points[1] = ccp(worldVertices[2], worldVertices[3]);
|
|
|
- points[2] = ccp(worldVertices[4], worldVertices[5]);
|
|
|
- points[3] = ccp(worldVertices[6], worldVertices[7]);
|
|
|
+ spRegionAttachment_computeWorldVertices(attachment, slot->bone, _worldVertices);
|
|
|
+ points[0] = ccp(_worldVertices[0], _worldVertices[1]);
|
|
|
+ points[1] = ccp(_worldVertices[2], _worldVertices[3]);
|
|
|
+ points[2] = ccp(_worldVertices[4], _worldVertices[5]);
|
|
|
+ points[3] = ccp(_worldVertices[6], _worldVertices[7]);
|
|
|
[_drawNode drawPolyWithVerts:points count:4 fillColor:[CCColor clearColor] borderWidth:1 borderColor:[CCColor blueColor]];
|
|
|
}
|
|
|
}
|
|
@@ -283,20 +301,20 @@ static const int quadTriangles[6] = {0, 1, 2, 2, 3, 0};
|
|
|
int verticesCount;
|
|
|
if (slot->attachment->type == SP_ATTACHMENT_REGION) {
|
|
|
spRegionAttachment* attachment = (spRegionAttachment*)slot->attachment;
|
|
|
- spRegionAttachment_computeWorldVertices(attachment, slot->bone, worldVertices);
|
|
|
+ spRegionAttachment_computeWorldVertices(attachment, slot->bone, _worldVertices);
|
|
|
verticesCount = 8;
|
|
|
} else if (slot->attachment->type == SP_ATTACHMENT_MESH) {
|
|
|
spMeshAttachment* mesh = (spMeshAttachment*)slot->attachment;
|
|
|
- spMeshAttachment_computeWorldVertices(mesh, slot, worldVertices);
|
|
|
+ spMeshAttachment_computeWorldVertices(mesh, slot, _worldVertices);
|
|
|
verticesCount = mesh->verticesCount;
|
|
|
} else if (slot->attachment->type == SP_ATTACHMENT_SKINNED_MESH) {
|
|
|
spSkinnedMeshAttachment* mesh = (spSkinnedMeshAttachment*)slot->attachment;
|
|
|
- spSkinnedMeshAttachment_computeWorldVertices(mesh, slot, worldVertices);
|
|
|
+ spSkinnedMeshAttachment_computeWorldVertices(mesh, slot, _worldVertices);
|
|
|
verticesCount = mesh->uvsCount;
|
|
|
} else
|
|
|
continue;
|
|
|
for (int ii = 0; ii < verticesCount; ii += 2) {
|
|
|
- float x = worldVertices[ii] * scaleX, y = worldVertices[ii + 1] * scaleY;
|
|
|
+ float x = _worldVertices[ii] * scaleX, y = _worldVertices[ii + 1] * scaleY;
|
|
|
minX = fmin(minX, x);
|
|
|
minY = fmin(minY, y);
|
|
|
maxX = fmax(maxX, x);
|