3
3
import com .jme3 .anim .MorphControl ;
4
4
import com .jme3 .app .ChaseCameraAppState ;
5
5
import com .jme3 .app .SimpleApplication ;
6
+ import com .jme3 .font .BitmapFont ;
7
+ import com .jme3 .font .BitmapText ;
6
8
import com .jme3 .input .KeyInput ;
7
9
import com .jme3 .input .controls .ActionListener ;
8
10
import com .jme3 .input .controls .AnalogListener ;
9
11
import com .jme3 .input .controls .KeyTrigger ;
10
12
import com .jme3 .material .Material ;
11
- import com .jme3 .math . ColorRGBA ;
13
+ import com .jme3 .material . RenderState ;
12
14
import com .jme3 .scene .Geometry ;
13
15
import com .jme3 .scene .VertexBuffer ;
14
16
import com .jme3 .scene .mesh .MorphTarget ;
@@ -28,37 +30,47 @@ public static void main(String... args) {
28
30
29
31
@ Override
30
32
public void simpleInitApp () {
33
+ BitmapFont font = assetManager .loadFont ("Interface/Fonts/Default.fnt" );
34
+ BitmapText text = new BitmapText (font , false );
35
+ text .setText ("Press U-Y-I-J to vary weights. Drag LMB to orbit camera." );
36
+ text .setLocalTranslation (10f , cam .getHeight () - 10f , 0f );
37
+ guiNode .attachChild (text );
38
+
31
39
final Box box = new Box (1 , 1 , 1 );
40
+ /*
41
+ * Add a morph target that increases X coordinates of the "right" face.
42
+ */
32
43
FloatBuffer buffer = BufferUtils .createVector3Buffer (box .getVertexCount ());
33
44
34
45
float [] d = new float [box .getVertexCount () * 3 ];
35
46
for (int i = 0 ; i < d .length ; i ++) {
36
47
d [i ] = 0 ;
37
48
}
38
49
39
- d [12 ] = 1f ;
40
- d [15 ] = 1f ;
41
- d [18 ] = 1f ;
42
- d [21 ] = 1f ;
50
+ d [12 ] = 3f ;
51
+ d [15 ] = 3f ;
52
+ d [18 ] = 3f ;
53
+ d [21 ] = 3f ;
43
54
44
55
buffer .put (d );
45
56
buffer .rewind ();
46
57
47
58
MorphTarget target = new MorphTarget ();
48
59
target .setBuffer (VertexBuffer .Type .Position , buffer );
49
60
box .addMorphTarget (target );
50
-
51
-
61
+ /*
62
+ * Add a morph target that increases Y coordinates of the "right" face.
63
+ */
52
64
buffer = BufferUtils .createVector3Buffer (box .getVertexCount ());
53
65
54
66
for (int i = 0 ; i < d .length ; i ++) {
55
67
d [i ] = 0 ;
56
68
}
57
69
58
- d [13 ] = 1f ;
59
- d [16 ] = 1f ;
60
- d [19 ] = 1f ;
61
- d [22 ] = 1f ;
70
+ d [13 ] = 3f ;
71
+ d [16 ] = 3f ;
72
+ d [19 ] = 3f ;
73
+ d [22 ] = 3f ;
62
74
63
75
buffer .put (d );
64
76
buffer .rewind ();
@@ -70,7 +82,8 @@ public void simpleInitApp() {
70
82
final Geometry g = new Geometry ("box" , box );
71
83
Material m = new Material (assetManager , "Common/MatDefs/Misc/Unshaded.j3md" );
72
84
g .setMaterial (m );
73
- m .setColor ("Color" , ColorRGBA .Red );
85
+ m .getAdditionalRenderState ().setFaceCullMode (RenderState .FaceCullMode .Off );
86
+ m .setTexture ("ColorMap" , assetManager .loadTexture ("Interface/Logo/Monkey.jpg" ));
74
87
m .setInt ("NumberOfMorphTargets" , 2 );
75
88
76
89
rootNode .attachChild (g );
@@ -103,6 +116,8 @@ public void onAnalog(String name, float value, float tpf) {
103
116
if (name .equals ("morphdown" )) {
104
117
weights [1 ] -= tpf ;
105
118
}
119
+ weights [0 ] = Math .max (0f , weights [0 ]);
120
+ weights [1 ] = Math .max (0f , weights [1 ]);
106
121
g .setMorphState (weights );
107
122
108
123
}
0 commit comments