use of com.badlogic.gdx.graphics.g3d.model.Node in project libgdx by libgdx.
the class Model method loadAnimations.
protected 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;
if (nanim.translation != null) {
nodeAnim.translation = new Array<NodeKeyframe<Vector3>>();
nodeAnim.translation.ensureCapacity(nanim.translation.size);
for (ModelNodeKeyframe<Vector3> kf : nanim.translation) {
if (kf.keytime > animation.duration)
animation.duration = kf.keytime;
nodeAnim.translation.add(new NodeKeyframe<Vector3>(kf.keytime, new Vector3(kf.value == null ? node.translation : kf.value)));
}
}
if (nanim.rotation != null) {
nodeAnim.rotation = new Array<NodeKeyframe<Quaternion>>();
nodeAnim.rotation.ensureCapacity(nanim.rotation.size);
for (ModelNodeKeyframe<Quaternion> kf : nanim.rotation) {
if (kf.keytime > animation.duration)
animation.duration = kf.keytime;
nodeAnim.rotation.add(new NodeKeyframe<Quaternion>(kf.keytime, new Quaternion(kf.value == null ? node.rotation : kf.value)));
}
}
if (nanim.scaling != null) {
nodeAnim.scaling = new Array<NodeKeyframe<Vector3>>();
nodeAnim.scaling.ensureCapacity(nanim.scaling.size);
for (ModelNodeKeyframe<Vector3> kf : nanim.scaling) {
if (kf.keytime > animation.duration)
animation.duration = kf.keytime;
nodeAnim.scaling.add(new NodeKeyframe<Vector3>(kf.keytime, new Vector3(kf.value == null ? node.scale : kf.value)));
}
}
if ((nodeAnim.translation != null && nodeAnim.translation.size > 0) || (nodeAnim.rotation != null && nodeAnim.rotation.size > 0) || (nodeAnim.scaling != null && nodeAnim.scaling.size > 0))
animation.nodeAnimations.add(nodeAnim);
}
if (animation.nodeAnimations.size > 0)
animations.add(animation);
}
}
use of com.badlogic.gdx.graphics.g3d.model.Node in project libgdx by libgdx.
the class ModelInstance method invalidate.
/** Makes sure that each {@link NodePart} of the {@link Node} and its sub-nodes, doesn't reference a node outside this node
* tree and that all materials are listed in the {@link #materials} array. */
private void invalidate(Node node) {
for (int i = 0, n = node.parts.size; i < n; ++i) {
NodePart part = node.parts.get(i);
ArrayMap<Node, Matrix4> bindPose = part.invBoneBindTransforms;
if (bindPose != null) {
for (int j = 0; j < bindPose.size; ++j) {
bindPose.keys[j] = getNode(bindPose.keys[j].id);
}
}
if (!materials.contains(part.material, true)) {
final int midx = materials.indexOf(part.material, false);
if (midx < 0)
materials.add(part.material = part.material.copy());
else
part.material = materials.get(midx);
}
}
for (int i = 0, n = node.getChildCount(); i < n; ++i) {
invalidate(node.getChild(i));
}
}
use of com.badlogic.gdx.graphics.g3d.model.Node in project libgdx by libgdx.
the class ModelInstance method copyAnimations.
private void copyAnimations(final Iterable<Animation> source, boolean shareKeyframes) {
for (final Animation anim : source) {
Animation animation = new Animation();
animation.id = anim.id;
animation.duration = anim.duration;
for (final NodeAnimation nanim : anim.nodeAnimations) {
final Node node = getNode(nanim.node.id);
if (node == null)
continue;
NodeAnimation nodeAnim = new NodeAnimation();
nodeAnim.node = node;
if (shareKeyframes) {
nodeAnim.translation = nanim.translation;
nodeAnim.rotation = nanim.rotation;
nodeAnim.scaling = nanim.scaling;
} else {
if (nanim.translation != null) {
nodeAnim.translation = new Array<NodeKeyframe<Vector3>>();
for (final NodeKeyframe<Vector3> kf : nanim.translation) nodeAnim.translation.add(new NodeKeyframe<Vector3>(kf.keytime, kf.value));
}
if (nanim.rotation != null) {
nodeAnim.rotation = new Array<NodeKeyframe<Quaternion>>();
for (final NodeKeyframe<Quaternion> kf : nanim.rotation) nodeAnim.rotation.add(new NodeKeyframe<Quaternion>(kf.keytime, kf.value));
}
if (nanim.scaling != null) {
nodeAnim.scaling = new Array<NodeKeyframe<Vector3>>();
for (final NodeKeyframe<Vector3> kf : nanim.scaling) nodeAnim.scaling.add(new NodeKeyframe<Vector3>(kf.keytime, kf.value));
}
}
if (nodeAnim.translation != null || nodeAnim.rotation != null || nodeAnim.scaling != null)
animation.nodeAnimations.add(nodeAnim);
}
if (animation.nodeAnimations.size > 0)
animations.add(animation);
}
}
use of com.badlogic.gdx.graphics.g3d.model.Node in project libgdx by libgdx.
the class BaseAnimationController method applyNodeAnimationBlending.
private static final void applyNodeAnimationBlending(final NodeAnimation nodeAnim, final ObjectMap<Node, Transform> out, final Pool<Transform> pool, final float alpha, final float time) {
final Node node = nodeAnim.node;
node.isAnimated = true;
final Transform transform = getNodeAnimationTransform(nodeAnim, time);
Transform t = out.get(node, null);
if (t != null) {
if (alpha > 0.999999f)
t.set(transform);
else
t.lerp(transform, alpha);
} else {
if (alpha > 0.999999f)
out.put(node, pool.obtain().set(transform));
else
out.put(node, pool.obtain().set(node.translation, node.rotation, node.scale).lerp(transform, alpha));
}
}
use of com.badlogic.gdx.graphics.g3d.model.Node in project libgdx by libgdx.
the class ModelBuilder method createXYZCoordinates.
/** Convenience method to create a model with three orthonormal vectors shapes. The resources the Material might contain are not
* managed, use {@link Model#manageDisposable(Disposable)} to add those to the model.
* @param axisLength Length of each axis.
* @param capLength is the height of the cap in percentage, must be in (0,1)
* @param stemThickness is the percentage of stem diameter compared to cap diameter, must be in (0,1]
* @param divisions the amount of vertices used to generate the cap and stem ellipsoidal bases */
public Model createXYZCoordinates(float axisLength, float capLength, float stemThickness, int divisions, int primitiveType, Material material, long attributes) {
begin();
MeshPartBuilder partBuilder;
Node node = node();
partBuilder = part("xyz", primitiveType, attributes, material);
partBuilder.setColor(Color.RED);
partBuilder.arrow(0, 0, 0, axisLength, 0, 0, capLength, stemThickness, divisions);
partBuilder.setColor(Color.GREEN);
partBuilder.arrow(0, 0, 0, 0, axisLength, 0, capLength, stemThickness, divisions);
partBuilder.setColor(Color.BLUE);
partBuilder.arrow(0, 0, 0, 0, 0, axisLength, capLength, stemThickness, divisions);
return end();
}
Aggregations