Package com.ardor3d.extension.model.collada.jdom.data

Examples of com.ardor3d.extension.model.collada.jdom.data.AnimationItem


                logger.warning("No animations found in collada file!");
            }
            return;
        }

        final AnimationItem animationItemRoot = new AnimationItem("Animation Root");
        _colladaStorage.setAnimationItemRoot(animationItemRoot);

        final Multimap<Element, TargetChannel> channelMap = ArrayListMultimap.create();

        parseAnimations(channelMap, libraryAnimations, animationItemRoot);
View Full Code Here


                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) {
View Full Code Here

            if (nameAttribute == null) {
                nameAttribute = animationRoot.getAttribute("id");
            }
            final String name = nameAttribute != null ? nameAttribute.getValue() : "Default";

            final AnimationItem animationItem = new AnimationItem(name);
            animationItemRoot.getChildren().add(animationItem);

            for (final Element animationElement : animationRoot.getChildren("animation")) {
                parseAnimations(channelMap, animationElement, animationItem);
            }
View Full Code Here

TOP

Related Classes of com.ardor3d.extension.model.collada.jdom.data.AnimationItem

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.