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