[csharp] Port of commit 1dbbfda: Added skeleton reference scale. Fixed leftover gravity and wind timeline scale.

This commit is contained in:
Harald Csaszar 2024-03-04 16:24:45 +01:00
parent ad71a986ad
commit 8e56a6c920
6 changed files with 37 additions and 35 deletions

View File

@ -156,7 +156,7 @@ namespace Spine {
ux = bx; ux = bx;
uy = by; uy = by;
} else { } else {
float remaining = this.remaining, i = inertia, step = data.step; float a = this.remaining, i = inertia, t = data.step, f = skeleton.data.referenceScale;
if (x || y) { if (x || y) {
if (x) { if (x) {
xOffset += (ux - bx) * i; xOffset += (ux - bx) * i;
@ -166,22 +166,22 @@ namespace Spine {
yOffset += (uy - by) * i; yOffset += (uy - by) * i;
uy = by; uy = by;
} }
if (remaining >= step) { if (a >= t) {
float m = massInverse * step, e = strength, w = wind * 100, g = gravity * -100; float m = massInverse * t, e = strength, w = wind * f, g = gravity * f;
float d = (float)Math.Pow(damping, 60 * step); float d = (float)Math.Pow(damping, 60 * t);
do { do {
if (x) { if (x) {
xVelocity += (w - xOffset * e) * m; xVelocity += (w - xOffset * e) * m;
xOffset += xVelocity * step; xOffset += xVelocity * t;
xVelocity *= d; xVelocity *= d;
} }
if (y) { if (y) {
yVelocity += (g - yOffset * e) * m; yVelocity -= (g + yOffset * e) * m;
yOffset += yVelocity * step; yOffset += yVelocity * t;
yVelocity *= d; yVelocity *= d;
} }
remaining -= step; a -= t;
} while (remaining >= step); } while (a >= t);
} }
if (x) bone.worldX += xOffset * mix * data.x; if (x) bone.worldX += xOffset * mix * data.x;
if (y) bone.worldY += yOffset * mix * data.y; if (y) bone.worldY += yOffset * mix * data.y;
@ -205,31 +205,31 @@ namespace Spine {
float r = l * bone.WorldScaleX; float r = l * bone.WorldScaleX;
if (r > 0) scaleOffset += ((cx - bone.worldX) * c + (cy - bone.worldY) * s) * i / r; if (r > 0) scaleOffset += ((cx - bone.worldX) * c + (cy - bone.worldY) * s) * i / r;
} }
remaining = this.remaining; a = this.remaining;
if (remaining >= step) { if (a >= t) {
float m = massInverse * step, e = strength, w = wind, g = gravity; float m = massInverse * t, e = strength, w = wind, g = gravity;
float d = (float)Math.Pow(damping, 60 * step); float d = (float)Math.Pow(damping, 60 * t), h = l / f;
while (true) { while (true) {
remaining -= step; a -= t;
if (scaleX) { if (scaleX) {
scaleVelocity += (w * c - g * s - scaleOffset * e) * m; scaleVelocity += (w * c - g * s - scaleOffset * e) * m;
scaleOffset += scaleVelocity * step; scaleOffset += scaleVelocity * t;
scaleVelocity *= d; scaleVelocity *= d;
} }
if (rotateOrShearX) { if (rotateOrShearX) {
rotateVelocity += (-0.01f * l * (w * s + g * c) - rotateOffset * e) * m; rotateVelocity -= ((w * s + g * c) * h + rotateOffset * e) * m;
rotateOffset += rotateVelocity * step; rotateOffset += rotateVelocity * t;
rotateVelocity *= d; rotateVelocity *= d;
if (remaining < step) break; if (a < t) break;
float r = rotateOffset * mr + ca; float r = rotateOffset * mr + ca;
c = (float)Math.Cos(r); c = (float)Math.Cos(r);
s = (float)Math.Sin(r); s = (float)Math.Sin(r);
} else if (remaining < step) // } else if (a < t) //
break; break;
} }
} }
} }
this.remaining = remaining; this.remaining = a;
} }
cx = bone.worldX; cx = bone.worldX;
cy = bone.worldY; cy = bone.worldY;

View File

@ -42,9 +42,7 @@ namespace Spine {
internal ExposedList<IUpdatable> updateCache = new ExposedList<IUpdatable>(); internal ExposedList<IUpdatable> updateCache = new ExposedList<IUpdatable>();
internal Skin skin; internal Skin skin;
internal float r = 1, g = 1, b = 1, a = 1; internal float r = 1, g = 1, b = 1, a = 1;
internal float x, y; internal float x, y, scaleX = 1, scaleY = 1, time;
internal float scaleX = 1, scaleY = 1;
internal float time;
/// <summary>The skeleton's setup pose data.</summary> /// <summary>The skeleton's setup pose data.</summary>
public SkeletonData Data { get { return data; } } public SkeletonData Data { get { return data; } }

View File

@ -151,6 +151,7 @@ namespace Spine {
skeletonData.y = input.ReadFloat(); skeletonData.y = input.ReadFloat();
skeletonData.width = input.ReadFloat(); skeletonData.width = input.ReadFloat();
skeletonData.height = input.ReadFloat(); skeletonData.height = input.ReadFloat();
skeletonData.referenceScale = input.ReadFloat() * scale;
bool nonessential = input.ReadBoolean(); bool nonessential = input.ReadBoolean();
@ -322,8 +323,8 @@ namespace Spine {
data.strength = input.ReadFloat(); data.strength = input.ReadFloat();
data.damping = input.ReadFloat(); data.damping = input.ReadFloat();
data.massInverse = input.ReadFloat(); data.massInverse = input.ReadFloat();
data.wind = input.ReadFloat() * scale; data.wind = input.ReadFloat();
data.gravity = input.ReadFloat() * scale; data.gravity = input.ReadFloat();
data.mix = input.ReadFloat(); data.mix = input.ReadFloat();
flags = input.Read(); flags = input.Read();
if ((flags & 1) != 0) data.inertiaGlobal = true; if ((flags & 1) != 0) data.inertiaGlobal = true;
@ -1007,10 +1008,10 @@ namespace Spine {
ReadTimeline(input, timelines, new PhysicsConstraintMassTimeline(frameCount, bezierCount, index), 1); ReadTimeline(input, timelines, new PhysicsConstraintMassTimeline(frameCount, bezierCount, index), 1);
break; break;
case PHYSICS_WIND: case PHYSICS_WIND:
ReadTimeline(input, timelines, new PhysicsConstraintWindTimeline(frameCount, bezierCount, index), scale); ReadTimeline(input, timelines, new PhysicsConstraintWindTimeline(frameCount, bezierCount, index), 1);
break; break;
case PHYSICS_GRAVITY: case PHYSICS_GRAVITY:
ReadTimeline(input, timelines, new PhysicsConstraintGravityTimeline(frameCount, bezierCount, index), scale); ReadTimeline(input, timelines, new PhysicsConstraintGravityTimeline(frameCount, bezierCount, index), 1);
break; break;
case PHYSICS_MIX: case PHYSICS_MIX:
ReadTimeline(input, timelines, new PhysicsConstraintMixTimeline(frameCount, bezierCount, index), 1); ReadTimeline(input, timelines, new PhysicsConstraintMixTimeline(frameCount, bezierCount, index), 1);

View File

@ -44,7 +44,7 @@ namespace Spine {
internal ExposedList<TransformConstraintData> transformConstraints = new ExposedList<TransformConstraintData>(); internal ExposedList<TransformConstraintData> transformConstraints = new ExposedList<TransformConstraintData>();
internal ExposedList<PathConstraintData> pathConstraints = new ExposedList<PathConstraintData>(); internal ExposedList<PathConstraintData> pathConstraints = new ExposedList<PathConstraintData>();
internal ExposedList<PhysicsConstraintData> physicsConstraints = new ExposedList<PhysicsConstraintData>(); internal ExposedList<PhysicsConstraintData> physicsConstraints = new ExposedList<PhysicsConstraintData>();
internal float x, y, width, height; internal float x, y, width, height, referenceScale = 100;
internal string version, hash; internal string version, hash;
// Nonessential. // Nonessential.
@ -88,6 +88,11 @@ namespace Spine {
public float Y { get { return y; } set { y = value; } } public float Y { get { return y; } set { y = value; } }
public float Width { get { return width; } set { width = value; } } public float Width { get { return width; } set { width = value; } }
public float Height { get { return height; } set { height = value; } } public float Height { get { return height; } set { height = value; } }
/// <summary> Baseline scale factor for applying distance-dependent effects on non-scalable properties, such as angle or scale. Default
/// is 100.</summary>
public float ReferenceScale { get { return referenceScale; } set { referenceScale = value; } }
/// <summary>The Spine version used to export this data, or null.</summary> /// <summary>The Spine version used to export this data, or null.</summary>
public string Version { get { return version; } set { version = value; } } public string Version { get { return version; } set { version = value; } }

View File

@ -108,6 +108,7 @@ namespace Spine {
skeletonData.y = GetFloat(skeletonMap, "y", 0); skeletonData.y = GetFloat(skeletonMap, "y", 0);
skeletonData.width = GetFloat(skeletonMap, "width", 0); skeletonData.width = GetFloat(skeletonMap, "width", 0);
skeletonData.height = GetFloat(skeletonMap, "height", 0); skeletonData.height = GetFloat(skeletonMap, "height", 0);
skeletonData.referenceScale = GetFloat(skeletonMap, "referenceScale", 100) * scale;
skeletonData.fps = GetFloat(skeletonMap, "fps", 30); skeletonData.fps = GetFloat(skeletonMap, "fps", 30);
skeletonData.imagesPath = GetString(skeletonMap, "images", null); skeletonData.imagesPath = GetString(skeletonMap, "images", null);
skeletonData.audioPath = GetString(skeletonMap, "audio", null); skeletonData.audioPath = GetString(skeletonMap, "audio", null);
@ -307,8 +308,8 @@ namespace Spine {
data.strength = GetFloat(constraintMap, "strength", 100); data.strength = GetFloat(constraintMap, "strength", 100);
data.damping = GetFloat(constraintMap, "damping", 1); data.damping = GetFloat(constraintMap, "damping", 1);
data.massInverse = 1f / GetFloat(constraintMap, "mass", 1); data.massInverse = 1f / GetFloat(constraintMap, "mass", 1);
data.wind = GetFloat(constraintMap, "wind", 0) * scale; data.wind = GetFloat(constraintMap, "wind", 0);
data.gravity = GetFloat(constraintMap, "gravity", 0) * scale; data.gravity = GetFloat(constraintMap, "gravity", 0);
data.mix = GetFloat(constraintMap, "mix", 1); data.mix = GetFloat(constraintMap, "mix", 1);
data.inertiaGlobal = GetBoolean(constraintMap, "inertiaGlobal", false); data.inertiaGlobal = GetBoolean(constraintMap, "inertiaGlobal", false);
data.strengthGlobal = GetBoolean(constraintMap, "strengthGlobal", false); data.strengthGlobal = GetBoolean(constraintMap, "strengthGlobal", false);
@ -1044,7 +1045,6 @@ namespace Spine {
} }
CurveTimeline1 timeline; CurveTimeline1 timeline;
float timelineScale = 1.0f;
if (timelineName == "inertia") if (timelineName == "inertia")
timeline = new PhysicsConstraintInertiaTimeline(frames, frames, index); timeline = new PhysicsConstraintInertiaTimeline(frames, frames, index);
else if (timelineName == "strength") else if (timelineName == "strength")
@ -1055,15 +1055,13 @@ namespace Spine {
timeline = new PhysicsConstraintMassTimeline(frames, frames, index); timeline = new PhysicsConstraintMassTimeline(frames, frames, index);
else if (timelineName == "wind") { else if (timelineName == "wind") {
timeline = new PhysicsConstraintWindTimeline(frames, frames, index); timeline = new PhysicsConstraintWindTimeline(frames, frames, index);
timelineScale = scale;
} else if (timelineName == "gravity") { } else if (timelineName == "gravity") {
timeline = new PhysicsConstraintGravityTimeline(frames, frames, index); timeline = new PhysicsConstraintGravityTimeline(frames, frames, index);
timelineScale = scale;
} else if (timelineName == "mix") // } else if (timelineName == "mix") //
timeline = new PhysicsConstraintMixTimeline(frames, frames, index); timeline = new PhysicsConstraintMixTimeline(frames, frames, index);
else else
continue; continue;
timelines.Add(ReadTimeline(ref keyMapEnumerator, timeline, 0, timelineScale)); timelines.Add(ReadTimeline(ref keyMapEnumerator, timeline, 0, 1));
} }
} }
} }

View File

@ -2,7 +2,7 @@
"name": "com.esotericsoftware.spine.spine-csharp", "name": "com.esotericsoftware.spine.spine-csharp",
"displayName": "spine-csharp Runtime", "displayName": "spine-csharp Runtime",
"description": "This plugin provides the spine-csharp core runtime.", "description": "This plugin provides the spine-csharp core runtime.",
"version": "4.2.12", "version": "4.2.13",
"unity": "2018.3", "unity": "2018.3",
"author": { "author": {
"name": "Esoteric Software", "name": "Esoteric Software",