Skip to content
TheChatArchiveThe Chat Archive
Amazon Novaamazon-nova-experimental-chat-05-14Hugging 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. Amazon Nova Assistant

    Certainly! Below is a Blockbench plugin that generates a square with rounded corners. The plugin adds two new options: width and height. It uses a similar method to process the rounded corners and three cubes to create the square body.

    (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]];
      }
       
    
      // Storage for remembering previous values
      let savedValues = {
        width: 4,
        height: 2,
        cornerRadius: 1,
        center: [8, 8, 8],
        axis: 'y'
      };
    
      // UI
      function openDialog() {
        const dlg = new Dialog({
          title: 'Square with Rounded Corners Generator',
          id: 'square_rounded_corners_generator',
          form: {
            width: { label: 'Width', type: 'number', value: savedValues.width },
            height: { label: 'Height', 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: 'Axis', type: 'select', options: { y: 'Y', x: 'X', z: 'Z' }, value: savedValues.axis }
          },
          lines: [
            '<p>Generates a square with rounded corners.</p>',
            '<p>Uses Width, Height, and Corner Radius parameters.</p>'
          ],
          onConfirm(form) {
            const width = parseFloat(form.width);
            const height = parseFloat(form.height);
            const cornerRadius = parseFloat(form.cornerRadius);
            const axis = form.axis || 'y';
            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 positive', 2000);
            if (cornerRadius >= width / 2 || cornerRadius >= height / 2) {
              return Blockbench.showQuickMessage('Corner Radius must be smaller than half of Width and Height', 3000);
            }
           
    
            // Save values for next time
            savedValues = {
              width,
              height,
              cornerRadius,
              center: center.slice(),
              axis
            };
    
            generateSquare({
              width,
              height,
              cornerRadius,
              axis,
              center
            });
    
            dlg.hide();
          }
        });
    
        dlg.show();
      }
    
      // Main generator
      function generateSquare(opts) {
        const { width, height, cornerRadius, axis, center } = opts;
        const halfWidth = width / 2;
        const halfHeight = height / 2;
       
    
        Undo.initEdit({ outliner: true, elements: [], selection: true });
    
        // Create a group with default name (no explicit name)
        const group = new Group().init();
       
    
        // Generate the main body of the square
        const bodyFrom = [center[0] - halfWidth, center[1] - halfHeight, center[2] - cornerRadius];
        const bodyTo = [center[0] + halfWidth, center[1] + halfHeight, center[2] + cornerRadius];
        new Cube({ from: bodyFrom, to: bodyTo }).addTo(group).init();
       
    
        // Generate rounded corners
        const cornerSize = cornerRadius * 2;
        const cornerFrom = [-cornerRadius, -cornerRadius, -cornerRadius];
        const cornerTo = [cornerRadius, cornerRadius, cornerRadius];
       
    
        // Top-left corner
        let cornerPosition = [center[0] - halfWidth + cornerRadius, center[1] + halfHeight - cornerRadius, center[2]];
        let rotatedCorner = rotateAABB90(cornerFrom, cornerTo, cornerPosition, axis, 0);
        new Cube({ from: rotatedCorner.from, to: rotatedCorner.to }).addTo(group).init();
       
    
        // Top-right corner
        cornerPosition = [center[0] + halfWidth - cornerRadius, center[1] + halfHeight - cornerRadius, center[2]];
        rotatedCorner = rotateAABB90(cornerFrom, cornerTo, cornerPosition, axis, 0);
        new Cube({ from: rotatedCorner.from, to: rotatedCorner.to }).addTo(group).init();
       
    
        // Bottom-left corner
        cornerPosition = [center[0] - halfWidth + cornerRadius, center[1] - halfHeight + cornerRadius, center[2]];
        rotatedCorner = rotateAABB90(cornerFrom, cornerTo, cornerPosition, axis, 0);
        new Cube({ from: rotatedCorner.from, to: rotatedCorner.to }).addTo(group).init();
       
    
        // Bottom-right corner
        cornerPosition = [center[0] + halfWidth - cornerRadius, center[1] - halfHeight + cornerRadius, center[2]];
        rotatedCorner = rotateAABB90(cornerFrom, cornerTo, cornerPosition, axis, 0);
        new Cube({ from: rotatedCorner.from, to: rotatedCorner.to }).addTo(group).init();
       
    
        Canvas.updateAll();
        group.openUp().select();
    
        Undo.finishEdit('Generated square with rounded corners', { outliner: true, elements: selected, selection: true });
        Blockbench.showMessage(
          `Generated square with rounded corners (Width=${width.toFixed(3)}, Height=${height.toFixed(3)}, Corner Radius=${cornerRadius})`,
          'sidebar'
        );
      }
    
      // Plugin registration
      Plugin.register('square_rounded_corners', {
        title: 'Square with Rounded Corners',
        icon: 'square',
        author: 'YourName',
        description: 'Generates a square with rounded corners.',
        version: '1.0',
        min_version: '3.0.2',
        variant: 'both',
        onload() {
          this.action = new Action('generate_square_rounded_corners', {
            name: 'Generate Square with Rounded Corners',
            description: 'Generates a square with rounded corners.',
            icon: 'square',
            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();
        }
      });
    })();
    

    Explanation:

    1. UI Dialog:

      • Added width, height, and cornerRadius fields to the dialog.
      • Added validation to ensure the corner radius is smaller than half of the width and height.
    2. Main Generator (generateSquare function):

      • Creates the main body of the square using a single cube.
      • Creates rounded corners using four smaller cubes, each positioned at the corners of the square.
      • Ensures the corner cubes are correctly positioned and sized based on the provided cornerRadius.
    3. Plugin Registration:

      • Registers the plugin with the name "Square with Rounded Corners".
      • Adds an action to the menu bar to open the dialog when clicked.

    This plugin will generate a square with rounded corners when the action is triggered, using the specified width, height, and corner radius.

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