mirror of
https://github.com/exogen/t2-mapper.git
synced 2026-01-19 20:25:01 +00:00
1 line
9.8 KiB
JavaScript
1 line
9.8 KiB
JavaScript
(globalThis.TURBOPACK||(globalThis.TURBOPACK=[])).push(["object"==typeof document?document.currentScript:void 0,42585,e=>{"use strict";e.s(["WaterBlock",()=>x,"WaterMaterial",()=>h],42585);var n,t=e.i(43476),a=e.i(71645),o=e.i(31067),r=e.i(90072);let i=(n=0,a.forwardRef((e,n)=>{let{args:t,children:r,...i}=e,l=a.useRef(null);return a.useImperativeHandle(n,()=>l.current),a.useLayoutEffect(()=>void 0),a.createElement("mesh",(0,o.default)({ref:l},i),a.createElement("boxGeometry",{attach:"geometry",args:t}),r)}));var l=e.i(47071),s=e.i(5230),u=e.i(16096),c=e.i(12979),f=e.i(62395),v=e.i(75567),d=e.i(48066),m=e.i(47021);let p="\n #include <fog_pars_fragment>\n\n // Enable volumetric fog (must be defined before fog uniforms)\n #ifdef USE_FOG\n #define USE_VOLUMETRIC_FOG\n #define USE_FOG_WORLD_POSITION\n #endif\n\n uniform float uTime;\n uniform float uOpacity;\n uniform float uEnvMapIntensity;\n uniform sampler2D uBaseTexture;\n uniform sampler2D uEnvMapTexture;\n\n // Volumetric fog uniforms\n #ifdef USE_FOG\n uniform float fogVolumeData[12];\n uniform float cameraHeight;\n uniform bool fogEnabled;\n varying vec3 vFogWorldPosition;\n #endif\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 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 vec2 uv1b = rotateUV(baseUV + vec2(baseDriftX, baseDriftY), radians(60.0));\n\n // Calculate cross-fade swing value\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 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 // Combined alpha and color\n float combinedAlpha = 1.0 - (1.0 - alpha1a) * (1.0 - 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 vec3 reflectVec = -vViewVector;\n reflectVec.y = abs(reflectVec.y);\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 float value = (vDistance - reflectVec.y) / (vDistance * vDistance);\n envUV.x = reflectVec.x * value;\n envUV.y = reflectVec.z * value;\n }\n\n envUV = envUV * 0.5 + 0.5;\n envUV.x += A1 * Q3;\n envUV.y += A2 * Q3;\n\n vec4 envColor = texture2D(uEnvMapTexture, envUV);\n vec3 finalColor = baseColor + envColor.rgb * envColor.a * uEnvMapIntensity;\n\n // Note: Tribes 2 water does NOT use lighting - Phase 2 (lightmap) is disabled\n // in the original engine. Water colors come directly from textures.\n\n gl_FragColor = vec4(finalColor, combinedAlpha);\n\n // Apply volumetric fog using shared Torque-style fog shader\n ".concat(m.fogFragmentShader,"\n }\n");var g=e.i(79123);function h(e){let{surfaceTexture:n,attach:a}=e,o=(0,c.textureToUrl)(n),i=(0,l.useTexture)(o,e=>(0,v.setupColor)(e));return(0,t.jsx)("meshStandardMaterial",{attach:a,map:i,transparent:!0,opacity:.8,side:r.DoubleSide})}let x=(0,a.memo)(function(e){var n,o,l,c;let{object:v}=e,{debugMode:d}=(0,g.useDebug)(),m=(0,a.useMemo)(()=>(0,f.getRotation)(v),[v]),p=(0,a.useMemo)(()=>(0,f.getPosition)(v),[v]),h=(0,a.useMemo)(()=>(0,f.getScale)(v),[v]),[x,b,y]=h,M=(0,u.useThree)(e=>e.camera),w=function(){let e=(0,a.useRef)(null);return(0,a.useCallback)(n=>{if(!e.current)return e.current=n.clone(),!0;let t=e.current.x===n.x&&e.current.y===n.y&&e.current.z===n.z;return t||e.current.copy(n),t},[])}();p[1];let E=null!=(n=(0,f.getFloat)(v,"waveMagnitude"))?n:1,P=(0,a.useMemo)(()=>{let[e,n,t]=p,a=Math.round((e+1024)/8),o=Math.round((t+1024)/8);return[8*(a=Math.max(0,Math.min(2040,a))),n,8*(o=Math.max(0,Math.min(2040,o)))]},[p]),S=(e,n)=>{let t=e+1024,a=n+1024,o=Math.trunc(t/2048),r=Math.trunc(a/2048);t<0&&o--,a<0&&r--;let i=[];for(let e=r-1;e<=r+1;e++)for(let n=o-1;n<=o+1;n++)i.push([n,e]);return i},[V,_]=(0,a.useState)(()=>S(M.position.x,M.position.z));(0,s.useFrame)(()=>{if(!w(M.position))return;let e=S(M.position.x,M.position.z);_(n=>JSON.stringify(n)===JSON.stringify(e)?n:e)});let U=null!=(o=(0,f.getProperty)(v,"surfaceTexture"))?o:"liquidTiles/BlueWater",C=(0,f.getProperty)(v,"envMapTexture"),F=null!=(l=(0,f.getFloat)(v,"surfaceOpacity"))?l:.75,D=null!=(c=(0,f.getFloat)(v,"envMapIntensity"))?c:1,A=(0,a.useMemo)(()=>{let[e,n]=function(e,n){let t=e<=1024&&n<=1024?8:16;return[Math.max(4,Math.ceil(e/t)),Math.max(4,Math.ceil(n/t))]}(x,y),t=new r.PlaneGeometry(x,y,e,n);return t.rotateX(-Math.PI/2),t.translate(x/2,b,y/2),t},[x,b,y]);return(0,a.useEffect)(()=>()=>{A.dispose()},[A]),(0,t.jsxs)("group",{quaternion:m,children:[d&&(0,t.jsx)(i,{args:h,position:[p[0]+x/2,p[1]+b/2,p[2]+y/2],children:(0,t.jsx)("meshBasicMaterial",{color:"#00fbff",wireframe:!0})}),(0,t.jsx)(a.Suspense,{fallback:V.map(e=>{let[n,a]=e,o=P[0]+2048*n-1024,i=P[2]+2048*a-1024;return(0,t.jsx)("mesh",{geometry:A,position:[o,P[1],i],children:(0,t.jsx)("meshStandardMaterial",{color:"#00fbff",transparent:!0,opacity:.4,wireframe:!0,side:r.DoubleSide})},"".concat(n,",").concat(a))}),children:(0,t.jsx)(T,{reps:V,basePosition:P,surfaceGeometry:A,surfaceTexture:U,envMapTexture:C,opacity:F,waveMagnitude:E,envMapIntensity:D})})]})}),T=(0,a.memo)(function(e){let{reps:n,basePosition:o,surfaceGeometry:i,surfaceTexture:u,envMapTexture:f,opacity:m,waveMagnitude:h,envMapIntensity:x}=e,T=(0,c.textureToUrl)(u),b=(0,c.textureToUrl)(null!=f?f:"special/lush_env"),[y,M]=(0,l.useTexture)([T,b],e=>{(Array.isArray(e)?e:[e]).forEach(e=>{(0,v.setupColor)(e),e.colorSpace=r.NoColorSpace,e.wrapS=r.RepeatWrapping,e.wrapT=r.RepeatWrapping})}),{animationEnabled:w}=(0,g.useSettings)(),E=(0,a.useMemo)(()=>{var e,n,t,a,o,i;return e={opacity:m,waveMagnitude:h,envMapIntensity:x,baseTexture:y,envMapTexture:M},new r.ShaderMaterial({uniforms:{uTime:{value:0},uOpacity:{value:null!=(n=null==e?void 0:e.opacity)?n:.75},uWaveMagnitude:{value:null!=(t=null==e?void 0:e.waveMagnitude)?t:1},uEnvMapIntensity:{value:null!=(a=null==e?void 0:e.envMapIntensity)?a:1},uBaseTexture:{value:null!=(o=null==e?void 0:e.baseTexture)?o:null},uEnvMapTexture:{value:null!=(i=null==e?void 0:e.envMapTexture)?i:null},fogColor:{value:new r.Color},fogNear:{value:1},fogFar:{value:2e3},fogVolumeData:d.globalFogUniforms.fogVolumeData,cameraHeight:d.globalFogUniforms.cameraHeight,fogEnabled:d.globalFogUniforms.fogEnabled},vertexShader:"\n #include <fog_pars_vertex>\n\n #ifdef USE_FOG\n #define USE_FOG_WORLD_POSITION\n varying vec3 vFogWorldPosition;\n #endif\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 final world position after displacement for fog\n #ifdef USE_FOG\n vec4 displacedWorldPos = modelMatrix * vec4(displaced, 1.0);\n vFogWorldPosition = displacedWorldPos.xyz;\n #endif\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 // Set fog depth (distance from camera) - normally done by fog_vertex include\n // but we can't use that include because it references 'transformed' which we don't have\n #ifdef USE_FOG\n vFogDepth = length(mvPosition.xyz);\n #endif\n }\n",fragmentShader:p,transparent:!0,side:r.DoubleSide,depthWrite:!0,fog:!0})},[m,h,x,y,M]),P=(0,a.useRef)(0);return(0,s.useFrame)((e,n)=>{w?(P.current+=n,E.uniforms.uTime.value=P.current):(P.current=0,E.uniforms.uTime.value=0)}),(0,a.useEffect)(()=>()=>{E.dispose()},[E]),(0,t.jsx)(t.Fragment,{children:n.map(e=>{let[n,a]=e,r=o[0]+2048*n-1024,l=o[2]+2048*a-1024;return(0,t.jsx)("mesh",{geometry:i,material:E,position:[r,o[1],l]},"".concat(n,",").concat(a))})})})}]); |