1 line
8.8 KiB
Plaintext
1 line
8.8 KiB
Plaintext
|
|
{"version":3,"file":"ParametricGeometries.cjs","sources":["../../src/geometries/ParametricGeometries.js"],"sourcesContent":["import { Curve, Vector3 } from 'three'\nimport { ParametricGeometry } from './ParametricGeometry'\n\nclass TubeGeometry extends ParametricGeometry {\n constructor(path, segments = 64, radius = 1, segmentsRadius = 8, closed = false) {\n const numpoints = segments + 1\n\n const frames = path.computeFrenetFrames(segments, closed),\n tangents = frames.tangents,\n normals = frames.normals,\n binormals = frames.binormals\n\n const position = new Vector3()\n\n function ParametricTube(u, v, target) {\n v *= 2 * Math.PI\n\n const i = Math.floor(u * (numpoints - 1))\n\n path.getPointAt(u, position)\n\n const normal = normals[i]\n const binormal = binormals[i]\n\n const cx = -radius * Math.cos(v) // TODO: Hack: Negating it so it faces outside.\n const cy = radius * Math.sin(v)\n\n position.x += cx * normal.x + cy * binormal.x\n position.y += cx * normal.y + cy * binormal.y\n position.z += cx * normal.z + cy * binormal.z\n\n target.copy(position)\n }\n\n super(ParametricTube, segments, segmentsRadius)\n\n // proxy internals\n\n this.tangents = tangents\n this.normals = normals\n this.binormals = binormals\n\n this.path = path\n this.segments = segments\n this.radius = radius\n this.segmentsRadius = segmentsRadius\n this.closed = closed\n }\n}\n\n/**\n * Experimental primitive geometry creation using Surface Parametric equations\n */\nconst ParametricGeometries = {\n klein: function (v, u, target) {\n u *= Math.PI\n v *= 2 * Math.PI\n\n u = u * 2\n let x, z\n if (u < Math.PI) {\n x = 3 * Math.cos(u) * (1 + Math.sin(u)) + 2 * (1 - Math.cos(u) / 2) * Math.cos(u) * Math.cos(v)\n z = -8 * Math.sin(u) - 2 * (1 - Math.cos(u) / 2) * Math.sin(u) * Math.cos(v)\n } else {\n x = 3 * Math.cos(u) * (1 + Math.sin(u)) + 2 * (1 - Math.cos(u) / 2) * Math.cos(v + Math.PI)\n z = -8 * Math.sin(u)\n }\n\n const y = -2 * (1 - Math.cos(u) / 2) * Math.sin(v)\n\n target.set(x, y, z)\n },\n\n plane: function (width, height) {\n return function (u, v, target) {\n const x = u * width\n const y = 0\n const z = v * height\n\n target.set(x, y, z)\n }\n },\n\n mobius: function (u, t, target) {\n // flat mobius strip\n // http://www.wolframalpha.com/input/?i=M%C3%B6bius+strip+parametric+equations&lk=1&a=ClashPrefs_*Surface.MoebiusStrip.SurfaceProperty.ParametricEquations-\n u = u - 0.5\n const v = 2 * Math.PI * t\n\n const a = 2\n\n const x = Math.cos(v) * (a + u * Math.cos(v / 2))\n const y = Math.sin(v) * (a + u * Math.cos(v / 2))\n const z = u * Math.sin(v / 2)\n\n target.set(x, y, z)\n },\n\n mobius3d: function (u, t, target) {\n // volumetric mobius strip\n\n u *= Math.PI\n t *= 2 * Math.PI\n\n u = u * 2\n const phi = u / 2\n const major = 2.25,\n a = 0.125,\n b = 0.65\n\n let x = a * Math.cos(t) * Math.cos(phi) - b * Math.sin(t) * Math.sin(phi)\n const z = a * Math.cos(t) * Math.sin(phi) + b * Math.sin(t) * Math.cos(phi)\n const y = (major + x) * Math.sin(u)\n x = (major + x) * Math.cos(u)\n\n target.set(x, y, z)\n },\n TubeGeometry,\n TorusKnotGeometry: class TorusKnotGeometry extends TubeGeometry {\n constructor(radius = 200, tube = 40, segmentsT = 64, segmentsR = 8, p = 2, q = 3) {\n class TorusKnotCurve extends Curve {\n getPoint(t, optionalTarget = new Vector3()) {\n const point = optionalTarget\n\n t *= Math.PI * 2\n\n const r = 0.5\n\n const x = (1 + r * Math.cos(q * t)) * Math.cos(p * t)\n const y = (1 + r * Math.cos(q * t)) * Math.sin(p * t)\n const z = r * Math.sin(q * t)\n\n return point.set(x, y, z).multiplyScalar(radius)\n }\n }\n\n const segments = segmentsT\n const radiusSegments = segmentsR\n const extrudePath = new TorusKnotCurve()\n\n super(extru
|