/*---------------------------------------------------------------------------------------------
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
* See LICENSE.md in the project root for license terms and full copyright notice.
*--------------------------------------------------------------------------------------------*/
/** @packageDocumentation
 * @module Rendering
 */
import { IModelApp } from "../../IModelApp";
/** @internal */
export function formatAnimationBranchId(modelId, branchId) {
    if (branchId < 0)
        return modelId;
    return `${modelId}_Node_${branchId.toString()}`;
}
function addAnimationBranch(modelId, timeline, branchId, branches, time) {
    const clipVector = timeline.getClipVector(time);
    const clip = clipVector ? IModelApp.renderSystem.createClipVolume(clipVector) : undefined;
    if (clip)
        branches.set(formatAnimationBranchId(modelId, branchId), { clip });
}
export var AnimationBranchStates;
(function (AnimationBranchStates) {
    function fromScript(script, time) {
        if (!script.containsModelClipping && !script.requiresBatching)
            return undefined;
        const branches = new Map();
        for (const model of script.modelTimelines) {
            addAnimationBranch(model.modelId, model, -1, branches, time);
            for (const elem of model.elementTimelines) {
                if (elem.getVisibility(time) <= 0)
                    branches.set(formatAnimationBranchId(model.modelId, elem.batchId), { omit: true });
                else
                    addAnimationBranch(model.modelId, elem, elem.batchId, branches, time);
            }
        }
        return {
            branchStates: branches,
            transformNodeIds: script.transformBatchIds,
        };
    }
    AnimationBranchStates.fromScript = fromScript;
})(AnimationBranchStates || (AnimationBranchStates = {}));
//# sourceMappingURL=AnimationBranchState.js.map