Polybrush: Runtime vertex painting

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?

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!

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?

We're shooting for around the same time as Unity 18.3 lands, same for ProBuilder 4.x :) So, within the month perhaps?

1 Like

Cool! Thank you for the quick reply!

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?

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.

[quote=“gabrielw_unity”, post:2, topic: 720590]
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!
[/quote]

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?

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.

1 Like

[quote=“gabrielw_unity”, post:4, topic: 720590]
We’re shooting for around the same time as Unity 18.3 lands, same for ProBuilder 4.x :slight_smile: So, within the month perhaps?
[/quote]
What new features are available? As a signed up probuilder-lover I demand to know.

Have you tried Baking the Vertex to the Mesh, via the PolyBrush Bake Vertex Streams? That could also be a problem in some cases. ^^

I was curious if there was any update on this. Not much news on this tool lately.

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! :)

Any update now that 1.0 is released?

1 Like

[quote=“gabrielw_unity”, post:13, topic: 720590]
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! :slight_smile:
[/quote]
That’s for the best, it’s been a bit up and down so the communication is welcome thanks!

2 Likes

+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?

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.

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

[quote=“cherub”, post:18, topic: 720590]
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
[/quote]

you can also set a mesh’s index format to 32 bits to support up to about 4 billion vertices:

mesh.indexFormat = UnityEngine.Rendering.IndexFormat.UInt32;

[quote=“ApenasVB”, post:16, topic: 720590]
+1 Waiting for Polybrush APIs for usage during runtime :slight_smile:
@Tudor , how was your progress in tinkering with the tool? Anything that you could share with us?
[/quote]

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 :smile: 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.