mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2025-12-21 09:46:02 +08:00
[ts][pixi-v8] Moved state.apply and UWT right after time updates. (#2679)
This commit is contained in:
parent
6ab5ddf92d
commit
8a8fc74f8e
@ -53,12 +53,12 @@
|
|||||||
// from one animation to the next.
|
// from one animation to the next.
|
||||||
stretchyman.state.data.defaultMix = 0.2;
|
stretchyman.state.data.defaultMix = 0.2;
|
||||||
|
|
||||||
|
// Set animation "run" on track 0, looped.
|
||||||
|
stretchyman.state.setAnimation(0, "idle", true);
|
||||||
|
|
||||||
// Center the spine object on screen.
|
// Center the spine object on screen.
|
||||||
stretchyman.x = window.innerWidth / 2;
|
stretchyman.x = window.innerWidth / 2;
|
||||||
stretchyman.y = window.innerHeight / 2 + stretchyman.getBounds().height / 2;
|
stretchyman.y = window.innerHeight / 2 + stretchyman.getBounds().height / 2;
|
||||||
|
|
||||||
// Set animation "run" on track 0, looped.
|
|
||||||
stretchyman.state.setAnimation(0, "idle", true);
|
|
||||||
app.stage.addChild(stretchyman);
|
app.stage.addChild(stretchyman);
|
||||||
|
|
||||||
const controlBoneNames = [
|
const controlBoneNames = [
|
||||||
|
|||||||
@ -36,13 +36,13 @@
|
|||||||
// from one animation to the next.
|
// from one animation to the next.
|
||||||
spineboy.state.data.defaultMix = 0.2;
|
spineboy.state.data.defaultMix = 0.2;
|
||||||
|
|
||||||
|
// Set animation "run" on track 0, looped.
|
||||||
|
spineboy.state.setAnimation(0, "run", true);
|
||||||
|
|
||||||
// Center the spine object on screen.
|
// Center the spine object on screen.
|
||||||
spineboy.x = window.innerWidth / 2;
|
spineboy.x = window.innerWidth / 2;
|
||||||
spineboy.y = window.innerHeight / 2 + spineboy.getBounds().height / 2;
|
spineboy.y = window.innerHeight / 2 + spineboy.getBounds().height / 2;
|
||||||
|
|
||||||
// Set animation "run" on track 0, looped.
|
|
||||||
spineboy.state.setAnimation(0, "run", true);
|
|
||||||
|
|
||||||
// Add the display object to the stage.
|
// Add the display object to the stage.
|
||||||
app.stage.addChild(spineboy);
|
app.stage.addChild(spineboy);
|
||||||
})();
|
})();
|
||||||
|
|||||||
@ -43,13 +43,13 @@
|
|||||||
// from one animation to the next.
|
// from one animation to the next.
|
||||||
spineboy.state.data.defaultMix = 0.2;
|
spineboy.state.data.defaultMix = 0.2;
|
||||||
|
|
||||||
|
// Set animation "run" on track 0, looped.
|
||||||
|
spineboy.state.setAnimation(0, "run", true);
|
||||||
|
|
||||||
// Center the spine object on screen.
|
// Center the spine object on screen.
|
||||||
spineboy.x = window.innerWidth / 2;
|
spineboy.x = window.innerWidth / 2;
|
||||||
spineboy.y = window.innerHeight / 2 + spineboy.getBounds().height / 2;
|
spineboy.y = window.innerHeight / 2 + spineboy.getBounds().height / 2;
|
||||||
|
|
||||||
// Set animation "run" on track 0, looped.
|
|
||||||
spineboy.state.setAnimation(0, "run", true);
|
|
||||||
|
|
||||||
// Add the display object to the stage.
|
// Add the display object to the stage.
|
||||||
app.stage.addChild(spineboy);
|
app.stage.addChild(spineboy);
|
||||||
})();
|
})();
|
||||||
|
|||||||
@ -36,14 +36,14 @@
|
|||||||
// from one animation to another.
|
// from one animation to another.
|
||||||
spineboy.state.data.defaultMix = 0.2;
|
spineboy.state.data.defaultMix = 0.2;
|
||||||
|
|
||||||
// Center the Spine object on screen.
|
|
||||||
spineboy.x = window.innerWidth / 2;
|
|
||||||
spineboy.y = window.innerHeight / 2 + spineboy.getBounds().height / 2;
|
|
||||||
|
|
||||||
// Set looping animations "idle" on track 0 and "aim" on track 1.
|
// Set looping animations "idle" on track 0 and "aim" on track 1.
|
||||||
spineboy.state.setAnimation(0, "idle", true);
|
spineboy.state.setAnimation(0, "idle", true);
|
||||||
spineboy.state.setAnimation(1, "aim", true);
|
spineboy.state.setAnimation(1, "aim", true);
|
||||||
|
|
||||||
|
// Center the Spine object on screen.
|
||||||
|
spineboy.x = window.innerWidth / 2;
|
||||||
|
spineboy.y = window.innerHeight / 2 + spineboy.getBounds().height / 2;
|
||||||
|
|
||||||
// Add the display object to the stage.
|
// Add the display object to the stage.
|
||||||
app.stage.addChild(spineboy);
|
app.stage.addChild(spineboy);
|
||||||
app.stage.hitArea = new PIXI.Rectangle(0, 0, app.view.width, app.view.height);
|
app.stage.hitArea = new PIXI.Rectangle(0, 0, app.view.width, app.view.height);
|
||||||
|
|||||||
@ -35,13 +35,13 @@
|
|||||||
// from one animation to the next.
|
// from one animation to the next.
|
||||||
spineboy.state.data.defaultMix = 0.2;
|
spineboy.state.data.defaultMix = 0.2;
|
||||||
|
|
||||||
|
// Set animation "run" on track 0, looped.
|
||||||
|
spineboy.state.setAnimation(0, "walk", true);
|
||||||
|
|
||||||
// Center the spine object on screen.
|
// Center the spine object on screen.
|
||||||
spineboy.x = window.innerWidth / 2;
|
spineboy.x = window.innerWidth / 2;
|
||||||
spineboy.y = window.innerHeight / 2 + spineboy.getBounds().height / 2;
|
spineboy.y = window.innerHeight / 2 + spineboy.getBounds().height / 2;
|
||||||
|
|
||||||
// Set animation "run" on track 0, looped.
|
|
||||||
spineboy.state.setAnimation(0, "walk", true);
|
|
||||||
|
|
||||||
// Add the display object to the stage.
|
// Add the display object to the stage.
|
||||||
app.stage.addChild(spineboy);
|
app.stage.addChild(spineboy);
|
||||||
|
|
||||||
@ -126,6 +126,7 @@
|
|||||||
// for clipping attachments having slot objects
|
// for clipping attachments having slot objects
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
spineboy.state.setAnimation(0, "portal", true)
|
spineboy.state.setAnimation(0, "portal", true)
|
||||||
|
spineboy.update(0)
|
||||||
const tooth3 = PIXI.Sprite.from('raptor_jaw');
|
const tooth3 = PIXI.Sprite.from('raptor_jaw');
|
||||||
tooth3.scale.set(2);
|
tooth3.scale.set(2);
|
||||||
tooth3.x = -60;
|
tooth3.x = -60;
|
||||||
|
|||||||
@ -232,6 +232,7 @@ export class Spine extends ViewContainer {
|
|||||||
this._autoUpdate = value;
|
this._autoUpdate = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private hasNeverUpdated = true;
|
||||||
constructor (options: SpineOptions | SkeletonData) {
|
constructor (options: SpineOptions | SkeletonData) {
|
||||||
if (options instanceof SkeletonData) {
|
if (options instanceof SkeletonData) {
|
||||||
options = {
|
options = {
|
||||||
@ -257,8 +258,6 @@ export class Spine extends ViewContainer {
|
|||||||
for (let i = 0; i < slots.length; i++) {
|
for (let i = 0; i < slots.length; i++) {
|
||||||
this.attachmentCacheData[i] = Object.create(null);
|
this.attachmentCacheData[i] = Object.create(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
this._updateState(0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** If {@link Spine.autoUpdate} is `false`, this method allows to update the AnimationState and the Skeleton with the given delta. */
|
/** If {@link Spine.autoUpdate} is `false`, this method allows to update the AnimationState and the Skeleton with the given delta. */
|
||||||
@ -274,7 +273,7 @@ export class Spine extends ViewContainer {
|
|||||||
protected internalUpdate (_deltaFrame: any, deltaSeconds?: number): void {
|
protected internalUpdate (_deltaFrame: any, deltaSeconds?: number): void {
|
||||||
// Because reasons, pixi uses deltaFrames at 60fps.
|
// Because reasons, pixi uses deltaFrames at 60fps.
|
||||||
// We ignore the default deltaFrames and use the deltaSeconds from pixi ticker.
|
// We ignore the default deltaFrames and use the deltaSeconds from pixi ticker.
|
||||||
this._updateState(deltaSeconds ?? Ticker.shared.deltaMS / 1000);
|
this._updateAndApplyState(deltaSeconds ?? Ticker.shared.deltaMS / 1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
get bounds () {
|
get bounds () {
|
||||||
@ -343,36 +342,17 @@ export class Spine extends ViewContainer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Will update the state based on the specified time, this will not apply the state to the skeleton
|
* Advance the state and skeleton by the given time, then update slot objects too.
|
||||||
* as this is differed until the `applyState` method is called.
|
* The container transform is not updated.
|
||||||
*
|
*
|
||||||
* @param time the time at which to set the state
|
* @param time the time at which to set the state
|
||||||
* @internal
|
|
||||||
*/
|
*/
|
||||||
_updateState (time: number) {
|
private _updateAndApplyState (time: number) {
|
||||||
|
this.hasNeverUpdated = false;
|
||||||
|
|
||||||
this.state.update(time);
|
this.state.update(time);
|
||||||
this.skeleton.update(time);
|
this.skeleton.update(time);
|
||||||
|
|
||||||
this._stateChanged = true;
|
|
||||||
|
|
||||||
this._boundsDirty = true;
|
|
||||||
|
|
||||||
this.onViewUpdate();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Applies the state to this spine instance.
|
|
||||||
* - updates the state to the skeleton
|
|
||||||
* - updates its world transform (spine world transform)
|
|
||||||
* - validates the attachments - to flag if the attachments have changed this state
|
|
||||||
* - transforms the attachments - to update the vertices of the attachments based on the new positions
|
|
||||||
* - update the slot attachments - to update the position, rotation, scale, and visibility of the attached containers
|
|
||||||
* @internal
|
|
||||||
*/
|
|
||||||
_applyState () {
|
|
||||||
if (!this._stateChanged) return;
|
|
||||||
this._stateChanged = false;
|
|
||||||
|
|
||||||
const { skeleton } = this;
|
const { skeleton } = this;
|
||||||
|
|
||||||
this.state.apply(skeleton);
|
this.state.apply(skeleton);
|
||||||
@ -381,11 +361,27 @@ export class Spine extends ViewContainer {
|
|||||||
skeleton.updateWorldTransform(Physics.update);
|
skeleton.updateWorldTransform(Physics.update);
|
||||||
this.afterUpdateWorldTransforms(this);
|
this.afterUpdateWorldTransforms(this);
|
||||||
|
|
||||||
|
this.updateSlotObjects();
|
||||||
|
|
||||||
|
this._stateChanged = true;
|
||||||
|
|
||||||
|
this._boundsDirty = true;
|
||||||
|
|
||||||
|
this.onViewUpdate();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* - validates the attachments - to flag if the attachments have changed this state
|
||||||
|
* - transforms the attachments - to update the vertices of the attachments based on the new positions
|
||||||
|
* @internal
|
||||||
|
*/
|
||||||
|
_validateAndTransformAttachments () {
|
||||||
|
if (!this._stateChanged) return;
|
||||||
|
this._stateChanged = false;
|
||||||
|
|
||||||
this.validateAttachments();
|
this.validateAttachments();
|
||||||
|
|
||||||
this.transformAttachments();
|
this.transformAttachments();
|
||||||
|
|
||||||
this.updateSlotObjects();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private validateAttachments () {
|
private validateAttachments () {
|
||||||
@ -802,7 +798,11 @@ export class Spine extends ViewContainer {
|
|||||||
skeletonBounds.update(this.skeleton, true);
|
skeletonBounds.update(this.skeleton, true);
|
||||||
|
|
||||||
if (skeletonBounds.minX === Infinity) {
|
if (skeletonBounds.minX === Infinity) {
|
||||||
this._applyState();
|
if (this.hasNeverUpdated) {
|
||||||
|
this._updateAndApplyState(0);
|
||||||
|
this._boundsDirty = false;
|
||||||
|
}
|
||||||
|
this._validateAndTransformAttachments();
|
||||||
|
|
||||||
const drawOrder = this.skeleton.drawOrder;
|
const drawOrder = this.skeleton.drawOrder;
|
||||||
const bounds = this._bounds;
|
const bounds = this._bounds;
|
||||||
|
|||||||
@ -66,7 +66,7 @@ export class SpinePipe implements RenderPipe<Spine> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
validateRenderable (spine: Spine): boolean {
|
validateRenderable (spine: Spine): boolean {
|
||||||
spine._applyState();
|
spine._validateAndTransformAttachments();
|
||||||
|
|
||||||
// if pine attachments have changed, we need to rebuild the batch!
|
// if pine attachments have changed, we need to rebuild the batch!
|
||||||
if (spine.spineAttachmentsDirty) {
|
if (spine.spineAttachmentsDirty) {
|
||||||
@ -109,7 +109,7 @@ export class SpinePipe implements RenderPipe<Spine> {
|
|||||||
|
|
||||||
const roundPixels = (this.renderer._roundPixels | spine._roundPixels) as 0 | 1;
|
const roundPixels = (this.renderer._roundPixels | spine._roundPixels) as 0 | 1;
|
||||||
|
|
||||||
spine._applyState();
|
spine._validateAndTransformAttachments();
|
||||||
|
|
||||||
for (let i = 0, n = drawOrder.length; i < n; i++) {
|
for (let i = 0, n = drawOrder.length; i < n; i++) {
|
||||||
const slot = drawOrder[i];
|
const slot = drawOrder[i];
|
||||||
@ -148,7 +148,7 @@ export class SpinePipe implements RenderPipe<Spine> {
|
|||||||
// we assume that spine will always change its verts size..
|
// we assume that spine will always change its verts size..
|
||||||
const gpuSpine = this.gpuSpineData[spine.uid];
|
const gpuSpine = this.gpuSpineData[spine.uid];
|
||||||
|
|
||||||
spine._applyState();
|
spine._validateAndTransformAttachments();
|
||||||
|
|
||||||
const drawOrder = spine.skeleton.drawOrder;
|
const drawOrder = spine.skeleton.drawOrder;
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user