Every space in its place! (tm)

(whitespace clean up)
This commit is contained in:
NathanSweet 2016-10-15 23:15:41 +02:00
parent ded7a697d9
commit 7a18f0818c
106 changed files with 2314 additions and 2316 deletions

View File

@ -366,14 +366,14 @@ public class SkeletonJson {
var bones:Vector.<int> = new Vector.<int>(verticesLength * 3); var bones:Vector.<int> = new Vector.<int>(verticesLength * 3);
bones.length = 0; bones.length = 0;
for (i = 0, n = vertices.length; i < n;) { for (i = 0, n = vertices.length; i < n;) {
var boneCount:int = int(vertices[i++]); var boneCount:int = int(vertices[i++]);
bones.push(boneCount); bones.push(boneCount);
for (var nn:int = i + boneCount * 4; i < nn; i+=4) { for (var nn:int = i + boneCount * 4; i < nn; i+=4) {
bones.push(int(vertices[i])); bones.push(int(vertices[i]));
weights.push(vertices[i + 1] * scale); weights.push(vertices[i + 1] * scale);
weights.push(vertices[i + 2] * scale); weights.push(vertices[i + 2] * scale);
weights.push(vertices[i + 3]); weights.push(vertices[i + 3]);
} }
} }
attachment.bones = bones; attachment.bones = bones;
attachment.vertices = weights; attachment.vertices = weights;

View File

@ -463,7 +463,7 @@ void _spColorTimeline_apply (const spTimeline* timeline, spSkeleton* skeleton, f
frameTime = self->frames[frame]; frameTime = self->frames[frame];
percent = spCurveTimeline_getCurvePercent(SUPER(self), frame / COLOR_ENTRIES - 1, percent = spCurveTimeline_getCurvePercent(SUPER(self), frame / COLOR_ENTRIES - 1,
1 - (time - frameTime) / (self->frames[frame + COLOR_PREV_TIME] - frameTime)); 1 - (time - frameTime) / (self->frames[frame + COLOR_PREV_TIME] - frameTime));
r += (self->frames[frame + COLOR_R] - r) * percent; r += (self->frames[frame + COLOR_R] - r) * percent;
g += (self->frames[frame + COLOR_G] - g) * percent; g += (self->frames[frame + COLOR_G] - g) * percent;
@ -918,7 +918,7 @@ static const int PATHCONSTRAINTPOSITION_PREV_VALUE = -1;
static const int PATHCONSTRAINTPOSITION_VALUE = 1; static const int PATHCONSTRAINTPOSITION_VALUE = 1;
void _spPathConstraintPositionTimeline_apply(const spTimeline* timeline, spSkeleton* skeleton, float lastTime, float time, void _spPathConstraintPositionTimeline_apply(const spTimeline* timeline, spSkeleton* skeleton, float lastTime, float time,
spEvent** firedEvents, int* eventsCount, float alpha) { spEvent** firedEvents, int* eventsCount, float alpha) {
int frame; int frame;
float frameTime, percent, position; float frameTime, percent, position;
spPathConstraint* constraint; spPathConstraint* constraint;
@ -963,7 +963,7 @@ static const int PATHCONSTRAINTSPACING_PREV_VALUE = -1;
static const int PATHCONSTRAINTSPACING_VALUE = 1; static const int PATHCONSTRAINTSPACING_VALUE = 1;
void _spPathConstraintSpacingTimeline_apply(const spTimeline* timeline, spSkeleton* skeleton, float lastTime, float time, void _spPathConstraintSpacingTimeline_apply(const spTimeline* timeline, spSkeleton* skeleton, float lastTime, float time,
spEvent** firedEvents, int* eventsCount, float alpha) { spEvent** firedEvents, int* eventsCount, float alpha) {
int frame; int frame;
float frameTime, percent, spacing; float frameTime, percent, spacing;
spPathConstraint* constraint; spPathConstraint* constraint;

View File

@ -202,7 +202,7 @@ spAtlas* spAtlas_create (const char* begin, int length, const char* dir, void* r
switch (readTuple(&begin, end, tuple)) { switch (readTuple(&begin, end, tuple)) {
case 0: case 0:
return abortAtlas(self); return abortAtlas(self);
case 2: /* size is only optional for an atlas packed with an old TexturePacker. */ case 2: /* size is only optional for an atlas packed with an old TexturePacker. */
page->width = toInt(tuple); page->width = toInt(tuple);
page->height = toInt(tuple + 1); page->height = toInt(tuple + 1);
if (!readTuple(&begin, end, tuple)) return abortAtlas(self); if (!readTuple(&begin, end, tuple)) return abortAtlas(self);

View File

@ -126,7 +126,7 @@ void spPathConstraint_apply (spPathConstraint* self) {
} }
positions = spPathConstraint_computeWorldPositions(self, attachment, spacesCount, tangents, positions = spPathConstraint_computeWorldPositions(self, attachment, spacesCount, tangents,
data->positionMode == SP_POSITION_MODE_PERCENT, spacingMode == SP_SPACING_MODE_PERCENT); data->positionMode == SP_POSITION_MODE_PERCENT, spacingMode == SP_SPACING_MODE_PERCENT);
skeleton = self->target->bone->skeleton; skeleton = self->target->bone->skeleton;
skeletonX = skeleton->x, skeletonY = skeleton->y; skeletonX = skeleton->x, skeletonY = skeleton->y;
boneX = positions[0], boneY = positions[1], offsetRotation = self->data->offsetRotation; boneX = positions[0], boneY = positions[1], offsetRotation = self->data->offsetRotation;
@ -192,7 +192,7 @@ static void _addAfterPosition (float p, float* temp, int i, float* out, int o) {
} }
static void _addCurvePosition (float p, float x1, float y1, float cx1, float cy1, float cx2, float cy2, float x2, float y2, static void _addCurvePosition (float p, float x1, float y1, float cx1, float cy1, float cx2, float cy2, float x2, float y2,
float* out, int o, int/*bool*/tangents) { float* out, int o, int/*bool*/tangents) {
float tt, ttt, u, uu, uuu; float tt, ttt, u, uu, uuu;
float ut, ut3, uut3, utt3; float ut, ut3, uut3, utt3;
float x, y; float x, y;
@ -283,7 +283,7 @@ float* spPathConstraint_computeWorldPositions(spPathConstraint* self, spPathAtta
spPathAttachment_computeWorldVertices1(path, target, curve * 6 + 2, 8, world, 0); spPathAttachment_computeWorldVertices1(path, target, curve * 6 + 2, 8, world, 0);
} }
_addCurvePosition(p, world[0], world[1], world[2], world[3], world[4], world[5], world[6], world[7], out, o, _addCurvePosition(p, world[0], world[1], world[2], world[3], world[4], world[5], world[6], world[7], out, o,
tangents || (i > 0 && space == 0)); tangents || (i > 0 && space == 0));
} }
return out; return out;
} }

View File

@ -353,7 +353,7 @@ static spAnimation* _spSkeletonJson_readAnimation (spSkeletonJson* self, Json* r
timeline->pathConstraintIndex = constraintIndex; timeline->pathConstraintIndex = constraintIndex;
for (valueMap = timelineMap->child, frameIndex = 0; valueMap; valueMap = valueMap->next, ++frameIndex) { for (valueMap = timelineMap->child, frameIndex = 0; valueMap; valueMap = valueMap->next, ++frameIndex) {
spPathConstraintMixTimeline_setFrame(timeline, frameIndex, Json_getFloat(valueMap, "time", 0), spPathConstraintMixTimeline_setFrame(timeline, frameIndex, Json_getFloat(valueMap, "time", 0),
Json_getFloat(valueMap, "rotateMix", 1), Json_getFloat(valueMap, "translateMix", 1)); Json_getFloat(valueMap, "rotateMix", 1), Json_getFloat(valueMap, "translateMix", 1));
readCurve(valueMap, SUPER(timeline), frameIndex); readCurve(valueMap, SUPER(timeline), frameIndex);
} }
animation->timelines[animation->timelinesCount++] = SUPER_CAST(spTimeline, timeline); animation->timelines[animation->timelinesCount++] = SUPER_CAST(spTimeline, timeline);
@ -594,7 +594,7 @@ spSkeletonData* spSkeletonJson_readSkeletonData (spSkeletonJson* self, const cha
skeleton = Json_getItem(root, "skeleton"); skeleton = Json_getItem(root, "skeleton");
if (skeleton) { if (skeleton) {
MALLOC_STR(skeletonData->hash, Json_getString(skeleton, "hash", 0)); MALLOC_STR(skeletonData->hash, Json_getString(skeleton, "hash", 0));
MALLOC_STR(skeletonData->version, Json_getString(skeleton, "spine", 0)); MALLOC_STR(skeletonData->version, Json_getString(skeleton, "spine", 0));
skeletonData->width = Json_getFloat(skeleton, "width", 0); skeletonData->width = Json_getFloat(skeleton, "width", 0);
skeletonData->height = Json_getFloat(skeleton, "height", 0); skeletonData->height = Json_getFloat(skeleton, "height", 0);
} }

View File

@ -7,56 +7,56 @@ local activeSkeleton = 1
local lastTime = 0 local lastTime = 0
function loadSkeleton(atlasFile, jsonFile, x, y, scale, animation, skin) function loadSkeleton(atlasFile, jsonFile, x, y, scale, animation, skin)
-- to load an atlas, we need to define a function that returns -- to load an atlas, we need to define a function that returns
-- a Corona paint object. This allows you to resolve images -- a Corona paint object. This allows you to resolve images
-- however you see fit -- however you see fit
local imageLoader = function (path) local imageLoader = function (path)
local paint = { type = "image", filename = "data/" .. path } local paint = { type = "image", filename = "data/" .. path }
return paint return paint
end end
-- load the atlas -- load the atlas
local atlas = spine.TextureAtlas.new(spine.utils.readFile("data/" .. atlasFile), imageLoader) local atlas = spine.TextureAtlas.new(spine.utils.readFile("data/" .. atlasFile), imageLoader)
-- load the JSON and create a Skeleton from it -- load the JSON and create a Skeleton from it
local json = spine.SkeletonJson.new(spine.AtlasAttachmentLoader.new(atlas)) local json = spine.SkeletonJson.new(spine.AtlasAttachmentLoader.new(atlas))
json.scale = scale json.scale = scale
local skeletonData = json:readSkeletonDataFile("data/" .. jsonFile) local skeletonData = json:readSkeletonDataFile("data/" .. jsonFile)
local skeleton = spine.Skeleton.new(skeletonData) local skeleton = spine.Skeleton.new(skeletonData)
skeleton.flipY = true -- Corona's coordinate system has its y-axis point downwards skeleton.flipY = true -- Corona's coordinate system has its y-axis point downwards
skeleton.group.x = x skeleton.group.x = x
skeleton.group.y = y skeleton.group.y = y
-- Set the skin if we got one -- Set the skin if we got one
if skin then skeleton:setSkin(skin) end if skin then skeleton:setSkin(skin) end
-- create an animation state object to apply animations to the skeleton -- create an animation state object to apply animations to the skeleton
local animationStateData = spine.AnimationStateData.new(skeletonData) local animationStateData = spine.AnimationStateData.new(skeletonData)
local animationState = spine.AnimationState.new(animationStateData) local animationState = spine.AnimationState.new(animationStateData)
animationState:setAnimationByName(0, animation, true) animationState:setAnimationByName(0, animation, true)
-- set the skeleton invisible -- set the skeleton invisible
skeleton.group.isVisible = false skeleton.group.isVisible = false
-- set a name on the group of the skeleton so we can find it during debugging -- set a name on the group of the skeleton so we can find it during debugging
skeleton.group.name = jsonFile skeleton.group.name = jsonFile
-- set some event callbacks -- set some event callbacks
animationState.onStart = function (trackIndex) animationState.onStart = function (trackIndex)
print(trackIndex.." start: "..animationState:getCurrent(trackIndex).animation.name) print(trackIndex.." start: "..animationState:getCurrent(trackIndex).animation.name)
end end
animationState.onEnd = function (trackIndex) animationState.onEnd = function (trackIndex)
print(trackIndex.." end: "..animationState:getCurrent(trackIndex).animation.name) print(trackIndex.." end: "..animationState:getCurrent(trackIndex).animation.name)
end end
animationState.onComplete = function (trackIndex, loopCount) animationState.onComplete = function (trackIndex, loopCount)
print(trackIndex.." complete: "..animationState:getCurrent(trackIndex).animation.name..", "..loopCount) print(trackIndex.." complete: "..animationState:getCurrent(trackIndex).animation.name..", "..loopCount)
end end
animationState.onEvent = function (trackIndex, event) animationState.onEvent = function (trackIndex, event)
print(trackIndex.." event: "..animationState:getCurrent(trackIndex).animation.name..", "..event.data.name..", "..event.intValue..", "..event.floatValue..", '"..(event.stringValue or "").."'") print(trackIndex.." event: "..animationState:getCurrent(trackIndex).animation.name..", "..event.data.name..", "..event.intValue..", "..event.floatValue..", '"..(event.stringValue or "").."'")
end end
-- return the skeleton an animation state -- return the skeleton an animation state
return { skeleton = skeleton, state = animationState } return { skeleton = skeleton, state = animationState }
end end
table.insert(skeletons, loadSkeleton("spineboy.atlas", "spineboy.json", 240, 300, 0.4, "walk")) table.insert(skeletons, loadSkeleton("spineboy.atlas", "spineboy.json", 240, 300, 0.4, "walk"))
@ -73,21 +73,21 @@ Runtime:addEventListener("enterFrame", function (event)
local delta = currentTime - lastTime local delta = currentTime - lastTime
lastTime = currentTime lastTime = currentTime
skeleton = skeletons[activeSkeleton].skeleton skeleton = skeletons[activeSkeleton].skeleton
skeleton.group.isVisible = true skeleton.group.isVisible = true
state = skeletons[activeSkeleton].state state = skeletons[activeSkeleton].state
state:update(delta) state:update(delta)
state:apply(skeleton) state:apply(skeleton)
skeleton:updateWorldTransform() skeleton:updateWorldTransform()
-- uncomment if you want to know how many batches a skeleton renders to -- uncomment if you want to know how many batches a skeleton renders to
-- print(skeleton.batches) -- print(skeleton.batches)
end) end)
Runtime:addEventListener("tap", function(event) Runtime:addEventListener("tap", function(event)
skeletons[activeSkeleton].skeleton.group.isVisible = false skeletons[activeSkeleton].skeleton.group.isVisible = false
activeSkeleton = activeSkeleton + 1 activeSkeleton = activeSkeleton + 1
if activeSkeleton > #skeletons then activeSkeleton = 1 end if activeSkeleton > #skeletons then activeSkeleton = 1 end
skeletons[activeSkeleton].skeleton.group.isVisible = true skeletons[activeSkeleton].skeleton.group.isVisible = true
end) end)

File diff suppressed because it is too large Load Diff

View File

@ -54,7 +54,7 @@ namespace Spine {
* *
* Changes made: * Changes made:
* *
* - Optimized parser speed (deserialize roughly near 3x faster than original) * - Optimized parser speed (deserialize roughly near 3x faster than original)
* - Added support to handle lexer/parser error messages with line numbers * - Added support to handle lexer/parser error messages with line numbers
* - Added more fine grained control over type conversions during the parsing * - Added more fine grained control over type conversions during the parsing
* - Refactory API (Separate Lexer code from Parser code and the Encoder from Decoder) * - Refactory API (Separate Lexer code from Parser code and the Encoder from Decoder)
@ -263,8 +263,7 @@ namespace SharpJson
for (lastIndex = index; lastIndex < json.Length; lastIndex++) { for (lastIndex = index; lastIndex < json.Length; lastIndex++) {
char ch = json[lastIndex]; char ch = json[lastIndex];
if ((ch < '0' || ch > '9') && ch != '+' && ch != '-' if ((ch < '0' || ch > '9') && ch != '+' && ch != '-' && ch != '.' && ch != 'e' && ch != 'E')
&& ch != '.' && ch != 'e' && ch != 'E')
break; break;
} }
@ -333,10 +332,11 @@ namespace SharpJson
// false // false
if (remainingLength >= 5) { if (remainingLength >= 5) {
if (json[index] == 'f' && if (json[index] == 'f' &&
json[index + 1] == 'a' && json[index + 1] == 'a' &&
json[index + 2] == 'l' && json[index + 2] == 'l' &&
json[index + 3] == 's' && json[index + 3] == 's' &&
json[index + 4] == 'e') { json[index + 4] == 'e'
) {
index += 5; index += 5;
return Token.False; return Token.False;
} }
@ -345,9 +345,10 @@ namespace SharpJson
// true // true
if (remainingLength >= 4) { if (remainingLength >= 4) {
if (json[index] == 't' && if (json[index] == 't' &&
json[index + 1] == 'r' && json[index + 1] == 'r' &&
json[index + 2] == 'u' && json[index + 2] == 'u' &&
json[index + 3] == 'e') { json[index + 3] == 'e'
) {
index += 4; index += 4;
return Token.True; return Token.True;
} }
@ -356,9 +357,10 @@ namespace SharpJson
// null // null
if (remainingLength >= 4) { if (remainingLength >= 4) {
if (json[index] == 'n' && if (json[index] == 'n' &&
json[index + 1] == 'u' && json[index + 1] == 'u' &&
json[index + 2] == 'l' && json[index + 2] == 'l' &&
json[index + 3] == 'l') { json[index + 3] == 'l'
) {
index += 4; index += 4;
return Token.Null; return Token.Null;
} }

View File

@ -171,7 +171,7 @@ namespace Spine {
for (int i = 0, n = ReadVarint(input, true); i < n; i++) { for (int i = 0, n = ReadVarint(input, true); i < n; i++) {
TransformConstraintData data = new TransformConstraintData(ReadString(input)); TransformConstraintData data = new TransformConstraintData(ReadString(input));
for (int ii = 0, nn = ReadVarint(input, true); ii < nn; ii++) for (int ii = 0, nn = ReadVarint(input, true); ii < nn; ii++)
data.bones.Add(skeletonData.bones.Items[ReadVarint(input, true)]); data.bones.Add(skeletonData.bones.Items[ReadVarint(input, true)]);
data.target = skeletonData.bones.Items[ReadVarint(input, true)]; data.target = skeletonData.bones.Items[ReadVarint(input, true)];
data.offsetRotation = ReadFloat(input); data.offsetRotation = ReadFloat(input);
data.offsetX = ReadFloat(input) * scale; data.offsetX = ReadFloat(input) * scale;

View File

@ -34,74 +34,74 @@ local skeletons = {}
local activeSkeleton = 1 local activeSkeleton = 1
function loadSkeleton (jsonFile, atlasFile, animation, skin, scale, x, y) function loadSkeleton (jsonFile, atlasFile, animation, skin, scale, x, y)
local loader = function (path) return love.graphics.newImage("data/" .. path) end local loader = function (path) return love.graphics.newImage("data/" .. path) end
local atlas = spine.TextureAtlas.new(spine.utils.readFile("data/" .. atlasFile .. ".atlas"), loader) local atlas = spine.TextureAtlas.new(spine.utils.readFile("data/" .. atlasFile .. ".atlas"), loader)
local json = spine.SkeletonJson.new(spine.AtlasAttachmentLoader.new(atlas)) local json = spine.SkeletonJson.new(spine.AtlasAttachmentLoader.new(atlas))
json.scale = scale json.scale = scale
local skeletonData = json:readSkeletonDataFile("data/" .. jsonFile .. ".json") local skeletonData = json:readSkeletonDataFile("data/" .. jsonFile .. ".json")
local skeleton = spine.Skeleton.new(skeletonData) local skeleton = spine.Skeleton.new(skeletonData)
skeleton.x = x skeleton.x = x
skeleton.y = y skeleton.y = y
skeleton.flipX = false skeleton.flipX = false
skeleton.flipY = true skeleton.flipY = true
if skin then if skin then
skeleton:setSkin(skin) skeleton:setSkin(skin)
end end
skeleton:setToSetupPose() skeleton:setToSetupPose()
local stateData = spine.AnimationStateData.new(skeletonData) local stateData = spine.AnimationStateData.new(skeletonData)
local state = spine.AnimationState.new(stateData) local state = spine.AnimationState.new(stateData)
state:setAnimationByName(0, animation, true) state:setAnimationByName(0, animation, true)
state.onStart = function (trackIndex) state.onStart = function (trackIndex)
print(trackIndex.." start: "..state:getCurrent(trackIndex).animation.name) print(trackIndex.." start: "..state:getCurrent(trackIndex).animation.name)
end end
state.onEnd = function (trackIndex) state.onEnd = function (trackIndex)
print(trackIndex.." end: "..state:getCurrent(trackIndex).animation.name) print(trackIndex.." end: "..state:getCurrent(trackIndex).animation.name)
end end
state.onComplete = function (trackIndex, loopCount) state.onComplete = function (trackIndex, loopCount)
print(trackIndex.." complete: "..state:getCurrent(trackIndex).animation.name..", "..loopCount) print(trackIndex.." complete: "..state:getCurrent(trackIndex).animation.name..", "..loopCount)
end end
state.onEvent = function (trackIndex, event) state.onEvent = function (trackIndex, event)
print(trackIndex.." event: "..state:getCurrent(trackIndex).animation.name..", "..event.data.name..", "..event.intValue..", "..event.floatValue..", '"..(event.stringValue or "").."'") print(trackIndex.." event: "..state:getCurrent(trackIndex).animation.name..", "..event.data.name..", "..event.intValue..", "..event.floatValue..", '"..(event.stringValue or "").."'")
end end
state:update(0.5) state:update(0.5)
state:apply(skeleton) state:apply(skeleton)
return { state = state, skeleton = skeleton } return { state = state, skeleton = skeleton }
end end
function love.load(arg) function love.load(arg)
if arg[#arg] == "-debug" then require("mobdebug").start() end if arg[#arg] == "-debug" then require("mobdebug").start() end
table.insert(skeletons, loadSkeleton("test", "test", "animation", nil, 0.5, 400, 300)) table.insert(skeletons, loadSkeleton("test", "test", "animation", nil, 0.5, 400, 300))
table.insert(skeletons, loadSkeleton("spineboy", "spineboy", "walk", nil, 0.5, 400, 500)) table.insert(skeletons, loadSkeleton("spineboy", "spineboy", "walk", nil, 0.5, 400, 500))
table.insert(skeletons, loadSkeleton("raptor", "raptor", "walk", nil, 0.3, 400, 500)) table.insert(skeletons, loadSkeleton("raptor", "raptor", "walk", nil, 0.3, 400, 500))
table.insert(skeletons, loadSkeleton("goblins-mesh", "goblins", "walk", "goblin", 1, 400, 500)) table.insert(skeletons, loadSkeleton("goblins-mesh", "goblins", "walk", "goblin", 1, 400, 500))
table.insert(skeletons, loadSkeleton("tank", "tank", "drive", nil, 0.2, 600, 500)) table.insert(skeletons, loadSkeleton("tank", "tank", "drive", nil, 0.2, 600, 500))
table.insert(skeletons, loadSkeleton("vine", "vine", "animation", nil, 0.3, 400, 500)) table.insert(skeletons, loadSkeleton("vine", "vine", "animation", nil, 0.3, 400, 500))
table.insert(skeletons, loadSkeleton("stretchyman", "stretchyman", "sneak", nil, 0.3, 200, 500)) table.insert(skeletons, loadSkeleton("stretchyman", "stretchyman", "sneak", nil, 0.3, 200, 500))
skeletonRenderer = spine.SkeletonRenderer.new() skeletonRenderer = spine.SkeletonRenderer.new()
end end
function love.update (delta) function love.update (delta)
-- Update the state with the delta time, apply it, and update the world transforms. -- Update the state with the delta time, apply it, and update the world transforms.
local state = skeletons[activeSkeleton].state local state = skeletons[activeSkeleton].state
local skeleton = skeletons[activeSkeleton].skeleton local skeleton = skeletons[activeSkeleton].skeleton
state:update(delta) state:update(delta)
state:apply(skeleton) state:apply(skeleton)
skeleton:updateWorldTransform() skeleton:updateWorldTransform()
end end
function love.draw () function love.draw ()
love.graphics.setBackgroundColor(128, 128, 128, 255) love.graphics.setBackgroundColor(128, 128, 128, 255)
love.graphics.setColor(255, 255, 255) love.graphics.setColor(255, 255, 255)
local skeleton = skeletons[activeSkeleton].skeleton local skeleton = skeletons[activeSkeleton].skeleton
skeletonRenderer:draw(skeleton) skeletonRenderer:draw(skeleton)
end end
function love.mousepressed (x, y, button, istouch) function love.mousepressed (x, y, button, istouch)
activeSkeleton = activeSkeleton + 1 activeSkeleton = activeSkeleton + 1
if activeSkeleton > #skeletons then activeSkeleton = 1 end if activeSkeleton > #skeletons then activeSkeleton = 1 end
end end

View File

@ -187,9 +187,9 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE. SOFTWARE.
<!-- This documentation can be parsed using Markdown to generate HTML. <!-- This documentation can be parsed using Markdown to generate HTML.
The source code is enclosed in a HTML comment so it won't be displayed The source code is enclosed in a HTML comment so it won't be displayed
by browsers, but it should be removed from the final HTML file as by browsers, but it should be removed from the final HTML file as
it isn't a valid HTML comment (and wastes space). it isn't a valid HTML comment (and wastes space).
--> -->
<!--]==] <!--]==]
@ -245,7 +245,7 @@ end
local escapecodes = { local escapecodes = {
["\""] = "\\\"", ["\\"] = "\\\\", ["\b"] = "\\b", ["\f"] = "\\f", ["\""] = "\\\"", ["\\"] = "\\\\", ["\b"] = "\\b", ["\f"] = "\\f",
["\n"] = "\\n", ["\r"] = "\\r", ["\t"] = "\\t" ["\n"] = "\\n", ["\r"] = "\\r", ["\t"] = "\\t"
} }
local function escapeutf8 (uchar) local function escapeutf8 (uchar)
@ -315,8 +315,7 @@ end
function json.addnewline (state) function json.addnewline (state)
if state.indent then if state.indent then
state.bufferlen = addnewline2 (state.level or 0, state.bufferlen = addnewline2 (state.level or 0, state.buffer, state.bufferlen or #(state.buffer))
state.buffer, state.bufferlen or #(state.buffer))
end end
end end
@ -452,8 +451,7 @@ function json.encode (value, state)
state = state or {} state = state or {}
local oldbuffer = state.buffer local oldbuffer = state.buffer
local buffer = oldbuffer or {} local buffer = oldbuffer or {}
local ret, msg = encode2 (value, state.indent, state.level or 0, local ret, msg = encode2 (value, state.indent, state.level or 0, buffer, state.bufferlen or 0, state.tables or {}, state.keyorder)
buffer, state.bufferlen or 0, state.tables or {}, state.keyorder)
if not ret then if not ret then
error (msg, 2) error (msg, 2)
elseif oldbuffer then elseif oldbuffer then
@ -705,7 +703,7 @@ function json.use_lpeg ()
local function UTF16Surrogate (match, pos, high, low) local function UTF16Surrogate (match, pos, high, low)
high, low = tonumber (high, 16), tonumber (low, 16) high, low = tonumber (high, 16), tonumber (low, 16)
if 0xD800 <= high and high <= 0xDBff and 0xDC00 <= low and low <= 0xDFFF then if 0xD800 <= high and high <= 0xDBff and 0xDC00 <= low and low <= 0xDFFF then
return true, unichar ((high - 0xD800) * 0x400 + (low - 0xDC00) + 0x10000) return true, unichar ((high - 0xD800) * 0x400 + (low - 0xDC00) + 0x10000)
else else
return false return false
end end

View File

@ -69,7 +69,7 @@ function Animation.new (name, timelines, duration)
if loop and duration > 0 then if loop and duration > 0 then
time = time % self.duration time = time % self.duration
if lastTime > 0 then lastTime = lastTime % self.duration end if lastTime > 0 then lastTime = lastTime % self.duration end
end end
for i,timeline in ipairs(self.timelines) do for i,timeline in ipairs(self.timelines) do
@ -608,7 +608,6 @@ end
Animation.DeformTimeline = {} Animation.DeformTimeline = {}
function Animation.DeformTimeline.new (frameCount) function Animation.DeformTimeline.new (frameCount)
local self = Animation.CurveTimeline.new(frameCount) local self = Animation.CurveTimeline.new(frameCount)
self.frames = utils.newNumberArrayZero(frameCount) self.frames = utils.newNumberArrayZero(frameCount)
self.frameVertices = utils.newNumberArrayZero(frameCount) self.frameVertices = utils.newNumberArrayZero(frameCount)

View File

@ -57,7 +57,7 @@ function Atlas.parse(atlasPath, atlasBase)
local pages = {} local pages = {}
local it = string.gmatch(atlasLines, "(.-)\r?\n") -- iterate over lines local it = string.gmatch(atlasLines, "(.-)\r?\n") -- iterate over lines
for l in it do for l in it do
if #l == 0 then if #l == 0 then
l = it() l = it()

View File

@ -37,13 +37,13 @@ local math_atan2 = math.atan2
local math_sqrt = math.sqrt local math_sqrt = math.sqrt
function math.sign(x) function math.sign(x)
if x<0 then if x<0 then
return -1 return -1
elseif x>0 then elseif x>0 then
return 1 return 1
else else
return 0 return 0
end end
end end
local math_sign = math.sign local math_sign = math.sign

View File

@ -360,7 +360,7 @@ function PathConstraint:computeWorldPositions (path, spacesCount, tangents, perc
if percentPosition then position = position * pathLength end if percentPosition then position = position * pathLength end
if percentSpacing then if percentSpacing then
local i = 0 local i = 0
while i < spacesCount do while i < spacesCount do
spaces[i + 1] = spaces[i + 1] * pathLength spaces[i + 1] = spaces[i + 1] * pathLength
i = i + 1 i = i + 1
end end

View File

@ -125,9 +125,9 @@ function SkeletonJson.new (attachmentLoader)
local color = slotMap["color"] local color = slotMap["color"]
if color then if color then
data.color:set(tonumber(color:sub(1, 2), 16) / 255, data.color:set(tonumber(color:sub(1, 2), 16) / 255,
tonumber(color:sub(3, 4), 16) / 255, tonumber(color:sub(3, 4), 16) / 255,
tonumber(color:sub(5, 6), 16) / 255, tonumber(color:sub(5, 6), 16) / 255,
tonumber(color:sub(7, 8), 16) / 255) tonumber(color:sub(7, 8), 16) / 255)
end end
data.attachmentName = getValue(slotMap, "attachment", nil) data.attachmentName = getValue(slotMap, "attachment", nil)
@ -294,9 +294,9 @@ function SkeletonJson.new (attachmentLoader)
local color = map["color"] local color = map["color"]
if color then if color then
region.color:set(tonumber(color:sub(1, 2), 16) / 255, region.color:set(tonumber(color:sub(1, 2), 16) / 255,
tonumber(color:sub(3, 4), 16) / 255, tonumber(color:sub(3, 4), 16) / 255,
tonumber(color:sub(5, 6), 16) / 255, tonumber(color:sub(5, 6), 16) / 255,
tonumber(color:sub(7, 8), 16) / 255) tonumber(color:sub(7, 8), 16) / 255)
end end
region:updateOffset() region:updateOffset()
@ -309,9 +309,9 @@ function SkeletonJson.new (attachmentLoader)
local color = map.color local color = map.color
if color then if color then
box.color:set(tonumber(color:sub(1, 2), 16) / 255, box.color:set(tonumber(color:sub(1, 2), 16) / 255,
tonumber(color:sub(3, 4), 16) / 255, tonumber(color:sub(3, 4), 16) / 255,
tonumber(color:sub(5, 6), 16) / 255, tonumber(color:sub(5, 6), 16) / 255,
tonumber(color:sub(7, 8), 16) / 255) tonumber(color:sub(7, 8), 16) / 255)
end end
return box return box
@ -323,9 +323,9 @@ function SkeletonJson.new (attachmentLoader)
local color = map.color local color = map.color
if color then if color then
mesh.color:set(tonumber(color:sub(1, 2), 16) / 255, mesh.color:set(tonumber(color:sub(1, 2), 16) / 255,
tonumber(color:sub(3, 4), 16) / 255, tonumber(color:sub(3, 4), 16) / 255,
tonumber(color:sub(5, 6), 16) / 255, tonumber(color:sub(5, 6), 16) / 255,
tonumber(color:sub(7, 8), 16) / 255) tonumber(color:sub(7, 8), 16) / 255)
end end
local parent = map.parent local parent = map.parent
@ -371,9 +371,9 @@ function SkeletonJson.new (attachmentLoader)
local color = map.color local color = map.color
if color then if color then
path.color:set(tonumber(color:sub(1, 2), 16) / 255, path.color:set(tonumber(color:sub(1, 2), 16) / 255,
tonumber(color:sub(3, 4), 16) / 255, tonumber(color:sub(3, 4), 16) / 255,
tonumber(color:sub(5, 6), 16) / 255, tonumber(color:sub(5, 6), 16) / 255,
tonumber(color:sub(7, 8), 16) / 255) tonumber(color:sub(7, 8), 16) / 255)
end end
return path; return path;
end end
@ -563,7 +563,7 @@ function SkeletonJson.new (attachmentLoader)
end end
local frameIndex = 0 local frameIndex = 0
for i,valueMap in ipairs(values) do for i,valueMap in ipairs(values) do
timeline:setFrame(frameIndex, valueMap.time, getValue(valueMap, "rotateMix", 1), getValue(valueMap, "translateMix", 1), getValue(valueMap, "scaleMix", 1), getValue(valueMap, "shearMix", 1)) timeline:setFrame(frameIndex, valueMap.time, getValue(valueMap, "rotateMix", 1), getValue(valueMap, "translateMix", 1), getValue(valueMap, "scaleMix", 1) getValue(valueMap, "shearMix", 1))
readCurve(valueMap, timeline, frameIndex) readCurve(valueMap, timeline, frameIndex)
frameIndex = frameIndex + 1 frameIndex = frameIndex + 1
end end

View File

@ -36,15 +36,15 @@ local Attachment = {}
Attachment.__index = Attachment Attachment.__index = Attachment
function Attachment.new (name, attachmentType) function Attachment.new (name, attachmentType)
if not name then error("name cannot be nil.", 2) end if not name then error("name cannot be nil.", 2) end
if not attachmentType then error("attachmentType cannot be nil.", 2) end if not attachmentType then error("attachmentType cannot be nil.", 2) end
local self = { local self = {
name = name, name = name,
type = attachmentType type = attachmentType
} }
setmetatable(self, Attachment) setmetatable(self, Attachment)
return self return self
end end
return Attachment return Attachment

View File

@ -32,7 +32,7 @@ local AttachmentType = {
region = 0, region = 0,
boundingbox = 1, boundingbox = 1,
mesh = 2, mesh = 2,
linkedmesh = 3, linkedmesh = 3,
path = 4 path = 4
} }
return AttachmentType return AttachmentType

View File

@ -40,8 +40,8 @@ function BoundingBoxAttachment.new (name)
if not name then error("name cannot be nil", 2) end if not name then error("name cannot be nil", 2) end
local self = VertexAttachment.new(name, AttachmentType.boundingbox) local self = VertexAttachment.new(name, AttachmentType.boundingbox)
self.color = Color.newWith(1, 1, 1, 1) self.color = Color.newWith(1, 1, 1, 1)
setmetatable(self, BoundingBoxAttachment) setmetatable(self, BoundingBoxAttachment)
return self return self
end end
return BoundingBoxAttachment return BoundingBoxAttachment

View File

@ -42,191 +42,191 @@ function MeshAttachment.new (name)
if not name then error("name cannot be nil", 2) end if not name then error("name cannot be nil", 2) end
local self = VertexAttachment.new(name, AttachmentType.mesh) local self = VertexAttachment.new(name, AttachmentType.mesh)
self.region = nil self.region = nil
self.path = nil self.path = nil
self.regionUVs = nil self.regionUVs = nil
self.worldVertices = nil self.worldVertices = nil
self.triangles = nil self.triangles = nil
self.color = Color.newWith(1, 1, 1, 1) self.color = Color.newWith(1, 1, 1, 1)
self.hullLength = 0 self.hullLength = 0
self.parentMesh = nil self.parentMesh = nil
self.inheritDeform = false self.inheritDeform = false
self.tempColor = Color.newWith(1, 1, 1, 1) self.tempColor = Color.newWith(1, 1, 1, 1)
setmetatable(self, MeshAttachment) setmetatable(self, MeshAttachment)
return self return self
end end
function MeshAttachment:updateUVs () function MeshAttachment:updateUVs ()
local regionUVs = self.regionUVs local regionUVs = self.regionUVs
local verticesLength = #regionUVs local verticesLength = #regionUVs
local worldVerticesLength = (verticesLength / 2) * 8 local worldVerticesLength = (verticesLength / 2) * 8
if not self.worldVertices or #self.worldVertices ~= worldVerticesLength then if not self.worldVertices or #self.worldVertices ~= worldVerticesLength then
self.worldVertices = utils.newNumberArray(worldVerticesLength) self.worldVertices = utils.newNumberArray(worldVerticesLength)
end end
local u = 0 local u = 0
local v = 0 local v = 0
local width = 0 local width = 0
local height = 0 local height = 0
if not self.region then if not self.region then
u = 0 u = 0
v = 0 v = 0
width = 1 width = 1
height = 1 height = 1
else else
u = self.region.u; u = self.region.u;
v = self.region.v; v = self.region.v;
width = self.region.u2 - u; width = self.region.u2 - u;
height = self.region.v2 - v; height = self.region.v2 - v;
end end
if self.region and self.region.rotate then if self.region and self.region.rotate then
local i = 0 local i = 0
local w = 2 local w = 2
while i < verticesLength do while i < verticesLength do
self.worldVertices[w + 1] = u + regionUVs[i + 2] * width; self.worldVertices[w + 1] = u + regionUVs[i + 2] * width;
self.worldVertices[w + 2] = v + height - regionUVs[i + 1] * height; self.worldVertices[w + 2] = v + height - regionUVs[i + 1] * height;
i = i + 2 i = i + 2
w = w + 8 w = w + 8
end end
else else
local i = 0 local i = 0
local w = 2 local w = 2
while i < verticesLength do while i < verticesLength do
self.worldVertices[w + 1] = u + regionUVs[i + 1] * width; self.worldVertices[w + 1] = u + regionUVs[i + 1] * width;
self.worldVertices[w + 2] = v + regionUVs[i + 2] * height; self.worldVertices[w + 2] = v + regionUVs[i + 2] * height;
i = i + 2 i = i + 2
w = w + 8 w = w + 8
end end
end end
end end
function MeshAttachment:updateWorldVertices(slot, premultipliedAlpha) function MeshAttachment:updateWorldVertices(slot, premultipliedAlpha)
local skeleton = slot.bone.skeleton local skeleton = slot.bone.skeleton
local skeletonColor = skeleton.color local skeletonColor = skeleton.color
local slotColor = slot.color local slotColor = slot.color
local meshColor = self.color local meshColor = self.color
local alpha = skeletonColor.a * slotColor.a * meshColor.a local alpha = skeletonColor.a * slotColor.a * meshColor.a
local multiplier = 1 local multiplier = 1
if premultipliedAlpha then multiplier = alpha end if premultipliedAlpha then multiplier = alpha end
local color = self.tempColor local color = self.tempColor
color:set(skeletonColor.r * slotColor.r * meshColor.r * multiplier, color:set(skeletonColor.r * slotColor.r * meshColor.r * multiplier,
skeletonColor.g * slotColor.g * meshColor.g * multiplier, skeletonColor.g * slotColor.g * meshColor.g * multiplier,
skeletonColor.b * slotColor.b * meshColor.b * multiplier, skeletonColor.b * slotColor.b * meshColor.b * multiplier,
alpha) alpha)
local x = skeleton.x local x = skeleton.x
local y = skeleton.y local y = skeleton.y
local deformArray = slot.attachmentVertices local deformArray = slot.attachmentVertices
local vertices = self.vertices local vertices = self.vertices
local worldVertices = self.worldVertices local worldVertices = self.worldVertices
local bones = self.bones local bones = self.bones
if not bones then if not bones then
local verticesLength = #vertices local verticesLength = #vertices
if #deformArray > 0 then vertices = deformArray end if #deformArray > 0 then vertices = deformArray end
local bone = slot.bone; local bone = slot.bone;
x = x + bone.worldX x = x + bone.worldX
y = y + bone.worldY y = y + bone.worldY
local a = bone.a local a = bone.a
local b = bone.b local b = bone.b
local c = bone.c local c = bone.c
local d = bone.d local d = bone.d
local v = 0 local v = 0
local w = 0 local w = 0
while v < verticesLength do while v < verticesLength do
local vx = vertices[v + 1] local vx = vertices[v + 1]
local vy = vertices[v + 2] local vy = vertices[v + 2]
worldVertices[w + 1] = vx * a + vy * b + x worldVertices[w + 1] = vx * a + vy * b + x
worldVertices[w + 2] = vx * c + vy * d + y worldVertices[w + 2] = vx * c + vy * d + y
worldVertices[w + 5] = color.r worldVertices[w + 5] = color.r
worldVertices[w + 6] = color.g worldVertices[w + 6] = color.g
worldVertices[w + 7] = color.b worldVertices[w + 7] = color.b
worldVertices[w + 8] = color.a worldVertices[w + 8] = color.a
v = v + 2 v = v + 2
w = w + 8 w = w + 8
end end
return worldVertices return worldVertices
end end
local skeletonBones = skeleton.bones local skeletonBones = skeleton.bones
if #deformArray == 0 then if #deformArray == 0 then
local w = 0 local w = 0
local v = 0 local v = 0
local b = 0 local b = 0
local n = #bones local n = #bones
while v < n do while v < n do
local wx = x local wx = x
local wy = y local wy = y
local nn = bones[v + 1]; local nn = bones[v + 1];
v = v + 1 v = v + 1
nn = nn + v nn = nn + v
while v < nn do while v < nn do
local bone = skeletonBones[bones[v + 1]]; local bone = skeletonBones[bones[v + 1]];
local vx = vertices[b + 1] local vx = vertices[b + 1]
local vy = vertices[b + 2] local vy = vertices[b + 2]
local weight = vertices[b + 3] local weight = vertices[b + 3]
wx = wx + (vx * bone.a + vy * bone.b + bone.worldX) * weight wx = wx + (vx * bone.a + vy * bone.b + bone.worldX) * weight
wy = wy + (vx * bone.c + vy * bone.d + bone.worldY) * weight wy = wy + (vx * bone.c + vy * bone.d + bone.worldY) * weight
v = v + 1 v = v + 1
b = b + 3 b = b + 3
end end
worldVertices[w + 1] = wx worldVertices[w + 1] = wx
worldVertices[w + 2] = wy worldVertices[w + 2] = wy
worldVertices[w + 5] = color.r worldVertices[w + 5] = color.r
worldVertices[w + 6] = color.g worldVertices[w + 6] = color.g
worldVertices[w + 7] = color.b worldVertices[w + 7] = color.b
worldVertices[w + 8] = color.a worldVertices[w + 8] = color.a
w = w + 8 w = w + 8
end end
else else
local deform = deformArray; local deform = deformArray;
local w = 0 local w = 0
local v = 0 local v = 0
local b = 0 local b = 0
local f = 0 local f = 0
local n = #bones local n = #bones
while v < n do while v < n do
local wx = x local wx = x
local wy = y local wy = y
local nn = bones[v + 1] local nn = bones[v + 1]
v = v + 1 v = v + 1
nn = nn + v nn = nn + v
while v < nn do while v < nn do
local bone = skeletonBones[bones[v + 1]]; local bone = skeletonBones[bones[v + 1]];
local vx = vertices[b + 1] + deform[f + 1] local vx = vertices[b + 1] + deform[f + 1]
local vy = vertices[b + 2] + deform[f + 2] local vy = vertices[b + 2] + deform[f + 2]
local weight = vertices[b + 3] local weight = vertices[b + 3]
wx = wx + (vx * bone.a + vy * bone.b + bone.worldX) * weight wx = wx + (vx * bone.a + vy * bone.b + bone.worldX) * weight
wy = wy + (vx * bone.c + vy * bone.d + bone.worldY) * weight wy = wy + (vx * bone.c + vy * bone.d + bone.worldY) * weight
b = b + 3 b = b + 3
f = f + 2 f = f + 2
v = v + 1 v = v + 1
end end
worldVertices[w + 1] = wx; worldVertices[w + 1] = wx;
worldVertices[w + 2] = wy; worldVertices[w + 2] = wy;
worldVertices[w + 5] = color.r; worldVertices[w + 5] = color.r;
worldVertices[w + 6] = color.g; worldVertices[w + 6] = color.g;
worldVertices[w + 7] = color.b; worldVertices[w + 7] = color.b;
worldVertices[w + 8] = color.a; worldVertices[w + 8] = color.a;
w = w + 8 w = w + 8
end end
end end
return worldVertices; return worldVertices;
end end
function MeshAttachment:applyDeform (sourceAttachment) function MeshAttachment:applyDeform (sourceAttachment)
return self == sourceAttachment or (self.inheritDeform and self.parentMesh == sourceAttachment) return self == sourceAttachment or (self.inheritDeform and self.parentMesh == sourceAttachment)
end end
function MeshAttachment:setParentMesh (parentMesh) function MeshAttachment:setParentMesh (parentMesh)
self.parentMesh = parentMesh self.parentMesh = parentMesh
if parentMesh then if parentMesh then
self.bones = parentMesh.bones self.bones = parentMesh.bones
self.vertices = parentMesh.vertices self.vertices = parentMesh.vertices
self.regionUVs = parentMesh.regionUVs self.regionUVs = parentMesh.regionUVs
self.triangles = parentMesh.triangles self.triangles = parentMesh.triangles
self.hullLength = parentMesh.hullLength self.hullLength = parentMesh.hullLength
end end
end end
return MeshAttachment return MeshAttachment

View File

@ -40,9 +40,9 @@ function PathAttachment.new (name)
if not name then error("name cannot be nil", 2) end if not name then error("name cannot be nil", 2) end
local self = VertexAttachment.new(name, AttachmentType.path) local self = VertexAttachment.new(name, AttachmentType.path)
self.lengths = nil self.lengths = nil
self.color = Color.newWith(1, 1, 1, 1) self.color = Color.newWith(1, 1, 1, 1)
setmetatable(self, PathAttachment) setmetatable(self, PathAttachment)
return self return self
end end
return PathAttachment return PathAttachment

View File

@ -91,140 +91,140 @@ function RegionAttachment.new (name)
if not name then error("name cannot be nil", 2) end if not name then error("name cannot be nil", 2) end
local self = Attachment.new(name, AttachmentType.region) local self = Attachment.new(name, AttachmentType.region)
self.x = 0 self.x = 0
self.y = 0 self.y = 0
self.scaleX = 1 self.scaleX = 1
self.scaleY = 1 self.scaleY = 1
self.rotation = 0 self.rotation = 0
self.width = 0 self.width = 0
self.height = 0 self.height = 0
self.color = Color.newWith(1, 1, 1, 1) self.color = Color.newWith(1, 1, 1, 1)
self.path = nil self.path = nil
self.rendererObject = nil self.rendererObject = nil
self.region = nil self.region = nil
self.offset = Utils.newNumberArray(8) self.offset = Utils.newNumberArray(8)
self.vertices = Utils.newNumberArray(8 * 4) self.vertices = Utils.newNumberArray(8 * 4)
self.tempColor = Color.newWith(1, 1, 1, 1) self.tempColor = Color.newWith(1, 1, 1, 1)
setmetatable(self, RegionAttachment) setmetatable(self, RegionAttachment)
return self return self
end end
function RegionAttachment:setRegion (region) function RegionAttachment:setRegion (region)
local vertices = self.vertices local vertices = self.vertices
if region.rotate then if region.rotate then
vertices[U2] = region.u vertices[U2] = region.u
vertices[V2] = region.v2 vertices[V2] = region.v2
vertices[U3] = region.u vertices[U3] = region.u
vertices[V3] = region.v vertices[V3] = region.v
vertices[U4] = region.u2 vertices[U4] = region.u2
vertices[V4] = region.v vertices[V4] = region.v
vertices[U1] = region.u2 vertices[U1] = region.u2
vertices[V1] = region.v2 vertices[V1] = region.v2
else else
vertices[U1] = region.u vertices[U1] = region.u
vertices[V1] = region.v2 vertices[V1] = region.v2
vertices[U2] = region.u vertices[U2] = region.u
vertices[V2] = region.v vertices[V2] = region.v
vertices[U3] = region.u2 vertices[U3] = region.u2
vertices[V3] = region.v vertices[V3] = region.v
vertices[U4] = region.u2 vertices[U4] = region.u2
vertices[V4] = region.v2 vertices[V4] = region.v2
end end
end end
function RegionAttachment:updateOffset () function RegionAttachment:updateOffset ()
local regionScaleX = self.width / self.region.originalWidth * self.scaleX local regionScaleX = self.width / self.region.originalWidth * self.scaleX
local regionScaleY = self.height / self.region.originalHeight * self.scaleY local regionScaleY = self.height / self.region.originalHeight * self.scaleY
local localX = -self.width / 2 * self.scaleX + self.region.offsetX * regionScaleX local localX = -self.width / 2 * self.scaleX + self.region.offsetX * regionScaleX
local localY = -self.height / 2 * self.scaleY + self.region.offsetY * regionScaleY local localY = -self.height / 2 * self.scaleY + self.region.offsetY * regionScaleY
local localX2 = localX + self.region.width * regionScaleX local localX2 = localX + self.region.width * regionScaleX
local localY2 = localY + self.region.height * regionScaleY local localY2 = localY + self.region.height * regionScaleY
local radians = self.rotation * math_pi / 180 local radians = self.rotation * math_pi / 180
local cos = math_cos(radians) local cos = math_cos(radians)
local sin = math_sin(radians) local sin = math_sin(radians)
local localXCos = localX * cos + self.x local localXCos = localX * cos + self.x
local localXSin = localX * sin local localXSin = localX * sin
local localYCos = localY * cos + self.y local localYCos = localY * cos + self.y
local localYSin = localY * sin local localYSin = localY * sin
local localX2Cos = localX2 * cos + self.x local localX2Cos = localX2 * cos + self.x
local localX2Sin = localX2 * sin local localX2Sin = localX2 * sin
local localY2Cos = localY2 * cos + self.y local localY2Cos = localY2 * cos + self.y
local localY2Sin = localY2 * sin local localY2Sin = localY2 * sin
local offset = self.offset local offset = self.offset
offset[OX1] = localXCos - localYSin offset[OX1] = localXCos - localYSin
offset[OY1] = localYCos + localXSin offset[OY1] = localYCos + localXSin
offset[OX2] = localXCos - localY2Sin offset[OX2] = localXCos - localY2Sin
offset[OY2] = localY2Cos + localXSin offset[OY2] = localY2Cos + localXSin
offset[OX3] = localX2Cos - localY2Sin offset[OX3] = localX2Cos - localY2Sin
offset[OY3] = localY2Cos + localX2Sin offset[OY3] = localY2Cos + localX2Sin
offset[OX4] = localX2Cos - localYSin offset[OX4] = localX2Cos - localYSin
offset[OY4] = localYCos + localX2Sin offset[OY4] = localYCos + localX2Sin
end end
function RegionAttachment:updateWorldVertices (slot, premultipliedAlpha) function RegionAttachment:updateWorldVertices (slot, premultipliedAlpha)
local skeleton = slot.bone.skeleton local skeleton = slot.bone.skeleton
local skeletonColor = skeleton.color local skeletonColor = skeleton.color
local slotColor = slot.color local slotColor = slot.color
local regionColor = self.color local regionColor = self.color
local alpha = skeletonColor.a * slotColor.a * regionColor.a local alpha = skeletonColor.a * slotColor.a * regionColor.a
local multiplier = alpha local multiplier = alpha
if premultipliedAlpha then multiplier = 1 end if premultipliedAlpha then multiplier = 1 end
local color = self.tempColor local color = self.tempColor
color:set(skeletonColor.r * slotColor.r * regionColor.r * multiplier, color:set(skeletonColor.r * slotColor.r * regionColor.r * multiplier,
skeletonColor.g * slotColor.g * regionColor.g * multiplier, skeletonColor.g * slotColor.g * regionColor.g * multiplier,
skeletonColor.b * slotColor.b * regionColor.b * multiplier, skeletonColor.b * slotColor.b * regionColor.b * multiplier,
alpha) alpha)
local vertices = self.vertices local vertices = self.vertices
local offset = self.offset local offset = self.offset
local bone = slot.bone local bone = slot.bone
local x = skeleton.x + bone.worldX local x = skeleton.x + bone.worldX
local y = skeleton.y + bone.worldY local y = skeleton.y + bone.worldY
local a = bone.a local a = bone.a
local b = bone.b local b = bone.b
local c = bone.c local c = bone.c
local d = bone.d local d = bone.d
local offsetX = 0 local offsetX = 0
local offsetY = 0 local offsetY = 0
offsetX = offset[OX1] offsetX = offset[OX1]
offsetY = offset[OY1] offsetY = offset[OY1]
vertices[X1] = offsetX * a + offsetY * b + x -- br vertices[X1] = offsetX * a + offsetY * b + x -- br
vertices[Y1] = offsetX * c + offsetY * d + y vertices[Y1] = offsetX * c + offsetY * d + y
vertices[C1R] = color.r vertices[C1R] = color.r
vertices[C1G] = color.g vertices[C1G] = color.g
vertices[C1B] = color.b vertices[C1B] = color.b
vertices[C1A] = color.a vertices[C1A] = color.a
offsetX = offset[OX2] offsetX = offset[OX2]
offsetY = offset[OY2] offsetY = offset[OY2]
vertices[X2] = offsetX * a + offsetY * b + x -- bl vertices[X2] = offsetX * a + offsetY * b + x -- bl
vertices[Y2] = offsetX * c + offsetY * d + y vertices[Y2] = offsetX * c + offsetY * d + y
vertices[C2R] = color.r vertices[C2R] = color.r
vertices[C2G] = color.g vertices[C2G] = color.g
vertices[C2B] = color.b vertices[C2B] = color.b
vertices[C2A] = color.a vertices[C2A] = color.a
offsetX = offset[OX3] offsetX = offset[OX3]
offsetY = offset[OY3] offsetY = offset[OY3]
vertices[X3] = offsetX * a + offsetY * b + x -- ul vertices[X3] = offsetX * a + offsetY * b + x -- ul
vertices[Y3] = offsetX * c + offsetY * d + y vertices[Y3] = offsetX * c + offsetY * d + y
vertices[C3R] = color.r vertices[C3R] = color.r
vertices[C3G] = color.g vertices[C3G] = color.g
vertices[C3B] = color.b vertices[C3B] = color.b
vertices[C3A] = color.a vertices[C3A] = color.a
offsetX = offset[OX4] offsetX = offset[OX4]
offsetY = offset[OY4] offsetY = offset[OY4]
vertices[X4] = offsetX * a + offsetY * b + x -- ur vertices[X4] = offsetX * a + offsetY * b + x -- ur
vertices[Y4] = offsetX * c + offsetY * d + y vertices[Y4] = offsetX * c + offsetY * d + y
vertices[C4R] = color.r vertices[C4R] = color.r
vertices[C4G] = color.g vertices[C4G] = color.g
vertices[C4B] = color.b vertices[C4B] = color.b
vertices[C4A] = color.a vertices[C4A] = color.a
return vertices return vertices
end end
return RegionAttachment return RegionAttachment

View File

@ -42,112 +42,112 @@ VertexAttachment.__index = VertexAttachment
setmetatable(VertexAttachment, { __index = Attachment }) setmetatable(VertexAttachment, { __index = Attachment })
function VertexAttachment.new (name, attachmentType) function VertexAttachment.new (name, attachmentType)
local self = Attachment.new(name, attachmentType) local self = Attachment.new(name, attachmentType)
self.bones = nil self.bones = nil
self.vertices = nil self.vertices = nil
self.worldVerticesLength = 0 self.worldVerticesLength = 0
setmetatable(self, VertexAttachment) setmetatable(self, VertexAttachment)
return self return self
end end
function VertexAttachment:computeWorldVertices (slot, worldVertices) function VertexAttachment:computeWorldVertices (slot, worldVertices)
self:computeWorldVerticesWith(slot, 0, self.worldVerticesLength, worldVertices, 0) self:computeWorldVerticesWith(slot, 0, self.worldVerticesLength, worldVertices, 0)
end end
function VertexAttachment:computeWorldVerticesWith (slot, start, count, worldVertices, offset) function VertexAttachment:computeWorldVerticesWith (slot, start, count, worldVertices, offset)
count = count + offset count = count + offset
local skeleton = slot.bone.skeleton local skeleton = slot.bone.skeleton
local x = skeleton.x local x = skeleton.x
local y = skeleton.y local y = skeleton.y
local deformArray = slot.attachmentVertices local deformArray = slot.attachmentVertices
local vertices = self.vertices local vertices = self.vertices
local bones = self.bones local bones = self.bones
if not bones then if not bones then
if #deformArray > 0 then vertices = deformArray end if #deformArray > 0 then vertices = deformArray end
local bone = slot.bone local bone = slot.bone
x = x + bone.worldX x = x + bone.worldX
y = y + bone.worldY y = y + bone.worldY
local a = bone.a local a = bone.a
local b = bone.b local b = bone.b
local c = bone.c local c = bone.c
local d = bone.d local d = bone.d
local v = start local v = start
local w = offset local w = offset
while w < count do while w < count do
local vx = vertices[v + 1] local vx = vertices[v + 1]
local vy = vertices[v + 2] local vy = vertices[v + 2]
worldVertices[w + 1] = vx * a + vy * b + x worldVertices[w + 1] = vx * a + vy * b + x
worldVertices[w + 2] = vx * c + vy * d + y worldVertices[w + 2] = vx * c + vy * d + y
v = v + 2 v = v + 2
w = w + 2 w = w + 2
end end
return return
end end
local v = 0 local v = 0
local skip = 0 local skip = 0
local i = 0 local i = 0
while i < start do while i < start do
local n = bones[v + 1] local n = bones[v + 1]
v = v + n + 1 v = v + n + 1
skip = skip + n skip = skip + n
i = i + 2 i = i + 2
end end
local skeletonBones = skeleton.bones local skeletonBones = skeleton.bones
if #deformArray == 0 then if #deformArray == 0 then
local w = offset local w = offset
local b = skip * 3 local b = skip * 3
while w < count do while w < count do
local wx = x local wx = x
local wy = y local wy = y
local n = bones[v + 1] local n = bones[v + 1]
v = v + 1 v = v + 1
n = n + v n = n + v
while v < n do while v < n do
local bone = skeletonBones[bones[v + 1]] local bone = skeletonBones[bones[v + 1]]
local vx = vertices[b + 1] local vx = vertices[b + 1]
local vy = vertices[b + 2] local vy = vertices[b + 2]
local weight = vertices[b + 3] local weight = vertices[b + 3]
wx = wx + (vx * bone.a + vy * bone.b + bone.worldX) * weight wx = wx + (vx * bone.a + vy * bone.b + bone.worldX) * weight
wy = wy + (vx * bone.c + vy * bone.d + bone.worldY) * weight wy = wy + (vx * bone.c + vy * bone.d + bone.worldY) * weight
v = v + 1 v = v + 1
b = b + 3 b = b + 3
end end
worldVertices[w + 1] = wx worldVertices[w + 1] = wx
worldVertices[w + 2] = wy worldVertices[w + 2] = wy
w = w + 2 w = w + 2
end end
else else
local deform = deformArray local deform = deformArray
local w = offset local w = offset
local b = skip * 3 local b = skip * 3
local f = skip * 2 local f = skip * 2
while w < count do while w < count do
local wx = x local wx = x
local wy = y local wy = y
local n = bones[v + 1] local n = bones[v + 1]
v = v + 1 v = v + 1
n = n + v n = n + v
while v < n do while v < n do
local bone = skeletonBones[bones[v + 1]] local bone = skeletonBones[bones[v + 1]]
local vx = vertices[b + 1] + deform[f + 1] local vx = vertices[b + 1] + deform[f + 1]
local vy = vertices[b + 2] + deform[f + 2] local vy = vertices[b + 2] + deform[f + 2]
local weight = vertices[b + 3] local weight = vertices[b + 3]
wx = wx + (vx * bone.a + vy * bone.b + bone.worldX) * weight wx = wx + (vx * bone.a + vy * bone.b + bone.worldX) * weight
wy = wy + (vx * bone.c + vy * bone.d + bone.worldY) * weight wy = wy + (vx * bone.c + vy * bone.d + bone.worldY) * weight
v = v + 1 v = v + 1
b = b + 3 b = b + 3
f = f + 2 f = f + 2
end end
worldVertices[w + 1] = wx worldVertices[w + 1] = wx
worldVertices[w + 2] = wy worldVertices[w + 2] = wy
w = w + 2 w = w + 2
end end
end end
end end
function VertexAttachment:applyDeform (sourceAttachment) function VertexAttachment:applyDeform (sourceAttachment)
return self == sourceAttachment return self == sourceAttachment
end end
return VertexAttachment return VertexAttachment

View File

@ -62,9 +62,9 @@ char* _Util_readFile (const char* path, int* length){
namespace spine { namespace spine {
SkeletonDrawable::SkeletonDrawable (SkeletonData* skeletonData, AnimationStateData* stateData) : SkeletonDrawable::SkeletonDrawable (SkeletonData* skeletonData, AnimationStateData* stateData) :
timeScale(1), timeScale(1),
vertexArray(new VertexArray(Triangles, skeletonData->bonesCount * 4)), vertexArray(new VertexArray(Triangles, skeletonData->bonesCount * 4)),
worldVertices(0) { worldVertices(0) {
Bone_setYDown(true); Bone_setYDown(true);
worldVertices = MALLOC(float, SPINE_MESH_VERTEX_COUNT_MAX); worldVertices = MALLOC(float, SPINE_MESH_VERTEX_COUNT_MAX);
skeleton = Skeleton_create(skeletonData); skeleton = Skeleton_create(skeletonData);
@ -78,7 +78,7 @@ SkeletonDrawable::SkeletonDrawable (SkeletonData* skeletonData, AnimationStateDa
SkeletonDrawable::~SkeletonDrawable () { SkeletonDrawable::~SkeletonDrawable () {
delete vertexArray; delete vertexArray;
FREE(worldVertices); FREE(worldVertices);
if (ownsAnimationStateData) AnimationStateData_dispose(state->data); if (ownsAnimationStateData) AnimationStateData_dispose(state->data);
AnimationState_dispose(state); AnimationState_dispose(state);
Skeleton_dispose(skeleton); Skeleton_dispose(skeleton);
} }

View File

@ -38,9 +38,9 @@ import starling.display.Mesh;
public class SkeletonMesh extends Mesh { public class SkeletonMesh extends Mesh {
public function SkeletonMesh(texture:Texture, vertexData:VertexData = null, indexData:IndexData = null, style:MeshStyle=null) { public function SkeletonMesh(texture:Texture, vertexData:VertexData = null, indexData:IndexData = null, style:MeshStyle=null) {
super(vertexData == null? new VertexData(): vertexData, indexData == null? new IndexData(): indexData, style); super(vertexData == null? new VertexData(): vertexData, indexData == null? new IndexData(): indexData, style);
this.texture = texture; this.texture = texture;
} }
public function getVertexData(): VertexData { public function getVertexData(): VertexData {
return this.vertexData; return this.vertexData;

View File

@ -129,7 +129,7 @@ public class SkeletonSprite extends DisplayObject {
painter.batchMesh(image); painter.batchMesh(image);
} else if (slot.attachment is MeshAttachment) { } else if (slot.attachment is MeshAttachment) {
var meshAttachment:MeshAttachment = MeshAttachment(slot.attachment); var meshAttachment:MeshAttachment = MeshAttachment(slot.attachment);
verticesLength = meshAttachment.worldVerticesLength; verticesLength = meshAttachment.worldVerticesLength;
verticesCount = verticesLength >> 1; verticesCount = verticesLength >> 1;
if (worldVertices.length < verticesLength) worldVertices.length = verticesLength; if (worldVertices.length < verticesLength) worldVertices.length = verticesLength;
meshAttachment.computeWorldVertices(slot, worldVertices); meshAttachment.computeWorldVertices(slot, worldVertices);

View File

@ -95,7 +95,7 @@ module spine.canvas {
let blendMode: BlendMode = null; let blendMode: BlendMode = null;
let vertices: ArrayLike<number> = null; let vertices: ArrayLike<number> = null;
let triangles: Array<number> = null; let triangles: Array<number> = null;
let drawOrder = skeleton.drawOrder; let drawOrder = skeleton.drawOrder;
for (let i = 0, n = drawOrder.length; i < n; i++) { for (let i = 0, n = drawOrder.length; i < n; i++) {

View File

@ -84,7 +84,7 @@ module spine {
} }
img.onerror = (ev) => { img.onerror = (ev) => {
if (error) error(path, `Couldn't load image ${path}`); if (error) error(path, `Couldn't load image ${path}`);
this.errors[path] = `Couldn't load image ${path}`; this.errors[path] = `Couldn't load image ${path}`;
this.toLoad--; this.toLoad--;
this.loaded++; this.loaded++;
} }

View File

@ -121,7 +121,7 @@ module spine {
this.rawAssets[path] = img; this.rawAssets[path] = img;
} }
img.onerror = (ev) => { img.onerror = (ev) => {
this.errors[path] = `Couldn't load image ${path}`; this.errors[path] = `Couldn't load image ${path}`;
} }
} }

View File

@ -44,7 +44,6 @@ module spine {
abstract setWraps (uWrap: TextureWrap, vWrap: TextureWrap): void; abstract setWraps (uWrap: TextureWrap, vWrap: TextureWrap): void;
abstract dispose (): void; abstract dispose (): void;
public static filterFromString (text: string): TextureFilter { public static filterFromString (text: string): TextureFilter {
switch (text.toLowerCase()) { switch (text.toLowerCase()) {
case "nearest": return TextureFilter.Nearest; case "nearest": return TextureFilter.Nearest;

View File

@ -130,7 +130,7 @@ module spine {
static cbrt (x: number) { static cbrt (x: number) {
var y = Math.pow(Math.abs(x), 1/3); var y = Math.pow(Math.abs(x), 1/3);
return x < 0 ? -y : y; return x < 0 ? -y : y;
} }
} }

View File

@ -73,7 +73,7 @@ module spine.threejs {
let blendMode: BlendMode = null; let blendMode: BlendMode = null;
let vertices: ArrayLike<number> = null; let vertices: ArrayLike<number> = null;
let triangles: Array<number> = null; let triangles: Array<number> = null;
let drawOrder = this.skeleton.drawOrder; let drawOrder = this.skeleton.drawOrder;
let batcher = this.batcher; let batcher = this.batcher;
batcher.begin(); batcher.begin();

View File

@ -125,10 +125,10 @@ module spine.webgl {
// bottom left and top right corner points relative to origin // bottom left and top right corner points relative to origin
let worldOriginX = x + pivotX; let worldOriginX = x + pivotX;
let worldOriginY = y + pivotY; let worldOriginY = y + pivotY;
let fx = -pivotX; let fx = -pivotX;
let fy = -pivotY; let fy = -pivotY;
let fx2 = width - pivotX; let fx2 = width - pivotX;
let fy2 = height - pivotY; let fy2 = height - pivotY;
// construct corner points, start from top left and go counter clockwise // construct corner points, start from top left and go counter clockwise
let p1x = fx; let p1x = fx;

View File

@ -183,7 +183,7 @@ module spine.webgl {
void main () { void main () {
v_color = ${Shader.COLOR}; v_color = ${Shader.COLOR};
v_texCoords = ${Shader.TEXCOORDS}; v_texCoords = ${Shader.TEXCOORDS};
gl_Position = ${Shader.MVP_MATRIX} * ${Shader.POSITION}; gl_Position = ${Shader.MVP_MATRIX} * ${Shader.POSITION};
} }
`; `;
@ -215,7 +215,7 @@ module spine.webgl {
void main () { void main () {
v_color = ${Shader.COLOR}; v_color = ${Shader.COLOR};
gl_Position = ${Shader.MVP_MATRIX} * ${Shader.POSITION}; gl_Position = ${Shader.MVP_MATRIX} * ${Shader.POSITION};
} }
`; `;

View File

@ -44,7 +44,7 @@ module spine.webgl {
let blendMode: BlendMode = null; let blendMode: BlendMode = null;
let vertices: ArrayLike<number> = null; let vertices: ArrayLike<number> = null;
let triangles: Array<number> = null; let triangles: Array<number> = null;
let drawOrder = skeleton.drawOrder; let drawOrder = skeleton.drawOrder;
for (let i = 0, n = drawOrder.length; i < n; i++) { for (let i = 0, n = drawOrder.length; i < n; i++) {
let slot = drawOrder[i]; let slot = drawOrder[i];