import { CylinderGeometry, DoubleSide, Matrix4, Mesh, MeshDepthMaterial, MeshDistanceMaterial, MeshStandardMaterial, RGBADepthPacking, ShaderChunk, ShaderLib, UniformsUtils, Vector2, Vector3 } from "/_nuxt/node_modules/.cache/vite/client/deps/chunk-KHL3VXVA.js?v=e4f18c29"; // ../../node_modules/troika-three-utils/dist/troika-three-utils.esm.js var voidMainRegExp = /\bvoid\s+main\s*\(\s*\)\s*{/g; function expandShaderIncludes(source) { const pattern = /^[ \t]*#include +<([\w\d./]+)>/gm; function replace(match, include) { let chunk = ShaderChunk[include]; return chunk ? expandShaderIncludes(chunk) : match; } return source.replace(pattern, replace); } var _lut = []; for (let i = 0; i < 256; i++) { _lut[i] = (i < 16 ? "0" : "") + i.toString(16); } function generateUUID() { const d0 = Math.random() * 4294967295 | 0; const d1 = Math.random() * 4294967295 | 0; const d2 = Math.random() * 4294967295 | 0; const d3 = Math.random() * 4294967295 | 0; const uuid = _lut[d0 & 255] + _lut[d0 >> 8 & 255] + _lut[d0 >> 16 & 255] + _lut[d0 >> 24 & 255] + "-" + _lut[d1 & 255] + _lut[d1 >> 8 & 255] + "-" + _lut[d1 >> 16 & 15 | 64] + _lut[d1 >> 24 & 255] + "-" + _lut[d2 & 63 | 128] + _lut[d2 >> 8 & 255] + "-" + _lut[d2 >> 16 & 255] + _lut[d2 >> 24 & 255] + _lut[d3 & 255] + _lut[d3 >> 8 & 255] + _lut[d3 >> 16 & 255] + _lut[d3 >> 24 & 255]; return uuid.toUpperCase(); } var assign = Object.assign || function() { let target = arguments[0]; for (let i = 1, len = arguments.length; i < len; i++) { let source = arguments[i]; if (source) { for (let prop in source) { if (Object.prototype.hasOwnProperty.call(source, prop)) { target[prop] = source[prop]; } } } } return target; }; var epoch = Date.now(); var CONSTRUCTOR_CACHE = /* @__PURE__ */ new WeakMap(); var SHADER_UPGRADE_CACHE = /* @__PURE__ */ new Map(); var materialInstanceId = 1e10; function createDerivedMaterial(baseMaterial, options) { const optionsKey = getKeyForOptions(options); let ctorsByDerivation = CONSTRUCTOR_CACHE.get(baseMaterial); if (!ctorsByDerivation) { CONSTRUCTOR_CACHE.set(baseMaterial, ctorsByDerivation = /* @__PURE__ */ Object.create(null)); } if (ctorsByDerivation[optionsKey]) { return new ctorsByDerivation[optionsKey](); } const privateBeforeCompileProp = `_onBeforeCompile${optionsKey}`; const onBeforeCompile = function(shaderInfo, renderer) { baseMaterial.onBeforeCompile.call(this, shaderInfo, renderer); const cacheKey = this.customProgramCacheKey() + "|" + shaderInfo.vertexShader + "|" + shaderInfo.fragmentShader; let upgradedShaders = SHADER_UPGRADE_CACHE[cacheKey]; if (!upgradedShaders) { const upgraded = upgradeShaders(this, shaderInfo, options, optionsKey); upgradedShaders = SHADER_UPGRADE_CACHE[cacheKey] = upgraded; } shaderInfo.vertexShader = upgradedShaders.vertexShader; shaderInfo.fragmentShader = upgradedShaders.fragmentShader; assign(shaderInfo.uniforms, this.uniforms); if (options.timeUniform) { shaderInfo.uniforms[options.timeUniform] = { get value() { return Date.now() - epoch; } }; } if (this[privateBeforeCompileProp]) { this[privateBeforeCompileProp](shaderInfo); } }; const DerivedMaterial = function DerivedMaterial2() { return derive(options.chained ? baseMaterial : baseMaterial.clone()); }; const derive = function(base) { const derived = Object.create(base, descriptor); Object.defineProperty(derived, "baseMaterial", { value: baseMaterial }); Object.defineProperty(derived, "id", { value: materialInstanceId++ }); derived.uuid = generateUUID(); derived.uniforms = assign({}, base.uniforms, options.uniforms); derived.defines = assign({}, base.defines, options.defines); derived.defines[`TROIKA_DERIVED_MATERIAL_${optionsKey}`] = ""; derived.extensions = assign({}, base.extensions, options.extensions); derived._listeners = void 0; return derived; }; const descriptor = { constructor: { value: DerivedMaterial }, isDerivedMaterial: { value: true }, type: { get: () => baseMaterial.type, set: (value) => { baseMaterial.type = value; } }, isDerivedFrom: { writable: true, configurable: true, value: function(testMaterial) { const base = this.baseMaterial; return testMaterial === base || base.isDerivedMaterial && base.isDerivedFrom(testMaterial) || false; } }, customProgramCacheKey: { writable: true, configurable: true, value: function() { return baseMaterial.customProgramCacheKey() + "|" + optionsKey; } }, onBeforeCompile: { get() { return onBeforeCompile; }, set(fn) { this[privateBeforeCompileProp] = fn; } }, copy: { writable: true, configurable: true, value: function(source) { baseMaterial.copy.call(this, source); if (!baseMaterial.isShaderMaterial && !baseMaterial.isDerivedMaterial) { assign(this.extensions, source.extensions); assign(this.defines, source.defines); assign(this.uniforms, UniformsUtils.clone(source.uniforms)); } return this; } }, clone: { writable: true, configurable: true, value: function() { const newBase = new baseMaterial.constructor(); return derive(newBase).copy(this); } }, /** * Utility to get a MeshDepthMaterial that will honor this derived material's vertex * transformations and discarded fragments. */ getDepthMaterial: { writable: true, configurable: true, value: function() { let depthMaterial = this._depthMaterial; if (!depthMaterial) { depthMaterial = this._depthMaterial = createDerivedMaterial( baseMaterial.isDerivedMaterial ? baseMaterial.getDepthMaterial() : new MeshDepthMaterial({ depthPacking: RGBADepthPacking }), options ); depthMaterial.defines.IS_DEPTH_MATERIAL = ""; depthMaterial.uniforms = this.uniforms; } return depthMaterial; } }, /** * Utility to get a MeshDistanceMaterial that will honor this derived material's vertex * transformations and discarded fragments. */ getDistanceMaterial: { writable: true, configurable: true, value: function() { let distanceMaterial = this._distanceMaterial; if (!distanceMaterial) { distanceMaterial = this._distanceMaterial = createDerivedMaterial( baseMaterial.isDerivedMaterial ? baseMaterial.getDistanceMaterial() : new MeshDistanceMaterial(), options ); distanceMaterial.defines.IS_DISTANCE_MATERIAL = ""; distanceMaterial.uniforms = this.uniforms; } return distanceMaterial; } }, dispose: { writable: true, configurable: true, value() { const { _depthMaterial, _distanceMaterial } = this; if (_depthMaterial) _depthMaterial.dispose(); if (_distanceMaterial) _distanceMaterial.dispose(); baseMaterial.dispose.call(this); } } }; ctorsByDerivation[optionsKey] = DerivedMaterial; return new DerivedMaterial(); } function upgradeShaders(material, { vertexShader, fragmentShader }, options, key) { let { vertexDefs: vertexDefs2, vertexMainIntro, vertexMainOutro, vertexTransform: vertexTransform2, fragmentDefs: fragmentDefs2, fragmentMainIntro: fragmentMainIntro2, fragmentMainOutro, fragmentColorTransform, customRewriter, timeUniform } = options; vertexDefs2 = vertexDefs2 || ""; vertexMainIntro = vertexMainIntro || ""; vertexMainOutro = vertexMainOutro || ""; fragmentDefs2 = fragmentDefs2 || ""; fragmentMainIntro2 = fragmentMainIntro2 || ""; fragmentMainOutro = fragmentMainOutro || ""; if (vertexTransform2 || customRewriter) { vertexShader = expandShaderIncludes(vertexShader); } if (fragmentColorTransform || customRewriter) { fragmentShader = fragmentShader.replace( /^[ \t]*#include <((?:tonemapping|encodings|colorspace|fog|premultiplied_alpha|dithering)_fragment)>/gm, "\n//!BEGIN_POST_CHUNK $1\n$&\n//!END_POST_CHUNK\n" ); fragmentShader = expandShaderIncludes(fragmentShader); } if (customRewriter) { let res = customRewriter({ vertexShader, fragmentShader }); vertexShader = res.vertexShader; fragmentShader = res.fragmentShader; } if (fragmentColorTransform) { let postChunks = []; fragmentShader = fragmentShader.replace( /^\/\/!BEGIN_POST_CHUNK[^]+?^\/\/!END_POST_CHUNK/gm, // [^]+? = non-greedy match of any chars including newlines (match) => { postChunks.push(match); return ""; } ); fragmentMainOutro = `${fragmentColorTransform} ${postChunks.join("\n")} ${fragmentMainOutro}`; } if (timeUniform) { const code = ` uniform float ${timeUniform}; `; vertexDefs2 = code + vertexDefs2; fragmentDefs2 = code + fragmentDefs2; } if (vertexTransform2) { vertexShader = `vec3 troika_position_${key}; vec3 troika_normal_${key}; vec2 troika_uv_${key}; ${vertexShader} `; vertexDefs2 = `${vertexDefs2} void troikaVertexTransform${key}(inout vec3 position, inout vec3 normal, inout vec2 uv) { ${vertexTransform2} } `; vertexMainIntro = ` troika_position_${key} = vec3(position); troika_normal_${key} = vec3(normal); troika_uv_${key} = vec2(uv); troikaVertexTransform${key}(troika_position_${key}, troika_normal_${key}, troika_uv_${key}); ${vertexMainIntro} `; vertexShader = vertexShader.replace(/\b(position|normal|uv)\b/g, (match, match1, index, fullStr) => { return /\battribute\s+vec[23]\s+$/.test(fullStr.substr(0, index)) ? match1 : `troika_${match1}_${key}`; }); if (!(material.map && material.map.channel > 0)) { vertexShader = vertexShader.replace(/\bMAP_UV\b/g, `troika_uv_${key}`); } } vertexShader = injectIntoShaderCode(vertexShader, key, vertexDefs2, vertexMainIntro, vertexMainOutro); fragmentShader = injectIntoShaderCode(fragmentShader, key, fragmentDefs2, fragmentMainIntro2, fragmentMainOutro); return { vertexShader, fragmentShader }; } function injectIntoShaderCode(shaderCode, id, defs, intro, outro) { if (intro || outro || defs) { shaderCode = shaderCode.replace( voidMainRegExp, ` ${defs} void troikaOrigMain${id}() {` ); shaderCode += ` void main() { ${intro} troikaOrigMain${id}(); ${outro} }`; } return shaderCode; } function optionsJsonReplacer(key, value) { return key === "uniforms" ? void 0 : typeof value === "function" ? value.toString() : value; } var _idCtr = 0; var optionsHashesToIds = /* @__PURE__ */ new Map(); function getKeyForOptions(options) { const optionsHash = JSON.stringify(options, optionsJsonReplacer); let id = optionsHashesToIds.get(optionsHash); if (id == null) { optionsHashesToIds.set(optionsHash, id = ++_idCtr); } return id; } var MATERIAL_TYPES_TO_SHADERS = { MeshDepthMaterial: "depth", MeshDistanceMaterial: "distanceRGBA", MeshNormalMaterial: "normal", MeshBasicMaterial: "basic", MeshLambertMaterial: "lambert", MeshPhongMaterial: "phong", MeshToonMaterial: "toon", MeshStandardMaterial: "physical", MeshPhysicalMaterial: "physical", MeshMatcapMaterial: "matcap", LineBasicMaterial: "basic", LineDashedMaterial: "dashed", PointsMaterial: "points", ShadowMaterial: "shadow", SpriteMaterial: "sprite" }; function getShadersForMaterial(material) { let builtinType = MATERIAL_TYPES_TO_SHADERS[material.type]; return builtinType ? ShaderLib[builtinType] : material; } function getShaderUniformTypes(shader) { let uniformRE = /\buniform\s+(int|float|vec[234]|mat[34])\s+([A-Za-z_][\w]*)/g; let uniforms = /* @__PURE__ */ Object.create(null); let match; while ((match = uniformRE.exec(shader)) !== null) { uniforms[match[2]] = match[1]; } return uniforms; } function invertMatrix4(srcMatrix, tgtMatrix = new Matrix4()) { if (typeof tgtMatrix.invert === "function") { tgtMatrix.copy(srcMatrix).invert(); } else { tgtMatrix.getInverse(srcMatrix); } return tgtMatrix; } var vertexDefs = ` uniform vec3 pointA; uniform vec3 controlA; uniform vec3 controlB; uniform vec3 pointB; uniform float radius; varying float bezierT; vec3 cubicBezier(vec3 p1, vec3 c1, vec3 c2, vec3 p2, float t) { float t2 = 1.0 - t; float b0 = t2 * t2 * t2; float b1 = 3.0 * t * t2 * t2; float b2 = 3.0 * t * t * t2; float b3 = t * t * t; return b0 * p1 + b1 * c1 + b2 * c2 + b3 * p2; } vec3 cubicBezierDerivative(vec3 p1, vec3 c1, vec3 c2, vec3 p2, float t) { float t2 = 1.0 - t; return -3.0 * p1 * t2 * t2 + c1 * (3.0 * t2 * t2 - 6.0 * t2 * t) + c2 * (6.0 * t2 * t - 3.0 * t * t) + 3.0 * p2 * t * t; } `; var vertexTransform = ` float t = position.y; bezierT = t; vec3 bezierCenterPos = cubicBezier(pointA, controlA, controlB, pointB, t); vec3 bezierDir = normalize(cubicBezierDerivative(pointA, controlA, controlB, pointB, t)); // Make "sideways" always perpendicular to the camera ray; this ensures that any twists // in the cylinder occur where you won't see them: vec3 viewDirection = normalMatrix * vec3(0.0, 0.0, 1.0); if (bezierDir == viewDirection) { bezierDir = normalize(cubicBezierDerivative(pointA, controlA, controlB, pointB, t == 1.0 ? t - 0.0001 : t + 0.0001)); } vec3 sideways = normalize(cross(bezierDir, viewDirection)); vec3 upish = normalize(cross(sideways, bezierDir)); // Build a matrix for transforming this disc in the cylinder: mat4 discTx; discTx[0].xyz = sideways * radius; discTx[1].xyz = bezierDir * radius; discTx[2].xyz = upish * radius; discTx[3].xyz = bezierCenterPos; discTx[3][3] = 1.0; // Apply transform, ignoring original y position = (discTx * vec4(position.x, 0.0, position.z, 1.0)).xyz; normal = normalize(mat3(discTx) * normal); `; var fragmentDefs = ` uniform vec3 dashing; varying float bezierT; `; var fragmentMainIntro = ` if (dashing.x + dashing.y > 0.0) { float dashFrac = mod(bezierT - dashing.z, dashing.x + dashing.y); if (dashFrac > dashing.x) { discard; } } `; function createBezierMeshMaterial(baseMaterial) { return createDerivedMaterial( baseMaterial, { chained: true, uniforms: { pointA: { value: new Vector3() }, controlA: { value: new Vector3() }, controlB: { value: new Vector3() }, pointB: { value: new Vector3() }, radius: { value: 0.01 }, dashing: { value: new Vector3() } //on, off, offset }, vertexDefs, vertexTransform, fragmentDefs, fragmentMainIntro } ); } var geometry = null; var defaultBaseMaterial = new MeshStandardMaterial({ color: 16777215, side: DoubleSide }); var BezierMesh = class _BezierMesh extends Mesh { static getGeometry() { return geometry || (geometry = new CylinderGeometry(1, 1, 1, 6, 64).translate(0, 0.5, 0)); } constructor() { super( _BezierMesh.getGeometry(), defaultBaseMaterial ); this.pointA = new Vector3(); this.controlA = new Vector3(); this.controlB = new Vector3(); this.pointB = new Vector3(); this.radius = 0.01; this.dashArray = new Vector2(); this.dashOffset = 0; this.frustumCulled = false; } // Handler for automatically wrapping the base material with our upgrades. We do the wrapping // lazily on _read_ rather than write to avoid unnecessary wrapping on transient values. get material() { let derivedMaterial = this._derivedMaterial; const baseMaterial = this._baseMaterial || this._defaultMaterial || (this._defaultMaterial = defaultBaseMaterial.clone()); if (!derivedMaterial || derivedMaterial.baseMaterial !== baseMaterial) { derivedMaterial = this._derivedMaterial = createBezierMeshMaterial(baseMaterial); baseMaterial.addEventListener("dispose", function onDispose() { baseMaterial.removeEventListener("dispose", onDispose); derivedMaterial.dispose(); }); } return derivedMaterial; } set material(baseMaterial) { this._baseMaterial = baseMaterial; } // Create and update material for shadows upon request: get customDepthMaterial() { return this.material.getDepthMaterial(); } set customDepthMaterial(m) { } get customDistanceMaterial() { return this.material.getDistanceMaterial(); } set customDistanceMaterial(m) { } onBeforeRender() { const { uniforms } = this.material; const { pointA, controlA, controlB, pointB, radius, dashArray, dashOffset } = this; uniforms.pointA.value.copy(pointA); uniforms.controlA.value.copy(controlA); uniforms.controlB.value.copy(controlB); uniforms.pointB.value.copy(pointB); uniforms.radius.value = radius; uniforms.dashing.value.set(dashArray.x, dashArray.y, dashOffset || 0); } raycast() { } }; export { voidMainRegExp, expandShaderIncludes, createDerivedMaterial, getShadersForMaterial, getShaderUniformTypes, invertMatrix4, BezierMesh }; //# sourceMappingURL=chunk-REWIZMPU.js.map