|
Could anyone possibly show me how to transfer the byte[] of a texture from one client to another (using Unity's built in networking if possible). Essentially I would like to stream the texture from an object on client1 to an object on client 2. I would like to do this for as many frames possible (so compression/decompression would be nice). This is for experimental purposes so I'm not as concerned with bandwidth usage as I am with proof of concept. Any help achieving this affect would be greatly appreciated.
(comments are locked)
|
|
With unity networking, nope, not reasonably as you have to convert all to strings and even there you have size limits. But with regular sockets, there is no reason why it shouldn't work You could even use OnSerializeNetworkView with reliable delta compression and setup your own transfer protocol. There you can stream all kind of data, you just have to make sure that the receiving peer reads the same amount that have been sent. I use this method for our Hack&Slash game to transfer server snapshots of different sizes but i use unreliable of course ;) You have to serialize always some kind of header so the receiving peer knows what data follows. So it is possible but i guess it's less limited with sockets. Well, sockets have of course the limitation that you can't open a listening socket in a webplayer while with unity network you can start a server.
Jul 13 '11 at 03:06 AM
Bunny83
@Warwick- I don't see how I could send the entire Color[] on a per frame basis (the bitstream does not support Color[] serialization). I could probably split up the Color[] into ints and then (on the other end) reconstruct the Color[] and subsequently read the pixels. However this would mean the texture on client B would would be multiple frames behind the texture on client A. I need a way to send the entire texture once per frame. @Dreamora- This is what I feared haha. I might I have to brush up on my .NET and get hacking away at the network code. @Bunny- This seems like an interesting idea. Exactly how would I go about setting up a custom transfer protocol that Unity's networking will accept. Is it possible perhaps to combine Warwick's suggestion and yours(send the Color[] from Texture2D.GetPixels through the OnSerializeNetworkView once per frame). If this is possible, this would be ideal. If I may add-- these are not, by any means, large textures so sending the entire texture once per frame should not be a problem as far as bandwidth goes.
Jul 13 '11 at 01:04 PM
kaleetos
(comments are locked)
|
|
You can use Texture2D's GetPixels, then transfer them the same as any other data. If you use Texture2D.EncodeToPNG and Texture2D.LoadImage it's at least compressed ;)
Jul 13 '11 at 03:08 AM
Bunny83
(comments are locked)
|
|
To those of you who want to know, Dreamora's suggestion was the route I ended up taking. I turned the textures2d.getpixels into bytes[] and sent them over standard udp sockets. Reconstructed the texture on the other side and voila, streaming textures. Just curious: what was the application for this? I'm trying to figure out why you'd want to stream a texture that's constantly changing.
Oct 26 '11 at 09:15 PM
Julien.Lynge
(comments are locked)
|

Have you tried anything yet? Do you have some code to poke at?
If you haven't already, check out some wiki scripts; they show some streaming implementation (not for textures that I can see, but it'll give you an overview of how unity handles this stuff) that might be useful to you.
http://www.unifycommunity.com/wiki/index.php?title=Special%3ASearch&redirs=0&search=stream&fulltext=Search&ns0=1
No. Really I'm just trying to figure out if this is even possible. I do see a library called ulib in the asset store that can serialize arbitrary unity components. However before I spend the $75 I want to know if maybe there is a way to do it with Unity's built in networking.
Hi. In ULIB you can encode texture to bytearray, compress, encode to string and send over RPC to other user.