[engine] 修复 Spine 动态合图 uv 未更新的问题

This commit is contained in:
SmallMain 2022-06-27 15:24:52 +08:00
parent dbe9c6d28f
commit 19a018dc5e

View File

@ -83,6 +83,8 @@ let _x, _y, _m00, _m04, _m12, _m01, _m05, _m13;
let _r, _g, _b, _fr, _fg, _fb, _fa, _dr, _dg, _db, _da;
let _comp, _buffer, _renderer, _node, _needColor, _vertexEffect;
let _packedRegions = [];
function _getSlotMaterial (tex, blendMode) {
let src, dst;
switch (blendMode) {
@ -238,9 +240,39 @@ export default class SpineAssembler extends Assembler {
}
}
bindPackedRegion(attachment, region) {
const frame = region._spriteFrame;
sp.SkeletonData.updateRegionUV(region);
if (attachment instanceof sp.spine.MeshAttachment) {
attachment.updateUVs();
} else {
attachment.setRegion(region);
attachment.updateOffset();
}
frame.once("_resetDynamicAtlasFrame", () => {
region.x = region._original._x;
region.y = region._original._y;
region.texture = region._original._texture;
region._original = null;
// update uv
sp.SkeletonData.updateRegionUV(region);
if (attachment instanceof sp.spine.MeshAttachment) {
attachment.updateUVs();
} else {
attachment.setRegion(region);
attachment.updateOffset();
}
});
}
packDynamicAtlasForSpine(comp) {
if (CC_TEST) return false;
_packedRegions.length = 0;
const allowDynamicAtlas = comp.allowDynamicAtlas;
if ((cc.sp.allowDynamicAtlas && allowDynamicAtlas === 0) || allowDynamicAtlas === 1) {
if (cc.dynamicAtlasManager) {
@ -250,7 +282,14 @@ export default class SpineAssembler extends Assembler {
for (const key in attachments) {
const attachment = attachments[key];
const region = attachment.region;
if (region && !region._original && region.texture && region.texture._texture.packable) {
if (region) {
if (region._original) {
// 可能出现多个 attachment 共用同一个 region
if (_packedRegions.includes(region)) {
this.bindPackedRegion(attachment, region);
}
} else if (region.texture && region.texture._texture.packable) {
if (region._spriteFrame) {
region._spriteFrame.destroy();
region._spriteFrame = null;
@ -276,30 +315,10 @@ export default class SpineAssembler extends Assembler {
region.y = packedFrame.y;
// update uv
sp.SkeletonData.updateRegionUV(region);
if (attachment instanceof sp.spine.MeshAttachment) {
attachment.updateUVs();
} else {
attachment.setRegion(region);
attachment.updateOffset();
}
frame.once("_resetDynamicAtlasFrame", () => {
region.x = region._original._x;
region.y = region._original._y;
region.texture = region._original._texture;
region._original = null;
// update uv
sp.SkeletonData.updateRegionUV(region);
if (attachment instanceof sp.spine.MeshAttachment) {
attachment.updateUVs();
} else {
attachment.setRegion(region);
attachment.updateOffset();
}
});
region._spriteFrame = frame;
this.bindPackedRegion(attachment, region);
_packedRegions.push(region);
} else {
frame.destroy();
}
@ -311,6 +330,9 @@ export default class SpineAssembler extends Assembler {
}
}
_packedRegions.length = 0;
}
fillVertices (skeletonColor, attachmentColor, slotColor, clipper, slot) {
let vbuf = _buffer._vData,