/** * The method applies bone's current position to all of the traces of the given animations. * * @param boneContext the bone context * @param space the bone's evaluation space * @param referenceAnimData the object containing the animations */ protected void applyAnimData(BoneContext boneContext, Space space, AnimData referenceAnimData) { ConstraintHelper constraintHelper = blenderContext.getHelper(ConstraintHelper.class); Transform transform = constraintHelper.getBoneTransform(space, boneContext.getBone()); AnimData animData = blenderContext.getAnimData(boneContext.getBoneOma()); for (Animation animation : referenceAnimData.anims) { BoneTrack parentTrack = (BoneTrack) animation.getTracks()[0]; float[] times = parentTrack.getTimes(); Vector3f[] translations = new Vector3f[times.length]; Quaternion[] rotations = new Quaternion[times.length]; Vector3f[] scales = new Vector3f[times.length]; Arrays.fill(translations, transform.getTranslation()); Arrays.fill(rotations, transform.getRotation()); Arrays.fill(scales, transform.getScale()); for (Animation anim : animData.anims) { anim.addTrack( new BoneTrack( animData.skeleton.getBoneIndex(boneContext.getBone()), times, translations, rotations, scales)); } } blenderContext.setAnimData(boneContext.getBoneOma(), animData); }
public void bake( Transform ownerTransform, Transform targetTransform, Track ownerTrack, Track targetTrack, Ipo influenceIpo) { TrackWrapper ownerWrapperTrack = ownerTrack != null ? new TrackWrapper(ownerTrack) : null; TrackWrapper targetWrapperTrack = targetTrack != null ? new TrackWrapper(targetTrack) : null; // uruchamiamy bake dla transformat zalenie od tego, ktre argumenty s nullami, a ktre - nie this.bake(ownerTransform, targetTransform, influenceIpo.calculateValue(0)); if (ownerWrapperTrack != null) { float[] ownerTimes = ownerWrapperTrack.getTimes(); Vector3f[] translations = ownerWrapperTrack.getTranslations(); Quaternion[] rotations = ownerWrapperTrack.getRotations(); Vector3f[] scales = ownerWrapperTrack.getScales(); float[] targetTimes = targetWrapperTrack == null ? null : targetWrapperTrack.getTimes(); Vector3f[] targetTranslations = targetWrapperTrack == null ? null : targetWrapperTrack.getTranslations(); Quaternion[] targetRotations = targetWrapperTrack == null ? null : targetWrapperTrack.getRotations(); Vector3f[] targetScales = targetWrapperTrack == null ? null : targetWrapperTrack.getScales(); Vector3f translation = new Vector3f(), scale = new Vector3f(); Quaternion rotation = new Quaternion(); Transform ownerTemp = new Transform(), targetTemp = new Transform(); for (int i = 0; i < ownerTimes.length; ++i) { float t = ownerTimes[i]; ownerTemp.setTranslation(translations[i]); ownerTemp.setRotation(rotations[i]); ownerTemp.setScale(scales[i]); if (targetWrapperTrack == null) { this.bake(ownerTemp, targetTransform, influenceIpo.calculateValue(i)); } else { // getting the values that are the interpolation of the target track for the time 't' this.interpolate(targetTranslations, targetTimes, t, translation); this.interpolate(targetRotations, targetTimes, t, rotation); this.interpolate(targetScales, targetTimes, t, scale); targetTemp.setTranslation(translation); targetTemp.setRotation(rotation); targetTemp.setScale(scale); this.bake(ownerTemp, targetTemp, influenceIpo.calculateValue(i)); } // need to clone here because each of the arrays will reference the same instance if they // hold the same value in the compact array translations[i] = ownerTemp.getTranslation().clone(); rotations[i] = ownerTemp.getRotation().clone(); scales[i] = ownerTemp.getScale().clone(); } ownerWrapperTrack.setKeyframes(ownerTimes, translations, rotations, scales); } }
/** This method computes the pose transform for the bone. */ @SuppressWarnings("unchecked") private void computePoseTransform() { DynamicArray<Number> loc = (DynamicArray<Number>) poseChannel.getFieldValue("loc"); DynamicArray<Number> size = (DynamicArray<Number>) poseChannel.getFieldValue("size"); DynamicArray<Number> quat = (DynamicArray<Number>) poseChannel.getFieldValue("quat"); if (fixUpAxis) { poseTransform.setTranslation( loc.get(0).floatValue(), -loc.get(2).floatValue(), loc.get(1).floatValue()); poseTransform.setRotation( new Quaternion( quat.get(1).floatValue(), quat.get(3).floatValue(), -quat.get(2).floatValue(), quat.get(0).floatValue())); poseTransform.setScale( size.get(0).floatValue(), size.get(2).floatValue(), size.get(1).floatValue()); } else { poseTransform.setTranslation( loc.get(0).floatValue(), loc.get(1).floatValue(), loc.get(2).floatValue()); poseTransform.setRotation( new Quaternion( quat.get(0).floatValue(), quat.get(1).floatValue(), quat.get(2).floatValue(), quat.get(3).floatValue())); poseTransform.setScale( size.get(0).floatValue(), size.get(1).floatValue(), size.get(2).floatValue()); } Transform localTransform = new Transform(bone.getLocalPosition(), bone.getLocalRotation()); localTransform.setScale(bone.getLocalScale()); localTransform.getTranslation().addLocal(poseTransform.getTranslation()); localTransform.getRotation().multLocal(poseTransform.getRotation()); localTransform.getScale().multLocal(poseTransform.getScale()); poseTransform.set(localTransform); }
@AttributeName("scal") private Vector3f saveScale() { Transform transform = spatial.getLocalTransform(); return transform.getScale(); }
/** * <code>getLocalScale</code> retrieves the local scale of this node. * * @return the local scale of this node. */ public Vector3f getLocalScale() { return localTransform.getScale(); }
/** * <code>getWorldScale</code> retrieves the absolute scale factor of the spatial. * * @return the Spatial's world scale factor. */ public Vector3f getWorldScale() { checkDoTransformUpdate(); return worldTransform.getScale(); }