System.register(["cc"], function (_export, _context) { "use strict"; var _cclegacy, __checkObsolete__, __checkObsoleteInNamespace__, TrailData, CCInteger, CurveRange, Director, DynamicAtlasManager, GradientRange, SpriteFrame, UIRenderer, UITransform, _decorator, director, v2, _dec, _dec2, _dec3, _dec4, _dec5, _dec6, _dec7, _dec8, _dec9, _dec10, _dec11, _class2, _class3, _descriptor, _descriptor2, _descriptor3, _descriptor4, _descriptor5, _descriptor6, _crd, ccclass, property, executeInEditMode, menu, MotionTrail, simple; function _initializerDefineProperty(target, property, descriptor, context) { if (!descriptor) return; Object.defineProperty(target, property, { enumerable: descriptor.enumerable, configurable: descriptor.configurable, writable: descriptor.writable, value: descriptor.initializer ? descriptor.initializer.call(context) : void 0 }); } function _initializerWarningHelper(descriptor, context) { throw new Error('Decorating class property failed. Please ensure that ' + 'transform-class-properties is enabled and runs after the decorators transform.'); } function _applyDecoratedDescriptor(target, property, decorators, descriptor, context) { var desc = {}; Object.keys(descriptor).forEach(function (key) { desc[key] = descriptor[key]; }); desc.enumerable = !!desc.enumerable; desc.configurable = !!desc.configurable; if ('value' in desc || desc.initializer) { desc.writable = true; } desc = decorators.slice().reverse().reduce(function (desc, decorator) { return decorator(target, property, desc) || desc; }, desc); if (context && desc.initializer !== void 0) { desc.value = desc.initializer ? desc.initializer.call(context) : void 0; desc.initializer = undefined; } if (desc.initializer === void 0) { Object.defineProperty(target, property, desc); desc = null; } return desc; } return { setters: [function (_cc) { _cclegacy = _cc.cclegacy; __checkObsolete__ = _cc.__checkObsolete__; __checkObsoleteInNamespace__ = _cc.__checkObsoleteInNamespace__; CCInteger = _cc.CCInteger; CurveRange = _cc.CurveRange; Director = _cc.Director; DynamicAtlasManager = _cc.DynamicAtlasManager; GradientRange = _cc.GradientRange; SpriteFrame = _cc.SpriteFrame; UIRenderer = _cc.UIRenderer; UITransform = _cc.UITransform; _decorator = _cc._decorator; director = _cc.director; v2 = _cc.v2; }], execute: function () { _crd = true; _cclegacy._RF.push({}, "bb8ffN3AwpEqJr3cZDOVdXJ", "MotionTrail", undefined); TrailData = class TrailData { constructor() { this.x = 0; this.y = 0; this.dis = 0; this.cos = 0; this.sin = 0; } }; __checkObsolete__(['CCInteger', 'CurveRange', 'Director', 'DynamicAtlasManager', 'GradientRange', 'IAssembler', 'RenderData', 'SpriteFrame', 'UIRenderer', 'UITransform', 'Vec2', 'Vec3', '__private', '_decorator', 'director', 'v2']); ({ ccclass, property, executeInEditMode, menu } = _decorator); _export("default", MotionTrail = (_dec = menu('Comp/MotionTrail'), _dec2 = executeInEditMode(), _dec3 = property({ visible: false }), _dec4 = property({ type: SpriteFrame, displayName: 'SpriteFrame' }), _dec5 = property({ displayName: '世界坐标', tooltip: '顶点坐标是世界坐标还是本地坐标' }), _dec6 = property({ displayName: '偏移' }), _dec7 = property({ type: CCInteger, displayName: '拖尾长度' }), _dec8 = property({ type: CurveRange, displayName: '宽度变化', range: [0, 1] }), _dec9 = property({ type: CurveRange, displayName: '宽度变化', range: [0, 1] }), _dec10 = property({ type: GradientRange, displayName: '颜色变化' }), _dec11 = property({ type: GradientRange, displayName: '颜色变化' }), ccclass(_class2 = _dec(_class2 = _dec2(_class2 = (_class3 = class MotionTrail extends UIRenderer { constructor(...args) { super(...args); _initializerDefineProperty(this, "_spriteFrame", _descriptor, this); _initializerDefineProperty(this, "_isWorldXY", _descriptor2, this); _initializerDefineProperty(this, "offset", _descriptor3, this); _initializerDefineProperty(this, "_length", _descriptor4, this); this.trailData = []; _initializerDefineProperty(this, "_sizeCurveRange", _descriptor5, this); _initializerDefineProperty(this, "_colorCurveRange", _descriptor6, this); this._useVertexOpacity = true; } get color() { return this._color; } get spriteFrame() { return this._spriteFrame; } set spriteFrame(value) { this._spriteFrame = value; } get isWorldXY() { return this._isWorldXY; } set isWorldXY(value) { this._isWorldXY = value; } get length() { return this._length; } set length(value) { this._length = Math.max(value, 0); this.updateLength(); this.updateWidth(); this.resetPos(); this.freshBuffer(); } get sizeCurveRange() { return this._sizeCurveRange; } set sizeCurveRange(value) { this._sizeCurveRange = value; this.updateWidth(); } get colorCurveRange() { return this._colorCurveRange; } set colorCurveRange(value) { this._colorCurveRange = value; this._updateColor(); } _render(render) { render.commitComp(this, this.renderData, this._spriteFrame, this._assembler, null); } _flushAssembler() { this._assembler = simple; if (!this._renderData) { this._renderData = this.requestRenderData(); ; this._renderData.material = this.getRenderMaterial(0); this.freshBuffer(); this.markForUpdateRenderData(); if (this._spriteFrame) { this._assembler.updateUVs(this); } this._updateColor(); } } //更新buffer freshBuffer() { let len = this.length; let count = 4 + (len - 2) * 2; this._renderData.dataLength = count; this._renderData.resize(count, (count - 2) * 3); } updateLength() { let trailLen = this.length; let sub = trailLen - this.trailData.length; if (sub > 0) { for (let i = 0; i < sub; ++i) { this.trailData.push(new TrailData()); } } else if (sub < 0) { this.trailData.splice(trailLen); } } updateWidth() { let data = this.trailData; let trailLen = this.length; let width = this.getComponent(UITransform).width / 2; for (let i = 0; i < trailLen; ++i) { data[i].dis = this.sizeCurveRange.evaluate(i / (trailLen - 1), 0) * width; } } resetPos() { let data = this.trailData; let tx = this.offset.x; let ty = this.offset.y; if (this.isWorldXY) { tx += this.node.worldPosition.x; ty += this.node.worldPosition.y; } else { tx += this.node.position.x; ty += this.node.position.y; } for (let i = 0, len = this.length; i < len; i++) { data[i].x = tx; data[i].y = ty; } } onLoad() { this.length = this._length; } onEnable() { super.onEnable(); director.once(Director.EVENT_BEFORE_DRAW, this.resetPos, this); } }, (_applyDecoratedDescriptor(_class3.prototype, "color", [_dec3], Object.getOwnPropertyDescriptor(_class3.prototype, "color"), _class3.prototype), _descriptor = _applyDecoratedDescriptor(_class3.prototype, "_spriteFrame", [property], { configurable: true, enumerable: true, writable: true, initializer: function () { return null; } }), _applyDecoratedDescriptor(_class3.prototype, "spriteFrame", [_dec4], Object.getOwnPropertyDescriptor(_class3.prototype, "spriteFrame"), _class3.prototype), _descriptor2 = _applyDecoratedDescriptor(_class3.prototype, "_isWorldXY", [property], { configurable: true, enumerable: true, writable: true, initializer: function () { return true; } }), _applyDecoratedDescriptor(_class3.prototype, "isWorldXY", [_dec5], Object.getOwnPropertyDescriptor(_class3.prototype, "isWorldXY"), _class3.prototype), _descriptor3 = _applyDecoratedDescriptor(_class3.prototype, "offset", [_dec6], { configurable: true, enumerable: true, writable: true, initializer: function () { return v2(0, 0); } }), _descriptor4 = _applyDecoratedDescriptor(_class3.prototype, "_length", [property], { configurable: true, enumerable: true, writable: true, initializer: function () { return 20; } }), _applyDecoratedDescriptor(_class3.prototype, "length", [_dec7], Object.getOwnPropertyDescriptor(_class3.prototype, "length"), _class3.prototype), _descriptor5 = _applyDecoratedDescriptor(_class3.prototype, "_sizeCurveRange", [_dec8], { configurable: true, enumerable: true, writable: true, initializer: function () { return new CurveRange(); } }), _applyDecoratedDescriptor(_class3.prototype, "sizeCurveRange", [_dec9], Object.getOwnPropertyDescriptor(_class3.prototype, "sizeCurveRange"), _class3.prototype), _descriptor6 = _applyDecoratedDescriptor(_class3.prototype, "_colorCurveRange", [_dec10], { configurable: true, enumerable: true, writable: true, initializer: function () { return new GradientRange(); } }), _applyDecoratedDescriptor(_class3.prototype, "colorCurveRange", [_dec11], Object.getOwnPropertyDescriptor(_class3.prototype, "colorCurveRange"), _class3.prototype)), _class3)) || _class2) || _class2) || _class2)); simple = { updateRenderData(trail) { const frame = trail.spriteFrame; DynamicAtlasManager.instance.packToDynamicAtlas(trail, frame); this.updateUVs(trail); // dirty need //this.updateColor(sprite);// dirty need const renderData = trail.renderData; if (renderData && frame) { if (renderData.vertDirty) { this.updateVertexData(trail); } renderData.updateRenderData(trail, frame); } }, updateWorldVerts(trail) { const renderData = trail.renderData; const vData = renderData.chunk.vb; let len = trail.length; if (len < 1) return; let tx = 0, ty = 0; let data = trail.trailData; if (!trail.isWorldXY) { tx = trail.node.position.x; ty = trail.node.position.y; } let ax = 0, ay = 0; let curIdx = 0; let tempData = null; let tempNextData = null; // for (let i = 0; i < len; ++i) { tempData = data[i]; let sameIdx = i; for (; sameIdx < len; ++sameIdx) { tempNextData = data[sameIdx]; if (tempNextData.x != tempData.x || tempNextData.y != tempData.y) { break; } } sameIdx -= 1; if (sameIdx == i) { ax = tempData.x - tx; ay = tempData.y - ty; vData[curIdx] = ax + tempData.dis * tempData.sin; vData[curIdx + 1] = ay - tempData.dis * tempData.cos; vData[curIdx + 2] = 0; curIdx += renderData.floatStride; vData[curIdx] = ax - tempData.dis * tempData.sin; vData[curIdx + 1] = ay + tempData.dis * tempData.cos; vData[curIdx + 2] = 0; curIdx += renderData.floatStride; } else { tempData = data[sameIdx]; ax = tempData.x - tx; ay = tempData.y - ty; vData[curIdx] = ax + tempData.dis * tempData.sin; vData[curIdx + 1] = ay - tempData.dis * tempData.cos; vData[curIdx + 2] = 0; curIdx += renderData.floatStride; vData[curIdx] = ax - tempData.dis * tempData.sin; vData[curIdx + 1] = ay + tempData.dis * tempData.cos; vData[curIdx + 2] = 0; curIdx += renderData.floatStride; for (; i < sameIdx; ++i) { vData[curIdx] = vData[curIdx - renderData.floatStride * 2]; vData[curIdx + 1] = vData[curIdx - renderData.floatStride * 2 + 1]; vData[curIdx + 2] = 0; curIdx += renderData.floatStride; vData[curIdx] = vData[curIdx - renderData.floatStride * 2]; vData[curIdx + 1] = vData[curIdx - renderData.floatStride * 2 + 1]; vData[curIdx + 2] = 0; curIdx += renderData.floatStride; } } } }, fillBuffers(trail) { if (trail.spriteFrame == null) return; const renderData = trail.renderData; const chunk = renderData.chunk; this.update(trail); this.updateWorldVerts(trail, chunk); // quick version const vidOrigin = chunk.vertexOffset; const meshBuffer = chunk.meshBuffer; const ib = chunk.meshBuffer.iData; let indexOffset = meshBuffer.indexOffset; let vid = vidOrigin; let len = trail.length - 1; for (let i = 0; i < len; i++) { ib[indexOffset++] = vid + 0; ib[indexOffset++] = vid + 1; ib[indexOffset++] = vid + 2; ib[indexOffset++] = vid + 1; ib[indexOffset++] = vid + 3; ib[indexOffset++] = vid + 2; vid += 2; } meshBuffer.indexOffset += len * 6; }, updateVertexData(trail) { const renderData = trail.renderData; renderData.vertDirty = true; }, updateUVs(trail) { if (trail.spriteFrame == null) return; const renderData = trail.renderData; const vData = renderData.chunk.vb; const uv = trail.spriteFrame.uv; const length = trail.length - 1; const uvStep = length == 0 ? 0 : 1 / length; let curIdx = 3; let subV = uv[7] - uv[1]; for (let i = 0; i < length; i++) { vData[curIdx] = uv[0]; vData[curIdx + 1] = uv[1] + subV * i * uvStep; curIdx += renderData.floatStride; vData[curIdx] = uv[0]; vData[curIdx + 1] = uv[3] + subV * i * uvStep; curIdx += renderData.floatStride; } vData[curIdx] = uv[0]; vData[curIdx + 1] = uv[7]; curIdx += renderData.floatStride; vData[curIdx] = uv[0]; vData[curIdx + 1] = uv[5]; curIdx += renderData.floatStride; }, updateColor(trail) { const renderData = trail.renderData; const vData = renderData.chunk.vb; const total = 4 + (trail.length - 2) * 2; const stepTotal = trail.length; let stepIdx = -1; let colorOffset = 5; let curC, random; for (let i = 0; i < total; i++) { if (i % 2 == 0) { random = trail.colorCurveRange.mode === GradientRange.Mode.TwoGradients || trail.colorCurveRange.mode === GradientRange.Mode.TwoColors ? Math.random() : 0; curC = trail.colorCurveRange.evaluate(stepIdx / stepTotal, random); stepIdx++; } vData[colorOffset] = curC.r / 255; vData[colorOffset + 1] = curC.g / 255; vData[colorOffset + 2] = curC.b / 255; vData[colorOffset + 3] = curC.a / 255; colorOffset += renderData.floatStride; } }, update(trail) { if (trail.length === 0) return; let data = trail.trailData; for (let i = trail.length - 1; i > 0; --i) { let cur = data[i], prev = data[i - 1]; cur.x = prev.x; cur.y = prev.y; cur.sin = prev.sin; cur.cos = prev.cos; } let pos = null; if (trail.isWorldXY) { pos = trail.node.worldPosition; } else { pos = trail.node.position; } let fristData = data[0]; fristData.x = trail.offset.x + pos.x; fristData.y = trail.offset.y + pos.y; let secondData = data[1]; let radian = Math.atan2(secondData.y - fristData.y, secondData.x - fristData.x); fristData.sin = Math.sin(radian); fristData.cos = Math.cos(radian); }, updateOpacity(trail, alpha) { const renderData = trail.renderData; const vData = renderData.chunk.vb; const total = 4 + (trail.length - 2) * 2; const stepTotal = trail.length; let stepIdx = -1; let colorOffset = 5; let curC, random; for (let i = 0; i < total; i++) { if (i % 2 == 0) { random = trail.colorCurveRange.mode === GradientRange.Mode.TwoGradients || trail.colorCurveRange.mode === GradientRange.Mode.TwoColors ? Math.random() : 0; curC = trail.colorCurveRange.evaluate(stepIdx / stepTotal, random); stepIdx++; } vData[colorOffset + 3] = curC.a / 255 * alpha; colorOffset += renderData.floatStride; } } }; _cclegacy._RF.pop(); _crd = false; } }; }); //# sourceMappingURL=a5b4b8f57042f821244d112516d11eb631ec06c9.js.map