Search Unity

  1. Unity 2020.1 has been released.
    Dismiss Notice
  2. 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

Polybrush: Runtime vertex painting

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

  1. MechaWolf99

    MechaWolf99

    Joined:
    Aug 22, 2017
    Posts:
    52
    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:
    720
    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:
    52
    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:
    720
    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:
    52
    Cool! Thank you for the quick reply!
     
  6. Tudor

    Tudor

    Joined:
    Sep 27, 2012
    Posts:
    127
    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:
    253
    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:
    790
    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:
    127
    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:
    26,727
    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. OldLegWig

    OldLegWig

    Joined:
    Mar 18, 2018
    Posts:
    92
    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:
    720
    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. logixworx

    logixworx

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

    hippocoder

    Digital Ape Moderator

    Joined:
    Apr 11, 2010
    Posts:
    26,727
    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:
    2
    +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:
    494
    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:
    494
    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. OldLegWig

    OldLegWig

    Joined:
    Mar 18, 2018
    Posts:
    92
    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:
    127
    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:(
     
  22. Fensky

    Fensky

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