use of com.jme3.asset.TextureKey in project jmonkeyengine by jMonkeyEngine.
the class TestRagdollCharacter method initWall.
public void initWall(float bLength, float bWidth, float bHeight) {
Box brick = new Box(bLength, bHeight, bWidth);
brick.scaleTextureCoordinates(new Vector2f(1f, .5f));
Material mat2 = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
TextureKey key = new TextureKey("Textures/Terrain/BrickWall/BrickWall.jpg");
key.setGenerateMips(true);
Texture tex = assetManager.loadTexture(key);
mat2.setTexture("ColorMap", tex);
float startpt = bLength / 4;
float height = -5;
for (int j = 0; j < 15; j++) {
for (int i = 0; i < 4; i++) {
Vector3f ori = new Vector3f(i * bLength * 2 + startpt, bHeight + height, -10);
Geometry reBoxg = new Geometry("brick", brick);
reBoxg.setMaterial(mat2);
reBoxg.setLocalTranslation(ori);
//for geometry with sphere mesh the physics system automatically uses a sphere collision shape
reBoxg.addControl(new RigidBodyControl(1.5f));
reBoxg.setShadowMode(ShadowMode.CastAndReceive);
reBoxg.getControl(RigidBodyControl.class).setFriction(0.6f);
this.rootNode.attachChild(reBoxg);
this.getPhysicsSpace().add(reBoxg);
}
startpt = -startpt;
height += 2 * bHeight;
}
}
use of com.jme3.asset.TextureKey in project jmonkeyengine by jMonkeyEngine.
the class J3MOutputCapsule method formatMatParamTexture.
protected static String formatMatParamTexture(MatParamTexture param) {
StringBuilder ret = new StringBuilder();
Texture tex = (Texture) param.getValue();
TextureKey key;
if (tex != null) {
key = (TextureKey) tex.getKey();
if (key != null && key.isFlipY()) {
ret.append("Flip ");
}
ret.append(formatWrapMode(tex, Texture.WrapAxis.S));
ret.append(formatWrapMode(tex, Texture.WrapAxis.T));
ret.append(formatWrapMode(tex, Texture.WrapAxis.R));
//Min and Mag filter
Texture.MinFilter def = Texture.MinFilter.BilinearNoMipMaps;
if (tex.getImage().hasMipmaps() || (key != null && key.isGenerateMips())) {
def = Texture.MinFilter.Trilinear;
}
if (tex.getMinFilter() != def) {
ret.append("Min").append(tex.getMinFilter().name()).append(" ");
}
if (tex.getMagFilter() != Texture.MagFilter.Bilinear) {
ret.append("Mag").append(tex.getMagFilter().name()).append(" ");
}
ret.append("\"").append(key.getName()).append("\"");
}
return ret.toString();
}
use of com.jme3.asset.TextureKey in project jmonkeyengine by jMonkeyEngine.
the class FbxImage method toJmeObject.
@Override
protected Object toJmeObject() {
Image image = null;
String fileName = null;
String relativeFilePathJme;
if (filePath != null) {
fileName = getFileName(filePath);
} else if (relativeFilePath != null) {
fileName = getFileName(relativeFilePath);
}
if (fileName != null) {
try {
// Try to load filename relative to FBX folder
key = new TextureKey(sceneFolderName + fileName);
key.setGenerateMips(true);
image = loadImageSafe(assetManager, key);
// Try to load relative filepath relative to FBX folder
if (image == null && relativeFilePath != null) {
// Convert Windows paths to jME3 paths
relativeFilePathJme = relativeFilePath.replace('\\', '/');
key = new TextureKey(sceneFolderName + relativeFilePathJme);
key.setGenerateMips(true);
image = loadImageSafe(assetManager, key);
}
// Try to load embedded image
if (image == null && content != null && content.length > 0) {
key = new TextureKey(fileName);
key.setGenerateMips(true);
InputStream is = new ByteArrayInputStream(content);
image = assetManager.loadAssetFromStream(key, is).getImage();
// NOTE: embedded texture doesn't exist in the asset manager,
// so the texture key must not be saved.
key = null;
}
} catch (AssetLoadException ex) {
logger.log(Level.WARNING, "Error while attempting to load texture {0}:\n{1}", new Object[] { name, ex.toString() });
}
}
if (image == null) {
logger.log(Level.WARNING, "Cannot locate {0} for texture {1}", new Object[] { fileName, name });
image = PlaceholderAssets.getPlaceholderImage(assetManager);
}
return image;
}
use of com.jme3.asset.TextureKey in project jmonkeyengine by jMonkeyEngine.
the class FbxTexture method toJmeObject.
@Override
protected Texture toJmeObject() {
Image image = null;
TextureKey key = null;
if (media != null) {
image = (Image) media.getJmeObject();
key = media.getTextureKey();
}
if (image == null) {
image = PlaceholderAssets.getPlaceholderImage(assetManager);
}
Texture2D tex = new Texture2D(image);
if (key != null) {
tex.setKey(key);
tex.setName(key.getName());
tex.setAnisotropicFilter(key.getAnisotropy());
}
tex.setMinFilter(MinFilter.Trilinear);
tex.setMagFilter(MagFilter.Bilinear);
if (wrapModeU == 0) {
tex.setWrap(WrapAxis.S, WrapMode.Repeat);
}
if (wrapModeV == 0) {
tex.setWrap(WrapAxis.T, WrapMode.Repeat);
}
return tex;
}
use of com.jme3.asset.TextureKey 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);
}
}
Aggregations