8346f1745fc6cfca5a9df831ccc439dc13140cfb.js 28 KB

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