Possible to use SpriteManager with Mesh.CombineMeshes?

This is the place to find out how to accomplish something specific with SM2.

Possible to use SpriteManager with Mesh.CombineMeshes?

Postby seno » Tue Jul 05, 2011 9:58 am

First of all, please excuse my bad English.

I have been using SpriteManager2 and most working with Sprite class to run animations with
changing animation textures in run time.

Recently, I noticed that I need to reduce draw calls to improve performance.
And the one way to achieve the goal is using Mesh.CombineMeshes and Texture2D.PackTextures, together.

My question is,
if using animation sprites altas is ready via using Texture2D.PackTextures method, then
is it possible to use SpriteManager's Sprite class with Mesh.CombineMeshes?

If so, how can I do that?
For now, I am pretty sure that the combined mesh and the packed sprite atlas texture are ready.

Thanks in advance.
seno
 
Posts: 14
Joined: Thu Jan 06, 2011 9:23 am

Re: Possible to use SpriteManager with Mesh.CombineMeshes?

Postby seno » Tue Jul 05, 2011 12:05 pm

I researched little bit and I start to get feeling that, it's hard to get to use
SpriteManager with the combined meshes.

If so, do you have any idea to reduce the draw call with using SpriteManager(especially Sprite class)?
seno
 
Posts: 14
Joined: Thu Jan 06, 2011 9:23 am

Re: Possible to use SpriteManager with Mesh.CombineMeshes?

Postby Brady » Tue Jul 05, 2011 10:52 pm

Actually, don't use Mesh.CombineMeshes. Instead, mark the sprites as "Managed" (using the Managed check box), and then assign a SpriteManager object to them. This will combine all sprites into a single skinned mesh. You'll find a demonstration in the "Managed Sprites" tutorial video on the SM2 product page.
Brady
 
Posts: 5361
Joined: Tue Jul 06, 2010 11:33 pm

Re: Possible to use SpriteManager with Mesh.CombineMeshes?

Postby seno » Wed Jul 06, 2011 1:03 am

Ok. I will check the "Manged" Sprites" tutorial.

Thanks Brady.
seno
 
Posts: 14
Joined: Thu Jan 06, 2011 9:23 am

Re: Possible to use SpriteManager with Mesh.CombineMeshes?

Postby seno » Wed Jul 06, 2011 2:34 am

I checked the sprite manager tutorial and I would like to confirm my understanding. :geek:

First of all, the sprite objects to be combined might use different textures.

So, first, I need to pack all textures to one texture atlas.

Then, I need to set the texture atlas to the sprite manager and all sprite objects.
For sprite objects, I need to set proper uvs coordinates.

At last, if I set the sprite manager to all sprite objects to be combined(managed), then
those sprite objects will be drawn as one draw call.

I think only different with the tutorial is using the texture atlas.
:? Is this ok to use the texture atlas with SpriteManager?

Thanks.

Danny
seno
 
Posts: 14
Joined: Thu Jan 06, 2011 9:23 am

Re: Possible to use SpriteManager with Mesh.CombineMeshes?

Postby Brady » Wed Jul 06, 2011 2:44 am

seno wrote:So, first, I need to pack all textures to one texture atlas.

Yes, but this is automated if you're using the PackedSprite component, you just run the atlas builder from the menu and it builds the atlases for you.

Then, I need to set the texture atlas to the sprite manager and all sprite objects.

Actually, you only need to assign the material that uses the atlas to the SpriteManager. Nothing but the SpriteManager needs to be assigned to the sprites.

For sprite objects, I need to set proper uvs coordinates.

No, if you use PackedSprite as described above, the UVs are generated as part of the atlas building process.

At last, if I set the sprite manager to all sprite objects to be combined(managed), then
those sprite objects will be drawn as one draw call.

Yes. The way you do that is you check the "Managed" box on a sprite, then drag the SpriteManager object onto the "Manager" field in the sprite's inspector.
Brady
 
Posts: 5361
Joined: Tue Jul 06, 2010 11:33 pm

Re: Possible to use SpriteManager with Mesh.CombineMeshes?

Postby seno » Thu Jul 07, 2011 1:17 am

Actually, what I am developing is building city style game, like cityvill and framvill of Zinga.

following is an example picture of Zinga's city vill
http://cfile25.uf.tistory.com/image/1446BE524DE03FEF24C1FB

So, right now, I am using Sprite class, not PackedSprite and the Sprite objects that are used for
the structure to be built on the land. To do that, I prepared a prefab that contains Sprite component
and a component that changes texture and configures the Sprite component to run animations for
the different texture sizes(could handle different frame numbers).

For this case, I can't use atlas builder for sure, because it only works for the built PackedSprite instance in Editor time. Right?

To prevent loading unnecessary textures, I chose to build atlas textures only only for structures to be placed on the land.
Therefore, I built texture atlases using Texture2D.PackTexture. I said atlas textures because limiting texture size 1024 x 1024 caused
to use multiple texture atlases.

After building texture atlases, I faced to combine the structures using the Sprite component, but I couldn't achieve what I want so far.

First, I tested using SpriteManager using the SpriteManager object with material that was created in run time, but I failed.
Also, I couldn't get how to assign textur atlas UVs those are returned from Texture2D.PackTexture to the Sprite objects those are
managed by a SpriteManager object.

Many times I returned to this question :| , which Is, Is it possible to use SpriteManager component for the object with the Sprite component
that is created dynamically(with the sprite texture that is decided in run time)?

Thanks.

Danny
seno
 
Posts: 14
Joined: Thu Jan 06, 2011 9:23 am

Re: Possible to use SpriteManager with Mesh.CombineMeshes?

Postby seno » Thu Jul 07, 2011 1:20 am

Any advice will be very appreciated.

Mean time, I will drill to the way to use SpriteManager Component!
seno
 
Posts: 14
Joined: Thu Jan 06, 2011 9:23 am

Re: Possible to use SpriteManager with Mesh.CombineMeshes?

Postby seno » Thu Jul 07, 2011 9:28 am

Hi.

While I was dealing with this problem, I got another question to ask.

Is it possible to add objects with the Sprite component to the SpriteManager component in run time by scripts?
I tried to add in the Unity Editor in run time, however I never made it.
seno
 
Posts: 14
Joined: Thu Jan 06, 2011 9:23 am

Re: Possible to use SpriteManager with Mesh.CombineMeshes?

Postby seno » Thu Jul 07, 2011 11:13 am

I think I made it works.

However, the ordering problem is still remained.

It's about drawing order between unmanaged objects using the Sprite components and managed objects also using the Sprite components.

I have several structures with the Sprite component and they are managed by one SpriteManager component. Also, several citizens walk
between structures and the drawing order problem arised.

Hmm. What should I do?
seno
 
Posts: 14
Joined: Thu Jan 06, 2011 9:23 am

Next

Return to SM2 How to...

Who is online

Users browsing this forum: BobbyMam and 7 guests