mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2026-03-26 22:49:01 +08:00
Merge branch '4.1' into 4.2-beta
This commit is contained in:
commit
3b66796bb7
@ -50,7 +50,7 @@ import {
|
|||||||
} from "@esotericsoftware/spine-core";
|
} from "@esotericsoftware/spine-core";
|
||||||
|
|
||||||
class BaseSpineGameObject extends Phaser.GameObjects.GameObject {
|
class BaseSpineGameObject extends Phaser.GameObjects.GameObject {
|
||||||
constructor(scene: Phaser.Scene, type: string) {
|
constructor (scene: Phaser.Scene, type: string) {
|
||||||
super(scene, type);
|
super(scene, type);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -58,7 +58,7 @@ class BaseSpineGameObject extends Phaser.GameObjects.GameObject {
|
|||||||
/** A bounds provider calculates the bounding box for a skeleton, which is then assigned as the size of the SpineGameObject. */
|
/** A bounds provider calculates the bounding box for a skeleton, which is then assigned as the size of the SpineGameObject. */
|
||||||
export interface SpineGameObjectBoundsProvider {
|
export interface SpineGameObjectBoundsProvider {
|
||||||
// Returns the bounding box for the skeleton, in skeleton space.
|
// Returns the bounding box for the skeleton, in skeleton space.
|
||||||
calculateBounds(gameObject: SpineGameObject): {
|
calculateBounds (gameObject: SpineGameObject): {
|
||||||
x: number;
|
x: number;
|
||||||
y: number;
|
y: number;
|
||||||
width: number;
|
width: number;
|
||||||
@ -68,7 +68,7 @@ export interface SpineGameObjectBoundsProvider {
|
|||||||
|
|
||||||
/** A bounds provider that calculates the bounding box from the setup pose. */
|
/** A bounds provider that calculates the bounding box from the setup pose. */
|
||||||
export class SetupPoseBoundsProvider implements SpineGameObjectBoundsProvider {
|
export class SetupPoseBoundsProvider implements SpineGameObjectBoundsProvider {
|
||||||
calculateBounds(gameObject: SpineGameObject) {
|
calculateBounds (gameObject: SpineGameObject) {
|
||||||
if (!gameObject.skeleton) return { x: 0, y: 0, width: 0, height: 0 };
|
if (!gameObject.skeleton) return { x: 0, y: 0, width: 0, height: 0 };
|
||||||
// Make a copy of animation state and skeleton as this might be called while
|
// Make a copy of animation state and skeleton as this might be called while
|
||||||
// the skeleton in the GameObject has already been heavily modified. We can not
|
// the skeleton in the GameObject has already been heavily modified. We can not
|
||||||
@ -85,20 +85,19 @@ export class SetupPoseBoundsProvider implements SpineGameObjectBoundsProvider {
|
|||||||
|
|
||||||
/** A bounds provider that calculates the bounding box by taking the maximumg bounding box for a combination of skins and specific animation. */
|
/** A bounds provider that calculates the bounding box by taking the maximumg bounding box for a combination of skins and specific animation. */
|
||||||
export class SkinsAndAnimationBoundsProvider
|
export class SkinsAndAnimationBoundsProvider
|
||||||
implements SpineGameObjectBoundsProvider
|
implements SpineGameObjectBoundsProvider {
|
||||||
{
|
|
||||||
/**
|
/**
|
||||||
* @param animation The animation to use for calculating the bounds. If null, the setup pose is used.
|
* @param animation The animation to use for calculating the bounds. If null, the setup pose is used.
|
||||||
* @param skins The skins to use for calculating the bounds. If empty, the default skin is used.
|
* @param skins The skins to use for calculating the bounds. If empty, the default skin is used.
|
||||||
* @param timeStep The time step to use for calculating the bounds. A smaller time step means more precision, but slower calculation.
|
* @param timeStep The time step to use for calculating the bounds. A smaller time step means more precision, but slower calculation.
|
||||||
*/
|
*/
|
||||||
constructor(
|
constructor (
|
||||||
private animation: string | null,
|
private animation: string | null,
|
||||||
private skins: string[] = [],
|
private skins: string[] = [],
|
||||||
private timeStep: number = 0.05
|
private timeStep: number = 0.05
|
||||||
) {}
|
) { }
|
||||||
|
|
||||||
calculateBounds(gameObject: SpineGameObject): {
|
calculateBounds (gameObject: SpineGameObject): {
|
||||||
x: number;
|
x: number;
|
||||||
y: number;
|
y: number;
|
||||||
width: number;
|
width: number;
|
||||||
@ -199,11 +198,11 @@ export class SpineGameObject extends DepthMixin(
|
|||||||
skeleton: Skeleton;
|
skeleton: Skeleton;
|
||||||
animationStateData: AnimationStateData;
|
animationStateData: AnimationStateData;
|
||||||
animationState: AnimationState;
|
animationState: AnimationState;
|
||||||
beforeUpdateWorldTransforms: (object: SpineGameObject) => void = () => {};
|
beforeUpdateWorldTransforms: (object: SpineGameObject) => void = () => { };
|
||||||
afterUpdateWorldTransforms: (object: SpineGameObject) => void = () => {};
|
afterUpdateWorldTransforms: (object: SpineGameObject) => void = () => { };
|
||||||
private premultipliedAlpha = false;
|
private premultipliedAlpha = false;
|
||||||
|
|
||||||
constructor(
|
constructor (
|
||||||
scene: Phaser.Scene,
|
scene: Phaser.Scene,
|
||||||
private plugin: SpinePlugin,
|
private plugin: SpinePlugin,
|
||||||
x: number,
|
x: number,
|
||||||
@ -223,7 +222,7 @@ export class SpineGameObject extends DepthMixin(
|
|||||||
this.updateSize();
|
this.updateSize();
|
||||||
}
|
}
|
||||||
|
|
||||||
updateSize() {
|
updateSize () {
|
||||||
if (!this.skeleton) return;
|
if (!this.skeleton) return;
|
||||||
let bounds = this.boundsProvider.calculateBounds(this);
|
let bounds = this.boundsProvider.calculateBounds(this);
|
||||||
// For some reason the TS compiler and the ComputedSize mixin don't work well together and we have
|
// For some reason the TS compiler and the ComputedSize mixin don't work well together and we have
|
||||||
@ -236,7 +235,7 @@ export class SpineGameObject extends DepthMixin(
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** Converts a point from the skeleton coordinate system to the Phaser world coordinate system. */
|
/** Converts a point from the skeleton coordinate system to the Phaser world coordinate system. */
|
||||||
skeletonToPhaserWorldCoordinates(point: { x: number; y: number }) {
|
skeletonToPhaserWorldCoordinates (point: { x: number; y: number }) {
|
||||||
let transform = this.getWorldTransformMatrix();
|
let transform = this.getWorldTransformMatrix();
|
||||||
let a = transform.a,
|
let a = transform.a,
|
||||||
b = transform.b,
|
b = transform.b,
|
||||||
@ -251,7 +250,7 @@ export class SpineGameObject extends DepthMixin(
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** Converts a point from the Phaser world coordinate system to the skeleton coordinate system. */
|
/** Converts a point from the Phaser world coordinate system to the skeleton coordinate system. */
|
||||||
phaserWorldCoordinatesToSkeleton(point: { x: number; y: number }) {
|
phaserWorldCoordinatesToSkeleton (point: { x: number; y: number }) {
|
||||||
let transform = this.getWorldTransformMatrix();
|
let transform = this.getWorldTransformMatrix();
|
||||||
transform = transform.invert();
|
transform = transform.invert();
|
||||||
let a = transform.a,
|
let a = transform.a,
|
||||||
@ -267,7 +266,7 @@ export class SpineGameObject extends DepthMixin(
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** Converts a point from the Phaser world coordinate system to the bone's local coordinate system. */
|
/** Converts a point from the Phaser world coordinate system to the bone's local coordinate system. */
|
||||||
phaserWorldCoordinatesToBone(point: { x: number; y: number }, bone: Bone) {
|
phaserWorldCoordinatesToBone (point: { x: number; y: number }, bone: Bone) {
|
||||||
this.phaserWorldCoordinatesToSkeleton(point);
|
this.phaserWorldCoordinatesToSkeleton(point);
|
||||||
if (bone.parent) {
|
if (bone.parent) {
|
||||||
bone.parent.worldToLocal(point as Vector2);
|
bone.parent.worldToLocal(point as Vector2);
|
||||||
@ -280,7 +279,7 @@ export class SpineGameObject extends DepthMixin(
|
|||||||
* Updates the {@link AnimationState}, applies it to the {@link Skeleton}, then updates the world transforms of all bones.
|
* Updates the {@link AnimationState}, applies it to the {@link Skeleton}, then updates the world transforms of all bones.
|
||||||
* @param delta The time delta in milliseconds
|
* @param delta The time delta in milliseconds
|
||||||
*/
|
*/
|
||||||
updatePose(delta: number) {
|
updatePose (delta: number) {
|
||||||
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);
|
||||||
@ -288,16 +287,16 @@ export class SpineGameObject extends DepthMixin(
|
|||||||
this.afterUpdateWorldTransforms(this);
|
this.afterUpdateWorldTransforms(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
preUpdate(time: number, delta: number) {
|
preUpdate (time: number, delta: number) {
|
||||||
if (!this.skeleton || !this.animationState) return;
|
if (!this.skeleton || !this.animationState) return;
|
||||||
this.updatePose(delta);
|
this.updatePose(delta);
|
||||||
}
|
}
|
||||||
|
|
||||||
preDestroy() {
|
preDestroy () {
|
||||||
// FIXME tear down any event emitters
|
// FIXME tear down any event emitters
|
||||||
}
|
}
|
||||||
|
|
||||||
willRender(camera: Phaser.Cameras.Scene2D.Camera) {
|
willRender (camera: Phaser.Cameras.Scene2D.Camera) {
|
||||||
if (!this.visible) return false;
|
if (!this.visible) return false;
|
||||||
|
|
||||||
var GameObjectRenderMask = 0xf;
|
var GameObjectRenderMask = 0xf;
|
||||||
@ -315,7 +314,7 @@ export class SpineGameObject extends DepthMixin(
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
renderWebGL(
|
renderWebGL (
|
||||||
renderer: Phaser.Renderer.WebGL.WebGLRenderer,
|
renderer: Phaser.Renderer.WebGL.WebGLRenderer,
|
||||||
src: SpineGameObject,
|
src: SpineGameObject,
|
||||||
camera: Phaser.Cameras.Scene2D.Camera,
|
camera: Phaser.Cameras.Scene2D.Camera,
|
||||||
@ -363,7 +362,7 @@ export class SpineGameObject extends DepthMixin(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
renderCanvas(
|
renderCanvas (
|
||||||
renderer: Phaser.Renderer.Canvas.CanvasRenderer,
|
renderer: Phaser.Renderer.Canvas.CanvasRenderer,
|
||||||
src: SpineGameObject,
|
src: SpineGameObject,
|
||||||
camera: Phaser.Cameras.Scene2D.Camera,
|
camera: Phaser.Cameras.Scene2D.Camera,
|
||||||
|
|||||||
@ -52,7 +52,7 @@ export type SkeletonMeshMaterialParametersCustomizer = (
|
|||||||
) => void;
|
) => void;
|
||||||
|
|
||||||
export class SkeletonMeshMaterial extends THREE.ShaderMaterial {
|
export class SkeletonMeshMaterial extends THREE.ShaderMaterial {
|
||||||
constructor(customizer: SkeletonMeshMaterialParametersCustomizer) {
|
constructor (customizer: SkeletonMeshMaterialParametersCustomizer) {
|
||||||
let vertexShader = `
|
let vertexShader = `
|
||||||
attribute vec4 color;
|
attribute vec4 color;
|
||||||
varying vec2 vUv;
|
varying vec2 vUv;
|
||||||
@ -118,11 +118,11 @@ export class SkeletonMesh extends THREE.Object3D {
|
|||||||
private vertices = Utils.newFloatArray(1024);
|
private vertices = Utils.newFloatArray(1024);
|
||||||
private tempColor = new Color();
|
private tempColor = new Color();
|
||||||
|
|
||||||
constructor(
|
constructor (
|
||||||
skeletonData: SkeletonData,
|
skeletonData: SkeletonData,
|
||||||
private materialCustomerizer: SkeletonMeshMaterialParametersCustomizer = (
|
private materialCustomerizer: SkeletonMeshMaterialParametersCustomizer = (
|
||||||
material
|
material
|
||||||
) => {}
|
) => { }
|
||||||
) {
|
) {
|
||||||
super();
|
super();
|
||||||
|
|
||||||
@ -131,7 +131,7 @@ export class SkeletonMesh extends THREE.Object3D {
|
|||||||
this.state = new AnimationState(animData);
|
this.state = new AnimationState(animData);
|
||||||
}
|
}
|
||||||
|
|
||||||
update(deltaTime: number) {
|
update (deltaTime: number) {
|
||||||
let state = this.state;
|
let state = this.state;
|
||||||
let skeleton = this.skeleton;
|
let skeleton = this.skeleton;
|
||||||
|
|
||||||
@ -142,13 +142,13 @@ export class SkeletonMesh extends THREE.Object3D {
|
|||||||
this.updateGeometry();
|
this.updateGeometry();
|
||||||
}
|
}
|
||||||
|
|
||||||
dispose() {
|
dispose () {
|
||||||
for (var i = 0; i < this.batches.length; i++) {
|
for (var i = 0; i < this.batches.length; i++) {
|
||||||
this.batches[i].dispose();
|
this.batches[i].dispose();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private clearBatches() {
|
private clearBatches () {
|
||||||
for (var i = 0; i < this.batches.length; i++) {
|
for (var i = 0; i < this.batches.length; i++) {
|
||||||
this.batches[i].clear();
|
this.batches[i].clear();
|
||||||
this.batches[i].visible = false;
|
this.batches[i].visible = false;
|
||||||
@ -156,7 +156,7 @@ export class SkeletonMesh extends THREE.Object3D {
|
|||||||
this.nextBatchIndex = 0;
|
this.nextBatchIndex = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
private nextBatch() {
|
private nextBatch () {
|
||||||
if (this.batches.length == this.nextBatchIndex) {
|
if (this.batches.length == this.nextBatchIndex) {
|
||||||
let batch = new MeshBatcher(10920, this.materialCustomerizer);
|
let batch = new MeshBatcher(10920, this.materialCustomerizer);
|
||||||
this.add(batch);
|
this.add(batch);
|
||||||
@ -167,7 +167,7 @@ export class SkeletonMesh extends THREE.Object3D {
|
|||||||
return batch;
|
return batch;
|
||||||
}
|
}
|
||||||
|
|
||||||
private updateGeometry() {
|
private updateGeometry () {
|
||||||
this.clearBatches();
|
this.clearBatches();
|
||||||
|
|
||||||
let tempPos = this.tempPos;
|
let tempPos = this.tempPos;
|
||||||
|
|||||||
@ -170,7 +170,7 @@ export class SkeletonRenderer {
|
|||||||
WebGLBlendModeConverter.getSourceColorGLBlendMode(blendMode, premultipliedAlpha),
|
WebGLBlendModeConverter.getSourceColorGLBlendMode(blendMode, premultipliedAlpha),
|
||||||
WebGLBlendModeConverter.getSourceAlphaGLBlendMode(blendMode, premultipliedAlpha),
|
WebGLBlendModeConverter.getSourceAlphaGLBlendMode(blendMode, premultipliedAlpha),
|
||||||
WebGLBlendModeConverter.getDestColorGLBlendMode(blendMode),
|
WebGLBlendModeConverter.getDestColorGLBlendMode(blendMode),
|
||||||
WebGLBlendModeConverter.getDestAlphaGLBlendMode(blendMode, premultipliedAlpha) );
|
WebGLBlendModeConverter.getDestAlphaGLBlendMode(blendMode, premultipliedAlpha));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (clipper.isClipping()) {
|
if (clipper.isClipping()) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user