/** Initialize the materials used in this scene. */ public void initMaterials() { wall_mat = new Material(assetManager, "Common/MatDefs/Misc/SimpleTextured.j3md"); TextureKey key = new TextureKey("Textures/Terrain/BrickWall/BrickWall.jpg"); key.setGenerateMips(true); Texture tex = assetManager.loadTexture(key); wall_mat.setTexture("ColorMap", tex); stone_mat = new Material(assetManager, "Common/MatDefs/Misc/SimpleTextured.j3md"); TextureKey key2 = new TextureKey("Textures/Terrain/Rock/Rock.PNG"); key2.setGenerateMips(true); Texture tex2 = assetManager.loadTexture(key2); stone_mat.setTexture("ColorMap", tex2); floor_mat = new Material(assetManager, "Common/MatDefs/Misc/SimpleTextured.j3md"); TextureKey key3 = new TextureKey("Textures/Terrain/Pond/Pond.png"); key3.setGenerateMips(true); Texture tex3 = assetManager.loadTexture(key3); tex3.setWrap(WrapMode.Repeat); floor_mat.setTexture("ColorMap", tex3); }
public RenderImageJme(String filename, boolean linear, NiftyJmeDisplay display) { TextureKey key = new TextureKey(filename, true); key.setAnisotropy(0); key.setGenerateMips(false); texture = (Texture2D) display.getAssetManager().loadTexture(key); texture.setMagFilter(linear ? MagFilter.Bilinear : MagFilter.Nearest); texture.setMinFilter(linear ? MinFilter.BilinearNoMipMaps : MinFilter.NearestNoMipMaps); image = texture.getImage(); width = image.getWidth(); height = image.getHeight(); }
protected Texture tryLoadTexture(String name, boolean useDefaultTexture) { TextureKey texKey = new TextureKey(folderName + name); texKey.setGenerateMips(true); Texture texture = null; try { texture = assetManager.loadTexture(texKey); texture.setWrap(WrapMode.Repeat); logger.log(Level.INFO, "Loaded {0} for material {1}", new Object[] {texKey, key}); } catch (AssetNotFoundException ex) { logger.log(Level.WARNING, "Cannot locate {0} for material {1}", new Object[] {texKey, key}); } if (texture == null && useDefaultTexture) { texture = new Texture2D(PlaceholderAssets.getPlaceholderImage()); texture.setWrap(WrapMode.Repeat); texture.setKey(texKey); } return texture; }
public static void main(String[] args) { AssetManager assetManager = JmeSystem.newAssetManager( TestMaterialCompare.class.getResource("/com/jme3/asset/Desktop.cfg")); // Cloned materials Material mat1 = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md"); mat1.setName("mat1"); mat1.setColor("Color", ColorRGBA.Blue); Material mat2 = mat1.clone(); mat2.setName("mat2"); testEquality(mat1, mat2, true); // Cloned material with different render states Material mat3 = mat1.clone(); mat3.setName("mat3"); mat3.getAdditionalRenderState().setBlendMode(BlendMode.ModulateX2); testEquality(mat1, mat3, false); // Two separately loaded materials Material mat4 = assetManager.loadMaterial("Models/Sign Post/Sign Post.j3m"); mat4.setName("mat4"); Material mat5 = assetManager.loadMaterial("Models/Sign Post/Sign Post.j3m"); mat5.setName("mat5"); testEquality(mat4, mat5, true); // Comparing same textures TextureKey originalKey = (TextureKey) mat4.getTextureParam("DiffuseMap").getTextureValue().getKey(); TextureKey tex1key = new TextureKey("Models/Sign Post/Sign Post.jpg", false); tex1key.setGenerateMips(true); // Texture keys from the original and the loaded texture // must be identical, otherwise the resultant textures not identical // and thus materials are not identical! if (!originalKey.equals(tex1key)) { System.out.println("TEXTURE KEYS ARE NOT EQUAL"); } Texture tex1 = assetManager.loadTexture(tex1key); mat4.setTexture("DiffuseMap", tex1); testEquality(mat4, mat5, true); // Change some stuff on the texture and compare, materials no longer equal tex1.setWrap(Texture.WrapMode.MirroredRepeat); testEquality(mat4, mat5, false); // Comparing different textures Texture tex2 = assetManager.loadTexture("Interface/Logo/Monkey.jpg"); mat4.setTexture("DiffuseMap", tex2); testEquality(mat4, mat5, false); // Two materials created the same way Material mat6 = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md"); mat6.setName("mat6"); mat6.setColor("Color", ColorRGBA.Blue); testEquality(mat1, mat6, true); // Changing a material param mat6.setColor("Color", ColorRGBA.Green); testEquality(mat1, mat6, false); }
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; }