Metal character animation

I just fell in love with the world of Metal and I thought I got it! But then it occurred to me that if I wanted to make a game, then static objects moving around the screen would not be enough. So my question is, "Can we animate models with Metal?"

I considered using other APIs like SpriteKit and SceneKit, but I found that they don't support shaders and are not as strong as Metal.

The only way I can think of how I would do this would be to create 60 different models and then load each one one by one to give a "stop motion" effect, but I think that would probably be incredibly ineffective and hoped there was an easier answer?

Thank you so much!

+3


source to share


3 answers


Yes, there are other, more efficient ways to animate. But before getting into it, a word of warning: it looks like you are barking up the wrong tree here.

Metal is (conceptually) a very low level interface. You are using Metal to talk (almost) directly to the GPU, so to work with it you need to think (sort of) like a GPU: in terms of data buffers, vertex transformations, etc. You seem to be working at a much higher level conceptual level, so one of the high-level game engines is probably best for you: SpriteKit for 2D or SceneKit for 3D. (Or a third party engine like Cocos or Unity.) Metal, on the other hand, is better suited for building these game engines.



SpriteKit and SceneKit support shaders. Look SKShader

and SCNShadable

documents (and be sure to click "More" to read the full review). SceneKit also supports character animation (e.g. skeletal animation as well as skinning): typically one designs and builds a model for animation in an external development tool (Maya, Blender, etc.), and then uses SceneKit to work with animations in lead time.

You can do things like GPU-based skeletal animation in Metal. But I have not seen any tutorials or similar emails yet, probably because Metal is a new technology. Basically, it would be based on the same techniques you would use for skeletal animation in OpenGL or Direct3D - and a lot has been written about animation for these technologies. If you are willing to invest time and energy in low-level work, adapting a subject from the GL / D3D textbooks is relatively easy.

+5


source


You can do skeletal animation in Metal, SCNKit will use the GPU to deform the mesh. But in order to do this in Metal, you will need to transfer the weights of the skin, as well as the bone matrices for the pose and binding of the bones as they come to life, and then calculate the new positions of the vertices based on them. Actually, I think you need the inverse of call matrices. Then each mesh vertex is transformed with a weighted sum of transformations determined by the skin weights.

I tried this but screwed it up, somehow it didn't distort properly, I don't know if Id got wrong matrices from my custom script to grab animation data from blender, or error in my shader maths or from weights.

It was most likely close, but with all the possible things I could have gotten wrong in the process, it was hard to fix, so I left it at the end.



It's probably easier to stick with SceneKit and let apple take care of the rest, or use an existing game engine like Unity.

Again, if you need a challenge, I'm sure it's possible, just a little tricky. Can you try the CPU first to make sure the math is okay, and then transfer it to the GPU to make it faster?

+1


source


SceneKit supports shaders. And the object that manages the relationship between skeletal animations and the nodes and geometry they animate SCNSkinner

from SceneKit.

Typically, you will need to create a skin model using, for example, Autodesk Maya , and save it along with the animations that use the skeleton in a scene file. You load the model from a scene file, create or animate it in your application, either by using animation objects also loaded from the scene file, or by directly manipulating the nodes in the skeleton. What is it.

Follow this 7-part video on Blender's skeletal system and how to use it in SceneKit .

enter image description here

convenience init(baseGeometry: SCNGeometry?,              //character
                 bones: [SCNNode],                        //array of bones
                 boneInverseBindTransforms: [NSValue]?,   //ibt of matrix4
                 boneWeights: SCNGeometrySource,          //influence on geometry
                 boneIndices: SCNGeometrySource           //index mapping
                 )

      

0


source







All Articles