• Editor
  • 对于具有相同骨骼结构的不同骨架,如何使用同一套动画

你好,我们是2D项目,如题有这样一个需求,项目中有很多角色都具有人型骨架,并且有同样的动作需求,如10个人形角色他们都有攻击动作,他们的骨骼结构一致(包括骨骼节点的命名),但是是不同的骨架,可否共用一套动画,这样就不用每个角色都制作一个攻击动画了。类似unity的avatar功能。

    Related Discussions
    ...

    ECG_Kinsey You can import animations from another Spine project via Import Project.

    For your information, importing animations cannot be done through the CLI, so if you create your characters as separate skeletons, and you update an animation in one of them, the only way to reflect that update in the other skeleton is to import the animation manually.
    We plan to improve this in future releases and have an issue ticket for it, but we are not sure when: EsotericSoftware/spine-editor379

    In other words, if you want to share animations between many characters, the easiest way to share animations is to create the character using skins. By using skin bones and skin constraints, you can create multiple characters with a single skeleton, even if the bones and constraints required for each character are different.

      Misaki 感谢您的耐心解答,皮肤约束的功能一定程度上能满足人形不同尺寸的角色的需求,想咨询下如果不同人形角色都用皮肤的方式来制作,该骨架将会对应非常多的皮肤以满足不同的角色以及同一个角色的不同换装的需求。如此情况下该骨架在运行时是否会有数据过大而导致加载的性能问题呢?

      @ECG_Kinsey Unfortunately machine translation of your text was somewhat ambiguous. Are you asking whether loading this skeleton leads to long load times due to a lot of atlas texture pages (many textures)? Or are you concerned about a lot of bones, constraints, and so on leading to a larger skeleton.skel.bytes file to be loaded?

      Regarding atlas textures, you could use on-demand loading of only the currently needed atlas textures. We provide experimental UPM extension packages as described in this issue ticket:
      EsotericSoftware/spine-runtimes1890
      Otherwise whenever the skeleton is loaded by a scene, all atlas textures would all be loaded as well since the atlas textures are referenced by the materials, which are referenced by the AtlasAsset, which is referenced by the SkeletonDataAsset.

      Regarding loading additional skin bones and skin constraints: this will add a bit of an overhead, however it should not matter much compared to loaded atlas texture size.

      3 meses más tarde

      Misaki 对于您之前的建议,我们在实践中遇到了新的问题,当2个不同的角色通过皮肤和皮肤骨骼以及皮肤约束的方式共用同一套动画之时,这将有很大的局限性,目前看来,这种方式仅仅适合同一个角色的高矮胖瘦的不同情况,而不适用于完全不同的两个角色。

      举个例子,当我两个不同的角色(比如其中一个是人类,另一个是兽人)有不同的大腿长度,我无法通过约束来更改骨骼本身的长度,我只能通过约束去缩放腿部骨骼。但是当我这样做的时候,这又将导致该骨骼下的附件也会因为缩放而导致失真。而如果不改变骨骼本身的长度,适合人类的腿部IK在不同腿部比例的兽人模型下,看起来会显得不适配。

      这种情况是否我该单独为每个完全不同的角色建立一个新的骨架,通过动画导入的方式来复用另一个骨架的同名骨骼变换?如果这是推荐的解决办法,那么每当我人类的任意动画调整,我都得手动导入至其他角色的工程,来让其他角色也拥有对应的动画调整,当我角色众多之时,这将非常繁琐。

      或者是否有其他更好的解决办法?求助

      You can disable scale inheritance so you can scale the bone to make it longer without affecting child bones. Your bones would look like:

      leg > legAttachments > regions/meshes

      The legAttachments bone would have Inherit: Scale unchecked so when you scale leg, the attachments don't scale. Of course you will need longer attachments for a character that is taller. You'll be able to see how everything looks in the editor.

      Alternatively, you could adjust bones at runtime. You could increase the length of a bone (and move child bones that amount if needed). if you change the setup pose (SkeletonData class) it will affect all the skeleton instances. You may want to change the instance data (Skeleton class) and apply these changes each frame. Doing it this way you won't be able to see how everything looks in the editor.

        Nate 骨骼的继承:缩放勾选框选项在对于受两个骨骼IK约束的骨骼不可用,而我的腿部骨骼是受IK约束的,我无法通过这个方式来取消缩放对附件尺寸的影响

        That's why I added a legAttachments bone after the leg IK bone. Disable scale inherit for legAttachments and move your slots under that bone.

          Nate 我明白你的意思了,我去尝试一下,诚挚的感谢你的帮助

          • A Nate le gusta esto.

          Nate 有关缩放的问题,我通过您建议的方式解决了,但是对于完全不同体型比例的角色,通过皮肤+变换约束的方式我仍然无法很好的解决骨骼适配的问题,因为在这之中除了缩放,还需要改变骨骼和其附件的相对位置。哪怕我们的角色已经按照相同的姿势来产出了,但是由于他们的胯部宽度不同,角色B作为皮肤导入之后,他的腿部附件和骨架的腿部骨骼相对位置并不正确。我尝试先把腿部附件挪到别的节点,然后通过变换约束调整腿部骨骼,使之在当前皮肤下和当前的附件网格的相对位置变为正确,然后再把之前挪走的附件给挪回现在的腿部骨骼下,这个时候B看起来他的骨骼装配表现符合预期了,但是当我切换为A角色的皮肤之后,发现A角色的腿部附件和腿部骨骼的相对位置发生了变化,我始终无法很好的兼顾不同角色通过使用皮肤的方式共用一个骨骼和附件。

          我这种多个角色身材比例有较大的区别的情况,是否该采用每个角色单独建立一个骨架,骨骼关键节点保持相同的命名,通过动画导入来复用动画的方式呢?

          • Editado

          As a side note: disabling inherit scale has the downside that you can no longer squash your whole character with scale.

          the relative position of his leg attachments and the leg bones of the skeleton is not correct.

          I don't understand the problem. Attachments coming from a skin are positioned separately from other attachments. You should be able to have transform constraints in a skin to move and scale bones, then you can still place your attachments in that skin as appropriate for the new positions and scale.

          Can you show the problem with an example project? For example, here is spineboy with a tall skin:
          https://n4te.com/x/9913-spineboy-pro.spine

          should I create a separate skeleton for each character, keep the key nodes of the bones with the same names, and reuse animations through animation import

          It would be much better to avoid duplicating the animations. While you can import animations across skeletons, you end up with 2 of the same animation. You need to redo the import to keep them in sync. It's extra work and easy to forget.

          The runtime solution I mentioned might be better, though let's continue discussing the skin bones/constraints way of doing it first.

            Nate 我无法打开您提供的Spine项目,这个工程的版本信息好像不正确。

            您提到的运行时调整骨骼,可能也并不适合我们,因为我们的美术工作人员需要在Spine编辑器中预先预览确保每个动画的正确性,以及需要为每个角色的专有骨骼做额外的动画,在运行时调整骨骼,这对美术工作人员而言门槛太高了。

            我提到的关于附件和骨骼相对位置不正确的问题,可能描述有点不准确,由于我无法打开您提供的工程,下面我通过提供一个具有图片说明的例子来尝试解释下我们遇到的问题。

            上图中为骨架和角色A的适配情况,他们适配的很好,请关注红框内这个橙色的骨头。

            而在角色B的皮肤中,由于角色B的肩宽和角色A不同,所以导入角色B之后,红框内的橙色骨头和角色B手臂的相对位置并不正确。
            我们尝试用属于该皮肤的变换约束来调整橙色骨头的位置使之和角色B手臂相匹配。
            但是当我们调整变换约束的同时,这个骨骼下面的附件和插槽也会一起移动,哪怕我们勾选了“附件不会被父骨骼影响的选项”



            我们猜测可能是由于IK约束导致的,因为其他没有IK约束的骨骼,‘附件不会被父骨骼影响’这个功能能正常使用。而我们也需要Ik约束来制作动画效果,同时腿部也有同样的问题。

            所以我们尝试了先把插槽从橙色骨头下移走,来确保移动橙色骨头的时候不会影响到插槽以及其内部附件的位置,在通过变换约束调整完橙色骨头位置和网格匹配之后,再把插槽放回橙色骨头下,并且设置此变换约束是角色B当前皮肤下才生效,让该变换约束不影响其他皮肤下的骨骼,通过这种方式,我们确实将骨骼调整到了一个匹配角色B网格的状态。

            但是当我们切回角色A的皮肤之时,发现角色A的手臂区域插槽和骨骼的相对位置发生了变化,此时角色A的表现又变得异常了。

            我们猜测可能是因为插槽是共用的,我们挪动插槽的举动改变了其和骨骼的相对位置,从而影响到了使用该插槽的所有皮肤。

            是否有更好的办法解决我们的问题,如果没有很好的办法能解决这个问题的话,我们目前可能会考虑的做法是将每个角色单独做一个骨架,然后同一个角色的换装用皮肤功能制作,而非不同比例的角色用皮肤制作,这样在版本控制上,团队成员分布式开发制作动画还能避免Spine工程文件冲突。

              ECG_Kinsey I don't think the IK constraint has anything to do with this case in particular, the only issue is when you set the parent of the image attachment to a corresponding bone. The following is a very simple example, but I am assuming you are looking for a rig like this, is my understanding correct?:

              Here is the Spine project files:

              skinconstraints.zip
              192kB

              What I did should be almost identical to what you were trying to do. I imported images of another character and adjusted the transform of the bones to match that character's arms using transform constraints, then added the constraints to the character's skin. I then set the parent of the images to the corresponding bones. This allows you to place another character's attachments without affecting the position of the first character's attachments.
              I hope this will be of help to you.

                Misaki 这看起来和我们想要的效果很接近,我们因为角色的手臂长度不同,在变换约束中额外做了缩放处理,不过这个应该不是导致问题的原因,可能是哪个步骤没做对。

                所以想请教一下您制作的步骤细节,如果角色B作为皮肤导入,那么角色B的手臂附件和角色A 的手臂附件应该是共用一个插槽,在通过变换约束调整B的手臂骨骼和网格相匹配的过程中,角色B的手臂附件会随着骨骼移动而跟着移动,这个时候,您是如何处理这个问题的呢,是否先将手臂插槽的父节点设置为其他骨骼来避免手臂骨骼的移动造成的影响呢,然后等调整完骨骼并且将约束添加到皮肤后再将插槽的父级设置回手臂骨骼,是否是我理解的这个样子呢?

                感谢您的耐心解答,期待您的回复

                Misaki 我是否在调整变换约束的过程中不应该去移动插槽,而是去移动插槽下的附件,这个貌似是我出现问题的根本原因?

                  Nate 有关之前您提到的附件缩放的处理办法

                  我们遇到了新的问题

                  目前通过变化约束缩放骨骼和在IK控制的骨骼节点下新增新的骨骼禁用缩放,我们让骨骼尺寸适配了新角色的附件尺寸,可是当我通过IK去控制这部分骨骼变换的时候,IK所控制的骨骼长度发生了变化,导致骨骼和附件又一次的匹配不上了。


                  不确定这个问题是否和变换约束缩放IK骨骼长度有关,求助

                    ECG_Kinsey (Except for the IK issue you just posted, this is an answer to your earlier question on the matter.)
                    I think your understanding that you need to move the attachment is correct, but it's hard to explain well in words, so I've recorded the process of setting up the example I just posted above and uploaded it below so you can take a look at it:

                    ECG_Kinsey Hmmm, as far as I have tried on my end, changing the bone scale in the transform constraint does not produce that result. I've attached a updated Spine project with the results of my own testing (in skin B I scale the arm bones via the transform constraint UpperArm_Position_B):

                    skinconstraintswithbonescale.zip
                    35kB

                    Perhaps the quickest way to confirm your problem is to see your Spine project in person. A minimal Spine project with irrelevant parts removed would be fine, so could you email it to us?: contact@esotericsoftware.com

                      Bone and attachment (Images) compensation affects manipulating bones in the viewport. It does not affect applying constraints. It is not applied when adjusting a transform constraint.

                      You are fine up to this step:

                      If I understand, you parent the slot to the root bone, apply the transform constraint, then parent the slot back. That puts the arm in the right position, but in your original skin the arm moves. Is the arm that moves in the same slot? If so, then you can't use parenting the slot to the root to move your attachment. Instead, parent only the attachments in the second skin to the root bone in a new slot, apply the transform constraint, then parent them back and delete the temporary slots on the root bone.

                      As a simpler test, instead of changing the parent of attachments in the tree, just manually move the attachments to be in the right place in the viewport. Each attachment has its own position. Moving one doesn't affect other attachments in the slot or in other skins. (Except for linked meshes, which share the vertex positions.)

                      For your IK scaling problem, you probably need to set the transform constraint to local and possibly relative. In general it's not possible to tell what is going on from an image or GIF. If you can send a .spine file it would be easier to provide guidance.

                        Misaki 已经准备了一个工程通过邮件发至对应邮箱,可以复现这个问题,我的Spine版本是4.1.24