t2-mapper/docs/assets/playbackUtils-DuS6opSR.js
2026-04-08 23:48:42 -07:00

47 lines
No EOL
11 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{Ct as i,Gt as a,Ot as o,Wt as s,a as c,at as l,g as u,kt as d,o as f,ot as p,q as m,rt as ee,ut as h,v as g,wt as _}from"./three.module-DKAirPAO.js";import{a as v,i as y,n as te,t as b,u as x}from"./textureUtils-Bk_jPZib.js";import{a as S,c as ne,p as C}from"./loaders-5n1D4iOD.js";var w={directional:1,ambient:1.5};function T(e){e.uniforms.shapeDirectionalFactor={value:w.directional},e.uniforms.shapeAmbientFactor={value:w.ambient},e.fragmentShader=e.fragmentShader.replace(`#include <common>`,`#include <common>
uniform float shapeDirectionalFactor;
uniform float shapeAmbientFactor;
`),e.fragmentShader=e.fragmentShader.replace(`#include <lights_fragment_end>`,`#include <lights_fragment_end>
// Apply shape-specific lighting multipliers
reflectedLight.directDiffuse *= shapeDirectionalFactor;
reflectedLight.indirectDiffuse *= shapeAmbientFactor;
`)}var E={shapeEnvMap:{value:null},shapeEnvMapActive:{value:!1},shapeEnvMapDebugUV:{value:!1}};function D(e){E.shapeEnvMap.value=e,E.shapeEnvMapActive.value=!0}function O(){E.shapeEnvMap.value=null,E.shapeEnvMapActive.value=!1}function k(e,t){e.uniforms.shapeEnvMap=E.shapeEnvMap,e.uniforms.shapeEnvMapActive=E.shapeEnvMapActive,e.uniforms.shapeEnvMapDebugUV=E.shapeEnvMapDebugUV,e.uniforms.shapeReflectionAmount={value:t},e.fragmentShader=e.fragmentShader.replace(`#include <common>`,`#include <common>
uniform sampler2D shapeEnvMap;
uniform bool shapeEnvMapActive;
uniform float shapeReflectionAmount;
uniform bool shapeEnvMapDebugUV;
varying vec2 vShapeSphereUV;
`),e.vertexShader=e.vertexShader.replace(`#include <common>`,`#include <common>
varying vec2 vShapeSphereUV;
`),e.vertexShader=e.vertexShader.replace(`#include <fog_vertex>`,`#include <fog_vertex>
{
vec3 _eyePos = (modelViewMatrix * vec4(transformed, 1.0)).xyz;
#ifdef FLAT_SHADED
vec3 _eyeN = vec3(0.0, 0.0, 1.0);
#else
vec3 _eyeN = normalize(normalMatrix * normal);
#endif
vec3 _eyeU = normalize(_eyePos);
vec3 _r = reflect(_eyeU, _eyeN);
float _m = 2.0 * sqrt(_r.x * _r.x + _r.z * _r.z + (_r.y + 1.0) * (_r.y + 1.0));
vShapeSphereUV = vec2(_r.x, -_r.z) / _m + 0.5;
}
`),e.fragmentShader=e.fragmentShader.replace(`#include <opaque_fragment>`,`// Tribes 2 sphere-map environment reflections (GL_INTERPOLATE)
if (shapeEnvMapActive && shapeReflectionAmount > 0.0) {
if (shapeEnvMapDebugUV) {
outgoingLight = vec3(vShapeSphereUV, 0.0);
} else {
vec3 _envColor = texture2D(shapeEnvMap, vShapeSphereUV).rgb;
#ifdef USE_MAP
float _baseAlpha = texture2D(map, vMapUv).a;
#else
float _baseAlpha = 1.0;
#endif
float _factor = _baseAlpha * shapeReflectionAmount;
// Torque blends in sRGB space (fixed-function pipeline, no gamma).
// Convert outgoingLight to sRGB, mix with sRGB env map, convert back.
vec3 _baseSRGB = pow(max(outgoingLight, 0.0), vec3(1.0 / 2.2));
outgoingLight = pow(mix(_baseSRGB, _envColor, _factor), vec3(2.2));
}
}
#include <opaque_fragment>`)}var A=e=>{x(e,v),T(e)},re=e=>{x(e,v)};function j(e,t){if(!t){e.onBeforeCompile=e instanceof p?A:re;return}let n=e instanceof p?`lambert`:`basic`;e.customProgramCacheKey=()=>`shape-envmap-${n}`;let{reflectionAmount:r}=t;e.onBeforeCompile=e=>{x(e,v),T(e),k(e,r)}}function M(e,t,n,r,i=1,a=!1,o=0){let s=n.has(`Translucent`),c=n.has(`Additive`),u=n.has(`SelfIlluminating`),d=i<1||a,f=!n.has(`NeverEnvMap`)&&o>0&&!d?{reflectionAmount:o}:void 0;if(u||c){let e=c||s||d,n=new l({map:t,side:2,transparent:e,depthWrite:!e,alphaTest:0,fog:!0,...d&&{opacity:i},...c&&{blending:2}});return j(n,f),n}if(r||s){let e={map:t,transparent:d,alphaTest:d?0:.5,...d&&{opacity:i,depthWrite:!1},reflectivity:0},n=new p({...e,side:1,polygonOffset:!0,polygonOffsetFactor:1,polygonOffsetUnits:1}),r=new p({...e,side:0});return j(n,f),j(r,f),[n,r]}let m=new p({map:t,side:2,reflectivity:0,...d&&{transparent:!0,opacity:i,depthWrite:!1}});return j(m,f),m}var ie=t(),N=e(n(),1),ae=r(),oe=/borg|xorg|porg|dorg|plant|tree|bush|fern|vine|grass|leaf|flower|frond|palm|foliage/i;function P(e){return oe.test(e)}var F=(0,N.createContext)(null);function I(){let e=(0,N.useContext)(F);if(!e)throw Error(`useShapeInfo must be used within ShapeInfoProvider`);return e}function L(e){let t=(0,ie.c)(10),{children:n,object:r,shapeName:i,type:a}=e,o;t[0]===i?o=t[1]:(o=P(i),t[0]=i,t[1]=o);let s=o,c;t[2]!==s||t[3]!==r||t[4]!==i||t[5]!==a?(c={object:r,shapeName:i,type:a,isOrganic:s},t[2]=s,t[3]=r,t[4]=i,t[5]=a,t[6]=c):c=t[6];let l=c,u;return t[7]!==n||t[8]!==l?(u=(0,ae.jsx)(F.Provider,{value:l,children:n}),t[7]=n,t[8]=l,t[9]=u):u=t[9],u}var R=1/30,z=new Map;function B(e){let t=new Map,n=[],r=[];for(let i of e){let e=t.get(i.name);e===void 0&&(e=n.length,t.set(i.name,e),n.push(i.name)),r.push(e)}return{uniqueNames:n,frameToSlot:r}}function V(e,t){if(e.length===0)throw Error(`Cannot create IFL atlas with no textures`);let n=e[0].image,r=n.width,i=n.height,a=e.length,o=Math.ceil(Math.sqrt(a)),s=Math.ceil(a/o),c=document.createElement(`canvas`);c.width=r*o,c.height=i*s;let l=c.getContext(`2d`);e.forEach((e,t)=>{let n=t%o,a=Math.floor(t/o);l.drawImage(e.image,n*r,a*i)});let f=new u(c);return f.colorSpace=d,f.generateMipmaps=!1,f.minFilter=h,f.magFilter=h,f.wrapS=g,f.wrapT=g,f.repeat.set(1/o,1/s),{texture:f,columns:o,rows:s,slotCount:a,frameToSlot:t,frameOffsetSeconds:[],totalDurationSeconds:0,lastSlot:-1}}function H(e,t){if(e.length===0)throw Error(`Cannot create IFL swap atlas with no textures`);for(let t of e)t.wrapS=t.wrapT=o,t.colorSpace=d,t.flipY=!1,t.image&&(t.needsUpdate=!0);return{texture:e[0],columns:1,rows:1,slotCount:e.length,frameToSlot:t,frameOffsetSeconds:[],totalDurationSeconds:0,lastSlot:-1,swapMode:!0,frameTextures:e}}function U(e,t){let n=0;e.frameOffsetSeconds=t.map(e=>(n+=e.frameCount*R,n)),e.totalDurationSeconds=n}function W(e,t){let n=e.frameToSlot[t]??0;if(n===e.lastSlot)return!1;if(e.lastSlot=n,e.swapMode&&e.frameTextures)return e.texture=e.frameTextures[n]??e.frameTextures[0],!0;let r=n%e.columns,i=e.rows-1-Math.floor(n/e.columns);return e.texture.offset.set(r/e.columns,i/e.rows),!1}function G(e,t){let n=e.totalDurationSeconds;if(n<=0)return 0;let r=t;r>n&&(r-=n*Math.floor(r/n));for(let t=0;t<e.frameOffsetSeconds.length;t++)if(r<=e.frameOffsetSeconds[t])return t;return e.frameOffsetSeconds.length-1}async function K(e,t){let n=t?.repeat?`${e}:repeat`:e,r=z.get(n);if(r)return r;let i=await ne(e),{uniqueNames:a,frameToSlot:o}=B(i),s=a.map(t=>S(t,e)),c=await Promise.all(s.map(te)),l=t?.repeat?H(c,o):V(c,o);return U(l,i),z.set(n,l),l}var q=2.1,se=.25,ce=32/1e3,J=new s,Y=new s,X=new ee,le=new s(0,1,0);function ue(e,t){let n=Number.isFinite(t)&&t>1e-6?t:4/3,r=Math.max(.01,Math.min(179.99,e))*Math.PI/180;return 2*Math.atan(Math.tan(r/2)/n)*180/Math.PI}function de(e){e.wrapS=g,e.wrapT=g,e.minFilter=m,e.magFilter=m,e.colorSpace=``,e.flipY=!1,e.image&&(e.needsUpdate=!0)}function fe(e,t){return t.set(e[1],e[2],e[0])}function pe(e,t){J.crossVectors(e,le),J.lengthSq()<1e-8&&J.set(-1,0,0),J.normalize(),Y.crossVectors(J,e).normalize(),X.set(J.x,e.x,Y.x,0,J.y,e.y,Y.y,0,J.z,e.z,Y.z,0,0,0,0,1),t.setFromRotationMatrix(X)}function me(e,t){if(e.length===0)return null;if(t<=e[0].time)return e[0];if(t>=e[e.length-1].time)return e[e.length-1];let n=0,r=e.length-1;for(;r-n>1;){let i=n+r>>1;e[i].time<=t?n=i:r=i}return e[n]}function he(e,t){let n=new Map;e.traverse(e=>{e.name&&n.set(e.name,e)});let r=[];for(let e of t.tracks){let t=e.name.lastIndexOf(`.`);if(t===-1)continue;let i=e.name.slice(0,t),o=e.name.slice(t+1),s=n.get(i);if(s){if(o===`quaternion`){let t=s.quaternion;r.push(new _(e.name,[0],[t.x,t.y,t.z,t.w]))}else if(o===`position`){let t=s.position;r.push(new a(e.name,[0],[t.x,t.y,t.z]))}else if(o===`scale`){let t=s.scale;r.push(new a(e.name,[0],[t.x,t.y,t.z]))}}}return new c(`_restPose`,0,r)}function Z(e,t,n,r){let a=e.clone(!0),o=t.find(e=>e.name===`Root`);if(o){let e=new f(a);if(e.clipAction(o).play(),r)for(let n of r){let r=t.find(e=>e.name.toLowerCase()===n.toLowerCase());if(r){let t=e.clipAction(r);t.time=r.duration/2,t.setEffectiveTimeScale(0),t.play()}}e.setTime(0)}a.updateMatrixWorld(!0);let c=null,l=null;return a.traverse(e=>{!c&&e.name===n&&(c=new s,l=new i,e.getWorldPosition(c),e.getWorldQuaternion(l))}),!c||!l?null:{position:c,quaternion:l}}function ge(e){e.computeVertexNormals();let t=e.attributes.position,n=e.attributes.normal;if(!t||!n)return;let r=t.array,i=n.array,a=new Map;for(let e=0;e<t.count;e++){let t=`${r[e*3].toFixed(4)},${r[e*3+1].toFixed(4)},${r[e*3+2].toFixed(4)}`;a.has(t)||a.set(t,[]),a.get(t).push(e)}for(let e of a.values())if(e.length>1){let t=0,n=0,r=0;for(let a of e)t+=i[a*3],n+=i[a*3+1],r+=i[a*3+2];let a=Math.sqrt(t*t+n*n+r*r);a>0&&(t/=a,n/=a,r/=a);for(let a of e)i[a*3]=t,i[a*3+1]=n,i[a*3+2]=r}n.needsUpdate=!0}function Q(e,t,n=!1,r={}){let i=e.userData?.resource_path,a=new Set(e.userData?.flag_names??[]),o=e.userData?.reflection_amount??1;if(!i){let t=new p({color:e.color,side:2,reflectivity:0});return j(t),{material:t}}let s=r.emap?o:0;if(a.has(`IflMaterial`)){let r=a.has(`SWrap`)||a.has(`TWrap`),o=M(e,null,a,n,t,!1,s);if(Array.isArray(o)){let e=o[1];return{material:e,backMaterial:o[0],initialize:(t,n)=>$(e,i,t,n,r)}}return{material:o,initialize:(e,t)=>$(o,i,e,t,r)}}let c=/[/\\]base\./i.test(i),l;if(c&&r.skinUrl)l=r.skinUrl;else if(c&&r.skinName&&r.skinName!==`base`){let e=i.replace(/\bbase\./i,`${r.skinName}.`);try{l=C(e,null)}catch{}}let u=!!l,d=b(l??C(i),void 0,u?()=>{b(C(i),e=>{d.image=e.image,d.needsUpdate=!0})}:void 0),f=a.has(`Translucent`);n||f?y(d,{disableMipmaps:!0,anisotropy:r.anisotropy}):y(d,{anisotropy:r.anisotropy});let m=M(e,d,a,n,t,!1,s);return Array.isArray(m)?{material:m[1],backMaterial:m[0]}:{material:m}}async function $(e,t,n,r,i=!1){let a=await K(`textures/${t}.ifl`,{repeat:i});e.map=a.texture,e.needsUpdate=!0;let o=!1,s=n.onBeforeRender;return n.onBeforeRender=function(...t){s?.apply(this,t),!o&&(W(a,G(a,r())),a.swapMode&&e.map!==a.texture&&(e.map=a.texture,e.needsUpdate=!0))},()=>{o=!0,n.onBeforeRender=s??(()=>{})}}function _e(e,t,n={}){let r=[],i=t?P(t):!1,a=[];e.traverse(e=>{if(!e.isMesh)return;if(e.material?.name===`Unassigned`){e.visible=!1;return}if(typeof e.userData?.dts_detail_size==`number`&&e.userData.dts_detail_size<0){e.visible=!1;return}(e.userData?.vis??1)<.01&&(e.visible=!1),e.geometry&&ge(e.geometry);let t=e.userData?.vis_sequence?1:e.userData?.vis??1;if(Array.isArray(e.material))e.material=e.material.map(o=>{let s=Q(o,t,i,n);if(s.initialize&&r.push({mesh:e,initialize:s.initialize}),s.backMaterial&&e.parent){let t=e.clone();t.material=s.backMaterial,a.push({parent:e.parent,mesh:t})}return s.material});else if(e.material){let o=Q(e.material,t,i,n);if(o.initialize&&r.push({mesh:e,initialize:o.initialize}),e.material=o.material,o.backMaterial&&e.parent){let t=e.clone();t.material=o.backMaterial,a.push({parent:e.parent,mesh:t})}}});for(let{parent:e,mesh:t}of a)e.add(t);return r}function ve(e){e.traverse(e=>{if(e.geometry&&e.geometry.dispose(),e.material){let t=Array.isArray(e.material)?e.material:[e.material];for(let e of t)e.dispose()}})}function ye(e){switch(e.toLowerCase()){case`player`:return`#00ff88`;case`vehicle`:return`#ff8800`;case`projectile`:return`#ff0044`;case`deployable`:return`#ffcc00`;default:return`#8888ff`}}export{E as S,W as _,ve as a,O as b,Z as c,pe as d,de as f,K as g,G as h,he as i,_e as l,fe as m,q as n,ye as o,ue as p,ce as r,me as s,se as t,Q as u,L as v,D as x,I as y};