public void requestPreview( String textureName, String displayName, int width, int height, JComponent picLabel, JLabel infoLabel) { TextureKey key = new TextureKey(textureName); picPreview = picLabel; assetManager.deleteFromCache(key); Texture t = assetManager.loadTexture(key); Spatial geom = quad; if (key.getTextureTypeHint() == Texture.Type.TwoDimensional) { material.setTexture("ColorMap", t); geom.setMaterial(material); if (infoLabel != null) { infoLabel.setText( " " + displayName + " w : " + t.getImage().getWidth() + " h : " + t.getImage().getHeight()); } } else if (key.getTextureTypeHint() == Texture.Type.ThreeDimensional) { geom = quad3D; assetManager.deleteFromCache(key); key.setTextureTypeHint(Texture.Type.ThreeDimensional); t = assetManager.loadTexture(key); material3D.setTexture("Texture", t); geom.setMaterial(material3D); if (infoLabel != null) { infoLabel.setText( " " + displayName + " (Texture3D) w : " + t.getImage().getWidth() + " h : " + t.getImage().getHeight() + " d : " + t.getImage().getDepth()); } } else if (key.getTextureTypeHint() == Texture.Type.CubeMap) { assetManager.deleteFromCache(key); geom = SkyFactory.createSky(assetManager, textureName, SkyFactory.EnvMapType.CubeMap); if (infoLabel != null) { infoLabel.setText( " " + displayName + " (CubeMap) w : " + t.getImage().getWidth() + " h : " + t.getImage().getHeight()); } } PreviewRequest request = new PreviewRequest(this, geom, width, height); request.getCameraRequest().setLocation(new Vector3f(0, 0, 5.3f)); request.getCameraRequest().setLookAt(new Vector3f(0, 0, 0), Vector3f.UNIT_Y.mult(-1)); SceneApplication.getApplication().createPreview(request); }
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; }