Java 类com.badlogic.gdx.graphics.g3d.model.data.ModelAnimation 实例源码

项目:libgdxcn    文件:Model.java   
private void loadAnimations (Iterable<ModelAnimation> modelAnimations) {
    for (final ModelAnimation anim : modelAnimations) {
        Animation animation = new Animation();
        animation.id = anim.id;
        for (ModelNodeAnimation nanim : anim.nodeAnimations) {
            final Node node = getNode(nanim.nodeId);
            if (node == null) continue;
            NodeAnimation nodeAnim = new NodeAnimation();
            nodeAnim.node = node;
            for (ModelNodeKeyframe kf : nanim.keyframes) {
                if (kf.keytime > animation.duration) animation.duration = kf.keytime;
                NodeKeyframe keyframe = new NodeKeyframe();
                keyframe.keytime = kf.keytime;
                keyframe.rotation.set(kf.rotation == null ? node.rotation : kf.rotation);
                keyframe.scale.set(kf.scale == null ? node.scale : kf.scale);
                keyframe.translation.set(kf.translation == null ? node.translation : kf.translation);
                nodeAnim.keyframes.add(keyframe);
            }
            if (nodeAnim.keyframes.size > 0) animation.nodeAnimations.add(nodeAnim);
        }
        if (animation.nodeAnimations.size > 0) animations.add(animation);
    }
}
项目:gdx-proto    文件:HeadlessModel.java   
private void loadAnimations (Iterable<ModelAnimation> modelAnimations) {
    for (final ModelAnimation anim : modelAnimations) {
        Animation animation = new Animation();
        animation.id = anim.id;
        for (ModelNodeAnimation nanim : anim.nodeAnimations) {
            final Node node = getNode(nanim.nodeId);
            if (node == null) continue;
            NodeAnimation nodeAnim = new NodeAnimation();
            nodeAnim.node = node;
            for (ModelNodeKeyframe kf : nanim.keyframes) {
                if (kf.keytime > animation.duration) animation.duration = kf.keytime;
                NodeKeyframe keyframe = new NodeKeyframe();
                keyframe.keytime = kf.keytime;
                keyframe.rotation.set(kf.rotation == null ? node.rotation : kf.rotation);
                keyframe.scale.set(kf.scale == null ? node.scale : kf.scale);
                keyframe.translation.set(kf.translation == null ? node.translation : kf.translation);
                nodeAnim.keyframes.add(keyframe);
            }
            if (nodeAnim.keyframes.size > 0) animation.nodeAnimations.add(nodeAnim);
        }
        if (animation.nodeAnimations.size > 0) animations.add(animation);
    }
}
项目:libgdxcn    文件:G3dModelLoader.java   
private void parseAnimations (ModelData model, JsonValue json) {
    JsonValue animations = json.get("animations");
    if (animations == null) return;

    model.animations.ensureCapacity(animations.size);

    for (JsonValue anim = animations.child; anim != null; anim = anim.next) {
        JsonValue nodes = anim.get("bones");
        if (nodes == null) continue;
        ModelAnimation animation = new ModelAnimation();
        model.animations.add(animation);
        animation.nodeAnimations.ensureCapacity(nodes.size);
        animation.id = anim.getString("id");
        for (JsonValue node = nodes.child; node != null; node = node.next) {
            JsonValue keyframes = node.get("keyframes");

            ModelNodeAnimation nodeAnim = new ModelNodeAnimation();
            animation.nodeAnimations.add(nodeAnim);
            nodeAnim.nodeId = node.getString("boneId");
            nodeAnim.keyframes.ensureCapacity(keyframes.size);

            for (JsonValue keyframe = keyframes.child; keyframe != null; keyframe = keyframe.next) {
                ModelNodeKeyframe kf = new ModelNodeKeyframe();
                nodeAnim.keyframes.add(kf);
                kf.keytime = keyframe.getFloat("keytime") / 1000.f;
                JsonValue translation = keyframe.get("translation");
                if (translation != null && translation.size == 3)
                    kf.translation = new Vector3(translation.getFloat(0), translation.getFloat(1), translation.getFloat(2));
                JsonValue rotation = keyframe.get("rotation");
                if (rotation != null && rotation.size == 4)
                    kf.rotation = new Quaternion(rotation.getFloat(0), rotation.getFloat(1), rotation.getFloat(2),
                        rotation.getFloat(3));
                JsonValue scale = keyframe.get("scale");
                if (scale != null && scale.size == 3)
                    kf.scale = new Vector3(scale.getFloat(0), scale.getFloat(1), scale.getFloat(2));
            }
        }
    }
}
项目:gdx-proto    文件:HeadlessG3dModelLoader.java   
private void parseAnimations (ModelData model, JsonValue json) {
    JsonValue animations = json.get("animations");
    if (animations == null) return;

    model.animations.ensureCapacity(animations.size);

    for (JsonValue anim = animations.child; anim != null; anim = anim.next) {
        JsonValue nodes = anim.get("bones");
        if (nodes == null) continue;
        ModelAnimation animation = new ModelAnimation();
        model.animations.add(animation);
        animation.nodeAnimations.ensureCapacity(nodes.size);
        animation.id = anim.getString("id");
        for (JsonValue node = nodes.child; node != null; node = node.next) {
            JsonValue keyframes = node.get("keyframes");

            ModelNodeAnimation nodeAnim = new ModelNodeAnimation();
            animation.nodeAnimations.add(nodeAnim);
            nodeAnim.nodeId = node.getString("boneId");
            nodeAnim.keyframes.ensureCapacity(keyframes.size);

            for (JsonValue keyframe = keyframes.child; keyframe != null; keyframe = keyframe.next) {
                ModelNodeKeyframe kf = new ModelNodeKeyframe();
                nodeAnim.keyframes.add(kf);
                kf.keytime = keyframe.getFloat("keytime") / 1000.f;
                JsonValue translation = keyframe.get("translation");
                if (translation != null && translation.size == 3)
                    kf.translation = new Vector3(translation.getFloat(0), translation.getFloat(1), translation.getFloat(2));
                JsonValue rotation = keyframe.get("rotation");
                if (rotation != null && rotation.size == 4)
                    kf.rotation = new Quaternion(rotation.getFloat(0), rotation.getFloat(1), rotation.getFloat(2),
                            rotation.getFloat(3));
                JsonValue scale = keyframe.get("scale");
                if (scale != null && scale.size == 3)
                    kf.scale = new Vector3(scale.getFloat(0), scale.getFloat(1), scale.getFloat(2));
            }
        }
    }
}