Ogre Version: 1.12.8
Operating System: win10
Render System: dx9
I want manage in a quad (manual object) of fixed dimension, frames coming from a texture sheet. The frames are trimmed in the sheet, so each of them has an offset of center respect the original prepack dimension of frame (this last identical to the fixed dimension used in the quad). So when I apply the material to the quad i want the center of material applies this offset respect the center of quad. Is there a way to do this (so to keep the quad to his fixed dimension without follow the dimension of trimmed frame)? thanks
[solved] Manage trimmed texture frame from texture sheet
-
- Goblin
- Posts: 211
- Joined: Sat Jan 23, 2016 11:26 am
- x 17
[solved] Manage trimmed texture frame from texture sheet
Last edited by Niubbo on Fri Jan 07, 2022 2:08 pm, edited 1 time in total.
- sercero
- Bronze Sponsor
- Posts: 449
- Joined: Sun Jan 18, 2015 4:20 pm
- Location: Buenos Aires, Argentina
- x 156
Re: Manage trimmed texture frame from texture sheet
It is difficult to understand what you are saying.
Can you show some pictures or mock screen captures of what you want?
It seems to me that you want to change the displacement of a texture, so that would entail manipulating the UVs.
Correct me if I'm wrong.
Can you show some pictures or mock screen captures of what you want?
It seems to me that you want to change the displacement of a texture, so that would entail manipulating the UVs.
Correct me if I'm wrong.
-
- Goblin
- Posts: 211
- Joined: Sat Jan 23, 2016 11:26 am
- x 17
Re: Manage trimmed texture frame from texture sheet
essentially the problem is that one described here: https://en.sfml-dev.org/forums/index.php?topic=12065.0
in SFML they solved with a command setorigin in order to define the real center of texture. I wonder if in Ogre there's a better solution that changes the vertex positions. I cannot work directly with the untrimmed dimension of sprite because some of them must be rendered overlapped with others and have different untrimmed dimensions.
in SFML they solved with a command setorigin in order to define the real center of texture. I wonder if in Ogre there's a better solution that changes the vertex positions. I cannot work directly with the untrimmed dimension of sprite because some of them must be rendered overlapped with others and have different untrimmed dimensions.
-
- OGRE Team Member
- Posts: 1994
- Joined: Sun Mar 30, 2014 2:51 pm
- x 1074
- Contact:
Re: Manage trimmed texture frame from texture sheet
I think you need to read-up texture mapping. e.g. here: https://www.opengl-tutorial.org/beginne ... ured-cube/
Also, there is a Ogre Test that likely does what you are aiming at:
https://ogrecave.github.io/ogre/vtests1 ... tureCoords
Also, there is a Ogre Test that likely does what you are aiming at:
https://ogrecave.github.io/ogre/vtests1 ... tureCoords
-
- Goblin
- Posts: 211
- Joined: Sat Jan 23, 2016 11:26 am
- x 17
Re: Manage trimmed texture frame from texture sheet
Thanks Paroj, but I don't think mine is the same case of this Ogre Test. I suppose to work with vertex is the only solution. I'll return with more details after my tests. thanks.
-
- Goblin
- Posts: 211
- Joined: Sat Jan 23, 2016 11:26 am
- x 17
Re: Manage trimmed texture frame from texture sheet
Just to specify how I solved the thing if can be useful for others using texturepackers sprite:
First the problem nature:
All the sprites have the same not trimmed dimension ex. 300x300 and they overlap perfectly if the square are centered with this dimension, but the image are saved in the texture sheet in trimmed way (all the blank space is cut) with a value of offset representing the distance from the original untrimmed border of new trimmed top\left angle. If I create a quad using vertexes with dimension 300x300 of course the texture image result stretched.
1- I created a manual mesh, a simply quad with two submeshes 1 for layer using the trimmed dimension of texture
2 - in order to manage the offset of trimmed sprite respect the not trimmed image and overlap correctly the two layers, I copied and modified the texture rotation logic of billboardset:
- I calculate the center origin of texture using the same routine of billboard getParametricOffsets
- calculate the rotation axes respect the camera, using the same routine of billboard genAxes
- I modified the original routine of billboard genVertOffsets in this way
where width is the trimmed width of image, height the trimmed height of image, offsetleft is the offset of trimmed image from the origina left border and offsettop from the top border; because I used the center origin inleft\inright\intop\inbottom are all or 0.5 or -0.5.
In this way the two layer overlap perfectly in the same position. Now because I want the image is at the ground level with the bottom border
I calculated the half real dimension of height of the base layer, to add to the Y scenenode position, considering also the eventual scale I'm going to apply to the scenenode.
First the problem nature:
All the sprites have the same not trimmed dimension ex. 300x300 and they overlap perfectly if the square are centered with this dimension, but the image are saved in the texture sheet in trimmed way (all the blank space is cut) with a value of offset representing the distance from the original untrimmed border of new trimmed top\left angle. If I create a quad using vertexes with dimension 300x300 of course the texture image result stretched.
1- I created a manual mesh, a simply quad with two submeshes 1 for layer using the trimmed dimension of texture
2 - in order to manage the offset of trimmed sprite respect the not trimmed image and overlap correctly the two layers, I copied and modified the texture rotation logic of billboardset:
- I calculate the center origin of texture using the same routine of billboard getParametricOffsets
- calculate the rotation axes respect the camera, using the same routine of billboard genAxes
- I modified the original routine of billboard genVertOffsets in this way
Code: Select all
Ogre::Vector3 vLeftOff, vRightOff, vTopOff, vBottomOff;
/* Calculate default offsets. Scale the axes by
parametric offset and dimensions, ready to be added to
positions.
*/
vLeftOff = x * ((inleft * width) - offsetleft);
vRightOff = x * ((inright * width) - offsetleft);
vTopOff = y * ((intop * height) + offsettop);
vBottomOff = y * ((inbottom * height) + offsettop);
// Make final offsets to vertex positions
pDestVec[0] = vLeftOff + vTopOff;
pDestVec[1] = vLeftOff + vBottomOff;
pDestVec[2] = vRightOff + vTopOff;
pDestVec[3] = vRightOff + vBottomOff;
In this way the two layer overlap perfectly in the same position. Now because I want the image is at the ground level with the bottom border
I calculated the half real dimension of height of the base layer, to add to the Y scenenode position, considering also the eventual scale I'm going to apply to the scenenode.
Code: Select all
layerheight = (realdimension.y * mBottomOff) + offsettop;
layerheight *= -1.0F;
layerheight *= scale;