{"version":3,"file":"getRenderableBounds.mjs","sources":["../../../../src/scene/container/bounds/getRenderableBounds.ts"],"sourcesContent":["import { Matrix } from '../../../maths';\n\nimport type { Renderable } from '../../../rendering/renderers/shared/Renderable';\nimport type { Bounds } from './Bounds';\n\n/**\n * This matrix is used for calculations of the bounds for renderables placed inside cacheAsTexture render groups.\n * @ignore\n * @internal\n */\nconst tempProjectionMatrix: Matrix = new Matrix();\n\n/**\n * @param renderables\n * @param bounds\n * @internal\n */\nexport function getGlobalRenderableBounds(renderables: Renderable[], bounds: Bounds): Bounds\n{\n    bounds.clear();\n\n    // instead of copying the matrix each time we are assigning it in bounds\n    // this is a performance hack :D\n    // so we need to restore the matrix after we are done\n\n    const actualMatrix = bounds.matrix;\n\n    for (let i = 0; i < renderables.length; i++)\n    {\n        const renderable = renderables[i];\n\n        if (renderable.globalDisplayStatus < 0b111)\n        {\n            continue;\n        }\n\n        const renderGroup = renderable.renderGroup ?? renderable.parentRenderGroup;\n\n        if (renderGroup?.isCachedAsTexture)\n        {\n            bounds.matrix = tempProjectionMatrix.copyFrom(renderGroup.textureOffsetInverseTransform)\n                .append(renderable.worldTransform);\n        }\n        else if (renderGroup?._parentCacheAsTextureRenderGroup)\n        {\n            bounds.matrix = tempProjectionMatrix\n                .copyFrom(renderGroup._parentCacheAsTextureRenderGroup.inverseWorldTransform)\n                .append(renderable.groupTransform);\n        }\n        else\n        {\n            bounds.matrix = renderable.worldTransform;\n        }\n\n        bounds.addBounds(renderable.bounds);\n    }\n\n    bounds.matrix = actualMatrix;\n\n    return bounds;\n}\n"],"names":[],"mappings":";;;;AAUA,MAAM,oBAAA,GAA+B,IAAI,MAAA,EAAO;AAOzC,SAAS,yBAAA,CAA0B,aAA2B,MAAA,EACrE;AACI,EAAA,MAAA,CAAO,KAAA,EAAM;AAMb,EAAA,MAAM,eAAe,MAAA,CAAO,MAAA;AAE5B,EAAA,KAAA,IAAS,CAAA,GAAI,CAAA,EAAG,CAAA,GAAI,WAAA,CAAY,QAAQ,CAAA,EAAA,EACxC;AACI,IAAA,MAAM,UAAA,GAAa,YAAY,CAAC,CAAA;AAEhC,IAAA,IAAI,UAAA,CAAW,sBAAsB,CAAA,EACrC;AACI,MAAA;AAAA,IACJ;AAEA,IAAA,MAAM,WAAA,GAAc,UAAA,CAAW,WAAA,IAAe,UAAA,CAAW,iBAAA;AAEzD,IAAA,IAAI,aAAa,iBAAA,EACjB;AACI,MAAA,MAAA,CAAO,MAAA,GAAS,qBAAqB,QAAA,CAAS,WAAA,CAAY,6BAA6B,CAAA,CAClF,MAAA,CAAO,WAAW,cAAc,CAAA;AAAA,IACzC,CAAA,MAAA,IACS,aAAa,gCAAA,EACtB;AACI,MAAA,MAAA,CAAO,MAAA,GAAS,qBACX,QAAA,CAAS,WAAA,CAAY,iCAAiC,qBAAqB,CAAA,CAC3E,MAAA,CAAO,UAAA,CAAW,cAAc,CAAA;AAAA,IACzC,CAAA,MAEA;AACI,MAAA,MAAA,CAAO,SAAS,UAAA,CAAW,cAAA;AAAA,IAC/B;AAEA,IAAA,MAAA,CAAO,SAAA,CAAU,WAAW,MAAM,CAAA;AAAA,EACtC;AAEA,EAAA,MAAA,CAAO,MAAA,GAAS,YAAA;AAEhB,EAAA,OAAO,MAAA;AACX;;;;"}