Cinematic: * Reattach CameraNode to scene * Set CameraNode's camera to be app's camera AnimationEvent: * Save modelName * Use modelName and try to replace scene's model in initEventempirephoenix-patch-1
parent
ae97614c83
commit
74f2f703b3
@ -1,448 +1,476 @@ |
|||||||
/* |
/* |
||||||
* Copyright (c) 2009-2012 jMonkeyEngine |
* Copyright (c) 2009-2012 jMonkeyEngine |
||||||
* All rights reserved. |
* All rights reserved. |
||||||
* |
* |
||||||
* Redistribution and use in source and binary forms, with or without |
* Redistribution and use in source and binary forms, with or without |
||||||
* modification, are permitted provided that the following conditions are |
* modification, are permitted provided that the following conditions are |
||||||
* met: |
* met: |
||||||
* |
* |
||||||
* * Redistributions of source code must retain the above copyright |
* * Redistributions of source code must retain the above copyright |
||||||
* notice, this list of conditions and the following disclaimer. |
* notice, this list of conditions and the following disclaimer. |
||||||
* |
* |
||||||
* * Redistributions in binary form must reproduce the above copyright |
* * Redistributions in binary form must reproduce the above copyright |
||||||
* notice, this list of conditions and the following disclaimer in the |
* notice, this list of conditions and the following disclaimer in the |
||||||
* documentation and/or other materials provided with the distribution. |
* documentation and/or other materials provided with the distribution. |
||||||
* |
* |
||||||
* * Neither the name of 'jMonkeyEngine' nor the names of its contributors |
* * Neither the name of 'jMonkeyEngine' nor the names of its contributors |
||||||
* may be used to endorse or promote products derived from this software |
* may be used to endorse or promote products derived from this software |
||||||
* without specific prior written permission. |
* without specific prior written permission. |
||||||
* |
* |
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
||||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED |
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED |
||||||
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
||||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR |
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR |
||||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
||||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
||||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
||||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF |
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF |
||||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
||||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
||||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||||||
*/ |
*/ |
||||||
package com.jme3.cinematic.events; |
package com.jme3.cinematic.events; |
||||||
|
|
||||||
import com.jme3.animation.AnimChannel; |
import com.jme3.animation.AnimChannel; |
||||||
import com.jme3.animation.AnimControl; |
import com.jme3.animation.AnimControl; |
||||||
import com.jme3.animation.LoopMode; |
import com.jme3.animation.LoopMode; |
||||||
import com.jme3.app.Application; |
import com.jme3.app.Application; |
||||||
import com.jme3.cinematic.Cinematic; |
import com.jme3.cinematic.Cinematic; |
||||||
import com.jme3.cinematic.PlayState; |
import com.jme3.cinematic.PlayState; |
||||||
import com.jme3.export.InputCapsule; |
import com.jme3.export.InputCapsule; |
||||||
import com.jme3.export.JmeExporter; |
import com.jme3.export.JmeExporter; |
||||||
import com.jme3.export.JmeImporter; |
import com.jme3.export.JmeImporter; |
||||||
import com.jme3.export.OutputCapsule; |
import com.jme3.export.OutputCapsule; |
||||||
import com.jme3.scene.Spatial; |
import com.jme3.scene.Node; |
||||||
import java.io.IOException; |
import com.jme3.scene.Spatial; |
||||||
import java.util.Collection; |
import com.jme3.util.clone.Cloner; |
||||||
import java.util.HashMap; |
import com.jme3.util.clone.JmeCloneable; |
||||||
import java.util.Map; |
import java.io.IOException; |
||||||
import java.util.logging.Logger; |
import java.util.Collection; |
||||||
|
import java.util.HashMap; |
||||||
/** |
import java.util.Map; |
||||||
* An event based on an animation of a model. The model has to hold an |
import java.util.logging.Logger; |
||||||
* AnimControl with valid animation (bone or spatial animations). |
|
||||||
* |
/** |
||||||
* It helps to schedule the playback of an animation on a model in a Cinematic. |
* An event based on an animation of a model. The model has to hold an |
||||||
* |
* AnimControl with valid animation (bone or spatial animations). |
||||||
* |
* |
||||||
* @author Nehon |
* It helps to schedule the playback of an animation on a model in a Cinematic. |
||||||
*/ |
* |
||||||
public class AnimationEvent extends AbstractCinematicEvent { |
* |
||||||
|
* @author Nehon |
||||||
// Version #2: directly keeping track on the model instead of trying to retrieve
|
*/ |
||||||
//it from the scene according to its name, because the name is not supposed to be unique
|
public class AnimationEvent extends AbstractCinematicEvent { |
||||||
//For backward compatibility, if the model is null it's looked up into the scene
|
|
||||||
public static final int SAVABLE_VERSION = 2; |
// Version #2: directly keeping track on the model instead of trying to retrieve
|
||||||
private static final Logger log = Logger.getLogger(AnimationEvent.class.getName()); |
//it from the scene according to its name, because the name is not supposed to be unique
|
||||||
public static final String MODEL_CHANNELS = "modelChannels"; |
//For backward compatibility, if the model is null it's looked up into the scene
|
||||||
protected AnimChannel channel; |
public static final int SAVABLE_VERSION = 2; |
||||||
protected String animationName; |
private static final Logger log = Logger.getLogger(AnimationEvent.class.getName()); |
||||||
protected Spatial model; |
public static final String MODEL_CHANNELS = "modelChannels"; |
||||||
//kept for backward compatibility
|
protected AnimChannel channel; |
||||||
protected String modelName; |
protected String animationName; |
||||||
protected float blendTime = 0; |
protected Spatial model; |
||||||
protected int channelIndex = 0; |
//kept for backward compatibility
|
||||||
// parent cinematic
|
protected String modelName; |
||||||
protected Cinematic cinematic; |
protected float blendTime = 0; |
||||||
|
protected int channelIndex = 0; |
||||||
/** |
// parent cinematic
|
||||||
* used for serialization don't call directly use one of the following |
protected Cinematic cinematic; |
||||||
* constructors |
|
||||||
*/ |
/** |
||||||
public AnimationEvent() { |
* used for serialization don't call directly use one of the following |
||||||
super(); |
* constructors |
||||||
} |
*/ |
||||||
|
public AnimationEvent() { |
||||||
/** |
super(); |
||||||
* creates an animation event |
} |
||||||
* |
|
||||||
* @param model the model on which the animation will be played |
/** |
||||||
* @param animationName the name of the animation to play |
* creates an animation event |
||||||
*/ |
* |
||||||
public AnimationEvent(Spatial model, String animationName) { |
* @param model the model on which the animation will be played |
||||||
this.model = model; |
* @param animationName the name of the animation to play |
||||||
this.animationName = animationName; |
*/ |
||||||
initialDuration = model.getControl(AnimControl.class).getAnimationLength(animationName); |
public AnimationEvent(Spatial model, String animationName) { |
||||||
} |
this.model = model; |
||||||
|
this.modelName = model.getName(); |
||||||
/** |
this.animationName = animationName; |
||||||
* creates an animation event |
initialDuration = model.getControl(AnimControl.class).getAnimationLength(animationName); |
||||||
* |
} |
||||||
* @param model the model on which the animation will be played |
|
||||||
* @param animationName the name of the animation to play |
/** |
||||||
* @param initialDuration the initial duration of the event |
* creates an animation event |
||||||
*/ |
* |
||||||
public AnimationEvent(Spatial model, String animationName, float initialDuration) { |
* @param model the model on which the animation will be played |
||||||
super(initialDuration); |
* @param animationName the name of the animation to play |
||||||
this.model = model; |
* @param initialDuration the initial duration of the event |
||||||
this.animationName = animationName; |
*/ |
||||||
} |
public AnimationEvent(Spatial model, String animationName, float initialDuration) { |
||||||
|
super(initialDuration); |
||||||
/** |
this.model = model; |
||||||
* creates an animation event |
this.modelName = model.getName(); |
||||||
* |
this.animationName = animationName; |
||||||
* @param model the model on which the animation will be played |
} |
||||||
* @param animationName the name of the animation to play |
|
||||||
* @param loopMode the loopMode |
/** |
||||||
* @see LoopMode |
* creates an animation event |
||||||
*/ |
* |
||||||
public AnimationEvent(Spatial model, String animationName, LoopMode loopMode) { |
* @param model the model on which the animation will be played |
||||||
super(loopMode); |
* @param animationName the name of the animation to play |
||||||
initialDuration = model.getControl(AnimControl.class).getAnimationLength(animationName); |
* @param loopMode the loopMode |
||||||
this.model = model; |
* @see LoopMode |
||||||
this.animationName = animationName; |
*/ |
||||||
} |
public AnimationEvent(Spatial model, String animationName, LoopMode loopMode) { |
||||||
|
super(loopMode); |
||||||
/** |
initialDuration = model.getControl(AnimControl.class).getAnimationLength(animationName); |
||||||
* creates an animation event |
this.model = model; |
||||||
* |
this.modelName = model.getName(); |
||||||
* @param model the model on which the animation will be played |
this.animationName = animationName; |
||||||
* @param animationName the name of the animation to play |
} |
||||||
* @param initialDuration the initial duration of the event |
|
||||||
* @param loopMode the loopMode |
/** |
||||||
* @see LoopMode |
* creates an animation event |
||||||
*/ |
* |
||||||
public AnimationEvent(Spatial model, String animationName, float initialDuration, LoopMode loopMode) { |
* @param model the model on which the animation will be played |
||||||
super(initialDuration, loopMode); |
* @param animationName the name of the animation to play |
||||||
this.model = model; |
* @param initialDuration the initial duration of the event |
||||||
this.animationName = animationName; |
* @param loopMode the loopMode |
||||||
} |
* @see LoopMode |
||||||
|
*/ |
||||||
/** |
public AnimationEvent(Spatial model, String animationName, float initialDuration, LoopMode loopMode) { |
||||||
* creates an animation event |
super(initialDuration, loopMode); |
||||||
* |
this.model = model; |
||||||
* @param model the model on which the animation will be played |
this.modelName = model.getName(); |
||||||
* @param animationName the name of the animation to play |
this.animationName = animationName; |
||||||
* @param initialDuration the initial duration of the event |
} |
||||||
* @param blendTime the time during the animation are gonna be blended |
|
||||||
* @see AnimChannel#setAnim(java.lang.String, float) |
/** |
||||||
*/ |
* creates an animation event |
||||||
public AnimationEvent(Spatial model, String animationName, float initialDuration, float blendTime) { |
* |
||||||
super(initialDuration); |
* @param model the model on which the animation will be played |
||||||
this.model = model; |
* @param animationName the name of the animation to play |
||||||
this.animationName = animationName; |
* @param initialDuration the initial duration of the event |
||||||
this.blendTime = blendTime; |
* @param blendTime the time during the animation are gonna be blended |
||||||
} |
* @see AnimChannel#setAnim(java.lang.String, float) |
||||||
|
*/ |
||||||
/** |
public AnimationEvent(Spatial model, String animationName, float initialDuration, float blendTime) { |
||||||
* creates an animation event |
super(initialDuration); |
||||||
* |
this.model = model; |
||||||
* @param model the model on which the animation will be played |
this.modelName = model.getName(); |
||||||
* @param animationName the name of the animation to play |
this.animationName = animationName; |
||||||
* @param loopMode the loopMode |
this.blendTime = blendTime; |
||||||
* @see LoopMode |
} |
||||||
* @param blendTime the time during the animation are gonna be blended |
|
||||||
* @see AnimChannel#setAnim(java.lang.String, float) |
/** |
||||||
*/ |
* creates an animation event |
||||||
public AnimationEvent(Spatial model, String animationName, LoopMode loopMode, float blendTime) { |
* |
||||||
super(loopMode); |
* @param model the model on which the animation will be played |
||||||
initialDuration = model.getControl(AnimControl.class).getAnimationLength(animationName); |
* @param animationName the name of the animation to play |
||||||
this.model = model; |
* @param loopMode the loopMode |
||||||
this.animationName = animationName; |
* @see LoopMode |
||||||
this.blendTime = blendTime; |
* @param blendTime the time during the animation are gonna be blended |
||||||
} |
* @see AnimChannel#setAnim(java.lang.String, float) |
||||||
|
*/ |
||||||
/** |
public AnimationEvent(Spatial model, String animationName, LoopMode loopMode, float blendTime) { |
||||||
* creates an animation event |
super(loopMode); |
||||||
* |
initialDuration = model.getControl(AnimControl.class).getAnimationLength(animationName); |
||||||
* @param model the model on which the animation will be played |
this.model = model; |
||||||
* @param animationName the name of the animation to play |
this.modelName = model.getName(); |
||||||
* @param initialDuration the initial duration of the event |
this.animationName = animationName; |
||||||
* @param loopMode the loopMode |
this.blendTime = blendTime; |
||||||
* @see LoopMode |
} |
||||||
* @param blendTime the time during the animation are gonna be blended |
|
||||||
* @see AnimChannel#setAnim(java.lang.String, float) |
/** |
||||||
*/ |
* creates an animation event |
||||||
public AnimationEvent(Spatial model, String animationName, float initialDuration, LoopMode loopMode, float blendTime) { |
* |
||||||
super(initialDuration, loopMode); |
* @param model the model on which the animation will be played |
||||||
this.model = model; |
* @param animationName the name of the animation to play |
||||||
this.animationName = animationName; |
* @param initialDuration the initial duration of the event |
||||||
this.blendTime = blendTime; |
* @param loopMode the loopMode |
||||||
} |
* @see LoopMode |
||||||
|
* @param blendTime the time during the animation are gonna be blended |
||||||
/** |
* @see AnimChannel#setAnim(java.lang.String, float) |
||||||
* creates an animation event |
*/ |
||||||
* |
public AnimationEvent(Spatial model, String animationName, float initialDuration, LoopMode loopMode, float blendTime) { |
||||||
* @param model the model on which the animation will be played |
super(initialDuration, loopMode); |
||||||
* @param animationName the name of the animation to play |
this.model = model; |
||||||
* @param loopMode the loopMode |
this.modelName = model.getName(); |
||||||
* @see LoopMode |
this.animationName = animationName; |
||||||
* @param channelIndex the index of the channel default is 0. Events on the |
this.blendTime = blendTime; |
||||||
* same channelIndex will use the same channel. |
} |
||||||
*/ |
|
||||||
public AnimationEvent(Spatial model, String animationName, LoopMode loopMode, int channelIndex) { |
/** |
||||||
super(loopMode); |
* creates an animation event |
||||||
initialDuration = model.getControl(AnimControl.class).getAnimationLength(animationName); |
* |
||||||
this.model = model; |
* @param model the model on which the animation will be played |
||||||
this.animationName = animationName; |
* @param animationName the name of the animation to play |
||||||
this.channelIndex = channelIndex; |
* @param loopMode the loopMode |
||||||
} |
* @see LoopMode |
||||||
|
* @param channelIndex the index of the channel default is 0. Events on the |
||||||
/** |
* same channelIndex will use the same channel. |
||||||
* creates an animation event |
*/ |
||||||
* |
public AnimationEvent(Spatial model, String animationName, LoopMode loopMode, int channelIndex) { |
||||||
* @param model the model on which the animation will be played |
super(loopMode); |
||||||
* @param animationName the name of the animation to play |
initialDuration = model.getControl(AnimControl.class).getAnimationLength(animationName); |
||||||
* @param channelIndex the index of the channel default is 0. Events on the |
this.model = model; |
||||||
* same channelIndex will use the same channel. |
this.modelName = model.getName(); |
||||||
*/ |
this.animationName = animationName; |
||||||
public AnimationEvent(Spatial model, String animationName, int channelIndex) { |
this.channelIndex = channelIndex; |
||||||
this.model = model; |
} |
||||||
this.animationName = animationName; |
|
||||||
initialDuration = model.getControl(AnimControl.class).getAnimationLength(animationName); |
/** |
||||||
this.channelIndex = channelIndex; |
* creates an animation event |
||||||
} |
* |
||||||
|
* @param model the model on which the animation will be played |
||||||
/** |
* @param animationName the name of the animation to play |
||||||
* creates an animation event |
* @param channelIndex the index of the channel default is 0. Events on the |
||||||
* |
* same channelIndex will use the same channel. |
||||||
* @param model the model on which the animation will be played |
*/ |
||||||
* @param animationName the name of the animation to play |
public AnimationEvent(Spatial model, String animationName, int channelIndex) { |
||||||
* @param channelIndex the index of the channel default is 0. Events on the |
this.model = model; |
||||||
* @param blendTime the time during the animation are gonna be blended |
this.modelName = model.getName(); |
||||||
* same channelIndex will use the same channel. |
this.animationName = animationName; |
||||||
*/ |
initialDuration = model.getControl(AnimControl.class).getAnimationLength(animationName); |
||||||
public AnimationEvent(Spatial model, String animationName, LoopMode loopMode, int channelIndex, float blendTime) { |
this.channelIndex = channelIndex; |
||||||
this.model = model; |
} |
||||||
this.animationName = animationName; |
|
||||||
this.loopMode = loopMode; |
/** |
||||||
initialDuration = model.getControl(AnimControl.class).getAnimationLength(animationName); |
* creates an animation event |
||||||
this.channelIndex = channelIndex; |
* |
||||||
this.blendTime = blendTime; |
* @param model the model on which the animation will be played |
||||||
} |
* @param animationName the name of the animation to play |
||||||
|
* @param channelIndex the index of the channel default is 0. Events on the |
||||||
/** |
* @param blendTime the time during the animation are gonna be blended |
||||||
* creates an animation event |
* same channelIndex will use the same channel. |
||||||
* |
*/ |
||||||
* @param model the model on which the animation will be played |
public AnimationEvent(Spatial model, String animationName, LoopMode loopMode, int channelIndex, float blendTime) { |
||||||
* @param animationName the name of the animation to play |
this.model = model; |
||||||
* @param initialDuration the initial duration of the event |
this.modelName = model.getName(); |
||||||
* @param channelIndex the index of the channel default is 0. Events on the |
this.animationName = animationName; |
||||||
* same channelIndex will use the same channel. |
this.loopMode = loopMode; |
||||||
*/ |
initialDuration = model.getControl(AnimControl.class).getAnimationLength(animationName); |
||||||
public AnimationEvent(Spatial model, String animationName, float initialDuration, int channelIndex) { |
this.channelIndex = channelIndex; |
||||||
super(initialDuration); |
this.blendTime = blendTime; |
||||||
this.model = model; |
} |
||||||
this.animationName = animationName; |
|
||||||
this.channelIndex = channelIndex; |
/** |
||||||
} |
* creates an animation event |
||||||
|
* |
||||||
/** |
* @param model the model on which the animation will be played |
||||||
* creates an animation event |
* @param animationName the name of the animation to play |
||||||
* |
* @param initialDuration the initial duration of the event |
||||||
* @param model the model on which the animation will be played |
* @param channelIndex the index of the channel default is 0. Events on the |
||||||
* @param animationName the name of the animation to play |
* same channelIndex will use the same channel. |
||||||
* @param initialDuration the initial duration of the event |
*/ |
||||||
* @param loopMode the loopMode |
public AnimationEvent(Spatial model, String animationName, float initialDuration, int channelIndex) { |
||||||
* @see LoopMode |
super(initialDuration); |
||||||
* @param channelIndex the index of the channel default is 0. Events on the |
this.model = model; |
||||||
* same channelIndex will use the same channel. |
this.modelName = model.getName(); |
||||||
*/ |
this.animationName = animationName; |
||||||
public AnimationEvent(Spatial model, String animationName, float initialDuration, LoopMode loopMode, int channelIndex) { |
this.channelIndex = channelIndex; |
||||||
super(initialDuration, loopMode); |
} |
||||||
this.model = model; |
|
||||||
this.animationName = animationName; |
/** |
||||||
this.channelIndex = channelIndex; |
* creates an animation event |
||||||
} |
* |
||||||
|
* @param model the model on which the animation will be played |
||||||
@Override |
* @param animationName the name of the animation to play |
||||||
public void initEvent(Application app, Cinematic cinematic) { |
* @param initialDuration the initial duration of the event |
||||||
super.initEvent(app, cinematic); |
* @param loopMode the loopMode |
||||||
this.cinematic = cinematic; |
* @see LoopMode |
||||||
if (channel == null) { |
* @param channelIndex the index of the channel default is 0. Events on the |
||||||
Object s = cinematic.getEventData(MODEL_CHANNELS, model); |
* same channelIndex will use the same channel. |
||||||
if (s == null) { |
*/ |
||||||
s = new HashMap<Integer, AnimChannel>(); |
public AnimationEvent(Spatial model, String animationName, float initialDuration, LoopMode loopMode, int channelIndex) { |
||||||
int numChannels = model.getControl(AnimControl.class).getNumChannels(); |
super(initialDuration, loopMode); |
||||||
for(int i = 0; i < numChannels; i++){ |
this.model = model; |
||||||
((HashMap<Integer, AnimChannel>)s).put(i, model.getControl(AnimControl.class).getChannel(i)); |
this.modelName = model.getName(); |
||||||
} |
this.animationName = animationName; |
||||||
cinematic.putEventData(MODEL_CHANNELS, model, s); |
this.channelIndex = channelIndex; |
||||||
} |
} |
||||||
|
|
||||||
Map<Integer, AnimChannel> map = (Map<Integer, AnimChannel>) s; |
@Override |
||||||
this.channel = map.get(channelIndex); |
public void initEvent(Application app, Cinematic cinematic) { |
||||||
if (this.channel == null) { |
super.initEvent(app, cinematic); |
||||||
if (model == null) { |
this.cinematic = cinematic; |
||||||
//the model is null we try to find it according to the name
|
if (channel == null) { |
||||||
//this should occur only when loading an old saved cinematic
|
Object s = cinematic.getEventData(MODEL_CHANNELS, model); |
||||||
//othewise it's an error
|
if (s == null) { |
||||||
model = cinematic.getScene().getChild(modelName); |
s = new HashMap<Integer, AnimChannel>(); |
||||||
} |
int numChannels = model.getControl(AnimControl.class).getNumChannels(); |
||||||
if (model != null) { |
for(int i = 0; i < numChannels; i++){ |
||||||
channel = model.getControl(AnimControl.class).createChannel(); |
((HashMap<Integer, AnimChannel>)s).put(i, model.getControl(AnimControl.class).getChannel(i)); |
||||||
map.put(channelIndex, channel); |
} |
||||||
} else { |
cinematic.putEventData(MODEL_CHANNELS, model, s); |
||||||
//it's an error
|
} |
||||||
throw new UnsupportedOperationException("model should not be null"); |
|
||||||
} |
Map<Integer, AnimChannel> map = (Map<Integer, AnimChannel>) s; |
||||||
} |
this.channel = map.get(channelIndex); |
||||||
|
if (this.channel == null) { |
||||||
} |
if (model == null) { |
||||||
} |
//the model is null we try to find it according to the name
|
||||||
|
//this should occur only when loading an old saved cinematic
|
||||||
@Override |
//othewise it's an error
|
||||||
public void setTime(float time) { |
model = cinematic.getScene().getChild(modelName); |
||||||
super.setTime(time); |
} |
||||||
if (!animationName.equals(channel.getAnimationName())) { |
if (model != null) { |
||||||
channel.setAnim(animationName, blendTime); |
if(cinematic.getScene() != null){ |
||||||
} |
Spatial sceneModel = cinematic.getScene().getChild(model.getName()); |
||||||
float t = time; |
if(sceneModel != null){ |
||||||
if (loopMode == loopMode.Loop) { |
Node parent = sceneModel.getParent(); |
||||||
t = t % channel.getAnimMaxTime(); |
parent.detachChild(sceneModel); |
||||||
} |
sceneModel = model; |
||||||
if (loopMode == loopMode.Cycle) { |
parent.attachChild(sceneModel); |
||||||
float parity = (float) Math.ceil(time / channel.getAnimMaxTime()); |
} else { |
||||||
if (parity > 0 && parity % 2 == 0) { |
cinematic.getScene().attachChild(model); |
||||||
t = channel.getAnimMaxTime() - t % channel.getAnimMaxTime(); |
} |
||||||
} else { |
} |
||||||
t = t % channel.getAnimMaxTime(); |
|
||||||
} |
channel = model.getControl(AnimControl.class).createChannel(); |
||||||
|
map.put(channelIndex, channel); |
||||||
} |
} else { |
||||||
if (t < 0) { |
//it's an error
|
||||||
channel.setTime(0); |
throw new UnsupportedOperationException("model should not be null"); |
||||||
channel.reset(true); |
} |
||||||
} |
} |
||||||
if (t > channel.getAnimMaxTime()) { |
|
||||||
channel.setTime(t); |
} |
||||||
channel.getControl().update(0); |
} |
||||||
stop(); |
|
||||||
} else { |
@Override |
||||||
channel.setTime(t); |
public void setTime(float time) { |
||||||
channel.getControl().update(0); |
super.setTime(time); |
||||||
} |
if (!animationName.equals(channel.getAnimationName())) { |
||||||
|
channel.setAnim(animationName, blendTime); |
||||||
} |
} |
||||||
|
float t = time; |
||||||
@Override |
if (loopMode == loopMode.Loop) { |
||||||
public void onPlay() { |
t = t % channel.getAnimMaxTime(); |
||||||
channel.getControl().setEnabled(true); |
} |
||||||
if (playState == PlayState.Stopped) { |
if (loopMode == loopMode.Cycle) { |
||||||
channel.setAnim(animationName, blendTime); |
float parity = (float) Math.ceil(time / channel.getAnimMaxTime()); |
||||||
channel.setSpeed(speed); |
if (parity > 0 && parity % 2 == 0) { |
||||||
channel.setLoopMode(loopMode); |
t = channel.getAnimMaxTime() - t % channel.getAnimMaxTime(); |
||||||
channel.setTime(0); |
} else { |
||||||
} |
t = t % channel.getAnimMaxTime(); |
||||||
} |
} |
||||||
|
|
||||||
@Override |
} |
||||||
public void setSpeed(float speed) { |
if (t < 0) { |
||||||
super.setSpeed(speed); |
channel.setTime(0); |
||||||
if (channel != null) { |
channel.reset(true); |
||||||
channel.setSpeed(speed); |
} |
||||||
} |
if (t > channel.getAnimMaxTime()) { |
||||||
} |
channel.setTime(t); |
||||||
|
channel.getControl().update(0); |
||||||
@Override |
stop(); |
||||||
public void onUpdate(float tpf) { |
} else { |
||||||
} |
channel.setTime(t); |
||||||
|
channel.getControl().update(0); |
||||||
@Override |
} |
||||||
public void onStop() { |
|
||||||
} |
} |
||||||
|
|
||||||
@Override |
@Override |
||||||
public void forceStop() { |
public void onPlay() { |
||||||
if (channel != null) { |
channel.getControl().setEnabled(true); |
||||||
channel.setTime(time); |
if (playState == PlayState.Stopped) { |
||||||
channel.reset(false); |
channel.setAnim(animationName, blendTime); |
||||||
} |
channel.setSpeed(speed); |
||||||
super.forceStop(); |
channel.setLoopMode(loopMode); |
||||||
} |
channel.setTime(0); |
||||||
|
} |
||||||
@Override |
} |
||||||
public void onPause() { |
|
||||||
if (channel != null) { |
@Override |
||||||
channel.getControl().setEnabled(false); |
public void setSpeed(float speed) { |
||||||
} |
super.setSpeed(speed); |
||||||
} |
if (channel != null) { |
||||||
|
channel.setSpeed(speed); |
||||||
@Override |
} |
||||||
public void setLoopMode(LoopMode loopMode) { |
} |
||||||
super.setLoopMode(loopMode); |
|
||||||
if (channel != null) { |
@Override |
||||||
channel.setLoopMode(loopMode); |
public void onUpdate(float tpf) { |
||||||
} |
} |
||||||
} |
|
||||||
|
@Override |
||||||
@Override |
public void onStop() { |
||||||
public void write(JmeExporter ex) throws IOException { |
} |
||||||
super.write(ex); |
|
||||||
OutputCapsule oc = ex.getCapsule(this); |
@Override |
||||||
|
public void forceStop() { |
||||||
oc.write(model, "model", null); |
if (channel != null) { |
||||||
oc.write(animationName, "animationName", ""); |
channel.setTime(time); |
||||||
oc.write(blendTime, "blendTime", 0f); |
channel.reset(false); |
||||||
oc.write(channelIndex, "channelIndex", 0); |
} |
||||||
|
super.forceStop(); |
||||||
} |
} |
||||||
|
|
||||||
@Override |
@Override |
||||||
public void read(JmeImporter im) throws IOException { |
public void onPause() { |
||||||
super.read(im); |
if (channel != null) { |
||||||
InputCapsule ic = im.getCapsule(this); |
channel.getControl().setEnabled(false); |
||||||
if (im.getFormatVersion() == 0) { |
} |
||||||
modelName = ic.readString("modelName", ""); |
} |
||||||
} |
|
||||||
//FIXME always the same issue, because of the clonning of assets, this won't work
|
@Override |
||||||
//we have to somehow store userdata in the spatial and then recurse the
|
public void setLoopMode(LoopMode loopMode) { |
||||||
//scene sub scenegraph to find the correct instance of the model
|
super.setLoopMode(loopMode); |
||||||
//This brings a reflaxion about the cinematic being an appstate,
|
if (channel != null) { |
||||||
//shouldn't it be a control over the scene
|
channel.setLoopMode(loopMode); |
||||||
// this would allow to use the cloneForSpatial method and automatically
|
} |
||||||
//rebind cloned references of original objects.
|
} |
||||||
//for now as nobody probably ever saved a cinematic, this is not a critical issue
|
|
||||||
model = (Spatial) ic.readSavable("model", null); |
@Override |
||||||
animationName = ic.readString("animationName", ""); |
public void write(JmeExporter ex) throws IOException { |
||||||
blendTime = ic.readFloat("blendTime", 0f); |
super.write(ex); |
||||||
channelIndex = ic.readInt("channelIndex", 0); |
OutputCapsule oc = ex.getCapsule(this); |
||||||
} |
|
||||||
|
oc.write(model, "model", null); |
||||||
@Override |
oc.write(modelName, "modelName", null); |
||||||
public void dispose() { |
oc.write(animationName, "animationName", ""); |
||||||
super.dispose(); |
oc.write(blendTime, "blendTime", 0f); |
||||||
if (cinematic != null) { |
oc.write(channelIndex, "channelIndex", 0); |
||||||
Object o = cinematic.getEventData(MODEL_CHANNELS, model); |
|
||||||
if (o != null) { |
} |
||||||
Collection<AnimChannel> values = ((HashMap<Integer, AnimChannel>) o).values(); |
|
||||||
while (values.remove(channel)); |
@Override |
||||||
if (values.isEmpty()) { |
public void read(JmeImporter im) throws IOException { |
||||||
cinematic.removeEventData(MODEL_CHANNELS, model); |
super.read(im); |
||||||
} |
InputCapsule ic = im.getCapsule(this); |
||||||
} |
// if (im.getFormatVersion() == 0) {
|
||||||
cinematic = null; |
modelName = ic.readString("modelName", ""); |
||||||
channel = null; |
// }
|
||||||
} |
//FIXME always the same issue, because of the clonning of assets, this won't work
|
||||||
} |
//we have to somehow store userdata in the spatial and then recurse the
|
||||||
} |
//scene sub scenegraph to find the correct instance of the model
|
||||||
|
//This brings a reflaxion about the cinematic being an appstate,
|
||||||
|
//shouldn't it be a control over the scene
|
||||||
|
// this would allow to use the cloneForSpatial method and automatically
|
||||||
|
//rebind cloned references of original objects.
|
||||||
|
//for now as nobody probably ever saved a cinematic, this is not a critical issue
|
||||||
|
model = (Spatial) ic.readSavable("model", null); |
||||||
|
animationName = ic.readString("animationName", ""); |
||||||
|
blendTime = ic.readFloat("blendTime", 0f); |
||||||
|
channelIndex = ic.readInt("channelIndex", 0); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public void dispose() { |
||||||
|
super.dispose(); |
||||||
|
if (cinematic != null) { |
||||||
|
Object o = cinematic.getEventData(MODEL_CHANNELS, model); |
||||||
|
if (o != null) { |
||||||
|
Collection<AnimChannel> values = ((HashMap<Integer, AnimChannel>) o).values(); |
||||||
|
while (values.remove(channel)); |
||||||
|
if (values.isEmpty()) { |
||||||
|
cinematic.removeEventData(MODEL_CHANNELS, model); |
||||||
|
} |
||||||
|
} |
||||||
|
cinematic = null; |
||||||
|
channel = null; |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
Loading…
Reference in new issue