com.jme3.animation.LoopMode Java Examples

The following examples show how to use com.jme3.animation.LoopMode. 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: StopAnimationAction.java    From jmonkeybuilder with Apache License 2.0 6 votes vote down vote up
@Override
@FxThread
protected void process() {
    super.process();

    final AnimationTreeNode modelNode = (AnimationTreeNode) getNode();
    if (modelNode.getChannel() < 0) return;

    final AnimControl control = modelNode.getControl();
    if (control == null || control.getNumChannels() <= 0) return;

    final AnimChannel channel = control.getChannel(modelNode.getChannel());
    channel.setLoopMode(LoopMode.DontLoop);

    EXECUTOR_MANAGER.addJmeTask(control::clearChannels);

    final NodeTree<ModelChangeConsumer> nodeTree = getNodeTree();
    nodeTree.update(modelNode);
}
 
Example #2
Source File: PlaySettingsAction.java    From jmonkeybuilder with Apache License 2.0 6 votes vote down vote up
@Override
@FxThread
protected void process() {
    super.process();

    final AnimationControlTreeNode node = (AnimationControlTreeNode) getNode();
    final LoopMode loopMode = node.getLoopMode();
    final float speed = node.getSpeed();

    final Array<PropertyDefinition> definitions = ArrayFactory.newArray(PropertyDefinition.class);
    definitions.add(new PropertyDefinition(ENUM, Messages.MODEL_PROPERTY_LOOP_MODE, PROPERTY_LOOP_MODE, loopMode));
    definitions.add(new PropertyDefinition(FLOAT, Messages.MODEL_PROPERTY_SPEED, PROPERTY_SPEED, speed));

    final GenericFactoryDialog dialog = new GenericFactoryDialog(definitions, vars ->
            node.updateSettings(vars.get(PROPERTY_LOOP_MODE), vars.get(PROPERTY_SPEED)));

    dialog.setTitle(Messages.PLAY_ANIMATION_SETTINGS_DIALOG_TITLE);
    dialog.setButtonOkText(Messages.SIMPLE_DIALOG_BUTTON_OK);
    dialog.show();
}
 
Example #3
Source File: MotionEvent.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public void internalUpdate(float tpf) {
    if (playState == PlayState.Playing) {
        time = time + (tpf * speed);
        if (loopMode == LoopMode.Loop && time < 0) {
            time = initialDuration;
        }            
        if ((time >= initialDuration || time < 0) && loopMode == LoopMode.DontLoop) {
            if (time >= initialDuration) {
                path.triggerWayPointReach(path.getNbWayPoints() - 1, this);
            }
            stop();
        } else {
            time = AnimationUtils.clampWrapTime(time, initialDuration, loopMode);
            if(time<0){
                speed = - speed;
                time = - time;
            }
            onUpdate(tpf);
        }
    }
}
 
Example #4
Source File: AnimationPerformer.java    From OpenRTS with MIT License 6 votes vote down vote up
@Override
public void perform(Actor a) {
	AnimationActor actor = (AnimationActor)a;
	if(actor.launched) {
		return;
	}
	actor.launched = true;
	Spatial s = actor.getParentModelActor().getViewElements().spatial;
	AnimChannel channel = s.getControl(AnimControl.class).getChannel(0);
	channel.setAnim(actor.animName);
	switch (actor.cycle){
		case Once : channel.setLoopMode(LoopMode.DontLoop); break;
		case Loop : channel.setLoopMode(LoopMode.Loop); break;
		case Cycle : channel.setLoopMode(LoopMode.Cycle); break;
	}
	channel.setSpeed((float)actor.speed);
}
 
Example #5
Source File: TestCinematic.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
private void createCameraMotion() {

        CameraNode camNode = cinematic.bindCamera("topView", cam);
        camNode.setLocalTranslation(new Vector3f(0, 50, 0));
        camNode.lookAt(model.getLocalTranslation(), Vector3f.UNIT_Y);

        CameraNode camNode2 = cinematic.bindCamera("aroundCam", cam);
        path = new MotionPath();
        path.setCycle(true);
        path.addWayPoint(new Vector3f(20, 3, 0));
        path.addWayPoint(new Vector3f(0, 3, 20));
        path.addWayPoint(new Vector3f(-20, 3, 0));
        path.addWayPoint(new Vector3f(0, 3, -20));
        path.setCurveTension(0.83f);
        cameraMotionTrack = new MotionTrack(camNode2, path);
        cameraMotionTrack.setLoopMode(LoopMode.Loop);
        cameraMotionTrack.setLookAt(model.getWorldTranslation(), Vector3f.UNIT_Y);
        cameraMotionTrack.setDirectionType(MotionTrack.Direction.LookAt);

    }
 
Example #6
Source File: MotionTrack.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public void onUpdate(float tpf) {
    path.interpolatePath(tpf * speed, this);
    computeTargetDirection();

    if (currentValue >= 1.0f) {
        currentValue = 0;
        currentWayPoint++;
        path.triggerWayPointReach(currentWayPoint, this);
    }
    if (currentWayPoint == path.getNbWayPoints() - 1) {
        if (loopMode == LoopMode.Loop) {
            currentWayPoint = 0;
        } else {
            stop();
        }
    }
}
 
Example #7
Source File: AbstractCinematicEvent.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Used internally only.
 * @param tpf time per frame.
 */
@Override
public void internalUpdate(float tpf) {
    if (playState == PlayState.Playing) {
        time = time + (tpf * speed);         
        onUpdate(tpf);
        if (time >= initialDuration && loopMode == LoopMode.DontLoop) {
            stop();
        } else if(time >= initialDuration && loopMode == LoopMode.Loop){
            setTime(0);
        }else{
            time = AnimationUtils.clampWrapTime(time, initialDuration, loopMode);
            if(time<0){
                speed = - speed;
                time = - time;
            }
        }
    }

}
 
Example #8
Source File: MotionEvent.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Creates a MotionPath for the given spatial on the given motion path.
 * @param spatial
 * @param path
 */
public MotionEvent(Spatial spatial, MotionPath path, float initialDuration, LoopMode loopMode) {
    super(initialDuration);
    spatial.addControl(this);
    this.path = path;
    this.loopMode = loopMode;
}
 
Example #9
Source File: AbstractCinematicEvent.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * for serialization only
 * @param ex exporter
 * @throws IOException 
 */
public void write(JmeExporter ex) throws IOException {
    OutputCapsule oc = ex.getCapsule(this);
    oc.write(playState, "playState", PlayState.Stopped);
    oc.write(speed, "speed", 1);
    oc.write(initialDuration, "initalDuration", 10);
    oc.write(loopMode, "loopMode", LoopMode.DontLoop);
}
 
Example #10
Source File: Cinematic.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * This is used internally but can be called to shuffle through the
 * cinematic.
 *
 * @param time the time to shuffle to.
 */
@Override
public void setTime(float time) {

    //stopping all events
    onStop();
    super.setTime(time);

    int keyFrameIndex = timeLine.getKeyFrameIndexFromTime(time);
    //triggering all the event from start to "time" 
    //then computing timeOffset for each event
    for (int i = 0; i <= keyFrameIndex; i++) {
        KeyFrame keyFrame = timeLine.get(i);
        if (keyFrame != null) {
            for (CinematicEvent ce : keyFrame.getCinematicEvents()) {
                float t = this.time - timeLine.getKeyFrameTime(keyFrame);
                if (t >= 0 && (t <= ce.getInitialDuration() || ce.getLoopMode() != LoopMode.DontLoop)) {
                    ce.play();
                }
                ce.setTime(t);
            }
        }
    }
    lastFetchedKeyFrame = keyFrameIndex;
    if (playState != PlayState.Playing) {
        pause();
    }
}
 
Example #11
Source File: AbstractCinematicEvent.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * for serialization only
 * @param im importer
 * @throws IOException 
 */
public void read(JmeImporter im) throws IOException {
    InputCapsule ic = im.getCapsule(this);
    playState = ic.readEnum("playState", PlayState.class, PlayState.Stopped);
    speed = ic.readFloat("speed", 1);
    initialDuration = ic.readFloat("initalDuration", 10);
    loopMode = ic.readEnum("loopMode", LoopMode.class, LoopMode.DontLoop);
}
 
Example #12
Source File: SoundTrack.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public void setLoopMode(LoopMode loopMode) {
    super.setLoopMode(loopMode);
    
    if (loopMode != LoopMode.DontLoop) {
        audioNode.setLooping(true);
    } else {
        audioNode.setLooping(false);
    }
}
 
Example #13
Source File: TestAttachmentsNode.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void onAction(String binding, boolean value, float tpf) {
    if (binding.equals("Attack") && value) {
        if (!channel.getAnimationName().equals("Punches")) {
            channel.setAnim("Punches", 0.5f);
            channel.setLoopMode(LoopMode.Cycle);
            channel.setSpeed(0.5f);
        }
    }
}
 
Example #14
Source File: MotionTrack.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * Creates a MotionPath for the given spatial on the given motion path
 * @param spatial
 * @param path
 */
public MotionTrack(Spatial spatial, MotionPath path, float initialDuration, LoopMode loopMode) {
    super(initialDuration);
    this.spatial = spatial;
    spatial.addControl(this);
    this.path = path;
    this.loopMode = loopMode;
}
 
Example #15
Source File: SoundEvent.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void setLoopMode(LoopMode loopMode) {
    super.setLoopMode(loopMode);

    if (loopMode != LoopMode.DontLoop) {
        audioNode.setLooping(true);
    } else {
        audioNode.setLooping(false);
    }
}
 
Example #16
Source File: TestBoneRagdoll.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public void onAnimCycleDone(AnimControl control, AnimChannel channel, String animName) {
//        if(channel.getAnimationName().equals("StandUpFront")){
//            channel.setAnim("Dance");
//        }

        if (channel.getAnimationName().equals("StandUpBack") || channel.getAnimationName().equals("StandUpFront")) {
            channel.setLoopMode(LoopMode.DontLoop);
            channel.setAnim("IdleTop", 5);
            channel.setLoopMode(LoopMode.Loop);
        }
//        if(channel.getAnimationName().equals("IdleTop")){
//            channel.setAnim("StandUpFront");
//        }

    }
 
Example #17
Source File: TestRagdollCharacter.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public void onAnimCycleDone(AnimControl control, AnimChannel channel, String animName) {

        if (channel.getAnimationName().equals("SliceHorizontal")) {
            channel.setLoopMode(LoopMode.DontLoop);
            channel.setAnim("IdleTop", 5);
            channel.setLoopMode(LoopMode.Loop);
        }

    }
 
Example #18
Source File: TestOgreAnim.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public void onAction(String binding, boolean value, float tpf) {
    if (binding.equals("Attack") && value){
        if (!channel.getAnimationName().equals("Dodge")){
            channel.setAnim("Dodge", 0.50f);
            channel.setLoopMode(LoopMode.Cycle);
            channel.setSpeed(0.10f);
        }
    }
}
 
Example #19
Source File: TestOgreAnim.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public void onAnimCycleDone(AnimControl control, AnimChannel channel, String animName) {
    if (animName.equals("Dodge")){
        channel.setAnim("stand", 0.50f);
        channel.setLoopMode(LoopMode.DontLoop);
        channel.setSpeed(1f);
    }
}
 
Example #20
Source File: HelloAnimation.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public void onAction(String name, boolean keyPressed, float tpf) {
  if (name.equals("Walk") && !keyPressed) {
    if (!channel.getAnimationName().equals("Walk")) {
      /** Play the "walk" animation! */
      channel.setAnim("Walk", 0.50f);
      channel.setLoopMode(LoopMode.Loop);
    }
  }
}
 
Example #21
Source File: AbstractCinematicEvent.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Used for serialization only.
 * @param ex exporter
 * @throws IOException 
 */
@Override
public void write(JmeExporter ex) throws IOException {
    OutputCapsule oc = ex.getCapsule(this);
    oc.write(playState, "playState", PlayState.Stopped);
    oc.write(speed, "speed", 1);
    oc.write(initialDuration, "initalDuration", 10);
    oc.write(loopMode, "loopMode", LoopMode.DontLoop);
}
 
Example #22
Source File: HelloAnimation.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/** Use this listener to trigger something after an animation is done. */
public void onAnimCycleDone(AnimControl control, AnimChannel channel, String animName) {
  if (animName.equals("Walk")) {
    /** After "walk", reset to "stand". */
    channel.setAnim("stand", 0.50f);
    channel.setLoopMode(LoopMode.DontLoop);
    channel.setSpeed(1f);
  }
}
 
Example #23
Source File: HelloAnimation.java    From chuidiang-ejemplos with GNU Lesser General Public License v3.0 5 votes vote down vote up
public void onAction(String name, boolean keyPressed, float tpf) {
    if (name.equals("Walk") && !keyPressed) {
        if (!channel.getAnimationName().equals("Walk")) {
            channel.setAnim("Walk", 0.50f);
            channel.setLoopMode(LoopMode.Loop);
        }
    }
}
 
Example #24
Source File: HelloAnimation.java    From chuidiang-ejemplos with GNU Lesser General Public License v3.0 5 votes vote down vote up
public void onAnimCycleDone(AnimControl control, AnimChannel channel, String animName) {
    if (animName.equals("Walk")) {
        channel.setAnim("stand", 0.50f);
        channel.setLoopMode(LoopMode.DontLoop);
        channel.setSpeed(1f);
    }
}
 
Example #25
Source File: MotionEvent.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Creates a MotionPath for the given spatial on the given motion path.
 * @param spatial
 * @param path
 */
public MotionEvent(Spatial spatial, MotionPath path, LoopMode loopMode) {
    super();
    spatial.addControl(this);
    this.path = path;
    this.loopMode = loopMode;
}
 
Example #26
Source File: MotionTrack.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * Creates a MotionPath for the given spatial on the given motion path
 * @param spatial
 * @param path
 */
public MotionTrack(Spatial spatial, MotionPath path, LoopMode loopMode) {
    super();
    this.spatial = spatial;
    spatial.addControl(this);
    this.path = path;
    this.loopMode = loopMode;
}
 
Example #27
Source File: AnimationControlTreeNode.java    From jmonkeybuilder with Apache License 2.0 4 votes vote down vote up
public AnimationControlTreeNode(@NotNull final AnimControl element, final long objectId) {
    super(element, objectId);
    this.loopMode = LoopMode.Loop;
    this.speed = 1.0F;
}
 
Example #28
Source File: TestCameraMotionPath.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@Override
public void simpleInitApp() {
    createScene();
    cam.setLocation(new Vector3f(8.4399185f, 11.189463f, 14.267577f));
    camNode = new CameraNode("Motion cam", cam);
    camNode.setControlDir(ControlDirection.SpatialToCamera);
    camNode.getControl(CameraControl.class).setEnabled(false);
    path = new MotionPath();
    path.setCycle(true);
    path.addWayPoint(new Vector3f(20, 3, 0));
    path.addWayPoint(new Vector3f(0, 3, 20));
    path.addWayPoint(new Vector3f(-20, 3, 0));
    path.addWayPoint(new Vector3f(0, 3, -20));
    path.setCurveTension(0.83f);
    path.enableDebugShape(assetManager, rootNode);

    cameraMotionControl = new MotionTrack(camNode, path);
    cameraMotionControl.setLoopMode(LoopMode.Loop);
    //cameraMotionControl.setDuration(15f);
    cameraMotionControl.setLookAt(teapot.getWorldTranslation(), Vector3f.UNIT_Y);
    cameraMotionControl.setDirectionType(MotionTrack.Direction.LookAt);

    rootNode.attachChild(camNode);

    guiFont = assetManager.loadFont("Interface/Fonts/Default.fnt");
    final BitmapText wayPointsText = new BitmapText(guiFont, false);
    wayPointsText.setSize(guiFont.getCharSet().getRenderedSize());

    guiNode.attachChild(wayPointsText);

    path.addListener(new MotionPathListener() {

        public void onWayPointReach(MotionTrack control, int wayPointIndex) {
            if (path.getNbWayPoints() == wayPointIndex + 1) {
                wayPointsText.setText(control.getSpatial().getName() + " Finish!!! ");
            } else {
                wayPointsText.setText(control.getSpatial().getName() + " Reached way point " + wayPointIndex);
            }
            wayPointsText.setLocalTranslation((cam.getWidth() - wayPointsText.getLineWidth()) / 2, cam.getHeight(), 0);
        }
    });

    flyCam.setEnabled(false);
    chaser = new ChaseCamera(cam, teapot);
    chaser.registerWithInput(inputManager);
    chaser.setSmoothMotion(true);
    chaser.setMaxDistance(50);
    chaser.setDefaultDistance(50);
    initInputs();

}
 
Example #29
Source File: SoundTrack.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public SoundTrack(String path, LoopMode loopMode) {
    super(loopMode);        
    this.path = path;
}
 
Example #30
Source File: SoundTrack.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public SoundTrack(String path, boolean stream, float initialDuration, LoopMode loopMode) {
    super(initialDuration, loopMode);        
    this.path = path;
    this.stream = stream;
}