elementTransforms.add(child);
}
}
final List<TransformElement> transformList = getNodeTransformList(elementTransforms);
AnimationItem animationItemRoot = null;
for (final TargetChannel targetChannel : targetList) {
if (animationItemRoot == null) {
animationItemRoot = targetChannel.animationItemRoot;
}
final String source = targetChannel.source;
// final Target target = targetChannel.target;
final Element targetNode = targetChannel.targetNode;
final int targetIndex = elementTransforms.indexOf(targetNode);
if (logger.isLoggable(Level.FINE)) {
logger.fine(parentElement.getName() + "(" + parentElement.getAttributeValue("name") + ") -> "
+ targetNode.getName() + "(" + targetIndex + ")");
}
final EnumMap<Type, ColladaInputPipe> pipes = Maps.newEnumMap(Type.class);
final Element samplerElement = _colladaDOMUtil.findTargetWithId(source);
for (final Element inputElement : samplerElement.getChildren("input")) {
final ColladaInputPipe pipe = new ColladaInputPipe(_colladaDOMUtil, inputElement);
pipes.put(pipe.getType(), pipe);
}
// get input (which is TIME for now)
final ColladaInputPipe inputPipe = pipes.get(Type.INPUT);
final ColladaInputPipe.SourceData sdIn = inputPipe.getSourceData();
final float[] time = sdIn.floatArray;
targetChannel.time = time;
if (logger.isLoggable(Level.FINE)) {
logger.fine("inputPipe: " + Arrays.toString(time));
}
// get output data
final ColladaInputPipe outputPipe = pipes.get(Type.OUTPUT);
final ColladaInputPipe.SourceData sdOut = outputPipe.getSourceData();
final float[] animationData = sdOut.floatArray;
targetChannel.animationData = animationData;
if (logger.isLoggable(Level.FINE)) {
logger.fine("outputPipe: " + Arrays.toString(animationData));
}
// TODO: Need to add support for other interpolation types.
// get target array from transform list
final TransformElement transformElement = transformList.get(targetIndex);
final double[] array = transformElement.getArray();
targetChannel.array = array;
final int stride = sdOut.stride;
targetChannel.stride = stride;
targetChannel.currentPos = 0;
}
final List<Float> finalTimeList = Lists.newArrayList();
final List<Transform> finalTransformList = Lists.newArrayList();
final List<TargetChannel> workingChannels = Lists.newArrayList();
for (;;) {
float lowestTime = Float.MAX_VALUE;
boolean found = false;
for (final TargetChannel targetChannel : targetList) {
if (targetChannel.currentPos < targetChannel.time.length) {
final float time = targetChannel.time[targetChannel.currentPos];
if (time < lowestTime) {
lowestTime = time;
}
found = true;
}
}
if (!found) {
break;
}
workingChannels.clear();
for (final TargetChannel targetChannel : targetList) {
if (targetChannel.currentPos < targetChannel.time.length) {
final float time = targetChannel.time[targetChannel.currentPos];
if (time == lowestTime) {
workingChannels.add(targetChannel);
}
}
}
for (final TargetChannel targetChannel : workingChannels) {
final Target target = targetChannel.target;
final float[] animationData = targetChannel.animationData;
final double[] array = targetChannel.array;
// set the correct values depending on accessor
final int position = targetChannel.currentPos * targetChannel.stride;
if (target.accessorType == AccessorType.None) {
for (int j = 0; j < array.length; j++) {
array[j] = animationData[position + j];
}
} else {
if (target.accessorType == AccessorType.Vector) {
array[target.accessorIndexX] = animationData[position];
} else if (target.accessorType == AccessorType.Matrix) {
array[target.accessorIndexY * 4 + target.accessorIndexX] = animationData[position];
}
}
targetChannel.currentPos++;
}
// bake the transform
final Transform transform = bakeTransforms(transformList);
finalTimeList.add(lowestTime);
finalTransformList.add(transform);
}
final float[] time = new float[finalTimeList.size()];
for (int i = 0; i < finalTimeList.size(); i++) {
time[i] = finalTimeList.get(i);
}
final Transform[] transforms = finalTransformList.toArray(new Transform[finalTransformList.size()]);
AnimationClip animationClip = animationItemRoot.getAnimationClip();
if (animationClip == null) {
animationClip = new AnimationClip(animationItemRoot.getName());
animationItemRoot.setAnimationClip(animationClip);
}
// Make an animation channel - first find if we have a matching joint
Joint joint = _dataCache.getElementJointMapping().get(parentElement);
if (joint == null) {