/** * Returns the track as a spatial track. * * @return the spatial track */ public SpatialTrack getAsSpatialTrack() { if (translations == null && rotations == null && scales == null) { return null; } return new SpatialTrack(this.createTimes(), translations.toArray(new Vector3f[maxFrame]), rotations.toArray(new Quaternion[maxFrame]), scales.toArray(new Vector3f[maxFrame])); }
/** * Creates a spatial track for the given track data. * * @param times * a float array with the time of each frame * @param translations * the translation of the bone for each frame * @param rotations * the rotation of the bone for each frame * @param scales * the scale of the bone for each frame */ public SpatialTrack(float[] times, Vector3f[] translations, Quaternion[] rotations, Vector3f[] scales) { setKeyframes(times, translations, rotations, scales); }
/** * 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 }; }
/** * 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); }
Spatial s = (Spatial) node; spatials.add(s); SpatialTrack track = new SpatialTrack(trackData.times, trackData.translations, trackData.rotations, trackData.scales); track.setTrackSpatial(s); anim.addTrack(track); } else if (node instanceof BoneWrapper) {
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]);
/** * Creates an Animation based on the keyFrames previously added to the helper. * @return the generated animation */ public Animation buildAnimation() { interpolateTime(); interpolate(keyFramesTranslation, Type.Translation); interpolate(keyFramesRotation, Type.Rotation); interpolate(keyFramesScale, Type.Scale); SpatialTrack spatialTrack = new SpatialTrack(times, translations, rotations, scales); //creating the animation Animation spatialAnimation = new Animation(name, duration); spatialAnimation.setTracks(new SpatialTrack[]{spatialTrack}); return spatialAnimation; }
/** * Creates a spatial track for the given track data. * * @param times * a float array with the time of each frame * @param translations * the translation of the bone for each frame * @param rotations * the rotation of the bone for each frame * @param scales * the scale of the bone for each frame */ public SpatialTrack(float[] times, Vector3f[] translations, Quaternion[] rotations, Vector3f[] scales) { setKeyframes(times, translations, rotations, scales); }
return new SpatialTrack(times, translations, rotations, scales); } else { if (scales != null) {
/** * Creates a spatial track for the given track data. * * @param times * a float array with the time of each frame * @param translations * the translation of the bone for each frame * @param rotations * the rotation of the bone for each frame * @param scales * the scale of the bone for each frame */ public SpatialTrack(float[] times, Vector3f[] translations, Quaternion[] rotations, Vector3f[] scales) { setKeyframes(times, translations, rotations, scales); }
calculatedTrack = new SpatialTrack(times, translations, rotations, scales); } else { calculatedTrack = new BoneTrack(targetIndex, times, translations, rotations, scales);
scales[i] = Vector3f.UNIT_XYZ; SpatialTrack spatialTrack = new SpatialTrack(times, translations, rotations, scales);
/** * Creates an Animation based on the keyFrames previously added to the helper. * @return the generated animation */ public Animation buildAnimation() { interpolateTime(); interpolate(keyFramesTranslation, Type.Translation); interpolate(keyFramesRotation, Type.Rotation); interpolate(keyFramesScale, Type.Scale); SpatialTrack spatialTrack = new SpatialTrack(times, translations, rotations, scales); //creating the animation Animation spatialAnimation = new Animation(name, duration); spatialAnimation.setTracks(new SpatialTrack[]{spatialTrack}); return spatialAnimation; }
/** * Creates an Animation based on the keyFrames previously added to the helper. * @return the generated animation */ public Animation buildAnimation() { interpolateTime(); interpolate(keyFramesTranslation, Type.Translation); interpolate(keyFramesRotation, Type.Rotation); interpolate(keyFramesScale, Type.Scale); SpatialTrack spatialTrack = new SpatialTrack(times, translations, rotations, scales); //creating the animation Animation spatialAnimation = new Animation(name, duration); spatialAnimation.setTracks(new SpatialTrack[]{spatialTrack}); return spatialAnimation; }
return new SpatialTrack(times, translations, rotations, scales); } else { if (scales != null) {