{"version":3,"file":"collectRenderablesMixin.mjs","sources":["../../../../src/scene/container/container-mixins/collectRenderablesMixin.ts"],"sourcesContent":["import { type InstructionSet } from '../../../rendering/renderers/shared/instructions/InstructionSet';\nimport { type InstructionPipe } from '../../../rendering/renderers/shared/instructions/RenderPipe';\nimport { type Renderer, type RenderPipes } from '../../../rendering/renderers/types';\nimport { type RenderLayer } from '../../layers/RenderLayer';\n\nimport type { Container } from '../Container';\n\n/**\n * The CollectRenderablesMixin interface defines methods for collecting renderable objects\n * from a container and its children. These methods add the renderables to an instruction set,\n * which is used by the renderer to process and display the scene.\n * @category scene\n * @internal\n */\nexport interface CollectRenderablesMixin\n{\n    /**\n     * Collects all renderables from the container and its children, adding them to the instruction set.\n     * This method decides whether to use a simple or advanced collection method based on the container's properties.\n     * @param {InstructionSet} instructionSet - The set of instructions to which the renderables will be added.\n     * @param {Renderer} renderer - The renderer responsible for rendering the scene.\n     * @param {RenderLayer} currentLayer - The current render layer being processed.\n     * @internal\n     */\n    collectRenderables(instructionSet: InstructionSet, renderer: Renderer, currentLayer: RenderLayer): void;\n\n    /**\n     * Collects renderables using a simple method, suitable for containers marked as simple.\n     * This method iterates over the container's children and adds their renderables to the instruction set.\n     * @param {InstructionSet} instructionSet - The set of instructions to which the renderables will be added.\n     * @param {Renderer} renderer - The renderer responsible for rendering the scene.\n     * @param {RenderLayer} currentLayer - The current render layer being processed.\n     * @internal\n     */\n    collectRenderablesSimple(instructionSet: InstructionSet, renderer: Renderer, currentLayer: RenderLayer): void;\n\n    /**\n     * Collects renderables using an advanced method, suitable for containers with complex processing needs.\n     * This method handles additional effects and transformations that may be applied to the renderables.\n     * @param {InstructionSet} instructionSet - The set of instructions to which the renderables will be added.\n     * @param {Renderer} renderer - The renderer responsible for rendering the scene.\n     * @param {RenderLayer} currentLayer - The current render layer being processed.\n     * @internal\n     */\n    collectRenderablesWithEffects(\n        instructionSet: InstructionSet,\n        renderer: Renderer,\n        currentLayer: RenderLayer,\n    ): void;\n}\n\n/**\n * The collectRenderablesMixin provides implementations for the methods defined in the CollectRenderablesMixin interface.\n * It includes logic to determine the appropriate method for collecting renderables based on the container's properties.\n * @internal\n */\nexport const collectRenderablesMixin: Partial<Container> = {\n    collectRenderables(instructionSet: InstructionSet, renderer: Renderer, currentLayer: RenderLayer): void\n    {\n        // Skip processing if the container is not in the current render layer or is not fully visible.\n        if ((this.parentRenderLayer && this.parentRenderLayer !== currentLayer)\n            || this.globalDisplayStatus < 0b111 || !this.includeInBuild) return;\n\n        // Sort children if the container has sortable children.\n        if (this.sortableChildren)\n        {\n            this.sortChildren();\n        }\n\n        // Choose the appropriate method for collecting renderables based on the container's properties.\n        if (this.isSimple)\n        {\n            this.collectRenderablesSimple(instructionSet, renderer, currentLayer);\n        }\n        else if (this.renderGroup)\n        {\n            renderer.renderPipes.renderGroup.addRenderGroup(this.renderGroup, instructionSet);\n        }\n        else\n        {\n            this.collectRenderablesWithEffects(instructionSet, renderer, currentLayer);\n        }\n    },\n    collectRenderablesSimple(\n        instructionSet: InstructionSet,\n        renderer: Renderer,\n        currentLayer: RenderLayer,\n    ): void\n    {\n        const children = this.children;\n        const length = children.length;\n\n        // Iterate over each child and collect their renderables.\n        for (let i = 0; i < length; i++)\n        {\n            children[i].collectRenderables(instructionSet, renderer, currentLayer);\n        }\n    },\n    collectRenderablesWithEffects(\n        instructionSet: InstructionSet,\n        renderer: Renderer,\n        currentLayer: RenderLayer,\n    ): void\n    {\n        const { renderPipes } = renderer;\n\n        // Apply each effect to the renderables before collecting them.\n        for (let i = 0; i < this.effects.length; i++)\n        {\n            const effect = this.effects[i];\n            const pipe = renderPipes[effect.pipe as keyof RenderPipes] as InstructionPipe<any>;\n\n            pipe.push(effect, this, instructionSet);\n        }\n\n        // Collect renderables using the simple method after applying effects.\n        this.collectRenderablesSimple(instructionSet, renderer, currentLayer);\n\n        // Remove effects from the renderables after collection, processing in reverse order.\n        for (let i = this.effects.length - 1; i >= 0; i--)\n        {\n            const effect = this.effects[i];\n            const pipe = renderPipes[effect.pipe as keyof RenderPipes] as InstructionPipe<any>;\n\n            pipe.pop(effect, this, instructionSet);\n        }\n    }\n} as Container;\n"],"names":[],"mappings":";AAwDO,MAAM,uBAA8C,GAAA;AAAA,EACvD,kBAAA,CAAmB,cAAgC,EAAA,QAAA,EAAoB,YACvE,EAAA;AAEI,IAAK,IAAA,IAAA,CAAK,qBAAqB,IAAK,CAAA,iBAAA,KAAsB,gBACnD,IAAK,CAAA,mBAAA,GAAsB,CAAS,IAAA,CAAC,IAAK,CAAA,cAAA;AAAgB,MAAA,OAAA;AAGjE,IAAA,IAAI,KAAK,gBACT,EAAA;AACI,MAAA,IAAA,CAAK,YAAa,EAAA,CAAA;AAAA,KACtB;AAGA,IAAA,IAAI,KAAK,QACT,EAAA;AACI,MAAK,IAAA,CAAA,wBAAA,CAAyB,cAAgB,EAAA,QAAA,EAAU,YAAY,CAAA,CAAA;AAAA,KACxE,MAAA,IACS,KAAK,WACd,EAAA;AACI,MAAA,QAAA,CAAS,WAAY,CAAA,WAAA,CAAY,cAAe,CAAA,IAAA,CAAK,aAAa,cAAc,CAAA,CAAA;AAAA,KAGpF,MAAA;AACI,MAAK,IAAA,CAAA,6BAAA,CAA8B,cAAgB,EAAA,QAAA,EAAU,YAAY,CAAA,CAAA;AAAA,KAC7E;AAAA,GACJ;AAAA,EACA,wBAAA,CACI,cACA,EAAA,QAAA,EACA,YAEJ,EAAA;AACI,IAAA,MAAM,WAAW,IAAK,CAAA,QAAA,CAAA;AACtB,IAAA,MAAM,SAAS,QAAS,CAAA,MAAA,CAAA;AAGxB,IAAA,KAAA,IAAS,CAAI,GAAA,CAAA,EAAG,CAAI,GAAA,MAAA,EAAQ,CAC5B,EAAA,EAAA;AACI,MAAA,QAAA,CAAS,CAAC,CAAA,CAAE,kBAAmB,CAAA,cAAA,EAAgB,UAAU,YAAY,CAAA,CAAA;AAAA,KACzE;AAAA,GACJ;AAAA,EACA,6BAAA,CACI,cACA,EAAA,QAAA,EACA,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