Просмотр исходного кода

make TestMorph (in jme3-examples) more user-friendly

Stephen Gold 5 лет назад
Родитель
Сommit
1a05e3fc5f
1 измененных файлов с 27 добавлено и 12 удалено
  1. 27 12
      jme3-examples/src/main/java/jme3test/model/anim/TestMorph.java

+ 27 - 12
jme3-examples/src/main/java/jme3test/model/anim/TestMorph.java

@@ -3,12 +3,14 @@ package jme3test.model.anim;
 import com.jme3.anim.MorphControl;
 import com.jme3.app.ChaseCameraAppState;
 import com.jme3.app.SimpleApplication;
+import com.jme3.font.BitmapFont;
+import com.jme3.font.BitmapText;
 import com.jme3.input.KeyInput;
 import com.jme3.input.controls.ActionListener;
 import com.jme3.input.controls.AnalogListener;
 import com.jme3.input.controls.KeyTrigger;
 import com.jme3.material.Material;
-import com.jme3.math.ColorRGBA;
+import com.jme3.material.RenderState;
 import com.jme3.scene.Geometry;
 import com.jme3.scene.VertexBuffer;
 import com.jme3.scene.mesh.MorphTarget;
@@ -28,7 +30,16 @@ public class TestMorph extends SimpleApplication {
 
     @Override
     public void simpleInitApp() {
+        BitmapFont font = assetManager.loadFont("Interface/Fonts/Default.fnt");
+        BitmapText text = new BitmapText(font, false);
+        text.setText("Press U-Y-I-J to vary weights. Drag LMB to orbit camera.");
+        text.setLocalTranslation(10f, cam.getHeight() - 10f, 0f);
+        guiNode.attachChild(text);
+
         final Box box = new Box(1, 1, 1);
+        /*
+         * Add a morph target that increases X coordinates of the "right" face.
+         */
         FloatBuffer buffer = BufferUtils.createVector3Buffer(box.getVertexCount());
 
         float[] d = new float[box.getVertexCount() * 3];
@@ -36,10 +47,10 @@ public class TestMorph extends SimpleApplication {
             d[i] = 0;
         }
 
-        d[12] = 1f;
-        d[15] = 1f;
-        d[18] = 1f;
-        d[21] = 1f;
+        d[12] = 3f;
+        d[15] = 3f;
+        d[18] = 3f;
+        d[21] = 3f;
 
         buffer.put(d);
         buffer.rewind();
@@ -47,18 +58,19 @@ public class TestMorph extends SimpleApplication {
         MorphTarget target = new MorphTarget();
         target.setBuffer(VertexBuffer.Type.Position, buffer);
         box.addMorphTarget(target);
-
-
+        /*
+         * Add a morph target that increases Y coordinates of the "right" face.
+         */
         buffer = BufferUtils.createVector3Buffer(box.getVertexCount());
 
         for (int i = 0; i < d.length; i++) {
             d[i] = 0;
         }
 
-        d[13] = 1f;
-        d[16] = 1f;
-        d[19] = 1f;
-        d[22] = 1f;
+        d[13] = 3f;
+        d[16] = 3f;
+        d[19] = 3f;
+        d[22] = 3f;
 
         buffer.put(d);
         buffer.rewind();
@@ -70,7 +82,8 @@ public class TestMorph extends SimpleApplication {
         final Geometry g = new Geometry("box", box);
         Material m = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
         g.setMaterial(m);
-        m.setColor("Color", ColorRGBA.Red);
+        m.getAdditionalRenderState().setFaceCullMode(RenderState.FaceCullMode.Off);
+        m.setTexture("ColorMap", assetManager.loadTexture("Interface/Logo/Monkey.jpg"));
         m.setInt("NumberOfMorphTargets", 2);
 
         rootNode.attachChild(g);
@@ -103,6 +116,8 @@ public class TestMorph extends SimpleApplication {
                 if (name.equals("morphdown")) {
                     weights[1] -= tpf;
                 }
+                weights[0] = Math.max(0f, weights[0]);
+                weights[1] = Math.max(0f, weights[1]);
                 g.setMorphState(weights);
 
             }