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...
<!DOCTYPE html>
<html>
<head>
<title>Three.js Pergola</title>
<style>
body { margin: 0; overflow: hidden; }
</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); // Light blue sky
// Camera setup
const camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000);
camera.position.z = 10;
camera.position.y = 5;
// Renderer setup
const renderer = new THREE.WebGLRenderer();
renderer.setSize(window.innerWidth, window.innerHeight);
document.body.appendChild(renderer.domElement);
// Lighting
const ambientLight = new THREE.AmbientLight(0x808080);
scene.add(ambientLight);
const directionalLight = new THREE.DirectionalLight(0xffffff);
directionalLight.position.set(10, 10, 10);
scene.add(directionalLight);
// Material
const woodColor = 0xDEB887; // Light brown wood color
const woodTexture = new THREE.ImageTexture();
woodTexture.setRenderTarget(new THREE.WebGLRenderTarget(256, 256));
const woodMaterial = new THREE.MeshStandardMaterial({ color: woodColor, map: woodTexture });
woodMaterial.roughness = 0.6;
woodMaterial.metalness = 0.1;
// Helper function to create a rectangular prism with tapered relief
function createPergolaPart(width, height, depth, overhang, taperPercentage) {
const geometry = new THREE.BoxGeometry(width, height, depth);
const material = new THREE.MeshStandardMaterial({ color: woodColor, roughness: 0.6, metalness: 0.1 });
const mesh = new THREE.Mesh(geometry, material);
// Apply tapered relief
const reliefHeight = height * taperPercentage;
const reliefGeometry = new THREE.BoxGeometry(width, reliefHeight, depth);
const reliefMaterial = new THREE.MeshStandardMaterial({ color: woodColor, roughness: 0.6, metalness: 0.1 });
const reliefMesh = new THREE.Mesh(reliefGeometry, reliefMaterial);
reliefMesh.position.z = 0; // Position relief at the bottom
mesh.add(reliefMesh);
return mesh;
}
// --- Pergola Construction ---
// 1. Posts
const postWidth = 3.5 / 12;
const postHeight = 8.0 / 12;
const posts = [];
for (let i = 0; i < 4; i++) {
const post = createPergolaPart(postWidth, postHeight, 12, 0, 0);
post.position.set(
(i % 2 === 0) ? -4.5 : 4.5,
0,
(i * 2) * 3
);
scene.add(post);
}
// 2. Main Beams
const beamWidth = 1.5 / 12;
const beamHeight = 7.25 / 12;
const beamOverhang = 1.5 / 12;
const mainBeams = [];
for (let i = 0; i < 2; i++) {
const beam = createPergolaPart(beamWidth, beamHeight, 12, beamOverhang, 0);
beam.position.set(
(i % 2 === 0) ? -4.5 : 4.5,
beamHeight / 2,
3
);
scene.add(beam);
}
// 3. Rafters
const rafterWidth = 1.5 / 12;
const rafterHeight = 3.5 / 12;
const rafterOverhang = 1.5 / 12;
const rafterSpacing = 9 / (7 - 1); // Evenly spaced 7 rafters
const rafters = [];
for (let i = 0; i < 7; i++) {
const rafter = createPergolaPart(rafterWidth, rafterHeight, 12, rafterOverhang, 0);
const xPosition = (i - 3.5) * rafterSpacing;
rafter.position.set(
xPosition,
beamHeight + rafterHeight / 2,
3
);
scene.add(rafter);
}
// 4. Purlins
const purlinWidth = 1.5 / 12;
const purlinHeight = 1.5 / 12;
const purlinLength = 12;
const purlins = [];
for (let i = 0; i < 7; i++) {
const purlin = createPergolaPart(purlinWidth, purlinHeight, purlinLength, 0, 0);
const xPosition = (i - 3.5) * rafterSpacing;
purlin.position.set(
xPosition,
rafterHeight + purlinHeight / 2,
3
);
scene.add(purlin);
}
// Orbit Controls
const controls = new THREE.OrbitControls(camera, renderer.domElement);
controls.enableDamping = true;
controls.dampingFactor = 0.05;
controls.screenSpacePanning = false;
controls.maxPolarAngle = Math.PI / 2;
// Animation loop
function animate() {
requestAnimationFrame(animate);
renderer.render(scene, camera);
controls.update();
}
animate();
</script>
</body>
</html>