diff --git a/README.md b/README.md index 12158737..ec3f072e 100644 --- a/README.md +++ b/README.md @@ -78,6 +78,7 @@ TODO - [新特性] cc.Label、cc.RichText、cc.Sprite、cc.MotionStreak、Spine 组件支持使用多纹理材质,并支持自动切换材质机制 - [新特性] cc.RichText 支持使用自定义材质 - [修复] 直接修改 Effect 的属性不回导致其变体的 hash 值刷新 +- [修复] CHAR 缓存模式 hash 计算可能会有重复的问题 - [调整] 默认禁用 Label 原生 TTF 渲染器 所有更新日志请移步 [此处](https://smallmain.github.io/cocos-service-pack/docs/update-log)。 @@ -111,4 +112,9 @@ TODO 对于已经修改过引擎的人,由于服务包提供的是 Git Patch,所以可以让你在已有修改的基础上轻松应用上服务包的改动,甚至你可以只应用你想要的特性。 +### Cocos Creator 报 Error: Can not parse this input:undefined 错误 + +没有找到服务包的内置资源,请记得安装配套的引擎扩展。 + +--- **最后的最后,希望这个项目能帮助到你的学习或工作,enjoy!** diff --git a/demo/README.md b/demo/README.md index 4df3bdaf..ecc97e8b 100755 --- a/demo/README.md +++ b/demo/README.md @@ -21,9 +21,9 @@ // 扩展 Label:BITMAP 模式会复用同样式同文本的纹理,CHAR 模式改为使用多个图集,但是支持自动加入多纹理合批,这样就能与动态图集一起合批(增加配置,默认情况下动态图集最高8-1张,Char 图集为 1 张(无论如何设置,在装不完的情况下,因为需要正常渲染,都会最高使用 8 张图集,但是只有设置的数量才会加入多纹理合批,并且会创建一个专属材质,如果该材质无法完成渲染,会使用专属材质,或者可以仿照 spine flush buffer) // 扩展 Spine:支持自动切换材质与动态图集 -// 提醒 Spine 的材质自动切换会有缓存,修改关联的材质后,生效可以手动清除 comp._materialCache = {};,其它组件的材质生效需要 setVertsDirty +// 在编辑器中,Char 的显示有时候会出现异常 +// 提醒调整是否参与动态图集,需要 setVertsDirty // 提醒 cc.SkeletonData.createSpriteFrame ,如果 region 的旋转角度不是 270 或 0 不能完美转换,但不影响自动合图 -// 提醒 SpineData 如果同时使用多个 texture,只会使用第一个 texture 的 multiMaterial 进行自动切换 // Spine 需要更多测试!!!SkeletonData 克隆会有 ref 问题吗? // 注意:因 MotionSteak 直接使用 texture 而不是 spriteFrame,所以不支持动态图集 diff --git a/demo/assets/left-area.ts b/demo/assets/left-area.ts new file mode 100644 index 00000000..38cf5d3a --- /dev/null +++ b/demo/assets/left-area.ts @@ -0,0 +1,67 @@ +const { ccclass, property } = cc._decorator; + +@ccclass +export default class LeftArea extends cc.Component { + + @property(cc.Node) + home: cc.Node = null; + + @property(cc.Node) + multiMaterial: cc.Node = null; + + @property(cc.Node) + multiBatcher: cc.Node = null; + + @property(cc.Node) + mainArea: cc.Node = null; + + + start() { + this.home.on('toggle', (toggle: cc.Toggle) => { + if (toggle.isChecked) { + this.changePage(toggle.node); + } + }); + + this.multiMaterial.on('toggle', (toggle: cc.Toggle) => { + if (toggle.isChecked) { + this.changePage(toggle.node); + } + }); + + this.multiBatcher.on('toggle', (toggle: cc.Toggle) => { + if (toggle.isChecked) { + this.changePage(toggle.node); + } + }); + } + + tick = 0; + + changePage(node: cc.Node) { + const cur = ++this.tick; + const map = new Map([ + + [this.multiMaterial, { bundle: "multi-render", path: "multi-material/multi-material" }], + + [this.multiBatcher, { bundle: "multi-render", path: "multi-batcher/multi-batcher" }], + + ]); + + this.mainArea.destroyAllChildren(); + + const route = map.get(node); + if (route) { + cc.assetManager.loadBundle(route.bundle, (err, bundle) => { + if (!err) { + bundle.load(route.path, cc.Prefab, (err, prefab: cc.Prefab) => { + if (!err && cur === this.tick) { + this.mainArea.addChild(cc.instantiate(prefab)); + } + }); + } + }); + } + } + +} diff --git a/demo/assets/left-area.ts.meta b/demo/assets/left-area.ts.meta new file mode 100644 index 00000000..71707686 --- /dev/null +++ b/demo/assets/left-area.ts.meta @@ -0,0 +1,9 @@ +{ + "ver": "1.0.8", + "uuid": "853f5bb2-1b9a-451e-911a-5de5ed6b530b", + "isPlugin": false, + "loadPluginInWeb": true, + "loadPluginInNative": true, + "loadPluginInEditor": false, + "subMetas": {} +} \ No newline at end of file diff --git a/demo/assets/main.fire b/demo/assets/main.fire index 97b65918..e284bfd8 100644 --- a/demo/assets/main.fire +++ b/demo/assets/main.fire @@ -75,19 +75,19 @@ "__id__": 5 }, { - "__id__": 66 + "__id__": 69 } ], "_active": true, "_components": [ - { - "__id__": 70 - }, { "__id__": 71 }, { "__id__": 72 + }, + { + "__id__": 73 } ], "_prefab": null, @@ -102,7 +102,7 @@ "_contentSize": { "__type__": "cc.Size", "width": 960, - "height": 640 + "height": 600 }, "_anchorPoint": { "__type__": "cc.Vec2", @@ -114,7 +114,7 @@ "ctor": "Float64Array", "array": [ 480, - 320, + 300, 0, 0, 0, @@ -248,19 +248,22 @@ "__id__": 6 }, { - "__id__": 57 + "__id__": 59 } ], "_active": true, "_components": [ { - "__id__": 61 + "__id__": 63 }, { - "__id__": 64 + "__id__": 66 }, { - "__id__": 65 + "__id__": 67 + }, + { + "__id__": 68 } ], "_prefab": null, @@ -275,7 +278,7 @@ "_contentSize": { "__type__": "cc.Size", "width": 240, - "height": 640 + "height": 600 }, "_anchorPoint": { "__type__": "cc.Vec2", @@ -326,7 +329,7 @@ "_active": true, "_components": [ { - "__id__": 56 + "__id__": 58 } ], "_prefab": null, @@ -341,7 +344,7 @@ "_contentSize": { "__type__": "cc.Size", "width": 240, - "height": 640 + "height": 600 }, "_anchorPoint": { "__type__": "cc.Vec2", @@ -402,18 +405,21 @@ }, { "__id__": 41 + }, + { + "__id__": 43 } ], "_active": true, "_components": [ - { - "__id__": 53 - }, - { - "__id__": 54 - }, { "__id__": 55 + }, + { + "__id__": 56 + }, + { + "__id__": 57 } ], "_prefab": null, @@ -428,7 +434,7 @@ "_contentSize": { "__type__": "cc.Size", "width": 240, - "height": 262 + "height": 263 }, "_anchorPoint": { "__type__": "cc.Vec2", @@ -440,7 +446,7 @@ "ctor": "Float64Array", "array": [ 0, - 320, + 300, 0, 0, 0, @@ -553,13 +559,13 @@ "_batchAsBitmap": false, "_styleFlags": 0, "_underlineHeight": 0, - "autoSwitchMaterial": 0, - "allowDynamicAtlas": 0, "_N$horizontalAlign": 1, "_N$verticalAlign": 1, "_N$fontFamily": "Arial", "_N$overflow": 0, "_N$cacheMode": 2, + "_N$autoSwitchMaterial": 0, + "_N$allowDynamicAtlas": 0, "_N$enableRetina": 0, "_id": "b9rtT8HFhB+aRlMVUwgWwY" }, @@ -679,13 +685,13 @@ "_batchAsBitmap": false, "_styleFlags": 0, "_underlineHeight": 0, - "autoSwitchMaterial": 0, - "allowDynamicAtlas": 0, "_N$horizontalAlign": 1, "_N$verticalAlign": 1, "_N$fontFamily": "Arial", "_N$overflow": 3, "_N$cacheMode": 2, + "_N$autoSwitchMaterial": 0, + "_N$allowDynamicAtlas": 0, "_N$enableRetina": 0, "_id": "bbcML2sgVD/YS8wLMkuo84" }, @@ -886,8 +892,8 @@ "_fillRange": 0, "_isTrimmedMode": true, "_atlas": null, - "autoSwitchMaterial": 0, - "allowDynamicAtlas": 0, + "_N$autoSwitchMaterial": 0, + "_N$allowDynamicAtlas": 0, "_id": "d1eHsjYk9EWr2gwaBHGR8s" }, { @@ -925,7 +931,7 @@ "__id__": 14 }, "_children": [], - "_active": false, + "_active": true, "_components": [ { "__id__": 19 @@ -1012,8 +1018,8 @@ "_fillRange": 0, "_isTrimmedMode": true, "_atlas": null, - "autoSwitchMaterial": 0, - "allowDynamicAtlas": 0, + "_N$autoSwitchMaterial": 0, + "_N$allowDynamicAtlas": 0, "_id": "769i+ShNFDY7d+bfuiGFh/" }, { @@ -1132,13 +1138,13 @@ "_batchAsBitmap": false, "_styleFlags": 0, "_underlineHeight": 0, - "autoSwitchMaterial": 0, - "allowDynamicAtlas": 0, "_N$horizontalAlign": 1, "_N$verticalAlign": 1, "_N$fontFamily": "Arial", "_N$overflow": 0, "_N$cacheMode": 2, + "_N$autoSwitchMaterial": 0, + "_N$allowDynamicAtlas": 0, "_N$enableRetina": 0, "_id": "87mFyGpZpOMYGs0HmWLjQ9" }, @@ -1237,7 +1243,7 @@ "_N$target": { "__id__": 14 }, - "_N$isChecked": false, + "_N$isChecked": true, "toggleGroup": null, "checkMark": { "__id__": 19 @@ -1361,13 +1367,13 @@ "_batchAsBitmap": false, "_styleFlags": 0, "_underlineHeight": 0, - "autoSwitchMaterial": 0, - "allowDynamicAtlas": 0, "_N$horizontalAlign": 1, "_N$verticalAlign": 1, "_N$fontFamily": "Arial", "_N$overflow": 0, "_N$cacheMode": 2, + "_N$autoSwitchMaterial": 0, + "_N$allowDynamicAtlas": 0, "_N$enableRetina": 0, "_id": "46oKx6E7JC/aSnbXeUrraO" }, @@ -1568,8 +1574,8 @@ "_fillRange": 0, "_isTrimmedMode": true, "_atlas": null, - "autoSwitchMaterial": 0, - "allowDynamicAtlas": 0, + "_N$autoSwitchMaterial": 0, + "_N$allowDynamicAtlas": 0, "_id": "dasBuXH4lJbZaV0blB4989" }, { @@ -1607,7 +1613,7 @@ "__id__": 29 }, "_children": [], - "_active": true, + "_active": false, "_components": [ { "__id__": 34 @@ -1694,8 +1700,8 @@ "_fillRange": 0, "_isTrimmedMode": true, "_atlas": null, - "autoSwitchMaterial": 0, - "allowDynamicAtlas": 0, + "_N$autoSwitchMaterial": 0, + "_N$allowDynamicAtlas": 0, "_id": "cfO0DHZfFP+pO/CmbuMLc1" }, { @@ -1814,13 +1820,13 @@ "_batchAsBitmap": false, "_styleFlags": 0, "_underlineHeight": 0, - "autoSwitchMaterial": 0, - "allowDynamicAtlas": 0, "_N$horizontalAlign": 1, "_N$verticalAlign": 1, "_N$fontFamily": "Arial", "_N$overflow": 0, "_N$cacheMode": 2, + "_N$autoSwitchMaterial": 0, + "_N$allowDynamicAtlas": 0, "_N$enableRetina": 0, "_id": "b5LPG0j+lP4J3NQeiyoIU0" }, @@ -1919,7 +1925,7 @@ "_N$target": { "__id__": 29 }, - "_N$isChecked": true, + "_N$isChecked": false, "toggleGroup": null, "checkMark": { "__id__": 34 @@ -1954,6 +1960,102 @@ "_originalHeight": 0, "_id": "ea4HVs3PZPMooZxVgDb4oF" }, + { + "__type__": "cc.Node", + "_name": "line", + "_objFlags": 0, + "_parent": { + "__id__": 7 + }, + "_children": [], + "_active": true, + "_components": [ + { + "__id__": 42 + } + ], + "_prefab": null, + "_opacity": 150, + "_color": { + "__type__": "cc.Color", + "r": 0, + "g": 0, + "b": 0, + "a": 255 + }, + "_contentSize": { + "__type__": "cc.Size", + "width": 240, + "height": 1 + }, + "_anchorPoint": { + "__type__": "cc.Vec2", + "x": 0.5, + "y": 0.5 + }, + "_trs": { + "__type__": "TypedArray", + "ctor": "Float64Array", + "array": [ + 0, + -212.5, + 0, + 0, + 0, + 0, + 1, + 1, + 1, + 1 + ] + }, + "_eulerAngles": { + "__type__": "cc.Vec3", + "x": 0, + "y": 0, + "z": 0 + }, + "_skewX": 0, + "_skewY": 0, + "_is3DNode": false, + "_groupIndex": 0, + "groupIndex": 0, + "_id": "fdLjmHzURHBoTovn46gkO+" + }, + { + "__type__": "cc.Sprite", + "_name": "", + "_objFlags": 0, + "node": { + "__id__": 41 + }, + "_enabled": true, + "_materials": [ + { + "__uuid__": "eca5d2f2-8ef6-41c2-bbe6-f9c79d09c432" + } + ], + "_srcBlendFactor": 770, + "_dstBlendFactor": 771, + "_spriteFrame": { + "__uuid__": "a23235d1-15db-4b95-8439-a2e005bfff91" + }, + "_type": 0, + "_sizeMode": 0, + "_fillType": 0, + "_fillCenter": { + "__type__": "cc.Vec2", + "x": 0, + "y": 0 + }, + "_fillStart": 0, + "_fillRange": 0, + "_isTrimmedMode": true, + "_atlas": null, + "_N$autoSwitchMaterial": 0, + "_N$allowDynamicAtlas": 0, + "_id": "c9/hc9CapODpisEzYuFwpJ" + }, { "__type__": "cc.Node", "_name": "multi-render-batcher", @@ -1963,22 +2065,22 @@ }, "_children": [ { - "__id__": 42 + "__id__": 44 }, { - "__id__": 45 + "__id__": 47 }, { - "__id__": 48 + "__id__": 50 } ], "_active": true, "_components": [ { - "__id__": 51 + "__id__": 53 }, { - "__id__": 52 + "__id__": 54 } ], "_prefab": null, @@ -2005,7 +2107,7 @@ "ctor": "Float64Array", "array": [ 0, - -237, + -238, 0, 0, 0, @@ -2034,16 +2136,16 @@ "_name": "bg", "_objFlags": 0, "_parent": { - "__id__": 41 + "__id__": 43 }, "_children": [], "_active": true, "_components": [ { - "__id__": 43 + "__id__": 45 }, { - "__id__": 44 + "__id__": 46 } ], "_prefab": null, @@ -2099,7 +2201,7 @@ "_name": "", "_objFlags": 0, "node": { - "__id__": 42 + "__id__": 44 }, "_enabled": true, "_materials": [ @@ -2124,8 +2226,8 @@ "_fillRange": 0, "_isTrimmedMode": true, "_atlas": null, - "autoSwitchMaterial": 0, - "allowDynamicAtlas": 0, + "_N$autoSwitchMaterial": 0, + "_N$allowDynamicAtlas": 0, "_id": "5eCAXTLddC2YYw0qj1Ydlo" }, { @@ -2133,7 +2235,7 @@ "_name": "", "_objFlags": 0, "node": { - "__id__": 42 + "__id__": 44 }, "_enabled": true, "alignMode": 1, @@ -2160,16 +2262,16 @@ "_name": "check", "_objFlags": 0, "_parent": { - "__id__": 41 + "__id__": 43 }, "_children": [], "_active": false, "_components": [ { - "__id__": 46 + "__id__": 48 }, { - "__id__": 47 + "__id__": 49 } ], "_prefab": null, @@ -2225,7 +2327,7 @@ "_name": "", "_objFlags": 0, "node": { - "__id__": 45 + "__id__": 47 }, "_enabled": true, "_materials": [ @@ -2250,8 +2352,8 @@ "_fillRange": 0, "_isTrimmedMode": true, "_atlas": null, - "autoSwitchMaterial": 0, - "allowDynamicAtlas": 0, + "_N$autoSwitchMaterial": 0, + "_N$allowDynamicAtlas": 0, "_id": "c5Ph4qQRRGKLk4UsU2CuP1" }, { @@ -2259,7 +2361,7 @@ "_name": "", "_objFlags": 0, "node": { - "__id__": 45 + "__id__": 47 }, "_enabled": true, "alignMode": 1, @@ -2286,16 +2388,16 @@ "_name": "text", "_objFlags": 0, "_parent": { - "__id__": 41 + "__id__": 43 }, "_children": [], "_active": true, "_components": [ { - "__id__": 49 + "__id__": 51 }, { - "__id__": 50 + "__id__": 52 } ], "_prefab": null, @@ -2351,7 +2453,7 @@ "_name": "", "_objFlags": 0, "node": { - "__id__": 48 + "__id__": 50 }, "_enabled": true, "_materials": [ @@ -2370,13 +2472,13 @@ "_batchAsBitmap": false, "_styleFlags": 0, "_underlineHeight": 0, - "autoSwitchMaterial": 0, - "allowDynamicAtlas": 0, "_N$horizontalAlign": 1, "_N$verticalAlign": 1, "_N$fontFamily": "Arial", "_N$overflow": 0, "_N$cacheMode": 2, + "_N$autoSwitchMaterial": 0, + "_N$allowDynamicAtlas": 0, "_N$enableRetina": 0, "_id": "20fk8U3rpIGarOxB/zN7Js" }, @@ -2385,7 +2487,7 @@ "_name": "", "_objFlags": 0, "node": { - "__id__": 48 + "__id__": 50 }, "_enabled": true, "alignMode": 1, @@ -2412,7 +2514,7 @@ "_name": "", "_objFlags": 0, "node": { - "__id__": 41 + "__id__": 43 }, "_enabled": true, "_normalMaterial": null, @@ -2473,12 +2575,12 @@ "hoverSprite": null, "_N$disabledSprite": null, "_N$target": { - "__id__": 41 + "__id__": 43 }, "_N$isChecked": false, "toggleGroup": null, "checkMark": { - "__id__": 46 + "__id__": 48 }, "checkEvents": [], "_id": "e7i26YZV1FqKklg91bgGv0" @@ -2488,7 +2590,7 @@ "_name": "", "_objFlags": 0, "node": { - "__id__": 41 + "__id__": 43 }, "_enabled": true, "alignMode": 1, @@ -2533,7 +2635,7 @@ "_layoutSize": { "__type__": "cc.Size", "width": 240, - "height": 262 + "height": 263 }, "_resize": 1, "_N$layoutType": 2, @@ -2617,19 +2719,19 @@ }, "_children": [ { - "__id__": 58 + "__id__": 60 } ], "_active": true, "_components": [ - { - "__id__": 60 - }, { "__id__": 62 }, { - "__id__": 63 + "__id__": 64 + }, + { + "__id__": 65 } ], "_prefab": null, @@ -2644,7 +2746,7 @@ "_contentSize": { "__type__": "cc.Size", "width": 8, - "height": 640 + "height": 600 }, "_anchorPoint": { "__type__": "cc.Vec2", @@ -2685,13 +2787,13 @@ "_name": "bar", "_objFlags": 0, "_parent": { - "__id__": 57 + "__id__": 59 }, "_children": [], "_active": true, "_components": [ { - "__id__": 59 + "__id__": 61 } ], "_prefab": null, @@ -2747,7 +2849,7 @@ "_name": "", "_objFlags": 0, "node": { - "__id__": 58 + "__id__": 60 }, "_enabled": true, "_materials": [ @@ -2772,8 +2874,8 @@ "_fillRange": 0, "_isTrimmedMode": true, "_atlas": null, - "autoSwitchMaterial": 0, - "allowDynamicAtlas": 0, + "_N$autoSwitchMaterial": 0, + "_N$allowDynamicAtlas": 0, "_id": "9c2SrYmphDVquAHlr87fA/" }, { @@ -2781,18 +2883,18 @@ "_name": "", "_objFlags": 0, "node": { - "__id__": 57 + "__id__": 59 }, "_enabled": true, "_scrollView": { - "__id__": 61 + "__id__": 63 }, "_touching": false, "_opacity": 255, "enableAutoHide": true, "autoHideTime": 1, "_N$handle": { - "__id__": 59 + "__id__": 61 }, "_N$direction": 1, "_id": "45lAX/jYFK8bn5il0V2PGf" @@ -2821,7 +2923,7 @@ }, "_N$horizontalScrollBar": null, "_N$verticalScrollBar": { - "__id__": 60 + "__id__": 62 }, "_id": "f1ZKPgwatHKqxBlPMr/vU6" }, @@ -2830,7 +2932,7 @@ "_name": "", "_objFlags": 0, "node": { - "__id__": 57 + "__id__": 59 }, "_enabled": true, "alignMode": 0, @@ -2857,7 +2959,7 @@ "_name": "", "_objFlags": 0, "node": { - "__id__": 57 + "__id__": 59 }, "_enabled": true, "_materials": [ @@ -2882,8 +2984,8 @@ "_fillRange": 0, "_isTrimmedMode": true, "_atlas": null, - "autoSwitchMaterial": 0, - "allowDynamicAtlas": 0, + "_N$autoSwitchMaterial": 0, + "_N$allowDynamicAtlas": 0, "_id": "ffwZ4WTWJLeoK7epp1s1o3" }, { @@ -2943,10 +3045,32 @@ "_fillRange": 0, "_isTrimmedMode": false, "_atlas": null, - "autoSwitchMaterial": 0, - "allowDynamicAtlas": 0, + "_N$autoSwitchMaterial": 0, + "_N$allowDynamicAtlas": 0, "_id": "08P8DmnE9J748Jelsz9lrw" }, + { + "__type__": "853f5uyG5pFHpEaXeXta1ML", + "_name": "", + "_objFlags": 0, + "node": { + "__id__": 5 + }, + "_enabled": true, + "home": { + "__id__": 14 + }, + "multiMaterial": { + "__id__": 29 + }, + "multiBatcher": { + "__id__": 43 + }, + "mainArea": { + "__id__": 69 + }, + "_id": "62KSyy38xD/LU3CscZK3qC" + }, { "__type__": "cc.Node", "_name": "main-area", @@ -2954,15 +3078,11 @@ "_parent": { "__id__": 2 }, - "_children": [ - { - "__id__": 67 - } - ], + "_children": [], "_active": true, "_components": [ { - "__id__": 69 + "__id__": 70 } ], "_prefab": null, @@ -2977,7 +3097,7 @@ "_contentSize": { "__type__": "cc.Size", "width": 720, - "height": 640 + "height": 600 }, "_anchorPoint": { "__type__": "cc.Vec2", @@ -3013,58 +3133,12 @@ "groupIndex": 0, "_id": "54WBhHVtBF4JdadFee+PuD" }, - { - "__type__": "cc.Node", - "_objFlags": 0, - "_parent": { - "__id__": 66 - }, - "_prefab": { - "__id__": 68 - }, - "_name": "multi-material", - "_active": true, - "_trs": { - "__type__": "TypedArray", - "ctor": "Float64Array", - "array": [ - 0, - 0, - 0, - 0, - 0, - 0, - 1, - 1, - 1, - 1 - ] - }, - "_eulerAngles": { - "__type__": "cc.Vec3", - "x": 0, - "y": 0, - "z": 0 - }, - "_id": "e961JkgDFHhpfE4jDsQXGc" - }, - { - "__type__": "cc.PrefabInfo", - "root": { - "__id__": 67 - }, - "asset": { - "__uuid__": "c5f3051e-1b4f-4384-939c-b838bcb8f5bf" - }, - "fileId": "", - "sync": true - }, { "__type__": "cc.Widget", "_name": "", "_objFlags": 0, "node": { - "__id__": 66 + "__id__": 69 }, "_enabled": true, "alignMode": 1, @@ -3097,7 +3171,7 @@ "_designResolution": { "__type__": "cc.Size", "width": 960, - "height": 640 + "height": 600 }, "_fitWidth": false, "_fitHeight": true, diff --git a/demo/assets/multi-render/multi-batcher.meta b/demo/assets/multi-render/multi-batcher.meta new file mode 100644 index 00000000..85ab9e3a --- /dev/null +++ b/demo/assets/multi-render/multi-batcher.meta @@ -0,0 +1,12 @@ +{ + "ver": "1.1.2", + "uuid": "6aa6d587-b168-40f9-b961-78e28fc4e9a7", + "isBundle": false, + "bundleName": "", + "priority": 1, + "compressionType": {}, + "optimizeHotUpdate": {}, + "inlineSpriteFrames": {}, + "isRemoteBundle": {}, + "subMetas": {} +} \ No newline at end of file diff --git a/demo/assets/multi-render/multi-batcher/multi-batcher.prefab b/demo/assets/multi-render/multi-batcher/multi-batcher.prefab new file mode 100644 index 00000000..306959bd --- /dev/null +++ b/demo/assets/multi-render/multi-batcher/multi-batcher.prefab @@ -0,0 +1,958 @@ +[ + { + "__type__": "cc.Prefab", + "_name": "", + "_objFlags": 0, + "_native": "", + "data": { + "__id__": 1 + }, + "optimizationPolicy": 0, + "asyncLoadAssets": false, + "readonly": false + }, + { + "__type__": "cc.Node", + "_name": "multi-batcher", + "_objFlags": 0, + "_parent": null, + "_children": [ + { + "__id__": 2 + } + ], + "_active": true, + "_components": [ + { + "__id__": 26 + }, + { + "__id__": 27 + } + ], + "_prefab": { + "__id__": 28 + }, + "_opacity": 255, + "_color": { + "__type__": "cc.Color", + "r": 255, + "g": 255, + "b": 255, + "a": 255 + }, + "_contentSize": { + "__type__": "cc.Size", + "width": 960, + "height": 600 + }, + "_anchorPoint": { + "__type__": "cc.Vec2", + "x": 0.5, + "y": 0.5 + }, + "_trs": { + "__type__": "TypedArray", + "ctor": "Float64Array", + "array": [ + 480, + 300, + 0, + 0, + 0, + 0, + 1, + 1, + 1, + 1 + ] + }, + "_eulerAngles": { + "__type__": "cc.Vec3", + "x": 0, + "y": 0, + "z": 0 + }, + "_skewX": 0, + "_skewY": 0, + "_is3DNode": false, + "_groupIndex": 0, + "groupIndex": 0, + "_id": "" + }, + { + "__type__": "cc.Node", + "_name": "sv", + "_objFlags": 0, + "_parent": { + "__id__": 1 + }, + "_children": [ + { + "__id__": 3 + }, + { + "__id__": 14 + } + ], + "_active": true, + "_components": [ + { + "__id__": 19 + }, + { + "__id__": 23 + }, + { + "__id__": 24 + } + ], + "_prefab": { + "__id__": 25 + }, + "_opacity": 255, + "_color": { + "__type__": "cc.Color", + "r": 25, + "g": 25, + "b": 25, + "a": 255 + }, + "_contentSize": { + "__type__": "cc.Size", + "width": 960, + "height": 600 + }, + "_anchorPoint": { + "__type__": "cc.Vec2", + "x": 0.5, + "y": 0.5 + }, + "_trs": { + "__type__": "TypedArray", + "ctor": "Float64Array", + "array": [ + 0, + 0, + 0, + 0, + 0, + 0, + 1, + 1, + 1, + 1 + ] + }, + "_eulerAngles": { + "__type__": "cc.Vec3", + "x": 0, + "y": 0, + "z": 0 + }, + "_skewX": 0, + "_skewY": 0, + "_is3DNode": false, + "_groupIndex": 0, + "groupIndex": 0, + "_id": "" + }, + { + "__type__": "cc.Node", + "_name": "view", + "_objFlags": 0, + "_parent": { + "__id__": 2 + }, + "_children": [ + { + "__id__": 4 + } + ], + "_active": true, + "_components": [ + { + "__id__": 12 + } + ], + "_prefab": { + "__id__": 13 + }, + "_opacity": 255, + "_color": { + "__type__": "cc.Color", + "r": 255, + "g": 255, + "b": 255, + "a": 255 + }, + "_contentSize": { + "__type__": "cc.Size", + "width": 960, + "height": 600 + }, + "_anchorPoint": { + "__type__": "cc.Vec2", + "x": 0.5, + "y": 0.5 + }, + "_trs": { + "__type__": "TypedArray", + "ctor": "Float64Array", + "array": [ + 0, + 0, + 0, + 0, + 0, + 0, + 1, + 1, + 1, + 1 + ] + }, + "_eulerAngles": { + "__type__": "cc.Vec3", + "x": 0, + "y": 0, + "z": 0 + }, + "_skewX": 0, + "_skewY": 0, + "_is3DNode": false, + "_groupIndex": 0, + "groupIndex": 0, + "_id": "" + }, + { + "__type__": "cc.Node", + "_name": "content", + "_objFlags": 0, + "_parent": { + "__id__": 3 + }, + "_children": [ + { + "__id__": 5 + } + ], + "_active": true, + "_components": [ + { + "__id__": 8 + }, + { + "__id__": 9 + }, + { + "__id__": 10 + } + ], + "_prefab": { + "__id__": 11 + }, + "_opacity": 255, + "_color": { + "__type__": "cc.Color", + "r": 255, + "g": 255, + "b": 255, + "a": 255 + }, + "_contentSize": { + "__type__": "cc.Size", + "width": 785.815, + "height": 110 + }, + "_anchorPoint": { + "__type__": "cc.Vec2", + "x": 0.5, + "y": 1 + }, + "_trs": { + "__type__": "TypedArray", + "ctor": "Float64Array", + "array": [ + 0, + 300, + 0, + 0, + 0, + 0, + 1, + 1, + 1, + 1 + ] + }, + "_eulerAngles": { + "__type__": "cc.Vec3", + "x": 0, + "y": 0, + "z": 0 + }, + "_skewX": 0, + "_skewY": 0, + "_is3DNode": false, + "_groupIndex": 0, + "groupIndex": 0, + "_id": "" + }, + { + "__type__": "cc.Node", + "_name": "tips", + "_objFlags": 0, + "_parent": { + "__id__": 4 + }, + "_children": [], + "_active": true, + "_components": [ + { + "__id__": 6 + } + ], + "_prefab": { + "__id__": 7 + }, + "_opacity": 255, + "_color": { + "__type__": "cc.Color", + "r": 255, + "g": 255, + "b": 255, + "a": 255 + }, + "_contentSize": { + "__type__": "cc.Size", + "width": 664.92, + "height": 80 + }, + "_anchorPoint": { + "__type__": "cc.Vec2", + "x": 0.5, + "y": 0.5 + }, + "_trs": { + "__type__": "TypedArray", + "ctor": "Float64Array", + "array": [ + 0, + -70, + 0, + 0, + 0, + 0, + 1, + 1, + 1, + 1 + ] + }, + "_eulerAngles": { + "__type__": "cc.Vec3", + "x": 0, + "y": 0, + "z": 0 + }, + "_skewX": 0, + "_skewY": 0, + "_is3DNode": false, + "_groupIndex": 0, + "groupIndex": 0, + "_id": "" + }, + { + "__type__": "cc.Label", + "_name": "", + "_objFlags": 0, + "node": { + "__id__": 5 + }, + "_enabled": true, + "_materials": [ + null + ], + "_srcBlendFactor": 770, + "_dstBlendFactor": 771, + "_string": "点击按钮设置这些渲染组件纹理的关联材质,能看到 drawcall 的降低\n(切换左边的选项卡重置)", + "_N$string": "点击按钮设置这些渲染组件纹理的关联材质,能看到 drawcall 的降低\n(切换左边的选项卡重置)", + "_fontSize": 22, + "_lineHeight": 40, + "_enableWrapText": true, + "_N$file": null, + "_isSystemFontUsed": true, + "_spacingX": 0, + "_batchAsBitmap": false, + "_styleFlags": 0, + "_underlineHeight": 0, + "_N$horizontalAlign": 1, + "_N$verticalAlign": 1, + "_N$fontFamily": "Arial", + "_N$overflow": 0, + "_N$cacheMode": 2, + "_N$autoSwitchMaterial": 0, + "_N$allowDynamicAtlas": 0, + "_N$enableRetina": 0, + "_id": "" + }, + { + "__type__": "cc.PrefabInfo", + "root": { + "__id__": 1 + }, + "asset": { + "__uuid__": "145bba41-1962-49ee-aec9-08fb154e8bf2" + }, + "fileId": "fbSLTYNutL174TDvzvU3nT", + "sync": false + }, + { + "__type__": "cc.ToggleContainer", + "_name": "", + "_objFlags": 0, + "node": { + "__id__": 4 + }, + "_enabled": true, + "allowSwitchOff": false, + "checkEvents": [], + "_id": "" + }, + { + "__type__": "cc.Layout", + "_name": "", + "_objFlags": 0, + "node": { + "__id__": 4 + }, + "_enabled": true, + "_layoutSize": { + "__type__": "cc.Size", + "width": 785.815, + "height": 110 + }, + "_resize": 1, + "_N$layoutType": 2, + "_N$cellSize": { + "__type__": "cc.Size", + "width": 40, + "height": 40 + }, + "_N$startAxis": 1, + "_N$paddingLeft": 0, + "_N$paddingRight": 0, + "_N$paddingTop": 30, + "_N$paddingBottom": 0, + "_N$spacingX": 0, + "_N$spacingY": 0, + "_N$verticalDirection": 1, + "_N$horizontalDirection": 0, + "_N$affectedByScale": false, + "_id": "" + }, + { + "__type__": "cc.Widget", + "_name": "", + "_objFlags": 0, + "node": { + "__id__": 4 + }, + "_enabled": true, + "alignMode": 1, + "_target": null, + "_alignFlags": 41, + "_left": 87.09249999999997, + "_right": 87.09249999999997, + "_top": 0, + "_bottom": 0, + "_verticalCenter": 0, + "_horizontalCenter": 0, + "_isAbsLeft": true, + "_isAbsRight": true, + "_isAbsTop": true, + "_isAbsBottom": true, + "_isAbsHorizontalCenter": true, + "_isAbsVerticalCenter": true, + "_originalWidth": 220, + "_originalHeight": 0, + "_id": "" + }, + { + "__type__": "cc.PrefabInfo", + "root": { + "__id__": 1 + }, + "asset": { + "__uuid__": "145bba41-1962-49ee-aec9-08fb154e8bf2" + }, + "fileId": "98B5382ANHgKQw5BkMsWAq", + "sync": false + }, + { + "__type__": "cc.Widget", + "_name": "", + "_objFlags": 0, + "node": { + "__id__": 3 + }, + "_enabled": true, + "alignMode": 1, + "_target": null, + "_alignFlags": 45, + "_left": 0, + "_right": 0, + "_top": 0, + "_bottom": 0, + "_verticalCenter": 0, + "_horizontalCenter": 0, + "_isAbsLeft": true, + "_isAbsRight": true, + "_isAbsTop": true, + "_isAbsBottom": true, + "_isAbsHorizontalCenter": true, + "_isAbsVerticalCenter": true, + "_originalWidth": 240, + "_originalHeight": 250, + "_id": "" + }, + { + "__type__": "cc.PrefabInfo", + "root": { + "__id__": 1 + }, + "asset": { + "__uuid__": "145bba41-1962-49ee-aec9-08fb154e8bf2" + }, + "fileId": "645yltQ0dFpbIcIgDazPDc", + "sync": false + }, + { + "__type__": "cc.Node", + "_name": "scrollBar", + "_objFlags": 0, + "_parent": { + "__id__": 2 + }, + "_children": [ + { + "__id__": 15 + } + ], + "_active": true, + "_components": [ + { + "__id__": 18 + }, + { + "__id__": 20 + }, + { + "__id__": 21 + } + ], + "_prefab": { + "__id__": 22 + }, + "_opacity": 255, + "_color": { + "__type__": "cc.Color", + "r": 255, + "g": 255, + "b": 255, + "a": 255 + }, + "_contentSize": { + "__type__": "cc.Size", + "width": 8, + "height": 600 + }, + "_anchorPoint": { + "__type__": "cc.Vec2", + "x": 1, + "y": 0.5 + }, + "_trs": { + "__type__": "TypedArray", + "ctor": "Float64Array", + "array": [ + 480, + 0, + 0, + 0, + 0, + 0, + 1, + 1, + 1, + 1 + ] + }, + "_eulerAngles": { + "__type__": "cc.Vec3", + "x": 0, + "y": 0, + "z": 0 + }, + "_skewX": 0, + "_skewY": 0, + "_is3DNode": false, + "_groupIndex": 0, + "groupIndex": 0, + "_id": "" + }, + { + "__type__": "cc.Node", + "_name": "bar", + "_objFlags": 0, + "_parent": { + "__id__": 14 + }, + "_children": [], + "_active": true, + "_components": [ + { + "__id__": 16 + } + ], + "_prefab": { + "__id__": 17 + }, + "_opacity": 255, + "_color": { + "__type__": "cc.Color", + "r": 255, + "g": 255, + "b": 255, + "a": 255 + }, + "_contentSize": { + "__type__": "cc.Size", + "width": 8, + "height": 30 + }, + "_anchorPoint": { + "__type__": "cc.Vec2", + "x": 1, + "y": 0 + }, + "_trs": { + "__type__": "TypedArray", + "ctor": "Float64Array", + "array": [ + 0, + 0, + 0, + 0, + 0, + 0, + 1, + 1, + 1, + 1 + ] + }, + "_eulerAngles": { + "__type__": "cc.Vec3", + "x": 0, + "y": 0, + "z": 0 + }, + "_skewX": 0, + "_skewY": 0, + "_is3DNode": false, + "_groupIndex": 0, + "groupIndex": 0, + "_id": "" + }, + { + "__type__": "cc.Sprite", + "_name": "", + "_objFlags": 0, + "node": { + "__id__": 15 + }, + "_enabled": true, + "_materials": [ + { + "__uuid__": "eca5d2f2-8ef6-41c2-bbe6-f9c79d09c432" + } + ], + "_srcBlendFactor": 770, + "_dstBlendFactor": 771, + "_spriteFrame": { + "__uuid__": "5c3bb932-6c3c-468f-88a9-c8c61d458641" + }, + "_type": 1, + "_sizeMode": 0, + "_fillType": 0, + "_fillCenter": { + "__type__": "cc.Vec2", + "x": 0, + "y": 0 + }, + "_fillStart": 0, + "_fillRange": 0, + "_isTrimmedMode": true, + "_atlas": null, + "_N$autoSwitchMaterial": 0, + "_N$allowDynamicAtlas": 0, + "_id": "" + }, + { + "__type__": "cc.PrefabInfo", + "root": { + "__id__": 1 + }, + "asset": { + "__uuid__": "145bba41-1962-49ee-aec9-08fb154e8bf2" + }, + "fileId": "29pI3SelxAU6ODrNe5LS2g", + "sync": false + }, + { + "__type__": "cc.Scrollbar", + "_name": "", + "_objFlags": 0, + "node": { + "__id__": 14 + }, + "_enabled": true, + "_scrollView": { + "__id__": 19 + }, + "_touching": false, + "_opacity": 255, + "enableAutoHide": false, + "autoHideTime": 1, + "_N$handle": { + "__id__": 16 + }, + "_N$direction": 1, + "_id": "" + }, + { + "__type__": "cc.ScrollView", + "_name": "", + "_objFlags": 0, + "node": { + "__id__": 2 + }, + "_enabled": true, + "horizontal": false, + "vertical": true, + "inertia": true, + "brake": 0.75, + "elastic": true, + "bounceDuration": 0.23, + "scrollEvents": [], + "cancelInnerEvents": true, + "_N$content": { + "__id__": 4 + }, + "content": { + "__id__": 4 + }, + "_N$horizontalScrollBar": null, + "_N$verticalScrollBar": { + "__id__": 18 + }, + "_id": "" + }, + { + "__type__": "cc.Widget", + "_name": "", + "_objFlags": 0, + "node": { + "__id__": 14 + }, + "_enabled": true, + "alignMode": 0, + "_target": null, + "_alignFlags": 37, + "_left": 350.07654921020657, + "_right": 0, + "_top": 0, + "_bottom": 0, + "_verticalCenter": 0, + "_horizontalCenter": 0, + "_isAbsLeft": true, + "_isAbsRight": true, + "_isAbsTop": true, + "_isAbsBottom": true, + "_isAbsHorizontalCenter": true, + "_isAbsVerticalCenter": true, + "_originalWidth": 0, + "_originalHeight": 237, + "_id": "" + }, + { + "__type__": "cc.Sprite", + "_name": "", + "_objFlags": 0, + "node": { + "__id__": 14 + }, + "_enabled": true, + "_materials": [ + { + "__uuid__": "eca5d2f2-8ef6-41c2-bbe6-f9c79d09c432" + } + ], + "_srcBlendFactor": 770, + "_dstBlendFactor": 771, + "_spriteFrame": { + "__uuid__": "5fe5dcaa-b513-4dc5-a166-573627b3a159" + }, + "_type": 1, + "_sizeMode": 0, + "_fillType": 0, + "_fillCenter": { + "__type__": "cc.Vec2", + "x": 0, + "y": 0 + }, + "_fillStart": 0, + "_fillRange": 0, + "_isTrimmedMode": true, + "_atlas": null, + "_N$autoSwitchMaterial": 0, + "_N$allowDynamicAtlas": 0, + "_id": "" + }, + { + "__type__": "cc.PrefabInfo", + "root": { + "__id__": 1 + }, + "asset": { + "__uuid__": "145bba41-1962-49ee-aec9-08fb154e8bf2" + }, + "fileId": "c2cC2kA1NNeozY+5ZzkcSY", + "sync": false + }, + { + "__type__": "cc.Widget", + "_name": "", + "_objFlags": 0, + "node": { + "__id__": 2 + }, + "_enabled": true, + "alignMode": 1, + "_target": null, + "_alignFlags": 45, + "_left": 0, + "_right": 0, + "_top": 0, + "_bottom": 0, + "_verticalCenter": 0, + "_horizontalCenter": 0, + "_isAbsLeft": true, + "_isAbsRight": true, + "_isAbsTop": true, + "_isAbsBottom": true, + "_isAbsHorizontalCenter": true, + "_isAbsVerticalCenter": true, + "_originalWidth": 240, + "_originalHeight": 250, + "_id": "" + }, + { + "__type__": "cc.Sprite", + "_name": "", + "_objFlags": 0, + "node": { + "__id__": 2 + }, + "_enabled": true, + "_materials": [ + { + "__uuid__": "eca5d2f2-8ef6-41c2-bbe6-f9c79d09c432" + } + ], + "_srcBlendFactor": 770, + "_dstBlendFactor": 771, + "_spriteFrame": { + "__uuid__": "a23235d1-15db-4b95-8439-a2e005bfff91" + }, + "_type": 0, + "_sizeMode": 0, + "_fillType": 0, + "_fillCenter": { + "__type__": "cc.Vec2", + "x": 0, + "y": 0 + }, + "_fillStart": 0, + "_fillRange": 0, + "_isTrimmedMode": false, + "_atlas": null, + "_N$autoSwitchMaterial": 0, + "_N$allowDynamicAtlas": 0, + "_id": "" + }, + { + "__type__": "cc.PrefabInfo", + "root": { + "__id__": 1 + }, + "asset": { + "__uuid__": "145bba41-1962-49ee-aec9-08fb154e8bf2" + }, + "fileId": "b5RxDsAgFOW6xOyBdbz2rI", + "sync": false + }, + { + "__type__": "cc.Widget", + "_name": "", + "_objFlags": 0, + "node": { + "__id__": 1 + }, + "_enabled": true, + "alignMode": 1, + "_target": null, + "_alignFlags": 45, + "_left": 0, + "_right": 0, + "_top": 0, + "_bottom": 0, + "_verticalCenter": 0, + "_horizontalCenter": 0, + "_isAbsLeft": true, + "_isAbsRight": true, + "_isAbsTop": true, + "_isAbsBottom": true, + "_isAbsHorizontalCenter": true, + "_isAbsVerticalCenter": true, + "_originalWidth": 0, + "_originalHeight": 0, + "_id": "" + }, + { + "__type__": "3e9188DEK9FCYlYeL+jvmrQ", + "_name": "", + "_objFlags": 0, + "node": { + "__id__": 1 + }, + "_enabled": true, + "label": { + "__id__": 6 + }, + "_id": "" + }, + { + "__type__": "cc.PrefabInfo", + "root": { + "__id__": 1 + }, + "asset": { + "__uuid__": "145bba41-1962-49ee-aec9-08fb154e8bf2" + }, + "fileId": "", + "sync": false + } +] \ No newline at end of file diff --git a/demo/assets/multi-render/multi-batcher/multi-batcher.prefab.meta b/demo/assets/multi-render/multi-batcher/multi-batcher.prefab.meta new file mode 100644 index 00000000..d5d77761 --- /dev/null +++ b/demo/assets/multi-render/multi-batcher/multi-batcher.prefab.meta @@ -0,0 +1,8 @@ +{ + "ver": "1.2.9", + "uuid": "145bba41-1962-49ee-aec9-08fb154e8bf2", + "optimizationPolicy": "AUTO", + "asyncLoadAssets": false, + "readonly": false, + "subMetas": {} +} \ No newline at end of file diff --git a/demo/assets/multi-render/multi-batcher/multi-batcher.ts b/demo/assets/multi-render/multi-batcher/multi-batcher.ts new file mode 100644 index 00000000..f703aa28 --- /dev/null +++ b/demo/assets/multi-render/multi-batcher/multi-batcher.ts @@ -0,0 +1,13 @@ + +const { ccclass, property } = cc._decorator; + +@ccclass +export default class MultiBatcher extends cc.Component { + + @property(cc.Label) + label: cc.Label = null; + + protected onLoad(): void { + + } +} diff --git a/demo/assets/multi-render/multi-batcher/multi-batcher.ts.meta b/demo/assets/multi-render/multi-batcher/multi-batcher.ts.meta new file mode 100644 index 00000000..0218fc77 --- /dev/null +++ b/demo/assets/multi-render/multi-batcher/multi-batcher.ts.meta @@ -0,0 +1,9 @@ +{ + "ver": "1.0.8", + "uuid": "3e918f03-10af-4509-8958-78bfa3be6ad0", + "isPlugin": false, + "loadPluginInWeb": true, + "loadPluginInNative": true, + "loadPluginInEditor": false, + "subMetas": {} +} \ No newline at end of file diff --git a/demo/assets/multi-render/multi-material/multi-material.prefab b/demo/assets/multi-render/multi-material/multi-material.prefab index 8094ce1f..34ba90a9 100644 --- a/demo/assets/multi-render/multi-material/multi-material.prefab +++ b/demo/assets/multi-render/multi-material/multi-material.prefab @@ -290,7 +290,7 @@ "_contentSize": { "__type__": "cc.Size", "width": 960, - "height": 843 + "height": 803 }, "_anchorPoint": { "__type__": "cc.Vec2", @@ -485,13 +485,13 @@ "_batchAsBitmap": false, "_styleFlags": 0, "_underlineHeight": 0, - "autoSwitchMaterial": 0, - "allowDynamicAtlas": 0, "_N$horizontalAlign": 1, "_N$verticalAlign": 1, "_N$fontFamily": "Arial", "_N$overflow": 0, "_N$cacheMode": 2, + "_N$autoSwitchMaterial": 0, + "_N$allowDynamicAtlas": 0, "_N$enableRetina": 0, "_id": "" }, @@ -600,8 +600,8 @@ "_fillRange": 0, "_isTrimmedMode": false, "_atlas": null, - "autoSwitchMaterial": 2, - "allowDynamicAtlas": 2, + "_N$autoSwitchMaterial": 2, + "_N$allowDynamicAtlas": 2, "_id": "" }, { @@ -693,7 +693,7 @@ "_contentSize": { "__type__": "cc.Size", "width": 200, - "height": 390 + "height": 310 }, "_anchorPoint": { "__type__": "cc.Vec2", @@ -705,7 +705,7 @@ "ctor": "Float64Array", "array": [ -180, - -195, + -155, 0, 0, 0, @@ -769,7 +769,7 @@ "ctor": "Float64Array", "array": [ 0, - 130, + 90, 0, 0, 0, @@ -817,13 +817,13 @@ "_batchAsBitmap": false, "_styleFlags": 0, "_underlineHeight": 0, - "autoSwitchMaterial": 0, - "allowDynamicAtlas": 0, "_N$horizontalAlign": 1, "_N$verticalAlign": 1, "_N$fontFamily": "Arial", "_N$overflow": 0, "_N$cacheMode": 2, + "_N$autoSwitchMaterial": 0, + "_N$allowDynamicAtlas": 0, "_N$enableRetina": 0, "_id": "" }, @@ -865,8 +865,8 @@ }, "_contentSize": { "__type__": "cc.Size", - "width": 900, - "height": 1200 + "width": 700, + "height": 800 }, "_anchorPoint": { "__type__": "cc.Vec2", @@ -932,8 +932,8 @@ "_fillRange": 0, "_isTrimmedMode": false, "_atlas": null, - "autoSwitchMaterial": 2, - "allowDynamicAtlas": 2, + "_N$autoSwitchMaterial": 2, + "_N$allowDynamicAtlas": 2, "_id": "" }, { @@ -958,7 +958,7 @@ "_layoutSize": { "__type__": "cc.Size", "width": 200, - "height": 390 + "height": 310 }, "_resize": 1, "_N$layoutType": 2, @@ -1149,13 +1149,13 @@ "_batchAsBitmap": false, "_styleFlags": 0, "_underlineHeight": 0, - "autoSwitchMaterial": 0, - "allowDynamicAtlas": 0, "_N$horizontalAlign": 1, "_N$verticalAlign": 1, "_N$fontFamily": "Arial", "_N$overflow": 0, "_N$cacheMode": 2, + "_N$autoSwitchMaterial": 0, + "_N$allowDynamicAtlas": 0, "_N$enableRetina": 0, "_id": "" }, @@ -1264,8 +1264,8 @@ "_fillRange": 0, "_isTrimmedMode": false, "_atlas": null, - "autoSwitchMaterial": 2, - "allowDynamicAtlas": 2, + "_N$autoSwitchMaterial": 2, + "_N$allowDynamicAtlas": 2, "_id": "" }, { @@ -1481,13 +1481,13 @@ "_batchAsBitmap": false, "_styleFlags": 0, "_underlineHeight": 0, - "autoSwitchMaterial": 0, - "allowDynamicAtlas": 0, "_N$horizontalAlign": 1, "_N$verticalAlign": 1, "_N$fontFamily": "Arial", "_N$overflow": 0, "_N$cacheMode": 2, + "_N$autoSwitchMaterial": 0, + "_N$allowDynamicAtlas": 0, "_N$enableRetina": 0, "_id": "" }, @@ -1596,8 +1596,8 @@ "_fillRange": 0.7, "_isTrimmedMode": false, "_atlas": null, - "autoSwitchMaterial": 2, - "allowDynamicAtlas": 2, + "_N$autoSwitchMaterial": 2, + "_N$allowDynamicAtlas": 2, "_id": "" }, { @@ -1701,7 +1701,7 @@ "ctor": "Float64Array", "array": [ -380, - -520.5, + -480.5, 0, 0, 0, @@ -1813,13 +1813,13 @@ "_batchAsBitmap": false, "_styleFlags": 0, "_underlineHeight": 0, - "autoSwitchMaterial": 0, - "allowDynamicAtlas": 0, "_N$horizontalAlign": 1, "_N$verticalAlign": 1, "_N$fontFamily": "Arial", "_N$overflow": 0, "_N$cacheMode": 2, + "_N$autoSwitchMaterial": 0, + "_N$allowDynamicAtlas": 0, "_N$enableRetina": 0, "_id": "" }, @@ -1928,8 +1928,8 @@ "_fillRange": 0.7, "_isTrimmedMode": false, "_atlas": null, - "autoSwitchMaterial": 2, - "allowDynamicAtlas": 2, + "_N$autoSwitchMaterial": 2, + "_N$allowDynamicAtlas": 2, "_id": "" }, { @@ -2033,7 +2033,7 @@ "ctor": "Float64Array", "array": [ -180, - -480, + -440, 0, 0, 0, @@ -2145,13 +2145,13 @@ "_batchAsBitmap": false, "_styleFlags": 0, "_underlineHeight": 0, - "autoSwitchMaterial": 0, - "allowDynamicAtlas": 0, "_N$horizontalAlign": 1, "_N$verticalAlign": 1, "_N$fontFamily": "Arial", "_N$overflow": 0, "_N$cacheMode": 2, + "_N$autoSwitchMaterial": 0, + "_N$allowDynamicAtlas": 0, "_N$enableRetina": 0, "_id": "" }, @@ -2254,13 +2254,13 @@ "_batchAsBitmap": false, "_styleFlags": 0, "_underlineHeight": 0, - "autoSwitchMaterial": 2, - "allowDynamicAtlas": 2, "_N$horizontalAlign": 1, "_N$verticalAlign": 1, "_N$fontFamily": "Arial", "_N$overflow": 0, "_N$cacheMode": 2, + "_N$autoSwitchMaterial": 2, + "_N$allowDynamicAtlas": 2, "_N$enableRetina": 0, "_id": "" }, @@ -2365,7 +2365,7 @@ "ctor": "Float64Array", "array": [ 20, - -480, + -440, 0, 0, 0, @@ -2477,13 +2477,13 @@ "_batchAsBitmap": false, "_styleFlags": 0, "_underlineHeight": 0, - "autoSwitchMaterial": 0, - "allowDynamicAtlas": 0, "_N$horizontalAlign": 1, "_N$verticalAlign": 1, "_N$fontFamily": "Arial", "_N$overflow": 0, "_N$cacheMode": 2, + "_N$autoSwitchMaterial": 0, + "_N$allowDynamicAtlas": 0, "_N$enableRetina": 0, "_id": "" }, @@ -2590,13 +2590,13 @@ "_batchAsBitmap": false, "_styleFlags": 0, "_underlineHeight": 0, - "autoSwitchMaterial": 2, - "allowDynamicAtlas": 2, "_N$horizontalAlign": 1, "_N$verticalAlign": 1, "_N$fontFamily": "Arial", "_N$overflow": 0, "_N$cacheMode": 0, + "_N$autoSwitchMaterial": 2, + "_N$allowDynamicAtlas": 2, "_N$enableRetina": 0, "_id": "" }, @@ -2701,7 +2701,7 @@ "ctor": "Float64Array", "array": [ 220, - -475, + -435, 0, 0, 0, @@ -2813,13 +2813,13 @@ "_batchAsBitmap": false, "_styleFlags": 0, "_underlineHeight": 0, - "autoSwitchMaterial": 0, - "allowDynamicAtlas": 0, "_N$horizontalAlign": 1, "_N$verticalAlign": 1, "_N$fontFamily": "Arial", "_N$overflow": 0, "_N$cacheMode": 2, + "_N$autoSwitchMaterial": 0, + "_N$allowDynamicAtlas": 0, "_N$enableRetina": 0, "_id": "" }, @@ -2927,8 +2927,8 @@ "a": 255 }, "_fastMode": false, - "autoSwitchMaterial": 2, "_N$preview": true, + "_N$autoSwitchMaterial": 2, "_id": "" }, { @@ -3032,7 +3032,7 @@ "ctor": "Float64Array", "array": [ -380, - -747, + -707, 0, 0, 0, @@ -3144,13 +3144,13 @@ "_batchAsBitmap": false, "_styleFlags": 0, "_underlineHeight": 0, - "autoSwitchMaterial": 0, - "allowDynamicAtlas": 0, "_N$horizontalAlign": 1, "_N$verticalAlign": 1, "_N$fontFamily": "Arial", "_N$overflow": 0, "_N$cacheMode": 2, + "_N$autoSwitchMaterial": 0, + "_N$allowDynamicAtlas": 0, "_N$enableRetina": 0, "_id": "" }, @@ -3260,8 +3260,6 @@ "_headAniInfo": null, "_playTimes": 0, "_isAniComplete": true, - "autoSwitchMaterial": 2, - "allowDynamicAtlas": 2, "_N$skeletonData": { "__uuid__": "bcd99389-a393-426e-b234-157c62b44bc4" }, @@ -3271,6 +3269,8 @@ "_N$debugMesh": false, "_N$useTint": false, "_N$enableBatch": true, + "_N$autoSwitchMaterial": 2, + "_N$allowDynamicAtlas": 2, "_id": "" }, { @@ -3374,7 +3374,7 @@ "ctor": "Float64Array", "array": [ -180, - -747, + -707, 0, 0, 0, @@ -3486,13 +3486,13 @@ "_batchAsBitmap": false, "_styleFlags": 0, "_underlineHeight": 0, - "autoSwitchMaterial": 0, - "allowDynamicAtlas": 0, "_N$horizontalAlign": 1, "_N$verticalAlign": 1, "_N$fontFamily": "Arial", "_N$overflow": 0, "_N$cacheMode": 2, + "_N$autoSwitchMaterial": 0, + "_N$allowDynamicAtlas": 0, "_N$enableRetina": 0, "_id": "" }, @@ -3602,8 +3602,6 @@ "_headAniInfo": null, "_playTimes": 0, "_isAniComplete": true, - "autoSwitchMaterial": 2, - "allowDynamicAtlas": 2, "_N$skeletonData": { "__uuid__": "bcd99389-a393-426e-b234-157c62b44bc4" }, @@ -3613,6 +3611,8 @@ "_N$debugMesh": false, "_N$useTint": false, "_N$enableBatch": true, + "_N$autoSwitchMaterial": 2, + "_N$allowDynamicAtlas": 2, "_id": "" }, { @@ -3716,7 +3716,7 @@ "ctor": "Float64Array", "array": [ 20, - -746, + -706, 0, 0, 0, @@ -3828,13 +3828,13 @@ "_batchAsBitmap": false, "_styleFlags": 0, "_underlineHeight": 0, - "autoSwitchMaterial": 0, - "allowDynamicAtlas": 0, "_N$horizontalAlign": 1, "_N$verticalAlign": 1, "_N$fontFamily": "Arial", "_N$overflow": 0, "_N$cacheMode": 2, + "_N$autoSwitchMaterial": 0, + "_N$allowDynamicAtlas": 0, "_N$enableRetina": 0, "_id": "" }, @@ -3943,8 +3943,8 @@ "_fillRange": 0, "_isTrimmedMode": false, "_atlas": null, - "autoSwitchMaterial": 2, - "allowDynamicAtlas": 2, + "_N$autoSwitchMaterial": 2, + "_N$allowDynamicAtlas": 2, "_id": "" }, { @@ -4024,7 +4024,7 @@ "_layoutSize": { "__type__": "cc.Size", "width": 960, - "height": 843 + "height": 803 }, "_resize": 1, "_N$layoutType": 3, @@ -4289,8 +4289,8 @@ "_fillRange": 0, "_isTrimmedMode": true, "_atlas": null, - "autoSwitchMaterial": 0, - "allowDynamicAtlas": 0, + "_N$autoSwitchMaterial": 0, + "_N$allowDynamicAtlas": 0, "_id": "" }, { @@ -4410,8 +4410,8 @@ "_fillRange": 0, "_isTrimmedMode": true, "_atlas": null, - "autoSwitchMaterial": 0, - "allowDynamicAtlas": 0, + "_N$autoSwitchMaterial": 0, + "_N$allowDynamicAtlas": 0, "_id": "" }, { @@ -4482,8 +4482,8 @@ "_fillRange": 0, "_isTrimmedMode": false, "_atlas": null, - "autoSwitchMaterial": 0, - "allowDynamicAtlas": 0, + "_N$autoSwitchMaterial": 0, + "_N$allowDynamicAtlas": 0, "_id": "" }, { diff --git a/docs/docs/intro.md b/docs/docs/intro.md index 93fa4881..252234c9 100644 --- a/docs/docs/intro.md +++ b/docs/docs/intro.md @@ -63,6 +63,7 @@ TODO - [新特性] cc.Label、cc.RichText、cc.Sprite、cc.MotionStreak、Spine 组件支持使用多纹理材质,并支持自动切换材质机制 - [新特性] cc.RichText 支持使用自定义材质 - [修复] 直接修改 Effect 的属性不回导致其变体的 hash 值刷新 +- [修复] CHAR 缓存模式 hash 计算可能会有重复的问题 - [调整] 默认禁用 Label 原生 TTF 渲染器 所有更新日志请移步 [此处](./update-log)。 @@ -96,4 +97,9 @@ TODO 对于已经修改过引擎的人,由于服务包提供的是 Git Patch,所以可以让你在已有修改的基础上轻松应用上服务包的改动,甚至你可以只应用你想要的特性。 +### Cocos Creator 报 Error: Can not parse this input:undefined 错误 + +没有找到服务包的内置资源,请记得安装配套的引擎扩展。 + +--- **最后的最后,希望这个项目能帮助到你的学习或工作,enjoy!** diff --git a/docs/docs/start-guide/advance-batcher-guide.md b/docs/docs/start-guide/advance-batcher-guide.md index 2c722805..515a7879 100644 --- a/docs/docs/start-guide/advance-batcher-guide.md +++ b/docs/docs/start-guide/advance-batcher-guide.md @@ -6,3 +6,7 @@ description: "极致地减少游戏 Draw Call。" # 进阶合批指南 TODO + +动态图集与字符图集使用这个管理器来实现多纹理合批,使用的全局实例可以通过 `cc.sp.multiBatcher` 访问。 + +如果你的资源规划地非常细致,项目本身有已经打好的大图集,那么你就可以考虑 diff --git a/docs/docs/start-guide/batcher-guide.md b/docs/docs/start-guide/batcher-guide.md index 26c25d5a..ad3332a7 100644 --- a/docs/docs/start-guide/batcher-guide.md +++ b/docs/docs/start-guide/batcher-guide.md @@ -67,66 +67,66 @@ description: "在游戏开发中享受不用关注 Draw Call 的快乐。" --- ## 充分利用动态合图 -启用动态合图后,我们有几个小提示能让你发挥出动态合图的潜力: +下面几个建议能让你发挥出动态合图的潜力: ### 放宽能参与合图的纹理尺寸限制 -你可以适当地放宽能参与合图的纹理尺寸的限制(`cc.dynamicAtlasManager.maxFrameSize`)。 +**动态图集会自动进行多纹理合批,你可以放心地使用多达 8 张图集而不用担心交叉渲染导致的打断批次!** -推荐设置为 `512`、 `1024` 甚至 `2048`。 +有了这个新特性,你可以根据项目的具体情况来放宽能参与合图的纹理尺寸限制。 -因为**动态图集会自动进行多纹理合批,你可以放心地使用多达 8 张图集而不用担心交叉渲染导致的打断批次!** +```js +cc.dynamicAtlasManager.maxFrameSize = 1024; // 推荐 512、1024 甚至 2048 +``` :::tip -服务包会自动将图集最大数量调整至(设备能同时采样纹理数 - Char 缓存模式自动合批图集数),这个值默认为 `7`。 +服务包会自动将图集的最大数量调整至(设备能同时采样纹理数 - Char 缓存模式自动合批图集数),这个值默认为 `7`。 ::: ### 无需管理动态图集,只需要释放资源 -**动态合图支持复用废弃空间,释放纹理的同时会释放其在动态图集使用的空间。** +**动态合图会在纹理被释放的同时释放其在动态图集使用的空间。** -所以一般不需要去关心动态图集,只需要做好资源释放,就不会发生动态图集被用完的情况。 +有了这个新特性,你不需要关心动态图集,只需要做好应有的资源释放,就能保持动态图集的长期有效。 ### 更加细致地优化图集的使用效率 -除了引擎自带的 `packable` 属性可以控制纹理是否会参与动态合图之外。 +除了通过调整纹理的 `packable` 属性可以控制纹理是否会参与动态合图之外。 -服务包还额外支持了**控制组件是否默认参与动态合图,也可以控制单个组件是否参与动态合图。** +**还可以控制组件是否默认参与动态合图,也可以控制单个组件是否参与动态合图。** -有关动态合图的设置可前往 [动态合图](TODO) 的文档了解详情。 +可前往 [动态合图](TODO) 的文档了解详情。 -在上面我们推荐可以将纹理尺寸限制放宽到 `2048`,这听起来貌似有点离谱,但只要规划好项目的资源确实可行,比如: +在上面我们推荐可以将纹理尺寸限制放宽到 `2048`,这听起来貌似有点离谱,但只要规划得当确实可行,比如: -- 将优化程度有限但尺寸具大的纹理禁止参与动态合图 -- 分模块存放资源,将冷门界面(如活动)的纹理禁止参与动态合图,或尽早释放掉 -- 在资源已经一团糟的项目中,可以直接禁止渲染组件参与动态合图 +- 禁止优化程度有限但尺寸巨大的纹理参与动态合图 +- 分模块存放资源,禁止冷门(如活动界面)的纹理参与动态合图或尽早地释放掉 +- 在资源已经一团糟的项目中,可通过代码禁止某个界面下所有的渲染组件参与动态合图 + +完成上面几点这可能需要一些工作量,但能将动态图集用在刀刃上,发挥更大的作用。 --- ## Label 不再是合批噩梦 在项目之前的开发中,我们可能会使用字体图集、调整节点顺序,甚至修改渲染流程来解决 Label 的性能问题。 -但是引擎不是提供了 Bitmap 和 Char 两种缓存模式吗? +引擎提供的 Bitmap 和 Char 两种缓存模式在稍大一点的项目上就显得力所不及了: -是的,但是这两个解决方案与旧的动态合图一样在生产环境中使用太过 "玩具" 了: +- Bitmap 缓存模式:字体纹理会打入动态图集,但动态图集却无法复用,随着游戏的进行,图集用完则直接失去作用。 -- Bitmap 缓存模式的缺点:字体纹理会打入动态图集,而动态图集无法复用,随着游戏的进行,图集用完则直接失去作用。 +- Char 缓存模式的缺点:还是无法复用,并且只有一张图集,图集用完则直接无法渲染,应该没人能接受游戏可能跑着跑着字就全部消失了的情况。 -- Char 缓存模式的缺点:还是无法复用,并且只有一张图集,用完则直接无法渲染,试问谁能接受游戏可能跑着跑着字就全部消失了的情况。 - -所以,**服务包几乎重构了 Char 缓存模式,除了解决不能复用的问题之外,由于支持了多纹理渲染,所以既可以与动态图集一起合批,还拥有高达最多 8 张字体图集可以使用!** - -接下来我们有几个小提示能让你知道如何选择合适的缓存模式: +但,**服务包重构了 Char 缓存模式,除了解决不能复用的问题之外,由于支持了多纹理渲染,所以既能与动态图集合批,还有最多 8 张字体图集可以使用!** ### 委以重任一把梭 —— Char -遇事不决,先选 Char 缓存模式。 +**如果你不知道该选择什么缓存模式,那就遇事不决,先选 Char 缓存模式。** -虽然 Char 模式也有一些缺点,但能够应付大多数的场景,由于它既能与动态图集一起合批,还是是按字符进行复用的,所以相比 Bitmap 模式它有着更高的性能优势。 +虽然 Char 模式也有一些缺点,但由于它既能与动态图集一起合批,还是是按字符进行复用的,所以相比 Bitmap 模式它有着更高的性能优势。 -而且不用担心这 8 张字符图集会被用完,内部会用引用计数自动释放废弃字符所占用的空间,可以试着想一下你的游戏最多在同一帧会显示几个字符。 +不用担心字符图集会被用完,内部会用引用计数自动释放废弃字符所占用的空间。 但 Char 缓存模式不适合下面的场景: @@ -141,37 +141,37 @@ description: "在游戏开发中享受不用关注 Draw Call 的快乐。" 在解决了动态图集的复用问题后,Bitmap 缓存模式的纹理也会使用引用计数自动释放,并且不会有 Char 缓存模式无法显示字素簇的问题。 -但当然,Bitmap 缓存模式也不是万能的,如果遇到了下面这种情况就再考虑调整节点顺序等方法来解决吧: +但当然,Bitmap 缓存模式也不是万能的,如果遇到了下面这种情况,就需要考虑使用调整节点顺序这样的老办法来解决了: -- 巨大的字体大小也会瞬间占满整张动态图集 -- 在非常大量的 Label 需频繁改变文本的情况下,请使用性能分析工具检查动态图集的性能消耗,避免合批的弊大于利。 +- 巨大的字体大小也会瞬间占满整张动态图集,动态图集也不能这么霍霍。 +- 在大量的 Label 需频繁改变文本的情况下,请使用性能分析工具检查动态图集的性能消耗,避免合批的弊大于利。 + +:::caution 注意 + +无论使用哪种缓存模式,在做缩放动画时不要对 `fontSize` 属性进行缓动,这会导致每帧都需要重新生成文字纹理,造成巨大的性能负担,可以使用节点的 `scale` 来代替。 + +::: ### 关于字符图集与动态图集 -常见的误区: +**1.Char 缓存模式所使用的字符图集与动态图集并不是一个东西** -#### 1.Char 缓存模式所使用的字符图集与动态图集是一样的东西,只是叫法不同 +有多种因素导致没有让 Char 缓存模式直接使用动态图集,在 Char 缓存模式的原理文档中有详细解释。 -由于多种原因,没有设计让 Char 缓存模式直接使用动态图集,这当然可以做到,但是权衡之下选择了分开实现,在使用指南中有详细解释。 +多纹理材质只有 8 个纹理插槽,所以默认情况下动态图集最大数量为 7,字符图集自动多纹理合批的数量为 1(注意,这个不是指字符图集的最大数量,字符图集的最大数量是 8 张,并且不能调整)。 -多纹理材质只有 8 个纹理插槽,所以默认情况下动态图集最大数量为 7,字符图集自动多纹理合批的数量为 1。(注意不是最大数量) +你可以自己调整这个分配值,比如 6 张动态图集,字符图集自动合批 2 张,保持数量加起来不超过 8 张,也就能保持 1 Draw Call。 -你可以自己调整这个分配值,而服务包使用这个默认值有以下几点原因: +而服务包使用这个 “7 + 1” 的默认值有以下几点原因: - 引擎原本就只有 1 张 Char 字符图集 - 大多数项目因为 Char 缓存模式加入了可复用的特性后,1 张 Char 字符图集是足够的 -如果你直觉认为 1 张太少,我们建议你合理搭配使用 Bitmap 和 Char 两种缓存模式后,实际测试发现不够再调整该值。 +建议你合理搭配使用 Bitmap 和 Char 两种缓存模式后再进行实际测试,发现 Char 字符图集 1 张是真的不够再对其做调整。 -**请注意上面的 1 并非是字符图集的最大数量,而是字符图集进行自动多纹理合批的最大数量!** +**2.Char 缓存模式依然不能在图集用完的情况下正常渲染** -所以这并不意味着字符图集只能有 1 张,而是最大能有 8 张,并且这个数量不能调整。 - -如果你还是对为什么会出现一个 “字符图集进行自动多纹理合批的最大数量” 而一头雾水,建议详细阅读使用指南。 - -#### 2.Char 缓存模式能在图集满了的情况下依然能正常显示 - -现在如果字符图集满了,依旧不能正常显示,这样的原因有以下几点: +原因有以下几点: - 我们认为 8 张数量已经够多了,8 张都用完的情况大部分是没有合理搭配使用两种缓存模式 - 8 张是多纹理渲染的上限,这意味着如果超过 8 张,1 个 Label 有 100 个字,就可能有 100 个 Draw Call @@ -182,7 +182,7 @@ description: "在游戏开发中享受不用关注 Draw Call 的快乐。" 以上就是新合批指南的全部内容了,稍微总结一下渲染批次合并的几个要点: - 启用动态合图,只需要合理地释放资源即可保持动态合图的一直有效 -- 能就优先用 Char 缓存模式,不能则换为 Bitmap 缓存模式,字数太多字体太大的则放弃挣扎使用 None 模式 -- 不要优先考虑打图集,修改节点顺序等需要维护成本的优化方式 +- 优先使用 Char 缓存模式,不适合则使用 Bitmap 缓存模式,都不适合则采用老方法 +- 不要优先考虑修改节点顺序这种需要维护成本的优化方式 如果你对批次合并还有着更高的需求,可以阅读 [进阶合批指南](./advance-batcher-guide)。 diff --git a/docs/docs/update-log.md b/docs/docs/update-log.md index 8c3e61c7..ca733c02 100644 --- a/docs/docs/update-log.md +++ b/docs/docs/update-log.md @@ -17,5 +17,6 @@ sidebar_position: 7 - [新特性] cc.Label、cc.RichText、cc.Sprite、cc.MotionStreak、Spine 组件支持使用多纹理材质,并支持自动切换材质机制 - [新特性] cc.RichText 支持使用自定义材质 - [修复] 直接修改 Effect 的属性不回导致其变体的 hash 值刷新 +- [修复] CHAR 缓存模式 hash 计算可能会有重复的问题 - [调整] 默认禁用 Label 原生 TTF 渲染器 diff --git a/docs/docs/user-guide/multi-render/assets/autoswitch-settings.png b/docs/docs/user-guide/multi-render/assets/autoswitch-settings.png new file mode 100644 index 00000000..e12e8e7b Binary files /dev/null and b/docs/docs/user-guide/multi-render/assets/autoswitch-settings.png differ diff --git a/docs/docs/user-guide/multi-render/multi-batcher.md b/docs/docs/user-guide/multi-render/multi-batcher.md index a6480009..4ad5d3b6 100644 --- a/docs/docs/user-guide/multi-render/multi-batcher.md +++ b/docs/docs/user-guide/multi-render/multi-batcher.md @@ -5,5 +5,121 @@ description: "了解如何手动进行多纹理合批。" # 多纹理合批 +在 [新 UI 渲染批次合并指南](../../start-guide/batcher-guide#充分利用动态合图) 中提到了动态合图与多纹理渲染结合后,能让多张图集纹理在同一批次渲染。 -着重介绍管理器。 +如果你阅读过 [多纹理材质](./multi-material) 文档的话,肯定知道能使用 `MultiHandler` 的接口来动态设置材质的纹理插槽来实现。 + +但是这种完全手动的方式实现起来比较麻烦,比如你需要使用一个纹理时,还得找到该纹理所在的材质并设置到渲染组件上。 + +为了能更方便地进行多纹理合批,服务包封装了一个自动切换多纹理材质的机制与多纹理合批管理类 `cc.sp.MultiBatcher`。 + +动态图集与字符图集使用了一个全局实例,可以通过 `cc.sp.multiBatcher` 访问。 + +--- +## 开关自动切换多纹理材质 + +要让动态合图自动进行多纹理合批,首先要解决设置材质的问题,当切换成动态图集的纹理时,需要自动将组件的材质设置为有动态图集纹理的材质。 + +所以我们增加了一个机制,在支持的组件内使用开启了该机制的纹理进行渲染时,会提前切换为该纹理关联的材质(只要支持多纹理渲染就支持自动切换材质)。 + +这个机制默认是开启的,可以通过全局开关来控制默认值: + +```js +cc.sp.autoSwitchMaterial = false; +``` + +默认情况下组件会使用全局值,你可以控制单个组件是否强制启用/禁用该机制: + +![autoswitchsettings](./assets/autoswitch-settings.png) + +除了在编辑器调整,也可以通过代码控制: + +```js +// cc.RenderComponent.EnableType +// GLOBAL: 全局默认值 +// ENABLE: 开启 +// DISABLE: 关闭 +sprite.autoSwitchMaterial = cc.RenderComponent.EnableType.ENABLE; +``` + +:::caution 注意 + +组件有脏检查标记,如果修改全局开关或者修改纹理关联的材质,需要对所有使用该纹理的渲染组件调用 `comp.setVertsDirty()` 重新检查。 + +::: + +:::caution 特别注意 + +如果 Spine 组件所使用的 `SkeletonData` 同时使用了多个纹理,那么只会遍历数据以找到的第一个纹理为主执行自动切换机制。 + +::: + +--- +## 设置纹理的关联材质 + +:::info + +每个纹理只能关联一个材质,如果同一个纹理,不同的渲染组件需要使用不同材质就需要手动设置。 + +::: + +关联材质的接口有两种用法: + +```js +const bool = texture.linkMaterial(material); +const bool = texture.linkMaterial(material, index); +``` + +第一句代码会自动将纹理设置到材质的空插槽中,然后将该材质设置为该纹理的关联材质,如果没有空插槽会返回 `false`。 + +第二句则是强制将纹理设置到指定的插槽中,并将该材质设置为该纹理的关联材质。 + +想要解除两者的关联可以使用: + +```js +texture.unlinkMaterial(); +``` + +获取关联的材质可以使用: + +```js +const material = texture.getLinkedMaterial(); +``` + +--- +## 多纹理合批管理器 + +手动关联材质就意味着你需要手动创建并管理创建的所有材质,如果是大量纹理需要关联材质就会比较麻烦。 + +所以我们封装了一个小巧的多纹理合批管理器 `cc.sp.MultiBatcher`。 + +这个管理器有点像动态合图管理器,它会持有一个材质数组,初始化后会使用内置的多纹理 Effect 着色器创建一个材质并放在数组中。 + +你可以传给管理器一个纹理,它会查找所有材质的空插槽,如果没有材质有空插槽则会创建一个新材质,然后把纹理与材质关联。 + +### 如何使用 + +创建管理器并初始化可以使用: + +```js +const batcher = new cc.sp.MultiBatcher(); +batcher.init(); +``` + +传入纹理可以使用: + +```js +const material = batcher.requsetMaterial(texture); +``` + +会返回关联的材质,如果纹理本来就已经有关联的材质,则会直接返回已关联的材质。 + +清空内部数组可以使用: + +```js +batcher.reset(); +``` + +### 它的用途 + +在 [进阶合批指南](../../start-guide/advance-batcher-guide) 中有提供一些常见的使用案例。 diff --git a/docs/docs/user-guide/multi-render/multi-material.md b/docs/docs/user-guide/multi-render/multi-material.md index 57de40d0..b787d568 100644 --- a/docs/docs/user-guide/multi-render/multi-material.md +++ b/docs/docs/user-guide/multi-render/multi-material.md @@ -6,6 +6,7 @@ toc_max_heading_level: 5 # 多纹理材质 +--- ## 创建多纹理材质 你可以正常创建一个材质文件,Effect 选择内置的多纹理 Effect 着色器 `multi-2d-sprite` 即可。 @@ -14,6 +15,7 @@ toc_max_heading_level: 5 勾选 `USE_MULTI_TEXTURE` 后可以看到上面有 `texture` - `texture8` 一共 8 个纹理插槽,将需要使用的纹理拖到上面的插槽即可完成多纹理材质的配置。 +--- ## 在组件中使用多纹理材质 直接拖到组件的 `Materials` 属性上即可。 @@ -36,6 +38,7 @@ toc_max_heading_level: 5 ::: +--- ## 自定义多纹理材质 上面介绍的多纹理材质都是使用的内置的多纹理 Effect 着色器,你可以直接在内置多纹理 Effect 着色器的基础上修改。 @@ -56,6 +59,7 @@ toc_max_heading_level: 5 ::: +--- ## 通过代码设置纹理插槽 每个多纹理材质都对应着一个多纹理材质管理器,这是服务包新增的一个工具类,其主要用处是便捷、高性能地管理多纹理材质上面的纹理插槽。 @@ -76,6 +80,9 @@ handler.setTexture(1, null); // 直接移除指定纹理 handler.removeTexture(texture.getImpl()); + +// 将纹理自动设置到材质的空插槽 +handler.autoSetTexture(texture); ``` 从上面的代码中可以看出操作纹理插槽的时候并不是传入插槽的名称,而是需要提供下标。 @@ -100,12 +107,13 @@ cc.sp.propertyName2Index("texture"); // return: 0 :::caution 警告 -请勿直接通过 `setProperty` 接口修改多纹理材质的纹理插槽。 +请勿直接通过材质原始的 `setProperty` 接口修改多纹理材质的纹理插槽。 如果你必须这么做,需要调用 `material.getMultiHandler().syncTextures()` 来同步插槽数据到 `MultiHandler` 上。 ::: +--- ## 强制设置材质的类型 如果你想将某个材质强制视为多纹理材质或非多纹理材质,可以: @@ -118,4 +126,4 @@ material.setMultiSupport(true); material.setMultiSupport(false); ``` -但是这么做好像没有什么意义。 +没有特殊情况不需要这么做。