Search in sources :

Example 1 with AnimationSetup

use of net.drewke.tdme.engine.model.AnimationSetup in project tdme by andreasdr.

the class Object3DBase method setAnimation.

/**
	 * Sets up a base animation to play
	 * @param id
	 */
public void setAnimation(String id) {
    AnimationSetup _animationActiveSetup = model.getAnimationSetup(id);
    // only switch animation if we have one
    if (_animationActiveSetup != null) {
        baseAnimation.setup = _animationActiveSetup;
        baseAnimation.lastAtTime = Timing.UNDEFINED;
        baseAnimation.currentAtTime = 0L;
        baseAnimation.time = 0.0f;
        baseAnimation.finished = false;
    }
}
Also used : AnimationSetup(net.drewke.tdme.engine.model.AnimationSetup)

Example 2 with AnimationSetup

use of net.drewke.tdme.engine.model.AnimationSetup in project tdme by andreasdr.

the class Object3DBase method addOverlayAnimation.

/**
	 * Overlays a animation above the base animation
	 * @param id
	 */
public void addOverlayAnimation(String id) {
    // remove active overlay animation with given ids
    removeOverlayAnimation(id);
    // check overlay animation
    AnimationSetup animationSetup = model.getAnimationSetup(id);
    if (animationSetup == null)
        return;
    if (animationSetup.getOverlayFromGroupId() == null)
        return;
    // create animation state
    AnimationState animationState = new AnimationState();
    animationState.setup = animationSetup;
    animationState.lastAtTime = Timing.UNDEFINED;
    animationState.currentAtTime = 0L;
    animationState.time = 0.0f;
    animationState.finished = false;
    // register overlay animation
    overlayAnimationsById.put(id, animationState);
    overlayAnimationsByJointId.put(animationSetup.getOverlayFromGroupId(), animationState);
}
Also used : AnimationSetup(net.drewke.tdme.engine.model.AnimationSetup)

Example 3 with AnimationSetup

use of net.drewke.tdme.engine.model.AnimationSetup in project tdme by andreasdr.

the class ModelUtilitiesInternal method createBoundingBox.

/**
	 * Creates a bounding box from given object3d model
	 * @param model
	 * @return axis aligned bounding box
	 */
public static BoundingBox createBoundingBox(Object3DModelInternal object3DModelInternal) {
    Model model = object3DModelInternal.getModel();
    AnimationSetup defaultAnimation = model.getAnimationSetup(Model.ANIMATIONSETUP_DEFAULT);
    //
    float minX = 0f, minY = 0f, minZ = 0f;
    float maxX = 0f, maxY = 0f, maxZ = 0f;
    boolean firstVertex = true;
    // create bounding box for whole animation at 60fps
    AnimationState animationState = new AnimationState();
    animationState.setup = defaultAnimation;
    animationState.lastAtTime = Timing.UNDEFINED;
    animationState.currentAtTime = 0L;
    animationState.time = 0.0f;
    animationState.finished = false;
    for (float t = 0.0f; t <= (defaultAnimation != null ? defaultAnimation.getFrames() : 0.0f) / model.getFPS(); t += 1f / model.getFPS()) {
        //
        // calculate transformations matrices without world transformations
        object3DModelInternal.computeTransformationsMatrices(model.getSubGroups(), object3DModelInternal.getModel().getImportTransformationsMatrix().clone().multiply(object3DModelInternal.getTransformationsMatrix()), animationState, 0);
        Object3DGroup.computeTransformations(object3DModelInternal.object3dGroups, object3DModelInternal.transformationsMatrices);
        // parse through object groups to determine min, max
        for (Object3DGroup object3DGroup : object3DModelInternal.object3dGroups) {
            for (Vector3 vertex : object3DGroup.mesh.transformedVertices) {
                // vertex xyz array
                float[] vertexXYZ = vertex.getArray();
                // determine min, max
                if (firstVertex == true) {
                    minX = vertexXYZ[0];
                    minY = vertexXYZ[1];
                    minZ = vertexXYZ[2];
                    maxX = vertexXYZ[0];
                    maxY = vertexXYZ[1];
                    maxZ = vertexXYZ[2];
                    firstVertex = false;
                } else {
                    if (vertexXYZ[0] < minX)
                        minX = vertexXYZ[0];
                    if (vertexXYZ[1] < minY)
                        minY = vertexXYZ[1];
                    if (vertexXYZ[2] < minZ)
                        minZ = vertexXYZ[2];
                    if (vertexXYZ[0] > maxX)
                        maxX = vertexXYZ[0];
                    if (vertexXYZ[1] > maxY)
                        maxY = vertexXYZ[1];
                    if (vertexXYZ[2] > maxZ)
                        maxZ = vertexXYZ[2];
                }
            }
        }
        animationState.currentAtTime = (long) (t * 1000f);
        animationState.lastAtTime = (long) (t * 1000f);
    }
    // skip on models without meshes to be rendered
    if (firstVertex == true)
        return null;
    // otherwise go with bounding box
    return new BoundingBox(new Vector3(minX, minY, minZ), new Vector3(maxX, maxY, maxZ));
}
Also used : BoundingBox(net.drewke.tdme.engine.primitives.BoundingBox) Model(net.drewke.tdme.engine.model.Model) Vector3(net.drewke.tdme.math.Vector3) AnimationSetup(net.drewke.tdme.engine.model.AnimationSetup)

Aggregations

AnimationSetup (net.drewke.tdme.engine.model.AnimationSetup)3 Model (net.drewke.tdme.engine.model.Model)1 BoundingBox (net.drewke.tdme.engine.primitives.BoundingBox)1 Vector3 (net.drewke.tdme.math.Vector3)1