use of com.jme3.texture.Texture2D in project jmonkeyengine by jMonkeyEngine.
the class MaterialExtensionLoader method readExtendingMaterialStatement.
private void readExtendingMaterialStatement(Statement statement) throws IOException {
if (statement.getLine().startsWith("set_texture_alias")) {
String[] split = statement.getLine().split(" ", 3);
String aliasName = split[1];
String texturePath = split[2];
String jmeParamName = matExt.getTextureMapping(aliasName);
TextureKey texKey = new TextureKey(texturePath, false);
texKey.setGenerateMips(true);
Texture tex;
try {
tex = assetManager.loadTexture(texKey);
tex.setWrap(WrapMode.Repeat);
} catch (AssetNotFoundException ex) {
logger.log(Level.WARNING, "Cannot locate {0} for material {1}", new Object[] { texKey, key });
tex = new Texture2D(PlaceholderAssets.getPlaceholderImage(assetManager));
tex.setWrap(WrapMode.Repeat);
tex.setKey(texKey);
}
material.setTexture(jmeParamName, tex);
}
}
use of com.jme3.texture.Texture2D in project jmonkeyengine by jMonkeyEngine.
the class J3MLoader method parseTextureType.
private Texture parseTextureType(final VarType type, final String value) {
final List<String> textureValues = tokenizeTextureValue(value);
final List<TextureOptionValue> textureOptionValues = parseTextureOptions(textureValues);
TextureKey textureKey = null;
// If there is only one token on the value, it must be the path to the texture.
if (textureValues.size() == 1) {
textureKey = new TextureKey(textureValues.get(0), false);
} else {
String texturePath = value.trim();
// If there are no valid "new" texture options specified but the path is split into several parts, lets parse the old way.
if (isTexturePathDeclaredTheTraditionalWay(textureOptionValues, texturePath)) {
boolean flipY = false;
if (texturePath.startsWith("Flip Repeat ") || texturePath.startsWith("Repeat Flip ")) {
texturePath = texturePath.substring(12).trim();
flipY = true;
} else if (texturePath.startsWith("Flip ")) {
texturePath = texturePath.substring(5).trim();
flipY = true;
} else if (texturePath.startsWith("Repeat ")) {
texturePath = texturePath.substring(7).trim();
}
// Support path starting with quotes (double and single)
if (texturePath.startsWith("\"") || texturePath.startsWith("'")) {
texturePath = texturePath.substring(1);
}
// Support path ending with quotes (double and single)
if (texturePath.endsWith("\"") || texturePath.endsWith("'")) {
texturePath = texturePath.substring(0, texturePath.length() - 1);
}
textureKey = new TextureKey(texturePath, flipY);
}
if (textureKey == null) {
textureKey = new TextureKey(textureValues.get(textureValues.size() - 1), false);
}
// Apply texture options to the texture key
if (!textureOptionValues.isEmpty()) {
for (final TextureOptionValue textureOptionValue : textureOptionValues) {
textureOptionValue.applyToTextureKey(textureKey);
}
}
}
switch(type) {
case Texture3D:
textureKey.setTextureTypeHint(Texture.Type.ThreeDimensional);
break;
case TextureArray:
textureKey.setTextureTypeHint(Texture.Type.TwoDimensionalArray);
break;
case TextureCubeMap:
textureKey.setTextureTypeHint(Texture.Type.CubeMap);
break;
}
textureKey.setGenerateMips(true);
Texture texture;
try {
texture = assetManager.loadTexture(textureKey);
} catch (AssetNotFoundException ex) {
logger.log(Level.WARNING, "Cannot locate {0} for material {1}", new Object[] { textureKey, key });
texture = null;
}
if (texture == null) {
texture = new Texture2D(PlaceholderAssets.getPlaceholderImage(assetManager));
texture.setKey(textureKey);
texture.setName(textureKey.getName());
}
// Apply texture options to the texture
if (!textureOptionValues.isEmpty()) {
for (final TextureOptionValue textureOptionValue : textureOptionValues) {
textureOptionValue.applyToTexture(texture);
}
}
return texture;
}
use of com.jme3.texture.Texture2D in project jmonkeyengine by jMonkeyEngine.
the class MTLLoader method loadTexture.
protected Texture loadTexture(String path) {
String[] split = path.trim().split("\\p{javaWhitespace}+");
// will crash if path is an empty string
path = split[split.length - 1];
String name = new File(path).getName();
TextureKey texKey = new TextureKey(folderName + name);
texKey.setGenerateMips(true);
Texture texture;
try {
texture = assetManager.loadTexture(texKey);
texture.setWrap(WrapMode.Repeat);
} catch (AssetNotFoundException ex) {
logger.log(Level.WARNING, "Cannot locate {0} for material {1}", new Object[] { texKey, key });
texture = new Texture2D(PlaceholderAssets.getPlaceholderImage(assetManager));
texture.setWrap(WrapMode.Repeat);
texture.setKey(key);
}
return texture;
}
use of com.jme3.texture.Texture2D in project jmonkeyengine by jMonkeyEngine.
the class TestImageRaster method convertAndPutImage.
private void convertAndPutImage(Image image, float posX, float posY) {
Texture tex = new Texture2D(image);
tex.setMagFilter(MagFilter.Nearest);
tex.setMinFilter(MinFilter.NearestNoMipMaps);
tex.setAnisotropicFilter(16);
Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
mat.setTexture("ColorMap", tex);
Quad q = new Quad(5, 5);
Geometry g = new Geometry("quad", q);
g.setLocalTranslation(posX, posY - 5, -0.0001f);
g.setMaterial(mat);
rootNode.attachChild(g);
BitmapFont fnt = assetManager.loadFont("Interface/Fonts/Default.fnt");
BitmapText txt = new BitmapText(fnt);
txt.setBox(new Rectangle(0, 0, 5, 5));
txt.setQueueBucket(RenderQueue.Bucket.Transparent);
txt.setSize(0.5f);
txt.setText(image.getFormat().name());
txt.setLocalTranslation(posX, posY, 0);
rootNode.attachChild(txt);
}
use of com.jme3.texture.Texture2D 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");
}
Aggregations