/** Should only be called from updateGeometricState(). In most cases should not be subclassed. */ protected void updateWorldTransforms() { if (parent == null) { worldTransform.set(localTransform); refreshFlags &= ~RF_TRANSFORM; } else { // check if transform for parent is updated assert ((parent.refreshFlags & RF_TRANSFORM) == 0); worldTransform.set(localTransform); worldTransform.combineWithParent(parent.worldTransform); refreshFlags &= ~RF_TRANSFORM; } }
/** Computes the world transform of this Spatial in the most efficient manner possible. */ void checkDoTransformUpdate() { if ((refreshFlags & RF_TRANSFORM) == 0) { return; } if (parent == null) { worldTransform.set(localTransform); refreshFlags &= ~RF_TRANSFORM; } else { TempVars vars = TempVars.get(); Spatial[] stack = vars.spatialStack; Spatial rootNode = this; int i = 0; while (true) { Spatial hisParent = rootNode.parent; if (hisParent == null) { rootNode.worldTransform.set(rootNode.localTransform); rootNode.refreshFlags &= ~RF_TRANSFORM; i--; break; } stack[i] = rootNode; if ((hisParent.refreshFlags & RF_TRANSFORM) == 0) { break; } rootNode = hisParent; i++; } vars.release(); for (int j = i; j >= 0; j--) { rootNode = stack[j]; // rootNode.worldTransform.set(rootNode.localTransform); // rootNode.worldTransform.combineWithParent(rootNode.parent.worldTransform); // rootNode.refreshFlags &= ~RF_TRANSFORM; rootNode.updateWorldTransforms(); } } }
/** 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); }