I'm having an issue with libgdx skin.
When the app is paused or goes into the background and then reopens all my scene2d textures are just showing up black. I assume that the underlying textures need to be reloaded.
I'm creating my skin using the following code
FileHandle jsonFile = Gdx.files.internal( "ui/uiskin.json" );
FileHandle atlasFile = Gdx.files.internal( "ui/uiskin.atlas" );
TextureAtlas atlas = new TextureAtlas(atlasFile);
skin = new Skin(jsonFile, atlas);
My question is if there any way that I can detect when the texture needs to be reloaded and how to best do this?
I have found that it is best to rebuild the skin when you reopen your app.
Related
I am working on an AR application using ARCore and Sceneform. I want to add texture to face landmarks like nose, lips, face and eyes. I want to know how to create texture so that I can overlay it on Augmented Face mesh?
Texture.builder()
.setSource(this, R.drawable.makeupforlips)
.setUsage(Texture.Usage.COLOR)
.build()
.thenAccept(texture -> faceMeshTexture = texture);
addOnUpdateListener:
for (AugmentedFace face: faceList) {
if (!faceNodeMap.containsKey(face)) {
AugmentedFaceNode faceNode = new AugmentedFaceNode(face);
faceNode.setParent(scene);
// faceNode.setFaceRegionsRenderable(faceRegionsRenderable);
faceNode.setFaceMeshTexture(faceMeshTexture);
faceNodeMap.put(face, faceNode);
}
}
When you're building ARCore app with Augmented Faces functionality you need to use a canonical face mesh that was saved in .fbx, .obj, or .glTF file format. Import this canonical face into Autodesk Maya and using UV Texture Editor, create a UV-mapped texture that can be repainted in Adobe Photoshop or Pixelmator.
I'm having trouble using the skin once I've loaded it in the assetManager.
assetManager.load(skinPath+".atlas", TextureAtlas.class);
assetManager.finishLoading();
assetManager.load(skinPath+".json", Skin.class, new SkinLoader.SkinParameter(skinPath+".atlas"/*,Resources*/));
assetManager.finishLoading();
skin = skin.get(skinPath+".json", Skin.class);
The last line of code throws java.lang.NullPointerException, does anyone know why?
skin = skin.get(UIAssetsPath+skinName+".json", Skin.class);
skin.get() is your issue here. As skin is null and I am not sure why are you trying to get skin from a skin when you have your asset loader.
You need to call
assetManager.get(UIAssetsPath+skinName+".json", Skin.class);
Also suggest you reading more about exceptions. This seems a very beginner mistake.
I'm using OSMdroid library in my project to display map tiles (it's a shape with lines and blank background) from my company local sever in my app. The thing is when I use the app in offline mode and I browse the map shows an empty grey grid background for the tiles that aren't in the cache, and I want to change that empty grey grid for an blank background image/tile.
The only workaround that I've found to achieve this is the following:
Add a tile overlay and set setLoadingBackgroundColor and setLoadingLineColor to Color.WHITE, and then set the TileSource from the local server from OnlineTileSourceBase. I know this is not quite performant, so is there a better way to do this? Thanks in advance!
final ITileSource tileSource = new OnlineTileSourceBase(...)
{
#Override
public String getTileURLString(MapTile aTile) {
return getBaseUrl() + aTile.getX() + "+" + aTile.getY() + "+" + aTile.getZoomLevel();
}
};
tileProvider = new MapTileProviderBasic(context, tileSource);
tilesOverlay = new TilesOverlay(tileProvider , context);
tilesOverlay.setLoadingBackgroundColor(Color.WHITE);
tilesOverlay.setLoadingLineColor(Color.WHITE);
this.map.getOverlays().add(tilesOverlay);
this.map.setTileSource(tileProvider.getTileSource());
map.invalidate();
Your code is an example on adding a secondary tile overlay. That's useful for when you need another raster graphics overlay on top of the map imagery.
You can also change the loading lines and background for the existing and default tiles overlay. This should get you going
mMapView.getOverlayManager().getTilesOverlay().setLoadingBackgroundColor(Color.TRANSPARENT);
mMapView.getOverlayManager().getTilesOverlay().setLoadingLineColor(Color.TRANSPARENT);
I want to define the background of TextButton with uiskin.json.
Here is what i tried but didn't work:
com.badlogic.gdx.scenes.scene2d.ui.Skin$TintedDrawable: {
img: { file: bg.png }
},
com.badlogic.gdx.scenes.scene2d.ui.TextButton$TextButtonStyle: {
default: { down: default-round-down, up: img, font: default-font, fontColor: white }
}
So I want to make bg.png as the default background. How can i do it?
Skin cannot read file locations from the json. If you followed tutorials for Skin, you probably instantiated it with a TextureAtlas like this:
skin = new Skin(skinFilePath, textureAtlas);
When you load it like that, all the images in the json must be available by their names in the TextureAtlas.
Normally, you need all your images to be in a single TextureAtlas, for performance reasons. So the best solution would be to add this bg.png image into your TextureAtlas, and then you can refer to it by its TextureAtlas name.
If you must load it as a separate file, then you must manually load it before loading your skin.
Texture bgTexture = new Texture("bg.png");
skin = new Skin(); //empty constructor causes it not to load yet.
skin.add("bg", bgTexture);
skin.addRegions(textureAtlas); // you will be responsible for disposing the atlas separately from the skin now.
skin.load(skinFilePath);
I have a mesh generated from data in Renderables. Environment is set. Material is a simple new Material().
... /*init renderable*/
/*set mesh parameters*/
renderable.mesh = new Mesh(false,
(int)(meshVertexArray.length/SurfaceBuilder.__ELEMENTSPERVERTEX__), /*!vertices, not cordinates*/
meshIndexArray.length,
new VertexAttribute(Usage.Position,3,"a_position"),
new VertexAttribute(Usage.Normal,3,"a_normal"),
new VertexAttribute(Usage.TextureCoordinates,2,"a_texCoords"),
new VertexAttribute(Usage.ColorPacked,4, "a_color")
);
... /*set vertices*/
The mesh is generated properly, but I can't see the textures, only the gray (shaded) triangles. I did try the rtfm method, but so far I saw no way to bind a texture, so it displays properly in libGDX, only with shaders, and I'm not using them (I'm catching up on them after this feature is implemented). Is there a way in libGDX to bind textures to a mesh without shaders?
Without seeing your texturing code, maybe try specify a texture for your material using the following format:
Material mat = new Material();
//set the diffuse channel on the texture using some texture
mat.set(TextureAttribute.createDiffuse(new Texture("crate.jpg")));