11/*
2- * Copyright (c) 2009-2021 jMonkeyEngine
2+ * Copyright (c) 2009-2023 jMonkeyEngine
33 * All rights reserved.
44 *
55 * Redistribution and use in source and binary forms, with or without
3838 * Created by nehon on 15/04/17.
3939 */
4040public class FrameInterpolator {
41+ /**
42+ * A global default instance of this class, for compatibility with JME v3.5.
43+ * Due to issue #1806, use of this instance is discouraged.
44+ *
45+ * @deprecated use {@link #getThreadDefault()}
46+ */
47+ @ Deprecated
4148 public static final FrameInterpolator DEFAULT = new FrameInterpolator ();
49+ /**
50+ * The per-thread default instances of this class.
51+ */
52+ private static final ThreadLocal <FrameInterpolator > THREAD_DEFAULT
53+ = ThreadLocal .withInitial (() -> new FrameInterpolator ());
4254
4355 private AnimInterpolator <Float > timeInterpolator ;
4456 private AnimInterpolator <Vector3f > translationInterpolator = AnimInterpolators .LinearVec3f ;
@@ -52,6 +64,16 @@ public class FrameInterpolator {
5264
5365 final private Transform transforms = new Transform ();
5466
67+ /**
68+ * Obtain the default interpolator for the current thread.
69+ *
70+ * @return the pre-existing instance (not null)
71+ */
72+ public static FrameInterpolator getThreadDefault () {
73+ FrameInterpolator result = THREAD_DEFAULT .get ();
74+ return result ;
75+ }
76+
5577 public Transform interpolate (float t , int currentIndex , CompactVector3Array translations ,
5678 CompactQuaternionArray rotations , CompactVector3Array scales , float [] times ) {
5779 timesReader .setData (times );
0 commit comments