Texture not rendering at an angle

Hi,

I’m trying to render a polyhedron where each triangle (or face) consists of an outer triangle which is uniformly colored and an inside triangle which is not. To do this I’m using textures for the inside triangle.
The problem is that the textures are not rendered at certain angles. The two pictures below show the exact same polyhedron but with the camera slightly rotated. The texture is only displayed on one and shifts in the two pictures. I assume this is due to the angle as that is all that was changed.


The code i use to generate the inside material :

private Material getMaterial(ColorRGBA colorRGBA) {
 		Material material = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
 		TextureKey key = new TextureKey("/squigly.jpg"); 
		Texture tex = assetManager.loadTexture(key);
		material.setTexture("ColorMap", tex);
 		material.setColor("Color", colorRGBA);
		return material; 		
	} 

where squigly.jpg is the black and white texture.

Thanks in advance,

Nick

EDIT: The provided code looks fine so the problem must be elsewhere, can you post your full test-case?.
For texture loading you can use: assetManager.loadTexture("path-to-texture") instead of manually creating a key previously.

Thanks for the reply and the tips.

These are some more code snippets

Adds the 3 points as a mesh to a triangle and attaches it to polyhedron which is attached to RootNode later.

private void drawTriangle(ArrayList<Vector3f> pointsIn3f, ColorRGBA colorRGBA, Node polyhedron {
        Mesh mesh = new Mesh();
        float[] fl = new float[3*pointsIn3f.size()];
        for (int i = 0; i < pointsIn3f.size(); i++) {
        	Vector3f pos = pointsIn3f.get(i);
        	fl[i*3] 	= pos.getX();
        	fl[i*3 + 1]	= pos.getY();
        	fl[i*3 + 2]	= pos.getZ();
        }
        mesh.setBuffer(Type.Position, 3, BufferUtils.createFloatBuffer(fl));
        mesh.setMode(com.jme3.scene.Mesh.Mode.Triangles);
        mesh.setStatic();
        mesh.updateBound();
        Geometry geomTriangle = new Geometry("triangle", mesh);
        Material material = getMaterial(colorRGBA);
        geomTriangle.setMaterial(material);
        polyhedron.attachChild(geomTriangle);
} 

And this is the code used to initialize

public static void main(String[] args) {
	 PolyhedronTester app = new PolyhedronTester();
	 AppSettings settings = new AppSettings(true);
	 settings.setResolution(900, 600);
	 settings.setFullscreen(false);
	 settings.setVSync(true);
	 settings.setTitle("Test");
	 settings.setUseInput(true);
	 settings.setFrameRate(120);	
	 settings.setSamples(0);
	 app.setPauseOnLostFocus(false);
	 app.setShowSettings(false);
	 app.setSettings(settings);
	 app.setDisplayStatView(false);
	 app.setDisplayFps(true);
	 app.start();
}
	
	
@Override
public void simpleInitApp() {
	flyCam.setEnabled(true);
	flyCam.setMoveSpeed(3);
	inputManager.setCursorVisible(true);
	flyCam.setDragToRotate(true);
	
	viewPort.setBackgroundColor(ColorRGBA.White);

		cam.setLocation(new Vector3f(-5, 0.5f, 0));
} 

Thanks again

Nick

So… you are using textures but your mesh hasn’t got texture coords?, that looks awkward to me.

Take a look to this entry in the wiki.

You neither are creating the index buffer. Follow that tutorial and you shouldn’t have any problem.

Okay I’ll try that and then get back to you.
Thanks again for your time.

Setting the Texture Coordinates solved the problem, and it was simple to do aswell !!
Thanks for the help !

Please prefix the title this thread with [SOLVED] for the reasons, cheers =)