use of com.jme3.texture.Image in project jmonkeyengine by jMonkeyEngine.
the class TestTexture3D method simpleInitApp.
@Override
public void simpleInitApp() {
//mouseInput.setCursorVisible(true);
flyCam.setMoveSpeed(10);
//creating a sphere
Sphere sphere = new Sphere(32, 32, 1);
//getting the boundingbox
sphere.updateBound();
BoundingBox bb = (BoundingBox) sphere.getBound();
Vector3f min = bb.getMin(null);
float[] ext = new float[] { bb.getXExtent() * 2, bb.getYExtent() * 2, bb.getZExtent() * 2 };
//we need to change the UV coordinates (the sphere is assumet to be inside the 3D image box)
sphere.clearBuffer(Type.TexCoord);
VertexBuffer vb = sphere.getBuffer(Type.Position);
FloatBuffer fb = (FloatBuffer) vb.getData();
float[] uvCoordinates = BufferUtils.getFloatArray(fb);
//now transform the coordinates so that they are in the range of <0; 1>
for (int i = 0; i < uvCoordinates.length; i += 3) {
uvCoordinates[i] = (uvCoordinates[i] - min.x) / ext[0];
uvCoordinates[i + 1] = (uvCoordinates[i + 1] - min.y) / ext[1];
uvCoordinates[i + 2] = (uvCoordinates[i + 2] - min.z) / ext[2];
}
//apply new texture coordinates
VertexBuffer uvCoordsBuffer = new VertexBuffer(Type.TexCoord);
uvCoordsBuffer.setupData(Usage.Static, 3, com.jme3.scene.VertexBuffer.Format.Float, BufferUtils.createFloatBuffer(uvCoordinates));
sphere.setBuffer(uvCoordsBuffer);
//create geometry, and apply material and our 3D texture
Geometry g = new Geometry("sphere", sphere);
Material material = new Material(assetManager, "jme3test/texture/tex3D.j3md");
try {
Texture texture = this.getTexture();
material.setTexture("Texture", texture);
} catch (IOException e) {
e.printStackTrace();
}
g.setMaterial(material);
rootNode.attachChild(g);
//add some light so that it is visible
PointLight light = new PointLight();
light.setColor(ColorRGBA.White);
light.setPosition(new Vector3f(5, 5, 5));
light.setRadius(20);
rootNode.addLight(light);
light = new PointLight();
light.setColor(ColorRGBA.White);
light.setPosition(new Vector3f(-5, -5, -5));
light.setRadius(20);
rootNode.addLight(light);
}
use of com.jme3.texture.Image in project jmonkeyengine by jMonkeyEngine.
the class TestTexture3DLoading method simpleInitApp.
@Override
public void simpleInitApp() {
viewPort.setBackgroundColor(ColorRGBA.DarkGray);
flyCam.setEnabled(false);
Quad q = new Quad(10, 10);
Geometry geom = new Geometry("Quad", q);
Material material = new Material(assetManager, "jme3test/texture/tex3DThumb.j3md");
TextureKey key = new TextureKey("Textures/3D/flame.dds");
key.setGenerateMips(true);
key.setTextureTypeHint(Texture.Type.ThreeDimensional);
Texture t = assetManager.loadTexture(key);
//4 * 4
int rows = 4;
q.scaleTextureCoordinates(new Vector2f(rows, rows));
//The image only have 8 pictures and we have 16 thumbs, the data will be interpolated by the GPU
material.setFloat("InvDepth", 1f / 16f);
material.setInt("Rows", rows);
material.setTexture("Texture", t);
geom.setMaterial(material);
rootNode.attachChild(geom);
cam.setLocation(new Vector3f(4.7444625f, 5.160054f, 13.1939f));
}
use of com.jme3.texture.Image in project jmonkeyengine by jMonkeyEngine.
the class TestTextureArray method simpleInitApp.
@Override
public void simpleInitApp() {
Material mat = new Material(assetManager, "jme3test/texture/UnshadedArray.j3md");
for (Caps caps : renderManager.getRenderer().getCaps()) {
System.out.println(caps.name());
}
if (!renderManager.getRenderer().getCaps().contains(Caps.TextureArray)) {
throw new UnsupportedOperationException("Your hardware does not support TextureArray");
}
Texture tex1 = assetManager.loadTexture("Textures/Terrain/Pond/Pond.jpg");
Texture tex2 = assetManager.loadTexture("Textures/Terrain/Rock2/rock.jpg");
List<Image> images = new ArrayList<Image>();
images.add(tex1.getImage());
images.add(tex2.getImage());
TextureArray tex3 = new TextureArray(images);
tex3.setMinFilter(Texture.MinFilter.Trilinear);
mat.setTexture("ColorMap", tex3);
Mesh m = new Mesh();
Vector3f[] vertices = new Vector3f[8];
vertices[0] = new Vector3f(0, 0, 0);
vertices[1] = new Vector3f(3, 0, 0);
vertices[2] = new Vector3f(0, 3, 0);
vertices[3] = new Vector3f(3, 3, 0);
vertices[4] = new Vector3f(3, 0, 0);
vertices[5] = new Vector3f(6, 0, 0);
vertices[6] = new Vector3f(3, 3, 0);
vertices[7] = new Vector3f(6, 3, 0);
Vector3f[] texCoord = new Vector3f[8];
texCoord[0] = new Vector3f(0, 0, 0);
texCoord[1] = new Vector3f(1, 0, 0);
texCoord[2] = new Vector3f(0, 1, 0);
texCoord[3] = new Vector3f(1, 1, 0);
texCoord[4] = new Vector3f(0, 0, 1);
texCoord[5] = new Vector3f(1, 0, 1);
texCoord[6] = new Vector3f(0, 1, 1);
texCoord[7] = new Vector3f(1, 1, 1);
int[] indexes = { 2, 0, 1, 1, 3, 2, 6, 4, 5, 5, 7, 6 };
m.setBuffer(Type.Position, 3, BufferUtils.createFloatBuffer(vertices));
m.setBuffer(Type.TexCoord, 3, BufferUtils.createFloatBuffer(texCoord));
m.setBuffer(Type.Index, 1, BufferUtils.createIntBuffer(indexes));
m.updateBound();
Geometry geom = new Geometry("Mesh", m);
geom.setMaterial(mat);
rootNode.attachChild(geom);
}
use of com.jme3.texture.Image in project jmonkeyengine by jMonkeyEngine.
the class TerrainTestReadWrite method createMap.
private void createMap() {
matTerrain = new Material(assetManager, "Common/MatDefs/Terrain/TerrainLighting.j3md");
matTerrain.setBoolean("useTriPlanarMapping", false);
matTerrain.setBoolean("WardIso", true);
// ALPHA map (for splat textures)
matTerrain.setTexture("AlphaMap", assetManager.loadTexture("Textures/Terrain/splat/alphamap.png"));
// HEIGHTMAP image (for the terrain heightmap)
Texture heightMapImage = assetManager.loadTexture("Textures/Terrain/splat/mountains512.png");
// GRASS texture
Texture grass = assetManager.loadTexture("Textures/Terrain/splat/grass.jpg");
grass.setWrap(WrapMode.Repeat);
matTerrain.setTexture("DiffuseMap", grass);
matTerrain.setFloat("DiffuseMap_0_scale", grassScale);
// DIRT texture
Texture dirt = assetManager.loadTexture("Textures/Terrain/splat/dirt.jpg");
dirt.setWrap(WrapMode.Repeat);
matTerrain.setTexture("DiffuseMap_1", dirt);
matTerrain.setFloat("DiffuseMap_1_scale", dirtScale);
// ROCK texture
Texture rock = assetManager.loadTexture("Textures/Terrain/splat/road.jpg");
rock.setWrap(WrapMode.Repeat);
matTerrain.setTexture("DiffuseMap_2", rock);
matTerrain.setFloat("DiffuseMap_2_scale", rockScale);
Texture normalMap0 = assetManager.loadTexture("Textures/Terrain/splat/grass_normal.jpg");
normalMap0.setWrap(WrapMode.Repeat);
Texture normalMap1 = assetManager.loadTexture("Textures/Terrain/splat/dirt_normal.png");
normalMap1.setWrap(WrapMode.Repeat);
Texture normalMap2 = assetManager.loadTexture("Textures/Terrain/splat/road_normal.png");
normalMap2.setWrap(WrapMode.Repeat);
matTerrain.setTexture("NormalMap", normalMap0);
matTerrain.setTexture("NormalMap_1", normalMap2);
matTerrain.setTexture("NormalMap_2", normalMap2);
matWire = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
matWire.getAdditionalRenderState().setWireframe(true);
matWire.setColor("Color", ColorRGBA.Green);
// CREATE HEIGHTMAP
AbstractHeightMap heightmap = null;
try {
heightmap = new ImageBasedHeightMap(heightMapImage.getImage(), 1f);
heightmap.load();
} catch (Exception e) {
e.printStackTrace();
}
if (new File("terrainsave.jme").exists()) {
loadTerrain();
} else {
// create the terrain as normal, and give it a control for LOD management
//, new LodPerspectiveCalculatorFactory(getCamera(), 4)); // add this in to see it use entropy for LOD calculations
TerrainQuad terrainQuad = new TerrainQuad("terrain", 65, 129, heightmap.getHeightMap());
TerrainLodControl control = new TerrainLodControl(terrainQuad, getCamera());
// patch size, and a multiplier
control.setLodCalculator(new DistanceLodCalculator(65, 2.7f));
terrainQuad.addControl(control);
terrainQuad.setMaterial(matTerrain);
terrainQuad.setLocalTranslation(0, -100, 0);
terrainQuad.setLocalScale(4f, 0.25f, 4f);
rootNode.attachChild(terrainQuad);
this.terrain = terrainQuad;
}
DirectionalLight light = new DirectionalLight();
light.setDirection((new Vector3f(-0.5f, -1f, -0.5f)).normalize());
rootNode.addLight(light);
}
use of com.jme3.texture.Image in project jmonkeyengine by jMonkeyEngine.
the class IosImageLoader method load.
public Object load(AssetInfo info) throws IOException {
boolean flip = ((TextureKey) info.getKey()).isFlipY();
Image img = null;
InputStream in = null;
try {
in = info.openStream();
img = loadImageData(Format.RGBA8, flip, in);
} finally {
if (in != null) {
in.close();
}
}
return img;
}
Aggregations