-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Minor refactor to allow for saving AnimLayers #2307
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
c0b369b
Minor refactor to allow for saving AnimLayers
neph1 eb0fb5f
add a few tests
neph1 678bd44
move Savable to ArmatureMask
neph1 420994a
check if instance is of Savable instead for wider compatibility
neph1 8c31b05
review fixes
neph1 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I decided to only save name and mask. The other fields felt like they're only interesting for runtime. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -32,8 +32,14 @@ | |
| package com.jme3.anim; | ||
|
|
||
| import com.jme3.anim.tween.action.Action; | ||
| import com.jme3.export.InputCapsule; | ||
| import com.jme3.export.JmeExporter; | ||
| import com.jme3.export.JmeImporter; | ||
| import com.jme3.export.OutputCapsule; | ||
| import com.jme3.export.Savable; | ||
| import com.jme3.util.clone.Cloner; | ||
| import com.jme3.util.clone.JmeCloneable; | ||
| import java.io.IOException; | ||
|
|
||
| /** | ||
| * A named portion of an AnimComposer that can run (at most) one Action at a | ||
|
|
@@ -48,7 +54,7 @@ | |
| * <p>Animation time may advance at a different rate from application time, | ||
| * based on speedup factors in the composer and the current Action. | ||
| */ | ||
| public class AnimLayer implements JmeCloneable { | ||
| public class AnimLayer implements JmeCloneable, Savable { | ||
| /** | ||
| * The Action currently running on this layer, or null if none. | ||
| */ | ||
|
|
@@ -57,16 +63,12 @@ public class AnimLayer implements JmeCloneable { | |
| * The name of Action currently running on this layer, or null if none. | ||
| */ | ||
| private String currentActionName; | ||
| /** | ||
| * The composer that owns this layer. Were it not for cloning, this field | ||
| * would be final. | ||
| */ | ||
| private AnimComposer composer; | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. redundant field |
||
|
|
||
| /** | ||
| * Limits the portion of the model animated by this layer. If null, this | ||
| * layer can animate the entire model. | ||
| */ | ||
| private final AnimationMask mask; | ||
| private AnimationMask mask; | ||
| /** | ||
| * The current animation time, in scaled seconds. Always non-negative. | ||
| */ | ||
|
|
@@ -79,23 +81,26 @@ public class AnimLayer implements JmeCloneable { | |
| /** | ||
| * The name of this layer. | ||
| */ | ||
| final private String name; | ||
| private String name; | ||
|
|
||
| private boolean loop = true; | ||
|
|
||
| /** | ||
| * For serialization only. Do not use. | ||
| */ | ||
| protected AnimLayer() { | ||
neph1 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| } | ||
|
|
||
| /** | ||
| * Instantiates a layer without a manager or a current Action, owned by the | ||
| * specified composer. | ||
| * | ||
| * @param composer the owner (not null, alias created) | ||
| * @param name the layer name (not null) | ||
| * @param mask the AnimationMask (alias created) or null to allow this layer | ||
| * to animate the entire model | ||
| */ | ||
| AnimLayer(AnimComposer composer, String name, AnimationMask mask) { | ||
| assert composer != null; | ||
| this.composer = composer; | ||
|
|
||
| AnimLayer(String name, AnimationMask mask) { | ||
neph1 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| assert name != null; | ||
| this.name = name; | ||
|
|
||
|
|
@@ -248,14 +253,15 @@ public void setLooping(boolean loop) { | |
| * | ||
| * @param appDeltaTimeInSeconds the amount application time to advance the | ||
| * current Action, in seconds | ||
| * @param globalSpeed the global speed applied to all layers. | ||
| */ | ||
| void update(float appDeltaTimeInSeconds) { | ||
| void update(float appDeltaTimeInSeconds, float globalSpeed) { | ||
| Action action = currentAction; | ||
| if (action == null) { | ||
| return; | ||
| } | ||
|
|
||
| double speedup = action.getSpeed() * composer.getGlobalSpeed(); | ||
| double speedup = action.getSpeed() * globalSpeed; | ||
| double scaledDeltaTime = speedup * appDeltaTimeInSeconds; | ||
| time += scaledDeltaTime; | ||
|
|
||
|
|
@@ -292,7 +298,6 @@ void update(float appDeltaTimeInSeconds) { | |
| */ | ||
| @Override | ||
| public void cloneFields(Cloner cloner, Object original) { | ||
| composer = cloner.clone(composer); | ||
| currentAction = null; | ||
| currentActionName = null; | ||
| } | ||
|
|
@@ -306,4 +311,20 @@ public Object jmeClone() { | |
| throw new AssertionError(); | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public void write(JmeExporter ex) throws IOException { | ||
| OutputCapsule oc = ex.getCapsule(this); | ||
| oc.write(name, "name", null); | ||
| if (mask instanceof Savable) { | ||
| oc.write((Savable) mask, "mask", null); | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public void read(JmeImporter im) throws IOException { | ||
| InputCapsule ic = im.getCapsule(this); | ||
| name = ic.readString("name", null); | ||
| mask = (AnimationMask) ic.readSavable("mask", null); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.