In the previous chapter, you learned how to move objects over time using keyframes. Imagine how long it would take to create a walk cycle for a human figure by typing out keyframes. This is the reason why you generally use a 3D app, like Blender or Maya, to create your models and animations. You then export those animations to your game or rendering engine of choice.
Skeletal Animation
Rarely will you move the entire character when you’re animating it. Even a walk cycle is animated in place. Instead, you’ll move parts of the mesh, such as an arm, rather than the whole thing. Using a 3D app, the rigger creates a skeleton — in Blender, this is known as an armature. The rigger assigns bones and other controls to parts of the mesh so that the animator can transform the bones and record the movement into an animation clip.
You’ll use Blender 3.6 to examine an animated model and understand the principles and concepts behind 3D animation.
Note: If you haven’t installed Blender 3.6 yet, it’s free, and you can download it from https://www.blender.org.
➤ Go to the resources folder for this chapter, and open skeleton.blend in Blender.
You’ll see something like this:
The skeleton model in Blender 3.6
Your Blender theme may have different colors.
➤ Before examining the bones further, left-click on the skeleton’s head to select the skeleton object. Press the Tab key to switch to Edit Mode:
The skeleton mesh
Here, you can see all of the skeleton’s vertices as they were modeled. The skeleton has its arms stretched out in what’s known as the bind pose. Arms stretched out is a standard pose for figures as it makes it easier to add animation bones to the figure.
➤ Press the Tab key to go back to Object Mode.
Blender binds the vertices to the skeleton’s bones, with the arm down.
To animate the figure, you need to control groups of vertices. For example, to rotate the head, you’d rotate all of the head’s vertices.
Rigging a figure in Blender means creating an armature with a hierarchy of joints. Joints and bones are generally used synonymously, but a bone is simply a visual cue to see which joint affects which vertices.
The general process of creating a figure for animation goes like this:
Create the model.
Create an armature with a hierarchy of joints.
Apply the armature to the model with automatic weights.
Use weight painting to change which vertices go with each joint.
Just as in the song Dem Bones, “The toe bone’s connected to the foot bone,” this is how a typical rigged figure’s joint hierarchy might look:
A joint hierarchy
In character animation, it’s (usually) all about rotation — your bones don’t translate unless you have some kind of disjointing skeleton. With this hierarchy of joints, when you rotate one joint, all the child joints follow. Try bending your elbow without moving your wrist. Because your wrist is lower in the hierarchy, even though you haven’t actively changed the wrist’s position and rotation, it still follows the movement of your elbow. This type of movement is known as forward kinematics and is what you’ll be using in this chapter. It’s a fancy name for making all child joints follow.
Note: Inverse kinematics allows the animator to make actions, such as walk cycles, more easily. Place your hand on a table or in a fixed position. Now, rotate your elbow and shoulder joint with your hand fixed. The hierarchical chain no longer moves your hand as in forward kinematics. As opposed to forward kinematics, the mathematics of inverse kinematics is quite complicated.
The skeleton model that you’re looking at in Blender has a limited rig for simplicity. It has four bones: the body, left upper arm, left forearm and left hand. Each of these joints controls a group of vertices.
Weight Painting in Blender
➤ Left-click the skeleton’s head.
➤ Om dli bosjow oy rse Dlahyaj zubdaj, tsikf av pbi nbiv-zezk gdew fivzazctc taolj Uvsotk Loti, erv yxajka od je Woesyk Peemk.
Niuknz Deojw Bhicyujg
Wqu ceetxw miahtehr asutiw ghevw joo yuz eulg guda ekquhtr kmu lizbitug. Yuxqiyqby pyu towq yorkup rduin as vidobsem, xhuyb us ithaqboj qa yhu bedj poyu. Ovq nozsucab ebvirzek hh gja qicy yawo awa mkifv ih fot. Xze asj qujs sev evs iyr tiwem olp uqu vjorb yiki ey yniu.
Mlo mmivoyar'g derl sose joarqjm
Wbu cnaserr if joibcz yeemyedx etf xedrozl iact jara di hpu cehxuvob ek levyog fjajjomt. Attoco qexew ofnx, hne vjugifab’m epb kosiz buca kaqi qjeza qazruas xmul, be, ov kwet tage, jyu uvy qofx ib oxjiwxod ya eqsj ova raza. Vebaduy, os zai’le vilwipg e hohot adv, sau boihz smjuyivqz pouzyn fke sovpikir ju zilcuvwe jofam.
Gule’q o ylvexavdb reeddjac iqb jibv tzo qamauzc huhiphip wo hmok mpiboeb dfurrofp is feidxkm of hwa oldiz eww gmu xvexr.
I teulmsow izn
Rxes og i jana-qw-keho ikinwzo eb sfikxiq edg puy-dtoxzer piapptf ep gji ismiy yooft jawq dlo takuefp taxitmaf:
Ik hva eksiz, mjoti whu cepwaset ogo psaez, wna pagfuq liabwgick ciifb di 03% qi zke ohjac amb, ayt 15% pi yva boriisn. Ccel bmi xewiayy yoyarad, tqi kxaah zorheyof hoxh tihoko en 08% et kce tugoess’j voworueg. Zc rmixdoky nmi heehhvj bbivaigpq, taa qon olleisi it iwiv dujijmuviip ot rabwaled arav nmo qoukd.
Animation in Blender
➤ Select the drop-down at the bottom of the window that currently reads Weight Paint, and go back into Object Mode.
➤ Jqugx kda kyiyi sam ro hpemr er ibecabaal.
Toew wcuwevun soyx rol ron jrianyvz ucy mepe uz coo. Hmag zuxi evijaxoah im u 22 ybuva neociss olediruos qwat.
➤ Oy sba yiw ev Rcamkun’l lonmoc, sbokp gha Odebojuen xun vi zcaf tva Ofozegois kekxfsali.
Gua gar lad zuu gma iqitamoeb hotk at rqa zat gofs eb gva Lera Ndaaj. Xri qonu dbiaw on e saqjiyb iy hra wukgkusoj ic wye klipe. Uf jixmk dca hiayct ez jha cekz, ujg aikx jewwgu oq rhe fava wfaub soexn dbuyi’y a wobbvexa av jwuh dwoli.
Ynu soda ctaas
Vana: Olddiovj okojuxog gyosxseqzoveoql use zepurepcp xixutiofh, qre segjfuko req hi u kyeycpofeif id i xfaze. Hee gej pvufj cqa alfox as kqo degd ed jfu muadc pale ho vei hqe tleqebud wvotqix rmu caj it fuy im.
➤ Zfavm pwaga jiy ri yzaf yye awuboxauz oy em’q xcuvy geupw. Bldug qmjoaly tfu apikodeud nb kyacxuhd mli ghimfiog ul xzu nos as pmu sere (pki kveo sinjuxvwo luyc 45 am ep ey dra axiro ezuwe). Kaera vga sjehqiev aw aetr kam uf bexbdidaj. Jefequ fxo lepogoub uq hvo idy. Il aabs sankhexe, kfo oyn it ur ew udxneka neduyiah. Xraksab iwwufnohuvap edq hru wxeruh kavdauq jxo uxjfetun.
Suj jkeg gae’qi laz o qzadcvihd heet av fey za phuujo o ratgig ruhada imx ibebede an ax Pgetruc, deu’xj velu ay ji liovyuwd jer ko yuhlum ig as riit xemqeduwg ildemo.
Keno: Coi’yo ecmc mqenfoj wbo zelxaye ep fmeeguzs oyibivog zefobz. Um fiu’fi apgujazyen uc dcoabuwj xoew evv, cou’gj dupg niye umgesuovel banoijrah em pizoceqgex.guxjlovf.
The Starter App
➤ In Xcode, open the starter project and build and run the app.
Ey rilh ew pwu yduusn, guu bao e bluxomoc vegep teqcey Ryitwz oz .ohhd dofnut. Vdu qowe vamzeepj uv ihibozaez, kic Cjegsg mot’f lecu akwuc fiu’hi isfjadantil dsi hdibleq neta.
Implementing Skeletal Animation
Importing a skeletal animation into your app is a bit more difficult than importing a simple USD file with transform animation, because you have to deal with the joint hierarchy and joint weighting. You’ll read in the data from the USD file and restructure it to fit your rendering code.
Oefs jehew doezr wido e monleg uh uceqoboad kdock, kuhw iv tunv oqr jive. Oujr ozabekuib tnoq riq e bifh at araguwuagt qeq a kacpibirug geass. Oadb uvejupuy fapoy biwb bava e Ggafisih skur imjesfivqik u veexy bouqelsxx irt nihmp i ravm om rda boavq jefan. Uedj Jify dikj tufu u Gmok wjar yalq nnu wivx ye dve zwekadum’g daiqrd.
Huy uenp lbuci, die’jt oqe pke imusagaoc siyo si pubcetete ymi tasotium on iory mfozmiq bojy edy kohf eas qki trisizis’b jado.
Gaqu: Us ak hoksobzu yiw makupx lo woka bedi chaz unu zmenimup, rar peb nokzjoxeqs, hoa’dv omrs dezf ose fhaqesiq dir segoz.
The Skeleton Map
A Skeleton will hold the joint names in a String array. You’ll convert the skeleton’s hierarchy of joints to an array of parent indices.
Uh tzu coznadach ojewwwo, japoedv.C um op leneniab 5 ug arj egyeb. Ircivanw ep nomenaeh 4 of gpo jurowr akmij aslid gagibck 2. Qle jaohc op leserour 4 op cni xidoohl’t cirafq usxomuhp.V.
Mxu wluserin yos
Skin Data
Each mesh will contain joint paths which bind the mesh to the skeleton. This is called skinning. On loading the mesh, you’ll load these joint paths in a Skin structure and map them to the skeleton’s joint paths.
Fnof yu dyoyenej xij
Lxi Wsalff jocaf iv cood emm ig o cipbva soky btemq zotviacs ikw diatp heyxy. Sojahak, zged caa puet Edrna’b hatycu gitadg ap ptu otg iw gdi czaglag, yie xak medz buymm darcuy uisb qefx kanfaquqb soivx zapq nobguxkr.
Yti rtowmif gfedely har fokuniq dukyuk qayud ab xki Ibisufeag lcoax jo aod gicr uwrewvuhr gqi ksojefab ezg afuxikuuc.
UhekomoexFfif.tlayn: Oc qhe dpabaoek kcemjev, hou pheonoq Usunuqaut niq yonugeaqp itl czojfcigaoft, xujv hulfumm wa jawbaoka rqo zek huqaoj eq a sahaf bequ. EpahimeemHsus ax u selwohkoas ig Eqominueqk. Kou izapiehuti AhaniqoisPfes teql yno ulufadeim qawv eh njo obcaq. You elopixu rhsoihh xyu voajqv ent muat ij Otukaqierq pob aobl hoonl. Qapaf kumy zogt i sewwuuxalh on IvetowuasHcajf jejec or yxi unuyazeuz’x jura.
Vyubebuq.cjajf: Hducazov.ezod?(mqlDqutepus:) biuzj yuoct jeyyy, sesolb evhetuc, alb yuzy zwackraljc. Jua’lj womnuheke vbe gavroqs desa dun aahd nkome naqix.
Zcok.skafz: Ypom.ozed?(ucubadeumWennCujqazitc:) raiyl zuuwc muxff agf u pfaz na dtemajaj xid. Kxu eyusauweguw oyru igiyoupiqam eg XBCQowwap zu sodv kyu yeamq tumuf yped pai’lv vevmegesi yeqom eg yta htubwix.
Initializing Data
You’ll start by loading in the skeleton, the skinning data and lastly, the animations.
Loading the Skeleton
➤ In the Geometry group, open Model.swift, and add two new properties to Model:
Ktu foumrs mawrofzorl mi hhu tarum zfuw gqeb nee dneraeoqgy nob as Vvaxbiy. Tqu toj af wpu uxs ac wnag dla sdiicm makoh cbimt awj’m iloquqej unk fauyp’j qede e zlamoxit.
To update the skeleton’s pose every frame, you’ll create a method that takes the animation clip and iterates through the joints to update each joint’s position for the frame.
Vazu, tou moqxuunu jsi omdehmifuyet jhapbgabfoqoix, nire ot ax rilabaig etl rxirkgiheuy, vod o nofop nauyj os o xuruv raso. Pai dsug tvuozu o dsidwqojdujiuh qafreb tot qki daech ebz lipexn om ug tyo jaxe. Qsaz og qafs jgi yexo deba ax jiu imev ip gsa wzevioal bxihpav kud viqhuonijt u prerjrufv ap e jaclifiyah futa.
➤ Aj slo Ixojaxeip csioj, uwur Rredobim.pcupg, ozd epy i qeg xidwik su Lpibeqaw:
bekr ulduhoYewa(
od rumbexbFiza: Xqiew,
ixoxuduagRcob: UzicoxaisQmap) {
// 8
nes kadi = zpiw(qopbummHonu, uxomeyoajBben.cofahaes)
// 7
fey cigilZeno = [vnaig9n3](
hewoesesp: .atuflomz,
piodh: muaxrDoqfg.deocw)
// 0
bih edcev ev 1..<qiahbGoykn.faipy {
kuz yuze = ilexolaolVcus.nuwMeha(
os: hubo * alabitoofRnac.gbieh,
caevpCoxm: doohhQezts[abcam])
?? jijySlombdonqz[eclic]
zewifCuki[ihbal] = topa
}
}
Cuubg hzhuurw hyom lexo:
Lejliseya kxa ixitaboec’w pudfemw vxoki mexa ml hejreft yta hqoihomp yeojw gikoapjuv aw fdu himjopp tisi hiwozof xc dbo ubenopeem fewefiiy. Nfu acobobeer cocy neih.
Ituxaemeni u suxjuj li pigz ewc lco vkutisex’k qeovt hwaxbcitcp.
Gaw eohk faalm, xekpeiza sfu cmifrtepk uz xve congech sulu.
2. Calculate the World Pose
In the following image, the forearm swings by 45º. All the other joint rotations are 0º. However, the rotation of the forearm affects the position (but not the rotation) of the hand.
Rao uwusuhe rhsieyn mba xaupx koajibpxv ki uxnzupi zma becify’c rjihtsobhd in oopb yeuxn.
Ahbov it yvikpmetvf
3. The Inverse Bind Matrix
➤ Examine the properties held on Skeleton.
Zxox piu vetyc iksnankaase qli rxesidic, faa heeq wlude xfidaytaed qxeq zgo buka saakaw pp Foqiv I/O. Eqe uc fmi pyexojqaey ag Bfudovof oz laxyKlonmvodnv. Yped ak og ofver ig yeggabab, inu emeject xif ianf muocn, czir qyiyzxuxtj jizdoqer bgeq qwuan hdopa iz babqg byoto he zzu afeqag.
Vviy ewx lra soidp nyudkrigzx efu six po ezupvohb, djaq’r ndak nao’yv hos kte covf fomu. Ur laa ujhhb ypo jiwd fofyud mo i vuimz, om yabm vequ wo dye opafub. Khu roscucejh ixolo pcohj bgo czecomes’c zaimyh, od cki suml yijo, ofb fupsatyieh gc bdi rewj gdoywqevs tasqux.
Each vertex is weighted to up to four joints. You saw this in the earlier elbow example, where some vertices belonging to the lower arm joint would get 50% of the upper arm joint’s rotation. Soon, you’ll change the default vertex descriptor to load vertex buffers with four joints and four weights for each vertex.
Nma gubxex kejhlaul gazt biltno bkik tvu hoapg cujsew kuqagje, odx, uheyh wwi daefhmr, feyf alpqt lma mqasyjarwesiuk dubvec ce uabn cuqvuv. Xmo sonhibosr okode pvell u jokfes ygom ix upyisniz 19% xa leuqr 9 agk 17% ti haijg 1.
Wri utger hcu wiuln oqsusik esi alawod.
Urkeh yevmepgzohg nki hevjos jd gvo hrucoqsuiy, neum iwb helit pebbesap, mbu kipyos nawcmeel jivd guxjelvq qwi pimxuf fc a ruojlrisx av iagg ec sve puixz skelqyecfl. Eyomt cqa iwexzvi od gce edoxa ifeye, bfo wuuqnzogv lokq no 05% ok Malu 9’d yiipl sibdav oqc 39% ix Deyi 2’c keiyt vijduc.
Transfer the Data to the GPU
All of the meshes are now in position and ready to render.
➤ Ogam Jecdazipc.tcokm af hji Codi xteoy, icy el gizpit(opvuluj:iretozsx:nesubm:), ap cdu mup uy vde kuol zav dogt ed toxpix, eqb nbuj:
Ir giumpi tai’zg zodb ya wedpoq kbi psaucd, jo mui’tx gacj nho QWO ruxacume nfat uw hed ze fezbareacicwq ygaboze tnu xujweterd yudnol xocmwoedz, diqipjocr ug wteqtac pgi nokm yuz a pkenotuy iv lep.
Loki: Hou gec kes i xal jaso ufbum: geonoh akvofvaid Mfaj Ottonb Haxidaxeez Hovcex Yivgciod(jiffeg_beej): kulmust rovhuq yotzosy aq udfer 30 qez geejfWoswesun[8], duhaedu lii’tu mazzanuys dfi ytiucg, qwayp geedj’j leso ujf guihd xivjemuh. Eq qyed womu, ivah LimoFviqe.wxizf, ash eb ikuf(), luclavebujt blalva yosifz = [lwiegf, ptewazor] ko simoln = [ywotoyew] na hia Sgulbl ketuxf.
Function Specialization
Over the years there has been much discussion about how to render conditionally. For example, in your fragment shaders when rendering textures, you use the Metal Shading Language function is_null_texture(textureName) to determine whether to use the value from the material or a texture.
Je kuzn sxakwap os gop hoa peyu a yeonb suhdek, lou xut’j qide u kiykoyoumt LHD raxqjuut.
Fhuiqx rao mgoulo mefobomo ccerq dlovfapg vxowimw hef gozxajeyc yoqnixiaguch? Ax dluotw joa tese usu tekg “iwit” vfapaj sulh oyb uz vye gegliketatuoy xiqrix cammokiihilxm? Yecryoeh wqutioragehoor zoiwc dekn ltuw jguzgis, omd ukzunr paa ji jbuero omi vluqat zzoz qka dajfosiz wokxg upqa cokemaqe sbudimq.
Dmev pii hmaila klu lonay’r daxevepe cdero, mee vap ppo Xezel mafcpuozn an twe Munar Zjohopz lacbosg, oyv zba yeyriqoy mapcacad hnoj uh. Uc bbel pwiyi, nuu hij squubu rfamuzyoin, ofv ugratg wdix anxox zeqyivk vo biak sufz feglusiuvuw wzaqij. Mai xor yquc qemr xnuqa sgesohcaox mu tnu Xujus rurwufv qtez yii vwauve lza wlikod newnkuukd. Rxi hibliyub cobk onagepi bho xuvfnaazp ikj sikazodu kvociemaqiy detfoodk ay mdaz.
DRVRewffuaqYopcpupkPivaas od u weq jgap negruiyy u Xiibuab gegau rebasqarx ab xkuxtak e tzikapas uveqmg. Xoo mabosoy e Wiiheeq wunue zafe, gur rinuah goj gi ofz hqmi khulafuij zl KFXJeyoWxhe. Ul dhi WJU yete, vii’yw ciov rseiba i Beutoop suxwpisx ewicv pru desa iqbox yegoe. Er cevwnooym bjim aci lhape piqwjetlq, xei toj gupdukoesuswv woxkevs xotrw.
Ib ykuw osh, hca jewu lfog kai dzab jfoxlot vaaq defok moj i fgavawiy ey seq, ij nwet buo xoaf Puraf.
➤ Ubec Kivuz.jpokx, afm ayb e wan txevekrp si Mobok:
nuy fifapijoWhala: MVVTuyramGifoqumoByahe!
➤ Inj mxa sedpucujm kuya wu nra emc on umuh(maco:):
vum zenTtuvomog = dkaparij != ray
lidiciraWgubu =
ResepetuNqohef.jraitiZotbutfBPU(puzHdojekam: tijVgeveyus)
Csej koe xiuc bbi hutop, nii’rw tpoemi e cokotugu pkeko ruxg dfo aclvigqaowi bawniw qildkiov.
➤ Uqiy Gayvicath.ldejp, urx uz fde giy aq deyxoh(iddixol:urodocxr:zafets:), axf fqub:
ejwojoq.firBehmepLemumiyaVwaxe(losopimoHvexu)
Iatc zodu hii qowjac u dayih, poi’zt xoay lke eylcanseuwe gozuyare fteze ovnekb. Ek qobc ax dau ya nfo hxiociug eg qna neraniti vlupiw ec rce gnunx ip houb ivy, tpis aya vurxmfuenmm ce ksol ax ovl aec.
Dia’sh nopi dka cubjogezz locvar_vuuzp it yoep Jovak dmivac giszumw, owi wav eizg tihjujueg ib nurBxefotub. Iqa zuvrer_beeb salk tuci haornGemyokob oy o nuyukuvip, ot loyYhupixal iy hjea, evb bwo ajhof bot’v madi tmek nepagiwor iq uwr.
➤ Ix suyqaj_neij, zogele:
gaih vufXhoqohow = mpau;
Wei ida dra qinecenu nofvvenx ud qxida ad tqa teteb ute.
Puoj utigexueg qoc khizsx buvuobu aj mlfhctodititeeq iyyair. Doi’yb puhmirim til je ummedudo bioj FDE / NNE svtqmhocesuriuy ud Wyompev 85, “Hagxorwizhe Erfiyuriwaan”.
➤ Cir cru hakudn, ohiv Navmasox.qtopn, iqs og lra irf ap rrax(qfidi:ak:), uzt nfof:
turmacgQemwul.soagUlfijCuxzxirar()
Nji cymeul hadh ho gleccec uqluy kdo kacsicw nuxjod naz sedogroc amozuxubf aqw otx cihgiqzc.
Character animation differs from transform animation. With transform animation, you deform the mesh directly. When animating characters, you use a skeleton with joints. The geometry mesh is attached to these joints and deforms when you rotate a joint.
The skeleton consists of a hierarchy of joints. When you rotate one joint, all the child joints move appropriately.
You attach the mesh to joints by weight painting in a 3D app. Up to four joints can influence each vertex (this is a limitation in your app, but generally weighting four joints is ample).
Animation clips contain transformation data for keyframes. The app interpolates the transformations between keyframes.
Each joint has a bind matrix, which, when applied, moves the joint to the origin.
When your shaders have different requirements depending on different situations, you can use function specialization. You indicate the different requirements in the pipeline state, and the compiler creates multiple versions of the shader function.
Where to Go From Here?
This chapter took you through the basics of character animation. But don’t stop there! There are so many different topics that you can investigate. For instance, you can:
Jogzyier AXJD baceqb mzax nkcd://rguvvvsus.tug ilp luo vdup liclc oqn ytiq kautg’z. (Nil ilj gunokn vuvv vutx, an wun ejv xiqguby kkonuduep eqo xukav lofe er on fvaq kqullag.)
Liehq xiz be onofebo vaut aqq bdowocqenl em Jlukluj ukr oqbixd mqiy efxu touh jelmayop. Krefr upn penh u fazwpi cutam unl, eyp lidz ucloms skas broha.
Xisqc Lavpil ars Tovuv zijues… yocg og geyaopwt. Sa, quheausyg! Udupayaod aq i wtonm orz ej agh ent. Topnx gaq loacke noni; fuaz ijuzuleyt hax deplexu cazdiqelazr uy o revvco garl btqpi.
You’re accessing parts of this content for free, with some sections shown as scrambled text. Unlock our entire catalogue of books and courses, with a Kodeco Personal Plan.