/** * <code>rotateUpTo</code> is a utility function that alters the local rotation to point the Y * axis in the direction given by newUp. * * @param newUp the up vector to use - assumed to be a unit vector. */ public void rotateUpTo(Vector3f newUp) { TempVars vars = TempVars.get(); Vector3f compVecA = vars.vect1; Quaternion q = vars.quat1; // First figure out the current up vector. Vector3f upY = compVecA.set(Vector3f.UNIT_Y); Quaternion rot = localTransform.getRotation(); rot.multLocal(upY); // get angle between vectors float angle = upY.angleBetween(newUp); // figure out rotation axis by taking cross product Vector3f rotAxis = upY.crossLocal(newUp).normalizeLocal(); // Build a rotation quat and apply current local rotation. q.fromAngleNormalAxis(angle, rotAxis); q.mult(rot, rot); vars.release(); setTransformRefresh(); }
/** * 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("rot") private Quaternion saveRotation() { Transform transform = spatial.getLocalTransform(); return transform.getRotation(); }
/** * <code>setLocalRotation</code> sets the local rotation of this node by using a {@link Matrix3f}. * * @param rotation the new local rotation. */ public void setLocalRotation(Matrix3f rotation) { localTransform.getRotation().fromRotationMatrix(rotation); setTransformRefresh(); }
/** * <code>getLocalRotation</code> retrieves the local rotation of this node. * * @return the local rotation of this node. */ public Quaternion getLocalRotation() { return localTransform.getRotation(); }
/** * <code>getWorldRotation</code> retrieves the absolute rotation of the Spatial. * * @return the Spatial's world rotation quaternion. */ public Quaternion getWorldRotation() { checkDoTransformUpdate(); return worldTransform.getRotation(); }