Skip to content

Commit

Permalink
Specifying specific points in cube gen.
Browse files Browse the repository at this point in the history
  • Loading branch information
alexlitty committed Aug 18, 2017
1 parent ce83106 commit c567256
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 28 deletions.
9 changes: 5 additions & 4 deletions modules/wrapper/Generate/Shape/Cube.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ const _ = require('underscore');

module.exports = (randar) => {
randar.generate.cube = function(options) {
return randar.generate.cuboid(_.extend(options, {
height : options.width,
depth : options.width
}));
if (_.isNumber(options.width)) {
options.height = options.depth = options.width;
}

return randar.generate.cuboid(options);
}
}
53 changes: 38 additions & 15 deletions modules/wrapper/Generate/Shape/Cuboid.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,47 @@ module.exports = (randar) => {
let palette = options.palette || randar.palette.Default;
let geometry = randar.geometry();

let wr = options.width / 2;
let hr = options.height / 2;
let dr = options.depth / 2;

let vertex = randar.vertex();
if (_.isNumber(options.joint)) {
vertex = vertex.withJoint(options.joint);
let frontTopLeft, frontTopRight, frontBottomLeft, frontBottomRight,
backTopLeft, backTopRight, backBottomLeft, backBottomRight;

if (options.frontTopLeft && options.frontTopRight && options.frontBottomLeft && options.frontBottomRight &&
options.backTopLeft && options.backTopRight && options.backBottomLeft && options.backBottomRight)
{
frontTopLeft = options.frontTopLeft;
frontTopRight = options.frontTopRight;
frontBottomLeft = options.frontBottomLeft;
frontBottomRight = options.frontBottomRight;

backTopLeft = options.backTopLeft;
backTopRight = options.backTopRight;
backBottomLeft = options.backBottomLeft;
backBottomRight = options.backBottomRight;
}

let frontTopLeft = vertex.withPosition(randar.vector(-wr, -hr, -dr));
let frontTopRight = vertex.withPosition(randar.vector(wr, -hr, -dr));
let frontBottomLeft = vertex.withPosition(randar.vector(-wr, hr, -dr));
let frontBottomRight = vertex.withPosition(randar.vector(wr, hr, -dr));
else if (_.isNumber(options.width), _.isNumber(options.height), _.isNumber(options.depth)) {
let wr = options.width / 2;
let hr = options.height / 2;
let dr = options.depth / 2;

let vertex = randar.vertex();
if (_.isNumber(options.joint)) {
vertex = vertex.withJoint(options.joint);
}

frontTopLeft = vertex.withPosition(randar.vector(-wr, -hr, -dr));
frontTopRight = vertex.withPosition(randar.vector(wr, -hr, -dr));
frontBottomLeft = vertex.withPosition(randar.vector(-wr, hr, -dr));
frontBottomRight = vertex.withPosition(randar.vector(wr, hr, -dr));

backTopLeft = vertex.withPosition(randar.vector(-wr, -hr, dr));
backTopRight = vertex.withPosition(randar.vector(wr, -hr, dr));
backBottomLeft = vertex.withPosition(randar.vector(-wr, hr, dr));
backBottomRight = vertex.withPosition(randar.vector(wr, hr, dr));
}

let backTopLeft = vertex.withPosition(randar.vector(-wr, -hr, dr));
let backTopRight = vertex.withPosition(randar.vector(wr, -hr, dr));
let backBottomLeft = vertex.withPosition(randar.vector(-wr, hr, dr));
let backBottomRight = vertex.withPosition(randar.vector(wr, hr, dr));
else {
throw new Error('Invalid generation options');
}

// Front face.
let color = palette.sample();
Expand Down
29 changes: 23 additions & 6 deletions modules/wrapper/Generate/Shape/Rectangle.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,32 @@
const _ = require('underscore');

module.exports = (randar) => {
randar.generate.rectangle = function(options) {
let palette = options.palette || randar.palette.Default;
let geometry = randar.geometry();

let wr = options.width / 2;
let hr = options.height / 2;
let topLeft, topRight, bottomLeft, bottomRight;

if (options.topLeft && options.topRight && options.bottomLeft && options.bottomRight) {
topLeft = options.topLeft;
topRight = options.topRight;
bottomLeft = options.bottomLeft;
bottomRight = options.bottomRight;
}

else if (_.isNumber(options.width) && _.isNumber(options.height)) {
let wr = options.width / 2;
let hr = options.height / 2;

topLeft = randar.vector(-wr, -hr, 0);
topRight = randar.vector(wr, -hr, 0);
bottomLeft = randar.vector(-wr, hr, 0);
bottomRight = randar.vector(wr, hr, 0);
}

let topLeft = randar.vector(-wr, -hr, 0);
let topRight = randar.vector(wr, -hr, 0);
let bottomLeft = randar.vector(-wr, hr, 0);
let bottomRight = randar.vector(wr, hr, 0);
else {
throw new Error('Invalid generation options');
}

let color = palette.sample();
geometry.append(randar.vertex(topLeft, color));
Expand Down
8 changes: 5 additions & 3 deletions modules/wrapper/Generate/Shape/Square.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ const _ = require('underscore');

module.exports = (randar) => {
randar.generate.square = function(options) {
return randar.generate.rectangle(_.extend(options, {
height: options.width
}));
if (_.isNumber(options.width)) {
options.height = options.width;
}

return randar.generate.rectangle(options);
}
}

0 comments on commit c567256

Please sign in to comment.