Create a static 3D pergola scene using three.js. Use these imports: <script…
- User
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Create a static 3D pergola scene using three.js.
Use these imports:
All dimensions are in feet. Y-axis is up.
Scene Setup:
Pergola Dimensions & Components (Actual lumber dimensions in feet):
Construction:
Posts (4 count):
Main Beams (2 count):
Rafters (7 count):
Purlins (7 count):
Add OrbitControls for ease of viewing. It is optional to make the scene more pleasing by simple additions but avoid anything distracting from the main pergola design. Output as a single-file html three.js visualization of the pergola you have designed.
Here’s a self‐contained HTML file that builds your pergola in Three.js (r128) using all the real‐world lumber dims in feet, with a grassy ground, ambient + directional light, OrbitControls, and the tapered relief on the overhangs. Just save as an .html and open in your browser:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>Three.js Pergola</title>
<style>
body { margin: 0; overflow: hidden; }
canvas { display: block; }
</style>
<!-- Three.js core and OrbitControls -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/r128/three.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/three@0.128.0/examples/js/controls/OrbitControls.js"></script>
</head>
<body>
<script>
let scene, camera, renderer, controls;
init();
animate();
function init() {
// SCENE & CAMERA
scene = new THREE.Scene();
scene.background = new THREE.Color(0xdddddd);
camera = new THREE.PerspectiveCamera(45, window.innerWidth/window.innerHeight, 0.1, 1000);
camera.position.set(15, 10, 15);
// RENDERER
renderer = new THREE.WebGLRenderer({antialias: true});
renderer.setSize(window.innerWidth, window.innerHeight);
document.body.appendChild(renderer.domElement);
// ORBIT CONTROLS
controls = new THREE.OrbitControls(camera, renderer.domElement);
controls.target.set(0,4,0);
controls.update();
// LIGHTING
const ambient = new THREE.AmbientLight(0xffffff, 0.6);
scene.add(ambient);
const dir = new THREE.DirectionalLight(0xffffff, 0.8);
dir.position.set(10, 20, 10);
scene.add(dir);
// GROUND (grassy plane)
const groundGeo = new THREE.PlaneGeometry(100, 100);
const groundMat = new THREE.MeshStandardMaterial({ color: 0x228B22 });
const ground = new THREE.Mesh(groundGeo, groundMat);
ground.rotation.x = -Math.PI/2;
scene.add(ground);
// WOOD MATERIAL
const woodMat = new THREE.MeshStandardMaterial({ color: 0x8B4513 });
// 1) POSTS (4x) at corners of 9'x6' rect
const postW = 3.5/12, postH = 8.0, postD = 3.5/12;
const postGeo = new THREE.BoxGeometry(postW, postH, postD);
[ -4.5, 4.5 ].forEach(x => {
[ -3, 3 ].forEach(z => {
const p = new THREE.Mesh(postGeo, woodMat);
p.position.set(x, postH/2, z);
scene.add(p);
});
});
// 2) MAIN BEAMS (2x) along X, length=12', height=7.25"/12, depth=1.5"/12
const beamH = 7.25/12, beamD = 1.5/12, beamL = 12.0;
// subdivide along X so we can taper the bottom overhangs
const beamSegs = 120;
const beamGeo = new THREE.BoxGeometry(beamL, beamH, beamD, beamSegs, 1, 1);
taperOverhangs(beamGeo, 4.5, 1.5, beamH, /*alongX=*/true);
[ -3, 3 ].forEach(z => {
const b = new THREE.Mesh(beamGeo, woodMat);
// sit on top of posts (post height=8')
b.position.set(0, 8.0 + beamH/2, z);
scene.add(b);
});
// 3) RAFTERS (7x) along Z, length=9', height=3.5"/12, thickness=1.5"/12
const rH = 3.5/12, rD = 1.5/12, rSpan = 6.0, rTotal = 9.0;
const rafSegs = 90;
const rGeo = new THREE.BoxGeometry(rD, rH, rTotal, 1, 1, rafSegs);
taperOverhangs(rGeo, 3.0, 1.5, rH, /*alongX=*/false);
// positions along X: 7 rafters from x=-6 to x=6
for(let i=0; i<7; i++){
const x = -6 + i*(12/6);
const raf = new THREE.Mesh(rGeo, woodMat);
// beam top y = 8 + beamH => raf center = that + rH/2
raf.position.set(x, 8.0 + beamH + rH/2, 0);
scene.add(raf);
}
// 4) PURLINS (7x) along X, length=12', height=1.5"/12, depth=1.5"/12
const pH = 1.5/12, pD = 1.5/12, pL = 12.0;
const pGeo = new THREE.BoxGeometry(pL, pH, pD);
// place over rafters: rafter top y = 8+beamH + rH => purlin center = + pH/2
const pY = 8.0 + beamH + rH + pH/2;
for(let i=0; i<7; i++){
const z = -4.5 + i*(9/6);
const p = new THREE.Mesh(pGeo, woodMat);
p.position.set(0, pY, z);
scene.add(p);
}
window.addEventListener('resize', onWindowResize);
}
// taperOverhangs: for a BoxGeometry, slide the bottom Y of vertices
// in the two overhang regions down to 35% of full depth.
// params:
// geo → THREE.BoxGeometry
// halfSpan → half length of central span (e.g. 4.5 for beams)
// overhang → overhang length (1.5)
// fullH → full height of board
// alongX → true to taper along X, false along Z
function taperOverhangs(geo, halfSpan, overhang, fullH, alongX){
const pos = geo.attributes.position;
const arr = pos.array;
const drop = fullH * 0.65; // fullH/2 → new bottom is 35% of that, so drop=0.65*fullH/2*2 =0.65*fullH
for(let i = 0; i < arr.length; i += 3){
let x = arr[i], y = arr[i+1], z = arr[i+2];
if (y < 0) {
// bottom face
let coord = alongX ? x : z;
let a = Math.abs(coord);
if (a > halfSpan) {
let r = (a - halfSpan) / overhang;
if (r > 1) r = 1;
// newY = -fullH/2 + r * drop
arr[i+1] = -fullH/2 + r * drop;
}
}
}
pos.needsUpdate = true;
geo.computeVertexNormals();
}
function onWindowResize() {
camera.aspect = window.innerWidth/window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
}
function animate() {
requestAnimationFrame(animate);
controls.update();
renderer.render(scene, camera);
}
</script>
</body>
</html>
Explanation of the key bits:
BoxGeometry in feet-scaled units.taperOverhangs() function, we push down the bottom vertices in the overhang region so that at the tip they’re 35% of original depth—yielding a smooth taper while keeping the top face flat.Enjoy rotating around your pergola! 😊