t2-mapper/docs/_next/static/chunks/bd1dcee0b953cac2.js
Brian Beck 0bcb2ff9f4 build
2025-12-05 15:58:28 -08:00

1 line
8.8 KiB
JavaScript

(globalThis.TURBOPACK||(globalThis.TURBOPACK=[])).push(["object"==typeof document?document.currentScript:void 0,42585,e=>{"use strict";e.s(["WaterBlock",()=>p,"WaterMaterial",()=>v,"WaterSurfaceMaterial",()=>c],42585);var n=e.i(43476),a=e.i(71645),t=e.i(47071),i=e.i(5230),r=e.i(90072),o=e.i(12979),l=e.i(62395),s=e.i(75567),u=e.i(79123);function c(e){let{surfaceTexture:l,envMapTexture:c,opacity:v=.75,waveMagnitude:p=1,envMapIntensity:d=1,attach:f}=e,m=(0,o.textureToUrl)(l),g=(0,o.textureToUrl)(null!=c?c:"special/lush_env"),[h,T]=(0,t.useTexture)([m,g],e=>{(Array.isArray(e)?e:[e]).forEach(e=>{(0,s.setupColor)(e),e.wrapS=r.RepeatWrapping,e.wrapT=r.RepeatWrapping})}),{animationEnabled:x}=(0,u.useSettings)(),b=(0,a.useMemo)(()=>{var e,n,a,t,i,o;return e={opacity:v,waveMagnitude:p,envMapIntensity:d,baseTexture:h,envMapTexture:T},new r.ShaderMaterial({uniforms:{uTime:{value:0},uOpacity:{value:null!=(n=null==e?void 0:e.opacity)?n:.75},uWaveMagnitude:{value:null!=(a=null==e?void 0:e.waveMagnitude)?a:1},uEnvMapIntensity:{value:null!=(t=null==e?void 0:e.envMapIntensity)?t:1},uBaseTexture:{value:null!=(i=null==e?void 0:e.baseTexture)?i:null},uEnvMapTexture:{value:null!=(o=null==e?void 0:e.envMapTexture)?o:null},fogColor:{value:new r.Color},fogNear:{value:1},fogFar:{value:2e3}},vertexShader:"\n #include <fog_pars_vertex>\n\n uniform float uTime;\n uniform float uWaveMagnitude;\n\n varying vec3 vWorldPosition;\n varying vec3 vViewVector;\n varying float vDistance;\n\n // Wave function matching Tribes 2 engine\n // Z = surfaceZ + (sin(X*0.05 + time) + sin(Y*0.05 + time)) * waveFactor\n // waveFactor = waveAmplitude * 0.25\n // Note: Using xz for Three.js Y-up (Torque uses XY with Z-up)\n float getWaveHeight(vec3 worldPos) {\n float waveFactor = uWaveMagnitude * 0.25;\n return (sin(worldPos.x * 0.05 + uTime) + sin(worldPos.z * 0.05 + uTime)) * waveFactor;\n }\n\n void main() {\n // Get world position for wave calculation\n vec4 worldPos = modelMatrix * vec4(position, 1.0);\n vWorldPosition = worldPos.xyz;\n\n // Apply wave displacement to Y (vertical axis in Three.js)\n vec3 displaced = position;\n displaced.y += getWaveHeight(worldPos.xyz);\n\n // Calculate view vector for environment mapping\n vViewVector = cameraPosition - worldPos.xyz;\n vDistance = length(vViewVector);\n\n vec4 mvPosition = viewMatrix * modelMatrix * vec4(displaced, 1.0);\n gl_Position = projectionMatrix * mvPosition;\n\n #include <fog_vertex>\n }\n",fragmentShader:"\n #include <fog_pars_fragment>\n\n uniform float uTime;\n uniform float uOpacity;\n uniform float uEnvMapIntensity;\n uniform sampler2D uBaseTexture;\n uniform sampler2D uEnvMapTexture;\n\n varying vec3 vWorldPosition;\n varying vec3 vViewVector;\n varying float vDistance;\n\n #define TWO_PI 6.283185307179586\n\n // Constants from Tribes 2 engine\n #define BASE_DRIFT_CYCLE_TIME 8.0\n #define BASE_DRIFT_RATE 0.02\n #define BASE_DRIFT_SCALAR 0.03\n #define TEXTURE_SCALE (1.0 / 48.0)\n\n // Environment map UV wobble constants\n #define Q1 150.0\n #define Q2 2.0\n #define Q3 0.01\n\n // Rotate UV coordinates\n vec2 rotateUV(vec2 uv, float angle) {\n float c = cos(angle);\n float s = sin(angle);\n return vec2(\n uv.x * c - uv.y * s,\n uv.x * s + uv.y * c\n );\n }\n\n void main() {\n // Calculate base texture UVs using world position (1/48 tiling)\n // Note: In Three.js Y-up coordinates, the water surface is on the XZ plane\n // Torque uses Z-up where the surface is XY, so we use xz here\n vec2 baseUV = vWorldPosition.xz * TEXTURE_SCALE;\n\n // Phase (time in radians for drift cycle)\n float phase = mod(uTime * (TWO_PI / BASE_DRIFT_CYCLE_TIME), TWO_PI);\n\n // Base texture drift\n float baseDriftX = uTime * BASE_DRIFT_RATE;\n float baseDriftY = cos(phase) * BASE_DRIFT_SCALAR;\n\n // === Phase 1a: First base texture pass (rotated 30 degrees) ===\n vec2 uv1a = rotateUV(baseUV, radians(30.0));\n\n // === Phase 1b: Second base texture pass (rotated 60 degrees total, with drift) ===\n // OpenGL matrix order: glRotatef(60) then glTranslatef(drift) means\n // the transform is R60 * T, so when applied to UV: R60 * (UV + drift)\n // Translation is applied first, then rotation.\n vec2 uv1b = rotateUV(baseUV + vec2(baseDriftX, baseDriftY), radians(60.0));\n\n // Calculate cross-fade swing value\n // From engine: A1 = cos((X/Q1 + time/Q2) * 6.0), A2 = sin((Y/Q1 + time/Q2) * 6.28)\n // Using xz for Three.js Y-up coordinate system\n float A1 = cos(((vWorldPosition.x / Q1) + (uTime / Q2)) * 6.0);\n float A2 = sin(((vWorldPosition.z / Q1) + (uTime / Q2)) * TWO_PI);\n float swing = (A1 + A2) * 0.15 + 0.5;\n\n // Cross-fade alpha calculation from engine\n // alpha1a = ((1-swing) * opacity) / (1 - (swing * opacity))\n // alpha1b = swing * opacity\n float alpha1a = ((1.0 - swing) * uOpacity) / max(1.0 - (swing * uOpacity), 0.001);\n float alpha1b = swing * uOpacity;\n\n // Sample base texture for both passes\n vec4 texColor1a = texture2D(uBaseTexture, uv1a);\n vec4 texColor1b = texture2D(uBaseTexture, uv1b);\n\n // Simulate multi-pass alpha accumulation (screen blend formula)\n // Pass 1a: framebuffer = tex1a * alpha1a + bg * (1 - alpha1a)\n // Pass 1b: framebuffer = tex1b * alpha1b + prev * (1 - alpha1b)\n // Combined alpha = 1 - (1 - alpha1a) * (1 - alpha1b)\n float combinedAlpha = 1.0 - (1.0 - alpha1a) * (1.0 - alpha1b);\n\n // Combined color (premultiplied then divided by combined alpha)\n // color = tex1b * alpha1b + tex1a * alpha1a * (1 - alpha1b)\n vec3 baseColor = (texColor1a.rgb * alpha1a * (1.0 - alpha1b) + texColor1b.rgb * alpha1b) / max(combinedAlpha, 0.001);\n\n // === Phase 3: Environment map / specular ===\n // Reflection UV calculation from engine (fluidQuadTree.cc lines 910-962)\n // Engine uses eye-to-point vector (point - eye), unnormalized.\n // vViewVector is camera - worldPos (point-to-eye), so we negate it.\n // Torque Z-up maps XY to UV; Three.js Y-up maps XZ to UV.\n vec3 reflectVec = -vViewVector;\n reflectVec.y = abs(reflectVec.y); // Y is vertical in Three.js (was Z in Torque)\n if (reflectVec.y < 0.001) reflectVec.y = 0.001;\n\n vec2 envUV;\n if (vDistance < 0.001) {\n envUV = vec2(0.0);\n } else {\n // Standard UV reflection mapping with adjustment to reduce edge emphasis\n float value = (vDistance - reflectVec.y) / (vDistance * vDistance);\n envUV.x = reflectVec.x * value;\n envUV.y = reflectVec.z * value; // Z maps to V in Three.js Y-up\n }\n\n // Convert from [-1,1] to [0,1]\n envUV = envUV * 0.5 + 0.5;\n\n // Add time-based wobble to environment map\n envUV.x += A1 * Q3;\n envUV.y += A2 * Q3;\n\n vec4 envColor = texture2D(uEnvMapTexture, envUV);\n\n // Blend environment map additively (GL_SRC_ALPHA, GL_ONE in original engine)\n // Engine uses GL_MODULATE with color (1,1,1,envMapIntensity), so texture alpha\n // is multiplied with intensity before additive blend.\n vec3 finalColor = baseColor + envColor.rgb * envColor.a * uEnvMapIntensity;\n\n gl_FragColor = vec4(finalColor, combinedAlpha);\n\n // Apply scene fog (integrated with Three.js fog system)\n #include <fog_fragment>\n }\n",transparent:!0,side:r.DoubleSide,depthWrite:!0,fog:!0})},[v,p,d,h,T]),y=(0,a.useRef)(0);return(0,i.useFrame)((e,n)=>{if(!x){y.current=0,b.uniforms.uTime.value=0;return}y.current+=n,b.uniforms.uTime.value=y.current}),(0,a.useEffect)(()=>()=>{b.dispose()},[b]),(0,n.jsx)("primitive",{object:b,attach:f})}function v(e){let{surfaceTexture:a,attach:i}=e,l=(0,o.textureToUrl)(a),u=(0,t.useTexture)(l,e=>(0,s.setupColor)(e));return(0,n.jsx)("meshStandardMaterial",{attach:i,map:u,transparent:!0,opacity:.8,side:r.DoubleSide})}let p=(0,a.memo)(function(e){var t,i,o,s;let{object:u}=e,v=(0,a.useMemo)(()=>(0,l.getPosition)(u),[u]),p=(0,a.useMemo)(()=>(0,l.getRotation)(u),[u]),[d,f,m]=(0,a.useMemo)(()=>(0,l.getScale)(u),[u]),g=null!=(t=(0,l.getProperty)(u,"surfaceTexture"))?t:"liquidTiles/BlueWater",h=(0,l.getProperty)(u,"envMapTexture"),T=parseFloat(null!=(i=(0,l.getProperty)(u,"surfaceOpacity"))?i:"0.75"),x=parseFloat(null!=(o=(0,l.getProperty)(u,"waveMagnitude"))?o:"1.0"),b=parseFloat(null!=(s=(0,l.getProperty)(u,"envMapIntensity"))?s:"1.0"),y=(0,a.useMemo)(()=>{let[e,n]=function(e,n){let a=e<=1024&&n<=1024?8:16;return[Math.max(4,Math.ceil(e/a)),Math.max(4,Math.ceil(n/a))]}(d,m),a=new r.PlaneGeometry(d,m,e,n);return a.rotateX(-Math.PI/2),a.translate(d/2,f,m/2),a},[d,f,m]);return(0,a.useEffect)(()=>()=>{y.dispose()},[y]),(0,n.jsx)("group",{position:v,quaternion:p,children:(0,n.jsx)("mesh",{geometry:y,children:(0,n.jsx)(a.Suspense,{fallback:(0,n.jsx)("meshStandardMaterial",{color:"blue",transparent:!0,opacity:.3,side:r.DoubleSide}),children:(0,n.jsx)(c,{attach:"material",surfaceTexture:g,envMapTexture:h,opacity:T,waveMagnitude:x,envMapIntensity:b})})})})})}]);