[ts] 4.3 porting WIP - latest updates.

This commit is contained in:
Davide Tantillo 2025-06-16 09:33:33 +02:00
parent 425f3d5776
commit 8d046cbbf4
4 changed files with 47 additions and 26 deletions

View File

@ -139,8 +139,8 @@ export class PhysicsConstraint extends Constraint<PhysicsConstraint, PhysicsCons
this.ux = bx; this.ux = bx;
this.uy = by; this.uy = by;
} else { } else {
let a = this.remaining, i = p.inertia, f = skeleton.data.referenceScale, d = -1, m = 0, e = 0, qx = this.data.limit * delta, let a = this.remaining, i = p.inertia, f = skeleton.data.referenceScale, d = -1, m = 0, e = 0, ax = 0, ay = 0,
qy = qx * Math.abs(skeleton.scaleY); qx = this.data.limit * delta, qy = qx * Math.abs(skeleton.scaleY);
qx *= Math.abs(skeleton.scaleX); qx *= Math.abs(skeleton.scaleX);
if (x || y) { if (x || y) {
if (x) { if (x) {
@ -158,8 +158,9 @@ export class PhysicsConstraint extends Constraint<PhysicsConstraint, PhysicsCons
d = Math.pow(p.damping, 60 * t); d = Math.pow(p.damping, 60 * t);
m = t * p.massInverse; m = t * p.massInverse;
e = p.strength; e = p.strength;
let w = f * p.wind * skeleton.scaleX, g = f * p.gravity * skeleton.scaleY, let w = f * p.wind, g = f * p.gravity;
ax = w * skeleton.windX + g * skeleton.gravityX, ay = w * skeleton.windY + g * skeleton.gravityY; ax = (w * skeleton.windX + g * skeleton.gravityX) * skeleton.scaleX;
ay = (w * skeleton.windY + g * skeleton.gravityY) * skeleton.scaleY;
do { do {
if (x) { if (x) {
this.xVelocity += (ax - this.xOffset * e) * m; this.xVelocity += (ax - this.xOffset * e) * m;
@ -214,11 +215,11 @@ export class PhysicsConstraint extends Constraint<PhysicsConstraint, PhysicsCons
d = Math.pow(p.damping, 60 * t); d = Math.pow(p.damping, 60 * t);
m = t * p.massInverse; m = t * p.massInverse;
e = p.strength; e = p.strength;
const w = f * p.wind, g = f * (Skeleton.yDown ? -p.gravity : p.gravity);
ax = (w * skeleton.windX + g * skeleton.gravityX) * skeleton.scaleX;
ay = (w * skeleton.windY + g * skeleton.gravityY) * skeleton.scaleY;
} }
var g = Skeleton.yDown ? -p.gravity : p.gravity; let rs = this.rotateOffset, ss = this.scaleOffset, h = l / f
let rs = this.rotateOffset, ss = this.scaleOffset, h = l / f,
ax = p.wind * skeleton.windX + g * skeleton.gravityX,
ay = p.wind * skeleton.windY + g * skeleton.gravityY;
while (true) { while (true) {
a -= t; a -= t;
if (scaleX) { if (scaleX) {

View File

@ -37,19 +37,45 @@ export abstract class Posed<
/** The constraint's setup pose data. */ /** The constraint's setup pose data. */
readonly data: D; readonly data: D;
readonly pose: P; readonly pose: A;
readonly constrained: A; readonly constrained: A;
applied: A; applied: A;
constructor (data: D, pose: P, constrained: A) { constructor (data: D, pose: A, constrained: A) {
if (data == null) throw new Error("data cannot be null."); if (data == null) throw new Error("data cannot be null.");
this.data = data; this.data = data;
this.pose = pose; this.pose = pose;
this.constrained = constrained; this.constrained = constrained;
this.applied = pose as A; this.applied = pose;
} }
public setupPose (): void { public setupPose (): void {
this.pose.set(this.data.setup); this.pose.set(this.data.setup);
} }
/** The constraint's setup pose data. */
public getData (): D {
return this.data;
}
public getPose (): P {
return this.pose;
}
public getAppliedPose (): A {
return this.applied;
}
usePose () { // Port: usePose - reference runtime: pose()
this.applied = this.pose;
}
useConstrained () { // Port: useConstrained - reference runtime: constrained()
this.applied = this.constrained;
}
resetConstrained () { // Port: resetConstrained - reference runtime: reset()
this.constrained.set(this.pose);
}
} }

View File

@ -41,7 +41,7 @@ export abstract class PosedActive<
active = false; active = false;
constructor (data: D, pose: P, constrained: A) { constructor (data: D, pose: A, constrained: A) {
super(data, pose, constrained); super(data, pose, constrained);
this.setupPose(); this.setupPose();
} }

View File

@ -165,10 +165,8 @@ export class Skeleton {
this.resetCache.length = 0; this.resetCache.length = 0;
let slots = this.slots; let slots = this.slots;
for (let i = 0, n = slots.length; i < n; i++) { for (let i = 0, n = slots.length; i < n; i++)
const slot = slots[i]; slots[i].usePose();
slot.applied = slot.pose;
}
let bones = this.bones; let bones = this.bones;
const boneCount = bones.length; const boneCount = bones.length;
@ -176,7 +174,7 @@ export class Skeleton {
let bone = bones[i]; let bone = bones[i];
bone.sorted = bone.data.skinRequired; bone.sorted = bone.data.skinRequired;
bone.active = !bone.sorted; bone.active = !bone.sorted;
bone.applied = bone.pose as BonePose; bone.usePose();
} }
if (this.skin) { if (this.skin) {
let skinBones = this.skin.bones; let skinBones = this.skin.bones;
@ -192,10 +190,8 @@ export class Skeleton {
let constraints = this.constraints; let constraints = this.constraints;
let n = this.constraints.length; let n = this.constraints.length;
for (let i = 0; i < n; i++) { for (let i = 0; i < n; i++)
const constraint = constraints[i]; constraints[i].usePose();
constraint.applied = constraint.pose;
}
for (let i = 0; i < n; i++) { for (let i = 0; i < n; i++) {
const constraint = constraints[i]; const constraint = constraints[i];
constraint.active = constraint.isSourceActive() constraint.active = constraint.isSourceActive()
@ -216,7 +212,7 @@ export class Skeleton {
constrained (object: Posed<any, any, any>) { constrained (object: Posed<any, any, any>) {
if (object.pose === object.applied) { if (object.pose === object.applied) {
object.applied = object.constrained; object.useConstrained();
this.resetCache.push(object); this.resetCache.push(object);
} }
} }
@ -247,10 +243,8 @@ export class Skeleton {
this._update++; this._update++;
const resetCache = this.resetCache; const resetCache = this.resetCache;
for (let i = 0, n = this.resetCache.length; i < n; i++) { for (let i = 0, n = this.resetCache.length; i < n; i++)
const object = resetCache[i]; resetCache[i].resetConstrained();
object.applied.set(object.pose);
}
const updateCache = this._updateCache; const updateCache = this._updateCache;
for (let i = 0, n = this._updateCache.length; i < n; i++) for (let i = 0, n = this._updateCache.length; i < n; i++)