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.
Related
I styled a layer with uDig and exported the style as SLD file. I then applied the same style to the a layer (same shapefile) in my code using Geotools. However, uDig's rendering of the map looks much better than mine.
My project uses geotools version 21.2, Java 1.8 and I'm rendering the map with Geotools's JMapPane. Having noticed that the uDig version looks better that mine, I attempted digging into the uDig source to see how the shape files are rendered. I found that shape file are rendered in uDig by ShapefileFeatureRenderer, or so I think. I then copied and pasted the renderer's initialization code and applied it in my project but I didn't notice any difference.
renderer = new StreamingRenderer();
HashMap<String, Object> rendererHints = new HashMap<String, Object>();
rendererHints.put("optimizedDataLoadingEnabled", true); //$NON-NLS-1$
renderer.setRendererHints(rendererHints);
// renderer.removeRenderListener(StreamingRenderer.DEFAULT_LISTENER);
renderer.addRenderListener(listener);
// JG - these may be overriden by the preferences before use?
RenderingHints hints = new RenderingHints(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
renderer.setJava2DHints(hints)
mapPane.setRenderer(renderer);
How do I make my map rendering as good as uDig's (uDig's rendering is to the left in the screenshot below) ?
I would like some one to point me in the right direction on how to go about this. Any help would be appreciated.
I think you should leave the default renderer in place and simply add to it's hints, so something like:
renderer = frame.getMapPane().getRenderer();
Map<Object, Object> rendererHints = renderer.getRendererHints();
rendererHints.put("optimizedDataLoadingEnabled", true);
renderer.setRendererHints(rendererHints);
RenderingHints hints = new RenderingHints(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
renderer.setJava2DHints(hints);
If that doesn't do it then you might want to look at what hints the GeoServer render gets set, for example here
I created a simple model of a barrel (.zip) in Blender 2.69. Then I created a UV map in Blender and made a UV mapped texture out of it (its in the archive, too). Then I imported my texture in Blender, now the mapping matches:
In Blender the model looks fine so far:
By using the Ogre exporter plugin that I installed via the jmonkeyengine SDK, I exported the model. The result of this is my OgreXML format file of the barrel (I did not export material).
Now, I tried to add the barrel to my world like this:
this.barrel = this.assetManager.loadModel("models/barrel/Barrel.mesh.xml");
Material barrelMat = new Material(this.assetManager,
"Common/MatDefs/Light/Lighting.j3md");
barrelMat.setTexture("DiffuseMap",
this.assetManager.loadTexture("models/barrel/Barrel.jpg"));
barrelMat.setBoolean("UseMaterialColors", true);
barrelMat.setColor("Diffuse", ColorRGBA.White);
barrelMat.setColor("Specular", new ColorRGBA(0.3f, 0.1f, 0, 1));
barrelMat.setFloat("Shininess", 4f);
this.barrel.setMaterial(barrelMat);
this.rootNode.attachChild(this.barrel);
The result is this:
Is there something else I have to consider when setting the texture for my UV mapped model?
Often when transferring models from Blender to something like JME, the textures will be upside down. Where you load the texture:
barrelMat.setTexture(“DiffuseMap”,
assetManager.loadTexture(“models/barrel/Barrel.jpg”));
Instead use the TextureKey form of the loadTexture() method and pass yFlip false since true is the default.
assetManager.loadTexture(new TextureKey(“models/barrel/Barrel.jpg”, false));
That should fix your issue.
References:
loadTexture() : http://hub.jmonkeyengine.org/javadoc/com/jme3/asset/AssetManager.html#loadTexture(com.jme3.asset.TextureKey)
TextureKey : http://hub.jmonkeyengine.org/javadoc/com/jme3/asset/TextureKey.html#TextureKey(java.lang.String,%20boolean)
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
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 problem with OrgXML and JMonkeyEngine. I created a model in blender. After that I exported it into OrgXML format. And I got few files with extensions: mash.xml, scene, materials and some textures in jpg. I was reading the tutorial from JMonkey site and there is an example on that site:
// Load a model from test_data (OgreXML + material + texture)
Spatial ninja = assetManager.loadModel("Models/Ninja/Ninja.mesh.xml");
ninja.scale(0.05f, 0.05f, 0.05f);
ninja.rotate(0.0f, -3.0f, 0.0f);
ninja.setLocalTranslation(0.0f, -5.0f, -2.0f);
rootNode.attachChild(ninja);
// You must add a directional light to make the model visible!
DirectionalLight sun = new DirectionalLight();
sun.setDirection(new Vector3f(-0.1f, -0.7f, -1.0f).normalizeLocal());
rootNode.addLight(sun);
This is correct for this example. I have a beautifull ninja in Eclipse. But when I try do the same with my model, it doesn't work correctly. I have a red sword (which I created) in space, there aren't any textures. I created assets folder in my project directory, and subfolders "Models" and "Sword". In "Sword" directory I have all files which were exported from blender. Anybody know what I'm going wrong?
There's a bunch of stuff I would try.
First you probably want to figure out if it's an export problem in Blender or import problem in jmonkey.
Open the .mesh.xml files and see if there's a bunch of coordinates inside.
Second try importing the .scene with the asset manager instead of .mesh.xml.
Third, try to convert the .scene to a .j3o file by right clicking on it.
I'm a new jmonkey user an am trying to figure all this stuff out too.