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. You may add visual embellishments but will be penalized if you add anything distracting from the main pergola design. Output the pergola you designed as a three.js visualization in a single html file:
Here's a static 3D pergola scene using three.js:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>3D Pergola Visualization</title>
<style>
body { margin: 0; overflow: hidden; }
canvas { display: block; }
</style>
</head>
<body>
<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>
<script>
// Scene setup
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x87CEEB); // Sky blue background
// Camera setup
const camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000);
camera.position.set(15, 10, 15);
camera.lookAt(0, 0, 0);
// Renderer setup
const renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.shadowMap.enabled = true;
document.body.appendChild(renderer.domElement);
// Controls
const controls = new THREE.OrbitControls(camera, renderer.domElement);
controls.enableDamping = true;
controls.dampingFactor = 0.05;
// Lighting
const ambientLight = new THREE.AmbientLight(0xffffff, 0.5);
scene.add(ambientLight);
const directionalLight = new THREE.DirectionalLight(0xffffff, 0.8);
directionalLight.position.set(10, 15, 10);
directionalLight.castShadow = true;
directionalLight.shadow.mapSize.width = 2048;
directionalLight.shadow.mapSize.height = 2048;
scene.add(directionalLight);
// Materials
const woodMaterial = new THREE.MeshStandardMaterial({
color: 0x8B4513,
roughness: 0.8,
metalness: 0.1
});
const grassMaterial = new THREE.MeshStandardMaterial({
color: 0x4CAF50,
roughness: 0.9,
metalness: 0.0
});
// Ground
const groundGeometry = new THREE.PlaneGeometry(50, 50);
const ground = new THREE.Mesh(groundGeometry, grassMaterial);
ground.rotation.x = -Math.PI / 2;
ground.position.y = 0;
ground.receiveShadow = true;
scene.add(ground);
// Pergola dimensions (in feet)
const postWidth = 3.5/12;
const postHeight = 8.0;
const postDepth = 3.5/12;
const beamThickness = 1.5/12;
const beamHeight = 7.25/12;
const beamOverhang = 1.5;
const rafterThickness = 1.5/12;
const rafterHeight = 3.5/12;
const rafterOverhang = 1.5;
const purlinWidth = 1.5/12;
const purlinHeight = 1.5/12;
// Post positions
const postSpanX = 9.0;
const postSpanZ = 6.0;
const postPositions = [
{ x: -postSpanX/2, z: -postSpanZ/2 },
{ x: postSpanX/2, z: -postSpanZ/2 },
{ x: postSpanX/2, z: postSpanZ/2 },
{ x: -postSpanX/2, z: postSpanZ/2 }
];
// Create posts
postPositions.forEach(pos => {
const postGeometry = new THREE.BoxGeometry(postWidth, postHeight, postDepth);
const post = new THREE.Mesh(postGeometry, woodMaterial);
post.position.set(pos.x, postHeight/2, pos.z);
post.castShadow = true;
post.receiveShadow = true;
scene.add(post);
});
// Create main beams
const beamLength = postSpanX + 2 * beamOverhang;
const beamZ = [-postSpanZ/2, postSpanZ/2];
beamZ.forEach(z => {
// Create the main beam
const beamGeometry = new THREE.BoxGeometry(beamLength, beamHeight, beamThickness);
const beam = new THREE.Mesh(beamGeometry, woodMaterial);
beam.position.set(0, postHeight + beamHeight/2, z);
beam.castShadow = true;
beam.receiveShadow = true;
scene.add(beam);
// Create the tapered overhangs
const createTaperedOverhang = (isLeft) => {
const segments = 10;
const overhangLength = beamOverhang;
const points = [];
for (let i = 0; i <= segments; i++) {
const x = (i / segments) * overhangLength;
const y = beamHeight * (1 - 0.65 * (i / segments));
points.push(new THREE.Vector2(x, y / 2));
}
const shape = new THREE.Shape();
shape.moveTo(0, -beamHeight / 2);
shape.lineTo(0, beamHeight / 2);
shape.lineTo(overhangLength, beamHeight / 2);
shape.lineTo(overhangLength, -beamHeight / 2 + (beamHeight * 0.35));
shape.lineTo(0, -beamHeight / 2);
const extrudeSettings = {
steps: 1,
depth: beamThickness,
bevelEnabled: false
};
const geometry = new THREE.ExtrudeGeometry(shape, extrudeSettings);
const overhang = new THREE.Mesh(geometry, woodMaterial);
if (isLeft) {
overhang.position.set(-postSpanX/2 - beamOverhang, postHeight, z - beamThickness/2);
} else {
overhang.position.set(postSpanX/2, postHeight, z - beamThickness/2);
overhang.rotation.y = Math.PI;
}
overhang.castShadow = true;
overhang.receiveShadow = true;
scene.add(overhang);
};
// Create left and right overhangs
createTaperedOverhang(true);
createTaperedOverhang(false);
});
// Create rafters
const rafterCount = 7;
const rafterLength = postSpanZ + 2 * rafterOverhang;
const rafterSpacing = beamLength / (rafterCount - 1);
for (let i = 0; i < rafterCount; i++) {
const x = -beamLength/2 + i * rafterSpacing;
// Create the main rafter
const rafterGeometry = new THREE.BoxGeometry(rafterThickness, rafterHeight, rafterLength);
const rafter = new THREE.Mesh(rafterGeometry, woodMaterial);
rafter.position.set(x, postHeight + beamHeight + rafterHeight/2, 0);
rafter.castShadow = true;
rafter.receiveShadow = true;
scene.add(rafter);
// Create the tapered overhangs
const createTaperedOverhang = (isNorth) => {
const segments = 10;
const overhangLength = rafterOverhang;
const points = [];
for (let j = 0; j <= segments; j++) {
const z = (j / segments) * overhangLength;
const y = rafterHeight * (1 - 0.65 * (j / segments));
points.push(new THREE.Vector2(z, y / 2));
}
const shape = new THREE.Shape();
shape.moveTo(0, -rafterHeight / 2);
shape.lineTo(0, rafterHeight / 2);
shape.lineTo(overhangLength, rafterHeight / 2);
shape.lineTo(overhangLength, -rafterHeight / 2 + (rafterHeight * 0.35));
shape.lineTo(0, -rafterHeight / 2);
const extrudeSettings = {
steps: 1,
depth: rafterThickness,
bevelEnabled: false
};
const geometry = new THREE.ExtrudeGeometry(shape, extrudeSettings);
const overhang = new THREE.Mesh(geometry, woodMaterial);
if (isNorth) {
overhang.position.set(x - rafterThickness/2, postHeight + beamHeight, postSpanZ/2);
overhang.rotation.y = Math.PI / 2;
} else {
overhang.position.set(x + rafterThickness/2, postHeight + beamHeight, -postSpanZ/2 - rafterOverhang);
overhang.rotation.y = -Math.PI / 2;
}
overhang.castShadow = true;
overhang.receiveShadow = true;
scene.add(overhang);
};
// Create north and south overhangs
createTaperedOverhang(true);
createTaperedOverhang(false);
}
// Create purlins
const purlinCount = 7;
const purlinLength = beamLength;
const purlinSpacing = rafterLength / (purlinCount - 1);
for (let i = 0; i < purlinCount; i++) {
const z = -rafterLength/2 + i * purlinSpacing;
const purlinGeometry = new THREE.BoxGeometry(purlinLength, purlinHeight, purlinWidth);
const purlin = new THREE.Mesh(purlinGeometry, woodMaterial);
purlin.position.set(0, postHeight + beamHeight + rafterHeight + purlinHeight/2, z);
purlin.castShadow = true;
purlin.receiveShadow = true;
scene.add(purlin);
}
// Animation loop
function animate() {
requestAnimationFrame(animate);
controls.update();
renderer.render(scene, camera);
}
// Handle window resize
window.addEventListener('resize', () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
});
animate();
</script>
</body>
</html>
Would you like me to explain or break down the code?