diff --git a/cocos/2d/assembler/label/ttf.ts b/cocos/2d/assembler/label/ttf.ts index f1de2e6fd2b..0d2a006de86 100644 --- a/cocos/2d/assembler/label/ttf.ts +++ b/cocos/2d/assembler/label/ttf.ts @@ -81,7 +81,7 @@ export const ttf: IAssembler = { const x = curData.x; const y = curData.y; let rhw = m.m03 * x + m.m07 * y + m.m15; - rhw = rhw ? Math.abs(1 / rhw) : 1; + rhw = rhw ? 1 / rhw : 1; offset = i * stride; vData[offset + 0] = (m.m00 * x + m.m04 * y + m.m12) * rhw; diff --git a/cocos/2d/assembler/sprite/bar-filled.ts b/cocos/2d/assembler/sprite/bar-filled.ts index 8c9c816e6a5..b0244832800 100644 --- a/cocos/2d/assembler/sprite/bar-filled.ts +++ b/cocos/2d/assembler/sprite/bar-filled.ts @@ -224,7 +224,7 @@ export const barFilled: IAssembler = { const x = local.x; const y = local.y; let rhw = m.m03 * x + m.m07 * y + m.m15; - rhw = rhw ? Math.abs(1 / rhw) : 1; + rhw = rhw ? 1 / rhw : 1; offset = i * stride; vData[offset] = (m.m00 * x + m.m04 * y + m.m12) * rhw; diff --git a/cocos/2d/assembler/sprite/radial-filled.ts b/cocos/2d/assembler/sprite/radial-filled.ts index d41dbc35662..e0830329585 100644 --- a/cocos/2d/assembler/sprite/radial-filled.ts +++ b/cocos/2d/assembler/sprite/radial-filled.ts @@ -421,7 +421,7 @@ export const radialFilled: IAssembler = { const x = vert.x; const y = vert.y; let rhw = m.m03 * x + m.m07 * y + m.m15; - rhw = rhw ? Math.abs(1 / rhw) : 1; + rhw = rhw ? 1 / rhw : 1; vData[vertexOffset + 0] = (m.m00 * x + m.m04 * y + m.m12) * rhw; vData[vertexOffset + 1] = (m.m01 * x + m.m05 * y + m.m13) * rhw; diff --git a/cocos/2d/assembler/sprite/simple.ts b/cocos/2d/assembler/sprite/simple.ts index 10703f267ec..c214a2a31e6 100644 --- a/cocos/2d/assembler/sprite/simple.ts +++ b/cocos/2d/assembler/sprite/simple.ts @@ -83,7 +83,7 @@ export const simple: IAssembler = { const x = curData.x; const y = curData.y; let rhw = m.m03 * x + m.m07 * y + m.m15; - rhw = rhw ? Math.abs(1 / rhw) : 1; + rhw = rhw ? 1 / rhw : 1; offset = i * stride; vData[offset + 0] = (m.m00 * x + m.m04 * y + m.m12) * rhw; diff --git a/cocos/2d/assembler/sprite/sliced.ts b/cocos/2d/assembler/sprite/sliced.ts index 1019806a5e9..0d4be8aef0c 100644 --- a/cocos/2d/assembler/sprite/sliced.ts +++ b/cocos/2d/assembler/sprite/sliced.ts @@ -197,7 +197,7 @@ export const sliced: IAssembler = { const x = colD.x; const y = rowD.y; let rhw = m.m03 * x + m.m07 * y + m.m15; - rhw = rhw ? Math.abs(1 / rhw) : 1; + rhw = rhw ? 1 / rhw : 1; offset = (row * 4 + col) * stride; vData[offset + 0] = (m.m00 * x + m.m04 * y + m.m12) * rhw; diff --git a/cocos/2d/assembler/sprite/tiled.ts b/cocos/2d/assembler/sprite/tiled.ts index 79a961ede69..699548e8002 100644 --- a/cocos/2d/assembler/sprite/tiled.ts +++ b/cocos/2d/assembler/sprite/tiled.ts @@ -205,7 +205,7 @@ export const tiled: IAssembler = { const y = dataList[i].y; const z = dataList[i].z; let rhw = m.m03 * x + m.m07 * y + m.m11 * z + m.m15; - rhw = rhw ? Math.abs(1 / rhw) : 1; + rhw = rhw ? 1 / rhw : 1; const offset = i * stride; vData[offset] = (m.m00 * x + m.m04 * y + m.m08 * z + m.m12) * rhw; diff --git a/cocos/2d/assembler/utils.ts b/cocos/2d/assembler/utils.ts index edd862d5284..af17bbd4eca 100644 --- a/cocos/2d/assembler/utils.ts +++ b/cocos/2d/assembler/utils.ts @@ -44,7 +44,7 @@ export function fillMeshVertices3D (node: Node, renderer: IBatcher, renderData: const x = vert.x; const y = vert.y; let rhw = m.m03 * x + m.m07 * y + m.m15; - rhw = rhw ? Math.abs(1 / rhw) : 1; + rhw = rhw ? 1 / rhw : 1; vData[vertexOffset + 0] = (m.m00 * x + m.m04 * y + m.m12) * rhw; vData[vertexOffset + 1] = (m.m01 * x + m.m05 * y + m.m13) * rhw; vData[vertexOffset + 2] = (m.m02 * x + m.m06 * y + m.m14) * rhw; diff --git a/cocos/core/math/vec3.ts b/cocos/core/math/vec3.ts index 0400c544dda..ebf844cf2f5 100644 --- a/cocos/core/math/vec3.ts +++ b/cocos/core/math/vec3.ts @@ -456,9 +456,7 @@ export class Vec3 extends ValueType { const y = a.y; const z = a.z; let rhw = m.m03 * x + m.m07 * y + m.m11 * z + m.m15; - // Important note by stanley: - // Math.abs needs to be removed later, because the operation will generate a wrong homogeneous coordinate - rhw = rhw ? Math.abs(1 / rhw) : 1; + rhw = rhw ? 1 / rhw : 1; out.x = (m.m00 * x + m.m04 * y + m.m08 * z + m.m12) * rhw; out.y = (m.m01 * x + m.m05 * y + m.m09 * z + m.m13) * rhw; out.z = (m.m02 * x + m.m06 * y + m.m10 * z + m.m14) * rhw; @@ -474,9 +472,7 @@ export class Vec3 extends ValueType { const y = a.y; const z = a.z; let rhw = m.m03 * x + m.m07 * y + m.m11 * z; - // Important note by stanley: - // Math.abs needs to be removed later, because the operation will generate a wrong homogeneous coordinate - rhw = rhw ? Math.abs(1 / rhw) : 1; + rhw = rhw ? 1 / rhw : 1; out.x = (m.m00 * x + m.m04 * y + m.m08 * z) * rhw; out.y = (m.m01 * x + m.m05 * y + m.m09 * z) * rhw; out.z = (m.m02 * x + m.m06 * y + m.m10 * z) * rhw; diff --git a/native/cocos/math/Vec3.cpp b/native/cocos/math/Vec3.cpp index e4f6ae1270c..8296db2a3c2 100644 --- a/native/cocos/math/Vec3.cpp +++ b/native/cocos/math/Vec3.cpp @@ -280,9 +280,7 @@ void Vec3::transformMat4Normal(const Vec3 &v, const Mat4 &m, Vec3 *dst) { float y = v.y; float z = v.z; float rhw = m.m[3] * x + m.m[7] * y + m.m[11] * z; - // Important note by stanley: - // abs needs to be removed later, because the operation will generate a wrong homogeneous coordinate - rhw = rhw != 0.0F ? std::abs(1.0F / rhw) : 1.0F; + rhw = (rhw != 0.0F ? 1.0F / rhw : 1.0F); dst->x = (m.m[0] * x + m.m[4] * y + m.m[8] * z) * rhw; dst->y = (m.m[1] * x + m.m[5] * y + m.m[9] * z) * rhw; dst->z = (m.m[2] * x + m.m[6] * y + m.m[10] * z) * rhw;