Imagine I have a model of a human with some accessory like sunglasses, a hat, a chain and so on. Is there any way to switch the visibility of those items inside my libGDX application, by writing something like:
modelInstance.getNode("sunglasses").setVisible(false)
You can set a blending attibute to its material:
blendingAttribute = new BlendingAttribute(GL10.GL_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA);
material = modelinstance.materials.get(0);
material.set(blendingAttribute);
Then you can set its opacity like this:
blendingAttribute.opacity = 0.5F; //0-1
Related
To my immense surprise, it seems impossible to find any other people having this problem -- I can use Jmonkey to import a mesh (in my case a gear), but it doesn't properly map the texture (which is supposed to look like wood), only texturing a few select faces shown:
It still looks fine in Blender:
To summarize, how do I get the texture to map over the ENTIRE gear, not just some triangles?
My code is written like this (pardon if it's a little messy, I've been trying to solve this for a while now):
Spatial gear = assetManager.loadModel("Models/cog_3.j3o");
//Geometry geargeo=(Geometry)gear;
//Node gearnode = (Node)gear;
//Mesh gearmesh = (Mesh) gearnode;
//Mesh gearmesh = (Geometry)(gearnode.getChildren().get(0));
TangentBinormalGenerator.generate(gear);
Material wood = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
Texture woodtex = assetManager.loadTexture("Textures/wood-texture.jpg");
woodtex.setWrap(Texture.WrapMode.Repeat);
wood.getAdditionalRenderState().setFaceCullMode(RenderState.FaceCullMode.Off);
wood.setTexture("ColorMap", woodtex);
wood.getAdditionalRenderState().setBlendMode(RenderState.BlendMode.Alpha);
gear.setMaterial(wood);
rootNode.attachChild(gear);
My mesh looks like this (you can see the uv seams):
Uv looks like this:
I'm using blender 2.78a,
and (as far as I know), the latest version of JME.
Any help is appreciated greatly.
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 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")));
I've been trying to make a surface in Java 3D reflect in a similar manner to a mirror. The API says to use TexCoordGeneration in SPHERE_MAP mode, but it doesn't seem to be making any difference at all.
Can anyone spot what I'm doing wrong?
Appearance reflectAp = new Appearance();
TexCoordGeneration tex = new TexCoordGeneration();
tex.setGenMode(TexCoordGeneration.SPHERE_MAP);
reflectAp.setMaterial(matFact.silver());
reflectAp.setTexCoordGeneration(tex);
flat = new Box(.7f, .9f, .01f, Primitive.GENERATE_NORMALS | Primitive.GENERATE_TEXTURE_COORDS, reflectAp);
I have a java 3d application and this application I load an OBJ file into my scene. How can I assign a texture (a jpg file) to this model?
To be more precise, when I want to assign texture to a primitive java object (e.g. sphere) I use the following:
Sphere sphere = new Sphere(Radius, Primflags, Appearance);
However, when loading and adding an obj file I do:
Scene scene = getSceneFromFile("OBJ file");
myBranchGroup = scene.getSceneGroup();
And in second case, I can find no way of assigning the texture. How should I do that?
You would have to use a program that you made the obj file or were you can load the file. Paint it, then export that file. Then add this code to it outside any methods
static TextureLoader loader = new TextureLoader("C:\\Users\\Sawyera\\Desktop\\Paint Layer 1.jpg",
"RGP", new Container());
static Texture texture = loader.getTexture();
Then
texture.setBoundaryModeS(Texture.WRAP);
texture.setBoundaryModeT(Texture.WRAP);
texture.setBoundaryColor(new Color4f(0.0f, 1.0f, 0.0f, 0.0f));
TextureAttributes texAttr = new TextureAttributes();
texAttr.setTextureMode(TextureAttributes.MODULATE);
Appearance ap = new Appearance();
ap.setTexture(texture);
ap.setTextureAttributes(texAttr);
int primflags = Primitive.GENERATE_NORMALS
+ Primitive.GENERATE_TEXTURE_COORDS;
ObjectFile loader = new ObjectFile(ObjectFile.RESIZE);
Then add this before you assign the model to the scene. Assuming the 3D model varrible is called model
model.setAppearance(ap);
IIRC you need to get the Shape3D node you want to apply the texture to (calling setAppearance(...)) from your branch group, e.g. by using getChild(index) etc. Note that you might to iterate recursively through the children, since the branch group you get might actually contain other groups, so you might find the shapes further down the group tree.
Alternatively you should be able to add an AlternateAppearance object to the branch group.