Geometry Module

What is it?

Geometry Module provides an easy way to classify points based on whether they’re inside a convex geometry (part, models, meshes). It exposes two useful functions and provides feedback while processing.

How does it works?

The background concept is as simple as it can be. A point is inside a geometry if its distance from the center of the shape is less than the distance to the surface of the geometry in the same direction as the point (basically radius).

The distance to the surface is measured by using rays.

How to use it?

As stated earlier, there are two useful functions that are exposed.

.getClassifiedPoints(model, totalPoints, visualize)

This function takes in a model and generates a population of random points inside the bounding box (the amount of which is equal to totalPoints). It then classifies the points based on whether they’re inside or outside of the geometry. There is also the option of visualizing each point (colored green if they were inside and red if they were not).

The function returns two lists of points; inclusive points and exclusive points (those which were inside and those which were outside, respectively).

Depending on the complexity of the model (how many parts it contains) and the amount of total points, this function can take a while. Therefore, I’ve included three variables (also documented in the module) namely; generationSkipThreshold, classificationSkipThreshold and visualizationSkipThreshold

These are the amount of iterations each stage of the function (generation, classification and visualize if turned on) takes before wait()'ing to avoid the studio from crashing.

.checkPointInclusion(model, point)

This function takes in a model and a point (Vector3) and returns true or false depending on whether the point was inside or outside of the model (not the bounding box but of the geometry of every BasePart and meshes inside the model)

What are some example use cases?

I’ve used the first function to generate parts for Space Colonization Algorithm for generating trees.

The second function is much faster and can be used in run-time. As its name suggests, it can be used to check if a point lies within a geometry or not (I’m not sure if there is similar method that ROBLOX provides).

Is it fast enough?

As mentioned earlier, the first function can be quite expensive. Even with simple shapes, because it is not configured to run at maximum speed (it prints out details about its progress and uses wait()'s if necessary) it is unusable for very fast operations. A simple test of 100 points being classified inside the pine cone tree free model (which has 65 parts) results with a runtime of between 0.2 to 0.25 seconds.

The second function though is lightening fast. With the same pine cone tree, it takes between 0.002 to 0.003 seconds to finish execution.

Where to get it?

Here you go

11 Likes