@specy/liquid-glass
Version:
A Three.js powered library to make apple's liquid with glass effect
1 lines • 4.1 kB
Source Map (JSON)
{"version":3,"sources":["../src/PillGeometry.ts"],"sourcesContent":["import {ExtrudeGeometry, Shape, type ExtrudeGeometryOptions} from 'three';\r\n\r\nexport class PillGeometry extends ExtrudeGeometry {\r\n /**\r\n * Creates an instance of PillGeometry.\r\n * @param {number} [width=1] - The width of the box.\r\n * @param {number} [height=1] - The height of the box.\r\n * @param {number} [depth=1] - The total depth (thickness) of the box.\r\n * @param {number} [segments=16] - The number of segments used to create the rounded edges.\r\n * @param {number} [radius=0.1] - The radius of the corners and edges.\r\n */\r\n constructor(\r\n width: number = 1,\r\n height: number = 1,\r\n depth: number = 0.5,\r\n segments: number = 16,\r\n radius: number = 0.1\r\n ) {\r\n // Clamp the radius to be no more than half the smallest dimension.\r\n const clampedRadius = Math.min(radius, width / 2, height / 2, depth / 2);\r\n\r\n // The depth of the central flat part of the box.\r\n const extrudeDepth = depth - 2 * clampedRadius;\r\n\r\n // Create the 2D shape (a rounded rectangle) for the extrusion.\r\n // IMPORTANT: Account for bevel size in the shape dimensions\r\n const shapeWidth = width - 2 * clampedRadius;\r\n const shapeHeight = height - 2 * clampedRadius;\r\n \r\n const shape = new Shape();\r\n const x = -shapeWidth / 2;\r\n const y = -shapeHeight / 2;\r\n\r\n // Create rounded rectangle shape\r\n shape.moveTo(x + clampedRadius, y);\r\n shape.lineTo(x + shapeWidth - clampedRadius, y);\r\n shape.quadraticCurveTo(x + shapeWidth, y, x + shapeWidth, y + clampedRadius);\r\n shape.lineTo(x + shapeWidth, y + shapeHeight - clampedRadius);\r\n shape.quadraticCurveTo(x + shapeWidth, y + shapeHeight, x + shapeWidth - clampedRadius, y + shapeHeight);\r\n shape.lineTo(x + clampedRadius, y + shapeHeight);\r\n shape.quadraticCurveTo(x, y + shapeHeight, x, y + shapeHeight - clampedRadius);\r\n shape.lineTo(x, y + clampedRadius);\r\n shape.quadraticCurveTo(x, y, x + clampedRadius, y);\r\n\r\n // Define the extrusion settings\r\n const extrudeSettings: ExtrudeGeometryOptions = {\r\n depth: extrudeDepth,\r\n bevelEnabled: true,\r\n bevelThickness: clampedRadius,\r\n bevelSize: clampedRadius,\r\n bevelOffset: 0,\r\n bevelSegments: segments\r\n };\r\n \r\n // Call the parent constructor\r\n super(shape, extrudeSettings);\r\n\r\n // DON'T call this.center() - we want the geometry positioned correctly\r\n // this.center();\r\n \r\n // Instead, manually translate to ensure proper bounds\r\n this.center();\r\n }\r\n}"],"mappings":"yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,kBAAAE,IAAA,eAAAC,EAAAH,GAAA,IAAAI,EAAkE,iBAErDF,EAAN,cAA2B,iBAAgB,CAS9C,YACIG,EAAgB,EAChBC,EAAiB,EACjBC,EAAgB,GAChBC,EAAmB,GACnBC,EAAiB,GACnB,CAEE,IAAMC,EAAgB,KAAK,IAAID,EAAQJ,EAAQ,EAAGC,EAAS,EAAGC,EAAQ,CAAC,EAGjEI,EAAeJ,EAAQ,EAAIG,EAI3BE,EAAaP,EAAQ,EAAIK,EACzBG,EAAcP,EAAS,EAAII,EAE3BI,EAAQ,IAAI,QACZC,EAAI,CAACH,EAAa,EAClBI,EAAI,CAACH,EAAc,EAGzBC,EAAM,OAAOC,EAAIL,EAAeM,CAAC,EACjCF,EAAM,OAAOC,EAAIH,EAAaF,EAAeM,CAAC,EAC9CF,EAAM,iBAAiBC,EAAIH,EAAYI,EAAGD,EAAIH,EAAYI,EAAIN,CAAa,EAC3EI,EAAM,OAAOC,EAAIH,EAAYI,EAAIH,EAAcH,CAAa,EAC5DI,EAAM,iBAAiBC,EAAIH,EAAYI,EAAIH,EAAaE,EAAIH,EAAaF,EAAeM,EAAIH,CAAW,EACvGC,EAAM,OAAOC,EAAIL,EAAeM,EAAIH,CAAW,EAC/CC,EAAM,iBAAiBC,EAAGC,EAAIH,EAAaE,EAAGC,EAAIH,EAAcH,CAAa,EAC7EI,EAAM,OAAOC,EAAGC,EAAIN,CAAa,EACjCI,EAAM,iBAAiBC,EAAGC,EAAGD,EAAIL,EAAeM,CAAC,EAGjD,IAAMC,EAA0C,CAC5C,MAAON,EACP,aAAc,GACd,eAAgBD,EAChB,UAAWA,EACX,YAAa,EACb,cAAeF,CACnB,EAGA,MAAMM,EAAOG,CAAe,EAM5B,KAAK,OAAO,CAChB,CACJ","names":["PillGeometry_exports","__export","PillGeometry","__toCommonJS","import_three","width","height","depth","segments","radius","clampedRadius","extrudeDepth","shapeWidth","shapeHeight","shape","x","y","extrudeSettings"]}