Search Unity

MegaGrab

Discussion in 'Assets and Asset Store' started by SpookyCat, Apr 15, 2011.

  1. Rolands

    Rolands

    Joined:
    Aug 15, 2010
    Posts:
    90
    hi
    so i want to store this image in web in mysql database, and what i wanted to know is - which variable i need to sent as byte array to do it. output1? i am not sure..
     
  2. SpookyCat

    SpookyCat

    Joined:
    Jan 25, 2010
    Posts:
    3,762
    If you are just wanting the raw values then depending on whether you are using TGA or JPG you can use the byte[] output1; or the Color[] outputjpg; arrays. If you want the actual jpg or tga format data then you will need to alter the SaveTGA or SaveJPG methods a little to get the actual file format data. The jpg one is simple as you can just use the byte[] TexData returned from the jpg encoder, for the TGA one you will need to change the bw.write lines to write to an array and then use that.
     
  3. Rolands

    Rolands

    Joined:
    Aug 15, 2010
    Posts:
    90
    so i am trying to upload this image i get form your code, to server, upload works fine, i see image but it is 0 Kb so i am doing something wrong. maybe you plz can take a look
     
  4. proso

    proso

    Joined:
    May 24, 2012
    Posts:
    67
    The 'estimated time' function is great. I used it in my game. In the editor the estimated time is calculated, but in game mode it sticks to 0... Why is that, or what am I doing wrong?
     
  5. SpookyCat

    SpookyCat

    Joined:
    Jan 25, 2010
    Posts:
    3,762
    @Rolands - Sorry for the delay, from your code I don't actually see anywhere where you have done a grab, you are just using the memory arrays but you haven't done a grab to fill them up.

    @proso - You would just need to call the CalcEstimate() method on line 565 of MegaGrab.cs (you can alter the 0.41f value to get a more accurate estimate if you time an actual grab, that value works for my machine, you could even have that value calculated by timing the last grab done) you will need to make that method public to call it from outside of the MegaGrab class though.
     
  6. proso

    proso

    Joined:
    May 24, 2012
    Posts:
    67
    Thanks, I'll try that. I've got an other question in addition to my earlier post. I'm trying to make a simple (in game) funtion to make screenshot with DOF. It must be a 'use dof' button with a slider, for the amount of blur. I ask for some kind of pointer to measure the focus distance to an object. But it also would be super cool to see the result of these dof setting realtime (before saving it). Is that also possible?
     
  7. SpookyCat

    SpookyCat

    Joined:
    Jan 25, 2010
    Posts:
    3,762
    There is a script called DOFCamera.cs that if added along with the grab script and the camera you use selected will show you the point of focus of the DOF effect. As for doing a display of the result that isn't really possible as the DOF effect is done by moving the camera around the circle the number of sample times taking a grab and then blending them all together to get the end result. This system is really aimed at preparing poster and banner size grabs for presentations and shows so wasn't really built for speed.
     
  8. Rolands

    Rolands

    Joined:
    Aug 15, 2010
    Posts:
    90
    so i still trying to upload thies images to server
    this works fine in standalone and editor, but dosent work in web player. what i am doing wrong, i just dont know..
     
  9. SpookyCat

    SpookyCat

    Joined:
    Jan 25, 2010
    Posts:
    3,762
    Hopefully someone will have an answer for you, you may be better off posting this in another thread as it is more about uploading files than MegaGrab so you may get better help. I have personally not used the WWW part of Unity so cant offer and advice on your code snippet.
     
  10. proso

    proso

    Joined:
    May 24, 2012
    Posts:
    67
    Hi SpookyCat, are you thinking about implementing this in a next release? Thanks.
     
  11. SpookyCat

    SpookyCat

    Joined:
    Jan 25, 2010
    Posts:
    3,762
    A small update has been submitted to the Asset Store which will fix an error on newer versions of Unity. A 'Use Coroutine' options has been added which will force the grab to take place at the very end of the frame, so if you are using the system and you get a ReadPixels error when trying to grab check the Use Coroutine box and all will be good again.
     
  12. rebser

    rebser

    Joined:
    Nov 13, 2012
    Posts:
    6
    Hi Spooky!
    I purchased your app because I was trying to render videos with it. I've upgraded it with a simple solution to switch to "capture mode" and make a screenshot every frame. I've set my game on a fixed frame rate so all looks fine for the first 15 minutes.
    Unfortunately, if used so heavily, MegaGrab seems to leak memory like there's no tomorrow, about 10 MB every one or two frames according to Activity Monitor. So once it has filled my 4 GBs of RAM, the rendering grinds to a halt.
    Have you tried this? Any idea what might be happening there?
     
  13. SpookyCat

    SpookyCat

    Joined:
    Jan 25, 2010
    Posts:
    3,762
    Hi There
    I suspect that is not actually a leak but the garbage collector not kicking in, if you add a GC.Collect() call somewhere it will force the Mono garbage collector to be called returning the memory to the heap.
    Chris
     
  14. rebser

    rebser

    Joined:
    Nov 13, 2012
    Posts:
    6
    Hi Chris,
    I found it! If you create a new Texture2D, you have to destroy it, otherwise it will leak. Try it.
    You'll have to Destroy() your grabtex AND your tex references.
    I've added Destroy(grabtex) in CleanUp() and Destroy(tex) in DoGrabTGA() and that fixed the leak as far as I can see.

    Cheers and thanks for the great tool!
    Robin
     
    Last edited: Nov 13, 2012
  15. kaz2057

    kaz2057

    Joined:
    Jan 18, 2011
    Posts:
    326
    Dear Spooky,
    I check your code and I have a question

    On this lines
    Why you not use fs.Close on SaveJPG function? Is it wrong?
    And then ... BinaryWriter need to be ".Close()" also?
     
    Last edited: Nov 27, 2012
  16. SpookyCat

    SpookyCat

    Joined:
    Jan 25, 2010
    Posts:
    3,762
    I will add the close in, it is not strictly required as the file will be closed by the GC and until then the OS will hold a lock on the file but for sake of good coding practice I will add the close, I blame MSDN :) The examples on using filestream on MSDN all neglect to use close :)
     
  17. dwgagner

    dwgagner

    Joined:
    Nov 29, 2012
    Posts:
    2
    So I'm fairly new at using unity and I cannot find any information on how to setup this package in unity the first time. As in what to drag the scripts onto etc to get it to work. I thought that I had to drag the mega grab onto the scene camera and then feed the camera into the source camera, when I run the game and screen grab it appears to work but nothing is saved anywhere so obviously im doing something wrong. Help is appreciated.
     
  18. SpookyCat

    SpookyCat

    Joined:
    Jan 25, 2010
    Posts:
    3,762
    Can you email me at chris@west-racing.com with a grab of the inspector so I can check your settings.
     
  19. SpookyCat

    SpookyCat

    Joined:
    Jan 25, 2010
    Posts:
    3,762
    Quick note to say that the MegaGrab system is now included free in both the MegaFiers and the MegaShapes systems.
     
  20. mk1978

    mk1978

    Joined:
    Dec 27, 2009
    Posts:
    276
    Did you managed to get it to work with videos? I am making architectural fly through animations (about 20-30 sec. video clips) with Unity and this could be beneficial for that purpose.
     
  21. rebser

    rebser

    Joined:
    Nov 13, 2012
    Posts:
    6
    I did and it works. But I had to modify Chris's code for it. See my latest post above.
     
  22. amaceika

    amaceika

    Joined:
    Aug 27, 2012
    Posts:
    8
    Hey Cat,
    i keep gettign this error while using MegaGrab.
    ReadPixels was called to read pixels from system frame buffer, while not inside drawing frame.
    UnityEngine.Texture2D:ReadPixels(Rect, Int32, Int32)
    MegaGrab:GrabImage(Int32, Single, Single) (at Assets/Mega-Fiers/Scripts/MegaGrab/MegaGrab.cs:225)
    MegaGrab:DoGrabJPG() (at Assets/Mega-Fiers/Scripts/MegaGrab/MegaGrab.cs:482)
    MegaGrab:LateUpdate() (at Assets/Mega-Fiers/Scripts/MegaGrab/MegaGrab.cs:602)
    not to sure why.. think you can help me out?
    thanks
    amceika
     
  23. amaceika

    amaceika

    Joined:
    Aug 27, 2012
    Posts:
    8
    i found your solution but i dont have the updated version since i bought mega fiers not just mega grab>...:-x
     
  24. proso

    proso

    Joined:
    May 24, 2012
    Posts:
    67
    Hi, does Megagrab work in Unity4?
     
  25. SpookyCat

    SpookyCat

    Joined:
    Jan 25, 2010
    Posts:
    3,762
    Yes it does.
     
  26. SpookyCat

    SpookyCat

    Joined:
    Jan 25, 2010
    Posts:
    3,762
    Just submitted v1.15 to the assetstore that fixes a couple of syntax errors in the last version.
     
  27. portaplay

    portaplay

    Joined:
    May 17, 2013
    Posts:
    10
    Stupid question:

    Earlier on, I could screenshot while the editor was in pause mode, that does not seem to work anymore?
    -or is that just me doing something wrong (have tried to change the default grab key)...

    I am not using DOF or similar
     
  28. SpookyCat

    SpookyCat

    Joined:
    Jan 25, 2010
    Posts:
    3,762
    That wouldn't be possible, the grabber uses the update method to check for a key press so if the editor is paused the update would not be called. If you need that functionality it would be easy to add a grab now button to the inspector.
     
  29. portaplay

    portaplay

    Joined:
    May 17, 2013
    Posts:
    10
    Okay, might be my bad memory then. But such a functionality sure would be awesome, as you often want to play, pause, pose stuff, then screenshot.
    -but I don't think you would need to screenshot from "normal editor mode" (not in "play mode") very often.
     
  30. laserlars

    laserlars

    Joined:
    Nov 17, 2011
    Posts:
    255
    Hi Spooky,

    So I got the "ReadPixels was called to read pixels from system frame buffer, while not inside drawing frame.
    UnityEngine.Texture2D:ReadPixels(Rect, Int32, Int32)" -error.

    But no picture is created even if "Use Coroutine" is checked. Any ideas what might be going wrong?
     
    Last edited: May 18, 2013
  31. SpookyCat

    SpookyCat

    Joined:
    Jan 25, 2010
    Posts:
    3,762
    Which version of Unity is this on? You said it works on other projects just not in the one you need it in? Do you have any other components attached to the camera?
     
  32. laserlars

    laserlars

    Joined:
    Nov 17, 2011
    Posts:
    255
    Unity 4.1.04f
    And no, no other components attached.
     
  33. GlitchInTheMatrix

    GlitchInTheMatrix

    Joined:
    Apr 12, 2010
    Posts:
    285
    Hi SpookyCat, this tool looks fantastic!

    Are you going to give animation support to it? render 30fps per frames or something?

    will be cool can use unity like batch render engine.
     
  34. SpookyCat

    SpookyCat

    Joined:
    Jan 25, 2010
    Posts:
    3,762
    Well it would be very easy for any user to add a simple script to call a grab every frame (wold need to set the timestep so the game updates correctly), and then use an offline program to combine those into a video.
     
  35. SpookyCat

    SpookyCat

    Joined:
    Jan 25, 2010
    Posts:
    3,762
    Sequence Grab Added
    We have just added the ability to grab sequences of images all using the upscaling and AA values if you want so you can render out a sequence of very high quality high res anti aliased images which you can then join together using your favorite software to build an HD or even 4k video of your game. The help page on the website has been updated to show the changes and the new inspector for MegaGrab.
     
  36. SpookyCat

    SpookyCat

    Joined:
    Jan 25, 2010
    Posts:
    3,762
    Another small update to the Grab system, now forces a garbage collection at the end of the grab so if you are doing multiple very large grabs there should be no out of memory issues. We also changed the default values so they are in line with Unity 4.x use as opposed to Unity 3.5.
     
  37. I am da bawss

    I am da bawss

    Joined:
    Jun 2, 2011
    Posts:
    2,574
    Hey Chris, just updated to the latest MegaGrab and got the following warnings:

    Assets/MegaGrab/MegaGrab.cs(480,29): warning CS0219: the variable "total" is assigned by its value is never used
    Assets/MegaGrab/MegaGrab.cs(733,39): warning CS0219: the variable "time" is assigned by its value is never used
     
  38. ScrappyRMH

    ScrappyRMH

    Joined:
    Apr 11, 2011
    Posts:
    48
    Does this work with in the Unity webplayer?
     
  39. SpookyCat

    SpookyCat

    Joined:
    Jan 25, 2010
    Posts:
    3,762
    Thanks da Bawss, those lines have been removed and new version submitted.

    @ScrappyRMH - Yes it works in the standalone, mobile or editor, though in webplayer you may not have access to the local machine for saving files, but there is also an option to upload a grab directly and there is a php script in the readme for putting on your server which will receive the grabs and save them on the server.
     
  40. I am da bawss

    I am da bawss

    Joined:
    Jun 2, 2011
    Posts:
    2,574
    Thanks Chris! :)

    Strangely, I got another one after updating :

    Assets/MegaGrab/MegaGrab.cs(726,39): warning CS0219: the variable "t" is assigned by its value is never used
     
  41. krillmcrawl0

    krillmcrawl0

    Joined:
    Jan 13, 2014
    Posts:
    35
    Hi!

    I just bought the system, and here are some questions:

    I can't really figure out where the system gets it's grab size from. Rescaling the game window does not update the grab size and resizing the editor window I get updated values only if I drag and resize from the right side of the viewport. I am using the system in the editor and maybe screen.width and screen.width uses the editor window size and not the game views size? I guess this is not the correct behavior?

    Would it be possible to add so that we can choose a pixel resolution as well by entering into the GUI, for example 1280x720? (system would calculate the necessary upscale etc based on game view size)

    When I hit play I would like to see a preview of what I'm getting (does not have to be correct size offcourse since upscaling would make it extremly large but at least correct width and height ratio). When editor is stopped, reset to whatever value the size of the game window was before hitting play.

    Best Regards,

    Kristian
     
  42. SpookyCat

    SpookyCat

    Joined:
    Jan 25, 2010
    Posts:
    3,762
    Thanks for the purchase. The system just multiplies up whatever resolution the rendering window is running at, it is not possible to change the res of the final grab in any other way ie setting a grab size as it has to be a multiple of the screen size. The values may not update in the inspector if you drag the window sizes, I will see if that can be added to the inspector code, but if you have an upscaling value of 4 and you are running the game with a render window of 1270x720 then the final image will be 5080 x 2880, if you drag your window sizes the resolution of the grab will be 4 times whatever the new window size is.

    Not sure what you mean when yoo say when you hit play you would like a preview, the running game is the preview, not sure what else you need there :)
     
  43. krillmcrawl0

    krillmcrawl0

    Joined:
    Jan 13, 2014
    Posts:
    35
    Wow, thats a really quick respone, thank you!

    In editor:
    Lets say I put 1280x720 as my wanted export resolution in the GUI
    I hit play:
    Game windows aspect will update itself to 16:9 (1,77) and set the resolution to 640x360 and Upscale res updates itself to 2
    When I hit stop the size and aspect of the game window would be reset to what I had earlier.

    This way I have control of both the output resolution and I get a preview with correct aspect ratio. Not sure if I'm the only one thinking that this would be handy:)
     
  44. SpookyCat

    SpookyCat

    Joined:
    Jan 25, 2010
    Posts:
    3,762
    Iam not sure one can control the Unity editor windows in that way. You can set the play mode res in the player settings and select that in the drop down on the top left of the game window. I am still not sure what benefit doing that will bring though, people taking screen shots set the game to play in the res they want and then just set the upscaling value to get an image of the res they need for printing etc.
     
  45. krillmcrawl0

    krillmcrawl0

    Joined:
    Jan 13, 2014
    Posts:
    35
    I think I mainly got confused about why the why the grab size in th GUI never matched the output of my images, since the GUI it does not update the values from the game window. For a novice user like me it would be easier just to specify the output resolution and click a keyboard button:)

    I also noticed that in the Aspect dropdown menu in the game view you can add custom resolutions by clicking the plus at the bottom, makes things easier as long as you remember to resize the game window to be large enough.

    I think if you add so that the system updates the grab size depending of what the size of the game window it would all be clear:)

    Thanks!
     
  46. SpookyCat

    SpookyCat

    Joined:
    Jan 25, 2010
    Posts:
    3,762
    I see the issue now and have fixed it. It seems when you ask Unity for the Screen size in an editor script it decides to not tell you the game screen size but instead the inspector window size, even if you ask the camera for its pixel width and height again it will not tell you the game or even scene view size but the inspector window. I have changed the way the label calcs the actual grab size now so it should show the correct game window grab size now. An update will go up today at some point. Amazing no one else spotted that little bug :)
     
  47. SpookyCat

    SpookyCat

    Joined:
    Jan 25, 2010
    Posts:
    3,762
    New version with fixed grab size info in the asset store now.
     
  48. jcarpay

    jcarpay

    Joined:
    Aug 15, 2008
    Posts:
    561
    Just checked the new version. The width value is returned correctly, but the height value doesn't appear to equal the gameview's value. It always adds 17 pixels (menu bar height size) to the height compared to the gameview.

    $megagrab.jpg
     
    Last edited: Jan 14, 2014
  49. SpookyCat

    SpookyCat

    Joined:
    Jan 25, 2010
    Posts:
    3,762
    That is the best that can be done without guessing at the size of whatever borders Unity adds into the renderview, if it is always 17 pixels then can factor that in but the label that displays the info is only really there as a guide, the correct size grab is done. I will investigate further if there is a better way to find the actual render view size from an editor script, if anyone knows of a way please do share :) It does seem odd that even the Unity Camera returns inspector window sizes instead of what it is actually rendering to when asked from an Editor script.
     
  50. krillmcrawl0

    krillmcrawl0

    Joined:
    Jan 13, 2014
    Posts:
    35
    Can I call the render function in Megashot from my own script? I'm doing custom cubemap renders and need to be able to generate 6 highres images for each cubemap, I already have the code running for this using rendertextures and rotating the camera. The rendertextures lack antialiasing and rendering everything in twice the resoluton takes to much time. 10 min for each cubemap and I got hundreds of them, it will take days if I can't use Megagrab:)