"use strict";
cc._RF.push(module, '10b30V8c/ZEs5olGN2C+NyA', 'verlet_assembler');
// OP13/script/verlet_assembler.ts

"use strict";
var __extends = (this && this.__extends) || (function () {
    var extendStatics = function (d, b) {
        extendStatics = Object.setPrototypeOf ||
            ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
            function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
        return extendStatics(d, b);
    };
    return function (d, b) {
        extendStatics(d, b);
        function __() { this.constructor = d; }
        d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
    };
})();
Object.defineProperty(exports, "__esModule", { value: true });
var page_effect_assembler_base_1 = require("./page_effect_assembler_base");
var gfx = cc.gfx;
var vfmtPosUvColorFront = new gfx.VertexFormat([
    { name: gfx.ATTR_POSITION, type: gfx.ATTR_TYPE_FLOAT32, num: 2 },
    { name: gfx.ATTR_UV0, type: gfx.ATTR_TYPE_FLOAT32, num: 2 },
    { name: gfx.ATTR_COLOR, type: gfx.ATTR_TYPE_UINT8, num: 4, normalize: true },
    { name: "a_isFront", type: gfx.ATTR_TYPE_FLOAT32, num: 1 },
]);
var VerletAssembler = /** @class */ (function (_super) {
    __extends(VerletAssembler, _super);
    function VerletAssembler() {
        return _super !== null && _super.apply(this, arguments) || this;
    }
    VerletAssembler.prototype.init = function (comp) {
        _super.prototype.init.call(this, comp);
        //@ts-ignore
        var segmentCount = comp.pointsCount - 1;
        this.verticesCount = 4 * segmentCount;
        this.indicesCount = 6 * segmentCount;
        this.floatsPerVert = 6;
        this.initData();
    };
    VerletAssembler.prototype.getVfmt = function () {
        return vfmtPosUvColorFront;
    };
    VerletAssembler.prototype.updateRenderData = function (comp) {
        if (comp) {
            var pointList = comp.getPointList();
            var pointNum = pointList.length;
            if (pointNum < 2) {
                return;
            }
            var node = comp.node;
            var height = node.height;
            var width = node.width;
            var posX = -width * node.anchorX;
            var posY = -height * node.anchorY;
            var gapU = 1 / (pointNum - 1);
            var lastU = 0;
            var nextU = 0;
            var floatsPerVert = this.floatsPerVert;
            var verts = this.renderData.vDatas[0];
            // 写verts时的下标
            var dstOffset = 0;
            for (var i = 1; i < pointNum; i++) {
                var lastPoint = pointList[i - 1];
                var nextPoint = pointList[i];
                nextU = lastU + gapU;
                // 顶点和质点一一对应
                // 顶点数据写入verts
                dstOffset = floatsPerVert * (i - 1) * 4;
                verts[dstOffset] = posX + lastPoint.x;
                verts[dstOffset + 1] = posY + lastPoint.y;
                verts[dstOffset + 2] = lastU;
                verts[dstOffset + 3] = 1;
                dstOffset += floatsPerVert;
                verts[dstOffset] = posX + nextPoint.x;
                verts[dstOffset + 1] = posY + nextPoint.y;
                verts[dstOffset + 2] = nextU;
                verts[dstOffset + 3] = 1;
                dstOffset += floatsPerVert;
                verts[dstOffset] = posX + lastPoint.x;
                verts[dstOffset + 1] = posY + height + lastPoint.y;
                verts[dstOffset + 2] = lastU;
                verts[dstOffset + 3] = 0;
                dstOffset += floatsPerVert;
                verts[dstOffset] = posX + nextPoint.x;
                verts[dstOffset + 1] = posY + height + nextPoint.y;
                verts[dstOffset + 2] = nextU;
                verts[dstOffset + 3] = 0;
                lastU = nextU;
            }
            this.updateColor(comp, null);
            this.updateIsFront(comp, 5);
        }
    };
    return VerletAssembler;
}(page_effect_assembler_base_1.default));
exports.default = VerletAssembler;

cc._RF.pop();