gama.old icon indicating copy to clipboard operation
gama.old copied to clipboard

rotated_by apply on a textured shape seems to be broken

Open agrignard opened this issue 6 years ago • 9 comments

Describe the bug Problem with rotated_by on textured geometry (maybe on all geometry but we didn't realize it?) Run this model

model NewModel

/* Insert your model definition here */

global{
	file imageRaster <- file('./../images/Kent_Sketches.png');
}

experiment TEST{
	output{
		display goodwithCam2 type:opengl
		{
			graphics "image" {
				draw rectangle(500#px,500#px) rotated_by (cycle,{1,0,0}) texture:[imageRaster.path];
			}
		}			
	}
}

Can be tested running this picture_test.zip

Here is what I get with

draw rectangle(500#px,500#px) rotated_by (89,{1,0,0}) texture:[imageRaster.path]
Screen Shot 2019-06-04 at 18 59 09

and with

draw rectangle(500#px,500#px) rotated_by (90,{1,0,0}) texture:[imageRaster.path]
Screen Shot 2019-06-04 at 18 59 38

Expected behavior I would assume to see a spinning image (the idea was to draw an image as a white board to applying a 90° rotation on the X axis. However I see that the picture is flipped.

agrignard avatar Jun 04 '19 23:06 agrignard

Hi, Not sure to understand this bug report. Is it a problem with

  • the texture being flipped or
  • the shape not being correctly rotated ?

Besides, what does (maybe on all geometry but we didn't realize it?) mean ?

AlexisDrogoul avatar Jun 04 '19 23:06 AlexisDrogoul

I mean if you just draw a non textured rectangle we don't see that there is a problem as the geometry is "invariant" in term of rotation

agrignard avatar Jun 04 '19 23:06 agrignard

Sorry, I don't get it. The only 3D geometry I know which is 'invariant' in terms of rotation is the sphere. Rotating a rectangle around the x-axis should rotate the geometry, no ?

AlexisDrogoul avatar Jun 05 '19 00:06 AlexisDrogoul

Yes it will rotate the geometry what I mean by invariant is the texture (e.g a pure white picture is invariant)

I just did a gif that can maybe help to track the issue.

So first I display my rotated picture with the draw rectangle(500#px,500#px) rotated_by (89,{1,0,0}) as 90 doesn't work as explained below.

However I just discover that if I inspect the agent (so I guess the size of the window of the display change then the picture is being flipped no way to have it back in the right orientation unless i relaunch the experiment

imageflip mov

agrignard avatar Jun 05 '19 18:06 agrignard

It also happens (the flipped of the texture) if I switch to fullscreen

agrignard avatar Jun 05 '19 18:06 agrignard

Now tracked under #2209 -- for the OpenGL adventurous !

AlexisDrogoul avatar Jun 06 '19 04:06 AlexisDrogoul

Reopening this issue for the next round of development on GAMA 2.0

AlexisDrogoul avatar Feb 20 '22 03:02 AlexisDrogoul

There is actually a place in the code (in OpenGL.java) where we declare:

private final Rotation3D currentTextureRotation = Rotation3D.identity();

This field is then used to provide a "best guess" at how to rotate the texture according to the rotation of the object. I'm not quite sure to understand why it's failing here. ..

AlexisDrogoul avatar Mar 09 '22 17:03 AlexisDrogoul

Spent some time on this, few thing have changed except that the flip now happens between 90 and 91 instead of 89 and 90 degrees...

agrignard avatar May 05 '22 12:05 agrignard

I have pushed a commit that adds a new preference (pref_texture_orientation), which can be set or not in models. When set (default value), the textures are applied using a heuristic "best guess" algorithm, like now. When unset, no rotation/orientation is applied to the texture coordinates. This adresses your issue, but not applying any rotation also raises issues in some models, hence the possibility to set/unset this preference. I've added it in some models of the library by the way. Please test !

AlexisDrogoul avatar Dec 19 '22 08:12 AlexisDrogoul