/set_corner_pieces.v Secret
Created
February 12, 2020 15:41
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <math.h> | |
//VARIABLES | |
int points[] = primpoints(geoself(), 0); | |
int numCorners = len(points); | |
append(points, 0); | |
vector pointPos[]; | |
vector edgeDir[]; | |
float cornerAngles[]; | |
//get available corner pieces | |
string corner_90_param = chs("../kit_storage/mfloor_kit_corner_90"); | |
string corner_90_pieces[] = split(corner_90_param); | |
string corner_45_param = chs("../kit_storage/mfloor_kit_corner_45"); | |
string corner_45_pieces[] = split(corner_45_param); | |
//set corner pieces | |
int cornerIndex = (chi('../../mfloor_corner_index')) % len(corner_90_pieces); | |
string default_corner_45 = corner_45_pieces[cornerIndex]; | |
string default_corner_90 = corner_90_pieces[cornerIndex]; | |
float wallHeight = getbbox_size(chs("../../" + default_corner_90 + "/" + default_corner_90 + "/file"))[1]; | |
//get point positions | |
for(int i = 0; i < len(points); i++) { | |
vector newPos = pointattrib(geoself(), "P", points[i], 1); | |
pointPos[i] = newPos; | |
setpointattrib(geoself(), "scale", i, set(1,1,1), "set"); | |
//printf('%g: %e \n', points[i], pointPos[i]); | |
} | |
//Direction Vectors between Points | |
for(int i = 0; i < len(points)-1; i++) { | |
vector dir = normalize(pointPos[i+1]-pointPos[i]); | |
edgeDir[i] = dir; | |
//printf('%g - %g, Vector: %e \n', points[i], points[i+1], edgeDir[i]); | |
} | |
append(edgeDir, edgeDir[0]); | |
//get angles | |
for(int i = 0; i < len(edgeDir) - 1; i++){ | |
int ptIndex = (i+1) % numCorners; | |
vector v1 = set(edgeDir[i][0], 0, edgeDir[i][2]); | |
vector v2 = set(edgeDir[i + 1][0], 0, edgeDir[i + 1][2]); | |
float angle = atan2(v2[2], v2[0])-atan2(v1[2], v1[0]); | |
if(angle > PI) { | |
angle -= 2 * PI; | |
} | |
else if(angle <= PI * -1) { | |
angle += 2 * PI; | |
} | |
angle = degrees(angle); | |
vector n; | |
//90 degree corners | |
if(abs(rint(angle)) >= 89 && abs(rint(angle)) <= 91){ | |
n = v2 * -1; | |
if(angle < 0) { | |
float theta = radians(-90); | |
float cs = cos(theta); | |
float sn = sin(theta); | |
float px = n[0] * cs - n[2] * sn; | |
float pz = n[0] * sn + n[2] * cs; | |
n = set(px, n[1], pz); | |
} | |
setpointattrib(geoself(), "N", ptIndex, n, "set"); | |
setattrib(geoself(), "point", "instance", ptIndex, 0, "../../" + default_corner_90, "set"); | |
vector dim_max = getbbox_max(chs("../../" + default_corner_90 + "/" + default_corner_90 + "/file")); | |
float x_max = dim_max[0]; | |
setattrib(geoself(), "point", "piece_x_size", ptIndex, 0, x_max, "set"); | |
cornerAngles[ptIndex] = 90; | |
} | |
//45 degree corners | |
else if(abs(rint(angle)) >= 44 && abs(rint(angle)) <= 46){ | |
n = v2 * -1; | |
if(angle < 0) { | |
float theta = radians(-90); | |
float cs = cos(theta); | |
float sn = sin(theta); | |
float px = n[0] * cs - n[2] * sn; | |
float pz = n[0] * sn + n[2] * cs; | |
n = set(px, n[1], pz); | |
} | |
else { | |
float theta = radians(45); | |
float cs = cos(theta); | |
float sn = sin(theta); | |
float px = n[0] * cs - n[2] * sn; | |
float pz = n[0] * sn + n[2] * cs; | |
n = set(px, n[1], pz); | |
} | |
setpointattrib(geoself(), "N", ptIndex, n, "set"); | |
setattrib(geoself(), "point", "instance", ptIndex, 0, "../../" + default_corner_45, "set"); | |
vector dim_max = getbbox_max(chs("../../" + default_corner_45 + "/" + default_corner_45 + "/file")); | |
float x_max = dim_max[0]; | |
setattrib(geoself(), "point", "piece_x_size", ptIndex, 0, x_max, "set"); | |
cornerAngles[ptIndex] = 45; | |
} | |
printf("%g: %f \n",(i+1) % numCorners, cornerAngles[ptIndex]); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment