pixi-spine
Advanced tools
Comparing version 1.0.18 to 1.0.19
{ | ||
"name": "pixi-spine", | ||
"version": "1.0.18", | ||
"description": "Spine implementation for pixi v3", | ||
"version": "1.0.19", | ||
"description": "Spine implementation for pixi v^3", | ||
"author": "Mat Groves", | ||
@@ -6,0 +6,0 @@ "contributors": [ |
@@ -201,2 +201,12 @@ var spine = require('../SpineUtil'); | ||
}, | ||
/** | ||
* Returns true if animation exists in skeleton data | ||
* @param animationName | ||
* @returns {boolean} | ||
*/ | ||
hasAnimationByName: function (animationName) | ||
{ | ||
var animation = this.data.skeletonData.findAnimation(animationName); | ||
return animation !== null; | ||
}, | ||
/** May be null. */ | ||
@@ -203,0 +213,0 @@ getCurrent: function (trackIndex) |
@@ -47,6 +47,6 @@ var spine = require('../SpineUtil'); | ||
}, | ||
addTextureHash: function(textures) { | ||
addTextureHash: function(textures, stripExtension) { | ||
for (var key in textures) { | ||
if (textures.hasOwnProperty(key)) { | ||
this.addTexture(key, textures[key]); | ||
this.addTexture(stripExtension && key.indexOf('.') !== -1 ? key.substr(0, key.lastIndexOf('.')) : key, textures[key]); | ||
} | ||
@@ -53,0 +53,0 @@ } |
@@ -15,5 +15,10 @@ var spine = require('../SpineUtil'); | ||
scaleX: 1, scaleY: 1, | ||
shearX: 0, shearY: 0, | ||
flipX: false, flipY: false, | ||
worldSignX: 1, worldSignY: 1, | ||
update: function() { | ||
this.rotationIK = this.rotation; | ||
this.updateWorldTransform(); | ||
}, | ||
updateWorldTransform: function() { | ||
@@ -25,5 +30,7 @@ var rotation = this.rotationIK; | ||
var y = this.y; | ||
var rotationX = rotation + this.shearX; | ||
var rotationY = rotation + 90 + this.shearY; | ||
var cos = Math.cos(rotation * spine.degRad), sin = Math.sin(rotation * spine.degRad); | ||
var la = cos * scaleX, lb = -sin * scaleY, lc = sin * scaleX, ld = cos * scaleY; | ||
var la = Math.cos(rotationX * spine.degRad) * scaleX, lb = Math.cos(rotationY * spine.degRad) * scaleY, | ||
lc = Math.sin(rotationX * spine.degRad) * scaleX, ld = Math.sin(rotationY * spine.degRad) * scaleY; | ||
var parent = this.parent; | ||
@@ -159,2 +166,4 @@ var m = this.matrix; | ||
this.scaleY = data.scaleY; | ||
this.shearX = data.shearX; | ||
this.shearY = data.shearY; | ||
}, | ||
@@ -161,0 +170,0 @@ worldToLocal: function (world) |
@@ -12,2 +12,3 @@ var spine = require('../SpineUtil'); | ||
scaleX: 1, scaleY: 1, | ||
shearX: 0, shearY: 0, | ||
inheritScale: true, | ||
@@ -14,0 +15,0 @@ inheritRotation: true |
@@ -14,2 +14,5 @@ var spine = require('../SpineUtil'); | ||
spine.IkConstraint.prototype = { | ||
update: function() { | ||
this.apply(); | ||
}, | ||
apply: function () | ||
@@ -42,2 +45,3 @@ { | ||
bone.rotationIK = rotation + (rotationIK - rotation) * alpha; | ||
bone.updateWorldTransform(); | ||
}; | ||
@@ -167,6 +171,8 @@ /** Adjusts the parent and child bone rotations so the tip of the child is as close to the target position as possible. The | ||
parent.rotationIK = rotation + (a1 - rotation) * alpha; | ||
parent.updateWorldTransform(); | ||
rotation = child.rotation; | ||
child.rotationIK = rotation + (a2 - rotation) * alpha; | ||
child.updateWorldTransform(); | ||
}; | ||
module.exports = spine.IkConstraint; | ||
@@ -54,2 +54,5 @@ /****************************************************************************** | ||
spine.IkConstraintTimeline = require('./IkConstraintTimeline'); | ||
spine.TransformConstraintData = require('./TransformConstraintData'); | ||
spine.TransformConstraint = require('./TransformConstraint'); | ||
spine.TransformConstraintTimeline = require('./TransformConstraintTimeline'); | ||
spine.MeshAttachment = require('./MeshAttachment'); | ||
@@ -59,2 +62,3 @@ spine.RegionAttachment = require('./RegionAttachment'); | ||
spine.ScaleTimeline = require('./ScaleTimeline'); | ||
spine.ShearTimeline = require('./ShearTimeline'); | ||
spine.SkeletonBounds = require('./SkeletonBounds'); | ||
@@ -61,0 +65,0 @@ spine.SkeletonData = require('./SkeletonData'); |
@@ -32,2 +32,6 @@ var spine = require('../SpineUtil'); | ||
this.transformConstraints = []; | ||
for (var i = 0, n = skeletonData.transformConstraints.length; i < n; i++) | ||
this.transformConstraints.push(new spine.TransformConstraint(skeletonData.transformConstraints[i], this)); | ||
this.boneCache = []; | ||
@@ -47,40 +51,23 @@ this.updateCache(); | ||
var ikConstraintsCount = ikConstraints.length; | ||
var transformConstraints = this.transformConstraints; | ||
var transformConstraintsCount = transformConstraints.length; | ||
var arrayCount = ikConstraintsCount + 1; | ||
var boneCache = this.boneCache; | ||
if (boneCache.length > arrayCount) boneCache.length = arrayCount; | ||
for (var i = 0, n = boneCache.length; i < n; i++) | ||
boneCache[i].length = 0; | ||
while (boneCache.length < arrayCount) | ||
boneCache[boneCache.length] = []; | ||
var nonIkBones = boneCache[0]; | ||
boneCache.length = 0; | ||
var bones = this.bones; | ||
outer: | ||
for (var i = 0, n = bones.length; i < n; i++) | ||
{ | ||
var bone = bones[i]; | ||
var current = bone; | ||
do { | ||
for (var ii = 0; ii < ikConstraintsCount; ii++) | ||
{ | ||
var ikConstraint = ikConstraints[ii]; | ||
var parent = ikConstraint.bones[0]; | ||
var child= ikConstraint.bones[ikConstraint.bones.length - 1]; | ||
while (true) | ||
{ | ||
if (current == child) | ||
{ | ||
boneCache[ii].push(bone); | ||
boneCache[ii + 1].push(bone); | ||
continue outer; | ||
} | ||
if (child == parent) break; | ||
child = child.parent; | ||
} | ||
boneCache.push(bone); | ||
for (var j=0; j < transformConstraintsCount; j++) { | ||
if (transformConstraints[j].bone == bone) { | ||
boneCache.push(transformConstraints[j]); | ||
} | ||
current = current.parent; | ||
} while (current); | ||
nonIkBones[nonIkBones.length] = bone; | ||
} | ||
for (var j=0; j < ikConstraintsCount; j++) { | ||
if (ikConstraints[j].bones[ikConstraints[j].bones.length-1] == bone) { | ||
boneCache.push(ikConstraints[j]); | ||
break; | ||
} | ||
} | ||
} | ||
@@ -97,11 +84,5 @@ }, | ||
} | ||
var i = 0, last = this.boneCache.length - 1; | ||
while (true) | ||
{ | ||
var cacheBones = this.boneCache[i]; | ||
for (var ii = 0, nn = cacheBones.length; ii < nn; ii++) | ||
cacheBones[ii].updateWorldTransform(); | ||
if (i == last) break; | ||
this.ikConstraints[i].apply(); | ||
i++; | ||
var boneCache = this.boneCache; | ||
for (var i = 0, n = boneCache.length; i < n; i++) { | ||
boneCache[i].update(); | ||
} | ||
@@ -128,2 +109,13 @@ }, | ||
} | ||
var transformConstraints = this.transformConstraints; | ||
for (var i = 0, n = transformConstraints.length; i < n; i++) | ||
{ | ||
var constraint = transformConstraints[i]; | ||
var data = constraint.data; | ||
constraint.rotateMix = data.rotateMix; | ||
constraint.translateMix = data.translateMix; | ||
constraint.scaleMix = data.scaleMix; | ||
constraint.shearMix = data.shearMix; | ||
} | ||
}, | ||
@@ -248,9 +240,16 @@ setSlotsToSetupPose: function () | ||
/** @return May be null. */ | ||
findIkConstraint: function (ikConstraintName) | ||
findIkConstraint: function (constraintName) | ||
{ | ||
var ikConstraints = this.ikConstraints; | ||
for (var i = 0, n = ikConstraints.length; i < n; i++) | ||
if (ikConstraints[i].data.name == ikConstraintName) return ikConstraints[i]; | ||
var constraints = this.ikConstraints; | ||
for (var i = 0, n = constraints.length; i < n; i++) | ||
if (constraints[i].data.name == constraintName) return constraints[i]; | ||
return null; | ||
}, | ||
findTransformConstraint: function (constraintName) | ||
{ | ||
var constraints = this.transformConstraints; | ||
for (var i = 0, n = constraints.length; i < n; i++) | ||
if (constraints[i].data.name == constraintName) return constraints[i]; | ||
return null; | ||
}, | ||
update: function (delta) | ||
@@ -257,0 +256,0 @@ { |
@@ -10,2 +10,3 @@ var spine = require('../SpineUtil'); | ||
this.ikConstraints = []; | ||
this.transformConstraints = []; | ||
}; | ||
@@ -12,0 +13,0 @@ spine.SkeletonData.prototype = { |
@@ -5,2 +5,3 @@ var spine = require('../SpineUtil'); | ||
spine.IkConstraintData = require('./IkConstraintData'); | ||
spine.TransformConstraintData = require('./IkConstraintData'); | ||
spine.SlotData = require('./SlotData'); | ||
@@ -15,3 +16,5 @@ spine.Skin = require('./Skin'); | ||
spine.TranslateTimeline = require('./TranslateTimeline'); | ||
spine.ShearTimeline = require('./ShearTimeline'); | ||
spine.IkConstraintTimeline = require('./IkConstraintTimeline'); | ||
spine.TransformConstraintTimeline = require('./IkConstraintTimeline'); | ||
spine.FfdTimeline = require('./FfdTimeline'); | ||
@@ -79,2 +82,4 @@ spine.DrawOrderTimeline = require('./DrawOrderTimeline'); | ||
boneData.scaleY = boneMap.hasOwnProperty("scaleY") ? boneMap["scaleY"] : 1; | ||
boneData.shearX = boneMap["shearX"] || 0; | ||
boneData.shearY = boneMap["shearY"] || 0; | ||
boneData.inheritScale = boneMap.hasOwnProperty("inheritScale") ? boneMap["inheritScale"] : true; | ||
@@ -98,3 +103,3 @@ boneData.inheritRotation = boneMap.hasOwnProperty("inheritRotation") ? boneMap["inheritRotation"] : true; | ||
var bone = skeletonData.findBone(bones[ii]); | ||
if (!bone) throw "IK bone not found: " + bones[ii]; | ||
if (!bone) throw new Error( "IK bone not found: " + bones[ii] ); | ||
ikConstraintData.bones.push(bone); | ||
@@ -104,3 +109,3 @@ } | ||
ikConstraintData.target = skeletonData.findBone(ikMap["target"]); | ||
if (!ikConstraintData.target) throw "Target bone not found: " + ikMap["target"]; | ||
if (!ikConstraintData.target) throw new Error("Target bone not found: " + ikMap["target"]); | ||
@@ -114,2 +119,28 @@ ikConstraintData.bendDirection = (!ikMap.hasOwnProperty("bendPositive") || ikMap["bendPositive"]) ? 1 : -1; | ||
var transform = root["transform"]; | ||
if (transform) { | ||
for (var i = 0, n = transform.length; i<n; i++) { | ||
var transformMap = transform[i]; | ||
var transformData = new spine.TransformConstraintData(ikMap["name"]); | ||
transformData.bone = skeletonData.findBone(transformMap["bone"]); | ||
if (!transformData.bone) throw new Error("Transform bone not found: " + transformData["bone"]); | ||
transformData.target = skeletonData.findBone(transformMap["target"]); | ||
if (!transformData.target) throw new Error("Target bone not found: " + transformData["target"]); | ||
transformData.offsetRotation = transformMap["rotation"] || 0; | ||
transformData.offsetX = (transformMap["offsetX"] || 0) * scale; | ||
transformData.offsetY = (transformMap["offsetY"] || 0) * scale; | ||
transformData.offsetScaleX = (transformMap["scaleX"] || 0) * scale; | ||
transformData.offsetScaleY = (transformMap["scaleY"] || 0) * scale; | ||
transformData.offsetShearY = (transformMap["offsetShearY"] || 0) * scale; | ||
transformData.rotateMix = transformMap.hasOwnProperty("rotateMix") ? transformMap["rotateMix"] : 1; | ||
transformData.translateMix = transformMap.hasOwnProperty("translateMix") ? transformMap["translateMix"] : 1; | ||
transformData.scaleMix = transformMap.hasOwnProperty("scaleMix") ? transformMap["scaleMix"] : 1; | ||
transformData.shearMix = transformMap.hasOwnProperty("shearMix") ? transformMap["shearMix"] : 1; | ||
skeletonData.transformConstraints.push(transformData); | ||
} | ||
} | ||
// Slots. | ||
@@ -401,8 +432,11 @@ var slots = root["slots"]; | ||
} else if (timelineName == "translate" || timelineName == "scale") | ||
} else if (timelineName == "translate" || timelineName == "scale" || timelineName == "shear") | ||
{ | ||
var timeline; | ||
var timelineScale = 1; | ||
if (timelineName == "scale") | ||
if (timelineName == "scale") { | ||
timeline = new spine.ScaleTimeline(values.length); | ||
} else if (timelineName == "shear") { | ||
timeline = new spine.ShearTimeline(values.length); | ||
} | ||
else | ||
@@ -458,2 +492,26 @@ { | ||
var transformMap = map["transform"]; | ||
for (var transformConstraintName in transformMap) | ||
{ | ||
if (!transformMap.hasOwnProperty(transformConstraintName)) continue; | ||
var transformConstraint = skeletonData.findTransformConstraint(transformConstraintName); | ||
var values = transformMap[transformConstraintName]; | ||
var timeline = new spine.TransformConstraintTimeline(values.length); | ||
timeline.transformConstraintIndex = skeletonData.transformConstraints.indexOf(transformConstraint); | ||
var frameIndex = 0; | ||
for (var i = 0, n = values.length; i < n; i++) | ||
{ | ||
var valueMap = values[i]; | ||
var rotateMix = valueMap.hasOwnProperty("rotateMix") ? valueMap["rotateMix"] : 1; | ||
var translateMix = valueMap.hasOwnProperty("translateMix") ? valueMap["translateMix"] : 1; | ||
var scaleMix = valueMap.hasOwnProperty("scaleMix") ? valueMap["scaleMix"] : 1; | ||
var shearMix = valueMap.hasOwnProperty("shearMix") ? valueMap["shearMix"] : 1; | ||
timeline.setFrame(frameIndex, valueMap["time"], translateMix, scaleMix, shearMix); | ||
this.readCurve(timeline, frameIndex, valueMap); | ||
frameIndex++; | ||
} | ||
timelines.push(timeline); | ||
duration = Math.max(duration, timeline.frames[timeline.getFrameCount() * 5 - 5]); | ||
} | ||
var ffd = map["ffd"]; | ||
@@ -460,0 +518,0 @@ for (var skinName in ffd) |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1062804
80
9253