com.jme3.texture.Texture Java Examples
The following examples show how to use
com.jme3.texture.Texture.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TestBatchNodeTower.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 6 votes |
public void initMaterial() { mat = 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); mat.setTexture("ColorMap", tex); mat2 = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md"); TextureKey key2 = new TextureKey("Textures/Terrain/Rock/Rock.PNG"); key2.setGenerateMips(true); Texture tex2 = assetManager.loadTexture(key2); mat2.setTexture("ColorMap", tex2); mat3 = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md"); TextureKey key3 = new TextureKey("Textures/Terrain/Pond/Pond.jpg"); key3.setGenerateMips(true); Texture tex3 = assetManager.loadTexture(key3); tex3.setWrap(WrapMode.Repeat); mat3.setTexture("ColorMap", tex3); }
Example #2
Source File: Material.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** * Set a texture parameter. * * @param name The name of the parameter * @param type The variable type {@link VarType} * @param value The texture value of the parameter. * * @throws IllegalArgumentException is value is null */ public void setTextureParam(String name, VarType type, Texture value) { if (value == null) { throw new IllegalArgumentException(); } checkSetParam(type, name); MatParamTexture val = getTextureParam(name); if (val == null) { checkTextureParamColorSpace(name, value); paramValues.put(name, new MatParamTexture(type, name, value, value.getImage() != null ? value.getImage().getColorSpace() : null)); } else { checkTextureParamColorSpace(name, value); val.setTextureValue(value); val.setColorSpace(value.getImage() != null ? value.getImage().getColorSpace() : null); } if (technique != null) { technique.notifyParamChanged(name, type, value); } // need to recompute sort ID sortingId = -1; }
Example #3
Source File: OGLESShaderRenderer.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 6 votes |
private int convertMinFilter(Texture.MinFilter filter) { switch (filter) { case Trilinear: return GLES20.GL_LINEAR_MIPMAP_LINEAR; case BilinearNearestMipMap: return GLES20.GL_LINEAR_MIPMAP_NEAREST; case NearestLinearMipMap: return GLES20.GL_NEAREST_MIPMAP_LINEAR; case NearestNearestMipMap: return GLES20.GL_NEAREST_MIPMAP_NEAREST; case BilinearNoMipMaps: return GLES20.GL_LINEAR; case NearestNoMipMaps: return GLES20.GL_NEAREST; default: throw new UnsupportedOperationException("Unknown min filter: " + filter); } }
Example #4
Source File: GdxRenderer.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 6 votes |
private int convertWrapMode(Texture.WrapMode mode) { switch (mode) { // case BorderClamp: // return GLES20.GL_CLAMP_TO_BORDER; // case Clamp: // return GLES20.GL_CLAMP; case EdgeClamp: return GL20.GL_CLAMP_TO_EDGE; case Repeat: return GL20.GL_REPEAT; case MirroredRepeat: return GL20.GL_MIRRORED_REPEAT; default: throw new UnsupportedOperationException("Unknown wrap mode: " + mode); } }
Example #5
Source File: PaintTerrainToolAction.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 6 votes |
private Texture getAlphaTexture(Terrain terrain, int alphaLayer) { if (terrain == null) return null; MatParam matParam = null; if (alphaLayer == 0) matParam = terrain.getMaterial().getParam("AlphaMap"); else if(alphaLayer == 1) matParam = terrain.getMaterial().getParam("AlphaMap_1"); else if(alphaLayer == 2) matParam = terrain.getMaterial().getParam("AlphaMap_2"); if (matParam == null || matParam.getValue() == null) { return null; } Texture tex = (Texture) matParam.getValue(); return tex; }
Example #6
Source File: Material.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 6 votes |
private int applyOverrides(Renderer renderer, Shader shader, SafeArrayList<MatParamOverride> overrides, int unit) { for (MatParamOverride override : overrides.getArray()) { VarType type = override.getVarType(); MatParam paramDef = def.getMaterialParam(override.getName()); if (paramDef == null || paramDef.getVarType() != type || !override.isEnabled()) { continue; } Uniform uniform = shader.getUniform(override.getPrefixedName()); if (override.getValue() != null) { if (type.isTextureType()) { renderer.setTexture(unit, (Texture) override.getValue()); uniform.setValue(VarType.Int, unit); unit++; } else { uniform.setValue(type, override.getValue()); } } else { uniform.clearValue(); } } return unit; }
Example #7
Source File: J3MLoaderTest.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Test public void oldStyleTextureParameters_shouldBeSupported() throws Exception { when(assetInfo.openStream()).thenReturn(J3MLoader.class.getResourceAsStream("/texture-parameters-oldstyle.j3m")); final Texture textureOldStyle = Mockito.mock(Texture.class); final Texture textureOldStyleUsingQuotes = Mockito.mock(Texture.class); final TextureKey textureKeyUsingQuotes = setupMockForTexture("OldStyleUsingQuotes", "old style using quotes/texture.png", true, textureOldStyleUsingQuotes); final TextureKey textureKeyOldStyle = setupMockForTexture("OldStyle", "old style/texture.png", true, textureOldStyle); j3MLoader.load(assetInfo); verify(assetManager).loadTexture(textureKeyUsingQuotes); verify(assetManager).loadTexture(textureKeyOldStyle); verify(textureOldStyle).setWrap(Texture.WrapMode.Repeat); verify(textureOldStyleUsingQuotes).setWrap(Texture.WrapMode.Repeat); }
Example #8
Source File: PaintTerrainToolAction.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 6 votes |
public void paintTexture(Terrain terrain, Vector3f markerLocation, float toolRadius, float toolWeight, int selectedTextureIndex) { if (selectedTextureIndex < 0 || markerLocation == null) return; int alphaIdx = selectedTextureIndex/4; // 4 = rgba = 4 textures Texture tex = getAlphaTexture(terrain, alphaIdx); Image image = tex.getImage(); Vector2f UV = getPointPercentagePosition(terrain, markerLocation); // get the radius of the brush in pixel-percent float brushSize = toolRadius/(terrain.getTerrainSize()*((Node)terrain).getLocalScale().x); int texIndex = selectedTextureIndex - ((selectedTextureIndex/4)*4); // selectedTextureIndex/4 is an int floor, do not simplify the equation boolean erase = toolWeight<0; if (erase) toolWeight *= -1; doPaintAction(texIndex, image, UV, true, brushSize, erase, toolWeight); tex.getImage().setUpdateNeeded(); }
Example #9
Source File: MaterialContext.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 6 votes |
/** * Sets the texture to the given material. * * @param material * the material that we add texture to * @param mapTo * the texture mapping type * @param texture * the added texture */ private void setTexture(Material material, int mapTo, Texture texture) { switch (mapTo) { case MTEX_COL: material.setTexture(shadeless ? MaterialHelper.TEXTURE_TYPE_COLOR : MaterialHelper.TEXTURE_TYPE_DIFFUSE, texture); break; case MTEX_NOR: material.setTexture(MaterialHelper.TEXTURE_TYPE_NORMAL, texture); break; case MTEX_SPEC: material.setTexture(MaterialHelper.TEXTURE_TYPE_SPECULAR, texture); break; case MTEX_EMIT: material.setTexture(MaterialHelper.TEXTURE_TYPE_GLOW, texture); break; case MTEX_ALPHA: if (!shadeless) { material.setTexture(MaterialHelper.TEXTURE_TYPE_ALPHA, texture); } else { LOGGER.warning("JME does not support alpha map on unshaded material. Material name is " + name); } break; default: LOGGER.severe("Unknown mapping type: " + mapTo); } }
Example #10
Source File: TestUrlLoading.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Override public void simpleInitApp() { // create a simple plane/quad Quad quadMesh = new Quad(1, 1); quadMesh.updateGeometry(1, 1, true); Geometry quad = new Geometry("Textured Quad", quadMesh); assetManager.registerLocator("https://raw.githubusercontent.com/jMonkeyEngine/BookSamples/master/assets/Textures/", UrlLocator.class); TextureKey key = new TextureKey("mucha-window.png", false); key.setGenerateMips(true); Texture tex = assetManager.loadTexture(key); Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md"); mat.setTexture("ColorMap", tex); quad.setMaterial(mat); float aspect = tex.getImage().getWidth() / (float) tex.getImage().getHeight(); quad.setLocalScale(new Vector3f(aspect * 1.5f, 1.5f, 1)); quad.center(); rootNode.attachChild(quad); }
Example #11
Source File: LwjglRenderer.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 6 votes |
/*********************************************************************\ |* Textures *| \*********************************************************************/ private int convertTextureType(Texture.Type type, int samples) { switch (type) { case TwoDimensional: if (samples > 1) { return ARBTextureMultisample.GL_TEXTURE_2D_MULTISAMPLE; } else { return GL_TEXTURE_2D; } case TwoDimensionalArray: if (samples > 1) { return ARBTextureMultisample.GL_TEXTURE_2D_MULTISAMPLE_ARRAY; } else { return EXTTextureArray.GL_TEXTURE_2D_ARRAY_EXT; } case ThreeDimensional: return GL_TEXTURE_3D; case CubeMap: return GL_TEXTURE_CUBE_MAP; default: throw new UnsupportedOperationException("Unknown texture type: " + type); } }
Example #12
Source File: TerrainEditorController.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 6 votes |
private void doSetNormalMap(int layer, String texturePath) { Terrain terrain = (Terrain) getTerrain(null); if (terrain == null) return; if (texturePath == null) { // remove the texture if it is null if (layer == 0) terrain.getMaterial().clearParam("NormalMap"); else terrain.getMaterial().clearParam("NormalMap_"+layer); } else { Texture tex = SceneApplication.getApplication().getAssetManager().loadTexture(texturePath); tex.setWrap(WrapMode.Repeat); if (layer == 0) terrain.getMaterial().setTexture("NormalMap", tex); else terrain.getMaterial().setTexture("NormalMap_"+layer, tex); } enableTextureButtons(); setNeedsSave(true); }
Example #13
Source File: LwjglRenderer.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 6 votes |
private int convertWrapMode(Texture.WrapMode mode) { switch (mode) { case BorderClamp: return GL_CLAMP_TO_BORDER; case Clamp: return GL_CLAMP; case EdgeClamp: return GL_CLAMP_TO_EDGE; case Repeat: return GL_REPEAT; case MirroredRepeat: return GL_MIRRORED_REPEAT; default: throw new UnsupportedOperationException("Unknown wrap mode: " + mode); } }
Example #14
Source File: JoglRenderer.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 6 votes |
private int convertWrapMode(Texture.WrapMode mode) { switch (mode) { case BorderClamp: return GL2GL3.GL_CLAMP_TO_BORDER; case Clamp: return GL2.GL_CLAMP; case EdgeClamp: return GL.GL_CLAMP_TO_EDGE; case Repeat: return GL.GL_REPEAT; case MirroredRepeat: return GL.GL_MIRRORED_REPEAT; default: throw new UnsupportedOperationException("Unknown wrap mode: " + mode); } }
Example #15
Source File: TestCartoonEdge.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 6 votes |
public void makeToonish(Spatial spatial){ if (spatial instanceof Node){ Node n = (Node) spatial; for (Spatial child : n.getChildren()) makeToonish(child); }else if (spatial instanceof Geometry){ Geometry g = (Geometry) spatial; Material m = g.getMaterial(); if (m.getMaterialDef().getName().equals("Phong Lighting")){ Texture t = assetManager.loadTexture("Textures/ColorRamp/toon.png"); // t.setMinFilter(Texture.MinFilter.NearestNoMipMaps); // t.setMagFilter(Texture.MagFilter.Nearest); m.setTexture("ColorRamp", t); m.setBoolean("UseMaterialColors", true); m.setColor("Specular", ColorRGBA.Black); m.setColor("Diffuse", ColorRGBA.White); m.setBoolean("VertexLighting", true); } } }
Example #16
Source File: GuiGlobals.java From Lemur with BSD 3-Clause "New" or "Revised" License | 6 votes |
public Texture loadTexture( String path, boolean repeat, boolean generateMips ) { TextureKey key = new TextureKey(path); key.setGenerateMips(generateMips); Texture t = assets.loadTexture(key); if( t == null ) { throw new RuntimeException("Error loading texture:" + path); } if( repeat ) { t.setWrap(Texture.WrapMode.Repeat); } else { // JME has deprecated Clamp and defaults to EdgeClamp. // I think the WrapMode.EdgeClamp javadoc is totally bonkers, though. t.setWrap(Texture.WrapMode.EdgeClamp); } return t; }
Example #17
Source File: TerrainEditorController.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 6 votes |
/** * Get the normal map texture at the specified layer. * Run this on the GL thread! */ private Texture doGetNormalMap(int layer) { Terrain terrain = (Terrain) getTerrain(null); if (terrain == null) return null; MatParam matParam = null; if (layer == 0) matParam = terrain.getMaterial().getParam("NormalMap"); else matParam = terrain.getMaterial().getParam("NormalMap_"+layer); if (matParam == null || matParam.getValue() == null) { return null; } Texture tex = (Texture) matParam.getValue(); return tex; }
Example #18
Source File: PaintTerrainToolControl.java From jmonkeybuilder with Apache License 2.0 | 6 votes |
@Override @JmeThread public void startPainting(@NotNull final PaintingInput input, @NotNull final Quaternion brushRotation, @NotNull final Vector3f contactPoint) { final Texture alphaTexture = getAlphaTexture(); if (alphaTexture == null) { return; } super.startPainting(input, brushRotation, contactPoint); switch (input) { case MOUSE_PRIMARY: case MOUSE_SECONDARY: { startChange(); paintTexture(input, contactPoint); break; } } }
Example #19
Source File: LwjglContext.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 5 votes |
private int convertTextureType(Texture.Type textureType) { switch (textureType) { case TwoDimensional: return GL11.GL_TEXTURE_2D; case TwoDimensionalArray: return GL30.GL_TEXTURE_2D_ARRAY; case ThreeDimensional: return GL12.GL_TEXTURE_3D; case CubeMap: return GL13.GL_TEXTURE_CUBE_MAP; default: throw new IllegalArgumentException("unknown texture type "+textureType); } }
Example #20
Source File: TestEverything.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 5 votes |
public void setupSkyBox(){ Texture envMap; if (renderer.getCaps().contains(Caps.FloatTexture)){ envMap = assetManager.loadTexture("Textures/Sky/St Peters/StPeters.hdr"); }else{ envMap = assetManager.loadTexture("Textures/Sky/St Peters/StPeters.jpg"); } rootNode.attachChild(SkyFactory.createSky(assetManager, envMap, new Vector3f(-1,-1,-1), SkyFactory.EnvMapType.SphereMap)); }
Example #21
Source File: TerrainEditorController.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 5 votes |
private Spatial doCreateSky(Node parent, Texture texture, boolean useSpheremap, Vector3f normalScale) { AssetManager manager = SceneApplication.getApplication().getAssetManager(); Spatial sky = SkyFactory.createSky(manager, texture, normalScale, useSpheremap); parent.attachChild(sky); return sky; }
Example #22
Source File: MTLLoader.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 5 votes |
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 key = new TextureKey(folderName + name); key.setGenerateMips(true); Texture texture = assetManager.loadTexture(key); if (texture != null){ texture.setWrap(WrapMode.Repeat); } return texture; }
Example #23
Source File: JoglRenderer.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 5 votes |
@Override protected int convertTextureType(Texture.Type type) { switch (type) { case TwoDimensional: return GL.GL_TEXTURE_2D; case TwoDimensionalArray: return GL.GL_TEXTURE_2D_ARRAY; case ThreeDimensional: return GL2GL3.GL_TEXTURE_3D; case CubeMap: return GL.GL_TEXTURE_CUBE_MAP; default: throw new UnsupportedOperationException("Unknown texture type: " + type); } }
Example #24
Source File: J3MLoaderTest.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Test public void newStyleTextureParameters_shouldBeSupported() throws Exception { when(assetInfo.openStream()).thenReturn(J3MLoader.class.getResourceAsStream("/texture-parameters-newstyle.j3m")); final Texture textureNoParameters = Mockito.mock(Texture.class); final Texture textureFlip = Mockito.mock(Texture.class); final Texture textureRepeat = Mockito.mock(Texture.class); final Texture textureRepeatAxis = Mockito.mock(Texture.class); final Texture textureMin = Mockito.mock(Texture.class); final Texture textureMag = Mockito.mock(Texture.class); final Texture textureCombined = Mockito.mock(Texture.class); final Texture textureLooksLikeOldStyle = Mockito.mock(Texture.class); final TextureKey textureKeyNoParameters = setupMockForTexture("Empty", "empty.png", false, textureNoParameters); final TextureKey textureKeyFlip = setupMockForTexture("Flip", "flip.png", true, textureFlip); setupMockForTexture("Repeat", "repeat.png", false, textureRepeat); setupMockForTexture("RepeatAxis", "repeat-axis.png", false, textureRepeatAxis); setupMockForTexture("Min", "min.png", false, textureMin); setupMockForTexture("Mag", "mag.png", false, textureMag); setupMockForTexture("Combined", "combined.png", true, textureCombined); setupMockForTexture("LooksLikeOldStyle", "oldstyle.png", true, textureLooksLikeOldStyle); j3MLoader.load(assetInfo); verify(assetManager).loadTexture(textureKeyNoParameters); verify(assetManager).loadTexture(textureKeyFlip); verify(textureRepeat).setWrap(Texture.WrapMode.Repeat); verify(textureRepeatAxis).setWrap(Texture.WrapAxis.T, Texture.WrapMode.Repeat); verify(textureMin).setMinFilter(Texture.MinFilter.Trilinear); verify(textureMag).setMagFilter(Texture.MagFilter.Bilinear); verify(textureCombined).setMagFilter(Texture.MagFilter.Nearest); verify(textureCombined).setMinFilter(Texture.MinFilter.BilinearNoMipMaps); verify(textureCombined).setWrap(Texture.WrapMode.Repeat); }
Example #25
Source File: SkyFactory.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Create a sky using the given cubemap or spheremap texture. * * @param assetManager from which to load materials * @param textureName the path to the texture asset to use * @param envMapType see {@link EnvMapType} * @return a new spatial representing the sky, ready to be attached to the * scene graph */ public static Spatial createSky(AssetManager assetManager, String textureName, EnvMapType envMapType) { TextureKey key = new TextureKey(textureName, true); key.setGenerateMips(false); if (envMapType == EnvMapType.CubeMap) { key.setTextureTypeHint(Texture.Type.CubeMap); } Texture tex = assetManager.loadTexture(key); return createSky(assetManager, tex, envMapType); }
Example #26
Source File: TbtQuadBackgroundComponent.java From Lemur with BSD 3-Clause "New" or "Revised" License | 5 votes |
public static TbtQuadBackgroundComponent create( Texture t, float imageScale, int x1, int y1, int x2, int y2, float zOffset, boolean lit ) { Image img = t.getImage(); // we use the image size for the quad just to make sure // it is always big enough for whatever insets are thrown at it TbtQuad q = new TbtQuad(img.getWidth(), img.getHeight(), x1, y1, x2, y2, img.getWidth(), img.getHeight(), imageScale); TbtQuadBackgroundComponent c = new TbtQuadBackgroundComponent(q, t, x1, y1, zOffset, lit); return c; }
Example #27
Source File: TestTexture3D.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 5 votes |
/** * This method creates a RGB8 texture with the sizes of 10x10x10 pixels. */ private Texture getTexture() throws IOException { ArrayList<ByteBuffer> data = new ArrayList<ByteBuffer>(1); ByteBuffer bb = BufferUtils.createByteBuffer(10 * 10 * 10 * 3);//all data must be inside one buffer for (int i = 0; i < 10; ++i) { for (int j = 0; j < 10 * 10; ++j) { bb.put((byte) (255f*i/10f)); bb.put((byte) (255f*i/10f)); bb.put((byte) (255f)); } } bb.rewind(); data.add(bb); return new Texture3D(new Image(Format.RGB8, 10, 10, 10, data)); }
Example #28
Source File: MaterialMatParamTest.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 5 votes |
private void outTextures(Texture... textures) { for (int i = 0; i < usedTextures.length; i++) { if (i < textures.length) { Assert.assertSame(textures[i], usedTextures[i]); } else { Assert.assertNull(usedTextures[i]); } } }
Example #29
Source File: QuadBackgroundComponent.java From Lemur with BSD 3-Clause "New" or "Revised" License | 5 votes |
public void setTexture( Texture t ) { if( this.texture == t ) return; this.texture = t; if( material != null ) { material.setTexture(texture); } }
Example #30
Source File: TestShaderNodesStress.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override public void simpleInitApp() { Quad q = new Quad(1, 1); Geometry g = new Geometry("quad", q); g.setLocalTranslation(-500, -500, 0); g.setLocalScale(1000); rootNode.attachChild(g); cam.setLocation(new Vector3f(0.0f, 0.0f, 0.40647888f)); cam.setRotation(new Quaternion(0.0f, 1.0f, 0.0f, 0.0f)); Texture tex = assetManager.loadTexture("Interface/Logo/Monkey.jpg"); Material mat = new Material(assetManager, "Common/MatDefs/Misc/UnshadedNodes.j3md"); //Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md"); mat.setColor("Color", ColorRGBA.Yellow); mat.setTexture("ColorMap", tex); g.setMaterial(mat); //place the geoms in the transparent bucket so that they are rendered back to front for maximum overdraw g.setQueueBucket(RenderQueue.Bucket.Transparent); for (int i = 0; i < 1000; i++) { Geometry cl = g.clone(false); cl.move(0, 0, -(i + 1)); rootNode.attachChild(cl); } flyCam.setMoveSpeed(20); Logger.getLogger("com.jme3").setLevel(Level.WARNING); this.setAppProfiler(new Profiler()); }