|
//VARIABLES |
|
int points[] = primpoints(geoself(), 0); |
|
int numPtFloor = len(points); |
|
int numPt = @numpt; |
|
|
|
int numRows = numPt / numPtFloor; |
|
|
|
//modular kit piece arrays |
|
//pillars |
|
string pillars = chs('../kit_storage/mfloor_kit_pillar'); |
|
string pillarArray[] = split(pillars); |
|
int pillarIndex = int(chi('../../mfloor_pillar_index')%len(pillarArray)); |
|
string pillarRef = '../../'+ pillarArray[pillarIndex]; |
|
int numPillars = chi('../../num_pillars'); |
|
|
|
float pillarWidth = getbbox_size(chs('../../' + pillarArray[0] + '/' + pillarArray[0] + '/file' ))[0]; |
|
|
|
//plain wall |
|
string wall = chs('../kit_storage/mfloor_kit_wall'); |
|
string wallRef = '../../'+ wall; |
|
|
|
float wallWidth = getbbox_size(chs('../../' + wall + '/' + wall + '/file' ))[0]; |
|
|
|
//wall pieces |
|
string wallPieces = chs('../kit_storage/mfloor_kit_ww'); |
|
string wallPieceArray[] = split(wallPieces); |
|
|
|
int pieceIndex = chi('../../mfloor_wframe_index') % len(wallPieceArray); |
|
string piece = wallPieceArray[pieceIndex]; |
|
string pieceRef = '../../'+ piece; |
|
|
|
int numWallPieces = chi('../../num_pieces_btwn_pillars'); |
|
|
|
//windows |
|
string windows = chs('../kit_storage/mfloor_kit_window'); |
|
string windowArray[] = split(windows); |
|
|
|
string windowsRd[], windowsSq[]; |
|
|
|
//sort windows |
|
for(int w = 0; w < len(windowArray); w++){ |
|
if ( match('*rd*', tolower(windowArray[w])) == 1){ |
|
append(windowsRd, windowArray[w]); |
|
} |
|
else if ( match('*sq*', tolower(windowArray[w])) == 1){ |
|
append(windowsSq, windowArray[w]); |
|
} |
|
|
|
} |
|
|
|
// floor separation |
|
string fSep = chs('../kit_storage/fsep_kit_wall'); |
|
string fSepPillar = chs('../kit_storage/fsep_kit_pillar'); |
|
string fSepArray[] = split(fSep); |
|
string fSepPillarArray[] = split(fSepPillar); |
|
string fSepRef = '../../' + fSepArray[0]; |
|
string fSepPillarRef = '../../' + fSepPillarArray[0]; |
|
|
|
// roof separation |
|
string rSep = chs('../kit_storage/rsep_kit_wall'); |
|
string rSepArray[] = split(rSep); |
|
int rSepIndex = chi('../../rsep_index') % len(rSepArray); |
|
string rSepRef = '../../' + rSepArray[rSepIndex]; |
|
|
|
//Function for adding windows to the Window Frames |
|
void addWindows (string wRd[]; string wSq[]; string wPiece; vector wNormal; vector wPos) { |
|
int wIndex = chi('../../mfloor_window_index') % len(wRd); |
|
int wPt; |
|
string wRef; |
|
|
|
if (match('*rd*', tolower(wPiece))) { |
|
|
|
wRef = '../../' + wRd[wIndex]; |
|
|
|
wPt = addpoint(geoself(), wPos); |
|
setpointattrib(geoself(), 'instance', wPt, wRef, 'set'); |
|
setpointattrib(geoself(), 'scale', wPt, set(1,1,1), 'set'); |
|
setpointattrib(geoself(), 'N', wPt, wNormal, 'set'); |
|
} |
|
|
|
else if (match('*sq*', tolower(wPiece))){ |
|
|
|
wRef = '../../' + wSq[wIndex]; |
|
|
|
wPt = addpoint(geoself(), wPos); |
|
setpointattrib(geoself(), 'instance', wPt, wRef, 'set'); |
|
setpointattrib(geoself(), 'scale', wPt, set(1,1,1), 'set'); |
|
setpointattrib(geoself(), 'N', wPt, wNormal, 'set'); |
|
} |
|
} |
|
int numFloors = chi('../../numFloors'); |
|
|
|
//PLACE WALL SECTIONS |
|
if (numFloors > 0) { |
|
for (int r = 0; r < numRows; r++) { //loop through wall and separation rows |
|
//get points belonging to each row |
|
int rowPoints[] = {}; |
|
int start = r * numPtFloor; |
|
for ( int c = 0; c < numPtFloor; c++ ) { |
|
append(rowPoints, start + c); |
|
} |
|
append(rowPoints, start); |
|
|
|
string rowType = pointattrib(geoself(), 'row_type', rowPoints[0], 1); |
|
|
|
//place wall tiles |
|
for (int c = 0; c < len(rowPoints)-1; c++) { //loop through corner points |
|
//PREP |
|
// start and end point position |
|
vector startPointPos = pointattrib(geoself(), 'P', rowPoints[c], 1); |
|
vector endPointPos = pointattrib(geoself(), 'P', rowPoints[c + 1], 1); |
|
vector dir = normalize(endPointPos - startPointPos); |
|
|
|
// start and end position, taking corner piece width into consideration |
|
vector startPos = startPointPos + (pointattrib(geoself(), 'piece_x_size', rowPoints[c], 1)*dir); |
|
vector endPos = endPointPos - (pointattrib(geoself(), 'piece_x_size', rowPoints[c + 1], 1)*dir); |
|
|
|
//normal for placing the pieces on the edges |
|
vector n = set(dir[2], 0, dir[0] * -1); |
|
|
|
float dist = distance(startPos, endPos); |
|
|
|
//only place tiles, if corner pieces don't overlap |
|
if ( (pointattrib(geoself(), 'piece_x_size', rowPoints[c], 1) + pointattrib(geoself(), 'piece_x_size', rowPoints[c + 1], 1)) < distance(startPointPos, endPointPos) ) { |
|
|
|
//CALCULATE SECTIONS |
|
float sectionWidth = (numWallPieces * wallWidth) * clamp(numPillars - 1, 0, 10) + numPillars * pillarWidth; |
|
sectionWidth *= int(sectionWidth < dist); |
|
int numSections; |
|
numSections = int((sectionWidth != 0)); |
|
|
|
numWallPieces *= int(numPillars > 1); |
|
|
|
//num tiles on each side of pillar section |
|
float restWidth = dist - sectionWidth; |
|
int numPieces; |
|
|
|
if (sectionWidth != 0) { |
|
numPieces = int(floor((restWidth/2)/wallWidth)); |
|
numPieces -= (numPieces % 2) * (1 - int(sectionWidth < dist)); |
|
} |
|
else { |
|
numPieces = int(floor(restWidth / wallWidth)); |
|
} |
|
|
|
//filler |
|
float fillerWidth; |
|
if (sectionWidth != 0) { |
|
fillerWidth = (restWidth - ((numPieces * 2) * wallWidth))/2; |
|
} |
|
else { |
|
fillerWidth = (restWidth - ((numPieces) * wallWidth))/2; |
|
} |
|
|
|
float fillerScaleX = fillerWidth / wallWidth; |
|
|
|
|
|
//PLACE PIECES |
|
//place filler pieces |
|
vector tempPos; |
|
vector tempStartPos; |
|
vector tempEndPos; |
|
vector pillarStartPos; |
|
int tempPt; |
|
|
|
if (fillerWidth != 0) { |
|
string fillerRef = wallRef; |
|
|
|
if (rowType == 'floor_wall'){ |
|
fillerRef = wallRef; |
|
} |
|
else if (rowType == 'floor_sep'){ |
|
fillerRef = fSepRef; |
|
} |
|
else if (rowType == 'roof_sep'){ |
|
fillerRef = rSepRef; |
|
} |
|
|
|
if(dist > wallWidth) { |
|
tempPos = startPos + ((fillerWidth/2) * dir); |
|
|
|
//Start Filler |
|
tempPt = addpoint(geoself(), tempPos); |
|
tempStartPos = tempPos; |
|
setpointattrib(geoself(), 'instance', tempPt, fillerRef, 'set'); |
|
setpointattrib(geoself(), 'scale', tempPt, set(fillerScaleX,1,1), 'set'); |
|
setpointattrib(geoself(), 'N', tempPt, n, 'set'); |
|
|
|
//End Pos |
|
tempPt = addpoint(geoself(), endPos - ((fillerWidth/2) * dir)); |
|
tempEndPos = endPos - ((fillerWidth/2) * dir); |
|
setpointattrib(geoself(), 'instance', tempPt, fillerRef, 'set'); |
|
setpointattrib(geoself(), 'scale', tempPt, set(fillerScaleX,1,1), 'set'); |
|
setpointattrib(geoself(), 'N', tempPt, n, 'set'); |
|
} |
|
else { |
|
tempPos = startPos + (fillerWidth * dir); |
|
tempPos = startPos + (fillerWidth * dir); |
|
tempPt = addpoint(geoself(), tempPos); |
|
setpointattrib(geoself(), 'instance', tempPt, fillerRef, 'set'); |
|
setpointattrib(geoself(), 'scale', tempPt, set(fillerScaleX * 2,1,1), 'set'); |
|
setpointattrib(geoself(), 'N', tempPt, n, 'set'); |
|
} |
|
|
|
} |
|
//place outside wall tiles |
|
if (numPieces != 0){ |
|
|
|
string spareRef = pieceRef; |
|
|
|
if (rowType == 'floor_wall'){ |
|
spareRef = pieceRef; |
|
} |
|
else if (rowType == 'floor_sep'){ |
|
spareRef = fSepRef; |
|
} |
|
else if (rowType == 'roof_sep'){ |
|
spareRef = rSepRef; |
|
} |
|
|
|
if(sectionWidth != 0){ |
|
for (int p = 0; p < numPieces; p++){ |
|
//place a tile both at the start and end of the wall |
|
tempPos = tempStartPos + (wallWidth * dir)/2 + (wallWidth * dir) * p + (fillerWidth * dir)/2; |
|
tempPt = addpoint(geoself(), tempPos); |
|
setpointattrib(geoself(), 'instance', tempPt, spareRef, 'set'); |
|
setpointattrib(geoself(), 'scale', tempPt, set(1,1,1), 'set'); |
|
setpointattrib(geoself(), 'N', tempPt, n, 'set'); |
|
if (p == numPieces - 1) { |
|
pillarStartPos = tempPos; |
|
} |
|
|
|
if ( rowType == 'floor_wall') { |
|
addWindows(windowsRd, windowsSq, piece, n, tempPos); |
|
} |
|
|
|
tempPos = tempEndPos - (wallWidth * dir)/2 - (wallWidth * dir) * p - (fillerWidth * dir)/2; |
|
tempPt = addpoint(geoself(), tempPos); |
|
setpointattrib(geoself(), 'instance', tempPt, spareRef, 'set'); |
|
setpointattrib(geoself(), 'scale', tempPt, set(1,1,1), 'set'); |
|
setpointattrib(geoself(), 'N', tempPt, n, 'set'); |
|
|
|
if ( rowType == 'floor_wall') { |
|
addWindows(windowsRd, windowsSq, piece, n, tempPos); |
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
else { |
|
for (int p = 0; p < numPieces; p++) { |
|
tempPos = tempStartPos + (wallWidth * dir)/2 + (wallWidth * dir) * p + (fillerWidth * dir)/2; |
|
tempPt = addpoint(geoself(), tempPos); |
|
setpointattrib(geoself(), 'instance', tempPt, spareRef, 'set'); |
|
setpointattrib(geoself(), 'scale', tempPt, set(1,1,1), 'set'); |
|
setpointattrib(geoself(), 'N', tempPt, n, 'set'); |
|
|
|
if ( rowType == 'floor_wall') { |
|
addWindows(windowsRd, windowsSq, piece, n, tempPos); |
|
} |
|
} |
|
} |
|
} |
|
//if no wall tiles get placed |
|
else { |
|
pillarStartPos = tempPos + (fillerWidth * dir)/2; |
|
} |
|
|
|
//place pillar sections |
|
if(numSections != 0){ |
|
string wpRef = pieceRef; |
|
string pRef = pillarRef; |
|
float xScale = 1; |
|
|
|
if (rowType == 'floor_wall'){ |
|
wpRef = pieceRef; |
|
pRef = pillarRef; |
|
xScale = 1; |
|
} |
|
else if (rowType == 'floor_sep'){ |
|
wpRef = fSepRef; |
|
pRef = fSepPillarRef; |
|
xScale = 1; |
|
} |
|
else if (rowType == 'roof_sep'){ |
|
wpRef = rSepRef; |
|
pRef = rSepRef; |
|
xScale = pillarWidth / wallWidth; |
|
} |
|
printf('Pillar Start Pos: %e \n', pillarStartPos); |
|
printf('NumPieces: %g \n', numPieces); |
|
for (int pl = 0; pl < numPillars; pl++){ |
|
vector pillarPos; |
|
if(numPieces != 0){ |
|
pillarPos = (pillarStartPos + (wallWidth * dir)/2 + (pillarWidth * dir)/2 + (pillarWidth * dir) * pl) + ((numWallPieces * wallWidth)*dir)*pl; |
|
} |
|
else { |
|
pillarPos = (pillarStartPos + (pillarWidth * dir)/2 + (pillarWidth * dir) * pl) + ((numWallPieces * wallWidth)*dir)*pl; |
|
} |
|
tempPt = addpoint(geoself(), pillarPos); |
|
setpointattrib(geoself(), 'instance', tempPt, pRef, 'set'); |
|
setpointattrib(geoself(), 'scale', tempPt, set(xScale,1,1), 'set'); |
|
setpointattrib(geoself(), 'N', tempPt, n, 'set'); |
|
|
|
for (int sWall = 0; sWall < numWallPieces; sWall++){ |
|
if(pl < numPillars - 1){ |
|
vector wallPos = pillarPos + (pillarWidth * dir)/2 + (wallWidth * dir)/2 + (wallWidth * dir) * sWall; |
|
tempPt = addpoint(geoself(), wallPos); |
|
setpointattrib(geoself(), 'instance', tempPt, wpRef, 'set'); |
|
setpointattrib(geoself(), 'scale', tempPt, set(1,1,1), 'set'); |
|
setpointattrib(geoself(), 'N', tempPt, n, 'set'); |
|
|
|
if (rowType == 'floor_wall') { |
|
addWindows(windowsRd, windowsSq, piece, n, wallPos); |
|
} |
|
|
|
} |
|
} |
|
} |
|
} |
|
|
|
} //end if |
|
|
|
} // end for c |
|
|
|
} // end for r |
|
} |