Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Join us on Thursday, June 8, for a Q&A with Unity's Content Pipeline group here on the forum, and on the Unity Discord, and discuss topics around Content Build, Import Workflows, Asset Database, and Addressables!
    Dismiss Notice

Polybrush: Runtime vertex painting

Discussion in 'World Building' started by MechaWolf99, Nov 5, 2018.

  1. MechaWolf99

    MechaWolf99

    Joined:
    Aug 22, 2017
    Posts:
    257
    I need to do some vertex painting at runtime and was hopping to use Polybrush rather than having to make my own solution. But there seems to be 0 documentation on the APIs in Polybrush.

    So I am wondering if someone can direct me to some docs for it. Tell me how to do it or where to start.
    Or would it be better to just make my own solution from scratch to handle runtime vertex painting?
     
  2. gabrielw_unity

    gabrielw_unity

    Unity Technologies

    Joined:
    Feb 19, 2018
    Posts:
    957
    Hi there! With Polybrush 1.0 coming out soon, we're waiting a bit before enabling the Public API. Don't want to delay the tool just for that. However, we'll have full documentation and info when that does land (sometime after 1.0). Sorry for the wait!
     
  3. MechaWolf99

    MechaWolf99

    Joined:
    Aug 22, 2017
    Posts:
    257
    Okay, cool. Thank you for the reply and update. Are you able to give me an idea for what that soon looks like? Like a couple of weeks? a couple of months? 6+ months?
     
  4. gabrielw_unity

    gabrielw_unity

    Unity Technologies

    Joined:
    Feb 19, 2018
    Posts:
    957
    We're shooting for around the same time as Unity 18.3 lands, same for ProBuilder 4.x :) So, within the month perhaps?
     
    hippocoder likes this.
  5. MechaWolf99

    MechaWolf99

    Joined:
    Aug 22, 2017
    Posts:
    257
    Cool! Thank you for the quick reply!
     
  6. Tudor

    Tudor

    Joined:
    Sep 27, 2012
    Posts:
    148
    Hi, bumping this because I need to know IF polybrush HAS any runtime capabilities, or if it's something limited to the Editor only? (eg does it depend on editor code that isn't available at runtime (build time)?)

    Do I need to wait for version 1.0 to do runtime painting? Or were we waiting for v1.0 just for the documentation?
     
    Last edited: Dec 7, 2018
  7. lejean

    lejean

    Joined:
    Jul 4, 2013
    Posts:
    379
    Well there is a example in the probuilder package that has runtime face painting..

    But I'm also looking for a way to color a vertex only, not a face so ye, an API would be most useful.
     
  8. dadude123

    dadude123

    Joined:
    Feb 26, 2014
    Posts:
    789
    Using this API, will we be able to (for example) paint on any mesh? Or does it have to be prepared somehow?
    Could I just, for example, apply one brush stroke of "set vertex color to red" on any `UnityEngine.Mesh`?
     
  9. Tudor

    Tudor

    Joined:
    Sep 27, 2012
    Posts:
    148
    Yes the example scenes also work during playmode in the Editor. But the code seems to be heavily involved with `using UnityEditor;` I'm trying to sift through it now and see if/what I can do to get it to work in a build. I just want vertex painting at runtime >_>

    [EDIT] For others that want to use Polybrush in builds, for Vertex Painting, look at `
    z_BrushModePaint.cs` and start from `public override void OnBrushMove(z_BrushTarget target, z_BrushSettings settings)` inside there.
     
    Last edited: Dec 7, 2018
    Rahd likes this.
  10. hippocoder

    hippocoder

    Digital Ape Moderator

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    What new features are available? As a signed up probuilder-lover I demand to know.
     
  11. Sonorpearl

    Sonorpearl

    Joined:
    Sep 8, 2017
    Posts:
    32
    Have you tried Baking the Vertex to the Mesh, via the PolyBrush Bake Vertex Streams? That could also be a problem in some cases. ^^
     
  12. owen_proto

    owen_proto

    Joined:
    Mar 18, 2018
    Posts:
    118
    I was curious if there was any update on this. Not much news on this tool lately.
     
  13. gabrielw_unity

    gabrielw_unity

    Unity Technologies

    Joined:
    Feb 19, 2018
    Posts:
    957
    We burned WAY past that deadline (sorry!) but we do have a dev working 100% on this. One of the latest additions to 1.x was ensuring that pre-1.x meshes will update smoothly, we do not want to rush things and cause trouble. Thanks for your patience! :)
     
  14. SpindizzyGames

    SpindizzyGames

    Joined:
    Jun 29, 2017
    Posts:
    108
    Any update now that 1.0 is released?
     
    ApenasVB likes this.
  15. hippocoder

    hippocoder

    Digital Ape Moderator

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    That's for the best, it's been a bit up and down so the communication is welcome thanks!
     
    ApenasVB and gabrielw_unity like this.
  16. ApenasVB

    ApenasVB

    Joined:
    Nov 26, 2014
    Posts:
    3
    +1 Waiting for Polybrush APIs for usage during runtime :)
    @Tudor , how was your progress in tinkering with the tool? Anything that you could share with us?
     
  17. cherub

    cherub

    Joined:
    Apr 26, 2006
    Posts:
    493
    Working pretty good for us so far! we added flatten which is great. also specify a position option to use when u want to displace from a point like working w a sphere.
    (cant seem to post an image atm)
    Is there any way to get a collider out of it?
    Tried Baking but it got all garbled.
     
    Last edited: Aug 27, 2019
  18. cherub

    cherub

    Joined:
    Apr 26, 2006
    Posts:
    493
    got it to work, apparently the script vert limit is less than the import limit. reducing the original model to be under 64k verts fixed it
     
  19. owen_proto

    owen_proto

    Joined:
    Mar 18, 2018
    Posts:
    118
    you can also set a mesh's index format to 32 bits to support up to about 4 billion vertices:

    Code (CSharp):
    1. mesh.indexFormat = UnityEngine.Rendering.IndexFormat.UInt32;
     
  20. Tudor

    Tudor

    Joined:
    Sep 27, 2012
    Posts:
    148
    I dug through the code and most of it uses Editor scripts and namespace, and I noticed the actual mesh editing part is easy to implement yourself and not use polybrush... Actually the custom Editor part of polybrush is harder to make (because of unity) than the actual painting part.

    I implemented my own runtime, buildtime, editorless vertex painter from scratch in a couple of weeks :D It works great and isn't hard to do. (but I can't give you the code it's not mine to give)

    The only part that you need to put work in and be careful implementing is a custom data structure that links unity meshes to your internal structure of mirror vertices which you can edit. On start I read the vertices of the paintable unity meshes and populate them into a vertex graph so that I can color one vertex and easily fetch its neighbours to also color them and the next neighbours etc. The gist is you have unity's mesh that has a vertexcolor array, and you can replace that array completely with a new array that has your "brush stroke" changes in it.

    If you want to paint a vertex, you can get it with a raycast on a mesh collider (so your objects need to have mesh colliders that match 1:1 with the rendered mesh otherwise you need to do some fancy custom equivalancy somehow). One problem I had was that if those meshes are set to Static Batching, the batched mesh no longer corresponds to the mesh collider, so I ended up just not batching those paintable meshes due to time restrictions and poor unity documentation on how static batching creates a new mesh.

    It's pretty fast but I was using it on many terrain mesh tiles and other geometry on top, so I did an additional layer of optimization where I have an invisible spread of raycasts that have a maximum kind of deltatime budget and I cast them over multiple frames if I have to. So for one very large brush stroke that may hit trees and ground and rocks and other ground tiles etc, it takes 4-6 frames to cover them instead of 1 frame, but there's no visible differences for our case at 90+FPS and a soft brush. Also if you want the brush to have passthrough on multiple objects on top of each other you need to raycast and raycast again from the triangle hit point and raycast again etc. in short rays (so you can get e.g. a tree and a rock under the tree and the ground under the rock)

    Of course I didn't need fancy brushes, just one diffuse brush. Other brushes / tools are also easy to do once you have this but just take more work/time.
     
    Last edited: Sep 22, 2019
  21. Rey4033

    Rey4033

    Joined:
    Feb 9, 2018
    Posts:
    1
    Hello,how can I brush texture in runtime when using polybrush?I am very desired to konw:(
     
    chortaingseng likes this.
  22. Fensky

    Fensky

    Joined:
    Jul 4, 2017
    Posts:
    1
    Hello ! Any update about the release date of the runtime vertex painting with Polybrush ?
     
  23. xofreshxo

    xofreshxo

    Joined:
    Apr 12, 2017
    Posts:
    68
    Definitely want this functionality
     
  24. stychu

    stychu

    Joined:
    May 9, 2016
    Posts:
    62
    Still no API ??
     
    Last edited: Jan 16, 2021
  25. emrexconi

    emrexconi

    Joined:
    Jan 7, 2019
    Posts:
    4
    when polybrush will be at runtime ? ??
     
    chortaingseng and Sheynes like this.
  26. InglewoodTechnology

    InglewoodTechnology

    Joined:
    Mar 7, 2016
    Posts:
    40
    Would love this! Unity please provide or communicate.
     
  27. circlejerk69

    circlejerk69

    Joined:
    Aug 15, 2020
    Posts:
    2
    any update on this?
     
  28. MechaWolf99

    MechaWolf99

    Joined:
    Aug 22, 2017
    Posts:
    257
    Hey, just thought I would let you guys know that I wouldn't hold my breath. Currently Polybrush has not been updated since March of 2021. For all intents and purposes, it is dead (for now).

    gabrielw_unity moved to working on the Overlay system added in 2021.2 which acts as a foundation for all tools in the scene view. He has now moved to working on Splines for 2022.1. I would suspect that after Splines are done, he may move back to Polybrush now that there is more of a foundation for it, however I would expect to most likely see a decent rewrite for it, or maybe even started from scratch.

    So I wouldn't expect to see any movement until late 2022 at the soonest, but more likely 2023 (or later).
     
  29. hippocoder

    hippocoder

    Digital Ape Moderator

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    This is the least expected scenario TBH.
     
  30. MechaWolf99

    MechaWolf99

    Joined:
    Aug 22, 2017
    Posts:
    257
    Maybe not from scratch I suppose (more wishful thinking on my part), but the editor part is pretty old and clunky, I would expect it to be rewritten to use Overlays like Probuilder is/will be (has it already?). More so because it was Gabriel who did it.