Jump to content

Procedural Point-Cloud Bouyancy - In theory


Recommended Posts

I've been working on a theory to replace the stock completely useless buoyancy system with something that isn't completely useless.

Here's the basic process:

Step zero, disable stock bouyancy for all parts

  1. Pick a part that hasn't been processed yet
  2. Place a plane offset on one axis
  3. Intersect the plane with the visible mesh of the part and capture the lines where the triangles of the mesh intersect the plane; (here's an album)
  4. Take the resulting profile and strip it to just the vertices
  5. Run a variant of QuickHull to generate a convex nGon which contains all of the vertices
  6. Throw away all the vertices which are not part of the nGon
  7. Eliminate all collinear vertices on the nGon
  8. For each edge on the nGon if length is greater than X, split the edge at it's midpoint; repeat until no lines are greater than X
  9. Strip the nGon of it's edges and add the vertices to the part's point cloud
  10. Move the plane towards the far end of the part by X, where the part's length is divisible by X
  11. Repeat until the plane is at the far end of the part

Once the point cloud is generated it needs to be weighted so that the 'CoM' of the point cloud is the same as the part's actual CoM

The final step is to cache the point cloud to a file so that this process does not need to be completed repeated.

Now that every part has a point cloud representing their volume we move to the application of this information.

Every frame determine if any parts' bounding box intersects with the surface of the water. If so we need to do a partial submersion check.

Place a plane at sealevel, this is to prevent any 'specialness' about the ocean surface from mattering, for any rational scale vessel the curvature of the ocean doesn't matter. Now we take the point cloud and split it on the plane; figuring out which ones are above and below the plane. Any points below the plane will contribute to the part's buoyancy, above will not.

Below the ocean buoyancy will be invariant, maybe; above the ocean there is no buoyancy

There's still a lot of stuff I'm not sure about; I haven't laid down any code yet, I'm not entirely sure where I'm going to get the volume of the part from, though there are many options, I don't quite know how I'm going to apply the force, and there are going to be a lot of verts so this is probably going to be difficult to run.

But theoretically this would approximate buoyancy to a useful degree, and circumvent the faults that have existed in other subaquatic solutions.

The biggest issue with this plan is that it entirely fails to handle concave geometry, or parts such as trusses which have several pieces of convex geometry in the slice, I don't have a solution to that yet.

Edited by Greys
Link to comment
Share on other sites

I've been working on a theory to replace the stock completely useless buoyancy system with something that isn't completely useless.

Here's the basic process:

Step zero, disable stock bouyancy for all parts

  1. Pick a part that hasn't been processed yet
  2. Place a plane offset on one axis
  3. Intersect the plane with the visible mesh of the part and capture the lines where the triangles of the mesh intersect the plane; (here's an album)
  4. Take the resulting profile and strip it to just the vertices
  5. Run a variant of QuickHull to generate a convex nGon which contains all of the vertices
  6. Throw away all the vertices which are not part of the nGon
  7. Eliminate all collinear vertices on the nGon
  8. For each edge on the nGon if length is greater than X, split the edge at it's midpoint; repeat until no lines are greater than X
  9. Strip the nGon of it's edges and add the vertices to the part's point cloud
  10. Move the plane towards the far end of the part by X, where the part's length is divisible by X
  11. Repeat until the plane is at the far end of the part

Once the point cloud is generated it needs to be weighted so that the 'CoM' of the point cloud is the same as the part's actual CoM

The final step is to cache the point cloud to a file so that this process does not need to be completed.

Now that every part has a point cloud representing their volume we move to the application of this information.

Every frame determine if any parts' bounding box intersects with the surface of the water. If so we need to do a partial submersion check.

Place a plane at sealevel, this is to prevent any 'specialness' about the ocean surface from mattering, for any rational scale vessel the curvature of the ocean doesn't matter. Now we take the point cloud and split it on the plane; figuring out which ones are above and below the plane. Any points below the plane will contribute to the part's buoyancy, above will not.

Below the ocean buoyancy will be invariant, maybe; above the ocean there is no buoyancy

There's still a lot of stuff I'm not sure about; I haven't laid down any code yet, I'm not entirely sure where I'm going to get the volume of the part from, though there are many options, I don't quite know how I'm going to apply the force, and there are going to be a lot of verts so this is probably going to be difficult to run.

But theoretically this would approximate buoyancy to a useful degree, and circumvent the faults that have existed in other subaquatic solutions.

The biggest issue with this plan is that it entirely fails to handle concave geometry, or parts such as trusses which have several pieces of convex geometry in the slice, I don't have a solution to that yet.

I'll add some $.02 here...

So in my testing, I was VERY surprised to find that the actual ocean mesh has no bearing on craft. When I was testing ocean floor effects for EVE, I set the Ocean PQS radii to 1. This made the mesh effectively disappear, but to my surprise, craft still hit the "water"!

I suspect KSP is actually using a sphere collider or a plane as you suggested.

Link to comment
Share on other sites

This thread is quite old. Please consider starting a new thread rather than reviving this one.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...