use of com.jme3.ui.Picture in project jmonkeyengine by jMonkeyEngine.
the class Picture method setWidth.
/**
* Set the width in pixels of the picture, if the width
* does not match the texture's width, then the texture will
* be scaled to fit the picture.
*
* @param width the width to set.
*/
public void setWidth(float width) {
this.width = width;
setLocalScale(new Vector3f(width, height, 1f));
}
use of com.jme3.ui.Picture in project jmonkeyengine by jMonkeyEngine.
the class TestDepthStencil method simpleInitApp.
@Override
public void simpleInitApp() {
int w = settings.getWidth();
int h = settings.getHeight();
//setup framebuffer
fb = new FrameBuffer(w, h, 1);
Texture2D fbTex = new Texture2D(w, h, Format.RGB8);
fb.setDepthBuffer(Format.Depth24Stencil8);
fb.setColorTexture(fbTex);
// setup framebuffer's scene
Sphere sphMesh = new Sphere(20, 20, 1);
Material solidColor = assetManager.loadMaterial("Common/Materials/RedColor.j3m");
final Geometry sphere = new Geometry("sphere", sphMesh);
sphere.setMaterial(solidColor);
fbNode.attachChild(sphere);
sphere.addControl(new AbstractControl() {
@Override
protected void controlUpdate(float tpf) {
Material mat = sphere.getMaterial();
mat.getAdditionalRenderState().setStencil(enableStencil, RenderState.StencilOperation.Keep, RenderState.StencilOperation.Keep, RenderState.StencilOperation.Keep, RenderState.StencilOperation.Keep, RenderState.StencilOperation.Keep, RenderState.StencilOperation.Keep, RenderState.TestFunction.Never, RenderState.TestFunction.Never);
}
@Override
protected void controlRender(RenderManager rm, ViewPort vp) {
}
});
//setup main scene
Picture p = new Picture("Picture");
p.setPosition(0, 0);
p.setWidth(w);
p.setHeight(h);
p.setTexture(assetManager, fbTex, false);
rootNode.attachChild(p);
inputManager.addMapping("toggle", new KeyTrigger(KeyInput.KEY_SPACE));
ActionListener acl = new ActionListener() {
public void onAction(String name, boolean keyPressed, float tpf) {
if (name.equals("toggle") && keyPressed) {
if (enableStencil) {
enableStencil = false;
System.out.println("Stencil Enabled (model should be hidden)");
} else {
enableStencil = true;
System.out.println("Stencil Disabled (model should be visible)");
}
}
}
};
inputManager.addListener(acl, "toggle");
System.out.println("Press space to toggle stencil");
}
use of com.jme3.ui.Picture in project jmonkeyengine by jMonkeyEngine.
the class EnvMapUtils method getCubeMapCrossDebugView.
/**
* Creates a debug Node of the given cube map to attach to the gui node
*
* the cube map is layered this way :
* <pre>
* _____
* | |
* | +Y |
* _____|_____|_____ _____
* | | | | |
* | -X | +Z | +X | -Z |
* |_____|_____|_____|_____|
* | |
* | -Y |
* |_____|
*
*</pre>
*
* @param cubeMap the cube map
* @param assetManager the asset Manager
* @return
*/
public static Node getCubeMapCrossDebugView(TextureCubeMap cubeMap, AssetManager assetManager) {
Node n = new Node("CubeMapDebug" + cubeMap.getName());
int size = cubeMap.getImage().getWidth();
Picture[] pics = new Picture[6];
float ratio = 128f / (float) size;
for (int i = 0; i < 6; i++) {
pics[i] = new Picture("bla");
Texture2D tex = new Texture2D(new Image(cubeMap.getImage().getFormat(), size, size, cubeMap.getImage().getData(i), cubeMap.getImage().getColorSpace()));
pics[i].setTexture(assetManager, tex, true);
pics[i].setWidth(size);
pics[i].setHeight(size);
n.attachChild(pics[i]);
}
pics[0].setLocalTranslation(size, size * 2, 1);
pics[0].setLocalRotation(new Quaternion().fromAngleAxis(PI, Vector3f.UNIT_Z));
pics[1].setLocalTranslation(size * 3, size * 2, 1);
pics[1].setLocalRotation(new Quaternion().fromAngleAxis(PI, Vector3f.UNIT_Z));
pics[2].setLocalTranslation(size * 2, size * 3, 1);
pics[2].setLocalRotation(new Quaternion().fromAngleAxis(PI, Vector3f.UNIT_Z));
pics[3].setLocalTranslation(size * 2, size, 1);
pics[3].setLocalRotation(new Quaternion().fromAngleAxis(PI, Vector3f.UNIT_Z));
pics[4].setLocalTranslation(size * 2, size * 2, 1);
pics[4].setLocalRotation(new Quaternion().fromAngleAxis(PI, Vector3f.UNIT_Z));
pics[5].setLocalTranslation(size * 4, size * 2, 1);
pics[5].setLocalRotation(new Quaternion().fromAngleAxis(PI, Vector3f.UNIT_Z));
Quad q = new Quad(size * 4, size * 3);
Geometry g = new Geometry("bg", q);
Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
mat.setColor("Color", ColorRGBA.Black);
g.setMaterial(mat);
g.setLocalTranslation(0, 0, 0);
n.attachChild(g);
n.setLocalScale(ratio);
return n;
}
use of com.jme3.ui.Picture in project jmonkeyengine by jMonkeyEngine.
the class SimpleWaterProcessor method initialize.
public void initialize(RenderManager rm, ViewPort vp) {
this.rm = rm;
this.vp = vp;
loadTextures(manager);
createTextures();
applyTextures(material);
createPreViews();
material.setVector2("FrustumNearFar", new Vector2f(vp.getCamera().getFrustumNear(), vp.getCamera().getFrustumFar()));
if (debug) {
dispRefraction = new Picture("dispRefraction");
dispRefraction.setTexture(manager, refractionTexture, false);
dispReflection = new Picture("dispRefraction");
dispReflection.setTexture(manager, reflectionTexture, false);
dispDepth = new Picture("depthTexture");
dispDepth.setTexture(manager, depthTexture, false);
}
}
use of com.jme3.ui.Picture in project jmonkeyengine by jMonkeyEngine.
the class EnvMapUtils method getCubeMapCrossDebugViewWithMipMaps.
public static Node getCubeMapCrossDebugViewWithMipMaps(TextureCubeMap cubeMap, AssetManager assetManager) {
Node n = new Node("CubeMapDebug" + cubeMap.getName());
int size = cubeMap.getImage().getWidth();
int nbMips = cubeMap.getImage().getMipMapSizes().length;
Picture[] pics = new Picture[6 * nbMips];
// 128f / (float) size;
float ratio = 1f;
int offset = 0;
int guiOffset = 0;
for (int mipLevel = 0; mipLevel < nbMips; mipLevel++) {
size = Math.max(1, cubeMap.getImage().getWidth() >> mipLevel);
int dataSize = cubeMap.getImage().getMipMapSizes()[mipLevel];
byte[] dataArray = new byte[dataSize];
for (int i = 0; i < 6; i++) {
ByteBuffer bb = cubeMap.getImage().getData(i);
bb.rewind();
bb.position(offset);
bb.get(dataArray, 0, dataSize);
ByteBuffer data = BufferUtils.createByteBuffer(dataArray);
pics[i] = new Picture("bla");
Texture2D tex = new Texture2D(new Image(cubeMap.getImage().getFormat(), size, size, data, cubeMap.getImage().getColorSpace()));
pics[i].setTexture(assetManager, tex, true);
pics[i].setWidth(size);
pics[i].setHeight(size);
n.attachChild(pics[i]);
}
pics[0].setLocalTranslation(guiOffset + size, guiOffset + size * 2, 1);
pics[0].setLocalRotation(new Quaternion().fromAngleAxis(PI, Vector3f.UNIT_Z));
pics[1].setLocalTranslation(guiOffset + size * 3, guiOffset + size * 2, 1);
pics[1].setLocalRotation(new Quaternion().fromAngleAxis(PI, Vector3f.UNIT_Z));
pics[2].setLocalTranslation(guiOffset + size * 2, guiOffset + size * 3, 1);
pics[2].setLocalRotation(new Quaternion().fromAngleAxis(PI, Vector3f.UNIT_Z));
pics[3].setLocalTranslation(guiOffset + size * 2, guiOffset + size, 1);
pics[3].setLocalRotation(new Quaternion().fromAngleAxis(PI, Vector3f.UNIT_Z));
pics[4].setLocalTranslation(guiOffset + size * 2, guiOffset + size * 2, 1);
pics[4].setLocalRotation(new Quaternion().fromAngleAxis(PI, Vector3f.UNIT_Z));
pics[5].setLocalTranslation(guiOffset + size * 4, guiOffset + size * 2, 1);
pics[5].setLocalRotation(new Quaternion().fromAngleAxis(PI, Vector3f.UNIT_Z));
guiOffset += size * 2 + 1;
offset += dataSize;
}
Quad q = new Quad(cubeMap.getImage().getWidth() * 4 + nbMips, guiOffset + size);
Geometry g = new Geometry("bg", q);
Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
mat.setColor("Color", ColorRGBA.Black);
g.setMaterial(mat);
g.setLocalTranslation(0, 0, 0);
n.attachChild(g);
n.setLocalScale(ratio);
return n;
}
Aggregations