e55803fdad4509157e93866295c97e2478236978.js 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813
  1. System.register(["cc", "cc/env"], function (_export, _context) {
  2. "use strict";
  3. var _cclegacy, __checkObsolete__, __checkObsoleteInNamespace__, approx, assert, BitmapFont, cclegacy, Component, Director, director, EPSILON, Game, game, gfx, ImageAsset, Label, Material, MotionStreak, murmurhash2_32_gc, renderer, resources, Root, Sprite, StencilManager, Texture2D, TiledLayer, DEBUG, EDITOR, JSB, _crd, VER, MAX_TEX, SUPPORT_NATIVE, MultBatch2D, _image, Texture, loadMultTextures, endBatcher, _cacheUseCount, _cacheMaterials, getMultMaterial, inject_Renderdata, inject_Label, inject_Sprite, inject_MotionStreak, inject_TiledLayer;
  4. return {
  5. setters: [function (_cc) {
  6. _cclegacy = _cc.cclegacy;
  7. __checkObsolete__ = _cc.__checkObsolete__;
  8. __checkObsoleteInNamespace__ = _cc.__checkObsoleteInNamespace__;
  9. approx = _cc.approx;
  10. assert = _cc.assert;
  11. BitmapFont = _cc.BitmapFont;
  12. cclegacy = _cc.cclegacy;
  13. Component = _cc.Component;
  14. Director = _cc.Director;
  15. director = _cc.director;
  16. EPSILON = _cc.EPSILON;
  17. Game = _cc.Game;
  18. game = _cc.game;
  19. gfx = _cc.gfx;
  20. ImageAsset = _cc.ImageAsset;
  21. Label = _cc.Label;
  22. Material = _cc.Material;
  23. MotionStreak = _cc.MotionStreak;
  24. murmurhash2_32_gc = _cc.murmurhash2_32_gc;
  25. renderer = _cc.renderer;
  26. resources = _cc.resources;
  27. Root = _cc.Root;
  28. Sprite = _cc.Sprite;
  29. StencilManager = _cc.StencilManager;
  30. Texture2D = _cc.Texture2D;
  31. TiledLayer = _cc.TiledLayer;
  32. }, function (_ccEnv) {
  33. DEBUG = _ccEnv.DEBUG;
  34. EDITOR = _ccEnv.EDITOR;
  35. JSB = _ccEnv.JSB;
  36. }],
  37. execute: function () {
  38. _crd = true;
  39. _cclegacy._RF.push({}, "bd7e7vtojdMUJODlbuIb/Yi", "MultTextures", undefined); //*//
  40. __checkObsolete__(['__private', 'approx', 'assert', 'BaseRenderData', 'BitmapFont', 'cclegacy', 'Component', 'Director', 'director', 'EPSILON', 'Game', 'game', 'gfx', 'ImageAsset', 'Label', 'Material', 'MeshBuffer', 'MotionStreak', 'murmurhash2_32_gc', 'Node', 'renderer', 'resources', 'Root', 'Sprite', 'SpriteFrame', 'StencilManager', 'Texture2D', 'TiledLayer', 'TiledRenderData', 'UIMeshRenderer', 'UIRenderer']);
  41. VER = "2.0.2"; //最大纹理,固定8张
  42. MAX_TEX = 8; //原生开关,根据需要开启或关闭
  43. SUPPORT_NATIVE = true; //@ts-ignore
  44. gfx.Texture.prototype.texID = -1; //当前纹理id
  45. //@ts-ignore
  46. Material.prototype.isMult = false; //多纹理材质的标记
  47. //@ts-ignore
  48. Component.prototype.useMult = false; //组件多纹理开关
  49. _export("MultBatch2D", MultBatch2D = {
  50. native: !SUPPORT_NATIVE && JSB,
  51. enable: false,
  52. parent: null,
  53. incID: 0,
  54. count: 0,
  55. hash: 0,
  56. reset: function () {
  57. this.incID += this.count;
  58. this.count = 0;
  59. }
  60. });
  61. _image = new ImageAsset({
  62. width: 1,
  63. height: 1,
  64. _compressed: false,
  65. format: gfx.Format.RGBA32F,
  66. _data: new Float32Array(4).fill(0)
  67. });
  68. Texture = new Texture2D();
  69. Texture.setFilters(1, 1);
  70. Texture.image = _image;
  71. Texture.addRef(); //预加载多纹理材质
  72. loadMultTextures = function () {
  73. MultBatch2D.enable = false;
  74. resources.load("multTextures/Mult-material", Material, (err, material) => {
  75. if (!err) {
  76. let mat = cclegacy.builtinResMgr.get('ui-sprite-material');
  77. if (mat) {
  78. mat._hash = MultBatch2D.hash = Material.getHash(mat);
  79. MultBatch2D.parent = material;
  80. MultBatch2D.enable = true;
  81. material.addRef();
  82. }
  83. }
  84. });
  85. }; //填补原生纹理数据
  86. endBatcher = function () {
  87. var _director$root;
  88. if (!JSB) return;
  89. let batcher = (_director$root = director.root) == null ? void 0 : _director$root.batcher2D;
  90. if (batcher && batcher.isMult) {
  91. let mat = batcher._currMaterial;
  92. if (mat && MultBatch2D.count > 0) {
  93. let tid = Texture.getGFXTexture(); //?.objectID;
  94. let cache = batcher.cacheTextures;
  95. for (let i = MultBatch2D.count; i < 8; i++) {
  96. if (cache[i] !== tid) {
  97. mat.setProperty("texture" + i, Texture);
  98. cache[i] = tid;
  99. }
  100. }
  101. }
  102. }
  103. }; //多纹理材质缓存队列
  104. _cacheUseCount = 0;
  105. _cacheMaterials = [];
  106. getMultMaterial = function (oldMat, rd = null) {
  107. let MB = MultBatch2D;
  108. endBatcher();
  109. MB.reset();
  110. if (!MB.enable || !oldMat || !rd || !rd.isMult) {
  111. return oldMat;
  112. }
  113. if (!MB.parent || !MB.parent.isValid) {
  114. loadMultTextures();
  115. return oldMat;
  116. }
  117. let newMat = _cacheMaterials[_cacheUseCount++];
  118. if (!newMat || !newMat.isValid) {
  119. let material = {
  120. parent: MB.parent
  121. };
  122. newMat = new renderer.MaterialInstance(material);
  123. _cacheMaterials[_cacheUseCount - 1] = newMat;
  124. newMat['cacheTextures'] = [];
  125. newMat['isMult'] = true;
  126. newMat.addRef();
  127. }
  128. return newMat;
  129. }; //游戏启动前,务必加载多纹理材质
  130. game.once(Game.EVENT_GAME_INITED, () => {
  131. if (EDITOR || MultBatch2D.native) return; //|| JSB
  132. loadMultTextures();
  133. }); ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  134. // 多纹理合批,sprite , label , renderdata ,等其他组件的重写和监听
  135. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  136. inject_Renderdata = function () {
  137. const RenderData = cclegacy.UI.RenderData.prototype;
  138. RenderData.texID = -1;
  139. RenderData.isMult = false;
  140. RenderData.matDirty = true;
  141. RenderData.texDirty = true;
  142. RenderData.dataDirty = 0x0; //兼容多纹理hash计算
  143. RenderData.updateHash = function () {
  144. if (this.isMult && MultBatch2D.enable) {
  145. const bid = this.chunk ? this.chunk.bufferId : -1;
  146. const hashString = `${bid}${this.layer}` + '98k';
  147. this.dataHash = murmurhash2_32_gc(hashString, 666);
  148. this.hashDirty = false;
  149. } else {
  150. const bid = this.chunk ? this.chunk.bufferId : -1;
  151. const hashString = `${bid}${this.layer} ${this.textureHash}`;
  152. this.dataHash = murmurhash2_32_gc(hashString, 666);
  153. this.hashDirty = false;
  154. }
  155. this.matDirty = false;
  156. }; //监听纹理的变更
  157. Object.defineProperty(RenderData, "textureDirty", {
  158. get: function () {
  159. return this.texDirty;
  160. },
  161. set: function (val) {
  162. this.texDirty = val;
  163. if (val === true) {
  164. this.texID = -1;
  165. }
  166. }
  167. }); //检测是否支持多纹理合批
  168. const isMultTextures = function (rd, uir) {
  169. rd.isMult = false;
  170. let material = uir.getRenderMaterial(0);
  171. if (!material || !MultBatch2D.enable) return; //@ts-ignore
  172. //组件控制开关 useMult: 可以开启自定义组件参与多纹理
  173. //|| uir instanceof Sprite || uir instanceof Label
  174. if (uir.useMult) {
  175. material._hash = material.hash || material._hash;
  176. if (!material._hash) {
  177. material._hash = Material.getHash(material);
  178. }
  179. rd.isMult = MultBatch2D.hash == material._hash;
  180. }
  181. }; //监听pass变更,检测是否多纹理支持
  182. const updatePass = RenderData.updatePass;
  183. RenderData.updatePass = function (comp) {
  184. isMultTextures(this, comp);
  185. updatePass.call(this, comp);
  186. }; //监听pass变更,检测是否多纹理支持
  187. const updateRenderData = RenderData.updateRenderData;
  188. RenderData.updateRenderData = function (comp, frame) {
  189. if (this.passDirty) {
  190. isMultTextures(this, comp);
  191. } //isMultTextures(this, comp);
  192. updateRenderData.call(this, comp, frame);
  193. };
  194. };
  195. inject_Label = function () {
  196. //@ts-ignore
  197. Label.prototype.useMult = true; //监听 Label 的 uv 变更
  198. const label = Label.Assembler;
  199. if (label) {
  200. const getAssembler = label.getAssembler;
  201. label.getAssembler = function (comp) {
  202. const assembler = getAssembler.call(this, comp);
  203. if (assembler.changeUV == undefined) {
  204. assembler.changeUV = function (s) {
  205. let rd = s.renderData;
  206. rd && (rd.dataDirty = 1);
  207. };
  208. const UVs = assembler.updateUVs;
  209. if (UVs) {
  210. if (comp.font instanceof BitmapFont) {
  211. assembler.updateUVs = function (comp) {
  212. UVs.call(this, comp);
  213. this.changeUV(comp);
  214. };
  215. } else if (comp.cacheMode === Label.CacheMode.CHAR) {
  216. assembler.updateUVs = function (comp) {
  217. UVs.call(this, comp);
  218. this.changeUV(comp);
  219. };
  220. } else {
  221. assembler.updateUVs = function (comp) {
  222. UVs.call(this, comp);
  223. const renderData = comp.renderData;
  224. if (!renderData || !comp.ttfSpriteFrame) {
  225. return;
  226. }
  227. this.changeUV(comp);
  228. };
  229. }
  230. }
  231. }
  232. return assembler;
  233. };
  234. }
  235. };
  236. inject_Sprite = function () {
  237. //@ts-ignore
  238. Sprite.prototype.useMult = true; //监听 sprite 的 uv 变更
  239. const sprite = Sprite.Assembler;
  240. if (sprite) {
  241. const getAssembler = sprite.getAssembler;
  242. sprite.getAssembler = function (comp) {
  243. const assembler = getAssembler.call(this, comp);
  244. if (assembler.changeUV == undefined) {
  245. assembler.changeUV = function (s) {
  246. let rd = s.renderData;
  247. rd && (rd.dataDirty = 1);
  248. };
  249. const UVs = assembler.updateUVs;
  250. if (UVs) {
  251. if (comp.type == Sprite.Type.FILLED) {
  252. if (comp.fillType != Sprite.FillType.RADIAL) {
  253. assembler.updateUVs = function (s, f0, f1) {
  254. UVs.call(this, s, f0, f1);
  255. this.changeUV(s);
  256. };
  257. }
  258. } else {
  259. if (comp.type != Sprite.Type.TILED) {
  260. assembler.updateUVs = function (s) {
  261. UVs.call(this, s);
  262. if (s.spriteFrame) this.changeUV(s);
  263. };
  264. }
  265. }
  266. }
  267. if (JSB) {
  268. const wUV = assembler.updateWorldUVData;
  269. if (wUV) {
  270. assembler.updateWorldUVData = function (s) {
  271. wUV.call(this, s);
  272. this.changeUV(s);
  273. };
  274. }
  275. }
  276. const verUV = assembler.updateWorldVertexAndUVData;
  277. if (verUV) {
  278. assembler.updateWorldVertexAndUVData = function (s, c) {
  279. verUV.call(this, s, c);
  280. this.changeUV(s);
  281. };
  282. }
  283. }
  284. return assembler;
  285. };
  286. }
  287. };
  288. inject_MotionStreak = function () {
  289. if (MotionStreak) {
  290. const motionStreak = MotionStreak.prototype;
  291. motionStreak.useMult = true; //参与多纹理合批
  292. const lateUpdate = motionStreak.lateUpdate;
  293. motionStreak.lateUpdate = function (dt) {
  294. lateUpdate.call(this, dt);
  295. if (this._assembler) {
  296. if (this.points.length >= 2) {
  297. let rd = this.renderData; //全局标记刷新纹理uv
  298. rd && (rd.dataDirty = 1);
  299. }
  300. }
  301. };
  302. }
  303. };
  304. inject_TiledLayer = function () {
  305. if (TiledLayer && !JSB) {
  306. const Tiled = TiledLayer.prototype;
  307. ;
  308. Tiled.useMult = true; //参与多纹理合批
  309. Tiled.dataDirty = false; //全局标记刷新纹理uv
  310. const setUserNodeDirty = Tiled.setUserNodeDirty;
  311. Tiled.setUserNodeDirty = function (dirty) {
  312. setUserNodeDirty.call(this, dirty);
  313. if (!dirty) {
  314. //全局标记刷新纹理uv
  315. this.dataDirty = true;
  316. }
  317. };
  318. Tiled._render = function (ui) {
  319. const layer = this.node.layer;
  320. for (let i = 0, j = 0; i < this._tiledDataArray.length; i++) {
  321. this._tiledDataArrayIdx = i;
  322. const m = this._tiledDataArray[i];
  323. const info = this._drawInfoList[j];
  324. if (m.subNodes) {
  325. // 提前处理 User Nodes
  326. m.subNodes.forEach(c => {
  327. if (c) {
  328. ui.walk(c.node);
  329. j++;
  330. }
  331. });
  332. } else {
  333. const td = m;
  334. if (td.texture) {
  335. let isDirty = false;
  336. let rd = td.renderData;
  337. rd.material = this.getRenderMaterial(0);
  338. if (rd.texture !== td.texture) {
  339. rd.texture = td.texture; // isDirty = true;
  340. }
  341. if (rd.layer !== layer) {
  342. rd.layer = layer;
  343. isDirty = true;
  344. }
  345. rd.isMult = true; //强制参与多纹理
  346. // if (JSB) rd._renderDrawInfo = info;
  347. //更新renderdata hash
  348. isDirty && rd.updateHash();
  349. if (this.dataDirty) rd.dataDirty = 1; // NOTE: 由于 commitComp 只支持单张纹理, 故分多次提交
  350. ui.commitComp(this, td.renderData, td.texture, this._assembler, null);
  351. j++;
  352. }
  353. }
  354. }
  355. this.dataDirty = false;
  356. this.node._static = true;
  357. };
  358. }
  359. };
  360. game.once(Game.EVENT_ENGINE_INITED, () => {
  361. if (EDITOR || MultBatch2D.native) return; //|| JSB
  362. inject_Label();
  363. inject_Sprite();
  364. inject_Renderdata();
  365. inject_TiledLayer();
  366. inject_MotionStreak();
  367. director.on(Director.EVENT_AFTER_DRAW, dt => {
  368. MultBatch2D.reset();
  369. _cacheUseCount = 0;
  370. }); ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  371. // 多纹理合批,合批核心过程修改
  372. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  373. const Batcher2D = cclegacy.internal.Batcher2D.prototype;
  374. Batcher2D.isMult = false; //多纹理标记
  375. Batcher2D.isNative = JSB; //原生的开关
  376. Batcher2D.cacheTextures = []; //纹理缓存数据
  377. Batcher2D.currMaterial = null; //当前指定材质
  378. Object.defineProperty(Batcher2D, "_currMaterial", {
  379. get: function () {
  380. return this.currMaterial;
  381. },
  382. set: function (material) {
  383. // if (this.currMaterial === material) return;
  384. //检测多纹理材质,接替 _currMaterial
  385. let rd = this._currRenderData; //重置检测
  386. if (material == this._emptyMaterial) rd = null;
  387. this.currMaterial = getMultMaterial(material, rd);
  388. this.isMult = false;
  389. if (MultBatch2D.enable) {
  390. if (this.currMaterial && this.currMaterial.isMult) {
  391. this.cacheTextures = this.currMaterial.cacheTextures;
  392. this.isMult = true; //当前 batcher 多纹理标记
  393. }
  394. }
  395. }
  396. });
  397. const Stage_ENTER_LEVEL = 2;
  398. const Stage_ENTER_LEVEL_INVERTED = 6; //@ts-ignore
  399. Batcher2D.commitComp = function (comp, renderData, frame, assembler, transform) {
  400. let dataHash = 0;
  401. let mat = null;
  402. let bufferID = -1;
  403. if (renderData && renderData.chunk) {
  404. if (!renderData.isValid()) return;
  405. dataHash = renderData.dataHash;
  406. mat = renderData.material;
  407. bufferID = renderData.chunk.bufferId;
  408. } // Notice: A little hack, if it is for mask, not need update here, while control by stencilManger
  409. if (comp.stencilStage === Stage_ENTER_LEVEL || comp.stencilStage === Stage_ENTER_LEVEL_INVERTED) {
  410. this._insertMaskBatch(comp);
  411. } else {
  412. comp.stencilStage = StencilManager.sharedManager.stage;
  413. }
  414. const depthStencilStateStage = comp.stencilStage;
  415. let texID = -1;
  416. let texture = null;
  417. let MB = MultBatch2D;
  418. let flushBatch = false;
  419. let isNative = this.isNative; //@ts-ignore
  420. if (MB.enable && renderData && renderData.isMult) {
  421. if (frame && frame.isValid) texture = frame.getGFXTexture();
  422. if (texture) {
  423. //@ts-ignore
  424. if (texture.texID === undefined) texture.texID = -1; //@ts-ignore
  425. texID = texture.texID - MB.incID;
  426. flushBatch = texID < 0 && MB.count >= MAX_TEX;
  427. if (this.isMult) mat = this._currMaterial;
  428. }
  429. }
  430. if (flushBatch || this._currHash !== dataHash || dataHash === 0 || this._currMaterial !== mat || this._currDepthStencilStateStage !== depthStencilStateStage) {
  431. // Merge all previous data to a render batch, and update buffer for next render data
  432. this.autoMergeBatches(this._currComponent);
  433. if (!isNative && renderData && !renderData._isMeshBuffer) {
  434. this.updateBuffer(renderData.vertexFormat, bufferID);
  435. }
  436. this._currRenderData = renderData;
  437. this._currHash = renderData ? renderData.dataHash : 0;
  438. this._currComponent = comp;
  439. this._currTransform = transform;
  440. this._currMaterial = comp.getRenderMaterial(0);
  441. this._currDepthStencilStateStage = depthStencilStateStage;
  442. this._currLayer = comp.node.layer;
  443. if (frame) {
  444. if (DEBUG) {
  445. assert(frame.isValid, 'frame should not be invalid, it may have been released');
  446. }
  447. this._currTexture = frame.getGFXTexture();
  448. this._currSampler = frame.getGFXSampler();
  449. this._currTextureHash = frame.getHash();
  450. this._currSamplerHash = this._currSampler.hash;
  451. } else {
  452. this._currTexture = null;
  453. this._currSampler = null;
  454. this._currTextureHash = 0;
  455. this._currSamplerHash = 0;
  456. }
  457. }
  458. if (!isNative) assembler.fillBuffers(comp, this);
  459. if (texture) {
  460. if (texID < 0 || MB.count === 0) {
  461. texID = MB.count++; //@ts-ignore
  462. //let id = texture.objectID;
  463. //@ts-ignore
  464. texture.texID = texID + MB.incID;
  465. let caches = this.cacheTextures;
  466. if (caches[texID] !== texture) {
  467. caches[texID] = texture; //@ts-ignore
  468. texture = frame.texture;
  469. if (!texture) texture = frame;
  470. this._currMaterial.setProperty("texture" + texID, texture);
  471. }
  472. }
  473. this.fillTextureID(renderData, texID);
  474. if (isNative) {
  475. renderData.renderDrawInfo.setMaterial(this._currMaterial);
  476. }
  477. }
  478. }; //填充多纹理 id 到顶点数据
  479. Batcher2D.fillTextureID = function (renderData, texID) {
  480. // if (!renderData) return;
  481. let vbuf = renderData.chunk.vb;
  482. let uvX = 0,
  483. length = vbuf.length;
  484. if (renderData.dataDirty === 1) {
  485. for (let i = 0; i < length; i += 9) {
  486. uvX = ~~(vbuf[i + 3] * 100000);
  487. vbuf[i + 3] = uvX * 10 + texID;
  488. }
  489. } else {
  490. if (renderData.texID !== texID) {
  491. for (let i = 0; i < length; i += 9) {
  492. uvX = ~~(vbuf[i + 3] * 0.1);
  493. vbuf[i + 3] = uvX * 10 + texID;
  494. }
  495. }
  496. }
  497. renderData.dataDirty = 0;
  498. renderData.texID = texID;
  499. }; ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  500. // 多纹理合批,原生平台支持的修改
  501. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  502. if (!EDITOR && JSB) {
  503. const rootProto = Root.prototype;
  504. const oldFrameMove = rootProto.frameMove;
  505. rootProto.frameMove = function (deltaTime) {
  506. var _director$root2;
  507. //@ts-ignore
  508. (_director$root2 = director.root) == null || _director$root2.batcher2D.update(); //director.root?.batcher2D.reset();
  509. oldFrameMove.call(this, deltaTime, director.getTotalFrames());
  510. };
  511. Batcher2D.update = function update() {
  512. const screens = this._screens;
  513. for (let i = 0; i < screens.length; ++i) {
  514. const screen = screens[i];
  515. const scene = screen._getRenderScene();
  516. if (!screen.enabledInHierarchy || !scene) {
  517. continue;
  518. } // Reset state and walk
  519. this._opacityDirty = 0;
  520. this._pOpacity = 1;
  521. this._batchRootDepth = 0;
  522. this.walk(screen.node);
  523. this.resetRenderStates();
  524. }
  525. this._batches.clear();
  526. this.resetRenderStates();
  527. StencilManager.sharedManager.reset();
  528. };
  529. Batcher2D.walk = function walk(node, level = 0) {
  530. if (!node.activeInHierarchy) {
  531. return;
  532. }
  533. const children = node.children;
  534. const uiProps = node._uiProps;
  535. const render = uiProps.uiComp; // Save opacity
  536. const parentOpacity = this._pOpacity;
  537. let opacity = parentOpacity; // TODO Always cascade ui property's local opacity before remove it
  538. const selfOpacity = render && render.color ? render.color.a / 255 : 1;
  539. this._pOpacity = opacity *= selfOpacity * uiProps.localOpacity; // TODO Set opacity to ui property's opacity before remove it
  540. //@ts-ignore
  541. //uiProps.setOpacity(opacity);
  542. uiProps._opacity = opacity;
  543. if (!approx(opacity, 0, EPSILON)) {
  544. // Render assembler update logic
  545. if (render && render.enabledInHierarchy) {
  546. render.fillBuffers(this); // for rendering
  547. }
  548. if (children.length > 0 && !node._static) {
  549. for (let i = 0; i < children.length; ++i) {
  550. const child = children[i];
  551. this.walk(child, level);
  552. }
  553. }
  554. } // Restore opacity
  555. this._pOpacity = parentOpacity; // Post render assembler update logic
  556. // ATTENTION: Will also reset colorDirty inside postUpdateAssembler
  557. if (render && render.enabledInHierarchy) {
  558. render.postUpdateAssembler(this);
  559. if ((render.stencilStage === Stage_ENTER_LEVEL || render.stencilStage === Stage_ENTER_LEVEL_INVERTED) && StencilManager.sharedManager.getMaskStackSize() > 0) {
  560. this.autoMergeBatches(this._currComponent);
  561. this.resetRenderStates();
  562. StencilManager.sharedManager.exitMask();
  563. }
  564. }
  565. level += 1;
  566. };
  567. Batcher2D._insertMaskBatch = function (comp) {
  568. this.autoMergeBatches(this._currComponent);
  569. this.resetRenderStates(); //this._createClearModel();
  570. //this._maskClearModel!.node = this._maskClearModel!.transform = comp.node;
  571. const _stencilManager = StencilManager.sharedManager;
  572. _stencilManager.pushMask(1); //not need object,only use length
  573. //_stencilManager.clear(comp); //invert
  574. _stencilManager.enableMask();
  575. };
  576. Batcher2D.commitModel = function (comp, model, mat) {
  577. // if the last comp is spriteComp, previous comps should be batched.
  578. if (this._currMaterial !== this._emptyMaterial) {
  579. this.autoMergeBatches(this._currComponent);
  580. this.resetRenderStates();
  581. }
  582. if (mat) {
  583. // Notice: A little hack, if it is for mask, not need update here, while control by stencilManger
  584. if (comp.stencilStage === Stage_ENTER_LEVEL || comp.stencilStage === Stage_ENTER_LEVEL_INVERTED) {
  585. this._insertMaskBatch(comp);
  586. } else {
  587. //@ts-ignore
  588. comp._stencilStage = StencilManager.sharedManager.stage;
  589. }
  590. }
  591. };
  592. Batcher2D.commitIA = function (renderComp, ia, tex, mat, transform) {
  593. // if the last comp is spriteComp, previous comps should be batched.
  594. if (this._currMaterial !== this._emptyMaterial) {
  595. this.autoMergeBatches(this._currComponent);
  596. this.resetRenderStates();
  597. }
  598. if (renderComp) {
  599. //@ts-ignore
  600. renderComp._stencilStage = StencilManager.sharedManager.stage;
  601. }
  602. };
  603. Batcher2D.commitMiddleware = function (comp, meshBuffer, indexOffset, indexCount, tex, mat, enableBatch) {
  604. this.autoMergeBatches(this._currComponent);
  605. this.resetRenderStates();
  606. this._currIsMiddleware = true;
  607. };
  608. Batcher2D.autoMergeBatches = function (renderComp) {
  609. if (this._currIsMiddleware) {
  610. // this.mergeBatchesForMiddleware(renderComp!);
  611. if (renderComp) {
  612. //@ts-ignore
  613. renderComp._stencilStage = StencilManager.sharedManager.stage;
  614. }
  615. this._currIsMiddleware = false;
  616. this._middlewareBuffer = null;
  617. }
  618. }; // if (Graphics) {
  619. // const graphics: any = Graphics.prototype;
  620. // graphics.debugDraw = false;
  621. // const _render = graphics._render;
  622. // graphics._render = function (render: any): void {
  623. // if (this.debugDraw) {
  624. // this._isNeedUploadData = false;
  625. // }
  626. // _render.call(this, render);
  627. // }
  628. // }
  629. // if (sp.Skeleton) {
  630. // const Skeleton: any = sp.Skeleton.prototype;
  631. // const _updateDebugDraw = Skeleton._updateDebugDraw;
  632. // Skeleton._updateDebugDraw = function () {
  633. // _updateDebugDraw.call(this);
  634. // if (this._debugRenderer) {
  635. // this._debugRenderer.debugDraw = true;
  636. // }
  637. // }
  638. // }
  639. }
  640. }); //*/
  641. _cclegacy._RF.pop();
  642. _crd = false;
  643. }
  644. };
  645. });
  646. //# sourceMappingURL=e55803fdad4509157e93866295c97e2478236978.js.map