Any tips on how to measure (or estimate) the surface of an overlapping object?

I’m looking to measure the surface area of part of an object overlapping another object, preferrably in cm[SUP]2[/SUP]. Let me start with an example:

Imagine you have two blueprints:

1. The ball blueprint, containing the Static Mesh of a ball.
2. A water volume blueprint, containing a Box Collision.

The ball has been thrown towards the water and has landed in the water, as in this illustration:

The ball is partially submerged in the water. Basically, the ball static mesh is partially overlapping the box collision. I want to measure how much surface area of the ball is submerged. The area I want to measure is the one shown with red lines in this illustration:

How would I, if at all possible, go about doing this in blueprints only (no C++)? From what I can see I do not have access to vertex or triangle locations on a Static Mesh. Even so, measuring only based on triangles might give inaccuraces is even triangles can be partially submerged. If it isn’t possible to get an accurate measurement, does anyone have any suggestions on how to give calculate a fair estimate of the surface area?

Now, there might be formulas to calculate the surfaces of a sphere, but what if the mesh isn’t a simple shape? There aren’t exactly any universal formulas to measure the surface area of a chair.

I’ve been toying with some general ideas, but haven’t figured out how to actually implement the ones that may be possible to do.

• What about getting the bounding box of the ball, trace from the upper plane (or upper vertices) down to the box collision, then subtract that from the bounding box? That should be possible within the engine but this is still quite inaccurate for a ball, as a ball it doesn’t conform well to a box giving a lot of empty area within the bounding box. However, this works great for boxes… assuming they are falling straight down. I assume that if rotated, even boxes will start to show increasing amounts of inaccuracy.
• I’ve never used procedural meshes before, but could I create a temporary copy of the static mesh and slice it along the intersecting planes of the water volume, so that I am left only with the part that is inside the volume? This would give me a very accurate number assuming I find a way to actually measure the surface area of the mesh itself.
• Again, using procedural meshes to slice the object, could I measure the mass before and after the slice to figure out the surface area somehow? I reckon I would have to manually supply the game with the total surface area of the object, and do something like TotalSurfaceArea * (PostSliceMass / OriginalMass).

In lieu of an accurate way, any tips on how to achieve any of these estimates? Or for that matter, any better ideas?

Just to clarify, you want to know how to calculate the distance from the bottom of the ball to the surface of the water? So if a ball was 100cm tall and 40% of it was submerged then it would be 40cm from the bottom of the ball to the surface of the water.

I dont think Unreal has a way to measure the surface area of a mesh, although I may be wrong because Ive never needed something like this. I think you would have to work this out externally to UE4, then store it as a variable with the mesh. Maybe use a Tag if you want to have just StaticMesh

Maybe theres a way to do the measuring with materials. You could change the overlapping parts of the material, then maybe subtract the empty UV space from the used UV space, then find out what percentage of that is overlapping, say how much of the red channel is used. And compare this with your surface area tag or variable? Since the UV space is basically your surface area anyway, plus this would work with complicated shapes like chairs

@drb1992 : Not quite. I am interested in the surface area, not the height. So say the ball is clad in leather. The creators used 120 cm[SUP]2[/SUP] (square cm) to cover the ball. If 40% of the ball is underwater, it will tell me that 48 cm[SUP]2[/SUP] of leather is submerged. Or to put it another way, 40% of the outside area of the ball is wet.

@Orkney : You may be on to something. It didn’t occur to me to use the material.

An alternative would be, as you imply, to work out the total surface area outside of UE4 and add that as a variable to the blueprint containing the relevant meshes (I likely won’t apply this to “blueprint-free, pure Static Meshes”). I presume I may have to create an additional UV channel for my object where I map all triangles with equal proportions. In other words, all triangles would be 1:1 or 1:4, but not a combination of both.

I’ve seen some videos of games, mainly VR ones, where you can graffiti a wall. Point at an area, spray, and that part of the area turns red (or whatever color you like). Seem to recall talk about Render Targets and such, so I may have to look into that.

The idea is first and foremost to create a fair blueprint-only representation of buoyancy. I know there are a few C++ plugins that can do that, but I am looking to create something that only relies on blueprints. I barely know any C++, and I upgrade my engine version fairly often. When using external plugins like that I am reliant on the creators recompiling it for newer engine versions.

ehh I think you could do this without C++, I did something similar using materials in order to create something like world space location opacity. This is the thread on it…https://forums.unrealengine.com/deve…-cap-clip-ends

I used it for something different, but I think the material would be very similar. I didnt think about the second uv channel. As long as your UVs werent stretched in anyway (completely relaxed)

The material basically allowed me to move a plane around in the scene and everything on one side of it became invisibile. This plane would basically be your water level, if your draw the opacity to the diffuse slot instead you could see which parts were underwater. The material is in that thread. You can copy and paste it to the material graph. There are some vector parameter inputs which need to be set up though for the plane location and rotation. Note i only set this up to work in cardinal rotations. It is possible to do it with non cardinal rotation just I didnt need to do it for this and didnt spend the time to work it out.

EDIT:

This would just be a starting point though, I was thinking about this today and Im not entirely sure how you would transfer this channel data back into blueprint. Its possible you could write a custom node which returns the percentage of say ‘red’ in the UV channel

There is a node called DebugScalarValues, but this outputs a texture which you can overlay onto a texture, not sure theres anyway to turn this to a float

Hi,

Following the post of Orkney,

The problem is there is no way to set a variable inside a material and communicate it outside.

It would be easy to compute the surface area witstanded by a material if we could store it somewhere. The problem is there is no sequencial execution graph in a material.

If anyone knows how to do that please tell me !

On my side, I found this youtube video which may help or inspire: