Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Texture coordinates for Plane primitive object not correct #1561

Closed
dansoonie opened this issue Nov 6, 2015 · 8 comments

Comments

Projects
None yet
6 participants
@dansoonie
Copy link

commented Nov 6, 2015

Currently using the most recent master build(306).
I've been trying to use the plane object for simple testing. And for some reason I'm getting the texture horizontally flipped. After some investigation, I think the problem is related to #1306 and #1533.

I think #1306 on plane facing problem has been solved but resulted in a bug related to #1533. lin1987www points out that his material is reversed. The posted image on the issue suggests that it's the same problem that I am having. The issuer got around the problem by making the plane double sided and rotating along the y axis 180 degrees. However, I don't think that is supposed to be intended.

After doing some testing, I found out that the texture appears as I intend it to when upAxis for the plane is Axis.Y. But when upAxis is Axis.X or Axis.Z, the texture is flipped horizontally.

I didn't go through any detailed analysis but from my observations I believe that there must be some appropriate changes made to the texture coordinates constructing sequence in init() of Plane class.

if (mCreateTextureCoords) {
    float u = (float) i / (float) mSegmentsW;
    textureCoords[texCoordCount++] = (1.0f - u) * mNumTextureTiles;
    float v = (float) j / (float) mSegmentsH;
    textureCoords[texCoordCount++] = (1.0f - v) * mNumTextureTiles;
}

My guess is that
(1.0f - u) * mNumTextureTiles
should be simply
u * mNumTextureTiles
when upAxis is Axis.x or Axis.Z.

Can anyone confirm on this phenomenon? I'm quite surprised that there aren't many people who encountered this problem.

@dhelleberg

This comment has been minimized.

Copy link

commented Jan 31, 2016

Hi,
I had exactly the same issue using a plane for texture mapping and seeing a flipped texture.
Fixed it the same way you did.

I guess this is worth a pull request?

@kmare

This comment has been minimized.

Copy link

commented Mar 10, 2016

Thank you @dansoonie , that fixed it for me (1.0 branch). A push to stable branch is needed. It's indeed weird that no one noticed before.

@jwoolston jwoolston added this to the v1.1, Bombshell milestone Mar 10, 2016

@jwoolston jwoolston self-assigned this Mar 10, 2016

@jwoolston

This comment has been minimized.

Copy link
Member

commented Mar 10, 2016

It's indeed weird that no one noticed before.

Its been noticed but there have been PR requests for both sides of the mirror. There seems to be some debate about what is correct.

@dansoonie

This comment has been minimized.

Copy link
Author

commented Mar 14, 2016

@kmare I suspected that somebody had noticed about it and that is probably why I didn't attempt a pull request. I thought something was probably going on and I didn't want to complicate the issue by throwing pull requests at the maintainers.

Anyway, what's the debate about @jwoolston ? Does it have anything to do with how rajawali handles rotation? Because I found out that rajawali uses right handed coordinate system by default(z axis pointing out of the screen), but the rotation seems like its following the rule for left handed coordinate system(when rotating along z axis it rotates clockwise).

@jwoolston

This comment has been minimized.

Copy link
Member

commented Mar 14, 2016

@dansoonie Yes, that pretty well sums it up. The rotation is incorrect. The texture coordinates were at one point correct. I am not sure of their current state in that matter though.

@PopTudor

This comment has been minimized.

Copy link

commented Apr 15, 2016

Hello, is this fixed ? I'm using org.rajawali3d:rajawali:1.1.337 and on a plane, the texture is still flipped horizontally (works ok on cube)

@kmare

This comment has been minimized.

Copy link

commented Apr 15, 2016

It is fixed on master for sure.

@GonMolon

This comment has been minimized.

Copy link

commented Jul 18, 2016

I'm in 1.1.346 and still have the issue...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.