Skip to content

Instantly share code, notes, and snippets.

@deathbearbrown
Created November 18, 2015 16:59
Show Gist options
  • Save deathbearbrown/9d89d815e1a663b39e6e to your computer and use it in GitHub Desktop.
Save deathbearbrown/9d89d815e1a663b39e6e to your computer and use it in GitHub Desktop.
//----------------------------------------------------------------------------
// createAGrid
//
// opts
// {
// height: width,
// width: depth,
// linesHeight: b,
// linesWidth: c,
// color: 0xcccccc
// }
//
//____________________________________________________________________________
function createAGrid(opts){
var config = opts || {
height: 500,
width: 500,
linesHeight: 10,
linesWidth: 10,
color: 0xDD006C
};
var material = new THREE.LineBasicMaterial({
color: config.color,
opacity: 0.2
});
var gridObject = new THREE.Object3D(),
gridGeo= new THREE.Geometry(),
stepw = 2*config.width/config.linesWidth,
steph = 2*config.height/config.linesHeight;
//width
for ( var i = - config.width; i <= config.width; i += stepw ) {
gridGeo.vertices.push( new THREE.Vector3( - config.height, i,0 ) );
gridGeo.vertices.push( new THREE.Vector3( config.height, i,0 ) );
}
//height
for ( var i = - config.height; i <= config.height; i += steph ) {
gridGeo.vertices.push( new THREE.Vector3( i,- config.width,0 ) );
gridGeo.vertices.push( new THREE.Vector3( i, config.width, 0 ) );
}
var line = new THREE.Line( gridGeo, material, THREE.LinePieces );
gridObject.add(line);
return gridObject;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment