From 4e659c8a5b876106ac33f937af60f1367f9be68c Mon Sep 17 00:00:00 2001 From: luzhuang <364439895@qq.com> Date: Thu, 2 Jan 2025 11:33:59 +0800 Subject: [PATCH] Support destroy physicsMaterial (#2481) * feat: support destroy physicsMaterial --- packages/core/src/physics/PhysicsMaterial.ts | 4 ++-- tests/src/core/physics/PhysicsMaterial.test.ts | 8 ++++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/packages/core/src/physics/PhysicsMaterial.ts b/packages/core/src/physics/PhysicsMaterial.ts index f997e7869..382e46904 100644 --- a/packages/core/src/physics/PhysicsMaterial.ts +++ b/packages/core/src/physics/PhysicsMaterial.ts @@ -97,9 +97,9 @@ export class PhysicsMaterial { } /** - * @internal + * Destroy the material when the material is no be used by any shape. */ - _destroy() { + destroy() { !this._destroyed && this._nativeMaterial.destroy(); this._destroyed = true; } diff --git a/tests/src/core/physics/PhysicsMaterial.test.ts b/tests/src/core/physics/PhysicsMaterial.test.ts index ca26f85c3..43b0daa44 100644 --- a/tests/src/core/physics/PhysicsMaterial.test.ts +++ b/tests/src/core/physics/PhysicsMaterial.test.ts @@ -486,4 +486,12 @@ describe("PhysicsMaterial", () => { engine.sceneManager.activeScene.physics._update(1); expect(formatValue(boxEntity2.transform.position.z)).eq(0.57139); }); + + it("destroy", () => { + const physicsMaterial = new PhysicsMaterial(); + physicsMaterial.destroy(); + expect(() => { + physicsMaterial.bounciness = 1; + }).toThrowError(); + }); });