Skip to content

Commit e233830

Browse files
committed
Added worldToLocal method for webgl context
1 parent f2a19c9 commit e233830

1 file changed

Lines changed: 35 additions & 0 deletions

File tree

plugins/spine/src/SpinePlugin.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,9 @@ var SpinePlugin = new Class({
7272
this.getAtlas = this.getAtlasCanvas;
7373
}
7474

75+
this.temp1;
76+
this.temp2;
77+
7578
// Register our file type
7679
pluginManager.registerFileType('spine', this.spineFileCallback, scene);
7780

@@ -169,6 +172,38 @@ var SpinePlugin = new Class({
169172
this.sceneRenderer.shapes.setBlendMode = setBlendMode;
170173

171174
this.skeletonDebugRenderer = this.sceneRenderer.skeletonDebugRenderer;
175+
176+
this.temp1 = new Spine.webgl.Vector3(0, 0, 0);
177+
this.temp2 = new Spine.webgl.Vector3(0, 0, 0);
178+
},
179+
180+
worldToLocal: function (x, y, skeleton, bone)
181+
{
182+
var temp1 = this.temp1;
183+
var temp2 = this.temp2;
184+
var camera = this.sceneRenderer.camera;
185+
186+
temp1.set(x + skeleton.x, y - skeleton.y, 0);
187+
188+
var width = camera.viewportWidth;
189+
var height = camera.viewportHeight;
190+
191+
camera.screenToWorld(temp1, width, height);
192+
193+
if (bone && bone.parent !== null)
194+
{
195+
bone.parent.worldToLocal(temp2.set(temp1.x - skeleton.x, temp1.y - skeleton.y, 0));
196+
197+
return new Spine.Vector2(temp2.x, temp2.y);
198+
}
199+
else if (bone)
200+
{
201+
return new Spine.Vector2(temp1.x - skeleton.x, temp1.y - skeleton.y);
202+
}
203+
else
204+
{
205+
return new Spine.Vector2(temp1.x, temp1.y);
206+
}
172207
},
173208

174209
getAtlasWebGL: function (key)

0 commit comments

Comments
 (0)