Search Unity

  1. Looking for a job or to hire someone for a project? Check out the re-opened job forums.
    Dismiss Notice
  2. Unity 2020 LTS & Unity 2021.1 have been released.
    Dismiss Notice
  3. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

[FREE] YAPP - Yet Another Prefab Painter (Open Source, GitHub)

Discussion in 'Assets and Asset Store' started by Rowlan, Nov 24, 2019.

  1. Rowlan

    Rowlan

    Joined:
    Aug 4, 2016
    Posts:
    1,860
    YAPP - Yet Another Prefab Painter

    Introduction


    There are already many prefab painters available for Unity, this is yet another one. In case you have use for this one, feel free to download and use YAPP.

    It's FREE and Open Source, so also feel free to fork, modify and add more features to it.

    Here's a quick demo use case video to get you started:



    Example screenshot:

    screenshot.png

    Requirements

    • Unity 2018.3+

    Download

    http://bit.ly/PrefabPainter


    Quick Setup

    Installation
    • create a new Unity project

    • add the Yapp folder of the GitHub repository to your project

    • in Hierarchy view open the context menu and press Yapp -> Create PrefabPainter

    context menu.png


    First Steps

    The created prefab painter looks like this initially in the inspector:

    initial setup.png

    There are 2 things that are now required:

    • a container to put your prefabs in. You can use any gameobject for that. For convenience when you hit the New button, a container is generated automatically as child object of your prefab painter gameobject. But you can use whatever you prefer, it doesn't necessarily have to be a child. Just drag your container gameobject into the container slot.

    • prefabs which should be instantiated in the scene by this prefab painter and put into the specified container. The container can be cleared, i. e. the container children deleted, by using the Clear button.

    Now you can already start painting. Please read the scene view instructions about how to use the current brush, e. g. shift + mouse drag is painting with the brush.


    The Idea

    When I started Unity I thought this might be a good idea to learn coding. Creating a prefab painter is something rather trivial. All you need to do is analyze an area around the mouse cursor and instantiate a prefab there.

    However as usual one thing leads to the other and it turned out that there's always something that one wants more. The existing prefab painters - free and commercial - didn't meet my requirements. So I created my own.

    A big shoutout to the awesome people of the Unity Community who provided tutorials which I used for the more advanced features. Please see the credits section in the GitHub repository. Thanks to them coding this asset took about a week.


    Features

    Among others, these are the core features:

    • Container based

      Operates on gameobjects which are considered containers (or folders) for grouping and contain the actual prefab instances

    • Paint modes
      • Brush
        Brush settings like size, rotation, terrain alignment, slope dependency, distribution

      • Spline
        Spline settings like curve resolution, loop, separation distance, multiple lanes along the spline, snap to terrain
    • Prefab Instantiation

      Probability, scale variation, position offset, rotation offset, random rotation

    • Batch operations

      Batch operations on container children like applying Physics (gravity, other forces), copy/paste transforms

    Beta

    Please note that this is still beta and work in progress, so features may change. Also the UI might change. Currently I used standard Unity UI setup, it was rather trivial and straightforward to do so.

    Feedback is very welcome.

    Have fun :)
     
    Last edited: Nov 24, 2019
  2. p6r

    p6r

    Joined:
    Nov 6, 2010
    Posts:
    1,158
    Thanks a lot.
    A fantastic tool.
    I like the way to just drag a prefab on your panel to add it to "painting".
    6R
     
    antoripa and Rowlan like this.
  3. Rowlan

    Rowlan

    Joined:
    Aug 4, 2016
    Posts:
    1,860
    Thank you very much for the feedback in PM guys, it's very much appreciated :)

    Here's something that was requested after my post and I could add quickly: Limit the random rotation, so that bushes and trees can be painted:

    limit.png

    In the setup I simply set the random rotation to only affect the y axis. If you need some feature to set this up quicker, I'm open to suggestions. I guess adding buttons about resetting the relevant axis might be a quick start.

    Painting bushes via spline and brush looks now like this:

    bushes.gif

    I already uploaded the new version.
     
    Neviah, antoripa and konsic like this.
  4. Rowlan

    Rowlan

    Joined:
    Aug 4, 2016
    Posts:
    1,860
    I just saw that Asset Maiden released a new Western Town Asset. His Medieval Village was already awesome, so I bought this one without hesitation. Especially for $ 5.35 it's a must have.

    Then I opened his demo scene, removed everything and tried the spline prefab painter on the houses :)

    town-opt.gif

    Size doesn't matter on prefabs :D

    I guess it makes sense to have random free space around the prefab bounds. I'll add that option.

    ...

    ps: I'm not involved with Asset Maiden. His AAA assets are very cheap, I have no idea why that is, but this way he's really supporting the Community. I love to support him back, hence the mentioning.
     
    Lars-Steenhoff likes this.
  5. Rowlan

    Rowlan

    Joined:
    Aug 4, 2016
    Posts:
    1,860
    I thought I'd visualize the physics option for better understanding what's happening when you click that button and apply forces:

    physics animated.gif

    That's physics running in Editor mode. I'll push it as an option to github with the next update in case anyone fancies this kind of visualization :)

    It could be actually fun to have every prefab of a scene painted at the center of the scene and then have the physics applied and the prefabs distributed that way randomly. I might call that Genesis or the Big Bang :D
     
  6. Rowlan

    Rowlan

    Joined:
    Aug 4, 2016
    Posts:
    1,860
    I uploaded a new version, new features:
    • Splines: new Separation type "Prefab Forward Size" as preparation for Fence Builder using Splines

    • Operations: added new Selection Tool to select few (~25%), medium (~50%), many (~75%), all prefabs
      Use case: lower e. g. painted rocks randomly into the ground

    • Operations: Physics
      Created One-Shot Simulation of which the length depends on the number of Max Iterations.
      In addition to that added a Continuous Simulation which runs until the Stop button is pressed.
      The physics run as mentioned above in Editor mode.

      There's also a new Force Apply Type:
      Initial: Applies forces only at the start of the simulation, e. g. like explosion effect
      Continuous: Applies forces at every step of the simulation, e. g. like wind

    Snapshot of the new settings:

    operations.png

    And a demo with force being applied in one direction and on the other hand sending the prefabs randomly into all directions:

    physics.gif

    Watching this again, I guess it would make sense to allow you to change the gravity yourself. Will be in the next update.
     
    Last edited: Dec 14, 2019
    konsic likes this.
  7. doarp

    doarp

    Joined:
    Sep 24, 2019
    Posts:
    141
    Looks great, thanks for sharing
     
    Rowlan likes this.
  8. netpost

    netpost

    Joined:
    May 6, 2018
    Posts:
    290
    @Rowlan This asset is simply amazing!

    Thank you very much for developing and sharing this great placement tool!
     
    Rowlan likes this.
  9. netpost

    netpost

    Joined:
    May 6, 2018
    Posts:
    290
    @Rowlan Would it be possible to explain what is the Fall off distribution mode?

    Thanks again!
     
  10. Rowlan

    Rowlan

    Joined:
    Aug 4, 2016
    Posts:
    1,860
    The randomness of the distribution is determined by a curve. You could e. g. have more prefabs instantiated in the center and less on the outer bounds of the brush. Like so:

    falloff 2.jpg
    or linear:

    falloff 1.jpg
    But I just noticed I didn't push the code that effectively distributes the prefabs to github, since it was only an experiment. I think I'll remove it anyway, I haven't found a good use case yet.
     
    tobiass likes this.
  11. netpost

    netpost

    Joined:
    May 6, 2018
    Posts:
    290
    @Rowlan

    Thank you for the detail explanation. I really like the spline spawner. It 's great to be able to spawn prefabs along a spline without the need to use a third party spline asset. I also like to use the spline with a selected number of lanes. The physics operation is a great feature too. This is a great tool!
     
    Rowlan likes this.
  12. Reanimate_L

    Reanimate_L

    Joined:
    Oct 10, 2009
    Posts:
    2,458
    @Rowlan
    are you open for a feature request?
     
  13. Rowlan

    Rowlan

    Joined:
    Aug 4, 2016
    Posts:
    1,860
    Depends on what it is :)
     
  14. Reanimate_L

    Reanimate_L

    Joined:
    Oct 10, 2009
    Posts:
    2,458
    Draw and area using spline then fill the area with prefabs using distribution sampling method ie poisson disc sampling.
     
  15. Rowlan

    Rowlan

    Joined:
    Aug 4, 2016
    Posts:
    1,860
    You mean auto-updating and such while you resize the spline area? And with spline "area" you mean a polygon shape or something different?
     
    valarus likes this.
  16. Reanimate_L

    Reanimate_L

    Joined:
    Oct 10, 2009
    Posts:
    2,458
    ah yeah polygon shape might be a better term. It doesn't have to be auto updating, might be not too performant for a large area, having a button to refresh/update area might be a better solution
     
  17. Reanimate_L

    Reanimate_L

    Joined:
    Oct 10, 2009
    Posts:
    2,458
    Oh wait you already used poisson disc sampling, just need to add polygon shape fill mode it seem
     
  18. Rowlan

    Rowlan

    Joined:
    Aug 4, 2016
    Posts:
    1,860
    Yes. Question is what is the benefit of polygon shape? You are rather fast with adding and deleting using the brush.

    ui.png

    Demo:



    If you own Vegetation Studio Pro, I rather advise to use that one in case you want filling shapes, it has a lot of advanced options like smaller scale at the borders of the Biomes and such. Nothing I couldn't add though.
     
    Lars-Steenhoff likes this.
  19. Reanimate_L

    Reanimate_L

    Joined:
    Oct 10, 2009
    Posts:
    2,458
    ah i don't own VS, one benefit i can find from filling polygon shape are when we want to fill a large area quickly.
     
  20. BKprod

    BKprod

    Joined:
    Sep 19, 2014
    Posts:
    19
    Amazing tool you got there, I was looking for a replacement to Polybrush.
    I do have a few errors to remark.

    A "Fill shape" option like proposed could be a nice addition !

    The Align to Terrain option works 1 on 10 times (same thing when painting on a Mesh) :

    upload_2020-8-22_10-29-55.png

    Sometimes you can unintentionally paint prefabs on the painted prefabs. It results in a nice pile of prefabs in direction of the camera.

    When choosing Poisson distribution the prefabs no longer paint on Meshes, but only spawn on the Terrain under.

    Do you take in account if the model you're painting on has a collider ?

    Otherwise, great work !
     
  21. Rowlan

    Rowlan

    Joined:
    Aug 4, 2016
    Posts:
    1,860
    Thanks for your feedback :) Do you have a screenshot of your settings so that I can try to reproduce?

    The piling should only be possible when you activate "Allow Overlap". And the non-alignment should only be possible when you activate "Random Rotation".

    I'll see what I can do with the Poisson distribution.
     
  22. BKprod

    BKprod

    Joined:
    Sep 19, 2014
    Posts:
    19
    The piling does happend with or without "Allow Overlap" for me. I'm painting a prefab with a Capsule Collider.
    The "Align To Terrain" works effectively well, when random rotation is off. I did have it checked the last time.

    Anyway I find you tool much more responsive than others I had tested, and more simple than Polybrush, which is far too slow to paint something like a large grass plain. I love the fact that it's only one script, drag and paint.

    Thanks for sharing !
     
  23. Rowlan

    Rowlan

    Joined:
    Aug 4, 2016
    Posts:
    1,860
    Since it's Halloween I wanted to distribute some pumpkins in Lordenfel and couldn't be bothered to run physics steps with every paint. So I added a new mechanism which optionally invokes the physics automatically after painting. Looks like this:

    yapp.gif

    Quick details:

    sim.png

    Physics Simulation options:

    * None - no automatic physics simulation as before
    * Once - all physics steps in 1 simulation step
    * Continuous - animated physics, lets you see how the physics are applied

    Height Offset: is added to the prefab's painted height so that you can e.g. use gravity on it
    Step Count Max: maximum number of steps for the simulation
    Step Iterations: number of physics steps per simulation step; normally you have 1 physics step per simulation; that's not really necessary and very much depends on your processing power, but quite interesting to see how things flow with the physics
     
    Last edited: Oct 31, 2020
    koirat, Fibonaccov and valarus like this.
  24. Rowlan

    Rowlan

    Joined:
    Aug 4, 2016
    Posts:
    1,860
    Here's with Poisson Disc distribution inside the brush:

    pdd.gif
     
    Lars-Steenhoff likes this.
  25. Lars-Steenhoff

    Lars-Steenhoff

    Joined:
    Aug 7, 2007
    Posts:
    2,977
    That looks great!
    I have an idea, can you add a object attractor/repeller on mouse position?

    you could use this to tidy up some of the physics placed objects
     
    Swyfft likes this.
  26. Rowlan

    Rowlan

    Joined:
    Aug 4, 2016
    Posts:
    1,860
    You can tidy up already with holding CTRL+SHIFT while dragging. Here's spawning rocks and removing those which land in the river because of physics:



    But it's a great idea, I'll think about it. Or rather try, it's easy to add just a force towards the cursor to all gameobjects. Thank you!

    Some more:

    Falling Trees:



    Rock Placement



    There. Prefabs placed :D
     
    Last edited: Oct 31, 2020
    adamb70, Swyfft and Lars-Steenhoff like this.
  27. Lars-Steenhoff

    Lars-Steenhoff

    Joined:
    Aug 7, 2007
    Posts:
    2,977
    Yes a force towards the cursor or when holding another modifier key a force away from the cursor ( radius and force user setting )
     
    Rowlan likes this.
  28. Swyfft

    Swyfft

    Joined:
    Mar 14, 2019
    Posts:
    49
    Man.. @Rowlan .. always interesting to find stuff you’ve done...
    looks great!
     
    Rowlan likes this.
  29. StevenPicard

    StevenPicard

    Joined:
    Mar 7, 2016
    Posts:
    781
    I'm glad this thread got bumped since I wasn't aware of this. It looks great! I'm going to see about using this at run-time.

    I wanted to mention that this feature you removed could be useful. For example, spawning vegetation that's more dense in the center. Any chance of adding it back in?
     
  30. dsilverthorn

    dsilverthorn

    Joined:
    May 14, 2017
    Posts:
    655
    @Rowlan another great tool! Thanks for making this available! I didn't even know you had this out there.
    I love your work and the tools you share with us all!

    The ideas are flowing now after seeing it work.
    Luckily for me I just finished a project and now can play with it.:)
     
    Rowlan likes this.
  31. Rowlan

    Rowlan

    Joined:
    Aug 4, 2016
    Posts:
    1,860
    Yeah, sure, it's just another kind of distribution applied.

    That makes me think I should totally re-add it. After yesterday's quick implementation with the instant physics it might make sense to have the same what you can do with the brush along a spline. Just for re-use of the spline. And here that distribution could be very interesting, i. e. more along the spline center, less outside.
     
  32. Lars-Steenhoff

    Lars-Steenhoff

    Joined:
    Aug 7, 2007
    Posts:
    2,977
    You could even make a distrubution curve for the spline curve :)

    Or an object size curve
     
    dsilverthorn likes this.
  33. Rowlan

    Rowlan

    Joined:
    Aug 4, 2016
    Posts:
    1,860
    I made a very quick draft. There's a new tab "Interaction" for that kind of stuff. Only had a few hours today to spare, so unfortunately for the first try the time went up in refactoring the brush for re-use in the Interaction, which made sense. Anyway, Here's how the first draft looks like. While I was at it I thought I'd also add Anti-Gravity to shake the prefabs a bit:



    Definitely something I like, so that'll get a proper treatment with forces and such :D

    Thanks a lot for the idea! :)
     
  34. Lars-Steenhoff

    Lars-Steenhoff

    Joined:
    Aug 7, 2007
    Posts:
    2,977
    That looks so much fun!

    The gamification of game creation!
     
    Last edited: Nov 1, 2020
    dsilverthorn and Rowlan like this.
  35. Rowlan

    Rowlan

    Joined:
    Aug 4, 2016
    Posts:
    1,860
    It made sense to add physics to the spline spawned gameobjects as well:



    You have to click a button though once you're done. This is for later re-use of the splines. ie create one, drop prefabs, move it around, drop prefabs, etc.

    I might add some fuzzy distance and maybe also some force along the splines. Could be useful. However usability might be getting a tad complicated, too many settings already :)
     
    dsilverthorn and Lars-Steenhoff like this.
  36. Lars-Steenhoff

    Lars-Steenhoff

    Joined:
    Aug 7, 2007
    Posts:
    2,977
    Very nice, I would make the features first and for the UX perhaps do some refactoring once you know the complete feature set
     
    Rowlan likes this.
  37. Rowlan

    Rowlan

    Joined:
    Aug 4, 2016
    Posts:
    1,860
    Lars-Steenhoff and dsilverthorn like this.
  38. Rowlan

    Rowlan

    Joined:
    Aug 4, 2016
    Posts:
    1,860
    Yeah, that's the best solution I guess. Too many ideas to implement.
     
  39. Lars-Steenhoff

    Lars-Steenhoff

    Joined:
    Aug 7, 2007
    Posts:
    2,977
    That rocks placement along the spline looks perfect for a shoreline :)
    Do you think its possible to set an -y offset to the terrain collider?
    This could be useful when you want all the rocks to go a little in the ground for a natural look, for example on beach they would be a little in the sand.
     
    Rowlan likes this.
  40. Lars-Steenhoff

    Lars-Steenhoff

    Joined:
    Aug 7, 2007
    Posts:
    2,977
    Ow I see you have it already :). nevermind
     
    dsilverthorn and Rowlan like this.
  41. Rowlan

    Rowlan

    Joined:
    Aug 4, 2016
    Posts:
    1,860
    Yeah, in addition to that there's also the operations tab. You can e. g. select randomly few, medium, many, all prefabs and then use Unity's standard means to lower the selected ones.
     
    Lars-Steenhoff and dsilverthorn like this.
  42. dsilverthorn

    dsilverthorn

    Joined:
    May 14, 2017
    Posts:
    655
    I love this! So glad I’m starting a new project. :)
     
    Lars-Steenhoff and Rowlan like this.
  43. Microck

    Microck

    Joined:
    Oct 6, 2015
    Posts:
    5
    Hello !
    Fantastic asset !
    However, I got a little error:
    Assets\Yapp\Editor\UIComponents\BrushComponent.cs(3,19): error CS0234: The type or namespace name 'UIElements' does not exist in the namespace 'UnityEngine' (are you missing an assembly reference?)

    I'm using Unity 2018.4.21f1 (64-bit), Package manager UI 2.0.8.
     
  44. Rowlan

    Rowlan

    Joined:
    Aug 4, 2016
    Posts:
    1,860
    Thanks for reporting this. I uploaded a fix. It was just a redundant Unity import that didn't exist in 2018.
     
    Microck likes this.
  45. supanuka

    supanuka

    Joined:
    Oct 30, 2020
    Posts:
    1
    I can't figure out how to actually paint the stuff on the terrain
     
  46. Rowlan

    Rowlan

    Joined:
    Aug 4, 2016
    Posts:
    1,860
    Use the shift key and drag the mouse, the blue circle should become green then. ctrl+shift removes the prefabs. See the on-screen instructions here:

    instruction.jpg

    In case it is a problem of the general setup, I made quick video for you:



    Basically you have to

    * add the YAPP GameObject
    * create a container for the Prefabs; note: I dragged the container out of the YAPP GameObject simply because Unity would select all the children by default which could cost performance if you have 1000s of them in there; you can assign any gameobject as container manually
    * drag in Prefabs which should be used
    * add via shift + mouse drag, circle becomes green
    * remove via shift + ctrl + mouse drag, circle becomes red
    * brush size can be chanced via ctrl + mouse wheel
     
    antoripa and StevenPicard like this.
  47. derkoi

    derkoi

    Joined:
    Jul 3, 2012
    Posts:
    2,063
    This looks great. I develop a fishing game and looking at this tool, it will be useful for spawning many things.

    One thing I would like if possible is the ability to draw a spline around my lake without adding points, somehow automatically points are added from where I've drawn, it would be so much faster, not sure it's possible though.

    I've not seen it but is it possible to spawn only within a spline shape?
     
  48. Rowlan

    Rowlan

    Joined:
    Aug 4, 2016
    Posts:
    1,860
    Spawning inside a closed Spline isn't supported now. Basically that's just spawning inside a polygon. I think Vegetation Studio Pro and its Biomes are better suited for that purpose, in case you have it.

    But I can certainly look into it.
     
  49. JohnFalconEsq

    JohnFalconEsq

    Joined:
    Jan 11, 2018
    Posts:
    2
    Just wanted to stop by and say this tool is fantastic, I'm surprised you're not selling it on the asset store - I'd definitely buy it again.

    Many thanks for making it open source and free!
     
    Rowlan likes this.
  50. Rowlan

    Rowlan

    Joined:
    Aug 4, 2016
    Posts:
    1,860
    In order to make it all more convenient I added templates for the prefabs. Those are predefined settings for the prefabs. Example: A rock can be usually rotated in all directions, a tree can usually be only rotated around the Y axis.

    Just drag your prefabs over the template you wish to use:

    template.png

    Object is like it was before.

    I made it flexible, so that you can define your own templates and collection. The collection is stored in "Prefab Template Collection":

    collection.png

    You can add your own by modification of the array.

    The settings themselves are in prefab settings templates, e. g. Rock:

    rock.png

    Here's how it looks for trees and rocks:



    Important: If you create your own, then you need to save the scene for it to become effective. So if you edit your Rock setting, it will only applied after a save. It's a Unity thing with Scriptable Objects.
     
unityunity