export class SceneAnimationBridge {
    nodes = new Map();
    register(name, node) {
        if (name.trim().length === 0) {
            throw new Error("Scene animation target name cannot be empty.");
        }
        this.nodes.set(name, node);
    }
    setAnimationValue(target, value) {
        const [nodeName, property] = target.split(".");
        if (!nodeName || !property) {
            throw new Error(`Invalid scene animation target ${target}.`);
        }
        const node = this.nodes.get(nodeName);
        if (!node) {
            throw new Error(`Missing scene animation target ${nodeName}.`);
        }
        if (property === "position" || property === "translation") {
            writeVec3(node, "position", "setPosition", value);
        }
        else if (property === "rotation") {
            writeQuat(node, value);
        }
        else if (property === "scale") {
            writeVec3(node, "scale", "setScale", value);
        }
        else if (property === "weights") {
            writeWeights(node, value);
        }
        else {
            throw new Error(`Unsupported scene animation property ${property}.`);
        }
    }
}
function writeWeights(node, value) {
    if (!Array.isArray(value) || value.some((weight) => typeof weight !== "number" || !Number.isFinite(weight))) {
        throw new Error("weights animation value must be a finite number array.");
    }
    const weights = value.map((weight) => Math.max(0, Math.min(1, weight)));
    if (node.setWeights) {
        node.setWeights(weights);
    }
    else {
        node.weights = weights;
    }
}
function writeVec3(node, property, setter, value) {
    if (!Array.isArray(value) || value.length !== 3) {
        throw new Error(`${property} animation value must be a vec3.`);
    }
    if (node[setter]) {
        node[setter](value);
    }
    else {
        node[property] = [value[0], value[1], value[2]];
    }
}
function writeQuat(node, value) {
    if (!Array.isArray(value) || value.length !== 4) {
        throw new Error("rotation animation value must be a quaternion.");
    }
    if (node.setRotation) {
        node.setRotation(value);
    }
    else {
        node.rotation = [value[0], value[1], value[2], value[3]];
    }
}
//# sourceMappingURL=SceneAnimationBridge.js.map