Skip to content

Instantly share code, notes, and snippets.

@RH2
Created February 9, 2025 19:04
Show Gist options
  • Save RH2/754edb64f487f0e5ad3c4c67b7ea76fb to your computer and use it in GitHub Desktop.
Save RH2/754edb64f487f0e5ad3c4c67b7ea76fb to your computer and use it in GitHub Desktop.
three experiment
import * as THREE from 'three';
function createBrickWall({
rows = 5,
columns = 10,
brickWidth = 2,
brickHeight = 1,
brickDepth = 0.5,
mortar = 0.1,
color = 0x993333,
} = {}) {
const group = new THREE.Group();
const material = new THREE.MeshPhongMaterial({ color });
for (let row = 0; row < rows; row++) {
const yPos = row * (brickHeight + mortar);
const offset = row % 2 === 0 ? 0 : (brickWidth + mortar) / 2;
for (let col = 0; col < columns; col++) {
const xPos = col * (brickWidth + mortar) + offset;
const brick = new THREE.Mesh(
new THREE.BoxGeometry(brickWidth, brickHeight, brickDepth),
material
);
brick.position.set(xPos, yPos, 0);
group.add(brick);
}
}
// Center the wall
const box = new THREE.Box3().setFromObject(group);
const center = new THREE.Vector3();
box.getCenter(center);
group.position.sub(center);
return group;
}
export { createBrickWall };
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment