Pasting entire vex code of
compute_data_from_obb detail_wrangler referred in the OBB video:
int closest_point = -1;
float min_distance = 1e10; // Large initial value
// Get the minimum bounding box coordinates
vector bbox_min = getbbox_min(0);
// Loop through all points to find the one closest to bbox_min
int num_points = npoints(0);
for (int i = 0; i < num_points; i++)
{
vector pt_pos = point(0, "P", i); // Get the position of the point
float distance = length(pt_pos - bbox_min); // Calculate the distance to bbox_min
if (distance < min_distance)
{
min_distance = distance;
closest_point = i; // Update the closest point index
}
}
i@closest_point = closest_point;
f@minLength = 1e10; // Initialize with a large number
f@maxLength = 0.0; // Initialize with a small number
// Initialize direction vectors
v@minDir = {0, 0, 0};
v@maxDir = {0, 0, 0};
float allLength[] = array();
vector allDir[] = array();
if(closest_point >= 0 ) {
vector pos0 = point(0, "P", closest_point);
int neighPoints[] = neighbours(0, closest_point);
for(int i=0; i<len(neighPoints); ++i) {
vector pos1 = point(0, "P", neighPoints[i]);
vector direction = pos1 - pos0;
float length = length(direction);
vector unit_direction = normalize(direction);
append(allLength, length);
append(allDir, unit_direction);
}
if(allLength[0] < allLength[1]) {
f@minLength = allLength[0];
v@minDir = allDir[0];
f@maxLength = allLength[1];
v@maxDir = allDir[1];
} else if (allLength[0] > allLength[1]) {
f@minLength = allLength[1];
v@minDir = allDir[1];
f@maxLength = allLength[0];
v@maxDir = allDir[0];
} else {
f@minLength = allLength[0];
v@minDir = allDir[0];
f@maxLength = allLength[1];
v@maxDir = allDir[1];
}
}