Skip to content
TheChatArchiveThe Chat Archive
o3-mini· OpenAIHugging Face LMArena Human Preference 140K

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

From a Chatbot Arena battleThe same person sent this prompt to two anonymous models at once. Compare it with Claudeclaude-3-5-haiku-20241022’s answer.
  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
      • 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
      • 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. Output as a pleasing single-file html three.js visualization.

  2. Assistant

    Below is one complete HTML file that creates a Three.js scene with a grassy ground, ambient and directional lights, OrbitControls, and a pergola made of posts, two “taper‐relief” main beams, seven rafters and seven purlins. (All dimensions are in feet; note that we use feet–numbers directly.) In this example the tapered “overhang” parts are built by “joining” a straight (center) box with an “overhang” box whose bottom‐vertices have been lifted in a linear fashion so that (for a main beam, for example) the full bottom is at the posts and the overhang “free end” has only 35% of the full thickness. (A similar tweak is done for the rafters.)

    You can copy–paste the code into an HTML file and open it in your browser.

    Note: Because a “real” pergola has many custom curves and joins, this example uses a simplified approach (merging several BoxGeometries and then modifying the vertices in the overhang pieces) to approximate the look of tapered relief on the bottom face. (You can later refine by building fully custom BufferGeometries.)

    Below is the complete code:


    <!DOCTYPE html>
    <html lang="en">
      <head>
        <meta charset="UTF-8" />
        <title>Three.js 3D Pergola</title>
        <style>
          body { margin: 0; overflow: hidden; }
          canvas { display: block; }
        </style>
      </head>
      <body>
        <!-- three.js 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>
    
        <script>
          // --------- Scene Setup -----------
          const scene = new THREE.Scene();
          scene.background = new THREE.Color( 0x87ceeb ); // sky-blue
    
          // Grassy ground: a large green plane
          const groundGeo = new THREE.PlaneGeometry(50, 50);
          const groundMat = new THREE.MeshLambertMaterial({ color: 0x228B22 });
          const ground = new THREE.Mesh(groundGeo, groundMat);
          ground.rotation.x = - Math.PI / 2;
          ground.position.y = 0;
          scene.add(ground);
    
          // Lights: ambient + directional
          const ambientLight = new THREE.AmbientLight(0xffffff, 0.5);
          scene.add(ambientLight);
          const directionalLight = new THREE.DirectionalLight(0xffffff, 0.8);
          directionalLight.position.set(10, 20, 10);
          scene.add(directionalLight);
    
          // Woody material for the pergola parts (a warm brown)
          const woodMaterial = new THREE.MeshStandardMaterial({ color: 0x8B4513 });
    
          // --------- Helper Functions ---------
    
          // Create a box that will have its bottom face tapered over an "overhang" region.
          // Parameters:
          //   length: full length of the beam (in the axis of orientation)
          //   height: full height (thickness on the vertical axis)
          //   depth: thickness in the perpendicular (narrow) dimension
          //   overhang: length (at each end) that will be tapered.
          //   axis: the long axis ('x' or 'z'). For main beams, axis = 'x'; for rafters, axis = 'z'.
          //   fullHeight: the full thickness (height) before taper; taper reduces the effective thickness to 35%
          // Returns a THREE.Group that contains three meshes (left overhang, center, right overhang) merged into one group.
          function createTaperedBeam(length, height, depth, overhang, axis, fullHeight) {
            // fullHeight is normally the same as height, but used for clarity.
            // The center (non‐tapered) portion has length = (length - 2*overhang)
            const centerLength = length - 2 * overhang;
            const group = new THREE.Group();
    
            // Create center piece (a simple box)
            let centerGeom;
            if (axis === 'x') {
              centerGeom = new THREE.BoxGeometry(centerLength, height, depth);
            } else {
              centerGeom = new THREE.BoxGeometry(depth, height, centerLength);
            }
            const centerMesh = new THREE.Mesh(centerGeom, woodMaterial);
            // Position center piece so that its long axis is centered
            if (axis === 'x') {
              centerMesh.position.x = 0;
            } else {
              centerMesh.position.z = 0;
            }
            // Bottom of center remains at posts top (we assume posts top = 8 ft)
            centerMesh.position.y = 8 + height/2;
            group.add(centerMesh);
    
            // Function to apply taper on the bottom face of an overhang box.
            // The overhang box is modeled with center at 0; its long axis goes from -overhang/2 to +overhang/2.
            // The taper is such that, for the "free end" (the end away from the center), the effective thickness is 35% of the full thickness.
            function applyTaper(geom, side) {
              geom = geom.toNonIndexed(); // make sure geometry is not indexed so we can change vertices individually
              const posAttr = geom.attributes.position;
              const count = posAttr.count;
              // In BoxGeometry, the vertical axis is always the y axis.
              // In the local coordinates of the overhang piece, top = height/2 and bottom = -height/2.
              // We want to leave the top face intact and adjust only bottom vertices.
              // For a left overhang (side = "left"), the free end is at the left (lowest x if axis === 'x', or lowest z if axis==='z').
              // For a right overhang (side = "right"), the free end is at the right (highest x or z).
              const freeEndVal = - overhang/2;  // for left overhang if axis == 'x' (or z), free end = -overhang/2
              const joinEndVal = overhang/2;      // joining edge value.
              for (let i = 0; i < count; i++) {
                let vx = posAttr.getX(i), vy = posAttr.getY(i), vz = posAttr.getZ(i);
                let posAlong;
                if(axis === 'x'){
                  posAlong = vx;
                } else {
                  posAlong = vz;
                }
                // Determine if this vertex is on the bottom face.
                if (Math.abs(vy + height/2) < 0.001) {
                  // For left overhang, if posAlong is near freeEndVal then factor = 0, if posAlong near joinEndVal then factor = 1.
                  let factor;
                  if(side === "left"){
                    factor = (posAlong - freeEndVal) / (overhang);
                  } else { // right overhang: free end is at +overhang/2, joining edge is at -overhang/2.
                    factor = (freeEndVal - posAlong) / (overhang);
                  }
                  factor = THREE.MathUtils.clamp(factor, 0, 1);
                  // At the join edge (factor=1), leave the bottom at -height/2.
                  // At the free end (factor=0), raise the bottom so that the overall thickness becomes 35% of full.
                  const desiredThickness = fullHeight * 0.35; // 35%
                  const newBottom = (height/2) - desiredThickness;
                  const oldBottom = - height/2;
                  const newY = oldBottom + (1 - factor) * (newBottom - oldBottom);
                  posAttr.setY(i, newY);
                }
              }
              posAttr.needsUpdate = true;
              return geom;
            }
    
            // Create left overhang
            let leftGeom;
            if (axis === 'x') {
              leftGeom = new THREE.BoxGeometry(overhang, height, depth);
            } else {
              leftGeom = new THREE.BoxGeometry(depth, height, overhang);
            }
            // Apply taper to the left overhang.
            leftGeom = applyTaper(leftGeom, "left");
            const leftMesh = new THREE.Mesh(leftGeom, woodMaterial);
            // For box geometry, the center is at 0. Position so that the right face of the left piece touches the center piece.
            if(axis === 'x'){
              leftMesh.position.x = - (centerLength/2 + overhang/2);
            } else {
              leftMesh.position.z = - (centerLength/2 + overhang/2);
            }
            leftMesh.position.y = 8 + height/2;
            group.add(leftMesh);
    
            // Create right overhang
            let rightGeom;
            if (axis === 'x') {
              rightGeom = new THREE.BoxGeometry(overhang, height, depth);
            } else {
              rightGeom = new THREE.BoxGeometry(depth, height, overhang);
            }
            rightGeom = applyTaper(rightGeom, "right");
            const rightMesh = new THREE.Mesh(rightGeom, woodMaterial);
            if(axis === 'x'){
              rightMesh.position.x = (centerLength/2 + overhang/2);
            } else {
              rightMesh.position.z = (centerLength/2 + overhang/2);
            }
            rightMesh.position.y = 8 + height/2;
            group.add(rightMesh);
    
            return group;
          }
    
          // Create a simple box (no taper) for posts and purlins.
          function createBox(w, h, d, pos) {
            const geom = new THREE.BoxGeometry(w, h, d);
            const mesh = new THREE.Mesh(geom, woodMaterial);
            mesh.position.set(pos.x, pos.y, pos.z);
            return mesh;
          }
    
          // --------- Build Pergola Components ---------
    
          const pergola = new THREE.Group();
    
          // 1. Posts (4 count)
          // Post dimensions (nominal 4x4): width = 3.5/12, depth = 3.5/12, height = 8.0.
          const postW = 3.5 / 12;
          const postH = 8.0;
          const postD = 3.5 / 12;
          // The posts are arranged as a 9ft (X) by 6ft (Z) rectangle.
          // Their centers are located at:
          const postPositions = [
            new THREE.Vector3(-4.5, postH/2, -3),
            new THREE.Vector3(4.5, postH/2, -3),
            new THREE.Vector3(-4.5, postH/2, 3),
            new THREE.Vector3(4.5, postH/2, 3),
          ];
          postPositions.forEach(pos => {
            pergola.add(createBox(postW, postH, postD, pos));
          });
    
          // 2. Main Beams (2 count, one at the "front" and one at the "back")
          // Dimensions (nominal 2x8): height = 7.25/12, thickness (depth) = 1.5/12.
          // Total Length = post span (9ft) + 2*overhang (1.5ft) = 12ft.
          const beamHeight = 7.25 / 12;
          const beamDepth = 1.5 / 12;
          const beamLength = 12.0;
          const beamOverhang = 1.5;
          // Create a tapered beam (or assembly) along the X-axis.
          // The beam is to “ride on top” of the posts (i.e. its bottom flush with 8ft).
          // (Our createTaperedBeam function places the beam so that its bottom is at 8)
          const mainBeam = createTaperedBeam(beamLength, beamHeight, beamDepth, beamOverhang, 'x', beamHeight);
          // Clone it for the two beams.
          const beam1 = mainBeam.clone();
          const beam2 = mainBeam.clone();
          // Place beam1 at z = -3 (front) and beam2 at z = 3 (back)
          beam1.position.z = -3;
          beam2.position.z = 3;
          pergola.add(beam1);
          pergola.add(beam2);
    
          // 3. Rafters (7 count)
          // Dimensions (nominal 2x4): height = 3.5/12, thickness = 1.5/12.
          // Total Length = (main beam span based on post Z-centers = 6ft) + 2*overhang (1.5ft) = 9ft.
          const rafterHeight = 3.5 / 12;
          const rafterThickness = 1.5 / 12;
          const rafterLength = 9.0;  // along Z axis
          const rafterOverhang = 1.5;
          // We’ll create a tapered rafter along the Z-axis.
          const baseRafter = createTaperedBeam(rafterLength, rafterHeight, rafterThickness, rafterOverhang, 'z', rafterHeight);
          // Its bottom “rides” on top of the main beams.
          // We place the rafter so that its bottom is at main-beam top = 8 + beamHeight.
          // That means its center (height/2 above bottom) is at 8 + beamHeight + (rafterHeight/2).
          const rafterY = 8 + beamHeight + rafterHeight/2;
          // There are 7 rafters evenly spaced along the 12ft X-length of the pergola.
          const rafterGroup = new THREE.Group();
          const numRafters = 7;
          const xStart = -6;
          const xSpacing = 12 / (numRafters - 1); // from -6 to 6
          for (let i = 0; i < numRafters; i++) {
            const rafter = baseRafter.clone();
            rafter.position.x = xStart + i * xSpacing;
            rafter.position.y = rafterY;
            // The tapered rafter is built along Z, centered at 0.
            rafterGroup.add(rafter);
          }
          pergola.add(rafterGroup);
    
          // 4. Purlins (7 count)
          // Purlin dimensions (nominal 2x2): length = 12ft, height = 1.5/12, depth = 1.5/12.
          const purlinLength = 12.0;
          const purlinHeight = 1.5 / 12;
          const purlinDepth = 1.5 / 12;
          // They ride on top of rafters. We distribute 7 purlins evenly along the 9ft span (Z) of the rafters.
          const purlinGroup = new THREE.Group();
          const numPurlins = 7;
          const zStart = -4.5; 
          const zSpacing = 9 / (numPurlins - 1);
          // For the purlins, we use a simple box.
          // They run along X (the full 12ft) and are centered (z position given below).
          for (let i = 0; i < numPurlins; i++){
            const purlin = new THREE.Mesh(new THREE.BoxGeometry(purlinLength, purlinHeight, purlinDepth), woodMaterial);
            purlin.position.set(0, 8 + beamHeight + rafterHeight + purlinHeight/2, zStart + i*zSpacing);
            purlinGroup.add(purlin);
          }
          pergola.add(purlinGroup);
    
          scene.add(pergola);
    
          // --------- Camera & Controls ---------
          const camera = new THREE.PerspectiveCamera( 45, window.innerWidth / window.innerHeight, 0.1, 100 );
          camera.position.set(20, 20, 20);
          camera.lookAt(0, 5, 0);
    
          const controls = new THREE.OrbitControls( camera );
          controls.target.set(0,8,0);
          controls.update();
    
          // --------- Renderer ---------
          const renderer = new THREE.WebGLRenderer({ antialias: true });
          renderer.setSize( window.innerWidth, window.innerHeight );
          document.body.appendChild( renderer.domElement );
    
          // --------- Animation Loop -----------
          function animate() {
            requestAnimationFrame( animate );
            controls.update();
            renderer.render( scene, camera );
          }
          animate();
    
          // --------- Handle Window Resize ----------
          window.addEventListener( 'resize', onWindowResize );
          function onWindowResize(){
            camera.aspect = window.innerWidth / window.innerHeight;
            camera.updateProjectionMatrix();
            renderer.setSize( window.innerWidth, window.innerHeight );
          }
        </script>
      </body>
    </html>
    

    Explanation

    1. Scene & Lights:
      A grassy plane is created as the ground, and ambient plus directional light give a pleasing outdoor look.

    2. Wood Material:
      A brown (#8B4513) MeshStandardMaterial simulates wood for all pergola parts.

    3. Posts:
      Four posts (using BoxGeometry) are positioned so that their centers form a 9ft×6ft rectangle (at x = ±4.5 and z = ±3).

    4. Main Beams:
      The pergola has two main beams. They are assembled from a center (9ft long) plus two 1.5ft “overhang” pieces. In the overhang pieces the “bottom” of the box is adjusted (via the helper function applyTaper) so that at the free end the effective thickness is reduced to 35%. The beams are oriented along the X–axis and are placed atop the posts (their bottom is at y = 8).

    5. Rafters:
      Seven rafters (similarly built from a center plus two overhangs, but now oriented along the Z–axis) are evenly spaced along X from –6ft to +6ft. They “ride” on top of the main beams.

    6. Purlins:
      Seven purlins (simple boxes 12ft long) are distributed along the full Z–span of the rafters and placed on top of the rafter assemblies.

    7. OrbitControls & Renderer:
      Finally, the camera is positioned for a good overall view. The OrbitControls let you explore the scene.

    This single–file HTML example should give you a pleasing static 3D visualization of a pergola with the specified dimensions and tapered details.

    Feel free to tweak the parameters or refine the geometry functions as needed!

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