[ts] Temporarily use Physics.update everywhere

This commit is contained in:
Mario Zechner 2023-11-26 12:58:14 +01:00
parent f602177697
commit 4598da9a21
5 changed files with 18 additions and 15 deletions

View File

@ -945,7 +945,7 @@ export class TrackEntry {
} }
set mixDuration (mixDuration: number) { set mixDuration (mixDuration: number) {
this.mixDuration = mixDuration; this._mixDuration = mixDuration;
if (this.previous != null && this.delay <= 0) this.delay += this.previous.getTrackComplete() - mixDuration; if (this.previous != null && this.delay <= 0) this.delay += this.previous.getTrackComplete() - mixDuration;
this.delay = this.delay; this.delay = this.delay;
} }

View File

@ -44,6 +44,7 @@ import {
AnimationStateData, AnimationStateData,
Bone, Bone,
MathUtils, MathUtils,
Physics,
Skeleton, Skeleton,
Skin, Skin,
Vector2, Vector2,
@ -75,7 +76,7 @@ export class SetupPoseBoundsProvider implements SpineGameObjectBoundsProvider {
// reconstruct that state. // reconstruct that state.
const skeleton = new Skeleton(gameObject.skeleton.data); const skeleton = new Skeleton(gameObject.skeleton.data);
skeleton.setToSetupPose(); skeleton.setToSetupPose();
skeleton.updateWorldTransform(); skeleton.updateWorldTransform(Physics.update);
const bounds = skeleton.getBoundsRect(); const bounds = skeleton.getBoundsRect();
return bounds.width == Number.NEGATIVE_INFINITY return bounds.width == Number.NEGATIVE_INFINITY
? { x: 0, y: 0, width: 0, height: 0 } ? { x: 0, y: 0, width: 0, height: 0 }
@ -125,7 +126,7 @@ export class SkinsAndAnimationBoundsProvider
const animation = const animation =
this.animation != null ? data.findAnimation(this.animation!) : null; this.animation != null ? data.findAnimation(this.animation!) : null;
if (animation == null) { if (animation == null) {
skeleton.updateWorldTransform(); skeleton.updateWorldTransform(Physics.update);
const bounds = skeleton.getBoundsRect(); const bounds = skeleton.getBoundsRect();
return bounds.width == Number.NEGATIVE_INFINITY return bounds.width == Number.NEGATIVE_INFINITY
? { x: 0, y: 0, width: 0, height: 0 } ? { x: 0, y: 0, width: 0, height: 0 }
@ -141,7 +142,7 @@ export class SkinsAndAnimationBoundsProvider
for (let i = 0; i < steps; i++) { for (let i = 0; i < steps; i++) {
animationState.update(i > 0 ? this.timeStep : 0); animationState.update(i > 0 ? this.timeStep : 0);
animationState.apply(skeleton); animationState.apply(skeleton);
skeleton.updateWorldTransform(); skeleton.updateWorldTransform(Physics.update);
const bounds = skeleton.getBoundsRect(); const bounds = skeleton.getBoundsRect();
minX = Math.min(minX, bounds.x); minX = Math.min(minX, bounds.x);
@ -218,7 +219,7 @@ export class SpineGameObject extends DepthMixin(
this.skeleton = this.plugin.createSkeleton(dataKey, atlasKey); this.skeleton = this.plugin.createSkeleton(dataKey, atlasKey);
this.animationStateData = new AnimationStateData(this.skeleton.data); this.animationStateData = new AnimationStateData(this.skeleton.data);
this.animationState = new AnimationState(this.animationStateData); this.animationState = new AnimationState(this.animationStateData);
this.skeleton.updateWorldTransform(); this.skeleton.updateWorldTransform(Physics.update);
this.updateSize(); this.updateSize();
} }
@ -283,7 +284,7 @@ export class SpineGameObject extends DepthMixin(
this.animationState.update(delta / 1000); this.animationState.update(delta / 1000);
this.animationState.apply(this.skeleton); this.animationState.apply(this.skeleton);
this.beforeUpdateWorldTransforms(this); this.beforeUpdateWorldTransforms(this);
this.skeleton.updateWorldTransform(); this.skeleton.updateWorldTransform(Physics.update);
this.afterUpdateWorldTransforms(this); this.afterUpdateWorldTransforms(this);
} }
@ -387,7 +388,7 @@ export class SpineGameObject extends DepthMixin(
skeleton.scaleY = transform.scaleY; skeleton.scaleY = transform.scaleY;
let root = skeleton.getRootBone()!; let root = skeleton.getRootBone()!;
root.rotation = -MathUtils.radiansToDegrees * transform.rotationNormalized; root.rotation = -MathUtils.radiansToDegrees * transform.rotationNormalized;
this.skeleton.updateWorldTransform(); this.skeleton.updateWorldTransform(Physics.update);
context.save(); context.save();
skeletonRenderer.draw(skeleton); skeletonRenderer.draw(skeleton);

View File

@ -35,6 +35,7 @@ import {
ClippingAttachment, ClippingAttachment,
Color, Color,
MeshAttachment, MeshAttachment,
Physics,
RegionAttachment, RegionAttachment,
Skeleton, Skeleton,
SkeletonBinary, SkeletonBinary,
@ -123,7 +124,7 @@ export class Spine extends Container {
this.autoUpdate = options?.autoUpdate ?? true; this.autoUpdate = options?.autoUpdate ?? true;
this.slotMeshFactory = options?.slotMeshFactory ?? ((): ISlotMesh => new SlotMesh()); this.slotMeshFactory = options?.slotMeshFactory ?? ((): ISlotMesh => new SlotMesh());
this.skeleton.setToSetupPose(); this.skeleton.setToSetupPose();
this.skeleton.updateWorldTransform(); this.skeleton.updateWorldTransform(Physics.update);
} }
public update (deltaSeconds: number): void { public update (deltaSeconds: number): void {
@ -149,7 +150,7 @@ export class Spine extends Container {
// if I ever create the linked spines, this will be useful. // if I ever create the linked spines, this will be useful.
this.state.apply(this.skeleton); this.state.apply(this.skeleton);
this.skeleton.updateWorldTransform(); this.skeleton.updateWorldTransform(Physics.update);
this.updateGeometry(); this.updateGeometry();
this.sortChildren(); this.sortChildren();
} }

View File

@ -27,7 +27,7 @@
* SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/ *****************************************************************************/
import { Animation, AnimationState, AnimationStateData, AtlasAttachmentLoader, Bone, Color, Disposable, Downloader, MathUtils, MixBlend, MixDirection, Skeleton, SkeletonBinary, SkeletonData, SkeletonJson, StringMap, TextureAtlas, TextureFilter, TimeKeeper, TrackEntry, Vector2 } from "@esotericsoftware/spine-core" import { Animation, AnimationState, AnimationStateData, AtlasAttachmentLoader, Bone, Color, Disposable, Downloader, MathUtils, MixBlend, MixDirection, Physics, Skeleton, SkeletonBinary, SkeletonData, SkeletonJson, StringMap, TextureAtlas, TextureFilter, TimeKeeper, TrackEntry, Vector2 } from "@esotericsoftware/spine-core"
import { AssetManager, GLTexture, Input, LoadingScreen, ManagedWebGLRenderingContext, ResizeMode, SceneRenderer, Vector3 } from "@esotericsoftware/spine-webgl" import { AssetManager, GLTexture, Input, LoadingScreen, ManagedWebGLRenderingContext, ResizeMode, SceneRenderer, Vector3 } from "@esotericsoftware/spine-webgl"
export interface SpinePlayerConfig { export interface SpinePlayerConfig {
@ -370,7 +370,7 @@ export class SpinePlayer implements Disposable {
let time = animationDuration * percentage; let time = animationDuration * percentage;
this.animationState!.update(time - this.playTime); this.animationState!.update(time - this.playTime);
this.animationState!.apply(this.skeleton!); this.animationState!.apply(this.skeleton!);
this.skeleton!.updateWorldTransform(); this.skeleton!.updateWorldTransform(Physics.update);
this.playTime = time; this.playTime = time;
}; };
@ -542,7 +542,7 @@ export class SpinePlayer implements Disposable {
} else { } else {
entry = this.animationState.setEmptyAnimation(0); entry = this.animationState.setEmptyAnimation(0);
entry.trackEnd = 100000000; entry.trackEnd = 100000000;
this.skeleton.updateWorldTransform(); this.skeleton.updateWorldTransform(Physics.update);
this.setViewport(entry.animation!); this.setViewport(entry.animation!);
this.pause(); this.pause();
} }
@ -769,7 +769,7 @@ export class SpinePlayer implements Disposable {
for (let i = 0; i < steps; i++, time += stepTime) { for (let i = 0; i < steps; i++, time += stepTime) {
animation.apply(this.skeleton!, time, time, false, [], 1, MixBlend.setup, MixDirection.mixIn); animation.apply(this.skeleton!, time, time, false, [], 1, MixBlend.setup, MixDirection.mixIn);
this.skeleton!.updateWorldTransform(); this.skeleton!.updateWorldTransform(Physics.update);
this.skeleton!.getBounds(offset, size); this.skeleton!.getBounds(offset, size);
if (!isNaN(offset.x) && !isNaN(offset.y) && !isNaN(size.x) && !isNaN(size.y)) { if (!isNaN(offset.x) && !isNaN(offset.y) && !isNaN(size.x) && !isNaN(size.y)) {
@ -817,7 +817,7 @@ export class SpinePlayer implements Disposable {
if (!this.paused) { if (!this.paused) {
this.animationState!.update(playDelta); this.animationState!.update(playDelta);
this.animationState!.apply(skeleton); this.animationState!.apply(skeleton);
skeleton.updateWorldTransform(); skeleton.updateWorldTransform(Physics.update);
if (config.showControls) { if (config.showControls) {
this.playTime += playDelta; this.playTime += playDelta;

View File

@ -35,6 +35,7 @@ import {
Color, Color,
MeshAttachment, MeshAttachment,
NumberArrayLike, NumberArrayLike,
Physics,
RegionAttachment, RegionAttachment,
Skeleton, Skeleton,
SkeletonClipping, SkeletonClipping,
@ -137,7 +138,7 @@ export class SkeletonMesh extends THREE.Object3D {
state.update(deltaTime); state.update(deltaTime);
state.apply(skeleton); state.apply(skeleton);
skeleton.updateWorldTransform(); skeleton.updateWorldTransform(Physics.update);
this.updateGeometry(); this.updateGeometry();
} }