/** * Returns the track as a bone track. * * @param targetBoneIndex * the bone index * @return the bone track */ public BoneTrack getAsBoneTrack(int targetBoneIndex) { if (translations == null && rotations == null && scales == null) { return null; } return new BoneTrack(targetBoneIndex, this.createTimes(), translations.toArray(new Vector3f[maxFrame]), rotations.toArray(new Quaternion[maxFrame]), scales.toArray(new Vector3f[maxFrame])); }
/** * Creates a bone track for the given bone index * @param targetBoneIndex the bone index * @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 */ public BoneTrack(int targetBoneIndex, float[] times, Vector3f[] translations, Quaternion[] rotations) { this.targetBoneIndex = targetBoneIndex; this.setKeyframes(times, translations, rotations); }
public static TransformTrack fromBoneTrack(BoneTrack boneTrack, Bone bone, Joint joint) { float[] times = new float[boneTrack.getTimes().length]; int length = times.length; System.arraycopy(boneTrack.getTimes(), 0, times, 0, length); if (boneTrack.getTranslations() != null) { for (int i = 0; i < boneTrack.getTranslations().length; i++) { Vector3f oldTrans = boneTrack.getTranslations()[i]; Vector3f newTrans = new Vector3f(); newTrans.set(bone.getBindPosition()).addLocal(oldTrans); if (boneTrack.getRotations() != null) { for (int i = 0; i < boneTrack.getRotations().length; i++) { Quaternion oldRot = boneTrack.getRotations()[i]; Quaternion newRot = new Quaternion(); newRot.set(bone.getBindRotation()).multLocal(oldRot); if (boneTrack.getScales() != null) { for (int i = 0; i < boneTrack.getScales().length; i++) { Vector3f oldScale = boneTrack.getScales()[i]; Vector3f newScale = new Vector3f(); newScale.set(bone.getBindScale()).multLocal(oldScale);
/** * 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 BoneTrack clone() { int tablesLength = times.length; float[] times = this.times.clone(); Vector3f[] sourceTranslations = this.getTranslations(); Quaternion[] sourceRotations = this.getRotations(); Vector3f[] sourceScales = this.getScales(); Vector3f[] translations = new Vector3f[tablesLength]; Quaternion[] rotations = new Quaternion[tablesLength]; Vector3f[] scales = new Vector3f[tablesLength]; for (int i = 0; i < tablesLength; ++i) { translations[i] = sourceTranslations[i].clone(); rotations[i] = sourceRotations[i].clone(); scales[i] = sourceScales != null ? sourceScales[i].clone() : new Vector3f(1.0f, 1.0f, 1.0f); } // Need to use the constructor here because of the final fields used in this class return new BoneTrack(targetBoneIndex, times, translations, rotations, scales); }
float time = ((BoneTrack) track).getTimes()[frame]; track.setTime(time, 1, animControl, animChannel, vars); skeleton.updateWorldVectors(); boolean trackReplaced = false; for (Track track : animation.getTracks()) { if (((BoneTrack) track).getTargetBoneIndex() == trackEntry.getKey().intValue()) { animation.removeTrack(track); animation.addTrack(newTrack);
if (track instanceof BoneTrack) { BoneTrack boneTrack = (BoneTrack) track; int index = boneTrack.getTargetBoneIndex(); Bone bone = skeleton.getBone(index); Joint joint = joints[index];
/** * Creates a bone track for the given bone index * @param targetBoneIndex the bone index * @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 BoneTrack(int targetBoneIndex, float[] times, Vector3f[] translations, Quaternion[] rotations, Vector3f[] scales) { this.targetBoneIndex = targetBoneIndex; this.setKeyframes(times, translations, rotations, scales); }
/** * Set the translations, rotations and scales for this bone track * * @param times the time of each frame, measured from the start of the track * (not null, length>0) * @param translations the translation of the bone for each frame (not null, * same length as times) * @param rotations the rotation of the bone for each frame (not null, same * length as times) * @param scales the scale of the bone for each frame (ignored if null) */ public void setKeyframes(float[] times, Vector3f[] translations, Quaternion[] rotations, Vector3f[] scales) { this.setKeyframes(times, translations, rotations); if (scales != null) { assert times.length == scales.length; this.scales = new CompactVector3Array(); this.scales.add(scales); this.scales.freeze(); } }
calculatedTrack = new SpatialTrack(times, translations, rotations, scales); } else { calculatedTrack = new BoneTrack(targetIndex, times, translations, rotations, scales);
/** * Creates a bone track for the given bone index * @param targetBoneIndex the bone index * @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 */ public BoneTrack(int targetBoneIndex, float[] times, Vector3f[] translations, Quaternion[] rotations) { this.targetBoneIndex = targetBoneIndex; this.setKeyframes(times, translations, rotations); }
Bone bone = nameToBone.get(boneName); int index = skeleton.getBoneIndex(bone); track = new BoneTrack(index); } else if (qName.equals("boneparent")) { assert elementStack.peek().equals("bonehierarchy");
/** * Creates a bone track for the given bone index * @param targetBoneIndex the bone index * @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 BoneTrack(int targetBoneIndex, float[] times, Vector3f[] translations, Quaternion[] rotations, Vector3f[] scales) { this.targetBoneIndex = targetBoneIndex; this.setKeyframes(times, translations, rotations, scales); }
Bone bone = nameToBone.get(boneName); int index = skeleton.getBoneIndex(bone); track = new BoneTrack(index); } else if (qName.equals("boneparent")) { assert elementStack.peek().equals("bonehierarchy");
/** * Creates a bone track for the given bone index * @param targetBoneIndex the bone index * @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 */ public BoneTrack(int targetBoneIndex, float[] times, Vector3f[] translations, Quaternion[] rotations) { this.targetBoneIndex = targetBoneIndex; this.setKeyframes(times, translations, rotations); }
Bone bone = nameToBone.get(boneName); int index = skeleton.getBoneIndex(bone); track = new BoneTrack(index); } else if (qName.equals("boneparent")) { assert elementStack.peek().equals("bonehierarchy");
/** * Creates a bone track for the given bone index * @param targetBoneIndex the bone index * @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 BoneTrack(int targetBoneIndex, float[] times, Vector3f[] translations, Quaternion[] rotations, Vector3f[] scales) { this.targetBoneIndex = targetBoneIndex; this.setKeyframes(times, translations, rotations, scales); }