public void TestForwardCurveWithoutCache(float timeStep, int keyframeCount) { var animCurve = new UnityEngine.AnimationCurve(); for (var i = 0; i < keyframeCount; ++i) { animCurve.AddKey(new UnityEngine.Keyframe(i, i * timeStep, Mathf.Infinity, Mathf.Infinity)); } var curveBlob = animCurve.ToAnimationCurveBlobAssetRef(); Measure.Method(() => { // The longer the time step, the more the cache gets reused. for (var t = 0.0f; t <= keyframeCount * timeStep; t += 0.1f) { AnimationCurveEvaluator.Evaluate(t, curveBlob); } }) .WarmupCount(1) .MeasurementCount(100) .Run(); curveBlob.Dispose(); }
protected override JobHandle OnUpdate(JobHandle inputDeps) { var time = Mathf.Repeat((float)Time.ElapsedTime, 1.0F); return(Entities.ForEach((ref Translation position, in AnimateTranslation translation) => { float value = AnimationCurveEvaluator.Evaluate(time, translation.TranslationCurve); position.Value.y = value; }).Schedule(inputDeps)); }
protected override void OnUpdate() { var time = Mathf.Repeat((float)Time.ElapsedTime, 1.0F); Dependency = Entities.ForEach((ref Translation position, in AnimateTranslation translation) => { float value = AnimationCurveEvaluator.Evaluate(time, translation.TranslationCurve); position.Value.y = value; }).Schedule(Dependency); }
public void TestLinearCurve500Precision(float time) { var animCurve = new UnityEngine.AnimationCurve(); animCurve.AddKey(0f, 0f); animCurve.AddKey(500f, 1f); var keyframeCurve = animCurve.ToAnimationCurveBlobAssetRef(); var eval = AnimationCurveEvaluator.Evaluate(time, keyframeCurve); var expected = time / 500f; Assert.IsTrue(NearlyEqual(expected, eval, kTolerance), $"Expected {expected:n6} but was {eval:n6}."); keyframeCurve.Dispose(); }
protected override void OnUpdate() { var ecb = _ecbSystem.CreateCommandBuffer(); //Create an animation graph if the component isn't created and attached to the entity. Entities .WithName("CreateGraph") .WithNone <RotateCube_PlayStateRuntime>() .WithoutBurst() .WithStructuralChanges() .ForEach((Entity e, ref RotateCube_PlayClipRuntime animation, ref Rig rig) => { var data = CreateGraph(e, ref rig, ref animation); ecb.AddComponent(e, data); }).Run(); //Update the graph if the clip component changed Entities .WithName("UpdateGraph") .WithChangeFilter <RotateCube_PlayClipRuntime>() .WithoutBurst() .ForEach( (Entity e, ref RotateCube_PlayClipRuntime animation, ref RotateCube_PlayStateRuntime animationState) => _animationGraphSystem.Set.SendMessage(animationState.NodeHandle, ClipPlayerNode.SimulationPorts.Clip, animation.clip)).Run(); var pingPongTime = math.sin((float)World.Unmanaged.CurrentTime.ElapsedTime) * .5f + .5f; Entities .WithName("ChangeSpeed") .WithoutBurst() .ForEach((Entity entity, ref RotateCube_PlayStateRuntime animationState, in RotateCube_PlayClipRuntime animation) => { var value = AnimationCurveEvaluator.Evaluate(pingPongTime, animation.curve); _animationGraphSystem.Set.SetData(animationState.NodeHandle, ClipPlayerNode.KernelPorts.Speed, value); }).Run(); }