Skip to content

Instantly share code, notes, and snippets.

@Adrianl3d
Created July 6, 2014 10:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Adrianl3d/cd61f1f4697a81f202c8 to your computer and use it in GitHub Desktop.
Save Adrianl3d/cd61f1f4697a81f202c8 to your computer and use it in GitHub Desktop.
Tutorial build simple 2 level house
// greenGables.js
// Simple 2 level house script greenGables v0.1
// Created by Adrian on 30 April 2014
// Copyright 2014 Adrian McCarlie
// Released under Creative Commons By Attribution Share Alike, feel free to modify and share.
// Default Build a 60 mtr x 60 mtr building at given location
// Can be built anywhere simply by changing X_POS, Y_POS and Z_POS at lines 18, 19, and 20.
// Can scale by changing W, H and L and tweaking the value (16) at line 84 to allow for the gable ends
// Change colours by adjusting values of the last 3 numbers in the Voxels.setVoxel(x, y, z, 1, 100, 100, 255) in this case 100, 100, 255 which is lightblue. (rgb)
// This script is written with all different coloured walls for easier understanding of the script.
//
// for removal use eraseGreenGables.js
//CONSTANTS
//identify the south west co-ord of your house
var X_POS = 100; // "constant" this MUST be changed to the south boundary of proposed house
var Y_POS = 100; // "constant" this MUST be changed to the bottom boundary of proposed house (floor)
var Z_POS = 100; // "constant" this MUST be changed to the west boundary of proposed house
var W = 60; //optional-change this to change the WIDTH of your house
var H = 10; //optional-change this to change the HEIGHT of each level
var L = 60; //optional-change this to change the LENGTH of your house
//variables
var x = X_POS; // set up x variable to co-ord starting point
var y = Y_POS; // set up y variable to co-ord starting point
var z = Z_POS; // set up y variable to co-ord starting point
var a = 0; // variable used in gable slope
var b = L-2; // variable used in gable slope
///////////////-----------------------------------------///////////////////
// define function
function buildFloors() // first of 6 functions
{
// build lower and upper floors
while (z<=(Z_POS+L))//build 2 floors// do this until we reach the length L
{
while (x<=(X_POS+W))//build 2 rows//do this until we reach the width W
{
Voxels.setVoxel(x, Y_POS, z, 1, 230, 230, 180);// place offwhite voxel at groundfloor
Voxels.setVoxel(x, Y_POS+H, z, 1, 230, 230, 180);// place offwhite voxel upper floor (y plus height)
x++ // increment x to make a row
}
x = X_POS; // reset x to original position
z++; // increment z to make a floor
}//Ground floor and upper floor finished
z = Z_POS;// reset z to original position
} // end of buildFloors() function
/////////-----------------------------------------------/////////////
// define function
function buildWalls() // second of 6 functions
{
// build 4 walls to height of 2 levels
while (y < (Y_POS+(H*2)))// do this for all walls until we reach twice the height (2 levels)
{
// build left and right walls across the x axis
while (x<=(X_POS+W)) //build 2 walls until we reach the width
{
Voxels.setVoxel(x, y, Z_POS, 1.0, 250, 150, 250);//purple wall at z
Voxels.setVoxel(x, y, Z_POS+L, 1.0, 200, 200, 80);//yellow wall at z plus length
x++;
}
//build back and front walls across the z axis
while (z<=(Z_POS+L))//build 2 more walls until we reach the length
{
Voxels.setVoxel(X_POS, y, z, 1.0, 100, 100, 255);// blue wall at x
Voxels.setVoxel(X_POS+W, y, z, 1.0, 255, 100, 100); //red wall at x plus width
z++;
}
x = X_POS; //reset "x" to starting point
z = Z_POS; //reset "z" to starting point
y++; // increment "y" to build walls UP
}
} // end of buildWalls() function
///////////////------------------------------------------////////////////
// define function
function buildGable() // third of 6 functions
{
//builds a green gable end up from the top of the existing front and back walls
y = (Y_POS+(H*2));//set starting point at top of existing walls
while (y < (Y_POS+(H*2)+16))// (added 16) stack front and back gable ends down the z axis,
//you might have to play with this number if you change the size from default 60m.
{
while (z<=(Z_POS+(b+1)))// build decreasing rows until zero to create an apex
{
Voxels.setVoxel(X_POS, y, z, 1.0, 100, 255, 100);// green gable on blue wall
Voxels.setVoxel(X_POS+W, y, z, 1.0, 100, 255, 100); // green gable on red wall
z++;
}
a = (a+2)// increase a by 2 each loop
z = (Z_POS+a);//starting point steps in 2 voxels per loop
y++;// step up one voxel per loop
b = (b-2);// decrease row ending position by 2 voxels per loop
}
} // end of buildGable() function
///////////////------------------------------------------////////////////
// define function
function buildRoof() // fourth of 6 functions
{
x = X_POS;
z = Z_POS;
y = (Y_POS + (H*2)) //begin at top of walls
// Create a gable roof which creates voxels at 2:1 up slope until half the length of the building is reached
while (z<=((Z_POS-2)+(L/2)))// finish 2 vox back from center (half the length minus 2)
{
while (x<=(X_POS+W))//entire width of building
{
Voxels.setVoxel(x, y, z, 1.0, 200, 60, 0);// terracotta roof
Voxels.setVoxel(x, y, z+1, 1.0, 200, 60, 0);// this line puts another voxel right next to the first one to create the 2:1 slope
x++;
}
y++;// increment "y" as we go up the slope
x = X_POS;// reset starting x each loop
z=(z+2);// increment by 2 each loop to get 2:1 angle
}
// end of first half of the roof at peak
// do not reset "z" because we go on from here
// Continue gable roof at 2:1 down slope until the other half of the building is covered
while (z<=(Z_POS+L))// go all the way to the end of the building
{
while (x<=(X_POS+W))//entire width of building
{
Voxels.setVoxel(x, y, z, 1.0, 230, 80, 0);// terracotta roof
Voxels.setVoxel(x, y, z+1, 1.0, 230, 80, 0);
x++;
}
y--;// decrement "y" because we are coming down now
x = X_POS;// reset starting x each loop
z = (z+2);// add 2 across as we go 1 down (2:1)
}
} // end of buildRoof() function
///////////////------------------------------------------////////////////
function cutDoors() // fifth of 6 functions
{
y=(Y_POS);// reset y
while (y < (Y_POS+H))// cut door full height (10 vox)
{
// create 20vox wide doorway, from 10 voxels before center to 10 voxels past center
// lower level only front and back
z=Z_POS+((L/2)-10);// start position half length minus 10
while (z<Z_POS+((L/2)+10))//finish position half length plus 10
{
Voxels.eraseVoxel(X_POS, y, z, 1.0); //front door lower level
Voxels.eraseVoxel(X_POS+W, y, z, 1.0); // back door lower level
z++;
}
y++;
}
} // end function cutDoors()
///////////////------------------------------------------////////////////
// define function
function cutWindows() // sixth of 6 functions
{
y=(Y_POS+3);// start 3 voxels up from ground
while (y < (Y_POS+8))// cut all windows 5 voxels high (8-3)
{
x=(X_POS+5);//start 5 voxels in from X_POS
//cut first windows left and right walls
while (x<(X_POS+15))// doing this 10 times (15-5) cut 10 voxels
{
Voxels.eraseVoxel(x, y, Z_POS, 1.0);//left lower
Voxels.eraseVoxel(x, y, Z_POS+L, 1.0);//right lower
Voxels.eraseVoxel(x, y+H, Z_POS, 1.0);//left upper
Voxels.eraseVoxel(x, y+H, Z_POS+L, 1.0);//right upper
x++;
}
x=(X_POS+(W/2)-5);//move to middle window start 5 vox before center
//cut second windows left and right walls
while (x<(X_POS+(W/2)+5))//end 5 vox after center
{
Voxels.eraseVoxel(x, y, Z_POS, 1.0, 0);
Voxels.eraseVoxel(x, y, Z_POS+L, 1.0);
Voxels.eraseVoxel(x, y+H, Z_POS, 1.0);
Voxels.eraseVoxel(x, y+H, Z_POS+L, 1.0);
x++;
}
x=(X_POS+(W-15));// move to last window start 15 vox in from edge of wall
//cut third windows left and right walls
while (x<(X_POS+W-5))// end 5 vox before edge of wall
{
Voxels.eraseVoxel(x, y, Z_POS, 1.0);
Voxels.eraseVoxel(x, y, Z_POS+L, 1.0);
Voxels.eraseVoxel(x, y+H, Z_POS, 1.0);
Voxels.eraseVoxel(x, y+H, Z_POS+L, 1.0);
x++;
}
z=(Z_POS+5);//start 5 voxels in from Z_POS
/////////////////////////////cut front and back windows
while (z<(Z_POS+15))//first windows
{
Voxels.eraseVoxel(X_POS, y+H, z, 1.0);// upper level only // front
Voxels.eraseVoxel(X_POS+W, y+H, z, 1.0);// upper level only // back
z++;
}
z=(Z_POS+(L/2)-5);
while (z<(Z_POS+(L/2)+5))//second windows
{
Voxels.eraseVoxel(X_POS, y+H, z, 1.0);
Voxels.eraseVoxel(X_POS+W, y+H, z, 1.0);
z++;
}
z=(Z_POS+L-15);
while (z<(Z_POS+L-5))//third windows
{
Voxels.eraseVoxel(X_POS, y+H, z, 1.0);
Voxels.eraseVoxel(X_POS+W, y+H, z, 1.0);
z++;
}
y++;
}
} // end function cutWindows()
///////////////------------------------------------------////////////////
// define function
function buildHouse()// this function combines all the working functions into a single call
{
buildFloors(); //run first function
buildWalls(); //run second function
buildGable(); //run third function
buildRoof(); // run fourth function
cutDoors(); // run fifth function
cutWindows(); //run sixth function
Script.stop(); // stops the script after all functions have run
}
buildHouse(); // this command tells the system to run the buildHouse() function which will run all functions and build the house.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment