33import  com .jme3 .anim .MorphControl ;
44import  com .jme3 .app .ChaseCameraAppState ;
55import  com .jme3 .app .SimpleApplication ;
6+ import  com .jme3 .font .BitmapFont ;
7+ import  com .jme3 .font .BitmapText ;
68import  com .jme3 .input .KeyInput ;
79import  com .jme3 .input .controls .ActionListener ;
810import  com .jme3 .input .controls .AnalogListener ;
911import  com .jme3 .input .controls .KeyTrigger ;
1012import  com .jme3 .material .Material ;
11- import  com .jme3 .math . ColorRGBA ;
13+ import  com .jme3 .material . RenderState ;
1214import  com .jme3 .scene .Geometry ;
1315import  com .jme3 .scene .VertexBuffer ;
1416import  com .jme3 .scene .mesh .MorphTarget ;
@@ -28,37 +30,47 @@ public static void main(String... args) {
2830
2931    @ Override 
3032    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+ 
3139        final  Box  box  = new  Box (1 , 1 , 1 );
40+         /* 
41+          * Add a morph target that increases X coordinates of the "right" face. 
42+          */ 
3243        FloatBuffer  buffer  = BufferUtils .createVector3Buffer (box .getVertexCount ());
3344
3445        float [] d  = new  float [box .getVertexCount () * 3 ];
3546        for  (int  i  = 0 ; i  < d .length ; i ++) {
3647            d [i ] = 0 ;
3748        }
3849
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 ;
4354
4455        buffer .put (d );
4556        buffer .rewind ();
4657
4758        MorphTarget  target  = new  MorphTarget ();
4859        target .setBuffer (VertexBuffer .Type .Position , buffer );
4960        box .addMorphTarget (target );
50- 
51- 
61+         /* 
62+          * Add a morph target that increases Y coordinates of the "right" face. 
63+          */ 
5264        buffer  = BufferUtils .createVector3Buffer (box .getVertexCount ());
5365
5466        for  (int  i  = 0 ; i  < d .length ; i ++) {
5567            d [i ] = 0 ;
5668        }
5769
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 ;
6274
6375        buffer .put (d );
6476        buffer .rewind ();
@@ -70,7 +82,8 @@ public void simpleInitApp() {
7082        final  Geometry  g  = new  Geometry ("box" , box );
7183        Material  m  = new  Material (assetManager , "Common/MatDefs/Misc/Unshaded.j3md" );
7284        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" ));
7487        m .setInt ("NumberOfMorphTargets" , 2 );
7588
7689        rootNode .attachChild (g );
@@ -103,6 +116,8 @@ public void onAnalog(String name, float value, float tpf) {
103116                if  (name .equals ("morphdown" )) {
104117                    weights [1 ] -= tpf ;
105118                }
119+                 weights [0 ] = Math .max (0f , weights [0 ]);
120+                 weights [1 ] = Math .max (0f , weights [1 ]);
106121                g .setMorphState (weights );
107122
108123            }
0 commit comments