{"version":3,"file":"getGlobalMixin.mjs","sources":["../../../../src/scene/container/container-mixins/getGlobalMixin.ts"],"sourcesContent":["import { Matrix } from '../../../maths/matrix/Matrix';\nimport { updateTransformBackwards } from '../bounds/getGlobalBounds';\nimport { matrixPool } from '../bounds/utils/matrixAndBoundsPool';\nimport { multiplyColors } from '../utils/multiplyColors';\n\nimport type { Container } from '../Container';\n\n/**\n * Converts a color from BGR format to RGB format.\n * @param color - The color in BGR format (0xBBGGRR).\n * @returns The color in RGB format (0xRRGGBB).\n * @category utils\n * @internal\n */\nexport function bgr2rgb(color: number): number\n{\n    return ((color & 0xFF) << 16) + (color & 0xFF00) + ((color >> 16) & 0xFF);\n}\n\n/**\n * Interface for a mixin that provides methods to retrieve global properties of a container.\n * This mixin allows you to get the global alpha, transform matrix, and tint color of a container,\n * taking into account its parent containers and render groups.\n * It includes methods to optimize performance by using cached values when available.\n * @category scene\n * @advanced\n */\nexport interface GetGlobalMixin\n{\n    /**\n     * Returns the global (compound) alpha of the container within the scene.\n     * @param {boolean} skipUpdate - Performance optimization flag:\n     *   - If false (default): Recalculates the entire alpha chain through parents for accuracy\n     *   - If true: Uses cached worldAlpha from the last render pass for better performance\n     * @returns The resulting alpha value (between 0 and 1)\n     * @example\n     * ```ts\n     * // Accurate but slower - recalculates entire alpha chain\n     * const preciseAlpha = container.getGlobalAlpha();\n     *\n     * // Faster but may be outdated - uses cached alpha\n     * const cachedAlpha = container.getGlobalAlpha(true);\n     * ```\n     */\n    getGlobalAlpha(skipUpdate?: boolean): number;\n    /**\n     * Returns the global transform matrix of the container within the scene.\n     * @param {Matrix} matrix - Optional matrix to store the result. If not provided, a new Matrix will be created.\n     * @param {boolean} skipUpdate - Performance optimization flag:\n     *   - If false (default): Recalculates the entire transform chain for accuracy\n     *   - If true: Uses cached worldTransform from the last render pass for better performance\n     * @returns The resulting transformation matrix (either the input matrix or a new one)\n     * @example\n     * ```ts\n     * // Accurate but slower - recalculates entire transform chain\n     * const preciseTransform = container.getGlobalTransform();\n     *\n     * // Faster but may be outdated - uses cached transform\n     * const cachedTransform = container.getGlobalTransform(undefined, true);\n     *\n     * // Reuse existing matrix\n     * const existingMatrix = new Matrix();\n     * container.getGlobalTransform(existingMatrix);\n     * ```\n     */\n    getGlobalTransform(matrix?: Matrix, skipUpdate?: boolean): Matrix;\n    /**\n     * Returns the global (compound) tint color of the container within the scene.\n     * @param {boolean} skipUpdate - Performance optimization flag:\n     *   - If false (default): Recalculates the entire tint chain through parents for accuracy\n     *   - If true: Uses cached worldColor from the last render pass for better performance\n     * @returns The resulting tint color as a 24-bit RGB number (0xRRGGBB)\n     * @example\n     * ```ts\n     * // Accurate but slower - recalculates entire tint chain\n     * const preciseTint = container.getGlobalTint();\n     *\n     * // Faster but may be outdated - uses cached tint\n     * const cachedTint = container.getGlobalTint(true);\n     * ```\n     */\n    getGlobalTint(skipUpdate?: boolean): number;\n}\n\n/** @internal */\nexport const getGlobalMixin: Partial<Container> = {\n    getGlobalAlpha(skipUpdate?: boolean): number\n    {\n        if (skipUpdate)\n        {\n            if (this.renderGroup)\n            {\n                return this.renderGroup.worldAlpha;\n            }\n\n            if (this.parentRenderGroup)\n            {\n                return this.parentRenderGroup.worldAlpha * this.alpha;\n            }\n\n            return this.alpha;\n        }\n\n        let alpha = this.alpha;\n        let current = this.parent;\n\n        while (current)\n        {\n            alpha *= current.alpha;\n            current = current.parent;\n        }\n\n        return alpha;\n    },\n    getGlobalTransform(matrix = new Matrix(), skipUpdate?: boolean): Matrix\n    {\n        if (skipUpdate)\n        {\n            return matrix.copyFrom(this.worldTransform);\n        }\n\n        this.updateLocalTransform();\n\n        const parentTransform = updateTransformBackwards(this, matrixPool.get().identity());\n\n        matrix.appendFrom(this.localTransform, parentTransform);\n        matrixPool.return(parentTransform);\n\n        return matrix;\n    },\n    getGlobalTint(skipUpdate?: boolean): number\n    {\n        if (skipUpdate)\n        {\n            if (this.renderGroup)\n            {\n                return bgr2rgb(this.renderGroup.worldColor);\n            }\n\n            if (this.parentRenderGroup)\n            {\n                return bgr2rgb(\n                    multiplyColors(this.localColor, this.parentRenderGroup.worldColor)\n                );\n            }\n\n            return this.tint;\n        }\n\n        let color = this.localColor;\n        let parent = this.parent;\n\n        while (parent)\n        {\n            color = multiplyColors(color, parent.localColor);\n            parent = parent.parent;\n        }\n\n        return bgr2rgb(color);\n    }\n\n} as Container;\n"],"names":[],"mappings":";;;;;;AAcO,SAAS,QAAQ,KAAA,EACxB;AACI,EAAA,OAAA,CAAA,CAAS,QAAQ,GAAA,KAAS,EAAA,KAAO,KAAA,GAAQ,KAAA,CAAA,IAAY,SAAS,EAAA,GAAM,GAAA,CAAA;AACxE;AAoEO,MAAM,cAAA,GAAqC;AAAA,EAC9C,eAAe,UAAA,EACf;AACI,IAAA,IAAI,UAAA,EACJ;AACI,MAAA,IAAI,KAAK,WAAA,EACT;AACI,QAAA,OAAO,KAAK,WAAA,CAAY,UAAA;AAAA,MAC5B;AAEA,MAAA,IAAI,KAAK,iBAAA,EACT;AACI,QAAA,OAAO,IAAA,CAAK,iBAAA,CAAkB,UAAA,GAAa,IAAA,CAAK,KAAA;AAAA,MACpD;AAEA,MAAA,OAAO,IAAA,CAAK,KAAA;AAAA,IAChB;AAEA,IAAA,IAAI,QAAQ,IAAA,CAAK,KAAA;AACjB,IAAA,IAAI,UAAU,IAAA,CAAK,MAAA;AAEnB,IAAA,OAAO,OAAA,EACP;AACI,MAAA,KAAA,IAAS,OAAA,CAAQ,KAAA;AACjB,MAAA,OAAA,GAAU,OAAA,CAAQ,MAAA;AAAA,IACtB;AAEA,IAAA,OAAO,KAAA;AAAA,EACX,CAAA;AAAA,EACA,kBAAA,CAAmB,MAAA,GAAS,IAAI,MAAA,IAAU,UAAA,EAC1C;AACI,IAAA,IAAI,UAAA,EACJ;AACI,MAAA,OAAO,MAAA,CAAO,QAAA,CAAS,IAAA,CAAK,cAAc,CAAA;AAAA,IAC9C;AAEA,IAAA,IAAA,CAAK,oBAAA,EAAqB;AAE1B,IAA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