Skip to content

Commit

Permalink
multiply bone world space with region attachment local space
Browse files Browse the repository at this point in the history
  • Loading branch information
flyover committed Nov 4, 2015
1 parent 141e03b commit 2dd683d
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 17 deletions.
12 changes: 9 additions & 3 deletions demo/render-ctx2d.js
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,9 @@ renderCtx2D.prototype.drawPose = function (spine_pose, atlas_data)
switch (attachment.type)
{
case 'region':
ctxApplySpace(ctx, attachment.world_space);
var bone = spine_pose.bones[slot.bone_key];
ctxApplySpace(ctx, bone.world_space);
ctxApplySpace(ctx, attachment.local_space);
ctxApplyAtlasSitePosition(ctx, site);
ctx.scale(attachment.width/2, attachment.height/2);
ctxDrawImageMesh(ctx, render.region_vertex_triangle, render.region_vertex_position, render.region_vertex_texcoord, image, site, page);
Expand Down Expand Up @@ -333,7 +335,9 @@ renderCtx2D.prototype.drawDebugPose = function (spine_pose, atlas_data)
switch (attachment.type)
{
case 'region':
ctxApplySpace(ctx, attachment.world_space);
var bone = spine_pose.bones[slot.bone_key];
ctxApplySpace(ctx, bone.world_space);
ctxApplySpace(ctx, attachment.local_space);
ctxApplyAtlasSitePosition(ctx, site);
ctx.beginPath();
ctx.rect(-attachment.width/2, -attachment.height/2, attachment.width, attachment.height);
Expand Down Expand Up @@ -408,7 +412,9 @@ renderCtx2D.prototype.drawDebugData = function (spine_pose, atlas_data)
switch (attachment.type)
{
case 'region':
ctxApplySpace(ctx, attachment.world_space);
var bone = spine_pose.bones[slot.bone_key];
ctxApplySpace(ctx, bone.world_space);
ctxApplySpace(ctx, attachment.local_space);
ctxApplyAtlasSitePosition(ctx, site);
ctx.beginPath();
ctx.rect(-attachment.width/2, -attachment.height/2, attachment.width, attachment.height);
Expand Down
4 changes: 3 additions & 1 deletion demo/render-webgl.js
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,9 @@ renderWebGL.prototype.drawPose = function (spine_pose, atlas_data)
switch (attachment.type)
{
case 'region':
mat3x3ApplySpace(gl_modelview, attachment.world_space);
var bone = spine_pose.bones[slot.bone_key];
mat3x3ApplySpace(gl_modelview, bone.world_space);
mat3x3ApplySpace(gl_modelview, attachment.local_space);
mat3x3Scale(gl_modelview, attachment.width/2, attachment.height/2);
mat3x3ApplyAtlasSitePosition(gl_modelview, site);

Expand Down
13 changes: 0 additions & 13 deletions spine.js
Original file line number Diff line number Diff line change
Expand Up @@ -1222,15 +1222,12 @@ spine.RegionAttachment = function ()
{
goog.base(this, 'region');
this.local_space = new spine.Space();
this.world_space = new spine.Space();
}

goog.inherits(spine.RegionAttachment, spine.Attachment);

/** @type {spine.Space} */
spine.RegionAttachment.prototype.local_space;
/** @type {spine.Space} */
spine.RegionAttachment.prototype.world_space;
/** @type {number} */
spine.RegionAttachment.prototype.width = 0;
/** @type {number} */
Expand All @@ -1246,7 +1243,6 @@ spine.RegionAttachment.prototype.load = function (json)

var attachment = this;
attachment.local_space.load(json);
attachment.world_space.copy(attachment.local_space);
attachment.width = spine.loadFloat(json, 'width', 0);
attachment.height = spine.loadFloat(json, 'height', 0);
return attachment;
Expand Down Expand Up @@ -3323,15 +3319,6 @@ spine.Pose.prototype.strike = function ()

pose.slot_keys = data.slot_keys;

pose.iterateAttachments(function (slot_key, slot, skin_slot, attachment_key, attachment)
{
if (!attachment) { return; }
if (attachment.type !== 'region') { return; }

var bone = pose.bones[slot.bone_key];
spine.Space.combine(bone.world_space, attachment.local_space, attachment.world_space);
});

if (anim)
{
var keyframe_index = spine.Keyframe.find(anim.order_keyframes, time);
Expand Down

0 comments on commit 2dd683d

Please sign in to comment.