animation - Animating UVs in SceneKit -


i'm looking way animate sprite sheets in scenekit. after research found core animation way this, perfect need control on animation possible.

i've prepared simple plane mesh, uvs limited 1 spritesheet frame's size. way i'd need animate uvs horizontally. i've found relevant element of material's contentstransform matrix m14 (the 1 responsible horizontal translation).

however, @ runtime, scenekit spits following error:

[scnkit error] geometry?.firstmaterial?.diffuse.contentstransform.m14 not animatable path 

this relevant code:

let spritesheetanimation = cabasicanimation(keypath: "geometry?.firstmaterial?.diffuse.contentstransform.m14") spritesheetanimation.fromvalue = 1 - 1 / spritesheetframecount spritesheetanimation.tovalue = 0 spritesheetanimation.byvalue = 1 / spritesheetframecount spritesheetanimation.duration = 1.0 spritesheetanimation.repeatcount = float.infinity  node.geometry?.insertmaterial(material, atindex: 0) node.addanimation(spritesheetanimation, forkey: "spritesheetanimation") 

anyone having experience this? don't know if there's easier way this, or if i'm looking @ wrong way or anything. so, pointers appreciated!

two problems here.

  1. coreanimation extends animatable key paths data structures can animate — is, instead of animating between 1 complete catransform3d , another, lets animate key path describes member or attribute of transform (like transform.translation.x).

    scenekit not — can animate complete structure values. is, can animate contentstransform, not contentstransform.something, , need provide complete scnmatrix4 tovalue / fromvalue of animation.

  2. kvc key paths don't have swift optionals, geometry?.firstmaterial?.diffuse.contentstransform not legal key path. lose question marks , should okay.

so, code should (untested):

let spritesheetanimation = cabasicanimation(keypath: "geometry.firstmaterial.diffuse.contentstransform") let translation = scnmatrix4maketranslation(1 - 1 / spritesheetframecount, 0, 0) spritesheetanimation.fromvalue = nsvalue(scnmatrix4: translation) spritesheetanimation.tovalue = nsvalue(scnmatrix4: scnmatrix4identity) spritesheetanimation.duration = 1.0 spritesheetanimation.repeatcount = .infinity 

note need wrap scnmatrix4 in nsvalue pass fromvalue , tovalue, because swift can't automatically convert scalar numeric types.

also note can use type inference float.infinity if like.


Comments

Popular posts from this blog

python - mat is not a numerical tuple : openCV error -

c# - MSAA finds controls UI Automation doesn't -

wordpress - .htaccess: RewriteRule: bad flag delimiters -