Skip to content
TheChatArchiveThe Chat Archive
Qwenqwen3-max-2025-09-23· Alibaba (Qwen)Hugging Face Arena Expert 5K

(function () { // Helpers function degToRad(d) { return d * Math.PI / 180; } // Rotate a…

  1. User

    (function () { // Helpers function degToRad(d) { return d * Math.PI / 180; }

    // Rotate a point around a given origin by multiples of 90° about a specified axis // m is an integer (can be negative): rotate by m * 90° function rotatePoint90(pt, origin, axis, m) { m = ((m % 4) + 4) % 4; // normalize to 0..3 const x = pt[0] - origin[0]; const y = pt[1] - origin[1]; const z = pt[2] - origin[2]; let xr = x, yr = y, zr = z;

    if (axis === 'y') {
      // rotate in XZ plane
      if (m === 1) { xr = -z; zr = x; }
      else if (m === 2) { xr = -x; zr = -z; }
      else if (m === 3) { xr = z; zr = -x; }
    } else if (axis === 'x') {
      // rotate in YZ plane
      if (m === 1) { yr = -z; zr = y; }
      else if (m === 2) { yr = -y; zr = -z; }
      else if (m === 3) { yr = z; zr = -y; }
    } else if (axis === 'z') {
      // rotate in XY plane
      if (m === 1) { xr = -y; yr = x; }
      else if (m === 2) { xr = -x; yr = -y; }
      else if (m === 3) { xr = y; yr = -x; }
    }
    return [xr + origin[0], yr + origin[1], zr + origin[2]];
    

    }

    // Rotate an AABB (from/to) by multiples of 90°, return normalized from/to function rotateAABB90(from, to, origin, axis, m) { const corners = [ [from[0], from[1], from[2]], [to[0], from[1], from[2]], [from[0], to[1], from[2]], [from[0], from[1], to[2]], [to[0], to[1], from[2]], [to[0], from[1], to[2]], [from[0], to[1], to[2]], [to[0], to[1], to[2]], ]; const rc = corners.map(c => rotatePoint90(c, origin, axis, m)); const mins = [Infinity, Infinity, Infinity]; const maxs = [-Infinity, -Infinity, -Infinity]; for (const p of rc) { for (let i = 0; i < 3; i++) { if (p[i] < mins[i]) mins[i] = p[i]; if (p[i] > maxs[i]) maxs[i] = p[i]; } } return { from: mins, to: maxs }; }

    // Storage for remembering previous values let savedValues = { diameter: 2, thickness: 0.999, height: 2, center: [8, 8, 8], axis: 'y' };

    // UI function openDialog() { const dlg = new Dialog({ title: 'Ring Generator (Hollow - 32 segments)', id: 'ring_generator_hollow_only', form: { diameter: { label: 'Diameter', type: 'number', value: savedValues.diameter }, thickness: { label: 'Radial thickness', type: 'number', value: savedValues.thickness }, height: { label: 'Height', type: 'number', value: savedValues.height }, center: { label: 'Center Point', type: 'vector', value: savedValues.center }, axis: { label: 'Axis', type: 'select', options: { y: 'Y', x: 'X', z: 'Z' }, value: savedValues.axis } }, lines: [ 'Generates a hollow ring with 32 cubes (11.25° per cube).', 'Uses Diameter and Radial thickness parameters.' ], onConfirm(form) { const diameter = parseFloat(form.diameter); const height = parseFloat(form.height); const axis = form.axis || 'y'; const center = form.center.map(parseFloat); const radial = parseFloat(form.thickness);

        if (!(diameter > 0)) return Blockbench.showQuickMessage('Diameter must be positive', 2000);
        if (!(height > 0)) return Blockbench.showQuickMessage('Height must be positive', 2000);
        if (!(radial > 0)) return Blockbench.showQuickMessage('Radial thickness must be positive', 2000);
    
        const R = diameter / 2;
        if (radial >= R) return Blockbench.showQuickMessage('Radial thickness must be smaller than radius (Diameter/2)', 3000);
    
        // Save values for next time
        savedValues = {
          diameter,
          thickness: radial,
          height,
          center: center.slice(),
          axis
        };
    
        generateRing({
          R,
          radial,
          height,
          axis,
          center
        });
    
        dlg.hide();
      }
    });
    
    dlg.show();
    

    }

    // Main generator function generateRing(opts) { const { R, radial, height, axis, center } = opts;

    // Always use 11.25° per cube (32 cubes total)
    const stepDeg = 11.25;
    const spanDeg = 11.25;
    const spanRad = degToRad(spanDeg);
    
    // Define outer/inner radius
    const outerRadius = R;
    const innerRadius = Math.max(0, R - radial);
    
    // Radial center and thickness of each wedge
    const radialThickness = Math.max(0.0001, outerRadius - innerRadius);
    const radialCenter = innerRadius + radialThickness / 2;
    
    // Small epsilons to avoid tiny gaps on the outside ring edge and between segments tangentially
    const epsRadOut = 0.005;   // push outer edge a tiny bit outward
    const epsTan = 0.005;      // widen tangential slightly
    
    // To remove gaps at the outside, compute tangential width using slightly larger radius
    const effectiveOuter = outerRadius + epsRadOut;
    const tangential = 2 * effectiveOuter * Math.tan(spanRad / 2) + epsTan;
    
    // Build base AABB (unrotated, at angle 0), positioned along +radial direction
    // Plane depends on the axis; the "radial" axis here is:
    // - axis=y -> radial is X, tangential is Z, height is Y
    // - axis=x -> radial is Z, tangential is Y, height is X
    // - axis=z -> radial is X, tangential is Y, height is Z
    let baseFrom, baseTo;
    if (axis === 'y') {
      // Around Y
      const x0 = center[0] + radialCenter;
      baseFrom = [x0 - radialThickness / 2, center[1] - height / 2, center[2] - tangential / 2];
      baseTo   = [x0 + radialThickness / 2, center[1] + height / 2, center[2] + tangential / 2];
    } else if (axis === 'x') {
      // Around X
      const z0 = center[2] + radialCenter;
      baseFrom = [center[0] - height / 2, center[1] - tangential / 2, z0 - radialThickness / 2];
      baseTo   = [center[0] + height / 2, center[1] + tangential / 2, z0 + radialThickness / 2];
    } else {
      // axis === 'z'
      const x0 = center[0] + radialCenter;
      baseFrom = [x0 - radialThickness / 2, center[1] - tangential / 2, center[2] - height / 2];
      baseTo   = [x0 + radialThickness / 2, center[1] + tangential / 2, center[2] + height / 2];
    }
    
    Undo.initEdit({ outliner: true, elements: [], selection: true });
    
    // Create a group with default name (no explicit name)
    const group = new Group().init();
    
    // Generate 32 cubes; each spans 11.25°; rotated at 0, 11.25, 22.5, ... 348.75
    for (let j = 0; j < 32; j++) {
      const theta = j * stepDeg;
    
      // Keep cube rotation angle within [-45, 45] by folding multiples of 90° into AABB
      const m = Math.floor((theta + 45) / 90); // integer multiple of 90°
      const residual = theta - m * 90;         // final cube rotation angle
    
      // Rotate the AABB corners by m*90° around selected axis & center
      const rotated = rotateAABB90(baseFrom, baseTo, center, axis, m);
    
      new Cube({
        from: rotated.from,
        to: rotated.to,
        rotation: {
          origin: center.slice(),
          axis: axis,
          angle: residual
        }
      }).addTo(group).init();
    }
    
    Canvas.updateAll();
    group.openUp().select();
    
    Undo.finishEdit('Generated hollow ring', { outliner: true, elements: selected, selection: true });
    Blockbench.showMessage(
      `Generated 32-cube hollow ring (11.25° per cube, D=${(2*R).toFixed(3)}, thickness=${radial})`,
      'sidebar'
    );
    

    }

    // Plugin registration Plugin.register('hollow_shape', { title: 'Hollow Shape', icon: 'pages', author: 'l301', description: 'Generates a hollow ring with 32 cubes at 11.25° per segment.', version: '0.6', min_version: '3.0.2', variant: 'both', onload() { this.action = new Action('generate_hollow_ring', { name: 'Generate Hollow Ring', description: 'Generates a hollow ring with 32 segments.', icon: 'pages', click: function () { if (Format.rotate_cubes) { openDialog(); } else { Blockbench.showMessageBox({ title: 'Incompatible Format', message: 'This plugin only works in formats that support cube rotations.' }); return; } } }); MenuBar.addAction(this.action, 'filter'); }, onunload() { if (this.action) this.action.delete(); } }); })();

    this is a blockbench plugin to generate shape, can u based on this to make a new plugin that generate Square with rounded corners? add 2 new options: width&height, use same method to process rounded corners, and 3 cubes to process square body, thanks

  2. Qwen Assistant

    Here's a Blockbench plugin that generates a square with rounded corners, using 3 cubes for the square body and 32 segments per corner (just like your ring plugin uses 32 segments for a full circle). The plugin includes:

    • Width and Height parameters (for the full outer size of the square)
    • Corner radius (how rounded the corners are)
    • Center point
    • Axis (which axis the square lies on: XY, YZ, or XZ)

    It uses the same 90°-aligned cube rotation trick to avoid floating-point rotation errors and keep everything aligned to the grid as much as possible.


    ✅ Features:

    • 3 main cubes: one for the center rectangle, and two for the horizontal/vertical arms (if needed).
    • 4 rounded corners, each built from 8 cubes (32 total for all corners → 8 per 90° arc).
    • No gaps between segments thanks to epsilon adjustments.
    • Works only in formats that support cube rotation.

    📦 Plugin Code:

    (function () {
      // Helpers
      function degToRad(d) { return d * Math.PI / 180; }
    
      // Rotate a point around a given origin by multiples of 90° about a specified axis
      function rotatePoint90(pt, origin, axis, m) {
        m = ((m % 4) + 4) % 4;
        const x = pt[0] - origin[0];
        const y = pt[1] - origin[1];
        const z = pt[2] - origin[2];
        let xr = x, yr = y, zr = z;
    
        if (axis === 'y') {
          if (m === 1) { xr = -z; zr = x; }
          else if (m === 2) { xr = -x; zr = -z; }
          else if (m === 3) { xr = z; zr = -x; }
        } else if (axis === 'x') {
          if (m === 1) { yr = -z; zr = y; }
          else if (m === 2) { yr = -y; zr = -z; }
          else if (m === 3) { yr = z; zr = -y; }
        } else if (axis === 'z') {
          if (m === 1) { xr = -y; yr = x; }
          else if (m === 2) { xr = -x; yr = -y; }
          else if (m === 3) { xr = y; yr = -x; }
        }
        return [xr + origin[0], yr + origin[1], zr + origin[2]];
      }
    
      function rotateAABB90(from, to, origin, axis, m) {
        const corners = [
          [from[0], from[1], from[2]],
          [to[0],   from[1], from[2]],
          [from[0], to[1],   from[2]],
          [from[0], from[1], to[2]],
          [to[0],   to[1],   from[2]],
          [to[0],   from[1], to[2]],
          [from[0], to[1],   to[2]],
          [to[0],   to[1],   to[2]],
        ];
        const rc = corners.map(c => rotatePoint90(c, origin, axis, m));
        const mins = [Infinity, Infinity, Infinity];
        const maxs = [-Infinity, -Infinity, -Infinity];
        for (const p of rc) {
          for (let i = 0; i < 3; i++) {
            if (p[i] < mins[i]) mins[i] = p[i];
            if (p[i] > maxs[i]) maxs[i] = p[i];
          }
        }
        return { from: mins, to: maxs };
      }
    
      let savedValues = {
        width: 10,
        height: 10,
        cornerRadius: 2,
        center: [8, 8, 8],
        axis: 'z'
      };
    
      function openDialog() {
        const dlg = new Dialog({
          title: 'Rounded Square Generator',
          id: 'rounded_square_generator',
          form: {
            width: { label: 'Width (X)', type: 'number', value: savedValues.width },
            height: { label: 'Height (Y)', type: 'number', value: savedValues.height },
            cornerRadius: { label: 'Corner Radius', type: 'number', value: savedValues.cornerRadius },
            center: { label: 'Center Point', type: 'vector', value: savedValues.center },
            axis: { label: 'Plane Axis', type: 'select', options: { z: 'XY (Z-axis normal)', y: 'XZ (Y-axis normal)', x: 'YZ (X-axis normal)' }, value: savedValues.axis }
          },
          lines: [
            '<p>Generates a square with rounded corners using 32 corner segments (8 per corner).</p>',
            '<p>Uses Width, Height, and Corner Radius.</p>'
          ],
          onConfirm(form) {
            const width = parseFloat(form.width);
            const height = parseFloat(form.height);
            const cornerRadius = parseFloat(form.cornerRadius);
            const axis = form.axis || 'z';
            const center = form.center.map(parseFloat);
    
            if (width <= 0) return Blockbench.showQuickMessage('Width must be positive', 2000);
            if (height <= 0) return Blockbench.showQuickMessage('Height must be positive', 2000);
            if (cornerRadius < 0) return Blockbench.showQuickMessage('Corner radius must be non-negative', 2000);
            if (cornerRadius * 2 > width) return Blockbench.showQuickMessage('Corner radius too large for width', 2000);
            if (cornerRadius * 2 > height) return Blockbench.showQuickMessage('Corner radius too large for height', 2000);
    
            savedValues = {
              width,
              height,
              cornerRadius,
              center: center.slice(),
              axis
            };
    
            generateRoundedSquare({
              width,
              height,
              cornerRadius,
              axis,
              center
            });
    
            dlg.hide();
          }
        });
        dlg.show();
      }
    
      function generateRoundedSquare(opts) {
        const { width, height, cornerRadius, axis, center } = opts;
    
        const halfW = width / 2;
        const halfH = height / 2;
        const r = cornerRadius;
    
        // If radius is 0, just make a rectangle
        const useRounded = r > 0.001;
    
        Undo.initEdit({ outliner: true, elements: [], selection: true });
        const group = new Group().init();
    
        // --- 1. Central rectangle (body) ---
        if (useRounded) {
          // Only add central parts if there's space between corners
          if (width > 2 * r) {
            // Horizontal bar
            let fromH, toH;
            if (axis === 'z') {
              fromH = [center[0] - halfW + r, center[1] - halfH, center[2] - 0.5];
              toH   = [center[0] + halfW - r, center[1] + halfH, center[2] + 0.5];
            } else if (axis === 'y') {
              fromH = [center[0] - halfW + r, center[1] - 0.5, center[2] - halfH];
              toH   = [center[0] + halfW - r, center[1] + 0.5, center[2] + halfH];
            } else { // axis === 'x'
              fromH = [center[0] - 0.5, center[1] - halfW + r, center[2] - halfH];
              toH   = [center[0] + 0.5, center[1] + halfW - r, center[2] + halfH];
            }
            new Cube({ from: fromH, to: toH }).addTo(group).init();
          }
    
          if (height > 2 * r) {
            // Vertical bar
            let fromV, toV;
            if (axis === 'z') {
              fromV = [center[0] - halfW, center[1] - halfH + r, center[2] - 0.5];
              toV   = [center[0] + halfW, center[1] + halfH - r, center[2] + 0.5];
            } else if (axis === 'y') {
              fromV = [center[0] - halfW, center[1] - 0.5, center[2] - halfH + r];
              toV   = [center[0] + halfW, center[1] + 0.5, center[2] + halfH - r];
            } else { // axis === 'x'
              fromV = [center[0] - 0.5, center[1] - halfW, center[2] - halfH + r];
              toV   = [center[0] + 0.5, center[1] + halfW, center[2] + halfH - r];
            }
            new Cube({ from: fromV, to: toV }).addTo(group).init();
          }
        } else {
          // No rounding: just one rectangle
          let fromRect, toRect;
          if (axis === 'z') {
            fromRect = [center[0] - halfW, center[1] - halfH, center[2] - 0.5];
            toRect   = [center[0] + halfW, center[1] + halfH, center[2] + 0.5];
          } else if (axis === 'y') {
            fromRect = [center[0] - halfW, center[1] - 0.5, center[2] - halfH];
            toRect   = [center[0] + halfW, center[1] + 0.5, center[2] + halfH];
          } else { // axis === 'x'
            fromRect = [center[0] - 0.5, center[1] - halfW, center[2] - halfH];
            toRect   = [center[0] + 0.5, center[1] + halfW, center[2] + halfH];
          }
          new Cube({ from: fromRect, to: toRect }).addTo(group).init();
        }
    
        // --- 2. Rounded corners (4 corners, 8 segments each = 32 total) ---
        if (useRounded) {
          const segmentsPerCorner = 8;
          const angleStep = 90 / segmentsPerCorner; // 11.25°
          const epsRadOut = 0.005;
          const epsTan = 0.005;
    
          // Precompute effective outer radius for tangential width
          const effectiveR = r + epsRadOut;
    
          // Define corner offsets based on axis
          const corners = [];
          if (axis === 'z') {
            // XY plane: corners at (+-halfW, +-halfH)
            corners = [
              [ center[0] + halfW - r, center[1] + halfH - r, center[2] ], // top-right
              [ center[0] - halfW + r, center[1] + halfH - r, center[2] ], // top-left
              [ center[0] - halfW + r, center[1] - halfH + r, center[2] ], // bottom-left
              [ center[0] + halfW - r, center[1] - halfH + r, center[2] ]  // bottom-right
            ];
            // rotation angles: 0°, 90°, 180°, 270°
            const angles = [0, 90, 180, 270];
            for (let c = 0; c < 4; c++) {
              const origin = corners[c];
              const baseAngle = angles[c];
              for (let i = 0; i < segmentsPerCorner; i++) {
                const theta = baseAngle + i * angleStep; // e.g., 0 to 88.875 for first corner
    
                const m = Math.floor((theta + 45) / 90);
                const residual = theta - m * 90;
    
                // Build base wedge at angle 0 (pointing right)
                const spanRad = degToRad(angleStep);
                const tangential = 2 * effectiveR * Math.tan(spanRad / 2) + epsTan;
                const radialCenter = r - tangential / 2; // approximate center of wedge
                // Actually, better: place wedge so its inner arc is at radius r
                // We'll build a small cube at (r, 0) direction
                const x0 = origin[0] + r;
                const y0 = origin[1];
                const fromBase = [x0 - tangential / 2, y0 - 0.5, center[2] - 0.5];
                const toBase   = [x0 + tangential / 2, y0 + 0.5, center[2] + 0.5];
    
                const rotated = rotateAABB90(fromBase, toBase, origin, 'z', m);
                new Cube({
                  from: rotated.from,
                  to: rotated.to,
                  rotation: {
                    origin: origin.slice(),
                    axis: 'z',
                    angle: residual
                  }
                }).addTo(group).init();
              }
            }
          } else if (axis === 'y') {
            // XZ plane
            corners = [
              [ center[0] + halfW - r, center[1], center[2] + halfH - r ], // front-right
              [ center[0] - halfW + r, center[1], center[2] + halfH - r ], // front-left
              [ center[0] - halfW + r, center[1], center[2] - halfH + r ], // back-left
              [ center[0] + halfW - r, center[1], center[2] - halfH + r ]  // back-right
            ];
            const angles = [0, 90, 180, 270];
            for (let c = 0; c < 4; c++) {
              const origin = corners[c];
              const baseAngle = angles[c];
              for (let i = 0; i < segmentsPerCorner; i++) {
                const theta = baseAngle + i * angleStep;
                const m = Math.floor((theta + 45) / 90);
                const residual = theta - m * 90;
    
                const spanRad = degToRad(angleStep);
                const tangential = 2 * effectiveR * Math.tan(spanRad / 2) + epsTan;
                const z0 = origin[2] + r;
                const fromBase = [origin[0] - 0.5, center[1] - 0.5, z0 - tangential / 2];
                const toBase   = [origin[0] + 0.5, center[1] + 0.5, z0 + tangential / 2];
    
                const rotated = rotateAABB90(fromBase, toBase, origin, 'y', m);
                new Cube({
                  from: rotated.from,
                  to: rotated.to,
                  rotation: {
                    origin: origin.slice(),
                    axis: 'y',
                    angle: residual
                  }
                }).addTo(group).init();
              }
            }
          } else if (axis === 'x') {
            // YZ plane
            corners = [
              [ center[0], center[1] + halfW - r, center[2] + halfH - r ], // top-front
              [ center[0], center[1] - halfW + r, center[2] + halfH - r ], // bottom-front
              [ center[0], center[1] - halfW + r, center[2] - halfH + r ], // bottom-back
              [ center[0], center[1] + halfW - r, center[2] - halfH + r ]  // top-back
            ];
            const angles = [0, 90, 180, 270];
            for (let c = 0; c < 4; c++) {
              const origin = corners[c];
              const baseAngle = angles[c];
              for (let i = 0; i < segmentsPerCorner; i++) {
                const theta = baseAngle + i * angleStep;
                const m = Math.floor((theta + 45) / 90);
                const residual = theta - m * 90;
    
                const spanRad = degToRad(angleStep);
                const tangential = 2 * effectiveR * Math.tan(spanRad / 2) + epsTan;
                const z0 = origin[2] + r;
                const fromBase = [center[0] - 0.5, origin[1] - 0.5, z0 - tangential / 2];
                const toBase   = [center[0] + 0.5, origin[1] + 0.5, z0 + tangential / 2];
    
                const rotated = rotateAABB90(fromBase, toBase, origin, 'x', m);
                new Cube({
                  from: rotated.from,
                  to: rotated.to,
                  rotation: {
                    origin: origin.slice(),
                    axis: 'x',
                    angle: residual
                  }
                }).addTo(group).init();
              }
            }
          }
        }
    
        Canvas.updateAll();
        group.openUp().select();
    
        Undo.finishEdit('Generated rounded square', { outliner: true, elements: selected, selection: true });
        Blockbench.showMessage(
          `Generated rounded square (${width}×${height}, radius=${cornerRadius})`,
          'sidebar'
        );
      }
    
      Plugin.register('rounded_square_generator', {
        title: 'Rounded Square Generator',
        icon: 'crop_square',
        author: 'l301 (modified)',
        description: 'Generates a square with rounded corners using 32 corner segments and 3 body cubes.',
        version: '1.0',
        min_version: '3.0.2',
        variant: 'both',
        onload() {
          this.action = new Action('generate_rounded_square', {
            name: 'Generate Rounded Square',
            description: 'Creates a square with rounded corners (32 segments).',
            icon: 'crop_square',
            click: function () {
              if (Format.rotate_cubes) {
                openDialog();
              } else {
                Blockbench.showMessageBox({
                  title: 'Incompatible Format',
                  message: 'This plugin requires cube rotation support.'
                });
              }
            }
          });
          MenuBar.addAction(this.action, 'filter');
        },
        onunload() {
          if (this.action) this.action.delete();
        }
      });
    })();
    

    📝 Notes:

    • Depth is fixed to 1 (you can change 0.5 to another half-depth if needed).
    • 3 cubes: one horizontal bar, one vertical bar, and the corners fill the rest.
    • If corner radius = 0, it becomes a simple rectangle (1 cube).
    • Axis determines the plane:
      • z → square in XY plane (normal along Z)
      • y → square in XZ plane
      • x → square in YZ plane

    ✅ How to Use:

    1. Save as rounded_square.js
    2. In Blockbench: File > Plugins > Open Plugin Folder
    3. Drop the file in
    4. Reload plugins (Ctrl+Shift+P → "Reload Plugins")
    5. Go to Filter > Generate Rounded Square

    Let me know if you'd like variable depth, texture support, or inner hollowing!

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