hi, i’m new to jmonkey on android platform.
i have followed the beginner tutorial and successfully having the ninja model displayed on android.
but i have encountered a problem that ninja spatial displayed with wrong texture coords when i load a material and apply to it.
my source code is
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);
Material unshaded = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
unshaded.setTexture("ColorMap", assetManager.loadTexture("Models/Ninja/Ninja.jpg"));
ninja.setMaterial(unshaded);
rootNode.attachChild(ninja);
The texture has to be flipped.
you’ll have to use a TextureKey to load your texture (TextureKey is an AssetKey , AssetKey are just object that holds loading options for assets).
do that
[java]
Material unshaded = new Material(assetManager, “Common/MatDefs/Misc/Unshaded.j3md”);
//loading texture with a texture key
TextureKey key = new TextureKey(“Models/Ninja/Ninja.jpg”, true); //<-- true is for “flip the texture along the Y axis”
unshaded.setTexture(“ColorMap”, assetManager.loadTexture(key));
ninja.setMaterial(unshaded);
rootNode.attachChild(ninja);
[/java]
It should work
thanks all, and i have fix it.
but i use the “false” param to make it works.
TextureKey texKey = new TextureKey(“Models/Ninja/Ninja.jpg”, false);
@nehon said:
The texture has to be flipped.
you'll have to use a TextureKey to load your texture (TextureKey is an AssetKey , AssetKey are just object that holds loading options for assets).
do that
[java]
Material unshaded = new Material(assetManager, “Common/MatDefs/Misc/Unshaded.j3md”);
//loading texture with a texture key
TextureKey key = new TextureKey(“Models/Ninja/Ninja.jpg”, true); //<-- true is for “flip the texture along the Y axis”
unshaded.setTexture(“ColorMap”, assetManager.loadTexture(key));
ninja.setMaterial(unshaded);
rootNode.attachChild(ninja);
[/java]
It should work