mirror of
https://github.com/exogen/t2-mapper.git
synced 2026-03-18 20:01:01 +00:00
75 lines
No EOL
5.3 KiB
JavaScript
75 lines
No EOL
5.3 KiB
JavaScript
import{r as e}from"./chunk-DECur_0Z.js";import{n as t,r as n,t as r}from"./jsx-runtime-BpGWiA-R.js";import{i}from"./react-three-fiber.esm-1xQMUSXT.js";import{a}from"./SettingsProvider-DlQTXm3x.js";import"./logger-DePRU8Hm.js";import"./traditional-DPdbI9gv.js";import{Et as o,Vt as s,kt as c,p as l,y as u}from"./three.module-Bu2Gkdne.js";import"./mission-CWASMBNZ.js";import{F as d,V as f,r as p}from"./index-C2tCa94d.js";var m=t(),h=e(n(),1),g=`
|
|
#include <fog_pars_vertex>
|
|
|
|
varying vec2 vUv;
|
|
|
|
void main() {
|
|
vUv = uv;
|
|
vec4 mvPosition = modelViewMatrix * vec4(position, 1.0);
|
|
gl_Position = projectionMatrix * mvPosition;
|
|
#include <fog_vertex>
|
|
}
|
|
`,_=`
|
|
#include <fog_pars_fragment>
|
|
|
|
uniform sampler2D frame0;
|
|
uniform sampler2D frame1;
|
|
uniform sampler2D frame2;
|
|
uniform sampler2D frame3;
|
|
uniform sampler2D frame4;
|
|
uniform int currentFrame;
|
|
uniform float vScroll;
|
|
uniform vec2 uvScale;
|
|
uniform vec3 tintColor;
|
|
uniform float opacity;
|
|
uniform float opacityFactor;
|
|
|
|
varying vec2 vUv;
|
|
|
|
void main() {
|
|
// Scale and scroll UVs
|
|
vec2 scrolledUv = vec2(vUv.x * uvScale.x, vUv.y * uvScale.y + vScroll);
|
|
|
|
// Sample the current frame
|
|
vec4 texColor;
|
|
if (currentFrame == 0) {
|
|
texColor = texture2D(frame0, scrolledUv);
|
|
} else if (currentFrame == 1) {
|
|
texColor = texture2D(frame1, scrolledUv);
|
|
} else if (currentFrame == 2) {
|
|
texColor = texture2D(frame2, scrolledUv);
|
|
} else if (currentFrame == 3) {
|
|
texColor = texture2D(frame3, scrolledUv);
|
|
} else {
|
|
texColor = texture2D(frame4, scrolledUv);
|
|
}
|
|
|
|
// Tribes 2 GL_MODULATE: output = texture * vertexColor
|
|
// No gamma correction - textures use NoColorSpace and values pass through
|
|
// directly to display, matching how WaterBlock handles sRGB textures.
|
|
vec3 modulatedColor = texColor.rgb * tintColor;
|
|
|
|
float adjustedOpacity = opacity * opacityFactor;
|
|
|
|
gl_FragColor = vec4(modulatedColor, adjustedOpacity);
|
|
|
|
// Custom fog for additive blending: fade out rather than blend to fog color.
|
|
// Standard fog (mix toward fogColor) doesn't work with additive blending
|
|
// because we'd still be adding fogColor to the framebuffer.
|
|
// Uses Torque's quadratic haze formula for consistency.
|
|
#ifdef USE_FOG
|
|
float dist = vFogDepth;
|
|
float fogFactor = 0.0;
|
|
if (dist > fogNear) {
|
|
if (dist >= fogFar) {
|
|
fogFactor = 1.0;
|
|
} else {
|
|
float fogScale = 1.0 / (fogFar - fogNear);
|
|
float distFactor = (dist - fogNear) * fogScale - 1.0;
|
|
fogFactor = 1.0 - distFactor * distFactor;
|
|
}
|
|
}
|
|
gl_FragColor.a *= 1.0 - fogFactor;
|
|
#endif
|
|
}
|
|
`;function v({textures:e,scale:t,umapping:n,vmapping:r,color:i,baseTranslucency:a}){let o=[...t].sort((e,t)=>t-e),l=new s(o[0]*n,o[1]*r),d=e[0];return new c({uniforms:{frame0:{value:d},frame1:{value:e[1]??d},frame2:{value:e[2]??d},frame3:{value:e[3]??d},frame4:{value:e[4]??d},currentFrame:{value:0},vScroll:{value:0},uvScale:{value:l},tintColor:{value:new u(...i)},opacity:{value:a},opacityFactor:{value:1},fogColor:{value:new u},fogNear:{value:1},fogFar:{value:2e3}},vertexShader:g,fragmentShader:_,transparent:!0,blending:2,side:2,depthWrite:!1,fog:!0})}var y=r();function b(e){e.wrapS=e.wrapT=o,e.colorSpace=``,e.flipY=!1,e.needsUpdate=!0}function x(e){let t=(0,m.c)(7),[n,r,i]=e,a;t[0]!==n||t[1]!==r||t[2]!==i?(a=new l(n,r,i),a.translate(n/2,r/2,i/2),t[0]=n,t[1]=r,t[2]=i,t[3]=a):a=t[3];let o=a,s,c;return t[4]===o?(s=t[5],c=t[6]):(s=()=>()=>o.dispose(),c=[o],t[4]=o,t[5]=s,t[6]=c),(0,h.useEffect)(s,c),o}function S(e){let t=(0,m.c)(10),{scale:n,color:r,baseTranslucency:i}=e,a=x(n),o;t[0]!==r[0]||t[1]!==r[1]||t[2]!==r[2]?(o=new u(r[0],r[1],r[2]),t[0]=r[0],t[1]=r[1],t[2]=r[2],t[3]=o):o=t[3];let s=o,c=i*1,l;t[4]!==s||t[5]!==c?(l=(0,y.jsx)(`meshBasicMaterial`,{color:s,transparent:!0,opacity:c,blending:2,side:2,depthWrite:!1,fog:!1}),t[4]=s,t[5]=c,t[6]=l):l=t[6];let d;return t[7]!==a||t[8]!==l?(d=(0,y.jsx)(`mesh`,{geometry:a,renderOrder:1,children:l}),t[7]=a,t[8]=l,t[9]=d):d=t[9],d}function C({scale:e,data:t}){let{animationEnabled:n}=a(),r=x(e),o=f((0,h.useMemo)(()=>t.textures.map(e=>d(e)),[t.textures]),e=>{e.forEach(e=>b(e))}),s=(0,h.useMemo)(()=>v({textures:o,scale:e,umapping:t.umapping,vmapping:t.vmapping,color:t.color,baseTranslucency:t.baseTranslucency}),[o,e,t]);(0,h.useEffect)(()=>()=>s.dispose(),[s]);let c=(0,h.useRef)(0);return i((e,r)=>{if(!n){c.current=0,s.uniforms.currentFrame.value=0,s.uniforms.vScroll.value=0;return}c.current+=r,s.uniforms.currentFrame.value=Math.floor(c.current*t.framesPerSec)%t.numFrames,s.uniforms.vScroll.value=c.current*t.scrollSpeed}),(0,y.jsx)(`mesh`,{geometry:r,material:s,renderOrder:1})}function w(e){let t=(0,m.c)(14),{entity:n}=e,r=n.forceFieldData,i=r.dimensions;if(r.textures.map(T).length===0){let e;return t[0]!==r.baseTranslucency||t[1]!==r.color||t[2]!==i?(e=(0,y.jsx)(S,{scale:i,color:r.color,baseTranslucency:r.baseTranslucency}),t[0]=r.baseTranslucency,t[1]=r.color,t[2]=i,t[3]=e):e=t[3],e}let a;t[4]!==r.baseTranslucency||t[5]!==r.color||t[6]!==i?(a=(0,y.jsx)(S,{scale:i,color:r.color,baseTranslucency:r.baseTranslucency}),t[4]=r.baseTranslucency,t[5]=r.color,t[6]=i,t[7]=a):a=t[7];let o;t[8]!==r||t[9]!==i?(o=(0,y.jsx)(C,{scale:i,data:r}),t[8]=r,t[9]=i,t[10]=o):o=t[10];let s;return t[11]!==a||t[12]!==o?(s=(0,y.jsx)(p,{name:`ForceField`,fallback:a,children:o}),t[11]=a,t[12]=o,t[13]=s):s=t[13],s}function T(e){return d(e)}export{w as ForceFieldBare}; |