com.badlogic.gdx.graphics.g3d.model.Animation Java Examples

The following examples show how to use com.badlogic.gdx.graphics.g3d.model.Animation. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AnimationControllerHack.java    From gdx-gltf with Apache License 2.0 6 votes vote down vote up
/** Apply two animations, blending the second onto to first using weight. */
@Override
protected void applyAnimations (final Animation anim1, final float time1, final Animation anim2, final float time2,
	final float weight) {
	if (anim2 == null || weight == 0.f)
		applyAnimation(anim1, time1);
	else if (anim1 == null || weight == 1.f)
		applyAnimation(anim2, time2);
	else if (applying)
		throw new GdxRuntimeException("Call end() first");
	else {
		begin();
		apply(anim1, time1, 1.f);
		apply(anim2, time2, weight);
		end();
	}
}
 
Example #2
Source File: HeadlessModel.java    From gdx-proto with Apache License 2.0 6 votes vote down vote up
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);
	}
}
 
Example #3
Source File: GLTFDemoUI.java    From gdx-gltf with Apache License 2.0 5 votes vote down vote up
public void setAnimations(Array<Animation> animations) {
	if(animations.size > 0){
		Array<String> ids = new Array<String>();
		ids.add("");
		for(Animation anim : animations){
			ids.add(anim.id);
		}
		animationSelector.setItems(ids);
	}else{
		animationSelector.setItems();
	}
}
 
Example #4
Source File: GLTFInspector.java    From gdx-gltf with Apache License 2.0 5 votes vote down vote up
private void logAnimations(SceneAsset asset) {
	int t=0, r=0, s=0, w=0;
	for(Animation a : asset.animations){
		for(NodeAnimation na : a.nodeAnimations){
			t += na.translation == null ? 0 : na.translation.size;
			r += na.rotation == null ? 0 : na.rotation.size;
			s += na.scaling == null ? 0 : na.scaling.size;
			w += na instanceof NodeAnimationHack &&  ((NodeAnimationHack)na).weights == null ? 0 : ((NodeAnimationHack)na).weights.size;
		}
	}
	
	log("Animations", "count", asset.animations.size, "KeyFrames", t+r+s+w, "T", t, "R", r, "S", s, "W", w);
	
}
 
Example #5
Source File: AnimationControllerHack.java    From gdx-gltf with Apache License 2.0 5 votes vote down vote up
/** Apply a single animation to the {@link ModelInstance} and update the it to reflect the changes. */
@Override
protected void applyAnimation (final Animation animation, final float time) {
	if (applying) throw new GdxRuntimeException("Call end() first");
	applyAnimationPlus(null, (Pool<Transform>)null, 1.f, animation, time);
	if(calculateTransforms) target.calculateTransforms();
}
 
Example #6
Source File: AnimationLoader.java    From gdx-gltf with Apache License 2.0 5 votes vote down vote up
public void load(Array<GLTFAnimation> glAnimations, NodeResolver nodeResolver, DataResolver dataResolver) {
	
	if(glAnimations != null){
		for(int i=0 ; i<glAnimations.size ; i++){
			GLTFAnimation glAnimation = glAnimations.get(i);
			
			Animation animation = load(glAnimation, nodeResolver, dataResolver);
			animation.id = glAnimation.name == null ? "animation" + i : glAnimation.name;
			
			animations.add(animation);
		}
	}
}
 
Example #7
Source File: GLTFAnimationExporter.java    From gdx-gltf with Apache License 2.0 5 votes vote down vote up
private void export(Animation animation) {
	GLTFAnimation a = new GLTFAnimation();
	a.name = animation.id;
	if(base.root.animations == null) base.root.animations = new Array<GLTFAnimation>();
	base.root.animations.add(a);
	
	for(NodeAnimation nodeAnim : animation.nodeAnimations){
		int nodeID = base.nodeMapping.indexOf(nodeAnim.node, true);
		
		if(nodeAnim.translation != null){
			channelExporterVector3.export(base, a, nodeID, nodeAnim.translation, "translation", translationInterpolation(nodeAnim));
		}
		if(nodeAnim.rotation != null){
			channelExporterQuaternion.export(base, a, nodeID, nodeAnim.rotation, "rotation", rotationInterpolation(nodeAnim));
		}
		if(nodeAnim.scaling != null){
			channelExporterVector3.export(base, a, nodeID, nodeAnim.scaling, "scale", scaleInterpolation(nodeAnim));
		}
		if(nodeAnim instanceof NodeAnimationHack){
			NodeAnimationHack nodeAnimMorph = (NodeAnimationHack) nodeAnim;
			if(nodeAnimMorph.weights != null){
				int count = nodeAnimMorph.weights.first().value.count;
				channelExporterWeights(count).export(base, a, nodeID, nodeAnimMorph.weights, "weights", nodeAnimMorph.weightsMode);
			}
		}
	}
}
 
Example #8
Source File: Sprite3DRenderer.java    From bladecoder-adventure-engine with Apache License 2.0 5 votes vote down vote up
@Override
public String[] getInternalAnimations(AnimationDesc anim) {
	retrieveSource(anim.source);

	Array<Animation> animations = ((ModelCacheEntry) sourceCache.get(anim.source)).modelInstance.animations;
	String[] result = new String[animations.size];

	for (int i = 0; i < animations.size; i++) {
		Animation a = animations.get(i);
		result[i] = a.id;
	}

	return result;
}
 
Example #9
Source File: HeadlessModel.java    From gdx-proto with Apache License 2.0 5 votes vote down vote up
/** @param id The ID of the animation to fetch.
 * @param ignoreCase whether to use case sensitivity when comparing the animation id.
 * @return The {@link com.badlogic.gdx.graphics.g3d.model.Animation} with the specified id, or null if not available. */
public Animation getAnimation (final String id, boolean ignoreCase) {
	final int n = animations.size;
	Animation animation;
	if (ignoreCase) {
		for (int i = 0; i < n; i++)
			if ((animation = animations.get(i)).id.equalsIgnoreCase(id)) return animation;
	} else {
		for (int i = 0; i < n; i++)
			if ((animation = animations.get(i)).id.equals(id)) return animation;
	}
	return null;
}
 
Example #10
Source File: AnimationControllerHack.java    From gdx-gltf with Apache License 2.0 4 votes vote down vote up
/** Apply an animation, must be called between {{@link #begin()} and {{@link #end()}.
 * @param weight The blend weight of this animation relative to the previous applied animations. */
@Override
protected void apply (final Animation animation, final float time, final float weight) {
	if (!applying) throw new GdxRuntimeException("You must call begin() before adding an animation");
	applyAnimationPlus(transforms, transformPool, weight, animation, time);
}
 
Example #11
Source File: AnimationControllerHack.java    From gdx-gltf with Apache License 2.0 4 votes vote down vote up
public void setAnimation(Animation animation) {
	setAnimation(animation, 1);
}
 
Example #12
Source File: GLTFAnimationExporter.java    From gdx-gltf with Apache License 2.0 4 votes vote down vote up
public void export(Array<Animation> animations) {
	for(Animation animation : animations){
		export(animation);
	}
}
 
Example #13
Source File: Sprite3DRenderer.java    From bladecoder-adventure-engine with Apache License 2.0 4 votes vote down vote up
@Override
public void startAnimation(String id, Tween.Type repeatType, int count, ActionCallback cb) {
	AnimationDesc fa = fanims.get(id);

	if (fa == null) {
		EngineLogger.error("AnimationDesc not found: " + id);

		return;
	}

	if (currentAnimation != null && currentAnimation.disposeWhenPlayed)
		disposeSource(currentAnimation.source);

	currentAnimation = fa;
	currentSource = sourceCache.get(fa.source);
	animationCb = cb;

	if (currentSource == null || currentSource.refCounter < 1) {
		// If the source is not loaded. Load it.
		loadSource(fa.source);
		EngineAssetManager.getInstance().finishLoading();

		retrieveSource(fa.source);

		currentSource = sourceCache.get(fa.source);

		if (currentSource == null) {
			EngineLogger.error("Could not load AnimationDesc: " + id);
			currentAnimation = null;

			return;
		}
	}

	if (repeatType == Tween.Type.SPRITE_DEFINED) {
		currentAnimationType = currentAnimation.animationType;
		currentCount = currentAnimation.count;
	} else {
		currentCount = count;
		currentAnimationType = repeatType;
	}

	lastAnimationTime = 0;
	float speed = currentAnimation.duration;

	if (currentAnimationType == Tween.Type.REVERSE || currentAnimationType == Tween.Type.REVERSE_REPEAT)
		speed *= -1;

	ModelCacheEntry cs = (ModelCacheEntry) currentSource;

	if (cs.modelInstance.getAnimation(id) != null) {
		animationCb = cb;
		cs.controller.setAnimation(id, currentCount, speed, animationListener);
		computeBbox();
		return;
	}

	int idx = id.indexOf('.');

	if (idx != -1) {
		String s = id.substring(0, idx);
		String dir = id.substring(idx + 1);

		lookat(dir);

		if (cs.modelInstance.getAnimation(s) != null) {
			cs.controller.setAnimation(s, count, speed, animationListener);

			computeBbox();
			return;
		}
	}

	// ERROR CASE
	EngineLogger.error("Animation NOT FOUND: " + id);

	for (Animation a : cs.modelInstance.animations) {
		EngineLogger.debug(a.id);
	}

	if (cb != null) {
		ActionCallback tmpcb = cb;
		cb = null;
		tmpcb.resume();
	}

	computeBbox();
}
 
Example #14
Source File: HeadlessModel.java    From gdx-proto with Apache License 2.0 4 votes vote down vote up
/** @param id The ID of the animation to fetch (case sensitive).
 * @return The {@link com.badlogic.gdx.graphics.g3d.model.Animation} with the specified id, or null if not available. */
public Animation getAnimation (final String id) {
	return getAnimation(id, true);
}
 
Example #15
Source File: AnimationControllerHack.java    From gdx-gltf with Apache License 2.0 2 votes vote down vote up
/**
 * 
 * @param animation animation to play
 * @param loopCount loop count : 0 paused, -1 infinite, n for n loops
 */
public void setAnimation(Animation animation, int loopCount) {
	setAnimation(animation, 0f, animation.duration, loopCount, 1f, null); // loop count: 0 paused, -1 infinite
}