• Runtimes
  • Spine ios runtime 不支持使用外部动态贴图替换附件贴图

我正在iOS端使用Spine-ios runtime(spine-runtimes/spine-ios at 4.2 · EsotericSoftware/spine-runtimes),尝试使用动态图片替换附件贴图的方案来实现虚拟形象换装的效果,目前遇到1个问题

发现目前的iOS runtime api,并不支持更新RegionAttachment(swift)的region属性,通过以下代码
SpineSlot *slot = [controller.drawable.skeleton findSlotWithSlotName:@"xxx"];
获取到的slot对象的attachment属性默认是Attachment类型,而不是根据类型会提供不同的附件类型,如RegionAttachment、MeshAttachment,并且从目前的c++实现来看,RegionAttachment 或者 MeshAttachment 都是继承自Attachment,但是在iOS 的swift这一层这里,3者之间并没有关系,都是继承于NSObject,我们就无法通过RegionAttachment来替换贴图纹理,这个需求就无法实现
目前我看iOS,web,cocos,unity都是支持动态替换附件贴图,只有iOS不支持,这个可以考虑支持一下吗?

Related Discussions
...

目前,Spine iOS runtime 确实不支持直接在 Swift 中动态替换 RegionAttachment 的贴图。你提到的问题主要是由于在 iOS 的 Swift 层中,RegionAttachment、MeshAttachment 和 Attachment 之间的关系没有在 API 中暴露出来。

虽然目前官方的 Spine iOS runtime 不支持这个功能,但你可以尝试以下几种方法来实现你的需求:

  1. 使用 Skins 功能:Spine 的 Skins 功能可以用来动态替换附件贴图。你可以预先在 Spine 编辑器中创建不同的 Skins,然后在运行时切换 Skins。参考 Spine Skins 文档。

  2. 自定义 AttachmentLoader:你可以创建一个自定义的 AttachmentLoader 来加载和替换附件。参考 AtlasAttachmentLoader 的实现。

  3. 修改 Spine iOS runtime:如果你有能力修改 Spine iOS runtime 的源码,可以尝试在 Swift 层暴露更多的 API,使其支持动态替换 RegionAttachment 的贴图。

  4. 使用其他平台的实现作为参考:你可以参考其他平台(如 Web、Cocos、Unity)的实现,尝试在 iOS 上实现类似的功能。参考 spine-ts - change region on an attachment during runtime 的实现。

希望这些方法能帮助你实现动态替换附件贴图的需求。

14 jours plus tard

想问一下外部动态贴图纹理怎么转换成texture

也就是外部网络图片怎么转换成spine-cpp中TextureRegion的rendererObject属性

I'm afraid this is not easily possible with spine-ios at the moment. We are discussing internally how to provide examples for this use case. You can follow the issue here:
EsotericSoftware/spine-runtimes2639