[ts] Scale gravity/wind when loading skeleton, see #2446

This commit is contained in:
Mario Zechner 2024-01-16 12:16:05 +01:00
parent be25484ac2
commit bd1acdc1d6
2 changed files with 14 additions and 9 deletions

View File

@ -239,8 +239,8 @@ export class SkeletonBinary {
data.strength = input.readFloat();
data.damping = input.readFloat();
data.massInverse = input.readFloat();
data.wind = input.readFloat();
data.gravity = input.readFloat();
data.wind = input.readFloat() * scale;
data.gravity = input.readFloat() * scale;
data.mix = input.readFloat();
flags = input.readByte();
if ((flags & 1) != 0) data.inertiaGlobal = true;
@ -953,10 +953,10 @@ export class SkeletonBinary {
timelines.push(readTimeline1(input, new PhysicsConstraintMassTimeline(frameCount, bezierCount, index), 1));
break;
case PHYSICS_WIND:
timelines.push(readTimeline1(input, new PhysicsConstraintWindTimeline(frameCount, bezierCount, index), 1));
timelines.push(readTimeline1(input, new PhysicsConstraintWindTimeline(frameCount, bezierCount, index), scale));
break;
case PHYSICS_GRAVITY:
timelines.push(readTimeline1(input, new PhysicsConstraintGravityTimeline(frameCount, bezierCount, index), 1));
timelines.push(readTimeline1(input, new PhysicsConstraintGravityTimeline(frameCount, bezierCount, index), scale));
break;
case PHYSICS_MIX:
timelines.push(readTimeline1(input, new PhysicsConstraintMixTimeline(frameCount, bezierCount, index), 1));

View File

@ -258,8 +258,8 @@ export class SkeletonJson {
data.strength = getValue(constraintMap, "strength", 100);
data.damping = getValue(constraintMap, "damping", 1);
data.massInverse = 1 / getValue(constraintMap, "mass", 1);
data.wind = getValue(constraintMap, "wind", 0);
data.gravity = getValue(constraintMap, "gravity", 0);
data.wind = getValue(constraintMap, "wind", 0) * scale;
data.gravity = getValue(constraintMap, "gravity", 0) * scale;
data.mix = getValue(constraintMap, "mix", 1);
data.inertiaGlobal = getValue(constraintMap, "inertiaGlobal", false);
data.strengthGlobal = getValue(constraintMap, "strengthGlobal", false);
@ -911,6 +911,7 @@ export class SkeletonJson {
}
let timeline;
let timelineScale = 1;
if (timelineName == "inertia")
timeline = new PhysicsConstraintInertiaTimeline(frames, frames, constraintIndex);
else if (timelineName == "strength")
@ -919,15 +920,19 @@ export class SkeletonJson {
timeline = new PhysicsConstraintDampingTimeline(frames, frames, constraintIndex);
else if (timelineName == "mass")
timeline = new PhysicsConstraintMassTimeline(frames, frames, constraintIndex);
else if (timelineName == "wind")
else if (timelineName == "wind") {
timeline = new PhysicsConstraintWindTimeline(frames, frames, constraintIndex);
else if (timelineName == "gravity")
timelineScale = scale;
}
else if (timelineName == "gravity") {
timeline = new PhysicsConstraintGravityTimeline(frames, frames, constraintIndex);
timelineScale = scale;
}
else if (timelineName == "mix") //
timeline = new PhysicsConstraintMixTimeline(frames, frames, constraintIndex);
else
continue;
timelines.push(readTimeline1(timelineMap, timeline, 0, 1));
timelines.push(readTimeline1(timelineMap, timeline, 0, timelineScale));
}
}
}