use of com.jme3.texture.Texture in project jmonkeyengine by jMonkeyEngine.
the class OpaqueComparatorTest method testSortByAll.
@Test
public void testSortByAll() {
Material matBase1 = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md");
Material matBase2 = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
Texture texBase = createTexture("BASE");
texBase.getImage().setId(1);
Texture tex1 = createTexture("1");
tex1.getImage().setId(2);
Texture tex2 = createTexture("2");
tex2.getImage().setId(3);
matBase1.setName("BASE");
matBase1.selectTechnique(TechniqueDef.DEFAULT_TECHNIQUE_NAME, renderManager);
matBase1.setBoolean("UseVertexColor", true);
matBase1.setTexture("DiffuseMap", texBase);
Material mat1100 = matBase1.clone();
mat1100.setName("1100");
mat1100.selectTechnique("PreShadow", renderManager);
Material mat1101 = matBase1.clone();
mat1101.setName("1101");
mat1101.selectTechnique("PreShadow", renderManager);
mat1101.setTexture("DiffuseMap", tex1);
Material mat1102 = matBase1.clone();
mat1102.setName("1102");
mat1102.selectTechnique("PreShadow", renderManager);
mat1102.setTexture("DiffuseMap", tex2);
Material mat1110 = matBase1.clone();
mat1110.setName("1110");
mat1110.selectTechnique("PreShadow", renderManager);
mat1110.setFloat("AlphaDiscardThreshold", 2f);
Material mat1120 = matBase1.clone();
mat1120.setName("1120");
mat1120.selectTechnique("PreShadow", renderManager);
mat1120.setBoolean("UseInstancing", true);
Material mat1121 = matBase1.clone();
mat1121.setName("1121");
mat1121.selectTechnique("PreShadow", renderManager);
mat1121.setBoolean("UseInstancing", true);
mat1121.setTexture("DiffuseMap", tex1);
Material mat1122 = matBase1.clone();
mat1122.setName("1122");
mat1122.selectTechnique("PreShadow", renderManager);
mat1122.setBoolean("UseInstancing", true);
mat1122.setTexture("DiffuseMap", tex2);
Material mat1140 = matBase1.clone();
mat1140.setName("1140");
mat1140.selectTechnique("PreShadow", renderManager);
mat1140.setFloat("AlphaDiscardThreshold", 2f);
mat1140.setBoolean("UseInstancing", true);
Material mat1200 = matBase1.clone();
mat1200.setName("1200");
mat1200.selectTechnique("PostShadow", renderManager);
Material mat1210 = matBase1.clone();
mat1210.setName("1210");
mat1210.selectTechnique("PostShadow", renderManager);
mat1210.setFloat("AlphaDiscardThreshold", 2f);
Material mat1220 = matBase1.clone();
mat1220.setName("1220");
mat1220.selectTechnique("PostShadow", renderManager);
mat1220.setBoolean("UseInstancing", true);
Material mat2000 = matBase2.clone();
mat2000.setName("2000");
testSort(mat1100, mat1101, mat1102, mat1110, mat1120, mat1121, mat1122, mat1140, mat1200, mat1210, mat1220, mat2000);
}
use of com.jme3.texture.Texture in project jmonkeyengine by jMonkeyEngine.
the class OpaqueComparatorTest method createTexture.
private Texture createTexture(String name) {
ByteBuffer bb = BufferUtils.createByteBuffer(3);
Image image = new Image(Format.RGB8, 1, 1, bb, ColorSpace.sRGB);
Texture2D texture = new Texture2D(image);
texture.setName(name);
return texture;
}
use of com.jme3.texture.Texture in project jmonkeyengine by jMonkeyEngine.
the class DDSLoader method load.
public Object load(AssetInfo info) throws IOException {
if (!(info.getKey() instanceof TextureKey)) {
throw new IllegalArgumentException("Texture assets must be loaded using a TextureKey");
}
InputStream stream = null;
try {
stream = info.openStream();
in = new LittleEndien(stream);
loadHeader();
if (texture3D) {
((TextureKey) info.getKey()).setTextureTypeHint(Texture.Type.ThreeDimensional);
} else if (depth > 1) {
((TextureKey) info.getKey()).setTextureTypeHint(Texture.Type.CubeMap);
}
ArrayList<ByteBuffer> data = readData(((TextureKey) info.getKey()).isFlipY());
return new Image(pixelFormat, width, height, depth, data, sizes, ColorSpace.sRGB);
} finally {
if (stream != null) {
stream.close();
}
}
}
use of com.jme3.texture.Texture in project jmonkeyengine by jMonkeyEngine.
the class TextureAtlas method applyCoords.
/**
* Applies the texture coordinates to the given output mesh
* if the DiffuseMap or ColorMap of the input geometry exist in the atlas.
* @param geom The geometry to change the texture coordinate buffer on.
* @param offset Target buffer offset.
* @param outMesh The mesh to set the coords in (can be same as input).
* @return true if texture has been found and coords have been changed, false otherwise.
*/
public boolean applyCoords(Geometry geom, int offset, Mesh outMesh) {
Mesh inMesh = geom.getMesh();
geom.computeWorldMatrix();
VertexBuffer inBuf = inMesh.getBuffer(Type.TexCoord);
VertexBuffer outBuf = outMesh.getBuffer(Type.TexCoord);
if (inBuf == null || outBuf == null) {
throw new IllegalStateException("Geometry mesh has no texture coordinate buffer.");
}
Texture tex = getMaterialTexture(geom, "DiffuseMap");
if (tex == null) {
tex = getMaterialTexture(geom, "ColorMap");
}
if (tex != null) {
TextureAtlasTile tile = getAtlasTile(tex);
if (tile != null) {
FloatBuffer inPos = (FloatBuffer) inBuf.getData();
FloatBuffer outPos = (FloatBuffer) outBuf.getData();
tile.transformTextureCoords(inPos, offset, outPos);
return true;
} else {
return false;
}
} else {
throw new IllegalStateException("Geometry has no proper texture.");
}
}
use of com.jme3.texture.Texture in project jmonkeyengine by jMonkeyEngine.
the class TextureAtlas method makeAtlasBatch.
/**
* Creates one geometry out of the given root spatial and merges all single
* textures into one texture of the given size.
* @param spat The root spatial of the scene to batch
* @param mgr An assetmanager that can be used to create the material.
* @param atlasSize A size for the atlas texture, it has to be large enough to hold all single textures.
* @return A new geometry that uses the generated texture atlas and merges all meshes of the root spatial, null if the atlas cannot be created because not all textures fit.
*/
public static Geometry makeAtlasBatch(Spatial spat, AssetManager mgr, int atlasSize) {
List<Geometry> geometries = new ArrayList<Geometry>();
GeometryBatchFactory.gatherGeoms(spat, geometries);
TextureAtlas atlas = createAtlas(spat, atlasSize);
if (atlas == null) {
return null;
}
Geometry geom = new Geometry();
Mesh mesh = new Mesh();
GeometryBatchFactory.mergeGeometries(geometries, mesh);
applyAtlasCoords(geometries, mesh, atlas);
mesh.updateCounts();
mesh.updateBound();
geom.setMesh(mesh);
Material mat = new Material(mgr, "Common/MatDefs/Light/Lighting.j3md");
Texture diffuseMap = atlas.getAtlasTexture("DiffuseMap");
Texture normalMap = atlas.getAtlasTexture("NormalMap");
Texture specularMap = atlas.getAtlasTexture("SpecularMap");
if (diffuseMap != null) {
mat.setTexture("DiffuseMap", diffuseMap);
}
if (normalMap != null) {
mat.setTexture("NormalMap", normalMap);
}
if (specularMap != null) {
mat.setTexture("SpecularMap", specularMap);
}
mat.setFloat("Shininess", 16.0f);
geom.setMaterial(mat);
return geom;
}
Aggregations