From aa12248d8636ee3f4bf5a0c4e46c88ec5454d601 Mon Sep 17 00:00:00 2001 From: D8H Date: Wed, 27 Nov 2024 14:54:45 +0100 Subject: [PATCH] Fix custom objects inner area expansion on Z axis (#7200) --- Extensions/3D/CustomRuntimeObject3D.ts | 53 ++++++++++++++++++++++++-- 1 file changed, 50 insertions(+), 3 deletions(-) diff --git a/Extensions/3D/CustomRuntimeObject3D.ts b/Extensions/3D/CustomRuntimeObject3D.ts index 906cd55750fe..47a82ab1a243 100644 --- a/Extensions/3D/CustomRuntimeObject3D.ts +++ b/Extensions/3D/CustomRuntimeObject3D.ts @@ -112,10 +112,25 @@ namespace gdjs { * @return The Z position of the rendered object. */ getDrawableZ(): float { - if (this._isUntransformedHitBoxesDirty) { - this._updateUntransformedHitBoxes(); + let minZ = 0; + if (this._innerArea) { + minZ = this._innerArea.min[2]; + } else { + if (this._isUntransformedHitBoxesDirty) { + this._updateUntransformedHitBoxes(); + } + minZ = this._minZ; + } + const absScaleZ = this.getScaleZ(); + if (!this._flippedZ) { + return this._z + minZ * absScaleZ; + } else { + return ( + this._z + + (-minZ - this.getUnscaledDepth() + 2 * this.getUnscaledCenterZ()) * + absScaleZ + ); } - return this._z + this._minZ; } /** @@ -238,10 +253,39 @@ namespace gdjs { this.setAngle(gdjs.toDegrees(mesh.rotation.z)); } + /** + * @return the internal top bound of the object according to its children. + */ + getInnerAreaMinZ(): number { + if (this._innerArea) { + return this._innerArea.min[2]; + } + if (this._isUntransformedHitBoxesDirty) { + this._updateUntransformedHitBoxes(); + } + return this._minZ; + } + + /** + * @return the internal bottom bound of the object according to its children. + */ + getInnerAreaMaxZ(): number { + if (this._innerArea) { + return this._innerArea.max[2]; + } + if (this._isUntransformedHitBoxesDirty) { + this._updateUntransformedHitBoxes(); + } + return this._maxZ; + } + /** * @return the internal width of the object according to its children. */ getUnscaledDepth(): float { + if (this._innerArea) { + return this._innerArea.max[2] - this._innerArea.min[2]; + } if (this._isUntransformedHitBoxesDirty) { this._updateUntransformedHitBoxes(); } @@ -280,6 +324,9 @@ namespace gdjs { if (this.hasCustomRotationCenter()) { return this._customCenterZ; } + if (this._innerArea) { + return (this._innerArea.min[2] + this._innerArea.max[2]) / 2; + } if (this._isUntransformedHitBoxesDirty) { this._updateUntransformedHitBoxes(); }