/
githubmirror
/
pixijs
Обзор
Документация
Войти
/
githubmirror
/
pixijs
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
dev
src/unsafe-eval/particle/generateParticleUpdatePolyfill.ts
60 строк
2 KB
Arne Westphal
Fix unsafe-eval particle update polyfill (#11643)
01 сен 2025, 11:03
Не верифицирован
01 сен 2025, 11:03
4c7875d
Код
Авторство
О чём код?
import { getAttributeInfoFromFormat } from '../../rendering/renderers/shared/geometry/utils/getAttributeInfoFromFormat'; import { particleUpdateFunctions } from './particleUpdateFunctions'; import type { IParticle } from '../../scene/particle-container/shared/Particle'; import type { ParticleRendererProperty } from '../../scene/particle-container/shared/particleData'; // eslint-disable-next-line max-len type ParticleUpdateFunction = (ps: IParticle[], f32v: Float32Array, u32v: Uint32Array, offset: number, stride: number) => void; /** * @param properties * @internal */ export function generateParticleUpdatePolyfill(properties: Record<string, ParticleRendererProperty>) { const allProperties = Object.values(properties); const dynamicProperties = allProperties.filter((p) => p.dynamic); const staticProperties = allProperties.filter((p) => !p.dynamic); return { dynamicUpdate: generateUpdateFunction(dynamicProperties), staticUpdate: generateUpdateFunction(staticProperties), }; } function generateUpdateFunction(properties: ParticleRendererProperty[]): ParticleUpdateFunction { let stride = 0; const updateData: { stride: number; updateFunction: ParticleUpdateFunction }[] = []; for (let i = 0; i < properties.length; i++) { const property = properties[i]; const attributeStride = getAttributeInfoFromFormat(property.format).stride / 4; stride += attributeStride; updateData.push({ stride: attributeStride, updateFunction: property.updateFunction || particleUpdateFunctions[property.attributeName as keyof typeof particleUpdateFunctions] }); } return (ps: IParticle[], f32v: Float32Array, u32v: Uint32Array) => { let offset = 0; for (let i = 0; i < updateData.length; i++) { const obx = updateData[i]; obx.updateFunction(ps, f32v, u32v, offset, stride); offset += obx.stride; } }; }