Search Unity

  1. Unity 2019.1 is now released.
    Dismiss Notice

Runtime Preview (Thumbnail) Generator (Open Source)

Discussion in 'Assets and Asset Store' started by yasirkula, Oct 14, 2017.

  1. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    920
    Last edited: Mar 16, 2018
    mgear, christoph_r, deltamish and 2 others like this.
  2. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    920
    Now available on Asset Store!
     
  3. Darkirby3

    Darkirby3

    Joined:
    Apr 24, 2017
    Posts:
    2
    This is perfect ! You saved me a big headache. This is exactly what I was searching for my inventory system.

    If you are interested I would like to offer you a special account into my video game. You can find my game at www.citywars.ca. We are still far away from having a playable game but piece by piece we get further from a prototype. Your system is now part of our inventory system. :D
     
    yasirkula likes this.
  4. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    920
    It's nice to hear :) Thank you for your offer. I don't have free time for games nowadays but thanks again for your kindness, I appreciate it.
     
  5. Darkirby3

    Darkirby3

    Joined:
    Apr 24, 2017
    Posts:
    2
    Yeah i understand. Well Thanks again. If you need anything lets us know !

    Also if you change your mind latter you're still welcome ;P
    Have a nice day !
     
  6. Play_Edu

    Play_Edu

    Joined:
    Jun 10, 2012
    Posts:
    715
  7. matteumayo

    matteumayo

    Joined:
    Jul 25, 2016
    Posts:
    170
    Hello! First of all, thank you so much for sharing this asset, it's wonderful and exactly what I needed.

    I am having an issue however - has anybody figured the issue with this asset and Unity 2018? After upgrading, I recall seeing an error or warning about it, and since seeing that it's stopped working - annoyingly, there has been no error/warning since then, (I really wish I addressed it immediately - my next step is to make a new project and import to see if I can catch the error a second time) so I'm having trouble troubleshooting the issue.

    I tried finding an upgrade guide for 2018 with changes/deprecation but couldn't - if anyone could help I'd be very thankful! And I'll post here if I find the solution myself of course.
     
  8. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    920
    I was able to test the following code with success on a new scene with no post-processing applied on Unity 2018.1.3f1:

    Code (CSharp):
    1. public RawImage img;
    2. public Transform obj;
    3. private void Start()
    4. {
    5.     img.texture = RuntimePreviewGenerator.GenerateModelPreview( obj );
    6. }
    There were no error or warning messages for me while importing the plugin.
     
    matteumayo likes this.
  9. matteumayo

    matteumayo

    Joined:
    Jul 25, 2016
    Posts:
    170
    Thanks for the help. I found that it actually no longer occurs on 2018.2.0f1. We've moved builds a few times in the last few weeks, so it must have been some temporary issue that resolved itself - works just fine after testing again (should've done that before posting. My apologies!)
     
    yasirkula likes this.
  10. mathias_unity633

    mathias_unity633

    Joined:
    Jul 17, 2018
    Posts:
    26
    Any idea about soft shadows but transparent backgrounds? My best solution so far is just having a fake shadow, a sprite, that is resized to the bounding box of the object you're rendering, and repositioned to right below the bounding box. You can probably do it with 'real' shadows if you use some special shader on a plane below the object (?)
     
  11. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    920
    Yes you could use such a special shader (this could be a good starting point). However, as an object's shadow may overflow its bounding box, parts of the shadow may not be visible in the generated thumbnail.
     
  12. mathias_unity633

    mathias_unity633

    Joined:
    Jul 17, 2018
    Posts:
    26
    Yeah, depends on which direction you cast the shadow. I think a way to go around that issue would be to feather the thumbnail near the edges :D
     
  13. dcam_unity

    dcam_unity

    Joined:
    Dec 1, 2018
    Posts:
    1
    Hi there, I just had a question regarding this thumbnail generator. Right now I have a video player, and I save the texture of the video player to a RawImage. I want to generate a thumbnail based on the texture of the RawImage, but every time I try calling RuntimePreviewGenerator.GenerateModelPreview I get a null object.

    Code (CSharp):
    1. image.texture = videoPlayer.texture;
    2. thumbnail = RuntimePreviewGenerator.GenerateModelPreview(image.transform, 64, 64, true);
    3.  
    Am I calling runtime preview generator right or am I missing something?
     
  14. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    920
    RuntimePreviewGenerator can only work on objects with Renderer components. For a thumbnail of an existing texture, you may want to use the TextureOps.Scale function here: https://github.com/yasirkula/UnityTextureOps
     
  15. Firlefanz73

    Firlefanz73

    Joined:
    Apr 2, 2015
    Posts:
    1,018
    Hello,

    thanks a lot for this asset :)

    Is there a way to get the grey background completly transparent (Alpha)?

    Thanks!
     
  16. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    920
    RuntimePreviewGenerator.TransparentBackground = true;
    should do it.
     
    Firlefanz73 likes this.
  17. klhurley

    klhurley

    Joined:
    Dec 11, 2014
    Posts:
    2
    yasirkula likes this.
  18. Firlefanz73

    Firlefanz73

    Joined:
    Apr 2, 2015
    Posts:
    1,018
    Perfect! Thanks :)
     
  19. iddqd

    iddqd

    Joined:
    Apr 14, 2012
    Posts:
    370
    Hi, this tool is great and I see you have a ton of other clever content available. Thank you for that!

    I do have a question though, do you think there's a way for GenerateMaterialPreview to ignore the Ambient Lighting so it always looks the same, similar to the Unity Inspector Material Preview?

    Thanks
     
  20. iddqd

    iddqd

    Joined:
    Apr 14, 2012
    Posts:
    370
    Ok so I seem to be successful by changing the ambient mode and then changing it back again:

    Code (CSharp):
    1.  
    2. RenderSettings.ambientMode = UnityEngine.Rendering.AmbientMode.Flat;
    3. float oldIntensity = RenderSettings.ambientIntensity;
    4. RenderSettings.ambientIntensity = 1f;
    5.  
    6. sourceTexture = RuntimePreviewGenerator.GenerateMaterialPreview(prefab, PrimitiveType.Quad, 512, 512);
    7.  
    8. RenderSettings.ambientMode = UnityEngine.Rendering.AmbientMode.Skybox;
    9. RenderSettings.ambientIntensity = oldIntensity;
    10.  
    I've also added a Layer to the GameObject, so I can exclude it from the Directional Light.

    Perfect I would say.
    Thanks!
     
    yasirkula likes this.
  21. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    920
    I was about to suggest the same, good thinking!
     
    iddqd likes this.