From 74c11e6e693797cd62ebce5cba74dee497b9b7fc Mon Sep 17 00:00:00 2001 From: luzhuang <364439895@qq.com> Date: Thu, 2 Sep 2021 16:19:34 +0800 Subject: [PATCH 01/41] Animator editor (#475) * fix: bugfix --- .../src/scene-loader/resources/AnimatorControllerResource.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/loader/src/scene-loader/resources/AnimatorControllerResource.ts b/packages/loader/src/scene-loader/resources/AnimatorControllerResource.ts index 1eb8b6e0c4..cb39e3765f 100644 --- a/packages/loader/src/scene-loader/resources/AnimatorControllerResource.ts +++ b/packages/loader/src/scene-loader/resources/AnimatorControllerResource.ts @@ -98,8 +98,9 @@ export class AnimatorControllerResource extends SchemaResource { } _initAnimatorController(animatorControllerData) { - const { animations } = this.gltf; + const { animations } = this.gltf || {}; const { layers } = animatorControllerData; + if (!animations || !layers) return; this._resource.clearLayers(); for (let i = 0, length = layers.length; i < length; ++i) { const { name, blending, weight, stateMachine: stateMachineData } = layers[i]; From df25f0312fbc9d025bb57e3cfe124ac141ef7c82 Mon Sep 17 00:00:00 2001 From: yangfengzzz Date: Tue, 7 Sep 2021 13:32:39 +0800 Subject: [PATCH 02/41] feat: solve math design circular dependency (#485) * feat: solve math design cirular dependency --- packages/design/package.json | 5 ++++- packages/math/package.json | 5 +---- packages/math/src/BoundingBox.ts | 2 +- packages/math/src/BoundingFrustum.ts | 2 +- packages/math/src/BoundingSphere.ts | 2 +- packages/math/src/Color.ts | 2 +- packages/math/src/IClone.ts | 16 ++++++++++++++++ packages/math/src/Matrix.ts | 2 +- packages/math/src/Matrix3x3.ts | 2 +- packages/math/src/Plane.ts | 2 +- packages/math/src/Quaternion.ts | 2 +- packages/math/src/Rect.ts | 2 +- packages/math/src/SphericalHarmonics3.ts | 5 +++-- packages/math/src/Vector2.ts | 2 +- packages/math/src/Vector3.ts | 2 +- packages/math/src/Vector4.ts | 2 +- 16 files changed, 36 insertions(+), 19 deletions(-) create mode 100644 packages/math/src/IClone.ts diff --git a/packages/design/package.json b/packages/design/package.json index 659c27557f..6018bafd83 100755 --- a/packages/design/package.json +++ b/packages/design/package.json @@ -11,5 +11,8 @@ "dist/**/*", "types/**/*" ], - "types": "types/index.d.ts" + "types": "types/index.d.ts", + "dependencies": { + "@oasis-engine/math": "0.5.2" + } } diff --git a/packages/math/package.json b/packages/math/package.json index 647f70a8a2..c54b12d1d7 100755 --- a/packages/math/package.json +++ b/packages/math/package.json @@ -12,8 +12,5 @@ "files": [ "dist/**/*", "types/**/*" - ], - "devDependencies": { - "@oasis-engine/design": "0.5.2" - } + ] } diff --git a/packages/math/src/BoundingBox.ts b/packages/math/src/BoundingBox.ts index 538ef5bcec..d991cbb8bc 100644 --- a/packages/math/src/BoundingBox.ts +++ b/packages/math/src/BoundingBox.ts @@ -1,4 +1,4 @@ -import { IClone } from "@oasis-engine/design"; +import { IClone } from "./IClone"; import { BoundingSphere } from "./BoundingSphere"; import { Matrix } from "./Matrix"; import { Vector3 } from "./Vector3"; diff --git a/packages/math/src/BoundingFrustum.ts b/packages/math/src/BoundingFrustum.ts index 975e28ba6e..c1daa57c7b 100644 --- a/packages/math/src/BoundingFrustum.ts +++ b/packages/math/src/BoundingFrustum.ts @@ -1,4 +1,4 @@ -import { IClone } from "@oasis-engine/design"; +import { IClone } from "./IClone"; import { BoundingBox } from "./BoundingBox"; import { BoundingSphere } from "./BoundingSphere"; import { CollisionUtil } from "./CollisionUtil"; diff --git a/packages/math/src/BoundingSphere.ts b/packages/math/src/BoundingSphere.ts index 628b6531cd..0db173ff03 100644 --- a/packages/math/src/BoundingSphere.ts +++ b/packages/math/src/BoundingSphere.ts @@ -1,4 +1,4 @@ -import { IClone } from "@oasis-engine/design"; +import { IClone } from "./IClone"; import { BoundingBox } from "./BoundingBox"; import { Vector3 } from "./Vector3"; diff --git a/packages/math/src/Color.ts b/packages/math/src/Color.ts index ff5198c88e..fe0e959326 100644 --- a/packages/math/src/Color.ts +++ b/packages/math/src/Color.ts @@ -1,4 +1,4 @@ -import { IClone } from "@oasis-engine/design"; +import { IClone } from "./IClone"; import { MathUtil } from "./MathUtil"; /** diff --git a/packages/math/src/IClone.ts b/packages/math/src/IClone.ts new file mode 100644 index 0000000000..88bf04a002 --- /dev/null +++ b/packages/math/src/IClone.ts @@ -0,0 +1,16 @@ +/** + * Clone interface. + */ +export interface IClone { + /** + * Clone and return object. + * @returns Clone object + */ + clone(): Object; + + /** + * Clone to the target object. + * @param target - Target object + */ + cloneTo(target: Object): Object; +} diff --git a/packages/math/src/Matrix.ts b/packages/math/src/Matrix.ts index d6a1924070..f4e9b88db7 100644 --- a/packages/math/src/Matrix.ts +++ b/packages/math/src/Matrix.ts @@ -1,4 +1,4 @@ -import { IClone } from "@oasis-engine/design"; +import { IClone } from "./IClone"; import { MathUtil } from "./MathUtil"; import { Matrix3x3 } from "./Matrix3x3"; import { Quaternion } from "./Quaternion"; diff --git a/packages/math/src/Matrix3x3.ts b/packages/math/src/Matrix3x3.ts index 304520d716..e5ee0e607c 100644 --- a/packages/math/src/Matrix3x3.ts +++ b/packages/math/src/Matrix3x3.ts @@ -1,4 +1,4 @@ -import { IClone } from "@oasis-engine/design"; +import { IClone } from "./IClone"; import { MathUtil } from "./MathUtil"; import { Matrix } from "./Matrix"; import { Quaternion } from "./Quaternion"; diff --git a/packages/math/src/Plane.ts b/packages/math/src/Plane.ts index 46d65db82b..eaff0163b3 100644 --- a/packages/math/src/Plane.ts +++ b/packages/math/src/Plane.ts @@ -1,4 +1,4 @@ -import { IClone } from "@oasis-engine/design"; +import { IClone } from "./IClone"; import { Vector3 } from "./Vector3"; /** diff --git a/packages/math/src/Quaternion.ts b/packages/math/src/Quaternion.ts index e83e355c0e..8c5b28fba4 100644 --- a/packages/math/src/Quaternion.ts +++ b/packages/math/src/Quaternion.ts @@ -1,4 +1,4 @@ -import { IClone } from "@oasis-engine/design"; +import { IClone } from "./IClone"; import { MathUtil } from "./MathUtil"; import { Matrix3x3 } from "./Matrix3x3"; import { Vector3 } from "./Vector3"; diff --git a/packages/math/src/Rect.ts b/packages/math/src/Rect.ts index 838bff501e..af371ebcf7 100644 --- a/packages/math/src/Rect.ts +++ b/packages/math/src/Rect.ts @@ -1,4 +1,4 @@ -import { IClone } from "@oasis-engine/design"; +import { IClone } from "./IClone"; // A 2d rectangle defined by x and y position, width and height. export class Rect implements IClone { diff --git a/packages/math/src/SphericalHarmonics3.ts b/packages/math/src/SphericalHarmonics3.ts index c9fe995659..e60db6c0a9 100644 --- a/packages/math/src/SphericalHarmonics3.ts +++ b/packages/math/src/SphericalHarmonics3.ts @@ -1,4 +1,4 @@ -import { IClone } from "@oasis-engine/design"; +import { IClone } from "./IClone"; import { Color } from "./Color"; import { Vector3 } from "./Vector3"; @@ -203,7 +203,8 @@ export class SphericalHarmonics3 implements IClone { * @param out - The specified SphericalHarmonics3 * @returns The specified SphericalHarmonics3 */ - cloneTo(out: SphericalHarmonics3): void { + cloneTo(out: SphericalHarmonics3): SphericalHarmonics3 { this.toArray(out.coefficients); + return out; } } diff --git a/packages/math/src/Vector2.ts b/packages/math/src/Vector2.ts index 12af206f42..a4ee1ec855 100644 --- a/packages/math/src/Vector2.ts +++ b/packages/math/src/Vector2.ts @@ -1,4 +1,4 @@ -import { IClone } from "@oasis-engine/design"; +import { IClone } from "./IClone"; import { MathUtil } from "./MathUtil"; /** diff --git a/packages/math/src/Vector3.ts b/packages/math/src/Vector3.ts index 381dd22a91..b238f9be8b 100644 --- a/packages/math/src/Vector3.ts +++ b/packages/math/src/Vector3.ts @@ -1,4 +1,4 @@ -import { IClone } from "@oasis-engine/design"; +import { IClone } from "./IClone"; import { MathUtil } from "./MathUtil"; import { Matrix } from "./Matrix"; import { Quaternion } from "./Quaternion"; diff --git a/packages/math/src/Vector4.ts b/packages/math/src/Vector4.ts index 60af696950..83f460daeb 100644 --- a/packages/math/src/Vector4.ts +++ b/packages/math/src/Vector4.ts @@ -1,4 +1,4 @@ -import { IClone } from "@oasis-engine/design"; +import { IClone } from "./IClone"; import { MathUtil } from "./MathUtil"; import { Matrix } from "./Matrix"; import { Quaternion } from "./Quaternion"; From f064cc887c35c938f4d4a87554c92845e91bae30 Mon Sep 17 00:00:00 2001 From: GuoLei Date: Tue, 7 Sep 2021 13:33:18 +0800 Subject: [PATCH 03/41] Revert "feat: solve math design circular dependency (#485)" (#487) This reverts commit df25f0312fbc9d025bb57e3cfe124ac141ef7c82. --- packages/design/package.json | 5 +---- packages/math/package.json | 5 ++++- packages/math/src/BoundingBox.ts | 2 +- packages/math/src/BoundingFrustum.ts | 2 +- packages/math/src/BoundingSphere.ts | 2 +- packages/math/src/Color.ts | 2 +- packages/math/src/IClone.ts | 16 ---------------- packages/math/src/Matrix.ts | 2 +- packages/math/src/Matrix3x3.ts | 2 +- packages/math/src/Plane.ts | 2 +- packages/math/src/Quaternion.ts | 2 +- packages/math/src/Rect.ts | 2 +- packages/math/src/SphericalHarmonics3.ts | 5 ++--- packages/math/src/Vector2.ts | 2 +- packages/math/src/Vector3.ts | 2 +- packages/math/src/Vector4.ts | 2 +- 16 files changed, 19 insertions(+), 36 deletions(-) delete mode 100644 packages/math/src/IClone.ts diff --git a/packages/design/package.json b/packages/design/package.json index 6018bafd83..659c27557f 100755 --- a/packages/design/package.json +++ b/packages/design/package.json @@ -11,8 +11,5 @@ "dist/**/*", "types/**/*" ], - "types": "types/index.d.ts", - "dependencies": { - "@oasis-engine/math": "0.5.2" - } + "types": "types/index.d.ts" } diff --git a/packages/math/package.json b/packages/math/package.json index c54b12d1d7..647f70a8a2 100755 --- a/packages/math/package.json +++ b/packages/math/package.json @@ -12,5 +12,8 @@ "files": [ "dist/**/*", "types/**/*" - ] + ], + "devDependencies": { + "@oasis-engine/design": "0.5.2" + } } diff --git a/packages/math/src/BoundingBox.ts b/packages/math/src/BoundingBox.ts index d991cbb8bc..538ef5bcec 100644 --- a/packages/math/src/BoundingBox.ts +++ b/packages/math/src/BoundingBox.ts @@ -1,4 +1,4 @@ -import { IClone } from "./IClone"; +import { IClone } from "@oasis-engine/design"; import { BoundingSphere } from "./BoundingSphere"; import { Matrix } from "./Matrix"; import { Vector3 } from "./Vector3"; diff --git a/packages/math/src/BoundingFrustum.ts b/packages/math/src/BoundingFrustum.ts index c1daa57c7b..975e28ba6e 100644 --- a/packages/math/src/BoundingFrustum.ts +++ b/packages/math/src/BoundingFrustum.ts @@ -1,4 +1,4 @@ -import { IClone } from "./IClone"; +import { IClone } from "@oasis-engine/design"; import { BoundingBox } from "./BoundingBox"; import { BoundingSphere } from "./BoundingSphere"; import { CollisionUtil } from "./CollisionUtil"; diff --git a/packages/math/src/BoundingSphere.ts b/packages/math/src/BoundingSphere.ts index 0db173ff03..628b6531cd 100644 --- a/packages/math/src/BoundingSphere.ts +++ b/packages/math/src/BoundingSphere.ts @@ -1,4 +1,4 @@ -import { IClone } from "./IClone"; +import { IClone } from "@oasis-engine/design"; import { BoundingBox } from "./BoundingBox"; import { Vector3 } from "./Vector3"; diff --git a/packages/math/src/Color.ts b/packages/math/src/Color.ts index fe0e959326..ff5198c88e 100644 --- a/packages/math/src/Color.ts +++ b/packages/math/src/Color.ts @@ -1,4 +1,4 @@ -import { IClone } from "./IClone"; +import { IClone } from "@oasis-engine/design"; import { MathUtil } from "./MathUtil"; /** diff --git a/packages/math/src/IClone.ts b/packages/math/src/IClone.ts deleted file mode 100644 index 88bf04a002..0000000000 --- a/packages/math/src/IClone.ts +++ /dev/null @@ -1,16 +0,0 @@ -/** - * Clone interface. - */ -export interface IClone { - /** - * Clone and return object. - * @returns Clone object - */ - clone(): Object; - - /** - * Clone to the target object. - * @param target - Target object - */ - cloneTo(target: Object): Object; -} diff --git a/packages/math/src/Matrix.ts b/packages/math/src/Matrix.ts index f4e9b88db7..d6a1924070 100644 --- a/packages/math/src/Matrix.ts +++ b/packages/math/src/Matrix.ts @@ -1,4 +1,4 @@ -import { IClone } from "./IClone"; +import { IClone } from "@oasis-engine/design"; import { MathUtil } from "./MathUtil"; import { Matrix3x3 } from "./Matrix3x3"; import { Quaternion } from "./Quaternion"; diff --git a/packages/math/src/Matrix3x3.ts b/packages/math/src/Matrix3x3.ts index e5ee0e607c..304520d716 100644 --- a/packages/math/src/Matrix3x3.ts +++ b/packages/math/src/Matrix3x3.ts @@ -1,4 +1,4 @@ -import { IClone } from "./IClone"; +import { IClone } from "@oasis-engine/design"; import { MathUtil } from "./MathUtil"; import { Matrix } from "./Matrix"; import { Quaternion } from "./Quaternion"; diff --git a/packages/math/src/Plane.ts b/packages/math/src/Plane.ts index eaff0163b3..46d65db82b 100644 --- a/packages/math/src/Plane.ts +++ b/packages/math/src/Plane.ts @@ -1,4 +1,4 @@ -import { IClone } from "./IClone"; +import { IClone } from "@oasis-engine/design"; import { Vector3 } from "./Vector3"; /** diff --git a/packages/math/src/Quaternion.ts b/packages/math/src/Quaternion.ts index 8c5b28fba4..e83e355c0e 100644 --- a/packages/math/src/Quaternion.ts +++ b/packages/math/src/Quaternion.ts @@ -1,4 +1,4 @@ -import { IClone } from "./IClone"; +import { IClone } from "@oasis-engine/design"; import { MathUtil } from "./MathUtil"; import { Matrix3x3 } from "./Matrix3x3"; import { Vector3 } from "./Vector3"; diff --git a/packages/math/src/Rect.ts b/packages/math/src/Rect.ts index af371ebcf7..838bff501e 100644 --- a/packages/math/src/Rect.ts +++ b/packages/math/src/Rect.ts @@ -1,4 +1,4 @@ -import { IClone } from "./IClone"; +import { IClone } from "@oasis-engine/design"; // A 2d rectangle defined by x and y position, width and height. export class Rect implements IClone { diff --git a/packages/math/src/SphericalHarmonics3.ts b/packages/math/src/SphericalHarmonics3.ts index e60db6c0a9..c9fe995659 100644 --- a/packages/math/src/SphericalHarmonics3.ts +++ b/packages/math/src/SphericalHarmonics3.ts @@ -1,4 +1,4 @@ -import { IClone } from "./IClone"; +import { IClone } from "@oasis-engine/design"; import { Color } from "./Color"; import { Vector3 } from "./Vector3"; @@ -203,8 +203,7 @@ export class SphericalHarmonics3 implements IClone { * @param out - The specified SphericalHarmonics3 * @returns The specified SphericalHarmonics3 */ - cloneTo(out: SphericalHarmonics3): SphericalHarmonics3 { + cloneTo(out: SphericalHarmonics3): void { this.toArray(out.coefficients); - return out; } } diff --git a/packages/math/src/Vector2.ts b/packages/math/src/Vector2.ts index a4ee1ec855..12af206f42 100644 --- a/packages/math/src/Vector2.ts +++ b/packages/math/src/Vector2.ts @@ -1,4 +1,4 @@ -import { IClone } from "./IClone"; +import { IClone } from "@oasis-engine/design"; import { MathUtil } from "./MathUtil"; /** diff --git a/packages/math/src/Vector3.ts b/packages/math/src/Vector3.ts index b238f9be8b..381dd22a91 100644 --- a/packages/math/src/Vector3.ts +++ b/packages/math/src/Vector3.ts @@ -1,4 +1,4 @@ -import { IClone } from "./IClone"; +import { IClone } from "@oasis-engine/design"; import { MathUtil } from "./MathUtil"; import { Matrix } from "./Matrix"; import { Quaternion } from "./Quaternion"; diff --git a/packages/math/src/Vector4.ts b/packages/math/src/Vector4.ts index 83f460daeb..60af696950 100644 --- a/packages/math/src/Vector4.ts +++ b/packages/math/src/Vector4.ts @@ -1,4 +1,4 @@ -import { IClone } from "./IClone"; +import { IClone } from "@oasis-engine/design"; import { MathUtil } from "./MathUtil"; import { Matrix } from "./Matrix"; import { Quaternion } from "./Quaternion"; From 2878bdf13b826f0db0a63f10cd44813c2b9dd306 Mon Sep 17 00:00:00 2001 From: JujieX <67930474+JujieX@users.noreply.github.com> Date: Tue, 7 Sep 2021 18:31:43 +0800 Subject: [PATCH 04/41] feat: add rotateAxisAngle for Quaternion (#480) * feat: add rotateAxisAngle for Quaternion --- packages/math/src/Quaternion.ts | 14 ++++++++++++++ packages/math/tests/Quaternion.test.ts | 10 +++++++++- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/packages/math/src/Quaternion.ts b/packages/math/src/Quaternion.ts index e83e355c0e..a0f01dca77 100644 --- a/packages/math/src/Quaternion.ts +++ b/packages/math/src/Quaternion.ts @@ -9,6 +9,8 @@ import { Vector3 } from "./Vector3"; export class Quaternion implements IClone { /** @internal */ static readonly _tempVector3 = new Vector3(); + /** @internal */ + static readonly _tempQuat1 = new Quaternion(); /** * Determines the sum of two quaternions. @@ -697,4 +699,16 @@ export class Quaternion implements IClone { Quaternion.lerp(this, quat, t, this); return this; } + + /** + * Calculate this quaternion rotation around an arbitrary axis. + * @param axis - The axis + * @param rad - The rotation angle in radians + * @returns This quaternion + */ + rotateAxisAngle(axis: Vector3, rad: number): Quaternion { + Quaternion._tempQuat1.rotationAxisAngle(axis, rad); + this.multiply(Quaternion._tempQuat1); + return this; + } } diff --git a/packages/math/tests/Quaternion.test.ts b/packages/math/tests/Quaternion.test.ts index 3363889062..d8ae41090a 100644 --- a/packages/math/tests/Quaternion.test.ts +++ b/packages/math/tests/Quaternion.test.ts @@ -177,6 +177,14 @@ describe("Quaternion test", () => { expect(Quaternion.equals(out, b)).toEqual(true); }); + it("static rotatAxisAngle", () => { + const a = new Vector3(0, 5, 0); + const b = 0.5 * Math.PI; + const out = new Quaternion(0, 0, 0, 1); + out.rotateAxisAngle(a, b); + expect(Quaternion.equals(out, new Quaternion(0, 0.7071067811865475, 0, 0.7071067811865476))).toEqual(true); + }); + it("static scale", () => { const a = new Quaternion(3, 4, 5, 0); const out = new Quaternion(); @@ -200,7 +208,7 @@ describe("Quaternion test", () => { const b = new Quaternion(); b.setValueByArray([1, 1, 1, 1]); expect(Quaternion.equals(a, b)).toEqual(true); - + const c = []; b.toArray(c); const d = new Quaternion(); From 7d17191d508ca2e4da2a8452ecb52d89711ada82 Mon Sep 17 00:00:00 2001 From: Hu Song Date: Wed, 8 Sep 2021 11:49:39 +0800 Subject: [PATCH 05/41] refactor: delete useless scene raycast (#493) --- packages/core/src/Scene.ts | 7 ------- 1 file changed, 7 deletions(-) diff --git a/packages/core/src/Scene.ts b/packages/core/src/Scene.ts index 8effb4c860..4d6a7cf550 100644 --- a/packages/core/src/Scene.ts +++ b/packages/core/src/Scene.ts @@ -258,11 +258,4 @@ export class Scene extends EngineObject { } features: SceneFeature[] = []; - - /** - * Raycast. - * @deprecated - * @param ray - */ - public raycast(ray: { origin: Vector3; direction: Vector3 }, outPos?: Vector3, tag?: Layer): any {} } From aea42777b2067fa309e0bb77ece830a9e84df382 Mon Sep 17 00:00:00 2001 From: zhuxudong Date: Fri, 10 Sep 2021 18:05:22 +0800 Subject: [PATCH 06/41] fix: group other uniform block (#504) --- packages/core/src/RenderPipeline/BasicRenderPipeline.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/core/src/RenderPipeline/BasicRenderPipeline.ts b/packages/core/src/RenderPipeline/BasicRenderPipeline.ts index 5f9da6a13b..961b918c11 100644 --- a/packages/core/src/RenderPipeline/BasicRenderPipeline.ts +++ b/packages/core/src/RenderPipeline/BasicRenderPipeline.ts @@ -257,6 +257,7 @@ export class BasicRenderPipeline { const program = shader._getShaderProgram(engine, compileMacros); program.bind(); + program.groupingOtherUniformBlock(); program.uploadAll(program.materialUniformBlock, shaderData); program.uploadUngroupTextures(); From 6b86f88682bdb40fb9ea8d9154dd7d28bee5af22 Mon Sep 17 00:00:00 2001 From: singlecoder Date: Fri, 8 Oct 2021 16:25:45 +0800 Subject: [PATCH 07/41] fix(primitivemesh): fix cylinder error (#526) --- packages/core/src/mesh/PrimitiveMesh.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/core/src/mesh/PrimitiveMesh.ts b/packages/core/src/mesh/PrimitiveMesh.ts index 83e78b39d3..5d30d46591 100644 --- a/packages/core/src/mesh/PrimitiveMesh.ts +++ b/packages/core/src/mesh/PrimitiveMesh.ts @@ -340,7 +340,9 @@ export class PrimitiveMesh { // Create torso const thetaStart = Math.PI; const thetaRange = Math.PI * 2; - const slope = (radiusBottom - radiusTop) / height; + const radiusDiff = radiusBottom - radiusTop; + const slope = radiusDiff / height; + const radiusSlope = radiusDiff / heightSegments; for (let i = 0; i < torsoVertexCount; ++i) { const x = i % radialCount; @@ -350,7 +352,7 @@ export class PrimitiveMesh { const theta = thetaStart + u * thetaRange; const sinTheta = Math.sin(theta); const cosTheta = Math.cos(theta); - const radius = radiusBottom - y * (radiusBottom - radiusTop); + const radius = radiusBottom - y * radiusSlope; let posX = radius * sinTheta; let posY = y * unitHeight - halfHeight; From 750be3cb7b2087886030a0f6d418a567abb46884 Mon Sep 17 00:00:00 2001 From: zhuxudong Date: Sat, 9 Oct 2021 15:50:44 +0800 Subject: [PATCH 08/41] Perf: release gpu command (#503) * perf: release viewport gpu command * perf: release clearColor gpu command --- packages/rhi-webgl/src/WebGLRenderer.ts | 39 ++++++++++++++++++------- 1 file changed, 29 insertions(+), 10 deletions(-) diff --git a/packages/rhi-webgl/src/WebGLRenderer.ts b/packages/rhi-webgl/src/WebGLRenderer.ts index fb05cd1ec1..03c4f21ea0 100644 --- a/packages/rhi-webgl/src/WebGLRenderer.ts +++ b/packages/rhi-webgl/src/WebGLRenderer.ts @@ -21,7 +21,7 @@ import { } from "@oasis-engine/core"; import { CameraClearFlags } from "@oasis-engine/core"; import { IPlatformPrimitive } from "@oasis-engine/design"; -import { Color } from "@oasis-engine/math"; +import { Color, Vector4 } from "@oasis-engine/math"; import { GLCapability } from "./GLCapability"; import { GLExtensions } from "./GLExtensions"; import { GLPrimitive } from "./GLPrimitive"; @@ -71,6 +71,10 @@ export class WebGLRenderer implements IHardwareRenderer { private _activeTextureID: number = WebGLRenderingContext.TEXTURE0; private _activeTextures: GLTexture[] = new Array(32); + // cache value + private _lastViewport: Vector4 = new Vector4(undefined, undefined, undefined, undefined); + private _lastClearColor: Color = new Color(undefined, undefined, undefined, undefined); + get isWebGL2() { return this._isWebGL2; } @@ -181,11 +185,16 @@ export class WebGLRenderer implements IHardwareRenderer { return this.capability.canIUseCompressedTextureInternalFormat(type); } - viewport(x, y, width, height) { + viewport(x: number, y: number, width: number, height: number): void { // gl.enable(gl.SCISSOR_TEST); // gl.scissor(x, transformY, width, height); const gl = this._gl; - gl.viewport(x, gl.drawingBufferHeight - y - height, width, height); + const lv = this._lastViewport; + + if (x !== lv.x || y !== lv.y || width !== lv.z || height !== lv.w) { + gl.viewport(x, y, width, height); + lv.setValue(x, y, width, height); + } } colorMask(r, g, b, a) { @@ -205,11 +214,18 @@ export class WebGLRenderer implements IHardwareRenderer { } = engine._lastRenderState; let clearFlag = gl.DEPTH_BUFFER_BIT | gl.STENCIL_BUFFER_BIT; + if (clearFlags === CameraClearFlags.DepthColor) { - clearFlag = clearFlag | gl.COLOR_BUFFER_BIT; - if (clearColor) { - gl.clearColor(clearColor.r, clearColor.g, clearColor.b, clearColor.a); + clearFlag |= gl.COLOR_BUFFER_BIT; + + const lc = this._lastClearColor; + const { r, g, b, a } = clearColor; + + if (clearColor && (r !== lc.r || g !== lc.g || b !== lc.b || a !== lc.a)) { + gl.clearColor(r, g, b, a); + lc.setValue(r, g, b, a); } + if (targetBlendState.colorWriteMask !== ColorWriteMask.All) { gl.colorMask(true, true, true, true); targetBlendState.colorWriteMask = ColorWriteMask.All; @@ -245,13 +261,16 @@ export class WebGLRenderer implements IHardwareRenderer { /** @ts-ignore */ (renderTarget._platformRenderTarget as GLRenderTarget)?._activeRenderTarget(); const { width, height } = renderTarget; - gl.viewport(0.0, 0.0, width, height); + this.viewport(0, 0, width, height); } else { gl.bindFramebuffer(gl.FRAMEBUFFER, null); const viewport = camera.viewport; - const width = gl.drawingBufferWidth; - const height = gl.drawingBufferHeight; - this.viewport(viewport.x * width, viewport.y * height, viewport.z * width, viewport.w * height); + const { drawingBufferWidth, drawingBufferHeight } = gl; + const width = drawingBufferWidth * viewport.z; + const height = drawingBufferHeight * viewport.w; + const x = viewport.x * drawingBufferWidth; + const y = drawingBufferHeight - viewport.y * drawingBufferHeight - height; + this.viewport(x, y, width, height); } } From bc9487de1c5ac3e04c71537dc69a7a6fc955fd3d Mon Sep 17 00:00:00 2001 From: luzhuang <364439895@qq.com> Date: Sat, 9 Oct 2021 16:22:40 +0800 Subject: [PATCH 09/41] fix: reset clipTime (#530) * fix: reset clipTime --- packages/core/src/animation/internal/AnimatorStatePlayData.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/core/src/animation/internal/AnimatorStatePlayData.ts b/packages/core/src/animation/internal/AnimatorStatePlayData.ts index bfd5452e54..f34b8cd1e3 100644 --- a/packages/core/src/animation/internal/AnimatorStatePlayData.ts +++ b/packages/core/src/animation/internal/AnimatorStatePlayData.ts @@ -18,6 +18,7 @@ export class AnimatorStatePlayData { this.frameTime = offsetFrameTime; this.stateData = stateData; this.finished = false; + this.clipTime = this.state.clipStartTime; this.currentEventIndex = 0; } From 365219cd0a7f4c83bb844c262c9fd5ccb90e6646 Mon Sep 17 00:00:00 2001 From: Hu Song Date: Tue, 12 Oct 2021 14:28:25 +0800 Subject: [PATCH 10/41] fix: use string replace asset type to extend easily (#520) --- packages/core/src/asset/ResourceManager.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/core/src/asset/ResourceManager.ts b/packages/core/src/asset/ResourceManager.ts index 9bf8e9641a..d2fc8bb984 100644 --- a/packages/core/src/asset/ResourceManager.ts +++ b/packages/core/src/asset/ResourceManager.ts @@ -12,19 +12,19 @@ import { ObjectValues } from "../base/Util"; export class ResourceManager { /** Loader collection. */ private static _loaders: { [key: number]: Loader } = {}; - private static _extTypeMapping: { [key: string]: AssetType } = {}; + private static _extTypeMapping: { [key: string]: string } = {}; /** * @internal */ - static _addLoader(type: AssetType, loader: Loader, extnames: string[]) { + static _addLoader(type: string, loader: Loader, extnames: string[]) { this._loaders[type] = loader; for (let i = 0, len = extnames.length; i < len; i++) { this._extTypeMapping[extnames[i]] = type; } } - private static _getTypeByUrl(url: string): AssetType { + private static _getTypeByUrl(url: string): string { const path = url.split("?")[0]; return this._extTypeMapping[path.substring(path.lastIndexOf(".") + 1)]; } @@ -219,7 +219,7 @@ export class ResourceManager { * @param assetType - Type of asset * @param extnames - Name of file extension */ -export function resourceLoader(assetType: AssetType, extnames: string[], useCache: boolean = true) { +export function resourceLoader(assetType: string, extnames: string[], useCache: boolean = true) { return >(Target: { new (useCache: boolean): T }) => { const loader = new Target(useCache); ResourceManager._addLoader(assetType, loader, extnames); From 159e5a23b3ee348dc26d3200d429b9ea3aa69547 Mon Sep 17 00:00:00 2001 From: luzhuang <364439895@qq.com> Date: Tue, 12 Oct 2021 15:04:40 +0800 Subject: [PATCH 11/41] Fix/animator (#531) * fix: animator bug --- packages/core/src/animation/Animator.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/core/src/animation/Animator.ts b/packages/core/src/animation/Animator.ts index 5196dde13a..c7ca3746fd 100644 --- a/packages/core/src/animation/Animator.ts +++ b/packages/core/src/animation/Animator.ts @@ -192,7 +192,7 @@ export class Animator extends Component { if (animatorController) { const layers = animatorController.layers; if (layerIndex === -1) { - for (let i = 0, n = layers.length; i < n; i--) { + for (let i = 0, n = layers.length; i < n; i++) { state = layers[i].stateMachine.findStateByName(stateName); if (state) { layerIndex = i; From 18909ed173404992594607be61e533258cd2ccec Mon Sep 17 00:00:00 2001 From: Bob <768442443@qq.com> Date: Tue, 12 Oct 2021 16:15:27 +0800 Subject: [PATCH 12/41] Update README.md --- README.md | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 9fb7108132..2302cc9974 100644 --- a/README.md +++ b/README.md @@ -1,13 +1,11 @@ -# Oasis Engine (Ant Graphics Engine) - -

Oasis logo

+# Ant Graphics Engine ![npm-size](https://img.shields.io/bundlephobia/minzip/oasis-engine) ![npm-download](https://img.shields.io/npm/dm/oasis-engine) [![codecov](https://codecov.io/gh/oasis-engine/engine/branch/main/graph/badge.svg?token=KR2UBKE3OX)](https://codecov.io/gh/oasis-engine/engine) -Oasis is a **web-first** and **mobile-first** high-performance real-time development platform. Use **component system design** and pursue ease of use and light weight. This repository is the core engine of Oasis. Developers can independently use and write Typescript scripts to develop projects using pure code. +This is a **web-first** and **mobile-first** high-performance real-time development platform. Use **component system design** and pursue ease of use and light weight. Developers can independently use and write Typescript scripts to develop projects using pure code. ## Features @@ -51,13 +49,13 @@ engine.run(); ## npm -Oasis Engine are published on npm with full typing support. To install, use: +The engine is published on npm with full typing support. To install, use: ```sh npm install oasis-engine ``` -This will allow you to import Oasis Engine entirely using: +This will allow you to import engine entirely using: ```javascript import * as OASIS from "oasis-engine"; @@ -98,4 +96,4 @@ npm run b:all ## License -The Oasis Engine is released under the [MIT](https://opensource.org/licenses/MIT) license. See LICENSE file. +The engine is released under the [MIT](https://opensource.org/licenses/MIT) license. See LICENSE file. From 3085ac8d9febc629e4b04eff63230dee26dd126d Mon Sep 17 00:00:00 2001 From: luzhuang <364439895@qq.com> Date: Tue, 12 Oct 2021 18:07:46 +0800 Subject: [PATCH 13/41] Fix: cubic interpolation and crossfade bug: From fixed pose to dest pose, throw error. (#534) * fix: Animator bug --- packages/core/src/animation/AnimationCurve.ts | 22 +-------------- packages/core/src/animation/Animator.ts | 27 ++++++++++--------- 2 files changed, 15 insertions(+), 34 deletions(-) diff --git a/packages/core/src/animation/AnimationCurve.ts b/packages/core/src/animation/AnimationCurve.ts index 3246ba02e0..740ff3503d 100644 --- a/packages/core/src/animation/AnimationCurve.ts +++ b/packages/core/src/animation/AnimationCurve.ts @@ -127,12 +127,10 @@ export class AnimationCurve { case InterpolationType.Linear: value = this._evaluateLinear(curIndex, nextIndex, t); break; - case InterpolationType.CubicSpine: - value = this._evaluateCubicSpline(curIndex, nextIndex, t); - break; case InterpolationType.Step: value = this._evaluateStep(nextIndex); break; + case InterpolationType.CubicSpine: case InterpolationType.Hermite: value = this._evaluateHermite(curIndex, nextIndex, t, dur); } @@ -206,24 +204,6 @@ export class AnimationCurve { } } - private _evaluateCubicSpline(frameIndex: number, nextFrameIndex: number, t: number): Vector3 { - const { keys } = this; - const squared = t * t; - const cubed = t * squared; - const part1 = 2.0 * cubed - 3.0 * squared + 1.0; - const part2 = -2.0 * cubed + 3.0 * squared; - const part3 = cubed - 2.0 * squared + t; - const part4 = cubed - squared; - - const t1: Vector3 = (keys[frameIndex]).value; - const v1: Vector3 = (keys[frameIndex + 1]).value; - const t2: Vector3 = (keys[frameIndex + 2]).value; - const v2: Vector3 = (keys[nextFrameIndex + 1]).value; - - //CM:clone - return v1.scale(part1).add(v2.scale(part2)).add(t1.scale(part3)).add(t2.scale(part4)).clone(); - } - private _evaluateStep(nextFrameIndex: number): InterpolableValue { const { _valueSize, keys } = this; if (_valueSize === 1) { diff --git a/packages/core/src/animation/Animator.ts b/packages/core/src/animation/Animator.ts index c7ca3746fd..13d8c24cb9 100644 --- a/packages/core/src/animation/Animator.ts +++ b/packages/core/src/animation/Animator.ts @@ -316,7 +316,10 @@ export class Animator extends Component { // Save current cross curve data owner fixed pose. for (let i = crossCurveData.length - 1; i >= 0; i--) { - crossCurveData[i].curveOwner.saveFixedPoseValue(); + const item = crossCurveData[i]; + item.curveOwner.saveFixedPoseValue(); + // Reset destCurveIndex When fixed pose crossFading again. + item.destCurveIndex = -1; } // prepare dest AnimatorState cross data. this._prepareDestCrossData(crossCurveData, animatorLayerData.destPlayData, animatorLayerData.crossCurveMark, true); @@ -329,13 +332,12 @@ export class Animator extends Component { saveFixed: boolean ): void { const { curveOwners } = srcPlayData.stateData; - for (let i = curveOwners.length - 1; i >= 0; i--) { const owner = curveOwners[i]; owner.crossCurveMark = crossCurveMark; owner.crossCurveIndex = crossCurveData.length; saveFixed && owner.saveFixedPoseValue(); - this._addCrossCurveData(crossCurveData, owner, i, null); + this._addCrossCurveData(crossCurveData, owner, i, -1); } } @@ -346,7 +348,6 @@ export class Animator extends Component { saveFixed: boolean ): void { const { curveOwners } = destPlayData.stateData; - for (let i = curveOwners.length - 1; i >= 0; i--) { const owner = curveOwners[i]; // Not include in previous AnimatorState. @@ -355,7 +356,8 @@ export class Animator extends Component { } else { saveFixed && owner.saveFixedPoseValue(); owner.crossCurveMark = crossCurveMark; - this._addCrossCurveData(crossCurveData, owner, null, i); + owner.crossCurveIndex = crossCurveData.length; + this._addCrossCurveData(crossCurveData, owner, -1, i); } } } @@ -473,13 +475,14 @@ export class Animator extends Component { const { curveOwner, srcCurveIndex, destCurveIndex } = crossCurveDataCollection[i]; const { property, defaultValue } = curveOwner; - const srcCurve = srcCurves[srcCurveIndex].curve; - const destCurve = destCurves[destCurveIndex].curve; - const srcValue = - srcCurveIndex >= 0 ? this._evaluateCurve(property, srcCurve, srcClipTime, additive) : defaultValue; + srcCurveIndex >= 0 + ? this._evaluateCurve(property, srcCurves[srcCurveIndex].curve, srcClipTime, additive) + : defaultValue; const destValue = - destCurveIndex >= 0 ? this._evaluateCurve(property, destCurve, destClipTime, additive) : defaultValue; + destCurveIndex >= 0 + ? this._evaluateCurve(property, destCurves[destCurveIndex].curve, destClipTime, additive) + : defaultValue; this._applyCrossClipValue(curveOwner, srcValue, destValue, crossWeight, weight, additive); } @@ -503,13 +506,11 @@ export class Animator extends Component { destPlayData.update(); const destClipTime = destPlayData.clipTime; - for (let i = crossCurveDataCollection.length - 1; i >= 0; i--) { const { curveOwner, destCurveIndex } = crossCurveDataCollection[i]; - const destCurve = curves[destCurveIndex].curve; const destValue = destCurveIndex >= 0 - ? this._evaluateCurve(curveOwner.property, destCurve, destClipTime, additive) + ? this._evaluateCurve(curveOwner.property, curves[destCurveIndex].curve, destClipTime, additive) : curveOwner.defaultValue; this._applyCrossClipValue(curveOwner, curveOwner.fixedPoseValue, destValue, crossWeight, weight, additive); From b5bd22db327248d449c27e1a8c51b847af041398 Mon Sep 17 00:00:00 2001 From: GuoLei1990 Date: Tue, 12 Oct 2021 18:11:59 +0800 Subject: [PATCH 14/41] v0.5.3 --- lerna.json | 2 +- packages/controls/package.json | 4 ++-- packages/core/package.json | 6 +++--- packages/design/package.json | 2 +- packages/draco/package.json | 4 ++-- packages/framebuffer-picker/package.json | 4 ++-- packages/loader/package.json | 10 +++++----- packages/math/package.json | 4 ++-- packages/oasis-engine/package.json | 10 +++++----- packages/rhi-webgl/package.json | 8 ++++---- packages/stats/package.json | 4 ++-- 11 files changed, 29 insertions(+), 29 deletions(-) diff --git a/lerna.json b/lerna.json index 6a22adfdc1..341caf1045 100644 --- a/lerna.json +++ b/lerna.json @@ -1,6 +1,6 @@ { "npmClient": "npm", - "version": "0.5.2", + "version": "0.5.3", "bootstrap": { "hoist": true }, diff --git a/packages/controls/package.json b/packages/controls/package.json index 8ad4176110..9a6af60dbd 100644 --- a/packages/controls/package.json +++ b/packages/controls/package.json @@ -1,6 +1,6 @@ { "name": "@oasis-engine/controls", - "version": "0.5.2", + "version": "0.5.3", "license": "MIT", "scripts": { "b:types": "tsc", @@ -15,6 +15,6 @@ "types/**/*" ], "dependencies": { - "oasis-engine": "0.5.2" + "oasis-engine": "0.5.3" } } diff --git a/packages/core/package.json b/packages/core/package.json index bea83bb4d9..58b0a4e015 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -1,6 +1,6 @@ { "name": "@oasis-engine/core", - "version": "0.5.2", + "version": "0.5.3", "license": "MIT", "main": "dist/main.js", "module": "dist/module.js", @@ -14,9 +14,9 @@ "types/**/*" ], "dependencies": { - "@oasis-engine/math": "0.5.2" + "@oasis-engine/math": "0.5.3" }, "devDependencies": { - "@oasis-engine/design": "0.5.2" + "@oasis-engine/design": "0.5.3" } } diff --git a/packages/design/package.json b/packages/design/package.json index 659c27557f..7e04720b5b 100755 --- a/packages/design/package.json +++ b/packages/design/package.json @@ -1,6 +1,6 @@ { "name": "@oasis-engine/design", - "version": "0.5.2", + "version": "0.5.3", "license": "MIT", "main": "dist/main.js", "module": "dist/module.js", diff --git a/packages/draco/package.json b/packages/draco/package.json index 0c39bbd23f..4f40c49212 100644 --- a/packages/draco/package.json +++ b/packages/draco/package.json @@ -1,6 +1,6 @@ { "name": "@oasis-engine/draco", - "version": "0.5.2", + "version": "0.5.3", "license": "MIT", "scripts": { "b:types": "tsc" @@ -13,6 +13,6 @@ "types/**/*" ], "dependencies": { - "@oasis-engine/core": "0.5.2" + "@oasis-engine/core": "0.5.3" } } diff --git a/packages/framebuffer-picker/package.json b/packages/framebuffer-picker/package.json index ac69c04fc1..555d97651e 100755 --- a/packages/framebuffer-picker/package.json +++ b/packages/framebuffer-picker/package.json @@ -1,6 +1,6 @@ { "name": "@oasis-engine/framebuffer-picker", - "version": "0.5.2", + "version": "0.5.3", "license": "MIT", "main": "dist/main.js", "module": "dist/module.js", @@ -14,6 +14,6 @@ "types/**/*" ], "dependencies": { - "oasis-engine": "0.5.2" + "oasis-engine": "0.5.3" } } diff --git a/packages/loader/package.json b/packages/loader/package.json index 4c720c6cfc..d16da0b90f 100755 --- a/packages/loader/package.json +++ b/packages/loader/package.json @@ -1,6 +1,6 @@ { "name": "@oasis-engine/loader", - "version": "0.5.2", + "version": "0.5.3", "license": "MIT", "types": "types/index.d.ts", "scripts": { @@ -14,9 +14,9 @@ "types/**/*" ], "dependencies": { - "@oasis-engine/core": "0.5.2", - "@oasis-engine/draco": "0.5.2", - "@oasis-engine/math": "0.5.2", - "@oasis-engine/rhi-webgl": "0.5.2" + "@oasis-engine/core": "0.5.3", + "@oasis-engine/draco": "0.5.3", + "@oasis-engine/math": "0.5.3", + "@oasis-engine/rhi-webgl": "0.5.3" } } diff --git a/packages/math/package.json b/packages/math/package.json index 647f70a8a2..a4c709f48a 100755 --- a/packages/math/package.json +++ b/packages/math/package.json @@ -1,6 +1,6 @@ { "name": "@oasis-engine/math", - "version": "0.5.2", + "version": "0.5.3", "license": "MIT", "main": "dist/main.js", "module": "dist/module.js", @@ -14,6 +14,6 @@ "types/**/*" ], "devDependencies": { - "@oasis-engine/design": "0.5.2" + "@oasis-engine/design": "0.5.3" } } diff --git a/packages/oasis-engine/package.json b/packages/oasis-engine/package.json index 26e56ef0ed..304b80aa5a 100755 --- a/packages/oasis-engine/package.json +++ b/packages/oasis-engine/package.json @@ -1,6 +1,6 @@ { "name": "oasis-engine", - "version": "0.5.2", + "version": "0.5.3", "license": "MIT", "scripts": { "b:types": "tsc" @@ -14,9 +14,9 @@ "types/**/*" ], "dependencies": { - "@oasis-engine/core": "0.5.2", - "@oasis-engine/loader": "0.5.2", - "@oasis-engine/math": "0.5.2", - "@oasis-engine/rhi-webgl": "0.5.2" + "@oasis-engine/core": "0.5.3", + "@oasis-engine/loader": "0.5.3", + "@oasis-engine/math": "0.5.3", + "@oasis-engine/rhi-webgl": "0.5.3" } } diff --git a/packages/rhi-webgl/package.json b/packages/rhi-webgl/package.json index f21e178fe5..aaaa41ceb2 100755 --- a/packages/rhi-webgl/package.json +++ b/packages/rhi-webgl/package.json @@ -1,6 +1,6 @@ { "name": "@oasis-engine/rhi-webgl", - "version": "0.5.2", + "version": "0.5.3", "license": "MIT", "main": "dist/main.js", "module": "dist/module.js", @@ -14,10 +14,10 @@ "types/**/*" ], "dependencies": { - "@oasis-engine/core": "0.5.2", - "@oasis-engine/math": "0.5.2" + "@oasis-engine/core": "0.5.3", + "@oasis-engine/math": "0.5.3" }, "devDependencies": { - "@oasis-engine/design": "0.5.2" + "@oasis-engine/design": "0.5.3" } } diff --git a/packages/stats/package.json b/packages/stats/package.json index 8dcfdf2790..36e1ad621e 100755 --- a/packages/stats/package.json +++ b/packages/stats/package.json @@ -1,6 +1,6 @@ { "name": "@oasis-engine/stats", - "version": "0.5.2", + "version": "0.5.3", "license": "MIT", "scripts": { "b:types": "tsc" @@ -14,6 +14,6 @@ "types/**/*" ], "dependencies": { - "oasis-engine": "0.5.2" + "oasis-engine": "0.5.3" } } From 871c1026c4228f5f5207c4c830f7ad64cdca59ba Mon Sep 17 00:00:00 2001 From: GuoLei1990 Date: Tue, 12 Oct 2021 18:13:21 +0800 Subject: [PATCH 15/41] v0.5.4 --- lerna.json | 2 +- packages/controls/package.json | 4 ++-- packages/core/package.json | 6 +++--- packages/design/package.json | 2 +- packages/draco/package.json | 4 ++-- packages/framebuffer-picker/package.json | 4 ++-- packages/loader/package.json | 8 ++++---- packages/math/package.json | 4 ++-- packages/oasis-engine/package.json | 8 ++++---- packages/stats/package.json | 4 ++-- 10 files changed, 23 insertions(+), 23 deletions(-) diff --git a/lerna.json b/lerna.json index 341caf1045..8c00ad3176 100644 --- a/lerna.json +++ b/lerna.json @@ -1,6 +1,6 @@ { "npmClient": "npm", - "version": "0.5.3", + "version": "0.5.4", "bootstrap": { "hoist": true }, diff --git a/packages/controls/package.json b/packages/controls/package.json index 9a6af60dbd..cadc850b89 100644 --- a/packages/controls/package.json +++ b/packages/controls/package.json @@ -1,6 +1,6 @@ { "name": "@oasis-engine/controls", - "version": "0.5.3", + "version": "0.5.4", "license": "MIT", "scripts": { "b:types": "tsc", @@ -15,6 +15,6 @@ "types/**/*" ], "dependencies": { - "oasis-engine": "0.5.3" + "oasis-engine": "0.5.4" } } diff --git a/packages/core/package.json b/packages/core/package.json index 58b0a4e015..53a4fdede5 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -1,6 +1,6 @@ { "name": "@oasis-engine/core", - "version": "0.5.3", + "version": "0.5.4", "license": "MIT", "main": "dist/main.js", "module": "dist/module.js", @@ -14,9 +14,9 @@ "types/**/*" ], "dependencies": { - "@oasis-engine/math": "0.5.3" + "@oasis-engine/math": "0.5.4" }, "devDependencies": { - "@oasis-engine/design": "0.5.3" + "@oasis-engine/design": "0.5.4" } } diff --git a/packages/design/package.json b/packages/design/package.json index 7e04720b5b..2a1c1e436b 100755 --- a/packages/design/package.json +++ b/packages/design/package.json @@ -1,6 +1,6 @@ { "name": "@oasis-engine/design", - "version": "0.5.3", + "version": "0.5.4", "license": "MIT", "main": "dist/main.js", "module": "dist/module.js", diff --git a/packages/draco/package.json b/packages/draco/package.json index 4f40c49212..446b3cc97a 100644 --- a/packages/draco/package.json +++ b/packages/draco/package.json @@ -1,6 +1,6 @@ { "name": "@oasis-engine/draco", - "version": "0.5.3", + "version": "0.5.4", "license": "MIT", "scripts": { "b:types": "tsc" @@ -13,6 +13,6 @@ "types/**/*" ], "dependencies": { - "@oasis-engine/core": "0.5.3" + "@oasis-engine/core": "0.5.4" } } diff --git a/packages/framebuffer-picker/package.json b/packages/framebuffer-picker/package.json index 555d97651e..0cb175f787 100755 --- a/packages/framebuffer-picker/package.json +++ b/packages/framebuffer-picker/package.json @@ -1,6 +1,6 @@ { "name": "@oasis-engine/framebuffer-picker", - "version": "0.5.3", + "version": "0.5.4", "license": "MIT", "main": "dist/main.js", "module": "dist/module.js", @@ -14,6 +14,6 @@ "types/**/*" ], "dependencies": { - "oasis-engine": "0.5.3" + "oasis-engine": "0.5.4" } } diff --git a/packages/loader/package.json b/packages/loader/package.json index d16da0b90f..4f81bb5491 100755 --- a/packages/loader/package.json +++ b/packages/loader/package.json @@ -1,6 +1,6 @@ { "name": "@oasis-engine/loader", - "version": "0.5.3", + "version": "0.5.4", "license": "MIT", "types": "types/index.d.ts", "scripts": { @@ -14,9 +14,9 @@ "types/**/*" ], "dependencies": { - "@oasis-engine/core": "0.5.3", - "@oasis-engine/draco": "0.5.3", - "@oasis-engine/math": "0.5.3", + "@oasis-engine/core": "0.5.4", + "@oasis-engine/draco": "0.5.4", + "@oasis-engine/math": "0.5.4", "@oasis-engine/rhi-webgl": "0.5.3" } } diff --git a/packages/math/package.json b/packages/math/package.json index a4c709f48a..ad647527be 100755 --- a/packages/math/package.json +++ b/packages/math/package.json @@ -1,6 +1,6 @@ { "name": "@oasis-engine/math", - "version": "0.5.3", + "version": "0.5.4", "license": "MIT", "main": "dist/main.js", "module": "dist/module.js", @@ -14,6 +14,6 @@ "types/**/*" ], "devDependencies": { - "@oasis-engine/design": "0.5.3" + "@oasis-engine/design": "0.5.4" } } diff --git a/packages/oasis-engine/package.json b/packages/oasis-engine/package.json index 304b80aa5a..fb13adb91a 100755 --- a/packages/oasis-engine/package.json +++ b/packages/oasis-engine/package.json @@ -1,6 +1,6 @@ { "name": "oasis-engine", - "version": "0.5.3", + "version": "0.5.4", "license": "MIT", "scripts": { "b:types": "tsc" @@ -14,9 +14,9 @@ "types/**/*" ], "dependencies": { - "@oasis-engine/core": "0.5.3", - "@oasis-engine/loader": "0.5.3", - "@oasis-engine/math": "0.5.3", + "@oasis-engine/core": "0.5.4", + "@oasis-engine/loader": "0.5.4", + "@oasis-engine/math": "0.5.4", "@oasis-engine/rhi-webgl": "0.5.3" } } diff --git a/packages/stats/package.json b/packages/stats/package.json index 36e1ad621e..6daaff098d 100755 --- a/packages/stats/package.json +++ b/packages/stats/package.json @@ -1,6 +1,6 @@ { "name": "@oasis-engine/stats", - "version": "0.5.3", + "version": "0.5.4", "license": "MIT", "scripts": { "b:types": "tsc" @@ -14,6 +14,6 @@ "types/**/*" ], "dependencies": { - "oasis-engine": "0.5.3" + "oasis-engine": "0.5.4" } } From d9ef75d8a0345898a819e445971ffae3a670d05d Mon Sep 17 00:00:00 2001 From: GuoLei1990 Date: Tue, 12 Oct 2021 18:17:18 +0800 Subject: [PATCH 16/41] v0.5.5 --- lerna.json | 2 +- packages/controls/package.json | 4 ++-- packages/core/package.json | 6 +++--- packages/design/package.json | 2 +- packages/draco/package.json | 4 ++-- packages/framebuffer-picker/package.json | 4 ++-- packages/loader/package.json | 10 +++++----- packages/math/package.json | 4 ++-- packages/oasis-engine/package.json | 10 +++++----- packages/rhi-webgl/package.json | 2 +- packages/stats/package.json | 4 ++-- 11 files changed, 26 insertions(+), 26 deletions(-) diff --git a/lerna.json b/lerna.json index 8c00ad3176..9d456ea73b 100644 --- a/lerna.json +++ b/lerna.json @@ -1,6 +1,6 @@ { "npmClient": "npm", - "version": "0.5.4", + "version": "0.5.5", "bootstrap": { "hoist": true }, diff --git a/packages/controls/package.json b/packages/controls/package.json index cadc850b89..776a5b449c 100644 --- a/packages/controls/package.json +++ b/packages/controls/package.json @@ -1,6 +1,6 @@ { "name": "@oasis-engine/controls", - "version": "0.5.4", + "version": "0.5.5", "license": "MIT", "scripts": { "b:types": "tsc", @@ -15,6 +15,6 @@ "types/**/*" ], "dependencies": { - "oasis-engine": "0.5.4" + "oasis-engine": "0.5.5" } } diff --git a/packages/core/package.json b/packages/core/package.json index 53a4fdede5..a6905936d7 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -1,6 +1,6 @@ { "name": "@oasis-engine/core", - "version": "0.5.4", + "version": "0.5.5", "license": "MIT", "main": "dist/main.js", "module": "dist/module.js", @@ -14,9 +14,9 @@ "types/**/*" ], "dependencies": { - "@oasis-engine/math": "0.5.4" + "@oasis-engine/math": "0.5.5" }, "devDependencies": { - "@oasis-engine/design": "0.5.4" + "@oasis-engine/design": "0.5.5" } } diff --git a/packages/design/package.json b/packages/design/package.json index 2a1c1e436b..18dcc935eb 100755 --- a/packages/design/package.json +++ b/packages/design/package.json @@ -1,6 +1,6 @@ { "name": "@oasis-engine/design", - "version": "0.5.4", + "version": "0.5.5", "license": "MIT", "main": "dist/main.js", "module": "dist/module.js", diff --git a/packages/draco/package.json b/packages/draco/package.json index 446b3cc97a..e11b12c6e0 100644 --- a/packages/draco/package.json +++ b/packages/draco/package.json @@ -1,6 +1,6 @@ { "name": "@oasis-engine/draco", - "version": "0.5.4", + "version": "0.5.5", "license": "MIT", "scripts": { "b:types": "tsc" @@ -13,6 +13,6 @@ "types/**/*" ], "dependencies": { - "@oasis-engine/core": "0.5.4" + "@oasis-engine/core": "0.5.5" } } diff --git a/packages/framebuffer-picker/package.json b/packages/framebuffer-picker/package.json index 0cb175f787..d2b5b7a683 100755 --- a/packages/framebuffer-picker/package.json +++ b/packages/framebuffer-picker/package.json @@ -1,6 +1,6 @@ { "name": "@oasis-engine/framebuffer-picker", - "version": "0.5.4", + "version": "0.5.5", "license": "MIT", "main": "dist/main.js", "module": "dist/module.js", @@ -14,6 +14,6 @@ "types/**/*" ], "dependencies": { - "oasis-engine": "0.5.4" + "oasis-engine": "0.5.5" } } diff --git a/packages/loader/package.json b/packages/loader/package.json index 4f81bb5491..3345409a19 100755 --- a/packages/loader/package.json +++ b/packages/loader/package.json @@ -1,6 +1,6 @@ { "name": "@oasis-engine/loader", - "version": "0.5.4", + "version": "0.5.5", "license": "MIT", "types": "types/index.d.ts", "scripts": { @@ -14,9 +14,9 @@ "types/**/*" ], "dependencies": { - "@oasis-engine/core": "0.5.4", - "@oasis-engine/draco": "0.5.4", - "@oasis-engine/math": "0.5.4", - "@oasis-engine/rhi-webgl": "0.5.3" + "@oasis-engine/core": "0.5.5", + "@oasis-engine/draco": "0.5.5", + "@oasis-engine/math": "0.5.5", + "@oasis-engine/rhi-webgl": "0.5.5" } } diff --git a/packages/math/package.json b/packages/math/package.json index ad647527be..ae60e6f883 100755 --- a/packages/math/package.json +++ b/packages/math/package.json @@ -1,6 +1,6 @@ { "name": "@oasis-engine/math", - "version": "0.5.4", + "version": "0.5.5", "license": "MIT", "main": "dist/main.js", "module": "dist/module.js", @@ -14,6 +14,6 @@ "types/**/*" ], "devDependencies": { - "@oasis-engine/design": "0.5.4" + "@oasis-engine/design": "0.5.5" } } diff --git a/packages/oasis-engine/package.json b/packages/oasis-engine/package.json index fb13adb91a..15278bedca 100755 --- a/packages/oasis-engine/package.json +++ b/packages/oasis-engine/package.json @@ -1,6 +1,6 @@ { "name": "oasis-engine", - "version": "0.5.4", + "version": "0.5.5", "license": "MIT", "scripts": { "b:types": "tsc" @@ -14,9 +14,9 @@ "types/**/*" ], "dependencies": { - "@oasis-engine/core": "0.5.4", - "@oasis-engine/loader": "0.5.4", - "@oasis-engine/math": "0.5.4", - "@oasis-engine/rhi-webgl": "0.5.3" + "@oasis-engine/core": "0.5.5", + "@oasis-engine/loader": "0.5.5", + "@oasis-engine/math": "0.5.5", + "@oasis-engine/rhi-webgl": "0.5.5" } } diff --git a/packages/rhi-webgl/package.json b/packages/rhi-webgl/package.json index aaaa41ceb2..30bcfaa35a 100755 --- a/packages/rhi-webgl/package.json +++ b/packages/rhi-webgl/package.json @@ -1,6 +1,6 @@ { "name": "@oasis-engine/rhi-webgl", - "version": "0.5.3", + "version": "0.5.5", "license": "MIT", "main": "dist/main.js", "module": "dist/module.js", diff --git a/packages/stats/package.json b/packages/stats/package.json index 6daaff098d..66744e2dcf 100755 --- a/packages/stats/package.json +++ b/packages/stats/package.json @@ -1,6 +1,6 @@ { "name": "@oasis-engine/stats", - "version": "0.5.4", + "version": "0.5.5", "license": "MIT", "scripts": { "b:types": "tsc" @@ -14,6 +14,6 @@ "types/**/*" ], "dependencies": { - "oasis-engine": "0.5.4" + "oasis-engine": "0.5.5" } } From e8cc0e144869877caacfb33308536d2e31dee100 Mon Sep 17 00:00:00 2001 From: GuoLei1990 Date: Tue, 12 Oct 2021 19:32:19 +0800 Subject: [PATCH 17/41] v0.5.6 --- lerna.json | 2 +- packages/controls/package.json | 4 ++-- packages/core/package.json | 6 +++--- packages/design/package.json | 2 +- packages/draco/package.json | 4 ++-- packages/framebuffer-picker/package.json | 4 ++-- packages/loader/package.json | 10 +++++----- packages/math/package.json | 4 ++-- packages/oasis-engine/package.json | 10 +++++----- packages/rhi-webgl/package.json | 8 ++++---- packages/stats/package.json | 4 ++-- 11 files changed, 29 insertions(+), 29 deletions(-) diff --git a/lerna.json b/lerna.json index 9d456ea73b..d1c9dc65ca 100644 --- a/lerna.json +++ b/lerna.json @@ -1,6 +1,6 @@ { "npmClient": "npm", - "version": "0.5.5", + "version": "0.5.6", "bootstrap": { "hoist": true }, diff --git a/packages/controls/package.json b/packages/controls/package.json index 776a5b449c..8c269721f5 100644 --- a/packages/controls/package.json +++ b/packages/controls/package.json @@ -1,6 +1,6 @@ { "name": "@oasis-engine/controls", - "version": "0.5.5", + "version": "0.5.6", "license": "MIT", "scripts": { "b:types": "tsc", @@ -15,6 +15,6 @@ "types/**/*" ], "dependencies": { - "oasis-engine": "0.5.5" + "oasis-engine": "0.5.6" } } diff --git a/packages/core/package.json b/packages/core/package.json index a6905936d7..49606a4385 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -1,6 +1,6 @@ { "name": "@oasis-engine/core", - "version": "0.5.5", + "version": "0.5.6", "license": "MIT", "main": "dist/main.js", "module": "dist/module.js", @@ -14,9 +14,9 @@ "types/**/*" ], "dependencies": { - "@oasis-engine/math": "0.5.5" + "@oasis-engine/math": "0.5.6" }, "devDependencies": { - "@oasis-engine/design": "0.5.5" + "@oasis-engine/design": "0.5.6" } } diff --git a/packages/design/package.json b/packages/design/package.json index 18dcc935eb..f67d5f8ef2 100755 --- a/packages/design/package.json +++ b/packages/design/package.json @@ -1,6 +1,6 @@ { "name": "@oasis-engine/design", - "version": "0.5.5", + "version": "0.5.6", "license": "MIT", "main": "dist/main.js", "module": "dist/module.js", diff --git a/packages/draco/package.json b/packages/draco/package.json index e11b12c6e0..36b7eb1db6 100644 --- a/packages/draco/package.json +++ b/packages/draco/package.json @@ -1,6 +1,6 @@ { "name": "@oasis-engine/draco", - "version": "0.5.5", + "version": "0.5.6", "license": "MIT", "scripts": { "b:types": "tsc" @@ -13,6 +13,6 @@ "types/**/*" ], "dependencies": { - "@oasis-engine/core": "0.5.5" + "@oasis-engine/core": "0.5.6" } } diff --git a/packages/framebuffer-picker/package.json b/packages/framebuffer-picker/package.json index d2b5b7a683..554f0269ff 100755 --- a/packages/framebuffer-picker/package.json +++ b/packages/framebuffer-picker/package.json @@ -1,6 +1,6 @@ { "name": "@oasis-engine/framebuffer-picker", - "version": "0.5.5", + "version": "0.5.6", "license": "MIT", "main": "dist/main.js", "module": "dist/module.js", @@ -14,6 +14,6 @@ "types/**/*" ], "dependencies": { - "oasis-engine": "0.5.5" + "oasis-engine": "0.5.6" } } diff --git a/packages/loader/package.json b/packages/loader/package.json index 3345409a19..24f791c757 100755 --- a/packages/loader/package.json +++ b/packages/loader/package.json @@ -1,6 +1,6 @@ { "name": "@oasis-engine/loader", - "version": "0.5.5", + "version": "0.5.6", "license": "MIT", "types": "types/index.d.ts", "scripts": { @@ -14,9 +14,9 @@ "types/**/*" ], "dependencies": { - "@oasis-engine/core": "0.5.5", - "@oasis-engine/draco": "0.5.5", - "@oasis-engine/math": "0.5.5", - "@oasis-engine/rhi-webgl": "0.5.5" + "@oasis-engine/core": "0.5.6", + "@oasis-engine/draco": "0.5.6", + "@oasis-engine/math": "0.5.6", + "@oasis-engine/rhi-webgl": "0.5.6" } } diff --git a/packages/math/package.json b/packages/math/package.json index ae60e6f883..87c4377f21 100755 --- a/packages/math/package.json +++ b/packages/math/package.json @@ -1,6 +1,6 @@ { "name": "@oasis-engine/math", - "version": "0.5.5", + "version": "0.5.6", "license": "MIT", "main": "dist/main.js", "module": "dist/module.js", @@ -14,6 +14,6 @@ "types/**/*" ], "devDependencies": { - "@oasis-engine/design": "0.5.5" + "@oasis-engine/design": "0.5.6" } } diff --git a/packages/oasis-engine/package.json b/packages/oasis-engine/package.json index 15278bedca..46ad52ace7 100755 --- a/packages/oasis-engine/package.json +++ b/packages/oasis-engine/package.json @@ -1,6 +1,6 @@ { "name": "oasis-engine", - "version": "0.5.5", + "version": "0.5.6", "license": "MIT", "scripts": { "b:types": "tsc" @@ -14,9 +14,9 @@ "types/**/*" ], "dependencies": { - "@oasis-engine/core": "0.5.5", - "@oasis-engine/loader": "0.5.5", - "@oasis-engine/math": "0.5.5", - "@oasis-engine/rhi-webgl": "0.5.5" + "@oasis-engine/core": "0.5.6", + "@oasis-engine/loader": "0.5.6", + "@oasis-engine/math": "0.5.6", + "@oasis-engine/rhi-webgl": "0.5.6" } } diff --git a/packages/rhi-webgl/package.json b/packages/rhi-webgl/package.json index 30bcfaa35a..70033d6d00 100755 --- a/packages/rhi-webgl/package.json +++ b/packages/rhi-webgl/package.json @@ -1,6 +1,6 @@ { "name": "@oasis-engine/rhi-webgl", - "version": "0.5.5", + "version": "0.5.6", "license": "MIT", "main": "dist/main.js", "module": "dist/module.js", @@ -14,10 +14,10 @@ "types/**/*" ], "dependencies": { - "@oasis-engine/core": "0.5.3", - "@oasis-engine/math": "0.5.3" + "@oasis-engine/core": "0.5.6", + "@oasis-engine/math": "0.5.6" }, "devDependencies": { - "@oasis-engine/design": "0.5.3" + "@oasis-engine/design": "0.5.6" } } diff --git a/packages/stats/package.json b/packages/stats/package.json index 66744e2dcf..fbbede135d 100755 --- a/packages/stats/package.json +++ b/packages/stats/package.json @@ -1,6 +1,6 @@ { "name": "@oasis-engine/stats", - "version": "0.5.5", + "version": "0.5.6", "license": "MIT", "scripts": { "b:types": "tsc" @@ -14,6 +14,6 @@ "types/**/*" ], "dependencies": { - "oasis-engine": "0.5.5" + "oasis-engine": "0.5.6" } } From 3b4a242b3807252bb3789f8943733bb7f61b7659 Mon Sep 17 00:00:00 2001 From: singlecoder Date: Fri, 15 Oct 2021 17:37:28 +0800 Subject: [PATCH 18/41] fix(2d): opt shader precision (#542) --- packages/core/src/shaderlib/extra/sprite-mask.fs.glsl | 3 --- packages/core/src/shaderlib/extra/sprite-mask.vs.glsl | 2 -- packages/core/src/shaderlib/extra/sprite.fs.glsl | 3 --- packages/core/src/shaderlib/extra/sprite.vs.glsl | 2 -- 4 files changed, 10 deletions(-) diff --git a/packages/core/src/shaderlib/extra/sprite-mask.fs.glsl b/packages/core/src/shaderlib/extra/sprite-mask.fs.glsl index da06791c01..ec0a5e1419 100644 --- a/packages/core/src/shaderlib/extra/sprite-mask.fs.glsl +++ b/packages/core/src/shaderlib/extra/sprite-mask.fs.glsl @@ -1,6 +1,3 @@ -precision mediump float; -precision mediump int; - uniform sampler2D u_maskTexture; uniform float u_maskAlphaCutoff; varying vec2 v_uv; diff --git a/packages/core/src/shaderlib/extra/sprite-mask.vs.glsl b/packages/core/src/shaderlib/extra/sprite-mask.vs.glsl index 2e25725a93..3906cf5103 100644 --- a/packages/core/src/shaderlib/extra/sprite-mask.vs.glsl +++ b/packages/core/src/shaderlib/extra/sprite-mask.vs.glsl @@ -1,5 +1,3 @@ -precision highp float; - uniform mat4 u_VPMat; attribute vec3 POSITION; diff --git a/packages/core/src/shaderlib/extra/sprite.fs.glsl b/packages/core/src/shaderlib/extra/sprite.fs.glsl index f0fdefe57a..6d51f589ec 100644 --- a/packages/core/src/shaderlib/extra/sprite.fs.glsl +++ b/packages/core/src/shaderlib/extra/sprite.fs.glsl @@ -1,6 +1,3 @@ -precision mediump float; -precision mediump int; - #ifdef USE_CUSTOM_TEXTURE uniform sampler2D u_cusTomTexture; #else diff --git a/packages/core/src/shaderlib/extra/sprite.vs.glsl b/packages/core/src/shaderlib/extra/sprite.vs.glsl index 1782533aa3..80ac803b41 100644 --- a/packages/core/src/shaderlib/extra/sprite.vs.glsl +++ b/packages/core/src/shaderlib/extra/sprite.vs.glsl @@ -1,5 +1,3 @@ -precision highp float; - #ifdef USE_MODEL_MATRIX uniform mat4 u_MVPMat; #else From e36cb48b6462f16a65b7861e05726aab24214b0c Mon Sep 17 00:00:00 2001 From: zhuxudong Date: Mon, 25 Oct 2021 12:34:48 +0800 Subject: [PATCH 19/41] fix: delete default gl state (#550) Co-authored-by: shensi.zxd --- packages/rhi-webgl/src/WebGLRenderer.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/rhi-webgl/src/WebGLRenderer.ts b/packages/rhi-webgl/src/WebGLRenderer.ts index 03c4f21ea0..d674b29c2c 100644 --- a/packages/rhi-webgl/src/WebGLRenderer.ts +++ b/packages/rhi-webgl/src/WebGLRenderer.ts @@ -72,8 +72,8 @@ export class WebGLRenderer implements IHardwareRenderer { private _activeTextures: GLTexture[] = new Array(32); // cache value - private _lastViewport: Vector4 = new Vector4(undefined, undefined, undefined, undefined); - private _lastClearColor: Color = new Color(undefined, undefined, undefined, undefined); + private _lastViewport: Vector4 = new Vector4(null, null, null, null); + private _lastClearColor: Color = new Color(null, null, null, null); get isWebGL2() { return this._isWebGL2; From afb4771759e2076069a0dd007e7737c07a3e9d4a Mon Sep 17 00:00:00 2001 From: luzhuang <364439895@qq.com> Date: Mon, 25 Oct 2021 16:09:36 +0800 Subject: [PATCH 20/41] feat: stash --- packages/core/src/animation/Animator.ts | 30 ++++++++++++++++++- packages/core/src/animation/AnimatorState.ts | 14 +++++++++ .../animation/internal/AnimatorStateData.ts | 5 ++++ 3 files changed, 48 insertions(+), 1 deletion(-) diff --git a/packages/core/src/animation/Animator.ts b/packages/core/src/animation/Animator.ts index 442ad0c48c..892f483d1d 100644 --- a/packages/core/src/animation/Animator.ts +++ b/packages/core/src/animation/Animator.ts @@ -1,3 +1,4 @@ +import { StateMachineScript } from './StateMachineScript'; import { Quaternion, Vector3 } from "@oasis-engine/math"; import { assignmentClone, ignoreClone } from "../clone/CloneManager"; import { Component } from "../Component"; @@ -224,6 +225,7 @@ export class Animator extends Component { animatorStateDataCollection[stateName] = animatorStateData; this._saveAnimatorStateData(animatorState, animatorStateData); this._saveAnimatorEventHandlers(animatorState, animatorStateData); + this._saveAnimatorStateScripts(animatorState, animatorStateData); } return animatorStateData; } @@ -269,6 +271,31 @@ export class Animator extends Component { } } + private _saveAnimatorStateScripts(state: AnimatorState, animatorStateData: AnimatorStateData): void { + const { _scripts: scripts } = state; + const {prototype} = StateMachineScript + const { onStartScripts, onStateEnterScripts, onStateUpdateScripts, onStateExitScripts } = animatorStateData; + onStartScripts.length = 0; + onStateEnterScripts.length = 0; + onStateUpdateScripts.length = 0; + onStateExitScripts.length = 0; + for (let i = 0, n = scripts.length; i < n; i++) { + const script = scripts[i]; + if (script.onStart !== prototype.onStart) { + onStartScripts.push(script) + } + if (script.onStateEnter !== prototype.onStateEnter) { + onStateEnterScripts.push(script) + } + if (script.onStateUpdate !== prototype.onStateUpdate) { + onStateUpdateScripts.push(script) + } + if (script.onStateExit !== prototype.onStateExit) { + onStateEnterScripts.push(script) + } + } + } + private _clearCrossData(animatorLayerData: AnimatorLayerData): void { animatorLayerData.crossCurveMark++; this._crossCurveDataCollection.length = 0; @@ -419,7 +446,7 @@ export class Animator extends Component { delta: number, additive: boolean ): void { - const { curveOwners, eventHandlers } = playData.stateData; + const { curveOwners, eventHandlers, onStartScripts } = playData.stateData; const { state } = playData; const { _curveBindings: curves } = state.clip; const lastClipTime = playData.clipTime; @@ -429,6 +456,7 @@ export class Animator extends Component { const clipTime = playData.clipTime; eventHandlers.length && this._fireAnimationEvents(playData, eventHandlers, lastClipTime, clipTime); + // this._callScriptOnStart(); for (let i = curves.length - 1; i >= 0; i--) { const owner = curveOwners[i]; diff --git a/packages/core/src/animation/AnimatorState.ts b/packages/core/src/animation/AnimatorState.ts index eeca1cafb7..653b0bcda8 100644 --- a/packages/core/src/animation/AnimatorState.ts +++ b/packages/core/src/animation/AnimatorState.ts @@ -1,3 +1,4 @@ +import { StateMachineScript } from './StateMachineScript'; import { AnimationClip } from "./AnimationClip"; import { AnimatorStateTransition } from "./AnimatorTransition"; import { WrapMode } from "./enums/WrapMode"; @@ -11,6 +12,8 @@ export class AnimatorState { /** The wrap mode used in the state. */ wrapMode: WrapMode = WrapMode.Loop; + _scripts: StateMachineScript[] = []; + private _clipStartTime: number = 0; private _clipEndTime: number = Infinity; private _clip: AnimationClip; @@ -82,6 +85,17 @@ export class AnimatorState { index !== -1 && this._transitions.splice(index, 1); } + addStateMachineScript(type: new () => T): T { + const script = new type(); + this._scripts.push(script); + return script; + } + + removeStateMachineScript(stateMachineScript: StateMachineScript) { + const index = this._scripts.indexOf(stateMachineScript); + index !== -1 && this._scripts.splice(index, 1); + } + /** * Clears all transitions from the state. */ diff --git a/packages/core/src/animation/internal/AnimatorStateData.ts b/packages/core/src/animation/internal/AnimatorStateData.ts index bdcff9ff70..4522921492 100644 --- a/packages/core/src/animation/internal/AnimatorStateData.ts +++ b/packages/core/src/animation/internal/AnimatorStateData.ts @@ -1,3 +1,4 @@ +import { StateMachineScript } from '../StateMachineScript'; import { AnimationEventHandler } from "./AnimationEventHandler"; import { AnimationCurveOwner } from "./AnimationCurveOwner"; @@ -7,4 +8,8 @@ import { AnimationCurveOwner } from "./AnimationCurveOwner"; export class AnimatorStateData { curveOwners: AnimationCurveOwner[] = []; eventHandlers: AnimationEventHandler[] = []; + onStartScripts: StateMachineScript[] = []; + onStateEnterScripts: StateMachineScript[] = []; + onStateUpdateScripts: StateMachineScript[] = []; + onStateExitScripts: StateMachineScript[] = []; } From ea0914f9c0760ae13ef1885bc67d040e0f747acb Mon Sep 17 00:00:00 2001 From: luzhuang <364439895@qq.com> Date: Mon, 25 Oct 2021 16:09:45 +0800 Subject: [PATCH 21/41] feat: stash --- .../core/src/animation/StateMachineScript.ts | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 packages/core/src/animation/StateMachineScript.ts diff --git a/packages/core/src/animation/StateMachineScript.ts b/packages/core/src/animation/StateMachineScript.ts new file mode 100644 index 0000000000..cf66269d66 --- /dev/null +++ b/packages/core/src/animation/StateMachineScript.ts @@ -0,0 +1,19 @@ +import { AnimatorState } from '../animation/AnimatorState'; +import { Animator } from "../animation/Animator"; +/** + * Script class, used for logic writing. + */ +export class StateMachineScript { + constructor(animatorState: AnimatorState) { + } + // Start is called before the first frame update + onStart() {} + // onStateEnter is called when a transition starts and the state machine starts to evaluate this state + onStateEnter(animator: Animator, stateInfo: any, layerIndex: number) {} + + // onStateUpdate is called on each Update frame between onStateEnter and onStateExit callbacks + onStateUpdate(animator: Animator, stateInfo: any, layerIndex: number) {} + + // onStateExit is called when a transition ends and the state machine finishes evaluating this state + onStateExit(animator: Animator, stateInfo: any, layerIndex: number) {} +} From 82efab74158f8a8743ffb6e56d7627f4edbe5423 Mon Sep 17 00:00:00 2001 From: luzhuang <364439895@qq.com> Date: Mon, 25 Oct 2021 19:56:55 +0800 Subject: [PATCH 22/41] feat: add animatorStateScript --- packages/core/src/animation/Animator.ts | 96 +++++++++++++++---- .../core/src/animation/StateMachineScript.ts | 5 - packages/core/src/animation/index.ts | 1 + .../animation/internal/AnimatorStateData.ts | 1 - .../internal/AnimatorStatePlayData.ts | 3 + 5 files changed, 82 insertions(+), 24 deletions(-) diff --git a/packages/core/src/animation/Animator.ts b/packages/core/src/animation/Animator.ts index cd01d7dc2b..8d6506cba3 100644 --- a/packages/core/src/animation/Animator.ts +++ b/packages/core/src/animation/Animator.ts @@ -1,4 +1,3 @@ -import { StateMachineScript } from './StateMachineScript'; import { Quaternion, Vector3 } from "@oasis-engine/math"; import { assignmentClone, ignoreClone } from "../clone/CloneManager"; import { Component } from "../Component"; @@ -12,6 +11,7 @@ import { AnimatorController } from "./AnimatorController"; import { AnimatorState } from "./AnimatorState"; import { AnimatorStateTransition } from "./AnimatorTransition"; import { AnimatorUtils } from "./AnimatorUtils"; +import { StateMachineScript } from "./StateMachineScript"; import { AnimationProperty } from "./enums/AnimationProperty"; import { AnimatorLayerBlendingMode } from "./enums/AnimatorLayerBlendingMode"; import { LayerState } from "./enums/LayerState"; @@ -276,25 +276,21 @@ export class Animator extends Component { private _saveAnimatorStateScripts(state: AnimatorState, animatorStateData: AnimatorStateData): void { const { _scripts: scripts } = state; - const {prototype} = StateMachineScript - const { onStartScripts, onStateEnterScripts, onStateUpdateScripts, onStateExitScripts } = animatorStateData; - onStartScripts.length = 0; + const { prototype } = StateMachineScript; + const { onStateEnterScripts, onStateUpdateScripts, onStateExitScripts } = animatorStateData; onStateEnterScripts.length = 0; onStateUpdateScripts.length = 0; onStateExitScripts.length = 0; for (let i = 0, n = scripts.length; i < n; i++) { const script = scripts[i]; - if (script.onStart !== prototype.onStart) { - onStartScripts.push(script) - } if (script.onStateEnter !== prototype.onStateEnter) { - onStateEnterScripts.push(script) + onStateEnterScripts.push(script); } if (script.onStateUpdate !== prototype.onStateUpdate) { - onStateUpdateScripts.push(script) + onStateUpdateScripts.push(script); } if (script.onStateExit !== prototype.onStateExit) { - onStateEnterScripts.push(script) + onStateExitScripts.push(script); } } } @@ -433,13 +429,21 @@ export class Animator extends Component { this._checkTransition(srcPlayData, crossFadeTransitionInfo, layerIndex); switch (animLayerData.layerState) { case LayerState.Playing: - this._updatePlayingState(srcPlayData, animLayerData, layerWeight, deltaTime, layerAdditive); + this._updatePlayingState(srcPlayData, animLayerData, layerIndex, layerWeight, deltaTime, layerAdditive); break; case LayerState.FixedCrossFading: - this._updateCrossFadeFromPose(destPlayData, animLayerData, layerWeight, deltaTime, layerAdditive); + this._updateCrossFadeFromPose(destPlayData, animLayerData, layerIndex, layerWeight, deltaTime, layerAdditive); break; case LayerState.CrossFading: - this._updateCrossFade(srcPlayData, destPlayData, animLayerData, layerWeight, deltaTime, layerAdditive); + this._updateCrossFade( + srcPlayData, + destPlayData, + animLayerData, + layerIndex, + layerWeight, + deltaTime, + layerAdditive + ); break; } } @@ -447,21 +451,24 @@ export class Animator extends Component { private _updatePlayingState( playData: AnimatorStatePlayData, layerData: AnimatorLayerData, + layerIndex: number, weight: number, delta: number, additive: boolean ): void { - const { curveOwners, eventHandlers, onStartScripts } = playData.stateData; - const { state } = playData; + const { curveOwners, eventHandlers } = playData.stateData; + const { state, stateData } = playData; const { _curveBindings: curves } = state.clip; const lastClipTime = playData.clipTime; + const hasTriggeredEnter = playData.started; playData.update(); const clipTime = playData.clipTime; eventHandlers.length && this._fireAnimationEvents(playData, eventHandlers, lastClipTime, clipTime); - // this._callScriptOnStart(); + !hasTriggeredEnter && this._callAnimatorScriptOnEnter(state, stateData, layerIndex); + this._callAnimatorScriptOnUpdate(state, stateData, layerIndex); for (let i = curves.length - 1; i >= 0; i--) { const owner = curveOwners[i]; @@ -476,6 +483,7 @@ export class Animator extends Component { if (playData.finished) { layerData.layerState = LayerState.Standby; + this._callAnimatorScriptOnExit(state, stateData, layerIndex); } } @@ -483,14 +491,22 @@ export class Animator extends Component { srcPlayData: AnimatorStatePlayData, destPlayData: AnimatorStatePlayData, layerData: AnimatorLayerData, + layerIndex, weight: number, delta: number, additive: boolean ) { const crossCurveDataCollection = this._crossCurveDataCollection; const srcCurves = srcPlayData.state.clip._curveBindings; - const { state: destState } = destPlayData; + const { state: srcState, stateData: srcStateData } = srcPlayData; + const { eventHandlers: srcEventHandler } = srcStateData; + const { state: destState, stateData: destStateData } = destPlayData; + const { eventHandlers: destEventHandler } = destStateData; const destCurves = destState.clip._curveBindings; + const lastSrcClipTime = srcPlayData.clipTime; + const lastDestClipTime = destPlayData.clipTime; + const hasTriggeredSrcEnter = srcPlayData.started; + const hasTriggeredDestEnter = destPlayData.started; let crossWeight = destPlayData.frameTime / (destState._getDuration() * layerData.crossFadeTransition.duration); crossWeight >= 1.0 && (crossWeight = 1.0); @@ -499,6 +515,15 @@ export class Animator extends Component { const srcClipTime = srcPlayData.clipTime; const destClipTime = destPlayData.clipTime; + + srcEventHandler.length && this._fireAnimationEvents(srcPlayData, srcEventHandler, lastSrcClipTime, srcClipTime); + destEventHandler.length && + this._fireAnimationEvents(destPlayData, destEventHandler, lastDestClipTime, destClipTime); + !hasTriggeredSrcEnter && this._callAnimatorScriptOnEnter(srcState, srcStateData, layerIndex); + this._callAnimatorScriptOnUpdate(srcState, srcStateData, layerIndex); + !hasTriggeredDestEnter && this._callAnimatorScriptOnEnter(destState, destStateData, layerIndex); + this._callAnimatorScriptOnUpdate(destState, destStateData, layerIndex); + for (let i = crossCurveDataCollection.length - 1; i >= 0; i--) { const { curveOwner, srcCurveIndex, destCurveIndex } = crossCurveDataCollection[i]; const { property, defaultValue } = curveOwner; @@ -515,25 +540,37 @@ export class Animator extends Component { this._applyCrossClipValue(curveOwner, srcValue, destValue, crossWeight, weight, additive); } + (crossWeight === 1 || srcPlayData.finished) && this._callAnimatorScriptOnExit(srcState, srcStateData, layerIndex); + destPlayData.finished && this._callAnimatorScriptOnExit(destState, destStateData, layerIndex); + this._updateCrossFadeData(layerData, crossWeight, delta, false); } private _updateCrossFadeFromPose( destPlayData: AnimatorStatePlayData, layerData: AnimatorLayerData, + layerIndex: number, weight: number, delta: number, additive: boolean ) { const crossCurveDataCollection = this._crossCurveDataCollection; - const { state: destState } = destPlayData; + const { state: destState, stateData } = destPlayData; + const { eventHandlers } = stateData; const curves = destState.clip._curveBindings; + const lastDestClipTime = destPlayData.clipTime; + const hasTriggeredEnter = destPlayData.started; let crossWeight = destPlayData.frameTime / (destState._getDuration() * layerData.crossFadeTransition.duration); crossWeight >= 1.0 && (crossWeight = 1.0); destPlayData.update(); const destClipTime = destPlayData.clipTime; + + eventHandlers.length && this._fireAnimationEvents(destPlayData, eventHandlers, lastDestClipTime, destClipTime); + !hasTriggeredEnter && this._callAnimatorScriptOnEnter(destState, stateData, layerIndex); + this._callAnimatorScriptOnUpdate(destState, stateData, layerIndex); + for (let i = crossCurveDataCollection.length - 1; i >= 0; i--) { const { curveOwner, destCurveIndex } = crossCurveDataCollection[i]; const destValue = @@ -544,6 +581,8 @@ export class Animator extends Component { this._applyCrossClipValue(curveOwner, curveOwner.fixedPoseValue, destValue, crossWeight, weight, additive); } + destPlayData.finished && this._callAnimatorScriptOnExit(destState, stateData, layerIndex); + this._updateCrossFadeData(layerData, crossWeight, delta, true); } @@ -794,6 +833,27 @@ export class Animator extends Component { } } + private _callAnimatorScriptOnEnter(state: AnimatorState, stateData: AnimatorStateData, layerIndex: number) { + const scripts = stateData.onStateEnterScripts; + for (let i = 0, n = scripts.length; i < n; ++i) { + scripts[i].onStateEnter(this, state, layerIndex); + } + } + + private _callAnimatorScriptOnUpdate(state: AnimatorState, stateData: AnimatorStateData, layerIndex: number) { + const scripts = stateData.onStateUpdateScripts; + for (let i = 0, n = scripts.length; i < n; ++i) { + scripts[i].onStateUpdate(this, state, layerIndex); + } + } + + private _callAnimatorScriptOnExit(state: AnimatorState, stateData: AnimatorStateData, layerIndex: number) { + const scripts = stateData.onStateExitScripts; + for (let i = 0, n = scripts.length; i < n; ++i) { + scripts[i].onStateExit(this, state, layerIndex); + } + } + private _clearPlayData() { this._animatorLayersData.length = 0; this._crossCurveDataCollection.length = 0; diff --git a/packages/core/src/animation/StateMachineScript.ts b/packages/core/src/animation/StateMachineScript.ts index cf66269d66..b877959d3d 100644 --- a/packages/core/src/animation/StateMachineScript.ts +++ b/packages/core/src/animation/StateMachineScript.ts @@ -1,13 +1,8 @@ -import { AnimatorState } from '../animation/AnimatorState'; import { Animator } from "../animation/Animator"; /** * Script class, used for logic writing. */ export class StateMachineScript { - constructor(animatorState: AnimatorState) { - } - // Start is called before the first frame update - onStart() {} // onStateEnter is called when a transition starts and the state machine starts to evaluate this state onStateEnter(animator: Animator, stateInfo: any, layerIndex: number) {} diff --git a/packages/core/src/animation/index.ts b/packages/core/src/animation/index.ts index 01b734afcb..63686f0a4b 100644 --- a/packages/core/src/animation/index.ts +++ b/packages/core/src/animation/index.ts @@ -9,6 +9,7 @@ export { AnimationCurve } from "./AnimationCurve"; export { AnimationClipCurveBinding } from "./AnimationClipCurveBinding"; export * from "./KeyFrame"; export { AnimationEvent } from "./AnimationEvent"; +export { StateMachineScript } from "./StateMachineScript"; export { AnimatorConditionMode } from "./enums/AnimatorConditionMode"; export { InterpolableValueType } from "./enums/InterpolableValueType"; export { InterpolationType } from "./enums/InterpolationType"; diff --git a/packages/core/src/animation/internal/AnimatorStateData.ts b/packages/core/src/animation/internal/AnimatorStateData.ts index 4522921492..7eeb999dd2 100644 --- a/packages/core/src/animation/internal/AnimatorStateData.ts +++ b/packages/core/src/animation/internal/AnimatorStateData.ts @@ -8,7 +8,6 @@ import { AnimationCurveOwner } from "./AnimationCurveOwner"; export class AnimatorStateData { curveOwners: AnimationCurveOwner[] = []; eventHandlers: AnimationEventHandler[] = []; - onStartScripts: StateMachineScript[] = []; onStateEnterScripts: StateMachineScript[] = []; onStateUpdateScripts: StateMachineScript[] = []; onStateExitScripts: StateMachineScript[] = []; diff --git a/packages/core/src/animation/internal/AnimatorStatePlayData.ts b/packages/core/src/animation/internal/AnimatorStatePlayData.ts index f34b8cd1e3..bf83f8817f 100644 --- a/packages/core/src/animation/internal/AnimatorStatePlayData.ts +++ b/packages/core/src/animation/internal/AnimatorStatePlayData.ts @@ -9,6 +9,7 @@ export class AnimatorStatePlayData { state: AnimatorState; stateData: AnimatorStateData; frameTime: number; + started: boolean; finished: boolean; clipTime: number; currentEventIndex: number; @@ -26,12 +27,14 @@ export class AnimatorStatePlayData { const state = this.state; let time = this.frameTime; const duration = state.clipEndTime - state.clipStartTime; + this.started = true; if (time > duration) { if (state.wrapMode === WrapMode.Loop) { time = time % duration; } else { time = duration; this.finished = true; + this.started = false; } } this.clipTime = time + this.state.clipStartTime; From c6255aa43a7c29cba93f39d44016ff3f1c59a2c3 Mon Sep 17 00:00:00 2001 From: luzhuang <364439895@qq.com> Date: Tue, 26 Oct 2021 10:56:42 +0800 Subject: [PATCH 23/41] feat: add animatorStateScript --- lerna.json | 2 +- packages/controls/package.json | 4 ++-- packages/core/package.json | 6 +++--- packages/core/src/shaderlib/extra/sprite-mask.fs.glsl | 5 ++++- packages/core/src/shaderlib/extra/sprite-mask.vs.glsl | 4 +++- packages/core/src/shaderlib/extra/sprite.fs.glsl | 5 ++++- packages/core/src/shaderlib/extra/sprite.vs.glsl | 4 +++- packages/design/package.json | 2 +- packages/draco/package.json | 4 ++-- packages/framebuffer-picker/package.json | 4 ++-- packages/loader/package.json | 10 +++++----- packages/math/package.json | 4 ++-- packages/oasis-engine/package.json | 10 +++++----- packages/rhi-webgl/package.json | 8 ++++---- packages/stats/package.json | 4 ++-- 15 files changed, 43 insertions(+), 33 deletions(-) diff --git a/lerna.json b/lerna.json index d1c9dc65ca..6a22adfdc1 100644 --- a/lerna.json +++ b/lerna.json @@ -1,6 +1,6 @@ { "npmClient": "npm", - "version": "0.5.6", + "version": "0.5.2", "bootstrap": { "hoist": true }, diff --git a/packages/controls/package.json b/packages/controls/package.json index 8c269721f5..8ad4176110 100644 --- a/packages/controls/package.json +++ b/packages/controls/package.json @@ -1,6 +1,6 @@ { "name": "@oasis-engine/controls", - "version": "0.5.6", + "version": "0.5.2", "license": "MIT", "scripts": { "b:types": "tsc", @@ -15,6 +15,6 @@ "types/**/*" ], "dependencies": { - "oasis-engine": "0.5.6" + "oasis-engine": "0.5.2" } } diff --git a/packages/core/package.json b/packages/core/package.json index 49606a4385..bea83bb4d9 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -1,6 +1,6 @@ { "name": "@oasis-engine/core", - "version": "0.5.6", + "version": "0.5.2", "license": "MIT", "main": "dist/main.js", "module": "dist/module.js", @@ -14,9 +14,9 @@ "types/**/*" ], "dependencies": { - "@oasis-engine/math": "0.5.6" + "@oasis-engine/math": "0.5.2" }, "devDependencies": { - "@oasis-engine/design": "0.5.6" + "@oasis-engine/design": "0.5.2" } } diff --git a/packages/core/src/shaderlib/extra/sprite-mask.fs.glsl b/packages/core/src/shaderlib/extra/sprite-mask.fs.glsl index ec0a5e1419..c33dcc9623 100644 --- a/packages/core/src/shaderlib/extra/sprite-mask.fs.glsl +++ b/packages/core/src/shaderlib/extra/sprite-mask.fs.glsl @@ -1,3 +1,6 @@ +precision mediump float; +precision mediump int; + uniform sampler2D u_maskTexture; uniform float u_maskAlphaCutoff; varying vec2 v_uv; @@ -10,4 +13,4 @@ void main() } gl_FragColor = color; -} \ No newline at end of file +} diff --git a/packages/core/src/shaderlib/extra/sprite-mask.vs.glsl b/packages/core/src/shaderlib/extra/sprite-mask.vs.glsl index 3906cf5103..f33621e06d 100644 --- a/packages/core/src/shaderlib/extra/sprite-mask.vs.glsl +++ b/packages/core/src/shaderlib/extra/sprite-mask.vs.glsl @@ -1,3 +1,5 @@ +precision highp float; + uniform mat4 u_VPMat; attribute vec3 POSITION; @@ -9,4 +11,4 @@ void main() { gl_Position = u_VPMat * vec4(POSITION, 1.0); v_uv = TEXCOORD_0; -} \ No newline at end of file +} diff --git a/packages/core/src/shaderlib/extra/sprite.fs.glsl b/packages/core/src/shaderlib/extra/sprite.fs.glsl index 6d51f589ec..dc5fc8b566 100644 --- a/packages/core/src/shaderlib/extra/sprite.fs.glsl +++ b/packages/core/src/shaderlib/extra/sprite.fs.glsl @@ -1,3 +1,6 @@ +precision mediump float; +precision mediump int; + #ifdef USE_CUSTOM_TEXTURE uniform sampler2D u_cusTomTexture; #else @@ -16,4 +19,4 @@ void main() vec4 baseColor = texture2D(u_spriteTexture, v_uv); #endif gl_FragColor = baseColor * v_color; -} \ No newline at end of file +} diff --git a/packages/core/src/shaderlib/extra/sprite.vs.glsl b/packages/core/src/shaderlib/extra/sprite.vs.glsl index 80ac803b41..c0663583ff 100644 --- a/packages/core/src/shaderlib/extra/sprite.vs.glsl +++ b/packages/core/src/shaderlib/extra/sprite.vs.glsl @@ -1,3 +1,5 @@ +precision highp float; + #ifdef USE_MODEL_MATRIX uniform mat4 u_MVPMat; #else @@ -21,4 +23,4 @@ void main() v_uv = TEXCOORD_0; v_color = COLOR_0; -} \ No newline at end of file +} diff --git a/packages/design/package.json b/packages/design/package.json index a88ff0f9fe..6018bafd83 100755 --- a/packages/design/package.json +++ b/packages/design/package.json @@ -1,6 +1,6 @@ { "name": "@oasis-engine/design", - "version": "0.5.6", + "version": "0.5.2", "license": "MIT", "main": "dist/main.js", "module": "dist/module.js", diff --git a/packages/draco/package.json b/packages/draco/package.json index 36b7eb1db6..0c39bbd23f 100644 --- a/packages/draco/package.json +++ b/packages/draco/package.json @@ -1,6 +1,6 @@ { "name": "@oasis-engine/draco", - "version": "0.5.6", + "version": "0.5.2", "license": "MIT", "scripts": { "b:types": "tsc" @@ -13,6 +13,6 @@ "types/**/*" ], "dependencies": { - "@oasis-engine/core": "0.5.6" + "@oasis-engine/core": "0.5.2" } } diff --git a/packages/framebuffer-picker/package.json b/packages/framebuffer-picker/package.json index 554f0269ff..ac69c04fc1 100755 --- a/packages/framebuffer-picker/package.json +++ b/packages/framebuffer-picker/package.json @@ -1,6 +1,6 @@ { "name": "@oasis-engine/framebuffer-picker", - "version": "0.5.6", + "version": "0.5.2", "license": "MIT", "main": "dist/main.js", "module": "dist/module.js", @@ -14,6 +14,6 @@ "types/**/*" ], "dependencies": { - "oasis-engine": "0.5.6" + "oasis-engine": "0.5.2" } } diff --git a/packages/loader/package.json b/packages/loader/package.json index 24f791c757..4c720c6cfc 100755 --- a/packages/loader/package.json +++ b/packages/loader/package.json @@ -1,6 +1,6 @@ { "name": "@oasis-engine/loader", - "version": "0.5.6", + "version": "0.5.2", "license": "MIT", "types": "types/index.d.ts", "scripts": { @@ -14,9 +14,9 @@ "types/**/*" ], "dependencies": { - "@oasis-engine/core": "0.5.6", - "@oasis-engine/draco": "0.5.6", - "@oasis-engine/math": "0.5.6", - "@oasis-engine/rhi-webgl": "0.5.6" + "@oasis-engine/core": "0.5.2", + "@oasis-engine/draco": "0.5.2", + "@oasis-engine/math": "0.5.2", + "@oasis-engine/rhi-webgl": "0.5.2" } } diff --git a/packages/math/package.json b/packages/math/package.json index 87c4377f21..647f70a8a2 100755 --- a/packages/math/package.json +++ b/packages/math/package.json @@ -1,6 +1,6 @@ { "name": "@oasis-engine/math", - "version": "0.5.6", + "version": "0.5.2", "license": "MIT", "main": "dist/main.js", "module": "dist/module.js", @@ -14,6 +14,6 @@ "types/**/*" ], "devDependencies": { - "@oasis-engine/design": "0.5.6" + "@oasis-engine/design": "0.5.2" } } diff --git a/packages/oasis-engine/package.json b/packages/oasis-engine/package.json index 46ad52ace7..26e56ef0ed 100755 --- a/packages/oasis-engine/package.json +++ b/packages/oasis-engine/package.json @@ -1,6 +1,6 @@ { "name": "oasis-engine", - "version": "0.5.6", + "version": "0.5.2", "license": "MIT", "scripts": { "b:types": "tsc" @@ -14,9 +14,9 @@ "types/**/*" ], "dependencies": { - "@oasis-engine/core": "0.5.6", - "@oasis-engine/loader": "0.5.6", - "@oasis-engine/math": "0.5.6", - "@oasis-engine/rhi-webgl": "0.5.6" + "@oasis-engine/core": "0.5.2", + "@oasis-engine/loader": "0.5.2", + "@oasis-engine/math": "0.5.2", + "@oasis-engine/rhi-webgl": "0.5.2" } } diff --git a/packages/rhi-webgl/package.json b/packages/rhi-webgl/package.json index 70033d6d00..f21e178fe5 100755 --- a/packages/rhi-webgl/package.json +++ b/packages/rhi-webgl/package.json @@ -1,6 +1,6 @@ { "name": "@oasis-engine/rhi-webgl", - "version": "0.5.6", + "version": "0.5.2", "license": "MIT", "main": "dist/main.js", "module": "dist/module.js", @@ -14,10 +14,10 @@ "types/**/*" ], "dependencies": { - "@oasis-engine/core": "0.5.6", - "@oasis-engine/math": "0.5.6" + "@oasis-engine/core": "0.5.2", + "@oasis-engine/math": "0.5.2" }, "devDependencies": { - "@oasis-engine/design": "0.5.6" + "@oasis-engine/design": "0.5.2" } } diff --git a/packages/stats/package.json b/packages/stats/package.json index fbbede135d..8dcfdf2790 100755 --- a/packages/stats/package.json +++ b/packages/stats/package.json @@ -1,6 +1,6 @@ { "name": "@oasis-engine/stats", - "version": "0.5.6", + "version": "0.5.2", "license": "MIT", "scripts": { "b:types": "tsc" @@ -14,6 +14,6 @@ "types/**/*" ], "dependencies": { - "oasis-engine": "0.5.6" + "oasis-engine": "0.5.2" } } From 3bb4ee9da0fc5c33b4ee69c79c51d4f1ce4a62d4 Mon Sep 17 00:00:00 2001 From: luzhuang <364439895@qq.com> Date: Mon, 25 Oct 2021 19:56:55 +0800 Subject: [PATCH 24/41] feat: add animatorStateScript --- README.md | 12 ++- lerna.json | 2 +- packages/controls/package.json | 4 +- packages/core/package.json | 6 +- packages/core/src/animation/Animator.ts | 96 +++++++++++++++---- .../core/src/animation/StateMachineScript.ts | 5 - packages/core/src/animation/index.ts | 1 + .../animation/internal/AnimatorStateData.ts | 1 - .../internal/AnimatorStatePlayData.ts | 3 + packages/core/src/asset/ResourceManager.ts | 8 +- .../src/shaderlib/extra/sprite-mask.fs.glsl | 5 +- .../src/shaderlib/extra/sprite-mask.vs.glsl | 4 +- .../core/src/shaderlib/extra/sprite.fs.glsl | 5 +- .../core/src/shaderlib/extra/sprite.vs.glsl | 4 +- packages/design/package.json | 2 +- packages/draco/package.json | 4 +- packages/framebuffer-picker/package.json | 4 +- packages/loader/package.json | 10 +- packages/math/package.json | 7 +- packages/oasis-engine/package.json | 10 +- packages/rhi-webgl/package.json | 8 +- packages/rhi-webgl/src/WebGLRenderer.ts | 40 +++----- packages/stats/package.json | 4 +- 23 files changed, 147 insertions(+), 98 deletions(-) diff --git a/README.md b/README.md index 2302cc9974..9fb7108132 100644 --- a/README.md +++ b/README.md @@ -1,11 +1,13 @@ -# Ant Graphics Engine +# Oasis Engine (Ant Graphics Engine) + +

Oasis logo

![npm-size](https://img.shields.io/bundlephobia/minzip/oasis-engine) ![npm-download](https://img.shields.io/npm/dm/oasis-engine) [![codecov](https://codecov.io/gh/oasis-engine/engine/branch/main/graph/badge.svg?token=KR2UBKE3OX)](https://codecov.io/gh/oasis-engine/engine) -This is a **web-first** and **mobile-first** high-performance real-time development platform. Use **component system design** and pursue ease of use and light weight. Developers can independently use and write Typescript scripts to develop projects using pure code. +Oasis is a **web-first** and **mobile-first** high-performance real-time development platform. Use **component system design** and pursue ease of use and light weight. This repository is the core engine of Oasis. Developers can independently use and write Typescript scripts to develop projects using pure code. ## Features @@ -49,13 +51,13 @@ engine.run(); ## npm -The engine is published on npm with full typing support. To install, use: +Oasis Engine are published on npm with full typing support. To install, use: ```sh npm install oasis-engine ``` -This will allow you to import engine entirely using: +This will allow you to import Oasis Engine entirely using: ```javascript import * as OASIS from "oasis-engine"; @@ -96,4 +98,4 @@ npm run b:all ## License -The engine is released under the [MIT](https://opensource.org/licenses/MIT) license. See LICENSE file. +The Oasis Engine is released under the [MIT](https://opensource.org/licenses/MIT) license. See LICENSE file. diff --git a/lerna.json b/lerna.json index d1c9dc65ca..6a22adfdc1 100644 --- a/lerna.json +++ b/lerna.json @@ -1,6 +1,6 @@ { "npmClient": "npm", - "version": "0.5.6", + "version": "0.5.2", "bootstrap": { "hoist": true }, diff --git a/packages/controls/package.json b/packages/controls/package.json index 8c269721f5..8ad4176110 100644 --- a/packages/controls/package.json +++ b/packages/controls/package.json @@ -1,6 +1,6 @@ { "name": "@oasis-engine/controls", - "version": "0.5.6", + "version": "0.5.2", "license": "MIT", "scripts": { "b:types": "tsc", @@ -15,6 +15,6 @@ "types/**/*" ], "dependencies": { - "oasis-engine": "0.5.6" + "oasis-engine": "0.5.2" } } diff --git a/packages/core/package.json b/packages/core/package.json index 49606a4385..bea83bb4d9 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -1,6 +1,6 @@ { "name": "@oasis-engine/core", - "version": "0.5.6", + "version": "0.5.2", "license": "MIT", "main": "dist/main.js", "module": "dist/module.js", @@ -14,9 +14,9 @@ "types/**/*" ], "dependencies": { - "@oasis-engine/math": "0.5.6" + "@oasis-engine/math": "0.5.2" }, "devDependencies": { - "@oasis-engine/design": "0.5.6" + "@oasis-engine/design": "0.5.2" } } diff --git a/packages/core/src/animation/Animator.ts b/packages/core/src/animation/Animator.ts index cd01d7dc2b..8d6506cba3 100644 --- a/packages/core/src/animation/Animator.ts +++ b/packages/core/src/animation/Animator.ts @@ -1,4 +1,3 @@ -import { StateMachineScript } from './StateMachineScript'; import { Quaternion, Vector3 } from "@oasis-engine/math"; import { assignmentClone, ignoreClone } from "../clone/CloneManager"; import { Component } from "../Component"; @@ -12,6 +11,7 @@ import { AnimatorController } from "./AnimatorController"; import { AnimatorState } from "./AnimatorState"; import { AnimatorStateTransition } from "./AnimatorTransition"; import { AnimatorUtils } from "./AnimatorUtils"; +import { StateMachineScript } from "./StateMachineScript"; import { AnimationProperty } from "./enums/AnimationProperty"; import { AnimatorLayerBlendingMode } from "./enums/AnimatorLayerBlendingMode"; import { LayerState } from "./enums/LayerState"; @@ -276,25 +276,21 @@ export class Animator extends Component { private _saveAnimatorStateScripts(state: AnimatorState, animatorStateData: AnimatorStateData): void { const { _scripts: scripts } = state; - const {prototype} = StateMachineScript - const { onStartScripts, onStateEnterScripts, onStateUpdateScripts, onStateExitScripts } = animatorStateData; - onStartScripts.length = 0; + const { prototype } = StateMachineScript; + const { onStateEnterScripts, onStateUpdateScripts, onStateExitScripts } = animatorStateData; onStateEnterScripts.length = 0; onStateUpdateScripts.length = 0; onStateExitScripts.length = 0; for (let i = 0, n = scripts.length; i < n; i++) { const script = scripts[i]; - if (script.onStart !== prototype.onStart) { - onStartScripts.push(script) - } if (script.onStateEnter !== prototype.onStateEnter) { - onStateEnterScripts.push(script) + onStateEnterScripts.push(script); } if (script.onStateUpdate !== prototype.onStateUpdate) { - onStateUpdateScripts.push(script) + onStateUpdateScripts.push(script); } if (script.onStateExit !== prototype.onStateExit) { - onStateEnterScripts.push(script) + onStateExitScripts.push(script); } } } @@ -433,13 +429,21 @@ export class Animator extends Component { this._checkTransition(srcPlayData, crossFadeTransitionInfo, layerIndex); switch (animLayerData.layerState) { case LayerState.Playing: - this._updatePlayingState(srcPlayData, animLayerData, layerWeight, deltaTime, layerAdditive); + this._updatePlayingState(srcPlayData, animLayerData, layerIndex, layerWeight, deltaTime, layerAdditive); break; case LayerState.FixedCrossFading: - this._updateCrossFadeFromPose(destPlayData, animLayerData, layerWeight, deltaTime, layerAdditive); + this._updateCrossFadeFromPose(destPlayData, animLayerData, layerIndex, layerWeight, deltaTime, layerAdditive); break; case LayerState.CrossFading: - this._updateCrossFade(srcPlayData, destPlayData, animLayerData, layerWeight, deltaTime, layerAdditive); + this._updateCrossFade( + srcPlayData, + destPlayData, + animLayerData, + layerIndex, + layerWeight, + deltaTime, + layerAdditive + ); break; } } @@ -447,21 +451,24 @@ export class Animator extends Component { private _updatePlayingState( playData: AnimatorStatePlayData, layerData: AnimatorLayerData, + layerIndex: number, weight: number, delta: number, additive: boolean ): void { - const { curveOwners, eventHandlers, onStartScripts } = playData.stateData; - const { state } = playData; + const { curveOwners, eventHandlers } = playData.stateData; + const { state, stateData } = playData; const { _curveBindings: curves } = state.clip; const lastClipTime = playData.clipTime; + const hasTriggeredEnter = playData.started; playData.update(); const clipTime = playData.clipTime; eventHandlers.length && this._fireAnimationEvents(playData, eventHandlers, lastClipTime, clipTime); - // this._callScriptOnStart(); + !hasTriggeredEnter && this._callAnimatorScriptOnEnter(state, stateData, layerIndex); + this._callAnimatorScriptOnUpdate(state, stateData, layerIndex); for (let i = curves.length - 1; i >= 0; i--) { const owner = curveOwners[i]; @@ -476,6 +483,7 @@ export class Animator extends Component { if (playData.finished) { layerData.layerState = LayerState.Standby; + this._callAnimatorScriptOnExit(state, stateData, layerIndex); } } @@ -483,14 +491,22 @@ export class Animator extends Component { srcPlayData: AnimatorStatePlayData, destPlayData: AnimatorStatePlayData, layerData: AnimatorLayerData, + layerIndex, weight: number, delta: number, additive: boolean ) { const crossCurveDataCollection = this._crossCurveDataCollection; const srcCurves = srcPlayData.state.clip._curveBindings; - const { state: destState } = destPlayData; + const { state: srcState, stateData: srcStateData } = srcPlayData; + const { eventHandlers: srcEventHandler } = srcStateData; + const { state: destState, stateData: destStateData } = destPlayData; + const { eventHandlers: destEventHandler } = destStateData; const destCurves = destState.clip._curveBindings; + const lastSrcClipTime = srcPlayData.clipTime; + const lastDestClipTime = destPlayData.clipTime; + const hasTriggeredSrcEnter = srcPlayData.started; + const hasTriggeredDestEnter = destPlayData.started; let crossWeight = destPlayData.frameTime / (destState._getDuration() * layerData.crossFadeTransition.duration); crossWeight >= 1.0 && (crossWeight = 1.0); @@ -499,6 +515,15 @@ export class Animator extends Component { const srcClipTime = srcPlayData.clipTime; const destClipTime = destPlayData.clipTime; + + srcEventHandler.length && this._fireAnimationEvents(srcPlayData, srcEventHandler, lastSrcClipTime, srcClipTime); + destEventHandler.length && + this._fireAnimationEvents(destPlayData, destEventHandler, lastDestClipTime, destClipTime); + !hasTriggeredSrcEnter && this._callAnimatorScriptOnEnter(srcState, srcStateData, layerIndex); + this._callAnimatorScriptOnUpdate(srcState, srcStateData, layerIndex); + !hasTriggeredDestEnter && this._callAnimatorScriptOnEnter(destState, destStateData, layerIndex); + this._callAnimatorScriptOnUpdate(destState, destStateData, layerIndex); + for (let i = crossCurveDataCollection.length - 1; i >= 0; i--) { const { curveOwner, srcCurveIndex, destCurveIndex } = crossCurveDataCollection[i]; const { property, defaultValue } = curveOwner; @@ -515,25 +540,37 @@ export class Animator extends Component { this._applyCrossClipValue(curveOwner, srcValue, destValue, crossWeight, weight, additive); } + (crossWeight === 1 || srcPlayData.finished) && this._callAnimatorScriptOnExit(srcState, srcStateData, layerIndex); + destPlayData.finished && this._callAnimatorScriptOnExit(destState, destStateData, layerIndex); + this._updateCrossFadeData(layerData, crossWeight, delta, false); } private _updateCrossFadeFromPose( destPlayData: AnimatorStatePlayData, layerData: AnimatorLayerData, + layerIndex: number, weight: number, delta: number, additive: boolean ) { const crossCurveDataCollection = this._crossCurveDataCollection; - const { state: destState } = destPlayData; + const { state: destState, stateData } = destPlayData; + const { eventHandlers } = stateData; const curves = destState.clip._curveBindings; + const lastDestClipTime = destPlayData.clipTime; + const hasTriggeredEnter = destPlayData.started; let crossWeight = destPlayData.frameTime / (destState._getDuration() * layerData.crossFadeTransition.duration); crossWeight >= 1.0 && (crossWeight = 1.0); destPlayData.update(); const destClipTime = destPlayData.clipTime; + + eventHandlers.length && this._fireAnimationEvents(destPlayData, eventHandlers, lastDestClipTime, destClipTime); + !hasTriggeredEnter && this._callAnimatorScriptOnEnter(destState, stateData, layerIndex); + this._callAnimatorScriptOnUpdate(destState, stateData, layerIndex); + for (let i = crossCurveDataCollection.length - 1; i >= 0; i--) { const { curveOwner, destCurveIndex } = crossCurveDataCollection[i]; const destValue = @@ -544,6 +581,8 @@ export class Animator extends Component { this._applyCrossClipValue(curveOwner, curveOwner.fixedPoseValue, destValue, crossWeight, weight, additive); } + destPlayData.finished && this._callAnimatorScriptOnExit(destState, stateData, layerIndex); + this._updateCrossFadeData(layerData, crossWeight, delta, true); } @@ -794,6 +833,27 @@ export class Animator extends Component { } } + private _callAnimatorScriptOnEnter(state: AnimatorState, stateData: AnimatorStateData, layerIndex: number) { + const scripts = stateData.onStateEnterScripts; + for (let i = 0, n = scripts.length; i < n; ++i) { + scripts[i].onStateEnter(this, state, layerIndex); + } + } + + private _callAnimatorScriptOnUpdate(state: AnimatorState, stateData: AnimatorStateData, layerIndex: number) { + const scripts = stateData.onStateUpdateScripts; + for (let i = 0, n = scripts.length; i < n; ++i) { + scripts[i].onStateUpdate(this, state, layerIndex); + } + } + + private _callAnimatorScriptOnExit(state: AnimatorState, stateData: AnimatorStateData, layerIndex: number) { + const scripts = stateData.onStateExitScripts; + for (let i = 0, n = scripts.length; i < n; ++i) { + scripts[i].onStateExit(this, state, layerIndex); + } + } + private _clearPlayData() { this._animatorLayersData.length = 0; this._crossCurveDataCollection.length = 0; diff --git a/packages/core/src/animation/StateMachineScript.ts b/packages/core/src/animation/StateMachineScript.ts index cf66269d66..b877959d3d 100644 --- a/packages/core/src/animation/StateMachineScript.ts +++ b/packages/core/src/animation/StateMachineScript.ts @@ -1,13 +1,8 @@ -import { AnimatorState } from '../animation/AnimatorState'; import { Animator } from "../animation/Animator"; /** * Script class, used for logic writing. */ export class StateMachineScript { - constructor(animatorState: AnimatorState) { - } - // Start is called before the first frame update - onStart() {} // onStateEnter is called when a transition starts and the state machine starts to evaluate this state onStateEnter(animator: Animator, stateInfo: any, layerIndex: number) {} diff --git a/packages/core/src/animation/index.ts b/packages/core/src/animation/index.ts index 01b734afcb..63686f0a4b 100644 --- a/packages/core/src/animation/index.ts +++ b/packages/core/src/animation/index.ts @@ -9,6 +9,7 @@ export { AnimationCurve } from "./AnimationCurve"; export { AnimationClipCurveBinding } from "./AnimationClipCurveBinding"; export * from "./KeyFrame"; export { AnimationEvent } from "./AnimationEvent"; +export { StateMachineScript } from "./StateMachineScript"; export { AnimatorConditionMode } from "./enums/AnimatorConditionMode"; export { InterpolableValueType } from "./enums/InterpolableValueType"; export { InterpolationType } from "./enums/InterpolationType"; diff --git a/packages/core/src/animation/internal/AnimatorStateData.ts b/packages/core/src/animation/internal/AnimatorStateData.ts index 4522921492..7eeb999dd2 100644 --- a/packages/core/src/animation/internal/AnimatorStateData.ts +++ b/packages/core/src/animation/internal/AnimatorStateData.ts @@ -8,7 +8,6 @@ import { AnimationCurveOwner } from "./AnimationCurveOwner"; export class AnimatorStateData { curveOwners: AnimationCurveOwner[] = []; eventHandlers: AnimationEventHandler[] = []; - onStartScripts: StateMachineScript[] = []; onStateEnterScripts: StateMachineScript[] = []; onStateUpdateScripts: StateMachineScript[] = []; onStateExitScripts: StateMachineScript[] = []; diff --git a/packages/core/src/animation/internal/AnimatorStatePlayData.ts b/packages/core/src/animation/internal/AnimatorStatePlayData.ts index f34b8cd1e3..bf83f8817f 100644 --- a/packages/core/src/animation/internal/AnimatorStatePlayData.ts +++ b/packages/core/src/animation/internal/AnimatorStatePlayData.ts @@ -9,6 +9,7 @@ export class AnimatorStatePlayData { state: AnimatorState; stateData: AnimatorStateData; frameTime: number; + started: boolean; finished: boolean; clipTime: number; currentEventIndex: number; @@ -26,12 +27,14 @@ export class AnimatorStatePlayData { const state = this.state; let time = this.frameTime; const duration = state.clipEndTime - state.clipStartTime; + this.started = true; if (time > duration) { if (state.wrapMode === WrapMode.Loop) { time = time % duration; } else { time = duration; this.finished = true; + this.started = false; } } this.clipTime = time + this.state.clipStartTime; diff --git a/packages/core/src/asset/ResourceManager.ts b/packages/core/src/asset/ResourceManager.ts index d2fc8bb984..9bf8e9641a 100644 --- a/packages/core/src/asset/ResourceManager.ts +++ b/packages/core/src/asset/ResourceManager.ts @@ -12,19 +12,19 @@ import { ObjectValues } from "../base/Util"; export class ResourceManager { /** Loader collection. */ private static _loaders: { [key: number]: Loader } = {}; - private static _extTypeMapping: { [key: string]: string } = {}; + private static _extTypeMapping: { [key: string]: AssetType } = {}; /** * @internal */ - static _addLoader(type: string, loader: Loader, extnames: string[]) { + static _addLoader(type: AssetType, loader: Loader, extnames: string[]) { this._loaders[type] = loader; for (let i = 0, len = extnames.length; i < len; i++) { this._extTypeMapping[extnames[i]] = type; } } - private static _getTypeByUrl(url: string): string { + private static _getTypeByUrl(url: string): AssetType { const path = url.split("?")[0]; return this._extTypeMapping[path.substring(path.lastIndexOf(".") + 1)]; } @@ -219,7 +219,7 @@ export class ResourceManager { * @param assetType - Type of asset * @param extnames - Name of file extension */ -export function resourceLoader(assetType: string, extnames: string[], useCache: boolean = true) { +export function resourceLoader(assetType: AssetType, extnames: string[], useCache: boolean = true) { return >(Target: { new (useCache: boolean): T }) => { const loader = new Target(useCache); ResourceManager._addLoader(assetType, loader, extnames); diff --git a/packages/core/src/shaderlib/extra/sprite-mask.fs.glsl b/packages/core/src/shaderlib/extra/sprite-mask.fs.glsl index ec0a5e1419..c33dcc9623 100644 --- a/packages/core/src/shaderlib/extra/sprite-mask.fs.glsl +++ b/packages/core/src/shaderlib/extra/sprite-mask.fs.glsl @@ -1,3 +1,6 @@ +precision mediump float; +precision mediump int; + uniform sampler2D u_maskTexture; uniform float u_maskAlphaCutoff; varying vec2 v_uv; @@ -10,4 +13,4 @@ void main() } gl_FragColor = color; -} \ No newline at end of file +} diff --git a/packages/core/src/shaderlib/extra/sprite-mask.vs.glsl b/packages/core/src/shaderlib/extra/sprite-mask.vs.glsl index 3906cf5103..f33621e06d 100644 --- a/packages/core/src/shaderlib/extra/sprite-mask.vs.glsl +++ b/packages/core/src/shaderlib/extra/sprite-mask.vs.glsl @@ -1,3 +1,5 @@ +precision highp float; + uniform mat4 u_VPMat; attribute vec3 POSITION; @@ -9,4 +11,4 @@ void main() { gl_Position = u_VPMat * vec4(POSITION, 1.0); v_uv = TEXCOORD_0; -} \ No newline at end of file +} diff --git a/packages/core/src/shaderlib/extra/sprite.fs.glsl b/packages/core/src/shaderlib/extra/sprite.fs.glsl index 6d51f589ec..dc5fc8b566 100644 --- a/packages/core/src/shaderlib/extra/sprite.fs.glsl +++ b/packages/core/src/shaderlib/extra/sprite.fs.glsl @@ -1,3 +1,6 @@ +precision mediump float; +precision mediump int; + #ifdef USE_CUSTOM_TEXTURE uniform sampler2D u_cusTomTexture; #else @@ -16,4 +19,4 @@ void main() vec4 baseColor = texture2D(u_spriteTexture, v_uv); #endif gl_FragColor = baseColor * v_color; -} \ No newline at end of file +} diff --git a/packages/core/src/shaderlib/extra/sprite.vs.glsl b/packages/core/src/shaderlib/extra/sprite.vs.glsl index 80ac803b41..c0663583ff 100644 --- a/packages/core/src/shaderlib/extra/sprite.vs.glsl +++ b/packages/core/src/shaderlib/extra/sprite.vs.glsl @@ -1,3 +1,5 @@ +precision highp float; + #ifdef USE_MODEL_MATRIX uniform mat4 u_MVPMat; #else @@ -21,4 +23,4 @@ void main() v_uv = TEXCOORD_0; v_color = COLOR_0; -} \ No newline at end of file +} diff --git a/packages/design/package.json b/packages/design/package.json index a88ff0f9fe..6018bafd83 100755 --- a/packages/design/package.json +++ b/packages/design/package.json @@ -1,6 +1,6 @@ { "name": "@oasis-engine/design", - "version": "0.5.6", + "version": "0.5.2", "license": "MIT", "main": "dist/main.js", "module": "dist/module.js", diff --git a/packages/draco/package.json b/packages/draco/package.json index 36b7eb1db6..0c39bbd23f 100644 --- a/packages/draco/package.json +++ b/packages/draco/package.json @@ -1,6 +1,6 @@ { "name": "@oasis-engine/draco", - "version": "0.5.6", + "version": "0.5.2", "license": "MIT", "scripts": { "b:types": "tsc" @@ -13,6 +13,6 @@ "types/**/*" ], "dependencies": { - "@oasis-engine/core": "0.5.6" + "@oasis-engine/core": "0.5.2" } } diff --git a/packages/framebuffer-picker/package.json b/packages/framebuffer-picker/package.json index 554f0269ff..ac69c04fc1 100755 --- a/packages/framebuffer-picker/package.json +++ b/packages/framebuffer-picker/package.json @@ -1,6 +1,6 @@ { "name": "@oasis-engine/framebuffer-picker", - "version": "0.5.6", + "version": "0.5.2", "license": "MIT", "main": "dist/main.js", "module": "dist/module.js", @@ -14,6 +14,6 @@ "types/**/*" ], "dependencies": { - "oasis-engine": "0.5.6" + "oasis-engine": "0.5.2" } } diff --git a/packages/loader/package.json b/packages/loader/package.json index 24f791c757..4c720c6cfc 100755 --- a/packages/loader/package.json +++ b/packages/loader/package.json @@ -1,6 +1,6 @@ { "name": "@oasis-engine/loader", - "version": "0.5.6", + "version": "0.5.2", "license": "MIT", "types": "types/index.d.ts", "scripts": { @@ -14,9 +14,9 @@ "types/**/*" ], "dependencies": { - "@oasis-engine/core": "0.5.6", - "@oasis-engine/draco": "0.5.6", - "@oasis-engine/math": "0.5.6", - "@oasis-engine/rhi-webgl": "0.5.6" + "@oasis-engine/core": "0.5.2", + "@oasis-engine/draco": "0.5.2", + "@oasis-engine/math": "0.5.2", + "@oasis-engine/rhi-webgl": "0.5.2" } } diff --git a/packages/math/package.json b/packages/math/package.json index 87c4377f21..c54b12d1d7 100755 --- a/packages/math/package.json +++ b/packages/math/package.json @@ -1,6 +1,6 @@ { "name": "@oasis-engine/math", - "version": "0.5.6", + "version": "0.5.2", "license": "MIT", "main": "dist/main.js", "module": "dist/module.js", @@ -12,8 +12,5 @@ "files": [ "dist/**/*", "types/**/*" - ], - "devDependencies": { - "@oasis-engine/design": "0.5.6" - } + ] } diff --git a/packages/oasis-engine/package.json b/packages/oasis-engine/package.json index 46ad52ace7..26e56ef0ed 100755 --- a/packages/oasis-engine/package.json +++ b/packages/oasis-engine/package.json @@ -1,6 +1,6 @@ { "name": "oasis-engine", - "version": "0.5.6", + "version": "0.5.2", "license": "MIT", "scripts": { "b:types": "tsc" @@ -14,9 +14,9 @@ "types/**/*" ], "dependencies": { - "@oasis-engine/core": "0.5.6", - "@oasis-engine/loader": "0.5.6", - "@oasis-engine/math": "0.5.6", - "@oasis-engine/rhi-webgl": "0.5.6" + "@oasis-engine/core": "0.5.2", + "@oasis-engine/loader": "0.5.2", + "@oasis-engine/math": "0.5.2", + "@oasis-engine/rhi-webgl": "0.5.2" } } diff --git a/packages/rhi-webgl/package.json b/packages/rhi-webgl/package.json index 70033d6d00..f21e178fe5 100755 --- a/packages/rhi-webgl/package.json +++ b/packages/rhi-webgl/package.json @@ -1,6 +1,6 @@ { "name": "@oasis-engine/rhi-webgl", - "version": "0.5.6", + "version": "0.5.2", "license": "MIT", "main": "dist/main.js", "module": "dist/module.js", @@ -14,10 +14,10 @@ "types/**/*" ], "dependencies": { - "@oasis-engine/core": "0.5.6", - "@oasis-engine/math": "0.5.6" + "@oasis-engine/core": "0.5.2", + "@oasis-engine/math": "0.5.2" }, "devDependencies": { - "@oasis-engine/design": "0.5.6" + "@oasis-engine/design": "0.5.2" } } diff --git a/packages/rhi-webgl/src/WebGLRenderer.ts b/packages/rhi-webgl/src/WebGLRenderer.ts index f67d2b1b13..0f9a7c810e 100644 --- a/packages/rhi-webgl/src/WebGLRenderer.ts +++ b/packages/rhi-webgl/src/WebGLRenderer.ts @@ -21,7 +21,7 @@ import { } from "@oasis-engine/core"; import { CameraClearFlags } from "@oasis-engine/core"; import { IPlatformPrimitive } from "@oasis-engine/design"; -import { Color, Vector4 } from "@oasis-engine/math"; +import { Color } from "@oasis-engine/math"; import { GLCapability } from "./GLCapability"; import { GLExtensions } from "./GLExtensions"; import { GLPrimitive } from "./GLPrimitive"; @@ -71,10 +71,6 @@ export class WebGLRenderer implements IHardwareRenderer { private _activeTextureID: number = WebGLRenderingContext.TEXTURE0; private _activeTextures: GLTexture[] = new Array(32); - // cache value - private _lastViewport: Vector4 = new Vector4(null, null, null, null); - private _lastClearColor: Color = new Color(null, null, null, null); - get isWebGL2() { return this._isWebGL2; } @@ -185,16 +181,11 @@ export class WebGLRenderer implements IHardwareRenderer { return this.capability.canIUseCompressedTextureInternalFormat(type); } - viewport(x: number, y: number, width: number, height: number): void { + viewport(x, y, width, height) { // gl.enable(gl.SCISSOR_TEST); // gl.scissor(x, transformY, width, height); const gl = this._gl; - const lv = this._lastViewport; - - if (x !== lv.x || y !== lv.y || width !== lv.z || height !== lv.w) { - gl.viewport(x, y, width, height); - lv.setValue(x, y, width, height); - } + gl.viewport(x, gl.drawingBufferHeight - y - height, width, height); } colorMask(r, g, b, a) { @@ -214,18 +205,11 @@ export class WebGLRenderer implements IHardwareRenderer { } = engine._lastRenderState; let clearFlag = gl.DEPTH_BUFFER_BIT | gl.STENCIL_BUFFER_BIT; - if (clearFlags === CameraClearFlags.DepthColor) { - clearFlag |= gl.COLOR_BUFFER_BIT; - - const lc = this._lastClearColor; - const { r, g, b, a } = clearColor; - - if (clearColor && (r !== lc.r || g !== lc.g || b !== lc.b || a !== lc.a)) { - gl.clearColor(r, g, b, a); - lc.setValue(r, g, b, a); + clearFlag = clearFlag | gl.COLOR_BUFFER_BIT; + if (clearColor) { + gl.clearColor(clearColor.r, clearColor.g, clearColor.b, clearColor.a); } - if (targetBlendState.colorWriteMask !== ColorWriteMask.All) { gl.colorMask(true, true, true, true); targetBlendState.colorWriteMask = ColorWriteMask.All; @@ -261,16 +245,14 @@ export class WebGLRenderer implements IHardwareRenderer { /** @ts-ignore */ (renderTarget._platformRenderTarget as GLRenderTarget)?._activeRenderTarget(); const { width, height } = renderTarget; - this.viewport(0, 0, width, height); + + gl.viewport(0.0, 0.0, width >> mipLevel, height >> mipLevel); } else { gl.bindFramebuffer(gl.FRAMEBUFFER, null); const viewport = camera.viewport; - const { drawingBufferWidth, drawingBufferHeight } = gl; - const width = drawingBufferWidth * viewport.z; - const height = drawingBufferHeight * viewport.w; - const x = viewport.x * drawingBufferWidth; - const y = drawingBufferHeight - viewport.y * drawingBufferHeight - height; - this.viewport(x, y, width, height); + const width = gl.drawingBufferWidth; + const height = gl.drawingBufferHeight; + this.viewport(viewport.x * width, viewport.y * height, viewport.z * width, viewport.w * height); } } diff --git a/packages/stats/package.json b/packages/stats/package.json index fbbede135d..8dcfdf2790 100755 --- a/packages/stats/package.json +++ b/packages/stats/package.json @@ -1,6 +1,6 @@ { "name": "@oasis-engine/stats", - "version": "0.5.6", + "version": "0.5.2", "license": "MIT", "scripts": { "b:types": "tsc" @@ -14,6 +14,6 @@ "types/**/*" ], "dependencies": { - "oasis-engine": "0.5.6" + "oasis-engine": "0.5.2" } } From 851a49050fa2c4a55bab00f3e32e3053cf4c1921 Mon Sep 17 00:00:00 2001 From: singlecoder Date: Fri, 15 Oct 2021 17:37:28 +0800 Subject: [PATCH 25/41] fix(2d): opt shader precision (#542) --- packages/core/src/shaderlib/extra/sprite-mask.fs.glsl | 3 --- packages/core/src/shaderlib/extra/sprite-mask.vs.glsl | 2 -- packages/core/src/shaderlib/extra/sprite.fs.glsl | 3 --- packages/core/src/shaderlib/extra/sprite.vs.glsl | 2 -- 4 files changed, 10 deletions(-) diff --git a/packages/core/src/shaderlib/extra/sprite-mask.fs.glsl b/packages/core/src/shaderlib/extra/sprite-mask.fs.glsl index c33dcc9623..4da855d30e 100644 --- a/packages/core/src/shaderlib/extra/sprite-mask.fs.glsl +++ b/packages/core/src/shaderlib/extra/sprite-mask.fs.glsl @@ -1,6 +1,3 @@ -precision mediump float; -precision mediump int; - uniform sampler2D u_maskTexture; uniform float u_maskAlphaCutoff; varying vec2 v_uv; diff --git a/packages/core/src/shaderlib/extra/sprite-mask.vs.glsl b/packages/core/src/shaderlib/extra/sprite-mask.vs.glsl index f33621e06d..b5d5bad68d 100644 --- a/packages/core/src/shaderlib/extra/sprite-mask.vs.glsl +++ b/packages/core/src/shaderlib/extra/sprite-mask.vs.glsl @@ -1,5 +1,3 @@ -precision highp float; - uniform mat4 u_VPMat; attribute vec3 POSITION; diff --git a/packages/core/src/shaderlib/extra/sprite.fs.glsl b/packages/core/src/shaderlib/extra/sprite.fs.glsl index dc5fc8b566..ef44cf80eb 100644 --- a/packages/core/src/shaderlib/extra/sprite.fs.glsl +++ b/packages/core/src/shaderlib/extra/sprite.fs.glsl @@ -1,6 +1,3 @@ -precision mediump float; -precision mediump int; - #ifdef USE_CUSTOM_TEXTURE uniform sampler2D u_cusTomTexture; #else diff --git a/packages/core/src/shaderlib/extra/sprite.vs.glsl b/packages/core/src/shaderlib/extra/sprite.vs.glsl index c0663583ff..02c1928af3 100644 --- a/packages/core/src/shaderlib/extra/sprite.vs.glsl +++ b/packages/core/src/shaderlib/extra/sprite.vs.glsl @@ -1,5 +1,3 @@ -precision highp float; - #ifdef USE_MODEL_MATRIX uniform mat4 u_MVPMat; #else From f757f7fc4c6e5ec33da7d0529c8a7a8aeebf0d7d Mon Sep 17 00:00:00 2001 From: singlecoder Date: Tue, 26 Oct 2021 19:17:55 +0800 Subject: [PATCH 26/41] fix(gl): fix gl error (#555) --- packages/core/src/shader/state/BlendState.ts | 44 +++++++------- packages/core/src/shader/state/DepthState.ts | 22 +++---- .../core/src/shader/state/StencilState.ts | 58 ++++++++++--------- packages/rhi-webgl/src/WebGLRenderer.ts | 5 +- 4 files changed, 69 insertions(+), 60 deletions(-) diff --git a/packages/core/src/shader/state/BlendState.ts b/packages/core/src/shader/state/BlendState.ts index 8f0cc0d4bd..a5be507302 100644 --- a/packages/core/src/shader/state/BlendState.ts +++ b/packages/core/src/shader/state/BlendState.ts @@ -11,38 +11,40 @@ import { RenderTargetBlendState } from "./RenderTargetBlendState"; * Blend state. */ export class BlendState { - private static _getGLBlendFactor(blendFactor: BlendFactor): number { + private static _getGLBlendFactor(rhi: IHardwareRenderer, blendFactor: BlendFactor): number { + const gl = rhi.gl; + switch (blendFactor) { case BlendFactor.Zero: - return WebGLRenderingContext.ZERO; + return gl.ZERO; case BlendFactor.One: - return WebGLRenderingContext.ONE; + return gl.ONE; case BlendFactor.SourceColor: - return WebGLRenderingContext.SRC_COLOR; + return gl.SRC_COLOR; case BlendFactor.OneMinusSourceColor: - return WebGLRenderingContext.ONE_MINUS_SRC_COLOR; + return gl.ONE_MINUS_SRC_COLOR; case BlendFactor.DestinationColor: - return WebGLRenderingContext.DST_COLOR; + return gl.DST_COLOR; case BlendFactor.OneMinusDestinationColor: - return WebGLRenderingContext.ONE_MINUS_DST_COLOR; + return gl.ONE_MINUS_DST_COLOR; case BlendFactor.SourceAlpha: - return WebGLRenderingContext.SRC_ALPHA; + return gl.SRC_ALPHA; case BlendFactor.OneMinusSourceAlpha: - return WebGLRenderingContext.ONE_MINUS_SRC_ALPHA; + return gl.ONE_MINUS_SRC_ALPHA; case BlendFactor.DestinationAlpha: - return WebGLRenderingContext.DST_ALPHA; + return gl.DST_ALPHA; case BlendFactor.OneMinusDestinationAlpha: - return WebGLRenderingContext.ONE_MINUS_DST_ALPHA; + return gl.ONE_MINUS_DST_ALPHA; case BlendFactor.SourceAlphaSaturate: - return WebGLRenderingContext.SRC_ALPHA_SATURATE; + return gl.SRC_ALPHA_SATURATE; case BlendFactor.BlendColor: - return WebGLRenderingContext.CONSTANT_COLOR; + return gl.CONSTANT_COLOR; case BlendFactor.OneMinusBlendColor: - return WebGLRenderingContext.ONE_MINUS_CONSTANT_COLOR; + return gl.ONE_MINUS_CONSTANT_COLOR; } } - private static _getGLBlendOperation(blendOperation: BlendOperation, rhi: IHardwareRenderer): number { + private static _getGLBlendOperation(rhi: IHardwareRenderer, blendOperation: BlendOperation): number { const gl = rhi.gl; switch (blendOperation) { @@ -113,10 +115,10 @@ export class BlendState { destinationAlphaBlendFactor !== lastTargetBlendState.destinationAlphaBlendFactor ) { gl.blendFuncSeparate( - BlendState._getGLBlendFactor(sourceColorBlendFactor), - BlendState._getGLBlendFactor(destinationColorBlendFactor), - BlendState._getGLBlendFactor(sourceAlphaBlendFactor), - BlendState._getGLBlendFactor(destinationAlphaBlendFactor) + BlendState._getGLBlendFactor(rhi, sourceColorBlendFactor), + BlendState._getGLBlendFactor(rhi, destinationColorBlendFactor), + BlendState._getGLBlendFactor(rhi, sourceAlphaBlendFactor), + BlendState._getGLBlendFactor(rhi, destinationAlphaBlendFactor) ); lastTargetBlendState.sourceColorBlendFactor = sourceColorBlendFactor; lastTargetBlendState.destinationColorBlendFactor = destinationColorBlendFactor; @@ -130,8 +132,8 @@ export class BlendState { alphaBlendOperation !== lastTargetBlendState.alphaBlendOperation ) { gl.blendEquationSeparate( - BlendState._getGLBlendOperation(colorBlendOperation, rhi), - BlendState._getGLBlendOperation(alphaBlendOperation, rhi) + BlendState._getGLBlendOperation(rhi, colorBlendOperation), + BlendState._getGLBlendOperation(rhi, alphaBlendOperation) ); lastTargetBlendState.colorBlendOperation = colorBlendOperation; lastTargetBlendState.alphaBlendOperation = alphaBlendOperation; diff --git a/packages/core/src/shader/state/DepthState.ts b/packages/core/src/shader/state/DepthState.ts index 480b1d2f2c..29c8f03d3e 100644 --- a/packages/core/src/shader/state/DepthState.ts +++ b/packages/core/src/shader/state/DepthState.ts @@ -6,24 +6,26 @@ import { RenderState } from "./RenderState"; * Depth state. */ export class DepthState { - private static _getGLCompareFunction(compareFunction: CompareFunction): number { + private static _getGLCompareFunction(rhi: IHardwareRenderer, compareFunction: CompareFunction): number { + const gl = rhi.gl; + switch (compareFunction) { case CompareFunction.Never: - return WebGLRenderingContext.NEVER; + return gl.NEVER; case CompareFunction.Less: - return WebGLRenderingContext.LESS; + return gl.LESS; case CompareFunction.Equal: - return WebGLRenderingContext.EQUAL; + return gl.EQUAL; case CompareFunction.LessEqual: - return WebGLRenderingContext.LEQUAL; + return gl.LEQUAL; case CompareFunction.Greater: - return WebGLRenderingContext.GREATER; + return gl.GREATER; case CompareFunction.NotEqual: - return WebGLRenderingContext.NOTEQUAL; + return gl.NOTEQUAL; case CompareFunction.GreaterEqual: - return WebGLRenderingContext.GEQUAL; + return gl.GEQUAL; case CompareFunction.Always: - return WebGLRenderingContext.ALWAYS; + return gl.ALWAYS; } } @@ -58,7 +60,7 @@ export class DepthState { if (enabled) { // apply compare func. if (compareFunction != lastState.compareFunction) { - gl.depthFunc(DepthState._getGLCompareFunction(compareFunction)); + gl.depthFunc(DepthState._getGLCompareFunction(rhi, compareFunction)); lastState.compareFunction = compareFunction; } diff --git a/packages/core/src/shader/state/StencilState.ts b/packages/core/src/shader/state/StencilState.ts index c4f695ba0d..76cb39ab19 100644 --- a/packages/core/src/shader/state/StencilState.ts +++ b/packages/core/src/shader/state/StencilState.ts @@ -7,45 +7,49 @@ import { RenderState } from "./RenderState"; * Stencil state. */ export class StencilState { - private static _getGLCompareFunction(compareFunction: CompareFunction): number { + private static _getGLCompareFunction(rhi: IHardwareRenderer, compareFunction: CompareFunction): number { + const gl = rhi.gl; + switch (compareFunction) { case CompareFunction.Never: - return WebGLRenderingContext.NEVER; + return gl.NEVER; case CompareFunction.Less: - return WebGLRenderingContext.LESS; + return gl.LESS; case CompareFunction.Equal: - return WebGLRenderingContext.EQUAL; + return gl.EQUAL; case CompareFunction.LessEqual: - return WebGLRenderingContext.LEQUAL; + return gl.LEQUAL; case CompareFunction.Greater: - return WebGLRenderingContext.GREATER; + return gl.GREATER; case CompareFunction.NotEqual: - return WebGLRenderingContext.NOTEQUAL; + return gl.NOTEQUAL; case CompareFunction.GreaterEqual: - return WebGLRenderingContext.GEQUAL; + return gl.GEQUAL; case CompareFunction.Always: - return WebGLRenderingContext.ALWAYS; + return gl.ALWAYS; } } - private static _getGLStencilOperation(compareFunction: StencilOperation): number { + private static _getGLStencilOperation(rhi: IHardwareRenderer, compareFunction: StencilOperation): number { + const gl = rhi.gl; + switch (compareFunction) { case StencilOperation.Keep: - return WebGLRenderingContext.KEEP; + return gl.KEEP; case StencilOperation.Zero: - return WebGLRenderingContext.ZERO; + return gl.ZERO; case StencilOperation.Replace: - return WebGLRenderingContext.REPLACE; + return gl.REPLACE; case StencilOperation.IncrementSaturate: - return WebGLRenderingContext.INCR; + return gl.INCR; case StencilOperation.DecrementSaturate: - return WebGLRenderingContext.DECR; + return gl.DECR; case StencilOperation.Invert: - return WebGLRenderingContext.INVERT; + return gl.INVERT; case StencilOperation.IncrementWrap: - return WebGLRenderingContext.INCR_WRAP; + return gl.INCR_WRAP; case StencilOperation.DecrementWrap: - return WebGLRenderingContext.DECR_WRAP; + return gl.DECR_WRAP; } } @@ -102,7 +106,7 @@ export class StencilState { if (enabled) { gl.enable(gl.STENCIL_TEST); } else { - gl.disable(WebGLRenderingContext.STENCIL_TEST); + gl.disable(gl.STENCIL_TEST); } lastState.enabled = enabled; } @@ -113,7 +117,7 @@ export class StencilState { if (referenceOrMaskChange || compareFunctionFront !== lastState.compareFunctionFront) { gl.stencilFuncSeparate( gl.FRONT, - StencilState._getGLCompareFunction(compareFunctionFront), + StencilState._getGLCompareFunction(rhi, compareFunctionFront), referenceValue, mask ); @@ -121,7 +125,7 @@ export class StencilState { } if (referenceOrMaskChange || compareFunctionBack !== lastState.compareFunctionBack) { - gl.stencilFuncSeparate(gl.BACK, StencilState._getGLCompareFunction(compareFunctionBack), referenceValue, mask); + gl.stencilFuncSeparate(gl.BACK, StencilState._getGLCompareFunction(rhi, compareFunctionBack), referenceValue, mask); lastState.compareFunctionBack = this.compareFunctionBack; } if (referenceOrMaskChange) { @@ -137,9 +141,9 @@ export class StencilState { ) { gl.stencilOpSeparate( gl.FRONT, - StencilState._getGLStencilOperation(failOperationFront), - StencilState._getGLStencilOperation(zFailOperationFront), - StencilState._getGLStencilOperation(passOperationFront) + StencilState._getGLStencilOperation(rhi, failOperationFront), + StencilState._getGLStencilOperation(rhi, zFailOperationFront), + StencilState._getGLStencilOperation(rhi, passOperationFront) ); lastState.failOperationFront = failOperationFront; lastState.zFailOperationFront = zFailOperationFront; @@ -153,9 +157,9 @@ export class StencilState { ) { gl.stencilOpSeparate( gl.BACK, - StencilState._getGLStencilOperation(failOperationBack), - StencilState._getGLStencilOperation(zFailOperationBack), - StencilState._getGLStencilOperation(passOperationBack) + StencilState._getGLStencilOperation(rhi, failOperationBack), + StencilState._getGLStencilOperation(rhi, zFailOperationBack), + StencilState._getGLStencilOperation(rhi, passOperationBack) ); lastState.failOperationBack = failOperationBack; lastState.zFailOperationBack = zFailOperationBack; diff --git a/packages/rhi-webgl/src/WebGLRenderer.ts b/packages/rhi-webgl/src/WebGLRenderer.ts index d674b29c2c..46c1c5e2b3 100644 --- a/packages/rhi-webgl/src/WebGLRenderer.ts +++ b/packages/rhi-webgl/src/WebGLRenderer.ts @@ -68,7 +68,7 @@ export class WebGLRenderer implements IHardwareRenderer { private _capability: GLCapability; private _isWebGL2: boolean; - private _activeTextureID: number = WebGLRenderingContext.TEXTURE0; + private _activeTextureID: number; private _activeTextures: GLTexture[] = new Array(32); // cache value @@ -140,11 +140,12 @@ export class WebGLRenderer implements IHardwareRenderer { } this._gl = gl; + this._activeTextureID = gl.TEXTURE0; this._renderStates = new GLRenderStates(gl); this._extensions = new GLExtensions(this); this._capability = new GLCapability(this); // Make sure the active texture in gl context is on default, because gl context may be used in other webgl renderer. - gl.activeTexture(WebGLRenderingContext.TEXTURE0); + gl.activeTexture(gl.TEXTURE0); this._options = null; } From e8b30979e18413921ca37cedacdaed64abce590c Mon Sep 17 00:00:00 2001 From: GuoLei1990 Date: Tue, 26 Oct 2021 19:28:46 +0800 Subject: [PATCH 27/41] v0.5.7 --- lerna.json | 2 +- packages/controls/package.json | 4 ++-- packages/core/package.json | 6 +++--- packages/design/package.json | 2 +- packages/draco/package.json | 4 ++-- packages/framebuffer-picker/package.json | 4 ++-- packages/loader/package.json | 10 +++++----- packages/math/package.json | 4 ++-- packages/oasis-engine/package.json | 10 +++++----- packages/rhi-webgl/package.json | 8 ++++---- packages/stats/package.json | 4 ++-- 11 files changed, 29 insertions(+), 29 deletions(-) diff --git a/lerna.json b/lerna.json index d1c9dc65ca..97f7227cec 100644 --- a/lerna.json +++ b/lerna.json @@ -1,6 +1,6 @@ { "npmClient": "npm", - "version": "0.5.6", + "version": "0.5.7", "bootstrap": { "hoist": true }, diff --git a/packages/controls/package.json b/packages/controls/package.json index 8c269721f5..9ff9048860 100644 --- a/packages/controls/package.json +++ b/packages/controls/package.json @@ -1,6 +1,6 @@ { "name": "@oasis-engine/controls", - "version": "0.5.6", + "version": "0.5.7", "license": "MIT", "scripts": { "b:types": "tsc", @@ -15,6 +15,6 @@ "types/**/*" ], "dependencies": { - "oasis-engine": "0.5.6" + "oasis-engine": "0.5.7" } } diff --git a/packages/core/package.json b/packages/core/package.json index 49606a4385..f3a44673cc 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -1,6 +1,6 @@ { "name": "@oasis-engine/core", - "version": "0.5.6", + "version": "0.5.7", "license": "MIT", "main": "dist/main.js", "module": "dist/module.js", @@ -14,9 +14,9 @@ "types/**/*" ], "dependencies": { - "@oasis-engine/math": "0.5.6" + "@oasis-engine/math": "0.5.7" }, "devDependencies": { - "@oasis-engine/design": "0.5.6" + "@oasis-engine/design": "0.5.7" } } diff --git a/packages/design/package.json b/packages/design/package.json index f67d5f8ef2..b5b5d9bb75 100755 --- a/packages/design/package.json +++ b/packages/design/package.json @@ -1,6 +1,6 @@ { "name": "@oasis-engine/design", - "version": "0.5.6", + "version": "0.5.7", "license": "MIT", "main": "dist/main.js", "module": "dist/module.js", diff --git a/packages/draco/package.json b/packages/draco/package.json index 36b7eb1db6..909213bfcf 100644 --- a/packages/draco/package.json +++ b/packages/draco/package.json @@ -1,6 +1,6 @@ { "name": "@oasis-engine/draco", - "version": "0.5.6", + "version": "0.5.7", "license": "MIT", "scripts": { "b:types": "tsc" @@ -13,6 +13,6 @@ "types/**/*" ], "dependencies": { - "@oasis-engine/core": "0.5.6" + "@oasis-engine/core": "0.5.7" } } diff --git a/packages/framebuffer-picker/package.json b/packages/framebuffer-picker/package.json index 554f0269ff..b94ba35bf2 100755 --- a/packages/framebuffer-picker/package.json +++ b/packages/framebuffer-picker/package.json @@ -1,6 +1,6 @@ { "name": "@oasis-engine/framebuffer-picker", - "version": "0.5.6", + "version": "0.5.7", "license": "MIT", "main": "dist/main.js", "module": "dist/module.js", @@ -14,6 +14,6 @@ "types/**/*" ], "dependencies": { - "oasis-engine": "0.5.6" + "oasis-engine": "0.5.7" } } diff --git a/packages/loader/package.json b/packages/loader/package.json index 24f791c757..474f23b8cd 100755 --- a/packages/loader/package.json +++ b/packages/loader/package.json @@ -1,6 +1,6 @@ { "name": "@oasis-engine/loader", - "version": "0.5.6", + "version": "0.5.7", "license": "MIT", "types": "types/index.d.ts", "scripts": { @@ -14,9 +14,9 @@ "types/**/*" ], "dependencies": { - "@oasis-engine/core": "0.5.6", - "@oasis-engine/draco": "0.5.6", - "@oasis-engine/math": "0.5.6", - "@oasis-engine/rhi-webgl": "0.5.6" + "@oasis-engine/core": "0.5.7", + "@oasis-engine/draco": "0.5.7", + "@oasis-engine/math": "0.5.7", + "@oasis-engine/rhi-webgl": "0.5.7" } } diff --git a/packages/math/package.json b/packages/math/package.json index 87c4377f21..2b7a1f9d5d 100755 --- a/packages/math/package.json +++ b/packages/math/package.json @@ -1,6 +1,6 @@ { "name": "@oasis-engine/math", - "version": "0.5.6", + "version": "0.5.7", "license": "MIT", "main": "dist/main.js", "module": "dist/module.js", @@ -14,6 +14,6 @@ "types/**/*" ], "devDependencies": { - "@oasis-engine/design": "0.5.6" + "@oasis-engine/design": "0.5.7" } } diff --git a/packages/oasis-engine/package.json b/packages/oasis-engine/package.json index 46ad52ace7..dfccde0861 100755 --- a/packages/oasis-engine/package.json +++ b/packages/oasis-engine/package.json @@ -1,6 +1,6 @@ { "name": "oasis-engine", - "version": "0.5.6", + "version": "0.5.7", "license": "MIT", "scripts": { "b:types": "tsc" @@ -14,9 +14,9 @@ "types/**/*" ], "dependencies": { - "@oasis-engine/core": "0.5.6", - "@oasis-engine/loader": "0.5.6", - "@oasis-engine/math": "0.5.6", - "@oasis-engine/rhi-webgl": "0.5.6" + "@oasis-engine/core": "0.5.7", + "@oasis-engine/loader": "0.5.7", + "@oasis-engine/math": "0.5.7", + "@oasis-engine/rhi-webgl": "0.5.7" } } diff --git a/packages/rhi-webgl/package.json b/packages/rhi-webgl/package.json index 70033d6d00..348b825c29 100755 --- a/packages/rhi-webgl/package.json +++ b/packages/rhi-webgl/package.json @@ -1,6 +1,6 @@ { "name": "@oasis-engine/rhi-webgl", - "version": "0.5.6", + "version": "0.5.7", "license": "MIT", "main": "dist/main.js", "module": "dist/module.js", @@ -14,10 +14,10 @@ "types/**/*" ], "dependencies": { - "@oasis-engine/core": "0.5.6", - "@oasis-engine/math": "0.5.6" + "@oasis-engine/core": "0.5.7", + "@oasis-engine/math": "0.5.7" }, "devDependencies": { - "@oasis-engine/design": "0.5.6" + "@oasis-engine/design": "0.5.7" } } diff --git a/packages/stats/package.json b/packages/stats/package.json index fbbede135d..cb5ea18a34 100755 --- a/packages/stats/package.json +++ b/packages/stats/package.json @@ -1,6 +1,6 @@ { "name": "@oasis-engine/stats", - "version": "0.5.6", + "version": "0.5.7", "license": "MIT", "scripts": { "b:types": "tsc" @@ -14,6 +14,6 @@ "types/**/*" ], "dependencies": { - "oasis-engine": "0.5.6" + "oasis-engine": "0.5.7" } } From 36bd30fb37bb7c1adce7a96dff281b63ad58d2d7 Mon Sep 17 00:00:00 2001 From: luzhuang <364439895@qq.com> Date: Wed, 27 Oct 2021 19:16:08 +0800 Subject: [PATCH 28/41] feat: update comment --- .../core/src/animation/StateMachineScript.ts | 31 ++++++++++++++----- 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/packages/core/src/animation/StateMachineScript.ts b/packages/core/src/animation/StateMachineScript.ts index b877959d3d..579e622e33 100644 --- a/packages/core/src/animation/StateMachineScript.ts +++ b/packages/core/src/animation/StateMachineScript.ts @@ -1,14 +1,31 @@ import { Animator } from "../animation/Animator"; +import { AnimatorState } from "../animation/AnimatorState"; + /** - * Script class, used for logic writing. + * StateMachineScript is a component that can be added to a state. It's the base class every script on a state derives from. */ export class StateMachineScript { - // onStateEnter is called when a transition starts and the state machine starts to evaluate this state - onStateEnter(animator: Animator, stateInfo: any, layerIndex: number) {} + /** + * onStateEnter is called when a transition starts and the state machine starts to evaluate this state. + * @param animator - The animator. + * @param stateInfo - The state be evaluated. + * @param layerIndex - The index of the layer where the state is located. + */ + onStateEnter(animator: Animator, stateInfo: AnimatorState, layerIndex: number) {} - // onStateUpdate is called on each Update frame between onStateEnter and onStateExit callbacks - onStateUpdate(animator: Animator, stateInfo: any, layerIndex: number) {} + /** + * onStateUpdate is called on each Update frame between onStateEnter and onStateExit callbacks. + * @param animator - The animator. + * @param stateInfo - The state be evaluated. + * @param layerIndex - The index of the layer where the state is located. + */ + onStateUpdate(animator: Animator, stateInfo: AnimatorState, layerIndex: number) {} - // onStateExit is called when a transition ends and the state machine finishes evaluating this state - onStateExit(animator: Animator, stateInfo: any, layerIndex: number) {} + /** + * onStateExit is called when a transition ends and the state machine finishes evaluating this state. + * @param animator - The animator. + * @param stateInfo - The state be evaluated. + * @param layerIndex - The index of the layer where the state is located. + */ + onStateExit(animator: Animator, stateInfo: AnimatorState, layerIndex: number) {} } From 5d6370f5d1807f5bb3832c8dd388ac9d0f0c3c89 Mon Sep 17 00:00:00 2001 From: luzhuang <364439895@qq.com> Date: Wed, 27 Oct 2021 19:21:53 +0800 Subject: [PATCH 29/41] feat: update comment --- packages/core/src/animation/AnimatorState.ts | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/packages/core/src/animation/AnimatorState.ts b/packages/core/src/animation/AnimatorState.ts index 653b0bcda8..2aded92447 100644 --- a/packages/core/src/animation/AnimatorState.ts +++ b/packages/core/src/animation/AnimatorState.ts @@ -85,12 +85,20 @@ export class AnimatorState { index !== -1 && this._transitions.splice(index, 1); } - addStateMachineScript(type: new () => T): T { - const script = new type(); + /** + * Adds a state machine script class of type T to the AnimatorState. + * @param scriptType - The state machine script class of type T. + */ + addStateMachineScript(scriptType: new () => T): T { + const script = new scriptType(); this._scripts.push(script); return script; } - + + /** + * Remove the state machine script added. + * @param stateMachineScript - The state machine script. + */ removeStateMachineScript(stateMachineScript: StateMachineScript) { const index = this._scripts.indexOf(stateMachineScript); index !== -1 && this._scripts.splice(index, 1); From 3ae034b6761da00442eb405b603552de8a00e5aa Mon Sep 17 00:00:00 2001 From: GuoLei1990 Date: Thu, 28 Oct 2021 10:46:01 +0800 Subject: [PATCH 30/41] refactor: opt `StateMachineScript` code --- .../core/src/animation/StateMachineScript.ts | 26 +++++++++---------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/packages/core/src/animation/StateMachineScript.ts b/packages/core/src/animation/StateMachineScript.ts index 579e622e33..13eb1be6bc 100644 --- a/packages/core/src/animation/StateMachineScript.ts +++ b/packages/core/src/animation/StateMachineScript.ts @@ -2,30 +2,30 @@ import { Animator } from "../animation/Animator"; import { AnimatorState } from "../animation/AnimatorState"; /** - * StateMachineScript is a component that can be added to a state. It's the base class every script on a state derives from. + * StateMachineScript is a component that can be added to a animator state. It's the base class every script on a state derives from. */ export class StateMachineScript { /** * onStateEnter is called when a transition starts and the state machine starts to evaluate this state. - * @param animator - The animator. - * @param stateInfo - The state be evaluated. - * @param layerIndex - The index of the layer where the state is located. + * @param animator - The animator + * @param animatorState - The state be evaluated + * @param layerIndex - The index of the layer where the state is located */ - onStateEnter(animator: Animator, stateInfo: AnimatorState, layerIndex: number) {} + onStateEnter(animator: Animator, animatorState: AnimatorState, layerIndex: number): void {} /** * onStateUpdate is called on each Update frame between onStateEnter and onStateExit callbacks. - * @param animator - The animator. - * @param stateInfo - The state be evaluated. - * @param layerIndex - The index of the layer where the state is located. + * @param animator - The animator + * @param animatorState - The state be evaluated + * @param layerIndex - The index of the layer where the state is located */ - onStateUpdate(animator: Animator, stateInfo: AnimatorState, layerIndex: number) {} + onStateUpdate(animator: Animator, animatorState: AnimatorState, layerIndex: number): void {} /** * onStateExit is called when a transition ends and the state machine finishes evaluating this state. - * @param animator - The animator. - * @param stateInfo - The state be evaluated. - * @param layerIndex - The index of the layer where the state is located. + * @param animator - The animator + * @param animatorState - The state be evaluated + * @param layerIndex - The index of the layer where the state is located */ - onStateExit(animator: Animator, stateInfo: AnimatorState, layerIndex: number) {} + onStateExit(animator: Animator, animatorState: AnimatorState, layerIndex: number): void {} } From 5998c3653cc6d94108e17cc1d51e143e141aa11e Mon Sep 17 00:00:00 2001 From: GuoLei1990 Date: Thu, 28 Oct 2021 11:52:28 +0800 Subject: [PATCH 31/41] refactor: opt code --- packages/core/src/animation/AnimatorState.ts | 24 +++++++++---------- .../core/src/animation/StateMachineScript.ts | 16 +++++++++++++ 2 files changed, 28 insertions(+), 12 deletions(-) diff --git a/packages/core/src/animation/AnimatorState.ts b/packages/core/src/animation/AnimatorState.ts index 2aded92447..d7e8b12fa5 100644 --- a/packages/core/src/animation/AnimatorState.ts +++ b/packages/core/src/animation/AnimatorState.ts @@ -1,4 +1,4 @@ -import { StateMachineScript } from './StateMachineScript'; +import { StateMachineScript } from "./StateMachineScript"; import { AnimationClip } from "./AnimationClip"; import { AnimatorStateTransition } from "./AnimatorTransition"; import { WrapMode } from "./enums/WrapMode"; @@ -13,7 +13,7 @@ export class AnimatorState { wrapMode: WrapMode = WrapMode.Loop; _scripts: StateMachineScript[] = []; - + private _clipStartTime: number = 0; private _clipEndTime: number = Infinity; private _clip: AnimationClip; @@ -87,22 +87,14 @@ export class AnimatorState { /** * Adds a state machine script class of type T to the AnimatorState. - * @param scriptType - The state machine script class of type T. + * @param scriptType - The state machine script class of type T */ addStateMachineScript(scriptType: new () => T): T { const script = new scriptType(); this._scripts.push(script); + script._state = this; return script; } - - /** - * Remove the state machine script added. - * @param stateMachineScript - The state machine script. - */ - removeStateMachineScript(stateMachineScript: StateMachineScript) { - const index = this._scripts.indexOf(stateMachineScript); - index !== -1 && this._scripts.splice(index, 1); - } /** * Clears all transitions from the state. @@ -117,4 +109,12 @@ export class AnimatorState { _getDuration(): number { return this._clipEndTime - this._clipStartTime; } + + /** + * @internal + */ + _removeStateMachineScript(stateMachineScript: StateMachineScript): void { + const index = this._scripts.indexOf(stateMachineScript); + index !== -1 && this._scripts.splice(index, 1); + } } diff --git a/packages/core/src/animation/StateMachineScript.ts b/packages/core/src/animation/StateMachineScript.ts index 13eb1be6bc..b71dab0661 100644 --- a/packages/core/src/animation/StateMachineScript.ts +++ b/packages/core/src/animation/StateMachineScript.ts @@ -5,6 +5,10 @@ import { AnimatorState } from "../animation/AnimatorState"; * StateMachineScript is a component that can be added to a animator state. It's the base class every script on a state derives from. */ export class StateMachineScript { + /** @internal */ + _destroyed: boolean = false; + /** @internal */ + _state: AnimatorState; /** * onStateEnter is called when a transition starts and the state machine starts to evaluate this state. * @param animator - The animator @@ -28,4 +32,16 @@ export class StateMachineScript { * @param layerIndex - The index of the layer where the state is located */ onStateExit(animator: Animator, animatorState: AnimatorState, layerIndex: number): void {} + + /** + * Destroy this instance. + */ + destroy(): void { + if (this._destroyed) { + return; + } + + this._state._removeStateMachineScript(this); + this._destroyed = true; + } } From 92bb4c690d40e6ef80b04fe9ce3b8bca30dba01e Mon Sep 17 00:00:00 2001 From: GuoLei1990 Date: Thu, 28 Oct 2021 17:04:13 +0800 Subject: [PATCH 32/41] refactor: opt code --- packages/core/src/animation/Animator.ts | 16 ++++++++-------- packages/core/src/animation/AnimatorState.ts | 3 ++- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/packages/core/src/animation/Animator.ts b/packages/core/src/animation/Animator.ts index 8d6506cba3..a1e152bb91 100644 --- a/packages/core/src/animation/Animator.ts +++ b/packages/core/src/animation/Animator.ts @@ -11,7 +11,6 @@ import { AnimatorController } from "./AnimatorController"; import { AnimatorState } from "./AnimatorState"; import { AnimatorStateTransition } from "./AnimatorTransition"; import { AnimatorUtils } from "./AnimatorUtils"; -import { StateMachineScript } from "./StateMachineScript"; import { AnimationProperty } from "./enums/AnimationProperty"; import { AnimatorLayerBlendingMode } from "./enums/AnimatorLayerBlendingMode"; import { LayerState } from "./enums/LayerState"; @@ -23,6 +22,7 @@ import { AnimatorStateInfo } from "./internal/AnimatorStateInfo"; import { AnimatorStatePlayData } from "./internal/AnimatorStatePlayData"; import { CrossCurveData } from "./internal/CrossCurveData"; import { InterpolableValue, UnionInterpolableKeyframe } from "./KeyFrame"; +import { StateMachineScript } from "./StateMachineScript"; /** * The controller of the animation system. @@ -833,28 +833,28 @@ export class Animator extends Component { } } - private _callAnimatorScriptOnEnter(state: AnimatorState, stateData: AnimatorStateData, layerIndex: number) { + private _callAnimatorScriptOnEnter(state: AnimatorState, stateData: AnimatorStateData, layerIndex: number): void { const scripts = stateData.onStateEnterScripts; - for (let i = 0, n = scripts.length; i < n; ++i) { + for (let i = 0, n = scripts.length; i < n; i++) { scripts[i].onStateEnter(this, state, layerIndex); } } - private _callAnimatorScriptOnUpdate(state: AnimatorState, stateData: AnimatorStateData, layerIndex: number) { + private _callAnimatorScriptOnUpdate(state: AnimatorState, stateData: AnimatorStateData, layerIndex: number): void { const scripts = stateData.onStateUpdateScripts; - for (let i = 0, n = scripts.length; i < n; ++i) { + for (let i = 0, n = scripts.length; i < n; i++) { scripts[i].onStateUpdate(this, state, layerIndex); } } - private _callAnimatorScriptOnExit(state: AnimatorState, stateData: AnimatorStateData, layerIndex: number) { + private _callAnimatorScriptOnExit(state: AnimatorState, stateData: AnimatorStateData, layerIndex: number): void { const scripts = stateData.onStateExitScripts; - for (let i = 0, n = scripts.length; i < n; ++i) { + for (let i = 0, n = scripts.length; i < n; i++) { scripts[i].onStateExit(this, state, layerIndex); } } - private _clearPlayData() { + private _clearPlayData(): void { this._animatorLayersData.length = 0; this._crossCurveDataCollection.length = 0; this._animationCurveOwners.length = 0; diff --git a/packages/core/src/animation/AnimatorState.ts b/packages/core/src/animation/AnimatorState.ts index d7e8b12fa5..a62900967d 100644 --- a/packages/core/src/animation/AnimatorState.ts +++ b/packages/core/src/animation/AnimatorState.ts @@ -1,7 +1,7 @@ -import { StateMachineScript } from "./StateMachineScript"; import { AnimationClip } from "./AnimationClip"; import { AnimatorStateTransition } from "./AnimatorTransition"; import { WrapMode } from "./enums/WrapMode"; +import { StateMachineScript } from "./StateMachineScript"; /** * States are the basic building blocks of a state machine. Each state contains a AnimationClip which will play while the character is in that state. @@ -12,6 +12,7 @@ export class AnimatorState { /** The wrap mode used in the state. */ wrapMode: WrapMode = WrapMode.Loop; + /** @internal */ _scripts: StateMachineScript[] = []; private _clipStartTime: number = 0; From 0694d511ec67fe0acc1d9f707fafdf8284827a6a Mon Sep 17 00:00:00 2001 From: GuoLei1990 Date: Thu, 28 Oct 2021 17:30:44 +0800 Subject: [PATCH 33/41] refactor: opt performance --- packages/core/src/animation/Animator.ts | 29 ++------------ packages/core/src/animation/AnimatorState.ts | 38 ++++++++++++++++--- .../animation/internal/AnimatorStateData.ts | 3 -- 3 files changed, 35 insertions(+), 35 deletions(-) diff --git a/packages/core/src/animation/Animator.ts b/packages/core/src/animation/Animator.ts index a1e152bb91..85da4a4a36 100644 --- a/packages/core/src/animation/Animator.ts +++ b/packages/core/src/animation/Animator.ts @@ -22,7 +22,6 @@ import { AnimatorStateInfo } from "./internal/AnimatorStateInfo"; import { AnimatorStatePlayData } from "./internal/AnimatorStatePlayData"; import { CrossCurveData } from "./internal/CrossCurveData"; import { InterpolableValue, UnionInterpolableKeyframe } from "./KeyFrame"; -import { StateMachineScript } from "./StateMachineScript"; /** * The controller of the animation system. @@ -228,7 +227,6 @@ export class Animator extends Component { animatorStateDataCollection[stateName] = animatorStateData; this._saveAnimatorStateData(animatorState, animatorStateData); this._saveAnimatorEventHandlers(animatorState, animatorStateData); - this._saveAnimatorStateScripts(animatorState, animatorStateData); } return animatorStateData; } @@ -274,27 +272,6 @@ export class Animator extends Component { } } - private _saveAnimatorStateScripts(state: AnimatorState, animatorStateData: AnimatorStateData): void { - const { _scripts: scripts } = state; - const { prototype } = StateMachineScript; - const { onStateEnterScripts, onStateUpdateScripts, onStateExitScripts } = animatorStateData; - onStateEnterScripts.length = 0; - onStateUpdateScripts.length = 0; - onStateExitScripts.length = 0; - for (let i = 0, n = scripts.length; i < n; i++) { - const script = scripts[i]; - if (script.onStateEnter !== prototype.onStateEnter) { - onStateEnterScripts.push(script); - } - if (script.onStateUpdate !== prototype.onStateUpdate) { - onStateUpdateScripts.push(script); - } - if (script.onStateExit !== prototype.onStateExit) { - onStateExitScripts.push(script); - } - } - } - private _clearCrossData(animatorLayerData: AnimatorLayerData): void { animatorLayerData.crossCurveMark++; this._crossCurveDataCollection.length = 0; @@ -834,21 +811,21 @@ export class Animator extends Component { } private _callAnimatorScriptOnEnter(state: AnimatorState, stateData: AnimatorStateData, layerIndex: number): void { - const scripts = stateData.onStateEnterScripts; + const scripts = state._onStateEnterScripts; for (let i = 0, n = scripts.length; i < n; i++) { scripts[i].onStateEnter(this, state, layerIndex); } } private _callAnimatorScriptOnUpdate(state: AnimatorState, stateData: AnimatorStateData, layerIndex: number): void { - const scripts = stateData.onStateUpdateScripts; + const scripts = state._onStateUpdateScripts; for (let i = 0, n = scripts.length; i < n; i++) { scripts[i].onStateUpdate(this, state, layerIndex); } } private _callAnimatorScriptOnExit(state: AnimatorState, stateData: AnimatorStateData, layerIndex: number): void { - const scripts = stateData.onStateExitScripts; + const scripts = state._onStateExitScripts; for (let i = 0, n = scripts.length; i < n; i++) { scripts[i].onStateExit(this, state, layerIndex); } diff --git a/packages/core/src/animation/AnimatorState.ts b/packages/core/src/animation/AnimatorState.ts index a62900967d..cfe4299099 100644 --- a/packages/core/src/animation/AnimatorState.ts +++ b/packages/core/src/animation/AnimatorState.ts @@ -13,7 +13,11 @@ export class AnimatorState { wrapMode: WrapMode = WrapMode.Loop; /** @internal */ - _scripts: StateMachineScript[] = []; + _onStateEnterScripts: StateMachineScript[] = []; + /** @internal */ + _onStateUpdateScripts: StateMachineScript[] = []; + /** @internal */ + _onStateExitScripts: StateMachineScript[] = []; private _clipStartTime: number = 0; private _clipEndTime: number = Infinity; @@ -28,7 +32,7 @@ export class AnimatorState { } /** - * ƒThe clip that is being played by this animator state. + * The clip that is being played by this animator state. */ get clip(): AnimationClip { return this._clip; @@ -92,8 +96,19 @@ export class AnimatorState { */ addStateMachineScript(scriptType: new () => T): T { const script = new scriptType(); - this._scripts.push(script); script._state = this; + + const { prototype } = StateMachineScript; + if (script.onStateEnter !== prototype.onStateEnter) { + this._onStateEnterScripts.push(script); + } + if (script.onStateUpdate !== prototype.onStateUpdate) { + this._onStateUpdateScripts.push(script); + } + if (script.onStateExit !== prototype.onStateExit) { + this._onStateExitScripts.push(script); + } + return script; } @@ -114,8 +129,19 @@ export class AnimatorState { /** * @internal */ - _removeStateMachineScript(stateMachineScript: StateMachineScript): void { - const index = this._scripts.indexOf(stateMachineScript); - index !== -1 && this._scripts.splice(index, 1); + _removeStateMachineScript(script: StateMachineScript): void { + const { prototype } = StateMachineScript; + if (script.onStateEnter !== prototype.onStateEnter) { + const index = this._onStateEnterScripts.indexOf(script); + index !== -1 && this._onStateEnterScripts.splice(index, 1); + } + if (script.onStateUpdate !== prototype.onStateUpdate) { + const index = this._onStateUpdateScripts.indexOf(script); + index !== -1 && this._onStateUpdateScripts.splice(index, 1); + } + if (script.onStateExit !== prototype.onStateExit) { + const index = this._onStateExitScripts.indexOf(script); + index !== -1 && this._onStateExitScripts.splice(index, 1); + } } } diff --git a/packages/core/src/animation/internal/AnimatorStateData.ts b/packages/core/src/animation/internal/AnimatorStateData.ts index 7eeb999dd2..e566c481c0 100644 --- a/packages/core/src/animation/internal/AnimatorStateData.ts +++ b/packages/core/src/animation/internal/AnimatorStateData.ts @@ -8,7 +8,4 @@ import { AnimationCurveOwner } from "./AnimationCurveOwner"; export class AnimatorStateData { curveOwners: AnimationCurveOwner[] = []; eventHandlers: AnimationEventHandler[] = []; - onStateEnterScripts: StateMachineScript[] = []; - onStateUpdateScripts: StateMachineScript[] = []; - onStateExitScripts: StateMachineScript[] = []; } From b6984c339202e103434d570c8fb786ee240e24a1 Mon Sep 17 00:00:00 2001 From: GuoLei1990 Date: Thu, 28 Oct 2021 17:34:56 +0800 Subject: [PATCH 34/41] refactor: opt code --- packages/core/src/animation/Animator.ts | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/packages/core/src/animation/Animator.ts b/packages/core/src/animation/Animator.ts index 85da4a4a36..24c1c9437b 100644 --- a/packages/core/src/animation/Animator.ts +++ b/packages/core/src/animation/Animator.ts @@ -445,7 +445,7 @@ export class Animator extends Component { eventHandlers.length && this._fireAnimationEvents(playData, eventHandlers, lastClipTime, clipTime); !hasTriggeredEnter && this._callAnimatorScriptOnEnter(state, stateData, layerIndex); - this._callAnimatorScriptOnUpdate(state, stateData, layerIndex); + this._callAnimatorScriptOnUpdate(state, layerIndex); for (let i = curves.length - 1; i >= 0; i--) { const owner = curveOwners[i]; @@ -460,7 +460,7 @@ export class Animator extends Component { if (playData.finished) { layerData.layerState = LayerState.Standby; - this._callAnimatorScriptOnExit(state, stateData, layerIndex); + this._callAnimatorScriptOnExit(state, layerIndex); } } @@ -497,9 +497,9 @@ export class Animator extends Component { destEventHandler.length && this._fireAnimationEvents(destPlayData, destEventHandler, lastDestClipTime, destClipTime); !hasTriggeredSrcEnter && this._callAnimatorScriptOnEnter(srcState, srcStateData, layerIndex); - this._callAnimatorScriptOnUpdate(srcState, srcStateData, layerIndex); + this._callAnimatorScriptOnUpdate(srcState, layerIndex); !hasTriggeredDestEnter && this._callAnimatorScriptOnEnter(destState, destStateData, layerIndex); - this._callAnimatorScriptOnUpdate(destState, destStateData, layerIndex); + this._callAnimatorScriptOnUpdate(destState, layerIndex); for (let i = crossCurveDataCollection.length - 1; i >= 0; i--) { const { curveOwner, srcCurveIndex, destCurveIndex } = crossCurveDataCollection[i]; @@ -517,8 +517,8 @@ export class Animator extends Component { this._applyCrossClipValue(curveOwner, srcValue, destValue, crossWeight, weight, additive); } - (crossWeight === 1 || srcPlayData.finished) && this._callAnimatorScriptOnExit(srcState, srcStateData, layerIndex); - destPlayData.finished && this._callAnimatorScriptOnExit(destState, destStateData, layerIndex); + (crossWeight === 1 || srcPlayData.finished) && this._callAnimatorScriptOnExit(srcState, layerIndex); + destPlayData.finished && this._callAnimatorScriptOnExit(destState, layerIndex); this._updateCrossFadeData(layerData, crossWeight, delta, false); } @@ -546,7 +546,7 @@ export class Animator extends Component { eventHandlers.length && this._fireAnimationEvents(destPlayData, eventHandlers, lastDestClipTime, destClipTime); !hasTriggeredEnter && this._callAnimatorScriptOnEnter(destState, stateData, layerIndex); - this._callAnimatorScriptOnUpdate(destState, stateData, layerIndex); + this._callAnimatorScriptOnUpdate(destState, layerIndex); for (let i = crossCurveDataCollection.length - 1; i >= 0; i--) { const { curveOwner, destCurveIndex } = crossCurveDataCollection[i]; @@ -558,7 +558,7 @@ export class Animator extends Component { this._applyCrossClipValue(curveOwner, curveOwner.fixedPoseValue, destValue, crossWeight, weight, additive); } - destPlayData.finished && this._callAnimatorScriptOnExit(destState, stateData, layerIndex); + destPlayData.finished && this._callAnimatorScriptOnExit(destState, layerIndex); this._updateCrossFadeData(layerData, crossWeight, delta, true); } @@ -817,14 +817,14 @@ export class Animator extends Component { } } - private _callAnimatorScriptOnUpdate(state: AnimatorState, stateData: AnimatorStateData, layerIndex: number): void { + private _callAnimatorScriptOnUpdate(state: AnimatorState, layerIndex: number): void { const scripts = state._onStateUpdateScripts; for (let i = 0, n = scripts.length; i < n; i++) { scripts[i].onStateUpdate(this, state, layerIndex); } } - private _callAnimatorScriptOnExit(state: AnimatorState, stateData: AnimatorStateData, layerIndex: number): void { + private _callAnimatorScriptOnExit(state: AnimatorState, layerIndex: number): void { const scripts = state._onStateExitScripts; for (let i = 0, n = scripts.length; i < n; i++) { scripts[i].onStateExit(this, state, layerIndex); From 473868d474b06cd5a6e3b8bc5360b5e7ff1e6063 Mon Sep 17 00:00:00 2001 From: GuoLei1990 Date: Thu, 28 Oct 2021 17:40:57 +0800 Subject: [PATCH 35/41] refactor: opt code --- packages/core/src/animation/Animator.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/core/src/animation/Animator.ts b/packages/core/src/animation/Animator.ts index 24c1c9437b..b19f624e04 100644 --- a/packages/core/src/animation/Animator.ts +++ b/packages/core/src/animation/Animator.ts @@ -532,21 +532,21 @@ export class Animator extends Component { additive: boolean ) { const crossCurveDataCollection = this._crossCurveDataCollection; - const { state: destState, stateData } = destPlayData; + const { state, stateData } = destPlayData; const { eventHandlers } = stateData; - const curves = destState.clip._curveBindings; + const curves = state.clip._curveBindings; const lastDestClipTime = destPlayData.clipTime; const hasTriggeredEnter = destPlayData.started; - let crossWeight = destPlayData.frameTime / (destState._getDuration() * layerData.crossFadeTransition.duration); + let crossWeight = destPlayData.frameTime / (state._getDuration() * layerData.crossFadeTransition.duration); crossWeight >= 1.0 && (crossWeight = 1.0); destPlayData.update(); const destClipTime = destPlayData.clipTime; eventHandlers.length && this._fireAnimationEvents(destPlayData, eventHandlers, lastDestClipTime, destClipTime); - !hasTriggeredEnter && this._callAnimatorScriptOnEnter(destState, stateData, layerIndex); - this._callAnimatorScriptOnUpdate(destState, layerIndex); + !hasTriggeredEnter && this._callAnimatorScriptOnEnter(state, stateData, layerIndex); + this._callAnimatorScriptOnUpdate(state, layerIndex); for (let i = crossCurveDataCollection.length - 1; i >= 0; i--) { const { curveOwner, destCurveIndex } = crossCurveDataCollection[i]; @@ -558,7 +558,7 @@ export class Animator extends Component { this._applyCrossClipValue(curveOwner, curveOwner.fixedPoseValue, destValue, crossWeight, weight, additive); } - destPlayData.finished && this._callAnimatorScriptOnExit(destState, layerIndex); + destPlayData.finished && this._callAnimatorScriptOnExit(state, layerIndex); this._updateCrossFadeData(layerData, crossWeight, delta, true); } From 978845b7add0654db088f0257bec43f40b442e78 Mon Sep 17 00:00:00 2001 From: GuoLei1990 Date: Thu, 28 Oct 2021 18:14:16 +0800 Subject: [PATCH 36/41] refactor: opt code --- packages/core/src/animation/Animator.ts | 35 ++++++++++++------- .../animation/enums/AnimatorStatePlayState.ts | 8 +++++ .../internal/AnimatorStatePlayData.ts | 11 +++--- 3 files changed, 35 insertions(+), 19 deletions(-) create mode 100644 packages/core/src/animation/enums/AnimatorStatePlayState.ts diff --git a/packages/core/src/animation/Animator.ts b/packages/core/src/animation/Animator.ts index b19f624e04..014f02a781 100644 --- a/packages/core/src/animation/Animator.ts +++ b/packages/core/src/animation/Animator.ts @@ -13,6 +13,7 @@ import { AnimatorStateTransition } from "./AnimatorTransition"; import { AnimatorUtils } from "./AnimatorUtils"; import { AnimationProperty } from "./enums/AnimationProperty"; import { AnimatorLayerBlendingMode } from "./enums/AnimatorLayerBlendingMode"; +import { AnimatorStatePlayState } from "./enums/AnimatorStatePlayState"; import { LayerState } from "./enums/LayerState"; import { AnimationCurveOwner } from "./internal/AnimationCurveOwner"; import { AnimationEventHandler } from "./internal/AnimationEventHandler"; @@ -437,14 +438,14 @@ export class Animator extends Component { const { state, stateData } = playData; const { _curveBindings: curves } = state.clip; const lastClipTime = playData.clipTime; - const hasTriggeredEnter = playData.started; + const playState = playData.playState; playData.update(); const clipTime = playData.clipTime; eventHandlers.length && this._fireAnimationEvents(playData, eventHandlers, lastClipTime, clipTime); - !hasTriggeredEnter && this._callAnimatorScriptOnEnter(state, stateData, layerIndex); + playState === AnimatorStatePlayState.UnStarted && this._callAnimatorScriptOnEnter(state, stateData, layerIndex); this._callAnimatorScriptOnUpdate(state, layerIndex); for (let i = curves.length - 1; i >= 0; i--) { @@ -458,7 +459,7 @@ export class Animator extends Component { } playData.frameTime += state.speed * delta; - if (playData.finished) { + if (playState === AnimatorStatePlayState.Finished) { layerData.layerState = LayerState.Standby; this._callAnimatorScriptOnExit(state, layerIndex); } @@ -482,8 +483,8 @@ export class Animator extends Component { const destCurves = destState.clip._curveBindings; const lastSrcClipTime = srcPlayData.clipTime; const lastDestClipTime = destPlayData.clipTime; - const hasTriggeredSrcEnter = srcPlayData.started; - const hasTriggeredDestEnter = destPlayData.started; + const srcPlayState = srcPlayData.playState; + const dstPlayState = destPlayData.playState; let crossWeight = destPlayData.frameTime / (destState._getDuration() * layerData.crossFadeTransition.duration); crossWeight >= 1.0 && (crossWeight = 1.0); @@ -496,9 +497,15 @@ export class Animator extends Component { srcEventHandler.length && this._fireAnimationEvents(srcPlayData, srcEventHandler, lastSrcClipTime, srcClipTime); destEventHandler.length && this._fireAnimationEvents(destPlayData, destEventHandler, lastDestClipTime, destClipTime); - !hasTriggeredSrcEnter && this._callAnimatorScriptOnEnter(srcState, srcStateData, layerIndex); + + if (srcPlayState === AnimatorStatePlayState.UnStarted) { + this._callAnimatorScriptOnEnter(srcState, srcStateData, layerIndex); + } this._callAnimatorScriptOnUpdate(srcState, layerIndex); - !hasTriggeredDestEnter && this._callAnimatorScriptOnEnter(destState, destStateData, layerIndex); + + if (dstPlayState === AnimatorStatePlayState.UnStarted) { + this._callAnimatorScriptOnEnter(destState, destStateData, layerIndex); + } this._callAnimatorScriptOnUpdate(destState, layerIndex); for (let i = crossCurveDataCollection.length - 1; i >= 0; i--) { @@ -517,8 +524,10 @@ export class Animator extends Component { this._applyCrossClipValue(curveOwner, srcValue, destValue, crossWeight, weight, additive); } - (crossWeight === 1 || srcPlayData.finished) && this._callAnimatorScriptOnExit(srcState, layerIndex); - destPlayData.finished && this._callAnimatorScriptOnExit(destState, layerIndex); + if (crossWeight === 1 || srcPlayState === AnimatorStatePlayState.Finished) { + this._callAnimatorScriptOnExit(srcState, layerIndex); + } + dstPlayState === AnimatorStatePlayState.Finished && this._callAnimatorScriptOnExit(destState, layerIndex); this._updateCrossFadeData(layerData, crossWeight, delta, false); } @@ -536,7 +545,7 @@ export class Animator extends Component { const { eventHandlers } = stateData; const curves = state.clip._curveBindings; const lastDestClipTime = destPlayData.clipTime; - const hasTriggeredEnter = destPlayData.started; + const playState = destPlayData.playState; let crossWeight = destPlayData.frameTime / (state._getDuration() * layerData.crossFadeTransition.duration); crossWeight >= 1.0 && (crossWeight = 1.0); @@ -545,7 +554,7 @@ export class Animator extends Component { const destClipTime = destPlayData.clipTime; eventHandlers.length && this._fireAnimationEvents(destPlayData, eventHandlers, lastDestClipTime, destClipTime); - !hasTriggeredEnter && this._callAnimatorScriptOnEnter(state, stateData, layerIndex); + playState === AnimatorStatePlayState.UnStarted && this._callAnimatorScriptOnEnter(state, stateData, layerIndex); this._callAnimatorScriptOnUpdate(state, layerIndex); for (let i = crossCurveDataCollection.length - 1; i >= 0; i--) { @@ -558,7 +567,7 @@ export class Animator extends Component { this._applyCrossClipValue(curveOwner, curveOwner.fixedPoseValue, destValue, crossWeight, weight, additive); } - destPlayData.finished && this._callAnimatorScriptOnExit(state, layerIndex); + playState === AnimatorStatePlayState.Finished && this._callAnimatorScriptOnExit(state, layerIndex); this._updateCrossFadeData(layerData, crossWeight, delta, true); } @@ -567,7 +576,7 @@ export class Animator extends Component { const { destPlayData } = layerData; destPlayData.frameTime += destPlayData.state.speed * delta; if (crossWeight === 1.0) { - if (destPlayData.finished) { + if (destPlayData.playState === AnimatorStatePlayState.Finished) { layerData.layerState = LayerState.Standby; } else { layerData.layerState = LayerState.Playing; diff --git a/packages/core/src/animation/enums/AnimatorStatePlayState.ts b/packages/core/src/animation/enums/AnimatorStatePlayState.ts new file mode 100644 index 0000000000..779713f2a4 --- /dev/null +++ b/packages/core/src/animation/enums/AnimatorStatePlayState.ts @@ -0,0 +1,8 @@ +/** + * @internal + */ +export enum AnimatorStatePlayState { + UnStarted, + Playing, + Finished +} diff --git a/packages/core/src/animation/internal/AnimatorStatePlayData.ts b/packages/core/src/animation/internal/AnimatorStatePlayData.ts index bf83f8817f..69116512ab 100644 --- a/packages/core/src/animation/internal/AnimatorStatePlayData.ts +++ b/packages/core/src/animation/internal/AnimatorStatePlayData.ts @@ -1,4 +1,5 @@ import { AnimatorState } from "../AnimatorState"; +import { AnimatorStatePlayState } from "../enums/AnimatorStatePlayState"; import { WrapMode } from "../enums/WrapMode"; import { AnimatorStateData } from "./AnimatorStateData"; @@ -9,8 +10,7 @@ export class AnimatorStatePlayData { state: AnimatorState; stateData: AnimatorStateData; frameTime: number; - started: boolean; - finished: boolean; + playState: AnimatorStatePlayState; clipTime: number; currentEventIndex: number; @@ -18,7 +18,7 @@ export class AnimatorStatePlayData { this.state = state; this.frameTime = offsetFrameTime; this.stateData = stateData; - this.finished = false; + this.playState = AnimatorStatePlayState.UnStarted; this.clipTime = this.state.clipStartTime; this.currentEventIndex = 0; } @@ -27,14 +27,13 @@ export class AnimatorStatePlayData { const state = this.state; let time = this.frameTime; const duration = state.clipEndTime - state.clipStartTime; - this.started = true; + this.playState = AnimatorStatePlayState.Playing; if (time > duration) { if (state.wrapMode === WrapMode.Loop) { time = time % duration; } else { time = duration; - this.finished = true; - this.started = false; + this.playState = AnimatorStatePlayState.Finished; } } this.clipTime = time + this.state.clipStartTime; From c727d338cb5ced6734a42de2e8d2ef5a1bcb3726 Mon Sep 17 00:00:00 2001 From: GuoLei1990 Date: Thu, 28 Oct 2021 18:26:11 +0800 Subject: [PATCH 37/41] refactor: opt code --- packages/core/src/animation/Animator.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/core/src/animation/Animator.ts b/packages/core/src/animation/Animator.ts index 014f02a781..6791f86ff1 100644 --- a/packages/core/src/animation/Animator.ts +++ b/packages/core/src/animation/Animator.ts @@ -445,7 +445,7 @@ export class Animator extends Component { const clipTime = playData.clipTime; eventHandlers.length && this._fireAnimationEvents(playData, eventHandlers, lastClipTime, clipTime); - playState === AnimatorStatePlayState.UnStarted && this._callAnimatorScriptOnEnter(state, stateData, layerIndex); + playState === AnimatorStatePlayState.UnStarted && this._callAnimatorScriptOnEnter(state, layerIndex); this._callAnimatorScriptOnUpdate(state, layerIndex); for (let i = curves.length - 1; i >= 0; i--) { @@ -499,12 +499,12 @@ export class Animator extends Component { this._fireAnimationEvents(destPlayData, destEventHandler, lastDestClipTime, destClipTime); if (srcPlayState === AnimatorStatePlayState.UnStarted) { - this._callAnimatorScriptOnEnter(srcState, srcStateData, layerIndex); + this._callAnimatorScriptOnEnter(srcState, layerIndex); } this._callAnimatorScriptOnUpdate(srcState, layerIndex); if (dstPlayState === AnimatorStatePlayState.UnStarted) { - this._callAnimatorScriptOnEnter(destState, destStateData, layerIndex); + this._callAnimatorScriptOnEnter(destState, layerIndex); } this._callAnimatorScriptOnUpdate(destState, layerIndex); @@ -554,7 +554,7 @@ export class Animator extends Component { const destClipTime = destPlayData.clipTime; eventHandlers.length && this._fireAnimationEvents(destPlayData, eventHandlers, lastDestClipTime, destClipTime); - playState === AnimatorStatePlayState.UnStarted && this._callAnimatorScriptOnEnter(state, stateData, layerIndex); + playState === AnimatorStatePlayState.UnStarted && this._callAnimatorScriptOnEnter(state, layerIndex); this._callAnimatorScriptOnUpdate(state, layerIndex); for (let i = crossCurveDataCollection.length - 1; i >= 0; i--) { @@ -819,7 +819,7 @@ export class Animator extends Component { } } - private _callAnimatorScriptOnEnter(state: AnimatorState, stateData: AnimatorStateData, layerIndex: number): void { + private _callAnimatorScriptOnEnter(state: AnimatorState, layerIndex: number): void { const scripts = state._onStateEnterScripts; for (let i = 0, n = scripts.length; i < n; i++) { scripts[i].onStateEnter(this, state, layerIndex); From 4ae43d53884bb4cd349c492d56965b8b9092c15a Mon Sep 17 00:00:00 2001 From: GuoLei1990 Date: Thu, 28 Oct 2021 18:37:44 +0800 Subject: [PATCH 38/41] refactor: opt code --- packages/core/src/animation/Animator.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/core/src/animation/Animator.ts b/packages/core/src/animation/Animator.ts index 6791f86ff1..b369049c15 100644 --- a/packages/core/src/animation/Animator.ts +++ b/packages/core/src/animation/Animator.ts @@ -435,7 +435,7 @@ export class Animator extends Component { additive: boolean ): void { const { curveOwners, eventHandlers } = playData.stateData; - const { state, stateData } = playData; + const { state } = playData; const { _curveBindings: curves } = state.clip; const lastClipTime = playData.clipTime; const playState = playData.playState; From fcdead5b4a825709717551fbe807d54220ca70a6 Mon Sep 17 00:00:00 2001 From: GuoLei1990 Date: Thu, 28 Oct 2021 22:25:59 +0800 Subject: [PATCH 39/41] refactor: opt code --- packages/core/src/animation/Animator.ts | 77 ++++++++++++++----------- 1 file changed, 42 insertions(+), 35 deletions(-) diff --git a/packages/core/src/animation/Animator.ts b/packages/core/src/animation/Animator.ts index b369049c15..3c21aa0f4a 100644 --- a/packages/core/src/animation/Animator.ts +++ b/packages/core/src/animation/Animator.ts @@ -435,18 +435,23 @@ export class Animator extends Component { additive: boolean ): void { const { curveOwners, eventHandlers } = playData.stateData; - const { state } = playData; + const { state, playState: lastPlayState, clipTime: lastClipTime } = playData; const { _curveBindings: curves } = state.clip; - const lastClipTime = playData.clipTime; - const playState = playData.playState; playData.update(); - const clipTime = playData.clipTime; + const { clipTime, playState } = playData; eventHandlers.length && this._fireAnimationEvents(playData, eventHandlers, lastClipTime, clipTime); - playState === AnimatorStatePlayState.UnStarted && this._callAnimatorScriptOnEnter(state, layerIndex); - this._callAnimatorScriptOnUpdate(state, layerIndex); + + if (lastPlayState === AnimatorStatePlayState.UnStarted) { + this._callAnimatorScriptOnEnter(state, layerIndex); + } + if (playState === AnimatorStatePlayState.Finished) { + this._callAnimatorScriptOnExit(state, layerIndex); + } else { + this._callAnimatorScriptOnUpdate(state, layerIndex); + } for (let i = curves.length - 1; i >= 0; i--) { const owner = curveOwners[i]; @@ -461,7 +466,6 @@ export class Animator extends Component { if (playState === AnimatorStatePlayState.Finished) { layerData.layerState = LayerState.Standby; - this._callAnimatorScriptOnExit(state, layerIndex); } } @@ -476,37 +480,43 @@ export class Animator extends Component { ) { const crossCurveDataCollection = this._crossCurveDataCollection; const srcCurves = srcPlayData.state.clip._curveBindings; - const { state: srcState, stateData: srcStateData } = srcPlayData; + const { state: srcState, stateData: srcStateData, playState: lastSrcPlayState } = srcPlayData; const { eventHandlers: srcEventHandler } = srcStateData; - const { state: destState, stateData: destStateData } = destPlayData; + const { state: destState, stateData: destStateData, playState: lastDstPlayState } = destPlayData; const { eventHandlers: destEventHandler } = destStateData; - const destCurves = destState.clip._curveBindings; - const lastSrcClipTime = srcPlayData.clipTime; - const lastDestClipTime = destPlayData.clipTime; - const srcPlayState = srcPlayData.playState; - const dstPlayState = destPlayData.playState; + const { _curveBindings: destCurves } = destState.clip; + const { clipTime: lastSrcClipTime } = srcPlayData; + const { clipTime: lastDestClipTime } = destPlayData; let crossWeight = destPlayData.frameTime / (destState._getDuration() * layerData.crossFadeTransition.duration); crossWeight >= 1.0 && (crossWeight = 1.0); srcPlayData.update(); destPlayData.update(); - const srcClipTime = srcPlayData.clipTime; - const destClipTime = destPlayData.clipTime; + const { clipTime: srcClipTime } = srcPlayData; + const { clipTime: destClipTime } = destPlayData; srcEventHandler.length && this._fireAnimationEvents(srcPlayData, srcEventHandler, lastSrcClipTime, srcClipTime); destEventHandler.length && this._fireAnimationEvents(destPlayData, destEventHandler, lastDestClipTime, destClipTime); - if (srcPlayState === AnimatorStatePlayState.UnStarted) { + if (lastSrcPlayState === AnimatorStatePlayState.UnStarted) { this._callAnimatorScriptOnEnter(srcState, layerIndex); } - this._callAnimatorScriptOnUpdate(srcState, layerIndex); + if (crossWeight === 1 || srcPlayData.playState === AnimatorStatePlayState.Finished) { + this._callAnimatorScriptOnExit(srcState, layerIndex); + } else { + this._callAnimatorScriptOnUpdate(srcState, layerIndex); + } - if (dstPlayState === AnimatorStatePlayState.UnStarted) { + if (lastDstPlayState === AnimatorStatePlayState.UnStarted) { this._callAnimatorScriptOnEnter(destState, layerIndex); } - this._callAnimatorScriptOnUpdate(destState, layerIndex); + if (destPlayData.playState === AnimatorStatePlayState.Finished) { + this._callAnimatorScriptOnExit(destState, layerIndex); + } else { + this._callAnimatorScriptOnUpdate(destState, layerIndex); + } for (let i = crossCurveDataCollection.length - 1; i >= 0; i--) { const { curveOwner, srcCurveIndex, destCurveIndex } = crossCurveDataCollection[i]; @@ -523,12 +533,6 @@ export class Animator extends Component { this._applyCrossClipValue(curveOwner, srcValue, destValue, crossWeight, weight, additive); } - - if (crossWeight === 1 || srcPlayState === AnimatorStatePlayState.Finished) { - this._callAnimatorScriptOnExit(srcState, layerIndex); - } - dstPlayState === AnimatorStatePlayState.Finished && this._callAnimatorScriptOnExit(destState, layerIndex); - this._updateCrossFadeData(layerData, crossWeight, delta, false); } @@ -541,21 +545,26 @@ export class Animator extends Component { additive: boolean ) { const crossCurveDataCollection = this._crossCurveDataCollection; - const { state, stateData } = destPlayData; + const { state, stateData, playState: lastPlayState } = destPlayData; const { eventHandlers } = stateData; - const curves = state.clip._curveBindings; - const lastDestClipTime = destPlayData.clipTime; - const playState = destPlayData.playState; + const { _curveBindings: curves } = state.clip; + const { clipTime: lastDestClipTime } = destPlayData; let crossWeight = destPlayData.frameTime / (state._getDuration() * layerData.crossFadeTransition.duration); crossWeight >= 1.0 && (crossWeight = 1.0); destPlayData.update(); - const destClipTime = destPlayData.clipTime; + const { clipTime: destClipTime } = destPlayData; eventHandlers.length && this._fireAnimationEvents(destPlayData, eventHandlers, lastDestClipTime, destClipTime); - playState === AnimatorStatePlayState.UnStarted && this._callAnimatorScriptOnEnter(state, layerIndex); - this._callAnimatorScriptOnUpdate(state, layerIndex); + if (lastPlayState === AnimatorStatePlayState.UnStarted) { + this._callAnimatorScriptOnEnter(state, layerIndex); + } + if (destPlayData.playState === AnimatorStatePlayState.Finished) { + this._callAnimatorScriptOnExit(state, layerIndex); + } else { + this._callAnimatorScriptOnUpdate(state, layerIndex); + } for (let i = crossCurveDataCollection.length - 1; i >= 0; i--) { const { curveOwner, destCurveIndex } = crossCurveDataCollection[i]; @@ -567,8 +576,6 @@ export class Animator extends Component { this._applyCrossClipValue(curveOwner, curveOwner.fixedPoseValue, destValue, crossWeight, weight, additive); } - playState === AnimatorStatePlayState.Finished && this._callAnimatorScriptOnExit(state, layerIndex); - this._updateCrossFadeData(layerData, crossWeight, delta, true); } From c25ed7ba34d6b5eab6a1800ab019d980c0b547b4 Mon Sep 17 00:00:00 2001 From: GuoLei1990 Date: Thu, 28 Oct 2021 22:28:25 +0800 Subject: [PATCH 40/41] refactor: opt code --- packages/core/src/animation/Animator.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/core/src/animation/Animator.ts b/packages/core/src/animation/Animator.ts index 3c21aa0f4a..e6c1b87fae 100644 --- a/packages/core/src/animation/Animator.ts +++ b/packages/core/src/animation/Animator.ts @@ -478,8 +478,8 @@ export class Animator extends Component { delta: number, additive: boolean ) { - const crossCurveDataCollection = this._crossCurveDataCollection; - const srcCurves = srcPlayData.state.clip._curveBindings; + const { _crossCurveDataCollection: crossCurveDataCollection } = this; + const { _curveBindings: srcCurves } = srcPlayData.state.clip; const { state: srcState, stateData: srcStateData, playState: lastSrcPlayState } = srcPlayData; const { eventHandlers: srcEventHandler } = srcStateData; const { state: destState, stateData: destStateData, playState: lastDstPlayState } = destPlayData; From a4ceeab4425fe07d7adc36ae01d8d714919484fa Mon Sep 17 00:00:00 2001 From: luzhuang <364439895@qq.com> Date: Fri, 29 Oct 2021 15:50:01 +0800 Subject: [PATCH 41/41] feat: merge opt --- packages/core/src/animation/Animator.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/core/src/animation/Animator.ts b/packages/core/src/animation/Animator.ts index e6c1b87fae..2a12e48ba2 100644 --- a/packages/core/src/animation/Animator.ts +++ b/packages/core/src/animation/Animator.ts @@ -557,6 +557,7 @@ export class Animator extends Component { const { clipTime: destClipTime } = destPlayData; eventHandlers.length && this._fireAnimationEvents(destPlayData, eventHandlers, lastDestClipTime, destClipTime); + if (lastPlayState === AnimatorStatePlayState.UnStarted) { this._callAnimatorScriptOnEnter(state, layerIndex); }