/** * Computes the maximum frame and time for the animation. Different tracks * can have different lengths so here the maximum one is being found. * * @param animation * the animation * @return maximum frame and time of the animation */ private float[] computeAnimationTimeBoundaries(Animation animation) { int maxFrame = Integer.MIN_VALUE; float maxTime = -Float.MAX_VALUE; for (Track track : animation.getTracks()) { if (track instanceof BoneTrack) { maxFrame = Math.max(maxFrame, ((BoneTrack) track).getTranslations().length); maxTime = Math.max(maxTime, ((BoneTrack) track).getTimes()[((BoneTrack) track).getTimes().length - 1]); } else if (track instanceof SpatialTrack) { maxFrame = Math.max(maxFrame, ((SpatialTrack) track).getTranslations().length); maxTime = Math.max(maxTime, ((SpatialTrack) track).getTimes()[((SpatialTrack) track).getTimes().length - 1]); } else { throw new IllegalStateException("Unsupported track type for simuation: " + track); } } return new float[] { maxFrame, maxTime }; }
for (Track track : animation.getTracks()) { for (int frame = 0; frame < maxFrame; ++frame) { spatial.setLocalTranslation(((SpatialTrack) track).getTranslations()[frame]); spatial.setLocalRotation(((SpatialTrack) track).getRotations()[frame]); spatial.setLocalScale(((SpatialTrack) track).getScales()[frame]);
/** * This method creates a clone of the current object. * @return a clone of the current object */ @Override public SpatialTrack clone() { int tablesLength = times.length; float[] timesCopy = this.times.clone(); Vector3f[] translationsCopy = this.getTranslations() == null ? null : Arrays.copyOf(this.getTranslations(), tablesLength); Quaternion[] rotationsCopy = this.getRotations() == null ? null : Arrays.copyOf(this.getRotations(), tablesLength); Vector3f[] scalesCopy = this.getScales() == null ? null : Arrays.copyOf(this.getScales(), tablesLength); //need to use the constructor here because of the final fields used in this class return new SpatialTrack(timesCopy, translationsCopy, rotationsCopy, scalesCopy); }