【方案】Cocos Creator 的 web/原生多平台 Spine 换装方案解析,附 Demo 源码

mark!!!

mark!

这个外部图片换装方案,用3.5.2打包apk运行报错,cpp文件已经替换了

给的demo工程经过3.5.2实测h5/native没有问题后直接打包的,麻烦再对比demo工程看看哪里漏了哦

3.6版本以上,原生平台有问题吗?

嗯,是使用了自己的spine,还没确定是spine哪里的问题

一直都是每个部件做一个spine 直接替换插槽 非常完美

使用了mesh动画的部件,换肤时setUV会报错

原生吗?我看他的git,原生只写了RegionAttachment 没有 MeshAttachment

是的,原生上的,mesh动画换装会有问题

我的做法和版本都不一致,你可以参考下

void SkeletonRenderer::updateRegion(const std::string &slotName, cocos2d::middleware::Texture2D *texture) {
    Slot *slot = _skeleton->findSlot(slotName.c_str());
    if(nullptr == slot){
        return;
    }
    Attachment *attachment = (Attachment *)slot->getAttachment();
    if(nullptr == attachment){
        return;
    }
    float wide = texture->getPixelsWide();
    float high = texture->getPixelsHigh();
    if(attachment->getRTTI().isExactly(RegionAttachment::rtti)) {
        RegionAttachment *_attachment = (RegionAttachment *) attachment;
        _attachment->setUVs(0, 0, 1, 1, false);
        _attachment->setRegionWidth(wide);
        _attachment->setRegionHeight(high);
        _attachment->setRegionOriginalWidth(wide);
        _attachment->setRegionOriginalHeight(high);
        _attachment->setWidth(wide);
        _attachment->setHeight(high);

        AttachmentVertices *attachV = (AttachmentVertices *)_attachment->getRendererObject();
        if (attachV->_texture == texture) {
            return;
        }
        CC_SAFE_RELEASE(attachV->_texture);
        attachV->_texture = texture;
        CC_SAFE_RETAIN(texture);

        V2F_T2F_C4B *vertices = attachV->_triangles->verts;
        for (int i = 0, ii = 0; i < 4; ++i, ii += 2)
        {
            vertices[i].texCoord.u = _attachment->getUVs()[ii];
            vertices[i].texCoord.v = _attachment->getUVs()[ii + 1];
        }

        _attachment->updateOffset();
        slot->setAttachment(_attachment);
    } else if(attachment->getRTTI().isExactly(MeshAttachment::rtti)) {
        MeshAttachment *_attachment = (MeshAttachment *) attachment;
        _attachment->setRegionU(0);
        _attachment->setRegionV(0);
        _attachment->setRegionU2(1);
        _attachment->setRegionV2(1);
//        _attachment->setRegionRotate(degrees!=0);
//        _attachment->setRegionDegrees(degrees);

        _attachment->setRegionWidth(wide);
        _attachment->setRegionHeight(high);
        _attachment->setRegionOriginalWidth(wide);
        _attachment->setRegionOriginalHeight(high);
//        _attachment->setRegionOffsetX(offset.x);
//        _attachment->setRegionOffsetY(offset.y);
        _attachment->updateUVs();
        AttachmentVertices *attachmentVertices = (AttachmentVertices *)_attachment->getRendererObject();
        if (attachmentVertices->_texture == texture) {
            return;
        }
        CC_SAFE_RELEASE(attachmentVertices->_texture);
        attachmentVertices->_texture = texture;
        CC_SAFE_RETAIN(texture);
        V2F_T2F_C4B* vertices = attachmentVertices->_triangles->verts;
        for (size_t i = 0, ii = 0, nn = _attachment->getWorldVerticesLength(); ii < nn; ++i, ii += 2) {
            vertices[i].texCoord.u = _attachment->getUVs()[ii];
            vertices[i].texCoord.v = _attachment->getUVs()[ii + 1];
        }
    }
}
2赞

mark一下

2.x的有吗^_^

2.x论坛有同学亲测改改就能用,上面有楼层回复

2.x的问题在原生,web能用的方法原生用不了,要做那个jsb自动绑定什么的,环境安装一大堆,很可能最后还绑定不成功,劝退了。我最后用的方法还是选择直接挂点换装得了,真正做到所有平台适用(奸笑)

手动绑定,就一个方法而已

请问节点无法与spine中其他附件进行渲染顺序混排的问题有进展不

图片又挂了

3.81貌似原生的不行,不知道是不是wsam的原因

有解决吗大佬,3d的有做过不