From e1452f9bdeadbed0ea7e15c2c48b577e36538b8e Mon Sep 17 00:00:00 2001 From: lealzhan Date: Tue, 19 Sep 2023 15:05:57 +0800 Subject: [PATCH] xx --- cocos/physics/utils/util.ts | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/cocos/physics/utils/util.ts b/cocos/physics/utils/util.ts index ead93adcf0e..cd2c5c6c661 100644 --- a/cocos/physics/utils/util.ts +++ b/cocos/physics/utils/util.ts @@ -22,7 +22,7 @@ THE SOFTWARE. */ -import { equals, Vec3, IVec3Like } from '../../core'; +import { equals, Vec3, IVec3Like, murmurhash2_32_gc } from '../../core'; import { CharacterController, CharacterTriggerEventType, Collider, CollisionEventType, IContactEquation, TriggerEventType } from '../framework'; export { cylinder } from '../../primitive'; @@ -69,23 +69,21 @@ export const CollisionEventObject = { export function shrinkPositions (buffer: Float32Array | number[]): number[] { const pos: number[] = []; + const posHashMap = {}; if (buffer.length >= 3) { - // eslint-disable-next-line no-unused-expressions - pos[0] = buffer[0], pos[1] = buffer[1], pos[2] = buffer[2]; + pos[0] = buffer[0]; + pos[1] = buffer[1]; + pos[2] = buffer[2]; const len = buffer.length; for (let i = 3; i < len; i += 3) { const p0 = buffer[i]; const p1 = buffer[i + 1]; const p2 = buffer[i + 2]; - const len2 = pos.length; - let isNew = true; - for (let j = 0; j < len2; j += 3) { - if (equals(p0, pos[j]) && equals(p1, pos[j + 1]) && equals(p2, pos[j + 2])) { - isNew = false; - break; - } - } - if (isNew) { + const str = String(p0) + String(p1) + String(p2); + //todo: directly use buffer as input + const hash = murmurhash2_32_gc(str, 666); + if (posHashMap[hash] !== str) { + posHashMap[hash] = str; pos.push(p0); pos.push(p1); pos.push(p2); } }