2
votes

I am loading a model and trying to change the animation track on an a-animation event:

<a-entity three-model="loader:object;src:url(http://localhost:3000/upload/6tTxHz6JMPXMsGD8W/marine_anims_core.json);animation:run;animationDuration:0;enableAnimation:true" >
   <a-animation begin="mouseenter" attribute="three-model.animation" repeat="1" dur="1000" direction="alternate" from="walk" to="run"></a-animation>
</a-entity>

I sadly seem to get errors like this:

aframe-extras.loaders.min.js:688 [three-model] Animation "NaN" not found.
   playAnimation @ aframe-extras.loaders.min.js:688
   update @ aframe-extras.loaders.min.js:658
   updateProperties @ component.js:205
   value @ a-entity.js:427
   value @ a-entity.js:450
   value @ a-entity.js:579
   f @ a-animation.js:426
   (anonymous function) @ a-animation.js:136
   update @ Tween.js:339
   update @ Tween.js:81
   value @ a-scene.js:382
   value @ a-scene.js:407

I am unsure if this is due to A-Animation not handling text or what?

2

2 Answers

2
votes

I would use the event-set component for changing values in response to events: https://github.com/ngokevin/kframe/tree/master/components/event-set

<a-entity three-model="animation: walk" event-set="_event: mouseenter; three-model.animation: run;>
1
votes

<-animation> relies on Tween.js (cf https://github.com/tweenjs/tween.js/ for documentation) which basically takes a from value and a to value which are, under the hood, numeric (yes even for colors). The from value will be the equivalent of 0 at time 0 and the value 1 at time dur. The change from 0 to 1 will depend on the easing chosen but basically you get assigned to your selected attribute to-from*0 to-from*0.1 to-from*.0.2 ... to-from*0.9 to-from*1.

All that to say that tweening relies on continuous values, not discrete values. What would the intermediary values between walk and run? run-walk*.0.2? walk-a-bit-faster? run-slowly? If your tweening system can't interpolate the values to go from from to to then your animation (at least as of the tweening system used in current 0.3) won't work.

What you could do instead is add an addEventListener() on your model, start the run animation if it's not already running, wait the desired time, stop it and start the walk animation again.