Skip to content

Commit b974f71

Browse files
authored
added test class (#2218)
1 parent 1cbdcd3 commit b974f71

File tree

1 file changed

+150
-0
lines changed

1 file changed

+150
-0
lines changed
Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
/*
2+
* Copyright (c) 2024 jMonkeyEngine
3+
* All rights reserved.
4+
*
5+
* Redistribution and use in source and binary forms, with or without
6+
* modification, are permitted provided that the following conditions are
7+
* met:
8+
*
9+
* * Redistributions of source code must retain the above copyright
10+
* notice, this list of conditions and the following disclaimer.
11+
*
12+
* * Redistributions in binary form must reproduce the above copyright
13+
* notice, this list of conditions and the following disclaimer in the
14+
* documentation and/or other materials provided with the distribution.
15+
*
16+
* * Neither the name of 'jMonkeyEngine' nor the names of its contributors
17+
* may be used to endorse or promote products derived from this software
18+
* without specific prior written permission.
19+
*
20+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21+
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22+
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23+
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24+
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25+
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26+
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
27+
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
28+
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
29+
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30+
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31+
*/
32+
package jme3test.model.anim;
33+
34+
import com.jme3.anim.AnimComposer;
35+
import com.jme3.anim.ArmatureMask;
36+
import com.jme3.anim.SingleLayerInfluenceMask;
37+
import com.jme3.anim.SkinningControl;
38+
import com.jme3.anim.tween.action.ClipAction;
39+
import com.jme3.anim.util.AnimMigrationUtils;
40+
import com.jme3.app.SimpleApplication;
41+
import com.jme3.font.BitmapFont;
42+
import com.jme3.font.BitmapText;
43+
import com.jme3.input.KeyInput;
44+
import com.jme3.input.controls.ActionListener;
45+
import com.jme3.input.controls.KeyTrigger;
46+
import com.jme3.light.DirectionalLight;
47+
import com.jme3.math.ColorRGBA;
48+
import com.jme3.math.Vector3f;
49+
import com.jme3.scene.Spatial;
50+
51+
/**
52+
* Tests {@link SingleLayerInfluenceMask}.
53+
*
54+
* The test runs two simultaneous looping actions on seperate layers.
55+
* <p>
56+
* The test <strong>fails</strong> if the visible dancing action does <em>not</em>
57+
* loop seamlessly when using SingleLayerInfluenceMasks. Note that the action is not
58+
* expected to loop seamlessly when <em>not</em> using SingleLayerArmatureMasks.
59+
* <p>
60+
* Press the spacebar to switch between using SingleLayerInfluenceMasks and masks
61+
* provided by {@link ArmatureMask}.
62+
*
63+
* @author codex
64+
*/
65+
public class TestSingleLayerInfluenceMask extends SimpleApplication implements ActionListener {
66+
67+
private Spatial model;
68+
private AnimComposer anim;
69+
private SkinningControl skin;
70+
private boolean useSLIMask = true;
71+
private BitmapText display;
72+
73+
public static void main(String[] args) {
74+
TestSingleLayerInfluenceMask app = new TestSingleLayerInfluenceMask();
75+
app.start();
76+
}
77+
78+
@Override
79+
public void simpleInitApp() {
80+
81+
flyCam.setMoveSpeed(30f);
82+
83+
DirectionalLight dl = new DirectionalLight();
84+
dl.setDirection(new Vector3f(-0.1f, -0.7f, -1).normalizeLocal());
85+
dl.setColor(new ColorRGBA(1f, 1f, 1f, 1.0f));
86+
rootNode.addLight(dl);
87+
88+
BitmapFont font = assetManager.loadFont("Interface/Fonts/Default.fnt");
89+
display = new BitmapText(font);
90+
display.setSize(font.getCharSet().getRenderedSize());
91+
display.setText("");
92+
display.setLocalTranslation(5, context.getSettings().getHeight()-5, 0);
93+
guiNode.attachChild(display);
94+
95+
inputManager.addMapping("reset", new KeyTrigger(KeyInput.KEY_SPACE));
96+
inputManager.addListener(this, "reset");
97+
98+
setupModel();
99+
100+
}
101+
@Override
102+
public void simpleUpdate(float tpf) {
103+
cam.lookAt(model.getWorldTranslation(), Vector3f.UNIT_Y);
104+
}
105+
@Override
106+
public void onAction(String name, boolean isPressed, float tpf) {
107+
if (name.equals("reset") && isPressed) {
108+
model.removeFromParent();
109+
setupModel();
110+
}
111+
}
112+
113+
private void setupModel() {
114+
115+
model = assetManager.loadModel("Models/Sinbad/SinbadOldAnim.j3o");
116+
AnimMigrationUtils.migrate(model);
117+
anim = model.getControl(AnimComposer.class);
118+
skin = model.getControl(SkinningControl.class);
119+
120+
if (useSLIMask) {
121+
SingleLayerInfluenceMask walkLayer = new SingleLayerInfluenceMask("idleLayer", anim, skin);
122+
walkLayer.addAll();
123+
walkLayer.makeLayer();
124+
SingleLayerInfluenceMask danceLayer = new SingleLayerInfluenceMask("danceLayer", anim, skin);
125+
danceLayer.addAll();
126+
danceLayer.makeLayer();
127+
} else {
128+
anim.makeLayer("idleLayer", ArmatureMask.createMask(skin.getArmature(), "Root"));
129+
anim.makeLayer("danceLayer", ArmatureMask.createMask(skin.getArmature(), "Root"));
130+
}
131+
132+
setSLIMaskInfo();
133+
useSLIMask = !useSLIMask;
134+
135+
ClipAction clip = (ClipAction)anim.action("Dance");
136+
clip.setMaxTransitionWeight(.9f);
137+
ClipAction clip2 = (ClipAction)anim.action("IdleTop");
138+
clip2.setMaxTransitionWeight(.8f);
139+
140+
anim.setCurrentAction("Dance", "danceLayer");
141+
anim.setCurrentAction("IdleTop", "idleLayer");
142+
143+
rootNode.attachChild(model);
144+
145+
}
146+
private void setSLIMaskInfo() {
147+
display.setText("Using SingleLayerInfluenceMasks: "+useSLIMask+"\nPress Spacebar to switch masks");
148+
}
149+
150+
}

0 commit comments

Comments
 (0)