Flipped uv mapping

Hi guys,



When I’m exporting a mesh from blender to the ogre.xml-format and load this with the assetManager everything looks fine except of the uv-mapping. It’s flipped on the x-axis.



How can I avoid this?



greetz



ceiphren

Which modeling tool are you using?

It’s blender 2.5? I think you can configure OgreXmlExporter to avoid flip it in blender.

I have exported many models from Blender 2.5 and never had this issue

i guess that when he imported the model in blender, it was already “flipped”.

Here is how to fix : i store my materials in .j3m files

Material lava : Shaders/Lighting.j3md {

MaterialParameters {

Shininess: 5.0

DiffuseMap: Flip Textures/BrickWallDiffuse.png

NormalMap: Flip Textures/BrickWallNormal.png

ParallaxMap: Flip Textures/BrickWallParallax.png

}

}

The “flip” will fix the texture.

Alternative, something like this may help you :

[java]

public static void flipUVs(Mesh mesh)

{

VertexBuffer uvBuffer = mesh.getBuffer(Type.TexCoord);

float[] uvArray = BufferUtils.getFloatArray((FloatBuffer) uvBuffer.getData());

for (int i = 0; i < uvArray.length; i += 2)

{

uvArray = (1 - uvArray) %1 ; // flip x

uvArray[i+1] = uvArray[i+1]; // y unchanged.

}

uvBuffer.updateData(BufferUtils.createFloatBuffer(uvArray));

}

public static void flipIndexes(Mesh mesh)

{

VertexBuffer indexBuffer = mesh.getBuffer(Type.Index);

short[] indexArray = getShortArray((ShortBuffer) indexBuffer.getData());

for (int i = 0; i < indexArray.length; i += 3)

{

short index1 = indexArray;

short index2 = indexArray;

short index3 = indexArray;

indexArray = index3;

indexArray = index2;

indexArray = index1;

}

indexBuffer.updateData(BufferUtils.createShortBuffer(indexArray));

}

/**

  • Create a new short[] array and populate it with the given ShortBuffer’s
  • contents.

    *
  • @param buff
  •        the ShortBuffer to read from<br />
    
  • @return a new short array populated from the ShortBuffer

    */

    public static short[] getShortArray(ShortBuffer buff)

    {

    if (buff == null)

    {

    return null;

    }

    buff.clear();

    short[] inds = new short[buff.limit()];

    for (int x = 0; x < inds.length; x++)

    {

    inds[x] = buff.get();

    }

    return inds;

    }

    [/java]
1 Like

@Momoko_Fan: It’s blender 2.49b. As I’ve read, the ogreXML-Exporter that comes with the current jMonkeyPlattform can’t be loaded in blender 2.5 (I tested it with blender 2.58. What version are you using? Is there another exporter?)



@glaucomardano: I also thought that but I couldn’t find the property.



@tralala: If I load .obj-files (I think it’s the wavefront-format) the uv-mapping is correct, if I load ogreXML-Files the uv-mapping is flipped. With this solution I have to look which texture should be flipped and which not. Also my application calculates new textures on demand so in this case a j3m-file is not the solution.



The source-code should do the trick. Thanks. But I hope to find a better solution.

ceiphren said:
It's blender 2.49b. As I've read, the ogreXML-Exporter that comes with the current jMonkeyPlattform can't be loaded in blender 2.5 (I tested it with blender 2.58. What version are you using? Is there another exporter?)


No. You don't need to use blender 2.49 anymore, just download and setup the OgreXml for blender 2.5x :D, it's hosted on googlecode : http://code.google.com/p/blender2ogre/downloads/list

Also, you don't need to use OgreXml anymore :D, new BlenderImporter for blender 2.4x...2.5x is available now for jme by @Kaelthas, just install the BlenderImporter Plugin in jmp and load the .blend file with this ;P.

The new xml-exporter now works with blender 2.58 but the flipped uv-mapping-issue is still there.



The importing of .blend-files with the jmp seems to be a little tricky. Where can I configure the animation-names?

ceiphren said:
Where can I configure the animation-names?

In blender

This was the fastest reply i’ve ever seen…

I named the animation but the jme can’t find it.

When I write:

AnimControl control = importedSpatial.getControl(AnimControl.class);

the AnimControl-object is null.

I found this post from Kaelthas:

http://hub.jmonkeyengine.org/groups/development-discussion-jme3/forum/topic/animations-in-jme/

Is the importer currently able to import animations (especially animations with bones)?

Yes it is capable of importing animations

Okay, unknown issue vs me → 3:0



If I’m trying it with the ogreXml-Exporter @glaucomardano mentoined I have the following issue:



This is my test-file



fileuploadx.de



and this is the texture for it:



fileuploadx.de



This is the source for it:



[java]

public class TestClass extends SimpleApplication {

private Node testNode;

private AnimChannel ship_channel;

private AnimControl ship_control;

@Override

public void simpleInitApp() {

testNode = (Node)assetManager.loadModel(“tests/animation/Cube.mesh.xml”);

ship_control = testNode.getControl(AnimControl.class);

System.out.println(ship_control.getAnimationNames());

ship_channel = ship_control.createChannel();

ship_channel.setAnim(“Act: ArmatureAction.001”);

cam.setLocation(new Vector3f(100, 100, 100));

cam.lookAt(Vector3f.ZERO, Vector3f.UNIT_Y);

Material mat = new Material(assetManager, “Common/MatDefs/Misc/Unshaded.j3md”);

mat.setColor(“Color”, ColorRGBA.Blue);

testNode.setMaterial(mat);

}

public static void main(String[] args) {

new TestClass().start();

}

}

[/java]



The problem is that the mesh doesn’t show up. It’s loaded and I can grab the anim_control, but I can’t see the mesh.



If I try a direct import via Kaelthas importer-tool and load the .j3o-file (with the same code above) I have a null-reference at this line:



“ship_channel = ship_control.createChannel();”

aaahhh f**k… well… yeah. At least the rootNode has an easy job -.-

Hell yeah, thanks to Kaelthas support I made it! :smiley:

I don’t know what’s happening with the uv-mapping-issue but with Kaelthas blender-importer it’s gone any more and the xml-bridge isn’t needed any more.^^