#Painting on a Mesh

9 messages · Page 1 of 1 (latest)

faint crater
#

Hi, I'm currently working on a project, where I have a globe that you can sculpt and (in the future) edit with different stuff. And I'm looking for 2 things:
(1) a good way to highlight the current area that is going to be edited. Right now I have a little spotlight that illuminates the area - and that s sort of the way i want it, but with an option to have an outline and without soft edges.
(2) a way to "paint" a polygon on the surface of the globe. Seems somewhat similar to the first one, but I want to (in theory) be able to draw arbitrary polygons.

My main issue is that I don't really know what to search/google for - I'm not sure what the kind of functionality would be called and how and where i should try to read up on it.

Here is what it looks like right now. The Globe is a sphere mesh that gets edited. Which is also something i'm trying to figure out:
(3) Is there a better way to do this than with a mesh, especially if i want to have more detail - the icosphere mesh is limited to 79 subdivisions, which isn't as much as I thought it would be :D

patent wagon
#

@faint crater For 1 and 2 I think what you're looking for is called "decal", it's a functionality that Bevy doesn't have natively on 0.15, but will have starting from 0.16, you can use a recent commit of Bevy to use it: https://github.com/bevyengine/bevy/blob/main/examples/3d/decal.rs / https://dev-docs.bevyengine.org/bevy/pbr/decal/index.html
The "problem" is it uses a texture, and if you want a varying polygon for example (I don't know if that's a need you have) you might need to either find a way to generate that texture first (with a 2D camera rendering to it?) or you might need to implement the shader yourself but you can use Bevy's decal shader as a starting point I guess?

GitHub

A refreshingly simple data-driven game engine built in Rust - bevyengine/bevy

faint crater
#

Ah yes, that sounds exactly like what I'm looking for - i'm gonna check that out :)

patent wagon
faint crater
#

Yeah, I'm just gonna start looking through it and testing things - just had no idea where to start :)

patent wagon
#

@faint crater
For 3, it took me a bit of digging to understand why there is the 80 limitation since it's not explicitly explained in the code to generate the Icosphere mesh https://docs.rs/bevy_mesh/0.15.2/src/bevy_mesh/primitives/dim3/sphere.rs.html#78 (which is a type of geodesic polyhedron with icosahedral base in case you need it: https://en.wikipedia.org/wiki/Geodesic_polyhedron ) and actually I'm still not sure I get it:

  • Mesh store their indices https://docs.rs/bevy/latest/bevy/prelude/struct.Mesh.html#method.insert_indices as an Indices type: https://docs.rs/bevy/latest/bevy/render/mesh/enum.Indices.html which is either a Vec<u16> or a Vec<u32>.
  • if you use 80 divisions, the number of vertices the code to generate the icosphere should generate is 10×81^2+2=65612 which is more than u16::max = 65535 so it can only be stored in a Vec<u32>
  • what I don't understand is the code to generate the Icosphere mesh does use a Vec<u32>, I thought it used a Vec<u16> because that's enough for most usages, it would be less efficient to use a Vec<u32> if not needed (? maybe not?), so it wasn't worth putting extra code to calculate that if the number of divisions will generate too many meshes, but yeah that's not the issue apparently? Maybe it was in the past because in the past Meshes only had Vec<u16> and it was never changed? It could be a limitation of the size of the Vec but that uses usize and usize::Max = 18_446_744_073_709_551_615

Sooooo I'm not sure if the limitation is really needed anymore, you could maybe argue that it is not in a github issue or PR?
You can maybe copy/paste Bevy's code to create the mesh and just... ignore the limitation?
idk

But when you have a mesh with a lot of indices/triangles like this you might need to use a Meshlet instead for performance reasons: https://docs.rs/bevy/latest/bevy/pbr/experimental/meshlet/index.html

A geodesic polyhedron is a convex polyhedron made from triangles. They usually have icosahedral symmetry, such that they have 6 triangles at a vertex, except 12 vertices which have 5 triangles. They are the dual of corresponding Goldberg polyhedra, of which all but the smallest one (which is a regular dodecahedron) have mostly hexagonal faces.
G...

faint crater
#

Oh wow, thanks - yeah i was also confused by that. I did look at the indices already and i only found U32, so to me it didn't make sense either.

I've also toyed around with creating a custom mesh that's a subset of the sphere mesh for creating a "second layer" - but that seems really complicated and I don't think the way meshes work is really intended for something like that. Like, how would I figure out the proper adjacencies?

anyway, lots to do and figure out - it's my first time working "directly" with meshes and transforming/warping them

patent wagon
#

(btw just in case the corresponding Bevy News section for Meshlet: https://bevyengine.org/news/bevy-0-14/#virtual-geometry-experimental )

I'm not sure what you mean by the second layer thing, like use a different mesh (with different "resolutions") depending on how close you are to the object? There's a functionality for that but I don't remember how it's called I'll try to dig for it.
(edit: found it: https://bevyengine.org/news/bevy-0-14/#visibility-ranges-hierarchical-levels-of-detail-hlods / https://docs.rs/bevy/0.14.2/bevy/render/view/struct.VisibilityRange.html)

You should be able to do any geometry with meshes, but you might have to have indices that are on the same point to use that point in several triangles with different properties.

It's not always easy to figure out how to create a mesh yourself there are several things you need to think about and if you have complex geometry it involves a lot of math, you can do it (example with a simple cube but different uv: https://github.com/bevyengine/bevy/blob/main/examples/3d/generate_custom_mesh.rs ), but unless you need something specific you can just copy Bevy's code to create an icosphere and modify it to your needs I think

GitHub

A refreshingly simple data-driven game engine built in Rust - bevyengine/bevy

faint crater
#

Oh, I meant i could basically create a „shell“ around the globe that is little bit further away from the center that has a different color (instead of decals), but that seems really difficult to handle