|
@@ -1,6 +1,9 @@
|
|
|
package jme3test.material;
|
|
|
|
|
|
import com.jme3.app.SimpleApplication;
|
|
|
+import com.jme3.input.KeyInput;
|
|
|
+import com.jme3.input.controls.AnalogListener;
|
|
|
+import com.jme3.input.controls.KeyTrigger;
|
|
|
import com.jme3.material.Material;
|
|
|
import com.jme3.scene.Geometry;
|
|
|
import com.jme3.scene.Mesh;
|
|
@@ -8,27 +11,55 @@ import com.jme3.scene.VertexBuffer;
|
|
|
import com.jme3.scene.shape.Quad;
|
|
|
import com.jme3.util.BufferUtils;
|
|
|
|
|
|
+import java.util.concurrent.Callable;
|
|
|
+
|
|
|
/**
|
|
|
* Created by michael on 28.02.15.
|
|
|
*/
|
|
|
public class TestTessellationShader extends SimpleApplication {
|
|
|
+ Material tessellationMaterial;
|
|
|
+ int tessFactor=5;
|
|
|
@Override
|
|
|
public void simpleInitApp() {
|
|
|
- Material material = new Material(getAssetManager(), "Materials/Tess/SimpleTess.j3md");
|
|
|
- material.setInt("TessellationFactor", 5);
|
|
|
- material.getAdditionalRenderState().setWireframe(true);
|
|
|
+ tessellationMaterial = new Material(getAssetManager(), "Materials/Tess/SimpleTess.j3md");
|
|
|
+ tessellationMaterial.setInt("TessellationFactor", tessFactor);
|
|
|
+ tessellationMaterial.getAdditionalRenderState().setWireframe(true);
|
|
|
Quad quad = new Quad(10, 10);
|
|
|
quad.clearBuffer(VertexBuffer.Type.Index);
|
|
|
quad.setBuffer(VertexBuffer.Type.Index, 4, BufferUtils.createIntBuffer(0, 1, 2, 3));
|
|
|
quad.setMode(Mesh.Mode.Patch);
|
|
|
quad.setPatchVertexCount(4);
|
|
|
Geometry geometry = new Geometry("tessTest", quad);
|
|
|
- geometry.setMaterial(material);
|
|
|
+ geometry.setMaterial(tessellationMaterial);
|
|
|
rootNode.attachChild(geometry);
|
|
|
|
|
|
- Geometry geometry1 = new Geometry("Demo", new Quad(2, 2));
|
|
|
- geometry1.setMaterial(new Material(getAssetManager(),"Common/MatDefs/Misc/Unshaded.j3md"));
|
|
|
- rootNode.attachChild(geometry1);
|
|
|
+ getInputManager().addMapping("TessUp", new KeyTrigger(KeyInput.KEY_A));
|
|
|
+ getInputManager().addMapping("TessDo", new KeyTrigger(KeyInput.KEY_Y));
|
|
|
+ getInputManager().addListener(new AnalogListener() {
|
|
|
+ @Override
|
|
|
+ public void onAnalog(String name, float value, float tpf) {
|
|
|
+ if(name.equals("TessUp")){
|
|
|
+ tessFactor++;
|
|
|
+ enqueue(new Callable<Boolean>() {
|
|
|
+ @Override
|
|
|
+ public Boolean call() throws Exception {
|
|
|
+ tessellationMaterial.setInt("TessellationFactor",tessFactor);
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ if(name.equals("TessDo")){
|
|
|
+ tessFactor--;
|
|
|
+ enqueue(new Callable<Boolean>() {
|
|
|
+ @Override
|
|
|
+ public Boolean call() throws Exception {
|
|
|
+ tessellationMaterial.setInt("TessellationFactor",tessFactor);
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+ },"TessUp","TessDo");
|
|
|
}
|
|
|
|
|
|
public static void main(String[] args) {
|