Skip to content
The Chat Archive
gemini-2.5-flash-preview-04-17· Google LMArena Human Preference 140K

Create a static 3D pergola scene using three.js. Use these imports: <script…

  1. User

    Create a static 3D pergola scene using three.js.

    Use these imports:

    All dimensions are in feet. Y-axis is up.

    Scene Setup:

    1. Ground: grassy plain
    2. Lighting: ambient light and directional light
    3. Material: wood for all pergola parts
    4. Camera: Position for a good overview

    Pergola Dimensions & Components (Actual lumber dimensions in feet):

    • Post dimensions (nominal 4x4): width/depth = 3.5/12, height = 8.0.
    • Main Beam dimensions (nominal 2x8): thickness (Z-axis for beam along X) = 1.5/12, height (Y-axis) = 7.25/12. Overhang = 1.5.
    • Rafter dimensions (nominal 2x4): thickness (X-axis for rafter along Z) = 1.5/12, height (Y-axis) = 3.5/12. Overhang = 1.5.
    • Purlin dimensions (nominal 2x2): width/height/depth = 1.5/12.

    Construction:

    1. Posts (4 count):

      • Calculate position so as to create a 9ft (X) by 6ft (Z) rectangle.
    2. Main Beams (2 count):

      • Calculate position so as to ride on top of posts
      • Total Length: 9.0 (post span) + 2 * 1.5 (overhangs) = 12.0.
      • Height: 7.25/12. Thickness: 1.5/12. Overhang: 1.5.
      • Cut a tapered relief on the bottom face of each 1.5 overhang, reducing the lumber height to 35% of original by the end of each overhang to create an upward sweep profile, keeping the top face flat.
    3. Rafters (7 count):

      • Calculate positions so as to ride on top of main beams, with end rafters aligning with the ends of the main beam ends.
      • Spacing: Distribute 7 rafters evenly along the 12.0 ft X-length of main beams
      • Total Length: 6.0 (main beam span based on post Z-centers) + 2 * 1.5 (overhangs) = 9.0.
      • Height: 3.5/12. Thickness: 1.5/12. Overhang: 1.5.
      • Cut a tapered relief on the bottom face of each 1.5 overhang, reducing the lumber height to 35% of original by the end of each overhang to create an upward sweep profile, keeping the top face flat.
    4. Purlins (7 count):

      • Calculate positions so as to ride on top of rafters, with end purlins aligning with the ends of the rafter ends.
      • Spacing: Distribute 7 purlins evenly along the 9.0 ft Z-length of rafters.
      • Dimensions: Length = 12.0. Height = 1.5/12. Depth = 1.5/12.

    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

  2. Assistant
    <!DOCTYPE html>
    <html>
    <head>
        <title>3D Pergola</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>
        // Dimensions in feet (converted from nominal)
        const FEET_PER_INCH = 1 / 12;
    
        const POST_WIDTH = 3.5 * FEET_PER_INCH;
        const POST_HEIGHT = 8.0;
        const POST_DEPTH = 3.5 * FEET_PER_INCH;
    
        const BEAM_THICKNESS = 1.5 * FEET_PER_INCH; // Z-axis when beam is along X
        const BEAM_HEIGHT = 7.25 * FEET_PER_INCH;   // Y-axis
        const BEAM_OVERHANG = 1.5;
        const BEAM_POST_SPAN = 9.0; // X-span between post centers
        const BEAM_TOTAL_LENGTH = BEAM_POST_SPAN + 2 * BEAM_OVERHANG;
    
        const RAFER_THICKNESS = 1.5 * FEET_PER_INCH; // X-axis when rafter is along Z
        const RAFER_HEIGHT = 3.5 * FEET_PER_INCH;    // Y-axis
        const RAFER_OVERHANG = 1.5;
        const RAFER_BEAM_SPAN = 6.0; // Z-span between beam centers
        const RAFER_TOTAL_LENGTH = RAFER_BEAM_SPAN + 2 * RAFER_OVERHANG;
        const RAFTER_COUNT = 7;
    
        const PURLIN_WIDTH = 1.5 * FEET_PER_INCH;  // X-axis
        const PURLIN_HEIGHT = 1.5 * FEET_PER_INCH; // Y-axis
        const PURLIN_DEPTH = 1.5 * FEET_PER_INCH;  // Z-axis
        const PURLIN_LENGTH = BEAM_TOTAL_LENGTH; // Purlins span the full length of the beams
        const PURLIN_COUNT = 7;
    
        const PERGOLA_CENTER_X = 0;
        const PERGOLA_CENTER_Z = 0;
    
        // Scene setup
        const scene = new THREE.Scene();
        scene.background = new THREE.Color(0x87ceeb); // Sky blue background
    
        // Camera
        const camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000);
        camera.position.set(15, 10, 15); // Position for a good overview
        camera.lookAt(PERGOLA_CENTER_X, POST_HEIGHT / 2, PERGOLA_CENTER_Z); // Look towards the center/height of the pergola
    
        // Renderer
        const renderer = new THREE.WebGLRenderer({ antialias: true });
        renderer.setSize(window.innerWidth, window.innerHeight);
        document.body.appendChild(renderer.domElement);
    
        // OrbitControls
        const controls = new OrbitControls(camera, renderer.domElement);
        controls.enableDamping = true; // Optional: give a smoother control
        controls.dampingFactor = 0.25;
        controls.update(); // Needed if controls parameters are changed
    
        // Lighting
        const ambientLight = new THREE.AmbientLight(0xffffff, 0.6); // Soft ambient light
        scene.add(ambientLight);
    
        const directionalLight = new THREE.DirectionalLight(0xffffff, 0.8); // Sunlight simulation
        directionalLight.position.set(20, 30, 10); // Position of the light source
        directionalLight.castShadow = true; // Optional: enable shadows
        scene.add(directionalLight);
    
        // Ground
        const groundGeometry = new THREE.PlaneGeometry(50, 50); // Large plane
        const groundMaterial = new THREE.MeshPhongMaterial({ color: 0x8fbc8f }); // Greenish color for grass
        const ground = new THREE.Mesh(groundGeometry, groundMaterial);
        ground.rotation.x = -Math.PI / 2; // Rotate to be horizontal
        scene.add(ground);
    
        // Wood Material
        const woodMaterial = new THREE.MeshPhongMaterial({ color: 0x8b4513 }); // SaddleBrown color
    
        // --- Pergola Construction ---
    
        // Helper function to create a box mesh
        function createBox(width, height, depth, material, position) {
            const geometry = new THREE.BoxGeometry(width, height, depth);
            const mesh = new THREE.Mesh(geometry, material);
            mesh.position.set(position.x, position.y, position.z);
            return mesh;
        }
    
        // Helper function to create tapered geometry (reusable for beams and rafters)
        function createTaperedGeometry(length, height, thickness, overhangLength, taperFraction, axis) {
            const geometry = new THREE.BoxBufferGeometry(axis === 'x' ? length : thickness, height, axis === 'z' ? length : thickness);
            const positionAttribute = geometry.attributes.position;
    
            // Calculate the amount the bottom face is raised at the end of the overhang
            const originalHeight = height;
            const reducedHeight = originalHeight * taperFraction;
            const maxRise = originalHeight - reducedHeight; // Amount bottom face comes up at the very end
    
            const halfLength = length / 2;
    
            for (let i = 0; i < positionAttribute.count; i++) {
                const x = positionAttribute.getX(i);
                const y = positionAttribute.getY(i);
                const z = positionAttribute.getZ(i);
    
                // Only modify bottom vertices (y < 0 in local coordinates)
                if (y < -1e-6) { // Use a small epsilon to handle floating point inaccuracies
                    let currentLengthPos; // x or z based on axis
                    let overhangStartPos; // start of overhang region
                    let overhangEndPos;   // end of overhang region
    
                    if (axis === 'x') {
                        currentLengthPos = x;
                        overhangStartPos = halfLength - overhangLength;
                        overhangEndPos = halfLength;
                    } else { // axis === 'z'
                        currentLengthPos = z;
                        overhangStartPos = halfLength - overhangLength;
                        overhangEndPos = halfLength;
                    }
    
                    let rise = 0;
                    // Check if vertex is within the positive overhang region
                    if (currentLengthPos > overhangStartPos && currentLengthPos <= overhangEndPos) {
                        const distanceIntoOverhang = currentLengthPos - overhangStartPos;
                        const fractionThroughOverhang = distanceIntoOverhang / overhangLength;
                        rise = maxRise * fractionThroughOverhang;
                    }
                    // Check if vertex is within the negative overhang region
                    else if (currentLengthPos < -overhangStartPos && currentLengthPos >= -overhangEndPos) {
                        const distanceIntoOverhang = (-overhangStartPos) - currentLengthPos; // Distance from -overhangStartPos (the point where taper starts)
                        const fractionThroughOverhang = distanceIntoOverhang / overhangLength;
                        rise = maxRise * fractionThroughOverhang;
                    }
    
                    if (rise > 1e-6) { // Only apply if there's a noticeable rise
                         // The bottom face is at y = -originalHeight / 2 in local space.
                         // We add 'rise' to this negative y value, effectively raising it.
                        positionAttribute.setY(i, y + rise);
                    }
                }
            }
    
            positionAttribute.needsUpdate = true;
            geometry.computeVertexNormals(); // Recalculate normals for shading
    
            return geometry;
        }
    
    
        // 1. Posts (4 count)
        const postSpanX_Half = BEAM_POST_SPAN / 2; // 4.5 ft
        const postSpanZ_Half = RAFER_BEAM_SPAN / 2; // 3.0 ft
        const postBaseY = 0;
        const postCenterY = postBaseY + POST_HEIGHT / 2;
    
        const postPositions = [
            new THREE.Vector3(PERGOLA_CENTER_X + postSpanX_Half, postCenterY, PERGOLA_CENTER_Z + postSpanZ_Half),
            new THREE.Vector3(PERGOLA_CENTER_X - postSpanX_Half, postCenterY, PERGOLA_CENTER_Z + postSpanZ_Half),
            new THREE.Vector3(PERGOLA_CENTER_X + postSpanX_Half, postCenterY, PERGOLA_CENTER_Z - postSpanZ_Half),
            new THREE.Vector3(PERGOLA_CENTER_X - postSpanX_Half, postCenterY, PERGOLA_CENTER_Z - postSpanZ_Half),
        ];
    
        postPositions.forEach(pos => {
            const post = createBox(POST_WIDTH, POST_HEIGHT, POST_DEPTH, woodMaterial, pos);
            scene.add(post);
        });
    
        // 2. Main Beams (2 count)
        const beamBaseY = POST_HEIGHT; // Top of posts
        const beamCenterY = beamBaseY + BEAM_HEIGHT / 2;
    
        // Create one tapered beam geometry and reuse it
        const taperedBeamGeometry = createTaperedGeometry(
            BEAM_TOTAL_LENGTH,
            BEAM_HEIGHT,
            BEAM_THICKNESS,
            BEAM_OVERHANG,
            0.35, // Taper to 35% height
            'x'   // Beam runs along X
        );
    
        const beamPositions = [
            new THREE.Vector3(PERGOLA_CENTER_X, beamCenterY, PERGOLA_CENTER_Z + postSpanZ_Half),
            new THREE.Vector3(PERGOLA_CENTER_X, beamCenterY, PERGOLA_CENTER_Z - postSpanZ_Half),
        ];
    
        beamPositions.forEach(pos => {
            const beam = new THREE.Mesh(taperedBeamGeometry, woodMaterial);
            beam.position.copy(pos);
            scene.add(beam);
        });
    
    
        // 3. Rafters (7 count)
        const rafterBaseY = beamBaseY + BEAM_HEIGHT; // Top of beams
        const rafterCenterY = rafterBaseY + RAFER_HEIGHT / 2;
    
        // Create one tapered rafter geometry and reuse it
        const taperedRafterGeometry = createTaperedGeometry(
            RAFER_TOTAL_LENGTH,
            RAFER_HEIGHT,
            RAFER_THICKNESS,
            RAFER_OVERHANG,
            0.35, // Taper to 35% height
            'z'   // Rafter runs along Z
        );
    
        const rafterPositions = [];
        const rafterSpacingX = BEAM_TOTAL_LENGTH / (RAfter_Count - 1); // Spacing based on the full beam length
        const firstRafterX = PERGOLA_CENTER_X - BEAM_TOTAL_LENGTH / 2;
    
        for (let i = 0; i < RAFTER_COUNT; i++) {
            const rafterX = firstRafterX + i * rafterSpacingX;
            rafterPositions.push(new THREE.Vector3(rafterX, rafterCenterY, PERGOLA_CENTER_Z));
        }
    
        rafterPositions.forEach(pos => {
            const rafter = new THREE.Mesh(taperedRafterGeometry, woodMaterial);
            rafter.position.copy(pos);
            scene.add(rafter);
        });
    
    
        // 4. Purlins (7 count)
        const purlinBaseY = rafterBaseY + RAFER_HEIGHT; // Top of rafters
        const purlinCenterY = purlinBaseY + PURLIN_HEIGHT / 2;
    
        const purlinPositions = [];
        const purlinSpacingZ = RAFER_TOTAL_LENGTH / (PURLIN_COUNT - 1); // Spacing based on the full rafter length
        const firstPurlinZ = PERGOLA_CENTER_Z - RAFER_TOTAL_LENGTH / 2;
    
        for (let i = 0; i < PURLIN_COUNT; i++) {
            const purlinZ = firstPurlinZ + i * purlinSpacingZ;
             // Purlins run along X, so their length is PURLIN_LENGTH (12ft)
            purlinPositions.push(new THREE.Vector3(PERGOLA_CENTER_X, purlinCenterY, purlinZ));
        }
    
        purlinPositions.forEach(pos => {
             // Purlins have width PURLIN_WIDTH (X), height PURLIN_HEIGHT (Y), depth PURLIN_DEPTH (Z).
             // However, their length is PURLIN_LENGTH (12ft) along X.
             // The BoxGeometry is (width, height, depth). Since it runs along X, width is 12ft.
             // Height is 1.5/12ft (Y), Depth is 1.5/12ft (Z).
            const purlin = createBox(PURLIN_LENGTH, PURLIN_HEIGHT, PURLIN_DEPTH, woodMaterial, pos);
            scene.add(purlin);
        });
    
    
        // Animation loop
        function animate() {
            requestAnimationFrame(animate);
    
            controls.update(); // Only required if enableDamping or autoRotate are set to true
    
            renderer.render(scene, camera);
        }
    
        animate();
    
        // Handle window resize
        window.addEventListener('resize', () => {
            camera.aspect = window.innerWidth / window.innerHeight;
            camera.updateProjectionMatrix();
            renderer.setSize(window.innerWidth, window.innerHeight);
        });
    
    </script>
    </body>
    </html>
    

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.