Author Topic: Create Atlas by Texture Packer with "rotation" sprite ?  (Read 64697 times)

RobD

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 1
    • View Profile
Re: Create Atlas by Texture Packer with "rotation" sprite ?
« Reply #15 on: December 20, 2012, 10:11:42 AM »
I just had a quick go at this (going through my whole HUD to fix items that had changed rotation every time I re-packed the textures was really getting on my nerves). My solution seems to work fine, and is pretty easy. No guarantees though - it's likely I've missed something somewhere...

Anyway, a brief summary of my changes:

NGUIJson.cs:
Just under
bool rotated = (bool)table["rotated"];
add
newSprite.isRotated = rotated;

UIAtlas.cs
Under
public bool hasPadding { get { return paddingLeft != 0f || paddingRight != 0f || paddingTop != 0f || paddingBottom != 0f; } }
add
public bool isRotated;

UISprite.cs
Under
float pixelSize = atlas.pixelSize
add
if (mSprite.isRotated)
{
float tmp = rect.width;
rect.width = rect.height;
rect.height = tmp;
}


Replace
uvs.Add(uv1);
uvs.Add(new Vector2(uv1.x, uv0.y));
uvs.Add(uv0);
uvs.Add(new Vector2(uv0.x, uv1.y));

with
if (!mSprite.isRotated)
{
uvs.Add(uv1);
uvs.Add(new Vector2(uv1.x, uv0.y));
uvs.Add(uv0);
uvs.Add(new Vector2(uv0.x, uv1.y));
}
else
{
uvs.Add(new Vector2(uv1.x, uv0.y));
uvs.Add(uv0);
uvs.Add(new Vector2(uv0.x, uv1.y));
uvs.Add(uv1);
}


That should be it!

ArenMook - if this looks OK to you, any chance you could drop it into the next version? I'd hate to have to merge it in every time.

Cheers!
Rob.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Create Atlas by Texture Packer with "rotation" sprite ?
« Reply #16 on: December 20, 2012, 11:19:04 AM »
Absolutely. Just keep in mind this wont affect sliced sprites or filled sprites. Just regular sprites.

Kiu

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 2
    • View Profile
Re: Create Atlas by Texture Packer with "rotation" sprite ?
« Reply #17 on: January 24, 2013, 04:48:09 AM »
@RobD: Thank you! Great help to squeeze the last few sprites into a tight ram budget. Would love to see this in the full version.

ranilian

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 24
    • View Profile
    • Industry Corporation
Re: Create Atlas by Texture Packer with "rotation" sprite ?
« Reply #18 on: May 14, 2013, 02:53:45 PM »
Any updates on this? I still can't see it in the Pro version.

PoN

  • Full Member
  • ***
  • Thank You
  • -Given: 1
  • -Receive: 4
  • Posts: 111
    • View Profile
Re: Create Atlas by Texture Packer with "rotation" sprite ?
« Reply #19 on: May 14, 2013, 09:31:51 PM »
Interesting to me too, Up
Worked on Doc&DogAge Of Fury 3D. Actually working on WarMach.

Zophiel

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 54
    • View Profile
Re: Create Atlas by Texture Packer with "rotation" sprite ?
« Reply #20 on: July 02, 2013, 07:26:25 AM »
I'm curious as well on what the status is on this? More so if i can use Texture Packer to generate my atlases and if so how do i import them for use with NGUI?

I'd love to use the rotate feature, it makes my textures oh so small!

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Create Atlas by Texture Packer with "rotation" sprite ?
« Reply #21 on: July 02, 2013, 10:12:49 AM »
From what I remember the posted code drew rotated sprites in the wrong order (back-faced) resulting in the sprite being inside-out. That combined with the fact that it only handled regular sprites, and not sliced, filled, or tiled sprites created too many inconsistencies for me to add it as-is.

Zophiel

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 54
    • View Profile
Re: Create Atlas by Texture Packer with "rotation" sprite ?
« Reply #22 on: July 03, 2013, 03:24:32 AM »
Is there a specific reason why the custom packer doesnt rotate sprites?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Create Atlas by Texture Packer with "rotation" sprite ?
« Reply #23 on: July 03, 2013, 04:27:15 AM »
Nothing does. Only TexturePacker rotates sprites, if enabled.

nah0y

  • Sr. Member
  • ****
  • Thank You
  • -Given: 1
  • -Receive: 2
  • Posts: 430
  • \o/
    • View Profile
Re: Create Atlas by Texture Packer with "rotation" sprite ?
« Reply #24 on: July 03, 2013, 04:28:01 AM »
Yup, I'm using TexturePacker with NGUI and it's much more powerful (no offense) than the one in NGUI :)

splash

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 4
    • View Profile
Re: Create Atlas by Texture Packer with "rotation" sprite ?
« Reply #25 on: July 04, 2013, 05:07:21 AM »
Hi, I just make some modify to UISprite and make it possible to use rotated sprite in Simple / Sliced / Tiled / Filled type. :D
I attached the patch file and if any problem please let me know :)


ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Create Atlas by Texture Packer with "rotation" sprite ?
« Reply #26 on: July 04, 2013, 08:34:26 AM »
Nice. You even #ifdef'd the whole thing -- that's useful, thanks.

Zophiel

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 54
    • View Profile
Re: Create Atlas by Texture Packer with "rotation" sprite ?
« Reply #27 on: July 08, 2013, 03:47:53 AM »
Sounds awesome. Can i apply the patch myself somehow or should i wait for an update?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Create Atlas by Texture Packer with "rotation" sprite ?
« Reply #28 on: July 08, 2013, 11:30:30 AM »
Can't apply it as-is unfortunately as splash is either not a Pro user or didn't use the pro repository, so revision numbers don't match.

Zophiel

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 54
    • View Profile
Re: Create Atlas by Texture Packer with "rotation" sprite ?
« Reply #29 on: July 08, 2013, 01:15:03 PM »
Is the #if flag set through the atlas information from TexturePacker? the patch file looks pretty straight forward. Guess i should test in an empty project.