From 46852f8b55a6accf0fc2834794bb15243d972003 Mon Sep 17 00:00:00 2001 From: ValerioSpagnoli Date: Mon, 9 Sep 2024 17:26:26 +0200 Subject: [PATCH] Updates --- assets/{index-DIGxXGBg.js => index-C76kgpPs.js} | 2 +- index.html | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) rename assets/{index-DIGxXGBg.js => index-C76kgpPs.js} (97%) diff --git a/assets/index-DIGxXGBg.js b/assets/index-C76kgpPs.js similarity index 97% rename from assets/index-DIGxXGBg.js rename to assets/index-C76kgpPs.js index 68e2707..9be1d19 100644 --- a/assets/index-DIGxXGBg.js +++ b/assets/index-C76kgpPs.js @@ -3843,4 +3843,4 @@ fflate - fast JavaScript compression/decompression Licensed under MIT. https://github.com/101arrowz/fflate/blob/master/LICENSE version 0.8.2 -*/var $t=Uint8Array,Ni=Uint16Array,k0=Int32Array,oh=new $t([0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0,0,0,0]),ch=new $t([0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13,0,0]),z0=new $t([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]),lh=function(r,e){for(var t=new Ni(31),n=0;n<31;++n)t[n]=e+=1<>1|(ot&21845)<<1;Hn=(Hn&52428)>>2|(Hn&13107)<<2,Hn=(Hn&61680)>>4|(Hn&3855)<<4,po[ot]=((Hn&65280)>>8|(Hn&255)<<8)>>1}var ps=function(r,e,t){for(var n=r.length,i=0,s=new Ni(e);i>c]=l}else for(o=new Ni(n),i=0;i>15-r[i]);return o},Es=new $t(288);for(var ot=0;ot<144;++ot)Es[ot]=8;for(var ot=144;ot<256;++ot)Es[ot]=9;for(var ot=256;ot<280;++ot)Es[ot]=7;for(var ot=280;ot<288;++ot)Es[ot]=8;var dh=new $t(32);for(var ot=0;ot<32;++ot)dh[ot]=5;var W0=ps(Es,9,1),X0=ps(dh,5,1),Ta=function(r){for(var e=r[0],t=1;te&&(e=r[t]);return e},on=function(r,e,t){var n=e/8|0;return(r[n]|r[n+1]<<8)>>(e&7)&t},Ea=function(r,e){var t=e/8|0;return(r[t]|r[t+1]<<8|r[t+2]<<16)>>(e&7)},j0=function(r){return(r+7)/8|0},q0=function(r,e,t){return(t==null||t>r.length)&&(t=r.length),new $t(r.subarray(e,t))},Y0=["unexpected EOF","invalid block type","invalid length/literal","invalid distance","stream finished","no stream handler",,"no callback","invalid UTF-8 data","extra field too long","date not in range 1980-2099","filename too long","stream finishing","invalid zip data"],cn=function(r,e,t){var n=new Error(e||Y0[r]);if(n.code=r,Error.captureStackTrace&&Error.captureStackTrace(n,cn),!t)throw n;return n},K0=function(r,e,t,n){var i=r.length,s=0;if(!i||e.f&&!e.l)return t||new $t(0);var a=!t,o=a||e.i!=2,c=e.i;a&&(t=new $t(i*3));var l=function(nt){var C=t.length;if(nt>C){var st=new $t(Math.max(C*2,nt));st.set(t),t=st}},u=e.f||0,h=e.p||0,d=e.b||0,f=e.l,_=e.d,g=e.m,m=e.n,p=i*8;do{if(!f){u=on(r,h,1);var b=on(r,h+1,3);if(h+=3,b)if(b==1)f=W0,_=X0,g=9,m=5;else if(b==2){var E=on(r,h,31)+257,A=on(r,h+10,15)+4,D=E+on(r,h+5,31)+1;h+=14;for(var w=new $t(D),y=new $t(19),P=0;P>4;if(x<16)w[P++]=x;else{var H=0,q=0;for(x==16?(q=3+on(r,h,3),h+=2,H=w[P-1]):x==17?(q=3+on(r,h,7),h+=3):x==18&&(q=11+on(r,h,127),h+=7);q--;)w[P++]=H}}var V=w.subarray(0,E),ie=w.subarray(E);g=Ta(V),m=Ta(ie),f=ps(V,g,1),_=ps(ie,m,1)}else cn(1);else{var x=j0(h)+4,M=r[x-4]|r[x-3]<<8,L=x+M;if(L>i){c&&cn(0);break}o&&l(d+M),t.set(r.subarray(x,L),d),e.b=d+=M,e.p=h=L*8,e.f=u;continue}if(h>p){c&&cn(0);break}}o&&l(d+131072);for(var oe=(1<>4;if(h+=H&15,h>p){c&&cn(0);break}if(H||cn(2),He<256)t[d++]=He;else if(He==256){Oe=h,f=null;break}else{var W=He-254;if(He>264){var P=He-257,J=oh[P];W=on(r,h,(1<>4;ce||cn(3),h+=ce&15;var ie=G0[ae];if(ae>3){var J=ch[ae];ie+=Ea(r,h)&(1<p){c&&cn(0);break}o&&l(d+131072);var Ae=d+W;if(d>4>7||(r[0]<<8|r[1])%31)&&cn(6,"invalid zlib data"),(r[1]>>5&1)==+!e&&cn(6,"invalid zlib data: "+(r[1]&32?"need":"unexpected")+" dictionary"),(r[1]>>3&4)+2};function J0(r,e){return K0(r.subarray($0(r,e),-4),{i:2},e,e)}var Q0=typeof TextDecoder<"u"&&new TextDecoder,ex=0;try{Q0.decode(Z0,{stream:!0}),ex=1}catch{}function fh(r,e,t){const n=t.length-r-1;if(e>=t[n])return n-1;if(e<=t[r])return r;let i=r,s=n,a=Math.floor((i+s)/2);for(;e=t[a+1];)e=g&&(_[f][0]=_[d][0]/o[b+1][p],m=_[f][0]*o[p][b]);const x=p>=-1?1:-p,M=h-1<=b?g-1:t-h;for(let E=x;E<=M;++E)_[f][E]=(_[d][E]-_[d][E-1])/o[b+1][p+E],m+=_[f][E]*o[p+E][b];h<=b&&(_[f][g]=-_[d][g-1]/o[b+1][h],m+=_[f][g]*o[h][b]),a[g][h]=m;const L=d;d=f,f=L}}let u=t;for(let h=1;h<=n;++h){for(let d=0;d<=t;++d)a[h][d]*=u;u*=t-h}return a}function sx(r,e,t,n,i){const s=i0,c=typeof s.Content=="string"&&s.Content!=="";if(o||c){const l=this.parseImage(n[i]);t[s.RelativeFilename||s.Filename]=l}}}}for(const n in e){const i=e[n];t[i]!==void 0?e[n]=t[i]:e[n]=e[n].split("\\").pop()}return e}parseImage(e){const t=e.Content,n=e.RelativeFilename||e.Filename,i=n.slice(n.lastIndexOf(".")+1).toLowerCase();let s;switch(i){case"bmp":s="image/bmp";break;case"jpg":case"jpeg":s="image/jpeg";break;case"png":s="image/png";break;case"tif":s="image/tiff";break;case"tga":this.manager.getHandler(".tga")===null&&console.warn("FBXLoader: TGA loader not found, skipping ",n),s="image/tga";break;default:console.warn('FBXLoader: Image type "'+i+'" is not supported.');return}if(typeof t=="string")return"data:"+s+";base64,"+t;{const a=new Uint8Array(t);return window.URL.createObjectURL(new Blob([a],{type:s}))}}parseTextures(e){const t=new Map;if("Texture"in Ve.Objects){const n=Ve.Objects.Texture;for(const i in n){const s=this.parseTexture(n[i],e);t.set(parseInt(i),s)}}return t}parseTexture(e,t){const n=this.loadTexture(e,t);n.ID=e.id,n.name=e.attrName;const i=e.WrapModeU,s=e.WrapModeV,a=i!==void 0?i.value:0,o=s!==void 0?s.value:0;if(n.wrapS=a===0?Jt:mn,n.wrapT=o===0?Jt:mn,"Scaling"in e){const c=e.Scaling.value;n.repeat.x=c[0],n.repeat.y=c[1]}if("Translation"in e){const c=e.Translation.value;n.offset.x=c[0],n.offset.y=c[1]}return n}loadTexture(e,t){const n=new Set(["tga","tif","tiff","exr","dds","hdr","ktx2"]),i=e.FileName.split(".").pop().toLowerCase(),s=n.has(i)?this.manager.getHandler(`.${i}`):this.textureLoader;if(!s)return console.warn(`FBXLoader: ${i.toUpperCase()} loader not found, creating placeholder texture for`,e.RelativeFilename),new St;const a=s.path;a||s.setPath(this.textureLoader.path);const o=_t.get(e.id).children;let c;o!==void 0&&o.length>0&&t[o[0].ID]!==void 0&&(c=t[o[0].ID],(c.indexOf("blob:")===0||c.indexOf("data:")===0)&&s.setPath(void 0));const l=s.load(c);return s.setPath(a),l}parseMaterials(e){const t=new Map;if("Material"in Ve.Objects){const n=Ve.Objects.Material;for(const i in n){const s=this.parseMaterial(n[i],e);s!==null&&t.set(parseInt(i),s)}}return t}parseMaterial(e,t){const n=e.id,i=e.attrName;let s=e.ShadingModel;if(typeof s=="object"&&(s=s.value),!_t.has(n))return null;const a=this.parseParameters(e,t,n);let o;switch(s.toLowerCase()){case"phong":o=new va;break;case"lambert":o=new Mg;break;default:console.warn('THREE.FBXLoader: unknown material type "%s". Defaulting to MeshPhongMaterial.',s),o=new va;break}return o.setValues(a),o.name=i,o}parseParameters(e,t,n){const i={};e.BumpFactor&&(i.bumpScale=e.BumpFactor.value),e.Diffuse?i.color=new ge().fromArray(e.Diffuse.value).convertSRGBToLinear():e.DiffuseColor&&(e.DiffuseColor.type==="Color"||e.DiffuseColor.type==="ColorRGB")&&(i.color=new ge().fromArray(e.DiffuseColor.value).convertSRGBToLinear()),e.DisplacementFactor&&(i.displacementScale=e.DisplacementFactor.value),e.Emissive?i.emissive=new ge().fromArray(e.Emissive.value).convertSRGBToLinear():e.EmissiveColor&&(e.EmissiveColor.type==="Color"||e.EmissiveColor.type==="ColorRGB")&&(i.emissive=new ge().fromArray(e.EmissiveColor.value).convertSRGBToLinear()),e.EmissiveFactor&&(i.emissiveIntensity=parseFloat(e.EmissiveFactor.value)),e.Opacity&&(i.opacity=parseFloat(e.Opacity.value)),i.opacity<1&&(i.transparent=!0),e.ReflectionFactor&&(i.reflectivity=e.ReflectionFactor.value),e.Shininess&&(i.shininess=e.Shininess.value),e.Specular?i.specular=new ge().fromArray(e.Specular.value).convertSRGBToLinear():e.SpecularColor&&e.SpecularColor.type==="Color"&&(i.specular=new ge().fromArray(e.SpecularColor.value).convertSRGBToLinear());const s=this;return _t.get(n).children.forEach(function(a){const o=a.relationship;switch(o){case"Bump":i.bumpMap=s.getTexture(t,a.ID);break;case"Maya|TEX_ao_map":i.aoMap=s.getTexture(t,a.ID);break;case"DiffuseColor":case"Maya|TEX_color_map":i.map=s.getTexture(t,a.ID),i.map!==void 0&&(i.map.colorSpace=Mt);break;case"DisplacementColor":i.displacementMap=s.getTexture(t,a.ID);break;case"EmissiveColor":i.emissiveMap=s.getTexture(t,a.ID),i.emissiveMap!==void 0&&(i.emissiveMap.colorSpace=Mt);break;case"NormalMap":case"Maya|TEX_normal_map":i.normalMap=s.getTexture(t,a.ID);break;case"ReflectionColor":i.envMap=s.getTexture(t,a.ID),i.envMap!==void 0&&(i.envMap.mapping=mr,i.envMap.colorSpace=Mt);break;case"SpecularColor":i.specularMap=s.getTexture(t,a.ID),i.specularMap!==void 0&&(i.specularMap.colorSpace=Mt);break;case"TransparentColor":case"TransparencyFactor":i.alphaMap=s.getTexture(t,a.ID),i.transparent=!0;break;case"AmbientColor":case"ShininessExponent":case"SpecularFactor":case"VectorDisplacementColor":default:console.warn("THREE.FBXLoader: %s map is not supported in three.js, skipping texture.",o);break}}),i}getTexture(e,t){return"LayeredTexture"in Ve.Objects&&t in Ve.Objects.LayeredTexture&&(console.warn("THREE.FBXLoader: layered textures are not supported in three.js. Discarding all but first layer."),t=_t.get(t).children[0].ID),e.get(t)}parseDeformers(){const e={},t={};if("Deformer"in Ve.Objects){const n=Ve.Objects.Deformer;for(const i in n){const s=n[i],a=_t.get(parseInt(i));if(s.attrType==="Skin"){const o=this.parseSkeleton(a,n);o.ID=i,a.parents.length>1&&console.warn("THREE.FBXLoader: skeleton attached to more than one geometry is not supported."),o.geometryID=a.parents[0].ID,e[i]=o}else if(s.attrType==="BlendShape"){const o={id:i};o.rawTargets=this.parseMorphTargets(a,n),o.id=i,a.parents.length>1&&console.warn("THREE.FBXLoader: morph target attached to more than one geometry is not supported."),t[i]=o}}}return{skeletons:e,morphTargets:t}}parseSkeleton(e,t){const n=[];return e.children.forEach(function(i){const s=t[i.ID];if(s.attrType!=="Cluster")return;const a={ID:i.ID,indices:[],weights:[],transformLink:new fe().fromArray(s.TransformLink.a)};"Indexes"in s&&(a.indices=s.Indexes.a,a.weights=s.Weights.a),n.push(a)}),{rawBones:n,bones:[]}}parseMorphTargets(e,t){const n=[];for(let i=0;i1?a=o:o.length>0?a=o[0]:(a=new va({name:In.DEFAULT_MATERIAL_NAME,color:13421772}),o.push(a)),"color"in s.attributes&&o.forEach(function(c){c.vertexColors=!0}),s.FBX_Deformer?(i=new Yl(s,a),i.normalizeSkinWeights()):i=new ye(s,a),i}createCurve(e,t){const n=e.children.reduce(function(s,a){return t.has(a.ID)&&(s=t.get(a.ID)),s},null),i=new Po({name:In.DEFAULT_MATERIAL_NAME,color:3342591,linewidth:1});return new Nr(n,i)}getTransformData(e,t){const n={};"InheritType"in t&&(n.inheritType=parseInt(t.InheritType.value)),"RotationOrder"in t?n.eulerOrder=_h(t.RotationOrder.value):n.eulerOrder="ZYX","Lcl_Translation"in t&&(n.translation=t.Lcl_Translation.value),"PreRotation"in t&&(n.preRotation=t.PreRotation.value),"Lcl_Rotation"in t&&(n.rotation=t.Lcl_Rotation.value),"PostRotation"in t&&(n.postRotation=t.PostRotation.value),"Lcl_Scaling"in t&&(n.scale=t.Lcl_Scaling.value),"ScalingOffset"in t&&(n.scalingOffset=t.ScalingOffset.value),"ScalingPivot"in t&&(n.scalingPivot=t.ScalingPivot.value),"RotationOffset"in t&&(n.rotationOffset=t.RotationOffset.value),"RotationPivot"in t&&(n.rotationPivot=t.RotationPivot.value),e.userData.transformData=n}setLookAtProperties(e,t){"LookAtProperty"in t&&_t.get(e.ID).children.forEach(function(i){if(i.relationship==="LookAtProperty"){const s=Ve.Objects.Model[i.ID];if("Lcl_Translation"in s){const a=s.Lcl_Translation.value;e.target!==void 0?(e.target.position.fromArray(a),Ft.add(e.target)):e.lookAt(new T().fromArray(a))}}})}bindSkeleton(e,t,n){const i=this.parsePoseNodes();for(const s in e){const a=e[s];_t.get(parseInt(a.ID)).parents.forEach(function(c){if(t.has(c.ID)){const l=c.ID;_t.get(l).parents.forEach(function(h){n.has(h.ID)&&n.get(h.ID).bind(new Ur(a.bones),i[h.ID])})}})}}parsePoseNodes(){const e={};if("Pose"in Ve.Objects){const t=Ve.Objects.Pose;for(const n in t)if(t[n].attrType==="BindPose"&&t[n].NbPoseNodes>0){const i=t[n].PoseNode;Array.isArray(i)?i.forEach(function(s){e[s.Node]=new fe().fromArray(s.Matrix.a)}):e[i.Node]=new fe().fromArray(i.Matrix.a)}}return e}addGlobalSceneSettings(){if("GlobalSettings"in Ve){if("AmbientColor"in Ve.GlobalSettings){const e=Ve.GlobalSettings.AmbientColor.value,t=e[0],n=e[1],i=e[2];if(t!==0||n!==0||i!==0){const s=new ge(t,n,i).convertSRGBToLinear();Ft.add(new sh(s,1))}}"UnitScaleFactor"in Ve.GlobalSettings&&(Ft.userData.unitScaleFactor=Ve.GlobalSettings.UnitScaleFactor.value)}}}class hx{constructor(){this.negativeMaterialIndices=!1}parse(e){const t=new Map;if("Geometry"in Ve.Objects){const n=Ve.Objects.Geometry;for(const i in n){const s=_t.get(parseInt(i)),a=this.parseGeometry(s,n[i],e);t.set(parseInt(i),a)}}return this.negativeMaterialIndices===!0&&console.warn("THREE.FBXLoader: The FBX file contains invalid (negative) material indices. The asset might not render as expected."),t}parseGeometry(e,t,n){switch(t.attrType){case"Mesh":return this.parseMeshGeometry(e,t,n);case"NurbsCurve":return this.parseNurbsGeometry(t)}}parseMeshGeometry(e,t,n){const i=n.skeletons,s=[],a=e.parents.map(function(h){return Ve.Objects.Model[h.ID]});if(a.length===0)return;const o=e.children.reduce(function(h,d){return i[d.ID]!==void 0&&(h=i[d.ID]),h},null);e.children.forEach(function(h){n.morphTargets[h.ID]!==void 0&&s.push(n.morphTargets[h.ID])});const c=a[0],l={};"RotationOrder"in c&&(l.eulerOrder=_h(c.RotationOrder.value)),"InheritType"in c&&(l.inheritType=parseInt(c.InheritType.value)),"GeometricTranslation"in c&&(l.translation=c.GeometricTranslation.value),"GeometricRotation"in c&&(l.rotation=c.GeometricRotation.value),"GeometricScaling"in c&&(l.scale=c.GeometricScaling.value);const u=mh(l);return this.genGeometry(t,o,s,u)}genGeometry(e,t,n,i){const s=new zt;e.attrName&&(s.name=e.attrName);const a=this.parseGeoNode(e,t),o=this.genBuffers(a),c=new gt(o.vertex,3);if(c.applyMatrix4(i),s.setAttribute("position",c),o.colors.length>0&&s.setAttribute("color",new gt(o.colors,3)),t&&(s.setAttribute("skinIndex",new Eo(o.weightsIndices,4)),s.setAttribute("skinWeight",new gt(o.vertexWeights,4)),s.FBX_Deformer=t),o.normal.length>0){const l=new Fe().getNormalMatrix(i),u=new gt(o.normal,3);u.applyNormalMatrix(l),s.setAttribute("normal",u)}if(o.uvs.forEach(function(l,u){const h=u===0?"uv":`uv${u}`;s.setAttribute(h,new gt(o.uvs[u],2))}),a.material&&a.material.mappingType!=="AllSame"){let l=o.materialIndex[0],u=0;if(o.materialIndex.forEach(function(h,d){h!==l&&(s.addGroup(u,d-u,l),l=h,u=d)}),s.groups.length>0){const h=s.groups[s.groups.length-1],d=h.start+h.count;d!==o.materialIndex.length&&s.addGroup(d,o.materialIndex.length-d,l)}s.groups.length===0&&s.addGroup(0,o.materialIndex.length,o.materialIndex[0])}return this.addMorphTargets(s,e,n,i),s}parseGeoNode(e,t){const n={};if(n.vertexPositions=e.Vertices!==void 0?e.Vertices.a:[],n.vertexIndices=e.PolygonVertexIndex!==void 0?e.PolygonVertexIndex.a:[],e.LayerElementColor&&(n.color=this.parseVertexColors(e.LayerElementColor[0])),e.LayerElementMaterial&&(n.material=this.parseMaterialIndices(e.LayerElementMaterial[0])),e.LayerElementNormal&&(n.normal=this.parseNormals(e.LayerElementNormal[0])),e.LayerElementUV){n.uv=[];let i=0;for(;e.LayerElementUV[i];)e.LayerElementUV[i].UV&&n.uv.push(this.parseUVs(e.LayerElementUV[i])),i++}return n.weightTable={},t!==null&&(n.skeleton=t,t.rawBones.forEach(function(i,s){i.indices.forEach(function(a,o){n.weightTable[a]===void 0&&(n.weightTable[a]=[]),n.weightTable[a].push({id:s,weight:i.weights[o]})})})),n}genBuffers(e){const t={vertex:[],normal:[],colors:[],uvs:[],materialIndex:[],vertexWeights:[],weightsIndices:[]};let n=0,i=0,s=!1,a=[],o=[],c=[],l=[],u=[],h=[];const d=this;return e.vertexIndices.forEach(function(f,_){let g,m=!1;f<0&&(f=f^-1,m=!0);let p=[],b=[];if(a.push(f*3,f*3+1,f*3+2),e.color){const x=ar(_,n,f,e.color);c.push(x[0],x[1],x[2])}if(e.skeleton){if(e.weightTable[f]!==void 0&&e.weightTable[f].forEach(function(x){b.push(x.weight),p.push(x.id)}),b.length>4){s||(console.warn("THREE.FBXLoader: Vertex has more than 4 skinning weights assigned to vertex. Deleting additional weights."),s=!0);const x=[0,0,0,0],M=[0,0,0,0];b.forEach(function(L,E){let A=L,D=p[E];M.forEach(function(w,y,P){if(A>w){P[y]=A,A=w;const z=x[y];x[y]=D,D=z}})}),p=x,b=M}for(;b.length<4;)b.push(0),p.push(0);for(let x=0;x<4;++x)u.push(b[x]),h.push(p[x])}if(e.normal){const x=ar(_,n,f,e.normal);o.push(x[0],x[1],x[2])}e.material&&e.material.mappingType!=="AllSame"&&(g=ar(_,n,f,e.material)[0],g<0&&(d.negativeMaterialIndices=!0,g=0)),e.uv&&e.uv.forEach(function(x,M){const L=ar(_,n,f,x);l[M]===void 0&&(l[M]=[]),l[M].push(L[0]),l[M].push(L[1])}),i++,m&&(d.genFace(t,e,a,g,o,c,l,u,h,i),n++,i=0,a=[],o=[],c=[],l=[],u=[],h=[])}),t}getNormalNewell(e){const t=new T(0,0,0);for(let n=0;n.5?new T(0,1,0):new T(0,0,1)).cross(t).normalize(),s=t.clone().cross(i).normalize();return{normal:t,tangent:i,bitangent:s}}flattenVertex(e,t,n){return new Ne(e.dot(t),e.dot(n))}genFace(e,t,n,i,s,a,o,c,l,u){let h;if(u>3){const d=[],f=t.baseVertexPositions||t.vertexPositions;for(let p=0;p1&&console.warn("THREE.FBXLoader: Encountered an animation stack with multiple layers, this is currently not supported. Ignoring subsequent layers.");const a=e.get(s[0].ID);n[i]={name:t[i].attrName,layer:a}}return n}addClip(e){let t=[];const n=this;return e.layer.forEach(function(i){t=t.concat(n.generateTracks(i))}),new Tr(e.name,-1,t)}generateTracks(e){const t=[];let n=new T,i=new T;if(e.transform&&e.transform.decompose(n,new pt,i),n=n.toArray(),i=i.toArray(),e.T!==void 0&&Object.keys(e.T.curves).length>0){const s=this.generateVectorTrack(e.modelName,e.T.curves,n,"position");s!==void 0&&t.push(s)}if(e.R!==void 0&&Object.keys(e.R.curves).length>0){const s=this.generateRotationTrack(e.modelName,e.R.curves,e.preRotation,e.postRotation,e.eulerOrder);s!==void 0&&t.push(s)}if(e.S!==void 0&&Object.keys(e.S.curves).length>0){const s=this.generateVectorTrack(e.modelName,e.S.curves,i,"scale");s!==void 0&&t.push(s)}if(e.DeformPercent!==void 0){const s=this.generateMorphTrack(e);s!==void 0&&t.push(s)}return t}generateVectorTrack(e,t,n,i){const s=this.getTimesForAllAxes(t),a=this.getKeyframeTrackValues(s,t,n);return new li(e+"."+i,s,a)}generateRotationTrack(e,t,n,i,s){let a,o;if(t.x!==void 0&&t.y!==void 0&&t.z!==void 0){const h=this.interpolateRotations(t.x,t.y,t.z,s);a=h[0],o=h[1]}n!==void 0&&(n=n.map(It.degToRad),n.push(s),n=new mt().fromArray(n),n=new pt().setFromEuler(n)),i!==void 0&&(i=i.map(It.degToRad),i.push(s),i=new mt().fromArray(i),i=new pt().setFromEuler(i).invert());const c=new pt,l=new mt,u=[];if(!o||!a)return new qn(e+".quaternion",[0],[0]);for(let h=0;h2&&new pt().fromArray(u,(h-3)/3*4).dot(c)<0&&c.set(-c.x,-c.y,-c.z,-c.w),c.toArray(u,h/3*4);return new qn(e+".quaternion",a,u)}generateMorphTrack(e){const t=e.DeformPercent.curves.morph,n=t.values.map(function(s){return s/100}),i=Ft.getObjectByName(e.modelName).morphTargetDictionary[e.morphName];return new ci(e.modelName+".morphTargetInfluences["+i+"]",t.times,n)}getTimesForAllAxes(e){let t=[];if(e.x!==void 0&&(t=t.concat(e.x.times)),e.y!==void 0&&(t=t.concat(e.y.times)),e.z!==void 0&&(t=t.concat(e.z.times)),t=t.sort(function(n,i){return n-i}),t.length>1){let n=1,i=t[0];for(let s=1;s=180||f[1]>=180||f[2]>=180){const g=Math.max(...f)/180,m=new mt(...l,i),p=new mt(...h,i),b=new pt().setFromEuler(m),x=new pt().setFromEuler(p);b.dot(x)&&x.set(-x.x,-x.y,-x.z,-x.w);const M=e.times[o-1],L=e.times[o]-M,E=new pt,A=new mt;for(let D=0;D<1;D+=1/g)E.copy(b.clone().slerp(x.clone(),D)),s.push(M+D*L),A.setFromQuaternion(E,i),a.push(A.x),a.push(A.y),a.push(A.z)}else s.push(e.times[o]),a.push(It.degToRad(e.values[o])),a.push(It.degToRad(t.values[o])),a.push(It.degToRad(n.values[o]))}return[s,a]}}class dx{getPrevNode(){return this.nodeStack[this.currentIndent-2]}getCurrentNode(){return this.nodeStack[this.currentIndent-1]}getCurrentProp(){return this.currentProp}pushStack(e){this.nodeStack.push(e),this.currentIndent+=1}popStack(){this.nodeStack.pop(),this.currentIndent-=1}setCurrentProp(e,t){this.currentProp=e,this.currentPropName=t}parse(e){this.currentIndent=0,this.allNodes=new ph,this.nodeStack=[],this.currentProp=[],this.currentPropName="";const t=this,n=e.split(/[\r\n]+/);return n.forEach(function(i,s){const a=i.match(/^[\s\t]*;/),o=i.match(/^[\s\t]*$/);if(a||o)return;const c=i.match("^\\t{"+t.currentIndent+"}(\\w+):(.*){",""),l=i.match("^\\t{"+t.currentIndent+"}(\\w+):[\\s\\t\\r\\n](.*)"),u=i.match("^\\t{"+(t.currentIndent-1)+"}}");c?t.parseNodeBegin(i,c):l?t.parseNodeProperty(i,l,n[++s]):u?t.popStack():i.match(/^[^\s\t}]/)&&t.parseNodePropertyContinued(i)}),this.allNodes}parseNodeBegin(e,t){const n=t[1].trim().replace(/^"/,"").replace(/"$/,""),i=t[2].split(",").map(function(c){return c.trim().replace(/^"/,"").replace(/"$/,"")}),s={name:n},a=this.parseNodeAttr(i),o=this.getCurrentNode();this.currentIndent===0?this.allNodes.add(n,s):n in o?(n==="PoseNode"?o.PoseNode.push(s):o[n].id!==void 0&&(o[n]={},o[n][o[n].id]=o[n]),a.id!==""&&(o[n][a.id]=s)):typeof a.id=="number"?(o[n]={},o[n][a.id]=s):n!=="Properties70"&&(n==="PoseNode"?o[n]=[s]:o[n]=s),typeof a.id=="number"&&(s.id=a.id),a.name!==""&&(s.attrName=a.name),a.type!==""&&(s.attrType=a.type),this.pushStack(s)}parseNodeAttr(e){let t=e[0];e[0]!==""&&(t=parseInt(e[0]),isNaN(t)&&(t=e[0]));let n="",i="";return e.length>1&&(n=e[1].replace(/^(\w+)::/,""),i=e[2]),{id:t,name:n,type:i}}parseNodeProperty(e,t,n){let i=t[1].replace(/^"/,"").replace(/"$/,"").trim(),s=t[2].replace(/^"/,"").replace(/"$/,"").trim();i==="Content"&&s===","&&(s=n.replace(/"/g,"").replace(/,$/,"").trim());const a=this.getCurrentNode();if(a.name==="Properties70"){this.parseNodeSpecialProperty(e,i,s);return}if(i==="C"){const c=s.split(",").slice(1),l=parseInt(c[0]),u=parseInt(c[1]);let h=s.split(",").slice(3);h=h.map(function(d){return d.trim().replace(/^"/,"")}),i="connections",s=[l,u],xx(s,h),a[i]===void 0&&(a[i]=[])}i==="Node"&&(a.id=s),i in a&&Array.isArray(a[i])?a[i].push(s):i!=="a"?a[i]=s:a.a=s,this.setCurrentProp(a,i),i==="a"&&s.slice(-1)!==","&&(a.a=Ra(s))}parseNodePropertyContinued(e){const t=this.getCurrentNode();t.a+=e,e.slice(-1)!==","&&(t.a=Ra(t.a))}parseNodeSpecialProperty(e,t,n){const i=n.split('",').map(function(u){return u.trim().replace(/^\"/,"").replace(/\s/,"_")}),s=i[0],a=i[1],o=i[2],c=i[3];let l=i[4];switch(a){case"int":case"enum":case"bool":case"ULongLong":case"double":case"Number":case"FieldOfView":l=parseFloat(l);break;case"Color":case"ColorRGB":case"Vector3D":case"Lcl_Translation":case"Lcl_Rotation":case"Lcl_Scaling":l=Ra(l);break}this.getPrevNode()[s]={type:a,type2:o,flag:c,value:l},this.setCurrentProp(this.getPrevNode(),s)}}class fx{parse(e){const t=new _l(e);t.skip(23);const n=t.getUint32();if(n<6400)throw new Error("THREE.FBXLoader: FBX version not supported, FileVersion: "+n);const i=new ph;for(;!this.endOfContent(t);){const s=this.parseNode(t,n);s!==null&&i.add(s.name,s)}return i}endOfContent(e){return e.size()%16===0?(e.getOffset()+160+16&-16)>=e.size():e.getOffset()+160+16>=e.size()}parseNode(e,t){const n={},i=t>=7500?e.getUint64():e.getUint32(),s=t>=7500?e.getUint64():e.getUint32();t>=7500?e.getUint64():e.getUint32();const a=e.getUint8(),o=e.getString(a);if(i===0)return null;const c=[];for(let d=0;d0?c[0]:"",u=c.length>1?c[1]:"",h=c.length>2?c[2]:"";for(n.singleProperty=s===1&&e.getOffset()===i;i>e.getOffset();){const d=this.parseNode(e,t);d!==null&&this.parseSubNode(o,n,d)}return n.propertyList=c,typeof l=="number"&&(n.id=l),u!==""&&(n.attrName=u),h!==""&&(n.attrType=h),o!==""&&(n.name=o),n}parseSubNode(e,t,n){if(n.singleProperty===!0){const i=n.propertyList[0];Array.isArray(i)?(t[n.name]=n,n.a=i):t[n.name]=i}else if(e==="Connections"&&n.name==="C"){const i=[];n.propertyList.forEach(function(s,a){a!==0&&i.push(s)}),t.connections===void 0&&(t.connections=[]),t.connections.push(i)}else if(n.name==="Properties70")Object.keys(n).forEach(function(s){t[s]=n[s]});else if(e==="Properties70"&&n.name==="P"){let i=n.propertyList[0],s=n.propertyList[1];const a=n.propertyList[2],o=n.propertyList[3];let c;i.indexOf("Lcl ")===0&&(i=i.replace("Lcl ","Lcl_")),s.indexOf("Lcl ")===0&&(s=s.replace("Lcl ","Lcl_")),s==="Color"||s==="ColorRGB"||s==="Vector"||s==="Vector3D"||s.indexOf("Lcl_")===0?c=[n.propertyList[4],n.propertyList[5],n.propertyList[6]]:c=n.propertyList[4],t[i]={type:s,type2:a,flag:o,value:c}}else t[n.name]===void 0?typeof n.id=="number"?(t[n.name]={},t[n.name][n.id]=n):t[n.name]=n:n.name==="PoseNode"?(Array.isArray(t[n.name])||(t[n.name]=[t[n.name]]),t[n.name].push(n)):t[n.name][n.id]===void 0&&(t[n.name][n.id]=n)}parseProperty(e){const t=e.getString(1);let n;switch(t){case"C":return e.getBoolean();case"D":return e.getFloat64();case"F":return e.getFloat32();case"I":return e.getInt32();case"L":return e.getInt64();case"R":return n=e.getUint32(),e.getArrayBuffer(n);case"S":return n=e.getUint32(),e.getString(n);case"Y":return e.getInt16();case"b":case"c":case"d":case"f":case"i":case"l":const i=e.getUint32(),s=e.getUint32(),a=e.getUint32();if(s===0)switch(t){case"b":case"c":return e.getBooleanArray(i);case"d":return e.getFloat64Array(i);case"f":return e.getFloat32Array(i);case"i":return e.getInt32Array(i);case"l":return e.getInt64Array(i)}const o=J0(new Uint8Array(e.getArrayBuffer(a))),c=new _l(o.buffer);switch(t){case"b":case"c":return c.getBooleanArray(i);case"d":return c.getFloat64Array(i);case"f":return c.getFloat32Array(i);case"i":return c.getInt32Array(i);case"l":return c.getInt64Array(i)}break;default:throw new Error("THREE.FBXLoader: Unknown property type "+t)}}}class _l{constructor(e,t){this.dv=new DataView(e),this.offset=0,this.littleEndian=t!==void 0?t:!0,this._textDecoder=new TextDecoder}getOffset(){return this.offset}size(){return this.dv.buffer.byteLength}skip(e){this.offset+=e}getBoolean(){return(this.getUint8()&1)===1}getBooleanArray(e){const t=[];for(let n=0;n=0&&(n=new Uint8Array(this.dv.buffer,t,i)),this._textDecoder.decode(n)}}class ph{add(e,t){this[e]=t}}function px(r){const e="Kaydara FBX Binary \0";return r.byteLength>=e.length&&e===gh(r,0,e.length)}function mx(r){const e=["K","a","y","d","a","r","a","\\","F","B","X","\\","B","i","n","a","r","y","\\","\\"];let t=0;function n(i){const s=r[i-1];return r=r.slice(t+i),t++,s}for(let i=0;i{t.scale.setScalar(this._normalScale),t.traverse(s=>{s.castShadow=!0}),t.position.set(0,0,190),t.rotation.y=0,this._target=t,this._params.scene.add(this._target),this._mixer=new ko(this._target),this._manager=new Do,this._manager.onLoad=()=>{this._stateMachine.SetState("idle")};const n=(s,a)=>{const o=a.animations[0],c=this._mixer.clipAction(o);this._animations[s]={clip:o,action:c}},i=new Er(this._manager);i.setPath("./models/knight/"),i.load("walk.fbx",s=>{n("walk",s)}),i.load("run.fbx",s=>{n("run",s)}),i.load("idle.fbx",s=>{n("idle",s)}),i.load("attack_1.fbx",s=>{n("attack_1",s)}),i.load("attack_2.fbx",s=>{n("attack_2",s)}),i.load("death.fbx",s=>{n("death",s)})})}get position(){return this._position}get previousPosition(){return this._previousPosition}get rotation(){return this._target?this._target.quaternion:new pt}set rotation(e){this._target&&this._target.quaternion.copy(e)}get keyPressed(){const e=this._input._keys;return{w:e.forward,a:e.left,s:e.backward,d:e.right,shift:e.shift,space:e.space}}get hitFlag(){return this._hitFlag}set hitFlag(e){this._hitFlag=e}get hitDirection(){return this._hitDirection}set hitDirection(e){this._hitDirection=e}get hitIntensity(){return this._hitIntensity}set hitIntensity(e){this._hitIntensity=e}get damage(){return this._damage}get attackRange(){return this._attackRange}get transformed(){return this._transformed}get timeTransformed(){return this._timeTransformed}get transformationTime(){return this._transformationTime}_PlayerMovementHandler(e){const t=this._velocity,n=new T(t.x*this._decceleration.x,t.y*this._decceleration.y,t.z*this._decceleration.z);n.multiplyScalar(e),n.z=Math.sign(n.z)*Math.min(Math.abs(n.z),Math.abs(t.z)),t.add(n);const i=this._target,s=new pt,a=new T,o=i.quaternion.clone(),c=this._acceleration.clone();this._input._keys.shift&&c.multiplyScalar(3),this._input._keys.forward&&(t.z+=c.z*e),this._input._keys.backward&&(t.z-=c.z*e),this._input._keys.left&&(a.set(0,1,0),s.setFromAxisAngle(a,4*Math.PI*e*this._acceleration.y),o.multiply(s)),this._input._keys.right&&(a.set(0,1,0),s.setFromAxisAngle(a,4*-Math.PI*e*this._acceleration.y),o.multiply(s)),i.quaternion.copy(o);const l=new T;l.copy(i.position);const u=new T(0,0,1);u.applyQuaternion(i.quaternion),u.normalize(),u.multiplyScalar(t.z*e),i.position.add(u);const h=new T(1,0,0);h.applyQuaternion(i.quaternion),h.normalize(),h.multiplyScalar(t.x*e),i.position.add(h),this._worldBoundingBoxes.map(d=>{new bt().setFromObject(d).containsPoint(i.position)&&i.position.copy(l)}),this._position.copy(i.position),this._previousPosition.copy(l)}_DeathHandler(){this._params.healthBar.hearts.length===0&&this._stateMachine.SetState("death")}_HitHandler(){if(this._hitFlag){const e=Math.random()<.5?-1:1;this._target.rotation.y+=Math.PI/40*e;const t=this._target.position.z-this._hitDirection.z*this._hitIntensity;let n=!0;for(const i of this._params.world.boundingBoxes)if(new bt().setFromObject(i).containsPoint(new T(this._target.position.x,this._target.position.y,t))){n=!1;break}n&&(this._target.position.z=t),this._hitTime=Date.now()}}_TransformationHandler(){if(this._normalDamage=this._params.powerBar.swords.length,this._bigDamage=this._params.powerBar.swords.length*2,this._params.starCounter.stars>=this._starsToGetBigger&&!this._transformed){if(this._transformed=!0,this._timeTransformed=Date.now(),this._params.starCounter.stars=0,this._target.scale.setScalar(this._bigScale),this._damage=this._bigDamage,this._attackRange=this._bigAttackRange,this._params.healthBar.hearts.length<10){const e=this._params.healthBar.hearts.length;for(let t=0;t<10-e;t++)this._params.healthBar.addHeart()}this._particleSpawner.create({x:this._position.x-10,y:this._position.y,z:this._position.z-10,width:15,height:30,depth:15},300)}if(this._transformed&&Date.now()-this._timeTransformed>this._transformationTime&&(this._transformed=!1,this._timeTransformed=0,this._target.scale.setScalar(this._normalScale),this._damage=this._normalDamage,this._attackRange=this._normalAttackRange,this._params.powerBar.swords.length>1))for(let e=0;ethis._onKeyDown(e),!1),document.addEventListener("keyup",e=>this._onKeyUp(e),!1)}_onKeyDown(e){switch(e.keyCode){case 87:this._keys.forward=!0;break;case 65:this._keys.left=!0;break;case 83:this._keys.backward=!0;break;case 68:this._keys.right=!0;break;case 32:this._keys.space=!0;break;case 16:this._keys.shift=!0;break;case 17:this._keys.ctrl=!0;break}}_onKeyUp(e){switch(e.keyCode){case 87:this._keys.forward=!1;break;case 65:this._keys.left=!1;break;case 83:this._keys.backward=!1;break;case 68:this._keys.right=!1;break;case 32:this._keys.space=!1;break;case 16:this._keys.shift=!1;break;case 17:this._keys.ctrl=!1;break}}}class Lx{constructor(e){this._params=e,this._camera=e.camera,this._currentPosition=new T,this._currentLookat=new T}_CalculateIdealOffset(){const e=new T(-5,20,-30);return e.applyQuaternion(this._params.target.rotation),e.add(this._params.target.position),e}_CalculateIdealLookat(){const e=new T(0,10,50);return e.applyQuaternion(this._params.target.rotation),e.add(this._params.target.position),e}Update(e){const t=this._CalculateIdealOffset(),n=this._CalculateIdealLookat(),i=1-Math.pow(.001,e);this._currentPosition.lerp(t,i),this._currentLookat.lerp(n,i),this._camera.position.copy(this._currentPosition),this._camera.lookAt(this._currentLookat)}}class Ix{constructor(e){this._params=e,this._stars=[],this._lastSpawnTime=0,this._spawnInterval=12,this._maxstars=5,this._worldBoundingBoxes=[];for(const t of this._params.world.boundingBoxes)this._worldBoundingBoxes.push(t)}_LoadModels(){const e=new Yi;this._lastSpawnTime=Date.now(),e.load("./models/scene_objects/star.glb",t=>{t.scene.traverse(l=>{l.castShadow=!0});const n=t.scene;n.scale.set(3,3,3);let i=new T,s=!1;const a=new ze(230,50,150),o=new Le({color:65280,wireframe:!0,visible:!1}),c=new ye(a,o);for(c.position.set(0,25,-130),this._params.scene.add(c),this._worldBoundingBoxes.push(c);!s;){i.x=Math.random()*200-100,i.y=1,i.z=Math.random()*200-100,s=!0;for(const l of this._worldBoundingBoxes)if(new bt().setFromObject(l).containsPoint(i)){s=!1;break}}n.position.set(i.x,i.y,i.z),this._params.scene.add(n),this._stars.push(n)})}Update(e){Date.now()-this._lastSpawnTime>this._spawnInterval*1e3&&this._stars.length{t.rotation.y+=1*e})}get stars(){return this._stars}set stars(e){this._stars=e}}class Dx{constructor(e){this._params=e,this._hearts=[],this._lastSpawnTime=0,this._spawnInterval=18,this._maxHearts=5,this._worldBoundingBoxes=[];for(const t of this._params.world.boundingBoxes)this._worldBoundingBoxes.push(t)}_LoadModels(){const e=new Yi;this._lastSpawnTime=Date.now(),e.load("./models/scene_objects/heart.glb",t=>{t.scene.traverse(l=>{l.castShadow=!0});const n=t.scene;n.scale.set(5,5,5);let i=new T,s=!1;const a=new ze(230,50,150),o=new Le({color:65280,wireframe:!0,visible:!1}),c=new ye(a,o);for(c.position.set(0,25,-130),this._params.scene.add(c),this._worldBoundingBoxes.push(c);!s;){i.x=Math.random()*200-100,i.y=4,i.z=Math.random()*200-100,s=!0;for(const l of this._worldBoundingBoxes)if(new bt().setFromObject(l).containsPoint(i)){s=!1;break}}n.position.set(i.x,i.y,i.z),this._params.scene.add(n),this._hearts.push(n)})}Update(e){Date.now()-this._lastSpawnTime>this._spawnInterval*1e3&&this._hearts.length{t.rotation.y+=1*e})}get hearts(){return this._hearts}set hearts(e){this._hearts=e}}class Ux{constructor(e){this._params=e,this._swords=[],this._lastSpawnTime=0,this._spawnInterval=20,this._maxSwords=5,this._worldBoundingBoxes=[];for(const t of this._params.world.boundingBoxes)this._worldBoundingBoxes.push(t)}_LoadModels(){const e=new Yi;this._lastSpawnTime=Date.now(),e.load("./models/scene_objects/sword.glb",t=>{t.scene.traverse(l=>{l.castShadow=!0});const n=t.scene;n.scale.set(20,20,20);let i=new T,s=!1;const a=new ze(230,50,150),o=new Le({color:65280,wireframe:!0,visible:!1}),c=new ye(a,o);for(c.position.set(0,25,-130),this._params.scene.add(c),this._worldBoundingBoxes.push(c);!s;){i.x=Math.random()*200-100,i.y=4,i.z=Math.random()*200-100,s=!0;for(const l of this._worldBoundingBoxes)if(new bt().setFromObject(l).containsPoint(i)){s=!1;break}}n.position.set(i.x,i.y,i.z),n.rotation.x=Math.PI/4,this._params.scene.add(n),this._swords.push(n)})}Update(e){Date.now()-this._lastSpawnTime>this._spawnInterval*1e3&&this._swords.length{t.rotation.z+=1*e})}get swords(){return this._swords}set swords(e){this._swords=e}}class Nx{constructor(e){this._params=e,this._mobs=[],this._worldBoundingBoxes=[];for(const t of this._params.world.boundingBoxes)this._worldBoundingBoxes.push(t);this._playerPosition=this._params.playerPosition,this._mobAttackDistance=6,this._mobAttackTime=this._params.mobAttackTime,this._lastSpawnTime=0,this._minNumberOfMobs=12,this._LoadModels()}get mobs(){return this._mobs}get mobAttackDistance(){return this._mobAttackDistance}get mobAttackTime(){return this._mobAttackTime}_LoadModels(){const e=new Yi;this._mobPositions=[],this._mobPositions.push(new T(0,1,-20)),this._mobPositions.push(new T(0,1,110)),this._mobPositions.push(new T(-50,1,30)),this._mobPositions.push(new T(50,1,30)),this._mobPositions.push(new T(80,1,130)),this._mobPositions.push(new T(-80,1,130)),this._mobPositions.push(new T(-150,1,100)),this._mobPositions.push(new T(150,1,100)),this._mobPositions.push(new T(-110,1,50)),this._mobPositions.push(new T(110,1,50)),this._mobPositions.push(new T(-120,1,0)),this._mobPositions.push(new T(120,1,0));const t=this._mobPositions.length;for(let l=0;l{i.scene.traverse(h=>{h.castShadow=!0});const s=i.scene;s.scale.set(4,4,4),s.position.set(t.x,t.y,t.z),this._params.scene.add(s),n.mob=s,n.position=s.position,n.rotation=s.rotation,n.velocity=new T(0,0,1);const a=new ko(s),o=a.clipAction(i.animations[6]),c=a.clipAction(i.animations[5]),l=a.clipAction(i.animations[0]),u=a.clipAction(i.animations[1]);o.play(),n.walk=o,n.run=c,n.attack=l,n.dead=u,n.currentAction=o,n.mixer=a,this._walkY=s.position.y-1,this._runY=s.position.y-1.2,this._mobs.push(n)})}update(e){if(Date.now()-this._lastSpawnTime>1e4&&this._mobs.lengthn.mixer))t.update(e);for(const t of this._mobs){const n=this._playerPosition.distanceTo(t.position);let i=!1;for(const s of this._worldBoundingBoxes)if(new bt().setFromObject(s).containsPoint(this._playerPosition)){i=!0;break}t.currentAction!==t.dead&&(n<40&&!i?this.moveMobTowardsPlayer(t):this.moveMobRandomly(t)),t.life<=0&&this.dead(t)}}moveMobTowardsPlayer(e){const t=e.position,n=e.velocity,i=this._playerPosition.distanceTo(t);let s=!1;for(const a of this._worldBoundingBoxes)if(new bt().setFromObject(a).containsPoint(t)){s=!0;break}if(i5e3&&(n.set(Math.random(),0,Math.random()).normalize().multiplyScalar(.1),e.time=s);for(const c of this._worldBoundingBoxes)new bt().setFromObject(c).containsPoint(t)&&(n.set(-n.x,0,-n.z).normalize().multiplyScalar(.1),e.time=s);t.add(n),t.y=this._walkY;const o=Math.atan2(n.x,n.z);e.mob.rotation.y=o}dead(e){e.deadFlag?new Date().getTime()-e.deadTime>1e4?(this._params.scene.remove(e.mob),this._mobs=this._mobs.filter(t=>t!==e)):e.currentAction.time>e.currentAction.getClip().duration-.1&&(e.currentAction.paused=!0):(e.currentAction.stop(),e.currentAction=e.dead,e.currentAction.play(),e.deadFlag=!0,e.deadTime=new Date().getTime())}}class Fx{constructor(e){this._params=e,this._animations={},this._stateMachine=new kx(new Ox(this._animations)),this._velocity=new T,this._position=new T,this._previousPosition=new T,this._worldBoundingBoxes=[];for(const t of this._params.world.boundingBoxes)this._worldBoundingBoxes.push(t);this._playerPosition=this._params.playerPosition,this._monsterAttackRange={min:15,max:20},this._monsterAttackTime=this._params.monsterAttackTime,this._LoadModel(),this._timeLastWalk=0,this._timeLastIdle=0,this._timeLastAttack=0,this._timeLastRoar=0,this._monsterLife=100,this._monsterDamage=2,this._monsterLastHit=0,this._monsterState="roar"}get monsterAttackRange(){return this._monsterAttackRange}get monsterAttackTime(){return this._monsterAttackTime}get monsterDamage(){return this._monsterDamage}set monsterDamage(e){this._monsterDamage=e}get monsterLife(){return this._monsterLife}set monsterLife(e){this._monsterLife=e}get monsterLastHit(){return this._monsterLastHit}set monsterLastHit(e){this._monsterLastHit=e}get monsterPosition(){return this._position}get monsterState(){return this._monsterState}_LoadModel(){const e=new Er;e.setPath("./models/monster/"),e.load("monster.fbx",o=>{o.scale.setScalar(.06),o.traverse(d=>{d.castShadow=!0}),o.position.set(0,0,-140),o.rotation.y=0,o.scale.set(.13,.13,.13);const l=new Ss().load("./models/monster/monster_texture.png");o.traverse(d=>{d.isMesh&&(d.material.map=l)}),this._target=o,this._params.scene.add(this._target),this._position=this._target.position,this._previousPosition=this._target.position,this._rotation=this._target.rotation,this._velocity=new T(0,0,0),this._mixer=new ko(this._target),this._manager=new Do,this._manager.onLoad=()=>{this._stateMachine.SetState("idle")};const u=(d,f)=>{const _=f.animations[0],g=this._mixer.clipAction(_);this._animations[d]={clip:_,action:g}},h=new Er(this._manager);h.setPath("./models/monster/"),h.load("walk.fbx",d=>{u("walk",d)}),h.load("idle.fbx",d=>{u("idle",d)}),h.load("roar.fbx",d=>{u("roar",d)}),h.load("attack_1.fbx",d=>{u("attack_1",d)}),h.load("attack_2.fbx",d=>{u("attack_2",d)}),h.load("death.fbx",d=>{u("death",d)})});const t=new ze(30,50,10),n=new Le({color:65280,wireframe:!0,visible:!1}),i=new ye(t,n);i.position.set(0,25,-70),this._params.scene.add(i),this._worldBoundingBoxes.push(i);const s=new ze(201,50,100),a=new Le({color:65280,wireframe:!0,visible:!1});this._insideTowers=new ye(s,a),this._insideTowers.position.set(1,25,-145),this._params.scene.add(this._insideTowers)}update(e){this._stateMachine._currentState&&(this._stateMachine._currentState.Update(e),this._monsterLife<=0&&this._monsterState!=="death"?(this._stateMachine.SetState("death"),this._monsterState="death"):new bt().setFromObject(this._insideTowers).containsPoint(this._playerPosition)?this.attackPlayer():this.moveMonsterRandomly(e),this._mixer&&this._mixer.update(e))}moveMonsterRandomly(e){if(this._timeLastAttack=0,this._timeLastRoar=0,(this._stateMachine._currentState.Name==="attack_1"||this._stateMachine._currentState.Name==="attack_2")&&(this._stateMachine.SetState("idle"),this._monsterState="idle",this._timeLastIdle=Date.now()),this._stateMachine._currentState.Name==="idle"&&Date.now()-this._timeLastIdle>5e3?(this._stateMachine.SetState("walk"),this._monsterState="walk",this._timeLastWalk=Date.now(),this._velocity.set(Math.random()*2-1,0,Math.random()*2-1),this._velocity.normalize().multiplyScalar(.2)):this._stateMachine._currentState.Name==="walk"&&Date.now()-this._timeLastWalk>5e3&&(this._stateMachine.SetState("idle"),this._monsterState="idle",this._timeLastIdle=Date.now()),this._stateMachine._currentState.Name==="walk"){for(const n of this._worldBoundingBoxes)if(new bt().setFromObject(n).containsPoint(this._position)){this._velocity.set(-this._velocity.x,0,-this._velocity.z),this._position=this._previousPosition;break}this._position.add(this._velocity);const t=Math.atan2(this._velocity.x,this._velocity.z);this._rotation.y=t}}attackPlayer(){const e=this._playerPosition.distanceTo(this._position);if(this._timeLastAttack===0&&(this._timeLastAttack=Date.now()),this._timeLastRoar===0&&(this._timeLastRoar=Date.now()),ethis._monsterAttackRange.max){this._stateMachine.SetState("walk"),this._velocity.copy(this._playerPosition).sub(this._position).normalize().multiplyScalar(.2),this._position.add(this._velocity);const t=Math.atan2(this._playerPosition.x-this._position.x,this._playerPosition.z-this._position.z);this._rotation.y=t}else{const t=Math.atan2(this._playerPosition.x-this._position.x,this._playerPosition.z-this._position.z);this._rotation.y=t,(this._stateMachine._currentState.Name==="roar"||this._stateMachine._currentState.Name==="walk")&&Date.now()-this._timeLastRoar>2500?(this._stateMachine.SetState("attack_1"),this._timeLastAttack=Date.now(),this._monsterState="attack",this._monsterLastHit=Date.now()):(this._stateMachine._currentState.Name==="attack_1"||this._stateMachine._currentState.Name==="attack_2")&&Date.now()-this._timeLastAttack>2500&&(this._stateMachine.SetState("roar"),this._timeLastRoar=Date.now(),this._monsterState="roar")}}}class Ox{constructor(e){this._animations=e}get animations(){return this._animations}}class Bx{constructor(){this._states={},this._currentState=null}_AddState(e,t){this._states[e]=t}SetState(e){const t=this._currentState;if(t){if(t.Name==e)return;t.Exit()}const n=new this._states[e](this);this._currentState=n,n.Enter(t)}Update(e){this._currentState&&this._currentState.Update(e)}}class kx extends Bx{constructor(e){super(),this._proxy=e,this._Init()}_Init(){this._AddState("idle",zx),this._AddState("walk",Hx),this._AddState("roar",Vx),this._AddState("attack_1",Gx),this._AddState("attack_2",Wx),this._AddState("death",Xx)}}class Qi{constructor(e){this._parent=e}Enter(){}Exit(){}Update(){}}class zx extends Qi{constructor(e){super(e)}get Name(){return"idle"}Enter(e){const t=this._parent._proxy._animations.idle.action;if(e){const n=this._parent._proxy._animations[e.Name].action;t.time=0,t.enabled=!0,t.setEffectiveTimeScale(1),t.setEffectiveWeight(1),t.crossFadeFrom(n,.5,!0),t.play()}else t.play()}Exit(){}Update(e){}}class Hx extends Qi{constructor(e){super(e)}get Name(){return"walk"}Enter(e){const t=this._parent._proxy._animations.walk.action;if(e){const n=this._parent._proxy._animations[e.Name].action;if(t.enabled=!0,e.Name=="idle"){const i=t.getClip().duration/n.getClip().duration;t.time=n.time*i}else t.time=0,t.setEffectiveTimeScale(1),t.setEffectiveWeight(1);t.crossFadeFrom(n,.5,!0),t.play()}else t.play()}Exit(){}Update(e){}}class Vx extends Qi{constructor(e){super(e)}get Name(){return"roar"}Enter(e){const t=this._parent._proxy._animations.roar.action;if(e){const n=this._parent._proxy._animations[e.Name].action;if(t.enabled=!0,e.Name=="idle"){const i=t.getClip().duration/n.getClip().duration;t.time=n.time*i}else t.time=0,t.setEffectiveTimeScale(1),t.setEffectiveWeight(1);t.crossFadeFrom(n,.5,!0),t.play()}else t.play()}Exit(){}Update(e){}}class Gx extends Qi{constructor(e){super(e)}get Name(){return"attack_1"}Enter(e){const t=this._parent._proxy._animations.attack_1.action;if(e){const n=this._parent._proxy._animations[e.Name].action;if(t.enabled=!0,e.Name=="idle"){const i=t.getClip().duration/n.getClip().duration;t.time=n.time*i}else t.time=0,t.setEffectiveTimeScale(1),t.setEffectiveWeight(1);t.crossFadeFrom(n,.5,!0),t.play()}else t.play()}Exit(){}Update(e){}}class Wx extends Qi{constructor(e){super(e)}get Name(){return"attack_2"}Enter(e){const t=this._parent._proxy._animations.attack_2.action;if(e){const n=this._parent._proxy._animations[e.Name].action;if(t.enabled=!0,e.Name=="idle"){const i=t.getClip().duration/n.getClip().duration;t.time=n.time*i}else t.time=0,t.setEffectiveTimeScale(1),t.setEffectiveWeight(1);t.crossFadeFrom(n,.5,!0),t.play()}else t.play()}Exit(){}Update(e){}}class Xx extends Qi{constructor(e){super(e)}get Name(){return"death"}Enter(e){const t=this._parent._proxy._animations.death.action;if(e){const n=this._parent._proxy._animations[e.Name].action;if(t.enabled=!0,e.Name=="idle"){const i=t.getClip().duration/n.getClip().duration;t.time=n.time*i}else t.time=0,t.setEffectiveTimeScale(1),t.setEffectiveWeight(1);t.crossFadeFrom(n,.5,!0),t.play()}else t.play()}Exit(){}Update(e){}}class jx{constructor(){this._Initialize()}_Initialize(){this._threejs=new q_({antialias:!0}),this._threejs.outputEncoding=void 0,this._threejs.shadowMap.enabled=!0,this._threejs.shadowMap.type=vl,this._threejs.setPixelRatio(window.devicePixelRatio),this._threejs.setSize(window.innerWidth,window.innerHeight),document.body.appendChild(this._threejs.domElement),window.addEventListener("resize",()=>{this._OnWindowResize()},!1);const e=60,t=1920/1080,n=1,i=1e3;this._camera=new Dt(e,t,n,i),this._camera.position.set(150,200,300),this._camera.lookAt(new T(-44,0,-100)),this._scene=new Y_,this._mixers=[],this._previousRAF=null,this._currentCollectedStars=0,this._currentHitFromMobs=0,this._currentHitFromMonster=0,this._lastAttackTime=0,this._gameOver=!1,this._gameOverTime=0,this._gameWin=!1,this._gameWinTime=0,this._blockGame=!1,this._blockGui=!1,this._difficulty="medium",this._mobAttackTime={easy:1e3,medium:500,hard:300},this._mobHitsToDamage={easy:4,medium:3,hard:2},this._monsterAttackTime={easy:1100,medium:600,hard:400},this._monsterHitsToDamage={easy:2,medium:1,hard:1},this._monsterDamageNormal={easy:2,medium:2,hard:3},this._monsterDamageTransformed={easy:1,medium:1,hard:2},this._bloodSpawnerParams={scene:this._scene,colors:[9052185,8850949,6032904],radius:{baseRadius:.1,randomRadius:.1},opacity:{baseOpacity:1,randomOpacity:0},transparency:!1,velocity:{baseVelocity:new T(-.05,-.15,-.05),randomVelocity:new T(.5,.8,.5),baseSign:new T(1,-1,1),randomSign:new T(!0,!1,!0),update:!1},expirationTime:{baseExpirationTime:5e3,randomExpirationTime:2e3},boxX:{baseMin:-100,baseMax:100,randomMin:0,randomMax:0,blockAll:!1,visible:!0},boxY:{baseMin:.1,baseMax:100,randomMin:0,randomMax:0,blockAll:!0,visible:!0},boxZ:{baseMin:-100,baseMax:100,randomMin:0,randomMax:0,blockAll:!1,visible:!0}},this._bloodSpawner=new zo(this._bloodSpawnerParams),this._LoadWorld(),this._LoadGUI(),this._LoadStars(),this._LoadHearts(),this._LoadSwords(),this._LoadPlayer(),this._LoadMobs(),this._LoadMonster(),this._RAF()}_LoadWorld(){this._world=new C0({scene:this._scene})}_LoadGUI(){this._gui=new B0({player:this._player})}_LoadPlayer(){const e={camera:this._camera,scene:this._scene,world:this._world,healthBar:this._gui._healthBar,powerBar:this._gui._powerBar,starCounter:this._gui._starCounter};this._player=new Rx(e),this._thirdPersonCamera=new Lx({camera:this._camera,target:this._player})}_LoadStars(){this._starsSpawner=new Ix({scene:this._scene,world:this._world})}_LoadHearts(){this._heartSpawner=new Dx({scene:this._scene,world:this._world})}_LoadSwords(){this._swordSpawner=new Ux({scene:this._scene,world:this._world})}_LoadMobs(){this._mobSpawner=new Nx({scene:this._scene,world:this._world,playerPosition:this._player.position,mobAttackTime:this._mobAttackTime[this._difficulty]})}_LoadMonster(){this._monsterSpawner=new Fx({scene:this._scene,world:this._world,playerPosition:this._player.position,monsterAttackTime:this._monsterAttackTime[this._difficulty]})}_OnWindowResize(){this._camera.aspect=window.innerWidth/window.innerHeight,this._camera.updateProjectionMatrix(),this._threejs.setSize(window.innerWidth,window.innerHeight)}_RAF(){requestAnimationFrame(e=>{this._previousRAF===null&&(this._previousRAF=e),this._RAF(),this._threejs.render(this._scene,this._camera),this._Step(e-this._previousRAF),this._previousRAF=e})}_Update(e){this._mixers&&!this._blockGame&&this._mixers.map(t=>t.update(e)),this._player&&!this._blockGame&&this._player.Update(e),this._starsSpawner&&!this._blockGame&&this._starsSpawner.Update(e),this._heartSpawner&&!this._blockGame&&this._heartSpawner.Update(e),this._swordSpawner&&!this._blockGame&&this._swordSpawner.Update(e),this._mobSpawner&&!this._blockGame&&this._mobSpawner.update(e),this._monsterSpawner&&!this._blockGame&&this._monsterSpawner.update(e),this._bloodSpawner&&!this._blockGame&&this._bloodSpawner.update(),this._world&&!this._blockGame&&this._world.update(e),this._gui&&!this._blockGui&&(this._gui.start.play?(this._blockGame&&(this._player.rotation=new pt(0,1,0,0)),this._blockGame=!1,this._gui.healthBar.show(),this._gui.powerBar.show(),this._gui.starCounter.show(),this._gui.monsterLifeBar.show(),this._gui.transformationTime.show()):this._blockGame=!0,this._gui.monsterLifeBar.update(),this._gui.transformationTime.update(this._player.transformed),this._gui.start.update(),this._difficulty=this._gui.start._difficulty,this._gui._monsterLifeBar.monsterLife=this._monsterSpawner.monsterLife,this._player.transformed?this._gui._transformationTime.time=Math.ceil((this._gui._transformationTime.time=this._player.transformationTime-(Date.now()-this._player.timeTransformed))/1e3):this._gui._transformationTime.time=Math.ceil(this._player.transformationTime/1e3)),this._blockGame||this._thirdPersonCamera.Update(e)}_GameOverWinHandler(){this._gui._healthBar.hearts.length===0&&!this._gameOver&&(this._gameOver=!0,this._gameOverTime=new Date().getTime(),this._gui._gameOver.show()),this._monsterSpawner.monsterState==="death"&&!this._gameWin&&(this._gameWin=!0,this._gameWinTime=new Date().getTime(),this._gui._gameWin.show()),(this._gameOver&&Date.now()-this._gameOverTime>2e3||this._gameWin&&Date.now()-this._gameWinTime>2e3)&&(this._blockGame=!0,this._blockGui=!0)}_CollectorHandler(){this._player.transformed||(this._stars=this._starsSpawner.stars,this._playerPosition=this._player.position,this._stars.map(e=>{e.position.distanceTo(this._playerPosition)<8&&(this._scene.remove(e),this._stars=this._stars.filter(t=>t!==e),this._starsSpawner.stars=this._stars,this._gui._starCounter.addStar())})),this._hearts=this._heartSpawner.hearts,this._playerPosition=this._player.position,this._hearts.map(e=>{e.position.distanceTo(this._playerPosition)<8&&(this._scene.remove(e),this._hearts=this._hearts.filter(t=>t!==e),this._heartSpawner.hearts=this._hearts,this._gui._healthBar.addHeart())}),this._swords=this._swordSpawner.swords,this._playerPosition=this._player.position,this._swords.map(e=>{e.position.distanceTo(this._playerPosition)<8&&(this._scene.remove(e),this._swords=this._swords.filter(t=>t!==e),this._swordSpawner.swords=this._swords,this._gui._powerBar.addSword())})}_MobAttackHandler(){this._mobs=this._mobSpawner.mobs,this._mobAttackDistance=this._mobSpawner.mobAttackDistance,this._mobAttackTime=this._mobSpawner.mobAttackTime,this._player.hitFlag=!1;for(const t of this._mobs)this._playerPosition.distanceTo(t.position)this._mobAttackTime&&!t.deadFlag&&(t.lastHit=new Date().getTime(),this._player.hitFlag=!0,this._player.hitDirection=t.position.clone().sub(this._playerPosition).normalize(),this._player.transformed?this._player.hitIntensity=.3:this._player.hitIntensity=1,this._currentHitFromMobs+=1);this._currentHitFromMobs===this._mobHitsToDamage[this._difficulty]&&(this._gui._healthBar.removeHeart(),this._currentHitFromMobs=0,this._bloodSpawner.create({x:this._player.position.x,y:this._player.position.y,z:this._player.position.z,width:5,height:5,depth:5},30));const e=this._player.damage;if(this._player._stateMachine._currentState&&(this._player._stateMachine._currentState.Name==="attack_1"||this._player._stateMachine._currentState.Name==="attack_2")&&Date.now()-this._lastAttackTime>1e3)for(const t of this._mobs){const n=this._playerPosition.distanceTo(t.position),i=t.position.clone().sub(this._playerPosition).normalize(),o=this._player.position.clone().sub(this._player.previousPosition).normalize().dot(i)>.5;nthis._monsterAttackRange.min&&ethis._monsterAttackTime&&this._monsterState==="attack"&&(this._monsterSpawner.monsterLastHit=new Date().getTime(),this._currentHitFromMonster+=1,this._player.hitFlag=!0,this._player.hitDirection=this._monsterSpawner.monsterPosition.clone().sub(this._playerPosition).normalize(),this._player.transformed?this._player.hitIntensity=1:this._player.hitIntensity=3),this._currentHitFromMonster===this._monsterHitsToDamage[this._difficulty]){for(let t=0;t1e3&&e{new jx}); +*/var $t=Uint8Array,Ni=Uint16Array,k0=Int32Array,oh=new $t([0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0,0,0,0]),ch=new $t([0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13,0,0]),z0=new $t([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]),lh=function(r,e){for(var t=new Ni(31),n=0;n<31;++n)t[n]=e+=1<>1|(ot&21845)<<1;Hn=(Hn&52428)>>2|(Hn&13107)<<2,Hn=(Hn&61680)>>4|(Hn&3855)<<4,po[ot]=((Hn&65280)>>8|(Hn&255)<<8)>>1}var ps=function(r,e,t){for(var n=r.length,i=0,s=new Ni(e);i>c]=l}else for(o=new Ni(n),i=0;i>15-r[i]);return o},Es=new $t(288);for(var ot=0;ot<144;++ot)Es[ot]=8;for(var ot=144;ot<256;++ot)Es[ot]=9;for(var ot=256;ot<280;++ot)Es[ot]=7;for(var ot=280;ot<288;++ot)Es[ot]=8;var dh=new $t(32);for(var ot=0;ot<32;++ot)dh[ot]=5;var W0=ps(Es,9,1),X0=ps(dh,5,1),Ta=function(r){for(var e=r[0],t=1;te&&(e=r[t]);return e},on=function(r,e,t){var n=e/8|0;return(r[n]|r[n+1]<<8)>>(e&7)&t},Ea=function(r,e){var t=e/8|0;return(r[t]|r[t+1]<<8|r[t+2]<<16)>>(e&7)},j0=function(r){return(r+7)/8|0},q0=function(r,e,t){return(t==null||t>r.length)&&(t=r.length),new $t(r.subarray(e,t))},Y0=["unexpected EOF","invalid block type","invalid length/literal","invalid distance","stream finished","no stream handler",,"no callback","invalid UTF-8 data","extra field too long","date not in range 1980-2099","filename too long","stream finishing","invalid zip data"],cn=function(r,e,t){var n=new Error(e||Y0[r]);if(n.code=r,Error.captureStackTrace&&Error.captureStackTrace(n,cn),!t)throw n;return n},K0=function(r,e,t,n){var i=r.length,s=0;if(!i||e.f&&!e.l)return t||new $t(0);var a=!t,o=a||e.i!=2,c=e.i;a&&(t=new $t(i*3));var l=function(nt){var C=t.length;if(nt>C){var st=new $t(Math.max(C*2,nt));st.set(t),t=st}},u=e.f||0,h=e.p||0,d=e.b||0,f=e.l,_=e.d,g=e.m,m=e.n,p=i*8;do{if(!f){u=on(r,h,1);var b=on(r,h+1,3);if(h+=3,b)if(b==1)f=W0,_=X0,g=9,m=5;else if(b==2){var E=on(r,h,31)+257,A=on(r,h+10,15)+4,D=E+on(r,h+5,31)+1;h+=14;for(var w=new $t(D),y=new $t(19),P=0;P>4;if(x<16)w[P++]=x;else{var H=0,q=0;for(x==16?(q=3+on(r,h,3),h+=2,H=w[P-1]):x==17?(q=3+on(r,h,7),h+=3):x==18&&(q=11+on(r,h,127),h+=7);q--;)w[P++]=H}}var V=w.subarray(0,E),ie=w.subarray(E);g=Ta(V),m=Ta(ie),f=ps(V,g,1),_=ps(ie,m,1)}else cn(1);else{var x=j0(h)+4,M=r[x-4]|r[x-3]<<8,L=x+M;if(L>i){c&&cn(0);break}o&&l(d+M),t.set(r.subarray(x,L),d),e.b=d+=M,e.p=h=L*8,e.f=u;continue}if(h>p){c&&cn(0);break}}o&&l(d+131072);for(var oe=(1<>4;if(h+=H&15,h>p){c&&cn(0);break}if(H||cn(2),He<256)t[d++]=He;else if(He==256){Oe=h,f=null;break}else{var W=He-254;if(He>264){var P=He-257,J=oh[P];W=on(r,h,(1<>4;ce||cn(3),h+=ce&15;var ie=G0[ae];if(ae>3){var J=ch[ae];ie+=Ea(r,h)&(1<p){c&&cn(0);break}o&&l(d+131072);var Ae=d+W;if(d>4>7||(r[0]<<8|r[1])%31)&&cn(6,"invalid zlib data"),(r[1]>>5&1)==+!e&&cn(6,"invalid zlib data: "+(r[1]&32?"need":"unexpected")+" dictionary"),(r[1]>>3&4)+2};function J0(r,e){return K0(r.subarray($0(r,e),-4),{i:2},e,e)}var Q0=typeof TextDecoder<"u"&&new TextDecoder,ex=0;try{Q0.decode(Z0,{stream:!0}),ex=1}catch{}function fh(r,e,t){const n=t.length-r-1;if(e>=t[n])return n-1;if(e<=t[r])return r;let i=r,s=n,a=Math.floor((i+s)/2);for(;e=t[a+1];)e=g&&(_[f][0]=_[d][0]/o[b+1][p],m=_[f][0]*o[p][b]);const x=p>=-1?1:-p,M=h-1<=b?g-1:t-h;for(let E=x;E<=M;++E)_[f][E]=(_[d][E]-_[d][E-1])/o[b+1][p+E],m+=_[f][E]*o[p+E][b];h<=b&&(_[f][g]=-_[d][g-1]/o[b+1][h],m+=_[f][g]*o[h][b]),a[g][h]=m;const L=d;d=f,f=L}}let u=t;for(let h=1;h<=n;++h){for(let d=0;d<=t;++d)a[h][d]*=u;u*=t-h}return a}function sx(r,e,t,n,i){const s=i0,c=typeof s.Content=="string"&&s.Content!=="";if(o||c){const l=this.parseImage(n[i]);t[s.RelativeFilename||s.Filename]=l}}}}for(const n in e){const i=e[n];t[i]!==void 0?e[n]=t[i]:e[n]=e[n].split("\\").pop()}return e}parseImage(e){const t=e.Content,n=e.RelativeFilename||e.Filename,i=n.slice(n.lastIndexOf(".")+1).toLowerCase();let s;switch(i){case"bmp":s="image/bmp";break;case"jpg":case"jpeg":s="image/jpeg";break;case"png":s="image/png";break;case"tif":s="image/tiff";break;case"tga":this.manager.getHandler(".tga")===null&&console.warn("FBXLoader: TGA loader not found, skipping ",n),s="image/tga";break;default:console.warn('FBXLoader: Image type "'+i+'" is not supported.');return}if(typeof t=="string")return"data:"+s+";base64,"+t;{const a=new Uint8Array(t);return window.URL.createObjectURL(new Blob([a],{type:s}))}}parseTextures(e){const t=new Map;if("Texture"in Ve.Objects){const n=Ve.Objects.Texture;for(const i in n){const s=this.parseTexture(n[i],e);t.set(parseInt(i),s)}}return t}parseTexture(e,t){const n=this.loadTexture(e,t);n.ID=e.id,n.name=e.attrName;const i=e.WrapModeU,s=e.WrapModeV,a=i!==void 0?i.value:0,o=s!==void 0?s.value:0;if(n.wrapS=a===0?Jt:mn,n.wrapT=o===0?Jt:mn,"Scaling"in e){const c=e.Scaling.value;n.repeat.x=c[0],n.repeat.y=c[1]}if("Translation"in e){const c=e.Translation.value;n.offset.x=c[0],n.offset.y=c[1]}return n}loadTexture(e,t){const n=new Set(["tga","tif","tiff","exr","dds","hdr","ktx2"]),i=e.FileName.split(".").pop().toLowerCase(),s=n.has(i)?this.manager.getHandler(`.${i}`):this.textureLoader;if(!s)return console.warn(`FBXLoader: ${i.toUpperCase()} loader not found, creating placeholder texture for`,e.RelativeFilename),new St;const a=s.path;a||s.setPath(this.textureLoader.path);const o=_t.get(e.id).children;let c;o!==void 0&&o.length>0&&t[o[0].ID]!==void 0&&(c=t[o[0].ID],(c.indexOf("blob:")===0||c.indexOf("data:")===0)&&s.setPath(void 0));const l=s.load(c);return s.setPath(a),l}parseMaterials(e){const t=new Map;if("Material"in Ve.Objects){const n=Ve.Objects.Material;for(const i in n){const s=this.parseMaterial(n[i],e);s!==null&&t.set(parseInt(i),s)}}return t}parseMaterial(e,t){const n=e.id,i=e.attrName;let s=e.ShadingModel;if(typeof s=="object"&&(s=s.value),!_t.has(n))return null;const a=this.parseParameters(e,t,n);let o;switch(s.toLowerCase()){case"phong":o=new va;break;case"lambert":o=new Mg;break;default:console.warn('THREE.FBXLoader: unknown material type "%s". Defaulting to MeshPhongMaterial.',s),o=new va;break}return o.setValues(a),o.name=i,o}parseParameters(e,t,n){const i={};e.BumpFactor&&(i.bumpScale=e.BumpFactor.value),e.Diffuse?i.color=new ge().fromArray(e.Diffuse.value).convertSRGBToLinear():e.DiffuseColor&&(e.DiffuseColor.type==="Color"||e.DiffuseColor.type==="ColorRGB")&&(i.color=new ge().fromArray(e.DiffuseColor.value).convertSRGBToLinear()),e.DisplacementFactor&&(i.displacementScale=e.DisplacementFactor.value),e.Emissive?i.emissive=new ge().fromArray(e.Emissive.value).convertSRGBToLinear():e.EmissiveColor&&(e.EmissiveColor.type==="Color"||e.EmissiveColor.type==="ColorRGB")&&(i.emissive=new ge().fromArray(e.EmissiveColor.value).convertSRGBToLinear()),e.EmissiveFactor&&(i.emissiveIntensity=parseFloat(e.EmissiveFactor.value)),e.Opacity&&(i.opacity=parseFloat(e.Opacity.value)),i.opacity<1&&(i.transparent=!0),e.ReflectionFactor&&(i.reflectivity=e.ReflectionFactor.value),e.Shininess&&(i.shininess=e.Shininess.value),e.Specular?i.specular=new ge().fromArray(e.Specular.value).convertSRGBToLinear():e.SpecularColor&&e.SpecularColor.type==="Color"&&(i.specular=new ge().fromArray(e.SpecularColor.value).convertSRGBToLinear());const s=this;return _t.get(n).children.forEach(function(a){const o=a.relationship;switch(o){case"Bump":i.bumpMap=s.getTexture(t,a.ID);break;case"Maya|TEX_ao_map":i.aoMap=s.getTexture(t,a.ID);break;case"DiffuseColor":case"Maya|TEX_color_map":i.map=s.getTexture(t,a.ID),i.map!==void 0&&(i.map.colorSpace=Mt);break;case"DisplacementColor":i.displacementMap=s.getTexture(t,a.ID);break;case"EmissiveColor":i.emissiveMap=s.getTexture(t,a.ID),i.emissiveMap!==void 0&&(i.emissiveMap.colorSpace=Mt);break;case"NormalMap":case"Maya|TEX_normal_map":i.normalMap=s.getTexture(t,a.ID);break;case"ReflectionColor":i.envMap=s.getTexture(t,a.ID),i.envMap!==void 0&&(i.envMap.mapping=mr,i.envMap.colorSpace=Mt);break;case"SpecularColor":i.specularMap=s.getTexture(t,a.ID),i.specularMap!==void 0&&(i.specularMap.colorSpace=Mt);break;case"TransparentColor":case"TransparencyFactor":i.alphaMap=s.getTexture(t,a.ID),i.transparent=!0;break;case"AmbientColor":case"ShininessExponent":case"SpecularFactor":case"VectorDisplacementColor":default:console.warn("THREE.FBXLoader: %s map is not supported in three.js, skipping texture.",o);break}}),i}getTexture(e,t){return"LayeredTexture"in Ve.Objects&&t in Ve.Objects.LayeredTexture&&(console.warn("THREE.FBXLoader: layered textures are not supported in three.js. Discarding all but first layer."),t=_t.get(t).children[0].ID),e.get(t)}parseDeformers(){const e={},t={};if("Deformer"in Ve.Objects){const n=Ve.Objects.Deformer;for(const i in n){const s=n[i],a=_t.get(parseInt(i));if(s.attrType==="Skin"){const o=this.parseSkeleton(a,n);o.ID=i,a.parents.length>1&&console.warn("THREE.FBXLoader: skeleton attached to more than one geometry is not supported."),o.geometryID=a.parents[0].ID,e[i]=o}else if(s.attrType==="BlendShape"){const o={id:i};o.rawTargets=this.parseMorphTargets(a,n),o.id=i,a.parents.length>1&&console.warn("THREE.FBXLoader: morph target attached to more than one geometry is not supported."),t[i]=o}}}return{skeletons:e,morphTargets:t}}parseSkeleton(e,t){const n=[];return e.children.forEach(function(i){const s=t[i.ID];if(s.attrType!=="Cluster")return;const a={ID:i.ID,indices:[],weights:[],transformLink:new fe().fromArray(s.TransformLink.a)};"Indexes"in s&&(a.indices=s.Indexes.a,a.weights=s.Weights.a),n.push(a)}),{rawBones:n,bones:[]}}parseMorphTargets(e,t){const n=[];for(let i=0;i1?a=o:o.length>0?a=o[0]:(a=new va({name:In.DEFAULT_MATERIAL_NAME,color:13421772}),o.push(a)),"color"in s.attributes&&o.forEach(function(c){c.vertexColors=!0}),s.FBX_Deformer?(i=new Yl(s,a),i.normalizeSkinWeights()):i=new ye(s,a),i}createCurve(e,t){const n=e.children.reduce(function(s,a){return t.has(a.ID)&&(s=t.get(a.ID)),s},null),i=new Po({name:In.DEFAULT_MATERIAL_NAME,color:3342591,linewidth:1});return new Nr(n,i)}getTransformData(e,t){const n={};"InheritType"in t&&(n.inheritType=parseInt(t.InheritType.value)),"RotationOrder"in t?n.eulerOrder=_h(t.RotationOrder.value):n.eulerOrder="ZYX","Lcl_Translation"in t&&(n.translation=t.Lcl_Translation.value),"PreRotation"in t&&(n.preRotation=t.PreRotation.value),"Lcl_Rotation"in t&&(n.rotation=t.Lcl_Rotation.value),"PostRotation"in t&&(n.postRotation=t.PostRotation.value),"Lcl_Scaling"in t&&(n.scale=t.Lcl_Scaling.value),"ScalingOffset"in t&&(n.scalingOffset=t.ScalingOffset.value),"ScalingPivot"in t&&(n.scalingPivot=t.ScalingPivot.value),"RotationOffset"in t&&(n.rotationOffset=t.RotationOffset.value),"RotationPivot"in t&&(n.rotationPivot=t.RotationPivot.value),e.userData.transformData=n}setLookAtProperties(e,t){"LookAtProperty"in t&&_t.get(e.ID).children.forEach(function(i){if(i.relationship==="LookAtProperty"){const s=Ve.Objects.Model[i.ID];if("Lcl_Translation"in s){const a=s.Lcl_Translation.value;e.target!==void 0?(e.target.position.fromArray(a),Ft.add(e.target)):e.lookAt(new T().fromArray(a))}}})}bindSkeleton(e,t,n){const i=this.parsePoseNodes();for(const s in e){const a=e[s];_t.get(parseInt(a.ID)).parents.forEach(function(c){if(t.has(c.ID)){const l=c.ID;_t.get(l).parents.forEach(function(h){n.has(h.ID)&&n.get(h.ID).bind(new Ur(a.bones),i[h.ID])})}})}}parsePoseNodes(){const e={};if("Pose"in Ve.Objects){const t=Ve.Objects.Pose;for(const n in t)if(t[n].attrType==="BindPose"&&t[n].NbPoseNodes>0){const i=t[n].PoseNode;Array.isArray(i)?i.forEach(function(s){e[s.Node]=new fe().fromArray(s.Matrix.a)}):e[i.Node]=new fe().fromArray(i.Matrix.a)}}return e}addGlobalSceneSettings(){if("GlobalSettings"in Ve){if("AmbientColor"in Ve.GlobalSettings){const e=Ve.GlobalSettings.AmbientColor.value,t=e[0],n=e[1],i=e[2];if(t!==0||n!==0||i!==0){const s=new ge(t,n,i).convertSRGBToLinear();Ft.add(new sh(s,1))}}"UnitScaleFactor"in Ve.GlobalSettings&&(Ft.userData.unitScaleFactor=Ve.GlobalSettings.UnitScaleFactor.value)}}}class hx{constructor(){this.negativeMaterialIndices=!1}parse(e){const t=new Map;if("Geometry"in Ve.Objects){const n=Ve.Objects.Geometry;for(const i in n){const s=_t.get(parseInt(i)),a=this.parseGeometry(s,n[i],e);t.set(parseInt(i),a)}}return this.negativeMaterialIndices===!0&&console.warn("THREE.FBXLoader: The FBX file contains invalid (negative) material indices. The asset might not render as expected."),t}parseGeometry(e,t,n){switch(t.attrType){case"Mesh":return this.parseMeshGeometry(e,t,n);case"NurbsCurve":return this.parseNurbsGeometry(t)}}parseMeshGeometry(e,t,n){const i=n.skeletons,s=[],a=e.parents.map(function(h){return Ve.Objects.Model[h.ID]});if(a.length===0)return;const o=e.children.reduce(function(h,d){return i[d.ID]!==void 0&&(h=i[d.ID]),h},null);e.children.forEach(function(h){n.morphTargets[h.ID]!==void 0&&s.push(n.morphTargets[h.ID])});const c=a[0],l={};"RotationOrder"in c&&(l.eulerOrder=_h(c.RotationOrder.value)),"InheritType"in c&&(l.inheritType=parseInt(c.InheritType.value)),"GeometricTranslation"in c&&(l.translation=c.GeometricTranslation.value),"GeometricRotation"in c&&(l.rotation=c.GeometricRotation.value),"GeometricScaling"in c&&(l.scale=c.GeometricScaling.value);const u=mh(l);return this.genGeometry(t,o,s,u)}genGeometry(e,t,n,i){const s=new zt;e.attrName&&(s.name=e.attrName);const a=this.parseGeoNode(e,t),o=this.genBuffers(a),c=new gt(o.vertex,3);if(c.applyMatrix4(i),s.setAttribute("position",c),o.colors.length>0&&s.setAttribute("color",new gt(o.colors,3)),t&&(s.setAttribute("skinIndex",new Eo(o.weightsIndices,4)),s.setAttribute("skinWeight",new gt(o.vertexWeights,4)),s.FBX_Deformer=t),o.normal.length>0){const l=new Fe().getNormalMatrix(i),u=new gt(o.normal,3);u.applyNormalMatrix(l),s.setAttribute("normal",u)}if(o.uvs.forEach(function(l,u){const h=u===0?"uv":`uv${u}`;s.setAttribute(h,new gt(o.uvs[u],2))}),a.material&&a.material.mappingType!=="AllSame"){let l=o.materialIndex[0],u=0;if(o.materialIndex.forEach(function(h,d){h!==l&&(s.addGroup(u,d-u,l),l=h,u=d)}),s.groups.length>0){const h=s.groups[s.groups.length-1],d=h.start+h.count;d!==o.materialIndex.length&&s.addGroup(d,o.materialIndex.length-d,l)}s.groups.length===0&&s.addGroup(0,o.materialIndex.length,o.materialIndex[0])}return this.addMorphTargets(s,e,n,i),s}parseGeoNode(e,t){const n={};if(n.vertexPositions=e.Vertices!==void 0?e.Vertices.a:[],n.vertexIndices=e.PolygonVertexIndex!==void 0?e.PolygonVertexIndex.a:[],e.LayerElementColor&&(n.color=this.parseVertexColors(e.LayerElementColor[0])),e.LayerElementMaterial&&(n.material=this.parseMaterialIndices(e.LayerElementMaterial[0])),e.LayerElementNormal&&(n.normal=this.parseNormals(e.LayerElementNormal[0])),e.LayerElementUV){n.uv=[];let i=0;for(;e.LayerElementUV[i];)e.LayerElementUV[i].UV&&n.uv.push(this.parseUVs(e.LayerElementUV[i])),i++}return n.weightTable={},t!==null&&(n.skeleton=t,t.rawBones.forEach(function(i,s){i.indices.forEach(function(a,o){n.weightTable[a]===void 0&&(n.weightTable[a]=[]),n.weightTable[a].push({id:s,weight:i.weights[o]})})})),n}genBuffers(e){const t={vertex:[],normal:[],colors:[],uvs:[],materialIndex:[],vertexWeights:[],weightsIndices:[]};let n=0,i=0,s=!1,a=[],o=[],c=[],l=[],u=[],h=[];const d=this;return e.vertexIndices.forEach(function(f,_){let g,m=!1;f<0&&(f=f^-1,m=!0);let p=[],b=[];if(a.push(f*3,f*3+1,f*3+2),e.color){const x=ar(_,n,f,e.color);c.push(x[0],x[1],x[2])}if(e.skeleton){if(e.weightTable[f]!==void 0&&e.weightTable[f].forEach(function(x){b.push(x.weight),p.push(x.id)}),b.length>4){s||(console.warn("THREE.FBXLoader: Vertex has more than 4 skinning weights assigned to vertex. Deleting additional weights."),s=!0);const x=[0,0,0,0],M=[0,0,0,0];b.forEach(function(L,E){let A=L,D=p[E];M.forEach(function(w,y,P){if(A>w){P[y]=A,A=w;const z=x[y];x[y]=D,D=z}})}),p=x,b=M}for(;b.length<4;)b.push(0),p.push(0);for(let x=0;x<4;++x)u.push(b[x]),h.push(p[x])}if(e.normal){const x=ar(_,n,f,e.normal);o.push(x[0],x[1],x[2])}e.material&&e.material.mappingType!=="AllSame"&&(g=ar(_,n,f,e.material)[0],g<0&&(d.negativeMaterialIndices=!0,g=0)),e.uv&&e.uv.forEach(function(x,M){const L=ar(_,n,f,x);l[M]===void 0&&(l[M]=[]),l[M].push(L[0]),l[M].push(L[1])}),i++,m&&(d.genFace(t,e,a,g,o,c,l,u,h,i),n++,i=0,a=[],o=[],c=[],l=[],u=[],h=[])}),t}getNormalNewell(e){const t=new T(0,0,0);for(let n=0;n.5?new T(0,1,0):new T(0,0,1)).cross(t).normalize(),s=t.clone().cross(i).normalize();return{normal:t,tangent:i,bitangent:s}}flattenVertex(e,t,n){return new Ne(e.dot(t),e.dot(n))}genFace(e,t,n,i,s,a,o,c,l,u){let h;if(u>3){const d=[],f=t.baseVertexPositions||t.vertexPositions;for(let p=0;p1&&console.warn("THREE.FBXLoader: Encountered an animation stack with multiple layers, this is currently not supported. Ignoring subsequent layers.");const a=e.get(s[0].ID);n[i]={name:t[i].attrName,layer:a}}return n}addClip(e){let t=[];const n=this;return e.layer.forEach(function(i){t=t.concat(n.generateTracks(i))}),new Tr(e.name,-1,t)}generateTracks(e){const t=[];let n=new T,i=new T;if(e.transform&&e.transform.decompose(n,new pt,i),n=n.toArray(),i=i.toArray(),e.T!==void 0&&Object.keys(e.T.curves).length>0){const s=this.generateVectorTrack(e.modelName,e.T.curves,n,"position");s!==void 0&&t.push(s)}if(e.R!==void 0&&Object.keys(e.R.curves).length>0){const s=this.generateRotationTrack(e.modelName,e.R.curves,e.preRotation,e.postRotation,e.eulerOrder);s!==void 0&&t.push(s)}if(e.S!==void 0&&Object.keys(e.S.curves).length>0){const s=this.generateVectorTrack(e.modelName,e.S.curves,i,"scale");s!==void 0&&t.push(s)}if(e.DeformPercent!==void 0){const s=this.generateMorphTrack(e);s!==void 0&&t.push(s)}return t}generateVectorTrack(e,t,n,i){const s=this.getTimesForAllAxes(t),a=this.getKeyframeTrackValues(s,t,n);return new li(e+"."+i,s,a)}generateRotationTrack(e,t,n,i,s){let a,o;if(t.x!==void 0&&t.y!==void 0&&t.z!==void 0){const h=this.interpolateRotations(t.x,t.y,t.z,s);a=h[0],o=h[1]}n!==void 0&&(n=n.map(It.degToRad),n.push(s),n=new mt().fromArray(n),n=new pt().setFromEuler(n)),i!==void 0&&(i=i.map(It.degToRad),i.push(s),i=new mt().fromArray(i),i=new pt().setFromEuler(i).invert());const c=new pt,l=new mt,u=[];if(!o||!a)return new qn(e+".quaternion",[0],[0]);for(let h=0;h2&&new pt().fromArray(u,(h-3)/3*4).dot(c)<0&&c.set(-c.x,-c.y,-c.z,-c.w),c.toArray(u,h/3*4);return new qn(e+".quaternion",a,u)}generateMorphTrack(e){const t=e.DeformPercent.curves.morph,n=t.values.map(function(s){return s/100}),i=Ft.getObjectByName(e.modelName).morphTargetDictionary[e.morphName];return new ci(e.modelName+".morphTargetInfluences["+i+"]",t.times,n)}getTimesForAllAxes(e){let t=[];if(e.x!==void 0&&(t=t.concat(e.x.times)),e.y!==void 0&&(t=t.concat(e.y.times)),e.z!==void 0&&(t=t.concat(e.z.times)),t=t.sort(function(n,i){return n-i}),t.length>1){let n=1,i=t[0];for(let s=1;s=180||f[1]>=180||f[2]>=180){const g=Math.max(...f)/180,m=new mt(...l,i),p=new mt(...h,i),b=new pt().setFromEuler(m),x=new pt().setFromEuler(p);b.dot(x)&&x.set(-x.x,-x.y,-x.z,-x.w);const M=e.times[o-1],L=e.times[o]-M,E=new pt,A=new mt;for(let D=0;D<1;D+=1/g)E.copy(b.clone().slerp(x.clone(),D)),s.push(M+D*L),A.setFromQuaternion(E,i),a.push(A.x),a.push(A.y),a.push(A.z)}else s.push(e.times[o]),a.push(It.degToRad(e.values[o])),a.push(It.degToRad(t.values[o])),a.push(It.degToRad(n.values[o]))}return[s,a]}}class dx{getPrevNode(){return this.nodeStack[this.currentIndent-2]}getCurrentNode(){return this.nodeStack[this.currentIndent-1]}getCurrentProp(){return this.currentProp}pushStack(e){this.nodeStack.push(e),this.currentIndent+=1}popStack(){this.nodeStack.pop(),this.currentIndent-=1}setCurrentProp(e,t){this.currentProp=e,this.currentPropName=t}parse(e){this.currentIndent=0,this.allNodes=new ph,this.nodeStack=[],this.currentProp=[],this.currentPropName="";const t=this,n=e.split(/[\r\n]+/);return n.forEach(function(i,s){const a=i.match(/^[\s\t]*;/),o=i.match(/^[\s\t]*$/);if(a||o)return;const c=i.match("^\\t{"+t.currentIndent+"}(\\w+):(.*){",""),l=i.match("^\\t{"+t.currentIndent+"}(\\w+):[\\s\\t\\r\\n](.*)"),u=i.match("^\\t{"+(t.currentIndent-1)+"}}");c?t.parseNodeBegin(i,c):l?t.parseNodeProperty(i,l,n[++s]):u?t.popStack():i.match(/^[^\s\t}]/)&&t.parseNodePropertyContinued(i)}),this.allNodes}parseNodeBegin(e,t){const n=t[1].trim().replace(/^"/,"").replace(/"$/,""),i=t[2].split(",").map(function(c){return c.trim().replace(/^"/,"").replace(/"$/,"")}),s={name:n},a=this.parseNodeAttr(i),o=this.getCurrentNode();this.currentIndent===0?this.allNodes.add(n,s):n in o?(n==="PoseNode"?o.PoseNode.push(s):o[n].id!==void 0&&(o[n]={},o[n][o[n].id]=o[n]),a.id!==""&&(o[n][a.id]=s)):typeof a.id=="number"?(o[n]={},o[n][a.id]=s):n!=="Properties70"&&(n==="PoseNode"?o[n]=[s]:o[n]=s),typeof a.id=="number"&&(s.id=a.id),a.name!==""&&(s.attrName=a.name),a.type!==""&&(s.attrType=a.type),this.pushStack(s)}parseNodeAttr(e){let t=e[0];e[0]!==""&&(t=parseInt(e[0]),isNaN(t)&&(t=e[0]));let n="",i="";return e.length>1&&(n=e[1].replace(/^(\w+)::/,""),i=e[2]),{id:t,name:n,type:i}}parseNodeProperty(e,t,n){let i=t[1].replace(/^"/,"").replace(/"$/,"").trim(),s=t[2].replace(/^"/,"").replace(/"$/,"").trim();i==="Content"&&s===","&&(s=n.replace(/"/g,"").replace(/,$/,"").trim());const a=this.getCurrentNode();if(a.name==="Properties70"){this.parseNodeSpecialProperty(e,i,s);return}if(i==="C"){const c=s.split(",").slice(1),l=parseInt(c[0]),u=parseInt(c[1]);let h=s.split(",").slice(3);h=h.map(function(d){return d.trim().replace(/^"/,"")}),i="connections",s=[l,u],xx(s,h),a[i]===void 0&&(a[i]=[])}i==="Node"&&(a.id=s),i in a&&Array.isArray(a[i])?a[i].push(s):i!=="a"?a[i]=s:a.a=s,this.setCurrentProp(a,i),i==="a"&&s.slice(-1)!==","&&(a.a=Ra(s))}parseNodePropertyContinued(e){const t=this.getCurrentNode();t.a+=e,e.slice(-1)!==","&&(t.a=Ra(t.a))}parseNodeSpecialProperty(e,t,n){const i=n.split('",').map(function(u){return u.trim().replace(/^\"/,"").replace(/\s/,"_")}),s=i[0],a=i[1],o=i[2],c=i[3];let l=i[4];switch(a){case"int":case"enum":case"bool":case"ULongLong":case"double":case"Number":case"FieldOfView":l=parseFloat(l);break;case"Color":case"ColorRGB":case"Vector3D":case"Lcl_Translation":case"Lcl_Rotation":case"Lcl_Scaling":l=Ra(l);break}this.getPrevNode()[s]={type:a,type2:o,flag:c,value:l},this.setCurrentProp(this.getPrevNode(),s)}}class fx{parse(e){const t=new _l(e);t.skip(23);const n=t.getUint32();if(n<6400)throw new Error("THREE.FBXLoader: FBX version not supported, FileVersion: "+n);const i=new ph;for(;!this.endOfContent(t);){const s=this.parseNode(t,n);s!==null&&i.add(s.name,s)}return i}endOfContent(e){return e.size()%16===0?(e.getOffset()+160+16&-16)>=e.size():e.getOffset()+160+16>=e.size()}parseNode(e,t){const n={},i=t>=7500?e.getUint64():e.getUint32(),s=t>=7500?e.getUint64():e.getUint32();t>=7500?e.getUint64():e.getUint32();const a=e.getUint8(),o=e.getString(a);if(i===0)return null;const c=[];for(let d=0;d0?c[0]:"",u=c.length>1?c[1]:"",h=c.length>2?c[2]:"";for(n.singleProperty=s===1&&e.getOffset()===i;i>e.getOffset();){const d=this.parseNode(e,t);d!==null&&this.parseSubNode(o,n,d)}return n.propertyList=c,typeof l=="number"&&(n.id=l),u!==""&&(n.attrName=u),h!==""&&(n.attrType=h),o!==""&&(n.name=o),n}parseSubNode(e,t,n){if(n.singleProperty===!0){const i=n.propertyList[0];Array.isArray(i)?(t[n.name]=n,n.a=i):t[n.name]=i}else if(e==="Connections"&&n.name==="C"){const i=[];n.propertyList.forEach(function(s,a){a!==0&&i.push(s)}),t.connections===void 0&&(t.connections=[]),t.connections.push(i)}else if(n.name==="Properties70")Object.keys(n).forEach(function(s){t[s]=n[s]});else if(e==="Properties70"&&n.name==="P"){let i=n.propertyList[0],s=n.propertyList[1];const a=n.propertyList[2],o=n.propertyList[3];let c;i.indexOf("Lcl ")===0&&(i=i.replace("Lcl ","Lcl_")),s.indexOf("Lcl ")===0&&(s=s.replace("Lcl ","Lcl_")),s==="Color"||s==="ColorRGB"||s==="Vector"||s==="Vector3D"||s.indexOf("Lcl_")===0?c=[n.propertyList[4],n.propertyList[5],n.propertyList[6]]:c=n.propertyList[4],t[i]={type:s,type2:a,flag:o,value:c}}else t[n.name]===void 0?typeof n.id=="number"?(t[n.name]={},t[n.name][n.id]=n):t[n.name]=n:n.name==="PoseNode"?(Array.isArray(t[n.name])||(t[n.name]=[t[n.name]]),t[n.name].push(n)):t[n.name][n.id]===void 0&&(t[n.name][n.id]=n)}parseProperty(e){const t=e.getString(1);let n;switch(t){case"C":return e.getBoolean();case"D":return e.getFloat64();case"F":return e.getFloat32();case"I":return e.getInt32();case"L":return e.getInt64();case"R":return n=e.getUint32(),e.getArrayBuffer(n);case"S":return n=e.getUint32(),e.getString(n);case"Y":return e.getInt16();case"b":case"c":case"d":case"f":case"i":case"l":const i=e.getUint32(),s=e.getUint32(),a=e.getUint32();if(s===0)switch(t){case"b":case"c":return e.getBooleanArray(i);case"d":return e.getFloat64Array(i);case"f":return e.getFloat32Array(i);case"i":return e.getInt32Array(i);case"l":return e.getInt64Array(i)}const o=J0(new Uint8Array(e.getArrayBuffer(a))),c=new _l(o.buffer);switch(t){case"b":case"c":return c.getBooleanArray(i);case"d":return c.getFloat64Array(i);case"f":return c.getFloat32Array(i);case"i":return c.getInt32Array(i);case"l":return c.getInt64Array(i)}break;default:throw new Error("THREE.FBXLoader: Unknown property type "+t)}}}class _l{constructor(e,t){this.dv=new DataView(e),this.offset=0,this.littleEndian=t!==void 0?t:!0,this._textDecoder=new TextDecoder}getOffset(){return this.offset}size(){return this.dv.buffer.byteLength}skip(e){this.offset+=e}getBoolean(){return(this.getUint8()&1)===1}getBooleanArray(e){const t=[];for(let n=0;n=0&&(n=new Uint8Array(this.dv.buffer,t,i)),this._textDecoder.decode(n)}}class ph{add(e,t){this[e]=t}}function px(r){const e="Kaydara FBX Binary \0";return r.byteLength>=e.length&&e===gh(r,0,e.length)}function mx(r){const e=["K","a","y","d","a","r","a","\\","F","B","X","\\","B","i","n","a","r","y","\\","\\"];let t=0;function n(i){const s=r[i-1];return r=r.slice(t+i),t++,s}for(let i=0;i{t.scale.setScalar(this._normalScale),t.traverse(s=>{s.castShadow=!0}),t.position.set(0,0,190),t.rotation.y=0,this._target=t,this._params.scene.add(this._target),this._mixer=new ko(this._target),this._manager=new Do,this._manager.onLoad=()=>{this._stateMachine.SetState("idle")};const n=(s,a)=>{const o=a.animations[0],c=this._mixer.clipAction(o);this._animations[s]={clip:o,action:c}},i=new Er(this._manager);i.setPath("./models/knight/"),i.load("walk.fbx",s=>{n("walk",s)}),i.load("run.fbx",s=>{n("run",s)}),i.load("idle.fbx",s=>{n("idle",s)}),i.load("attack_1.fbx",s=>{n("attack_1",s)}),i.load("attack_2.fbx",s=>{n("attack_2",s)}),i.load("death.fbx",s=>{n("death",s)})})}get position(){return this._position}get previousPosition(){return this._previousPosition}get rotation(){return this._target?this._target.quaternion:new pt}set rotation(e){this._target&&this._target.quaternion.copy(e)}get keyPressed(){const e=this._input._keys;return{w:e.forward,a:e.left,s:e.backward,d:e.right,shift:e.shift,space:e.space}}get hitFlag(){return this._hitFlag}set hitFlag(e){this._hitFlag=e}get hitDirection(){return this._hitDirection}set hitDirection(e){this._hitDirection=e}get hitIntensity(){return this._hitIntensity}set hitIntensity(e){this._hitIntensity=e}get damage(){return this._damage}get attackRange(){return this._attackRange}get transformed(){return this._transformed}get timeTransformed(){return this._timeTransformed}get transformationTime(){return this._transformationTime}_PlayerMovementHandler(e){const t=this._velocity,n=new T(t.x*this._decceleration.x,t.y*this._decceleration.y,t.z*this._decceleration.z);n.multiplyScalar(e),n.z=Math.sign(n.z)*Math.min(Math.abs(n.z),Math.abs(t.z)),t.add(n);const i=this._target,s=new pt,a=new T,o=i.quaternion.clone(),c=this._acceleration.clone();this._input._keys.shift&&c.multiplyScalar(3),this._input._keys.forward&&(t.z+=c.z*e),this._input._keys.backward&&(t.z-=c.z*e),this._input._keys.left&&(a.set(0,1,0),s.setFromAxisAngle(a,4*Math.PI*e*this._acceleration.y),o.multiply(s)),this._input._keys.right&&(a.set(0,1,0),s.setFromAxisAngle(a,4*-Math.PI*e*this._acceleration.y),o.multiply(s)),i.quaternion.copy(o);const l=new T;l.copy(i.position);const u=new T(0,0,1);u.applyQuaternion(i.quaternion),u.normalize(),u.multiplyScalar(t.z*e),i.position.add(u);const h=new T(1,0,0);h.applyQuaternion(i.quaternion),h.normalize(),h.multiplyScalar(t.x*e),i.position.add(h),this._worldBoundingBoxes.map(d=>{new bt().setFromObject(d).containsPoint(i.position)&&i.position.copy(l)}),this._position.copy(i.position),this._previousPosition.copy(l)}_DeathHandler(){this._params.healthBar.hearts.length===0&&this._stateMachine.SetState("death")}_HitHandler(){if(this._hitFlag){const e=Math.random()<.5?-1:1;this._target.rotation.y+=Math.PI/40*e;const t=this._target.position.z-this._hitDirection.z*this._hitIntensity;let n=!0;for(const i of this._params.world.boundingBoxes)if(new bt().setFromObject(i).containsPoint(new T(this._target.position.x,this._target.position.y,t))){n=!1;break}n&&(this._target.position.z=t),this._hitTime=Date.now()}}_TransformationHandler(){if(this._normalDamage=this._params.powerBar.swords.length,this._bigDamage=this._params.powerBar.swords.length*2,this._params.starCounter.stars>=this._starsToGetBigger&&!this._transformed){if(this._transformed=!0,this._timeTransformed=Date.now(),this._params.starCounter.stars=0,this._target.scale.setScalar(this._bigScale),this._damage=this._bigDamage,this._attackRange=this._bigAttackRange,this._params.healthBar.hearts.length<10){const e=this._params.healthBar.hearts.length;for(let t=0;t<10-e;t++)this._params.healthBar.addHeart()}this._particleSpawner.create({x:this._position.x-10,y:this._position.y,z:this._position.z-10,width:15,height:30,depth:15},300)}if(this._transformed&&Date.now()-this._timeTransformed>this._transformationTime&&(this._transformed=!1,this._timeTransformed=0,this._target.scale.setScalar(this._normalScale),this._damage=this._normalDamage,this._attackRange=this._normalAttackRange,this._params.powerBar.swords.length>1))for(let e=0;ethis._onKeyDown(e),!1),document.addEventListener("keyup",e=>this._onKeyUp(e),!1)}_onKeyDown(e){switch(e.keyCode){case 87:this._keys.forward=!0;break;case 65:this._keys.left=!0;break;case 83:this._keys.backward=!0;break;case 68:this._keys.right=!0;break;case 32:this._keys.space=!0;break;case 16:this._keys.shift=!0;break;case 17:this._keys.ctrl=!0;break}}_onKeyUp(e){switch(e.keyCode){case 87:this._keys.forward=!1;break;case 65:this._keys.left=!1;break;case 83:this._keys.backward=!1;break;case 68:this._keys.right=!1;break;case 32:this._keys.space=!1;break;case 16:this._keys.shift=!1;break;case 17:this._keys.ctrl=!1;break}}}class Lx{constructor(e){this._params=e,this._camera=e.camera,this._currentPosition=new T,this._currentLookat=new T}_CalculateIdealOffset(){const e=new T(-5,20,-30);return e.applyQuaternion(this._params.target.rotation),e.add(this._params.target.position),e}_CalculateIdealLookat(){const e=new T(0,10,50);return e.applyQuaternion(this._params.target.rotation),e.add(this._params.target.position),e}Update(e){const t=this._CalculateIdealOffset(),n=this._CalculateIdealLookat(),i=1-Math.pow(.001,e);this._currentPosition.lerp(t,i),this._currentLookat.lerp(n,i),this._camera.position.copy(this._currentPosition),this._camera.lookAt(this._currentLookat)}}class Ix{constructor(e){this._params=e,this._stars=[],this._lastSpawnTime=0,this._spawnInterval=12,this._maxstars=5,this._worldBoundingBoxes=[];for(const t of this._params.world.boundingBoxes)this._worldBoundingBoxes.push(t)}_LoadModels(){const e=new Yi;this._lastSpawnTime=Date.now(),e.load("./models/scene_objects/star.glb",t=>{t.scene.traverse(l=>{l.castShadow=!0});const n=t.scene;n.scale.set(3,3,3);let i=new T,s=!1;const a=new ze(230,50,150),o=new Le({color:65280,wireframe:!0,visible:!1}),c=new ye(a,o);for(c.position.set(0,25,-130),this._params.scene.add(c),this._worldBoundingBoxes.push(c);!s;){i.x=Math.random()*200-100,i.y=1,i.z=Math.random()*200-100,s=!0;for(const l of this._worldBoundingBoxes)if(new bt().setFromObject(l).containsPoint(i)){s=!1;break}}n.position.set(i.x,i.y,i.z),this._params.scene.add(n),this._stars.push(n)})}Update(e){Date.now()-this._lastSpawnTime>this._spawnInterval*1e3&&this._stars.length{t.rotation.y+=1*e})}get stars(){return this._stars}set stars(e){this._stars=e}}class Dx{constructor(e){this._params=e,this._hearts=[],this._lastSpawnTime=0,this._spawnInterval=18,this._maxHearts=5,this._worldBoundingBoxes=[];for(const t of this._params.world.boundingBoxes)this._worldBoundingBoxes.push(t)}_LoadModels(){const e=new Yi;this._lastSpawnTime=Date.now(),e.load("./models/scene_objects/heart.glb",t=>{t.scene.traverse(l=>{l.castShadow=!0});const n=t.scene;n.scale.set(5,5,5);let i=new T,s=!1;const a=new ze(230,50,150),o=new Le({color:65280,wireframe:!0,visible:!1}),c=new ye(a,o);for(c.position.set(0,25,-130),this._params.scene.add(c),this._worldBoundingBoxes.push(c);!s;){i.x=Math.random()*200-100,i.y=4,i.z=Math.random()*200-100,s=!0;for(const l of this._worldBoundingBoxes)if(new bt().setFromObject(l).containsPoint(i)){s=!1;break}}n.position.set(i.x,i.y,i.z),this._params.scene.add(n),this._hearts.push(n)})}Update(e){Date.now()-this._lastSpawnTime>this._spawnInterval*1e3&&this._hearts.length{t.rotation.y+=1*e})}get hearts(){return this._hearts}set hearts(e){this._hearts=e}}class Ux{constructor(e){this._params=e,this._swords=[],this._lastSpawnTime=0,this._spawnInterval=20,this._maxSwords=5,this._worldBoundingBoxes=[];for(const t of this._params.world.boundingBoxes)this._worldBoundingBoxes.push(t)}_LoadModels(){const e=new Yi;this._lastSpawnTime=Date.now(),e.load("./models/scene_objects/sword.glb",t=>{t.scene.traverse(l=>{l.castShadow=!0});const n=t.scene;n.scale.set(20,20,20);let i=new T,s=!1;const a=new ze(230,50,150),o=new Le({color:65280,wireframe:!0,visible:!1}),c=new ye(a,o);for(c.position.set(0,25,-130),this._params.scene.add(c),this._worldBoundingBoxes.push(c);!s;){i.x=Math.random()*200-100,i.y=4,i.z=Math.random()*200-100,s=!0;for(const l of this._worldBoundingBoxes)if(new bt().setFromObject(l).containsPoint(i)){s=!1;break}}n.position.set(i.x,i.y,i.z),n.rotation.x=Math.PI/4,this._params.scene.add(n),this._swords.push(n)})}Update(e){Date.now()-this._lastSpawnTime>this._spawnInterval*1e3&&this._swords.length{t.rotation.z+=1*e})}get swords(){return this._swords}set swords(e){this._swords=e}}class Nx{constructor(e){this._params=e,this._mobs=[],this._worldBoundingBoxes=[];for(const t of this._params.world.boundingBoxes)this._worldBoundingBoxes.push(t);this._playerPosition=this._params.playerPosition,this._mobAttackDistance=6,this._mobAttackTime=this._params.mobAttackTime,this._lastSpawnTime=0,this._minNumberOfMobs=12,this._LoadModels()}get mobs(){return this._mobs}get mobAttackDistance(){return this._mobAttackDistance}get mobAttackTime(){return this._mobAttackTime}_LoadModels(){const e=new Yi;this._mobPositions=[],this._mobPositions.push(new T(0,1,-20)),this._mobPositions.push(new T(0,1,110)),this._mobPositions.push(new T(-50,1,30)),this._mobPositions.push(new T(50,1,30)),this._mobPositions.push(new T(80,1,130)),this._mobPositions.push(new T(-80,1,130)),this._mobPositions.push(new T(-150,1,100)),this._mobPositions.push(new T(150,1,100)),this._mobPositions.push(new T(-110,1,50)),this._mobPositions.push(new T(110,1,50)),this._mobPositions.push(new T(-120,1,0)),this._mobPositions.push(new T(120,1,0));const t=this._mobPositions.length;for(let l=0;l{i.scene.traverse(h=>{h.castShadow=!0});const s=i.scene;s.scale.set(4,4,4),s.position.set(t.x,t.y,t.z),this._params.scene.add(s),n.mob=s,n.position=s.position,n.rotation=s.rotation,n.velocity=new T(0,0,1);const a=new ko(s),o=a.clipAction(i.animations[6]),c=a.clipAction(i.animations[5]),l=a.clipAction(i.animations[0]),u=a.clipAction(i.animations[1]);o.play(),n.walk=o,n.run=c,n.attack=l,n.dead=u,n.currentAction=o,n.mixer=a,this._walkY=s.position.y-1,this._runY=s.position.y-1.2,this._mobs.push(n)})}update(e){if(Date.now()-this._lastSpawnTime>1e4&&this._mobs.lengthn.mixer))t.update(e);for(const t of this._mobs){const n=this._playerPosition.distanceTo(t.position);let i=!1;for(const s of this._worldBoundingBoxes)if(new bt().setFromObject(s).containsPoint(this._playerPosition)){i=!0;break}t.currentAction!==t.dead&&(n<40&&!i?this.moveMobTowardsPlayer(t):this.moveMobRandomly(t)),t.life<=0&&this.dead(t)}}moveMobTowardsPlayer(e){const t=e.position,n=e.velocity,i=this._playerPosition.distanceTo(t);let s=!1;for(const a of this._worldBoundingBoxes)if(new bt().setFromObject(a).containsPoint(t)){s=!0;break}if(i5e3&&(n.set(Math.random()<.5?1:-1*Math.random(),0,Math.random()<.5?1:-1*Math.random()).normalize().multiplyScalar(.1),e.time=s);for(const c of this._worldBoundingBoxes)new bt().setFromObject(c).containsPoint(t)&&(n.set(-n.x,0,-n.z).normalize().multiplyScalar(.1),e.time=s);t.add(n),t.y=this._walkY;const o=Math.atan2(n.x,n.z);e.mob.rotation.y=o}dead(e){e.deadFlag?new Date().getTime()-e.deadTime>1e4?(this._params.scene.remove(e.mob),this._mobs=this._mobs.filter(t=>t!==e)):e.currentAction.time>e.currentAction.getClip().duration-.1&&(e.currentAction.paused=!0):(e.currentAction.stop(),e.currentAction=e.dead,e.currentAction.play(),e.deadFlag=!0,e.deadTime=new Date().getTime())}}class Fx{constructor(e){this._params=e,this._animations={},this._stateMachine=new kx(new Ox(this._animations)),this._velocity=new T,this._position=new T,this._previousPosition=new T,this._worldBoundingBoxes=[];for(const t of this._params.world.boundingBoxes)this._worldBoundingBoxes.push(t);this._playerPosition=this._params.playerPosition,this._monsterAttackRange={min:15,max:20},this._monsterAttackTime=this._params.monsterAttackTime,this._LoadModel(),this._timeLastWalk=0,this._timeLastIdle=0,this._timeLastAttack=0,this._timeLastRoar=0,this._monsterLife=100,this._monsterDamage=2,this._monsterLastHit=0,this._monsterState="roar"}get monsterAttackRange(){return this._monsterAttackRange}get monsterAttackTime(){return this._monsterAttackTime}get monsterDamage(){return this._monsterDamage}set monsterDamage(e){this._monsterDamage=e}get monsterLife(){return this._monsterLife}set monsterLife(e){this._monsterLife=e}get monsterLastHit(){return this._monsterLastHit}set monsterLastHit(e){this._monsterLastHit=e}get monsterPosition(){return this._position}get monsterState(){return this._monsterState}_LoadModel(){const e=new Er;e.setPath("./models/monster/"),e.load("monster.fbx",o=>{o.scale.setScalar(.06),o.traverse(d=>{d.castShadow=!0}),o.position.set(0,0,-140),o.rotation.y=0,o.scale.set(.13,.13,.13);const l=new Ss().load("./models/monster/monster_texture.png");o.traverse(d=>{d.isMesh&&(d.material.map=l)}),this._target=o,this._params.scene.add(this._target),this._position=this._target.position,this._previousPosition=this._target.position,this._rotation=this._target.rotation,this._velocity=new T(0,0,0),this._mixer=new ko(this._target),this._manager=new Do,this._manager.onLoad=()=>{this._stateMachine.SetState("idle")};const u=(d,f)=>{const _=f.animations[0],g=this._mixer.clipAction(_);this._animations[d]={clip:_,action:g}},h=new Er(this._manager);h.setPath("./models/monster/"),h.load("walk.fbx",d=>{u("walk",d)}),h.load("idle.fbx",d=>{u("idle",d)}),h.load("roar.fbx",d=>{u("roar",d)}),h.load("attack_1.fbx",d=>{u("attack_1",d)}),h.load("attack_2.fbx",d=>{u("attack_2",d)}),h.load("death.fbx",d=>{u("death",d)})});const t=new ze(30,50,10),n=new Le({color:65280,wireframe:!0,visible:!1}),i=new ye(t,n);i.position.set(0,25,-70),this._params.scene.add(i),this._worldBoundingBoxes.push(i);const s=new ze(201,50,100),a=new Le({color:65280,wireframe:!0,visible:!1});this._insideTowers=new ye(s,a),this._insideTowers.position.set(1,25,-145),this._params.scene.add(this._insideTowers)}update(e){this._stateMachine._currentState&&(this._stateMachine._currentState.Update(e),this._monsterLife<=0&&this._monsterState!=="death"?(this._stateMachine.SetState("death"),this._monsterState="death"):new bt().setFromObject(this._insideTowers).containsPoint(this._playerPosition)?this.attackPlayer():this.moveMonsterRandomly(e),this._mixer&&this._mixer.update(e))}moveMonsterRandomly(e){if(this._timeLastAttack=0,this._timeLastRoar=0,(this._stateMachine._currentState.Name==="attack_1"||this._stateMachine._currentState.Name==="attack_2")&&(this._stateMachine.SetState("idle"),this._monsterState="idle",this._timeLastIdle=Date.now()),this._stateMachine._currentState.Name==="idle"&&Date.now()-this._timeLastIdle>5e3?(this._stateMachine.SetState("walk"),this._monsterState="walk",this._timeLastWalk=Date.now(),this._velocity.set(Math.random()*2-1,0,Math.random()*2-1),this._velocity.normalize().multiplyScalar(.2)):this._stateMachine._currentState.Name==="walk"&&Date.now()-this._timeLastWalk>5e3&&(this._stateMachine.SetState("idle"),this._monsterState="idle",this._timeLastIdle=Date.now()),this._stateMachine._currentState.Name==="walk"){for(const n of this._worldBoundingBoxes)if(new bt().setFromObject(n).containsPoint(this._position)){this._velocity.set(-this._velocity.x,0,-this._velocity.z),this._position=this._previousPosition;break}this._position.add(this._velocity);const t=Math.atan2(this._velocity.x,this._velocity.z);this._rotation.y=t}}attackPlayer(){const e=this._playerPosition.distanceTo(this._position);if(this._timeLastAttack===0&&(this._timeLastAttack=Date.now()),this._timeLastRoar===0&&(this._timeLastRoar=Date.now()),ethis._monsterAttackRange.max){this._stateMachine.SetState("walk"),this._velocity.copy(this._playerPosition).sub(this._position).normalize().multiplyScalar(.2),this._position.add(this._velocity);const t=Math.atan2(this._playerPosition.x-this._position.x,this._playerPosition.z-this._position.z);this._rotation.y=t}else{const t=Math.atan2(this._playerPosition.x-this._position.x,this._playerPosition.z-this._position.z);this._rotation.y=t,(this._stateMachine._currentState.Name==="roar"||this._stateMachine._currentState.Name==="walk")&&Date.now()-this._timeLastRoar>2500?(this._stateMachine.SetState("attack_1"),this._timeLastAttack=Date.now(),this._monsterState="attack",this._monsterLastHit=Date.now()):(this._stateMachine._currentState.Name==="attack_1"||this._stateMachine._currentState.Name==="attack_2")&&Date.now()-this._timeLastAttack>2500&&(this._stateMachine.SetState("roar"),this._timeLastRoar=Date.now(),this._monsterState="roar")}}}class Ox{constructor(e){this._animations=e}get animations(){return this._animations}}class Bx{constructor(){this._states={},this._currentState=null}_AddState(e,t){this._states[e]=t}SetState(e){const t=this._currentState;if(t){if(t.Name==e)return;t.Exit()}const n=new this._states[e](this);this._currentState=n,n.Enter(t)}Update(e){this._currentState&&this._currentState.Update(e)}}class kx extends Bx{constructor(e){super(),this._proxy=e,this._Init()}_Init(){this._AddState("idle",zx),this._AddState("walk",Hx),this._AddState("roar",Vx),this._AddState("attack_1",Gx),this._AddState("attack_2",Wx),this._AddState("death",Xx)}}class Qi{constructor(e){this._parent=e}Enter(){}Exit(){}Update(){}}class zx extends Qi{constructor(e){super(e)}get Name(){return"idle"}Enter(e){const t=this._parent._proxy._animations.idle.action;if(e){const n=this._parent._proxy._animations[e.Name].action;t.time=0,t.enabled=!0,t.setEffectiveTimeScale(1),t.setEffectiveWeight(1),t.crossFadeFrom(n,.5,!0),t.play()}else t.play()}Exit(){}Update(e){}}class Hx extends Qi{constructor(e){super(e)}get Name(){return"walk"}Enter(e){const t=this._parent._proxy._animations.walk.action;if(e){const n=this._parent._proxy._animations[e.Name].action;if(t.enabled=!0,e.Name=="idle"){const i=t.getClip().duration/n.getClip().duration;t.time=n.time*i}else t.time=0,t.setEffectiveTimeScale(1),t.setEffectiveWeight(1);t.crossFadeFrom(n,.5,!0),t.play()}else t.play()}Exit(){}Update(e){}}class Vx extends Qi{constructor(e){super(e)}get Name(){return"roar"}Enter(e){const t=this._parent._proxy._animations.roar.action;if(e){const n=this._parent._proxy._animations[e.Name].action;if(t.enabled=!0,e.Name=="idle"){const i=t.getClip().duration/n.getClip().duration;t.time=n.time*i}else t.time=0,t.setEffectiveTimeScale(1),t.setEffectiveWeight(1);t.crossFadeFrom(n,.5,!0),t.play()}else t.play()}Exit(){}Update(e){}}class Gx extends Qi{constructor(e){super(e)}get Name(){return"attack_1"}Enter(e){const t=this._parent._proxy._animations.attack_1.action;if(e){const n=this._parent._proxy._animations[e.Name].action;if(t.enabled=!0,e.Name=="idle"){const i=t.getClip().duration/n.getClip().duration;t.time=n.time*i}else t.time=0,t.setEffectiveTimeScale(1),t.setEffectiveWeight(1);t.crossFadeFrom(n,.5,!0),t.play()}else t.play()}Exit(){}Update(e){}}class Wx extends Qi{constructor(e){super(e)}get Name(){return"attack_2"}Enter(e){const t=this._parent._proxy._animations.attack_2.action;if(e){const n=this._parent._proxy._animations[e.Name].action;if(t.enabled=!0,e.Name=="idle"){const i=t.getClip().duration/n.getClip().duration;t.time=n.time*i}else t.time=0,t.setEffectiveTimeScale(1),t.setEffectiveWeight(1);t.crossFadeFrom(n,.5,!0),t.play()}else t.play()}Exit(){}Update(e){}}class Xx extends Qi{constructor(e){super(e)}get Name(){return"death"}Enter(e){const t=this._parent._proxy._animations.death.action;if(e){const n=this._parent._proxy._animations[e.Name].action;if(t.enabled=!0,e.Name=="idle"){const i=t.getClip().duration/n.getClip().duration;t.time=n.time*i}else t.time=0,t.setEffectiveTimeScale(1),t.setEffectiveWeight(1);t.crossFadeFrom(n,.5,!0),t.play()}else t.play()}Exit(){}Update(e){}}class jx{constructor(){this._Initialize()}_Initialize(){this._threejs=new q_({antialias:!0}),this._threejs.outputEncoding=void 0,this._threejs.shadowMap.enabled=!0,this._threejs.shadowMap.type=vl,this._threejs.setPixelRatio(window.devicePixelRatio),this._threejs.setSize(window.innerWidth,window.innerHeight),document.body.appendChild(this._threejs.domElement),window.addEventListener("resize",()=>{this._OnWindowResize()},!1);const e=60,t=1920/1080,n=1,i=1e3;this._camera=new Dt(e,t,n,i),this._camera.position.set(150,200,300),this._camera.lookAt(new T(-44,0,-100)),this._scene=new Y_,this._mixers=[],this._previousRAF=null,this._currentCollectedStars=0,this._currentHitFromMobs=0,this._currentHitFromMonster=0,this._lastAttackTime=0,this._gameOver=!1,this._gameOverTime=0,this._gameWin=!1,this._gameWinTime=0,this._blockGame=!1,this._blockGui=!1,this._difficulty="medium",this._mobAttackTime={easy:1e3,medium:500,hard:300},this._mobHitsToDamage={easy:4,medium:3,hard:2},this._monsterAttackTime={easy:1100,medium:600,hard:400},this._monsterHitsToDamage={easy:2,medium:1,hard:1},this._monsterDamageNormal={easy:2,medium:2,hard:3},this._monsterDamageTransformed={easy:1,medium:1,hard:2},this._bloodSpawnerParams={scene:this._scene,colors:[9052185,8850949,6032904],radius:{baseRadius:.1,randomRadius:.1},opacity:{baseOpacity:1,randomOpacity:0},transparency:!1,velocity:{baseVelocity:new T(-.05,-.15,-.05),randomVelocity:new T(.5,.8,.5),baseSign:new T(1,-1,1),randomSign:new T(!0,!1,!0),update:!1},expirationTime:{baseExpirationTime:5e3,randomExpirationTime:2e3},boxX:{baseMin:-100,baseMax:100,randomMin:0,randomMax:0,blockAll:!1,visible:!0},boxY:{baseMin:.1,baseMax:100,randomMin:0,randomMax:0,blockAll:!0,visible:!0},boxZ:{baseMin:-100,baseMax:100,randomMin:0,randomMax:0,blockAll:!1,visible:!0}},this._bloodSpawner=new zo(this._bloodSpawnerParams),this._LoadWorld(),this._LoadGUI(),this._LoadStars(),this._LoadHearts(),this._LoadSwords(),this._LoadPlayer(),this._LoadMobs(),this._LoadMonster(),this._RAF()}_LoadWorld(){this._world=new C0({scene:this._scene})}_LoadGUI(){this._gui=new B0({player:this._player})}_LoadPlayer(){const e={camera:this._camera,scene:this._scene,world:this._world,healthBar:this._gui._healthBar,powerBar:this._gui._powerBar,starCounter:this._gui._starCounter};this._player=new Rx(e),this._thirdPersonCamera=new Lx({camera:this._camera,target:this._player})}_LoadStars(){this._starsSpawner=new Ix({scene:this._scene,world:this._world})}_LoadHearts(){this._heartSpawner=new Dx({scene:this._scene,world:this._world})}_LoadSwords(){this._swordSpawner=new Ux({scene:this._scene,world:this._world})}_LoadMobs(){this._mobSpawner=new Nx({scene:this._scene,world:this._world,playerPosition:this._player.position,mobAttackTime:this._mobAttackTime[this._difficulty]})}_LoadMonster(){this._monsterSpawner=new Fx({scene:this._scene,world:this._world,playerPosition:this._player.position,monsterAttackTime:this._monsterAttackTime[this._difficulty]})}_OnWindowResize(){this._camera.aspect=window.innerWidth/window.innerHeight,this._camera.updateProjectionMatrix(),this._threejs.setSize(window.innerWidth,window.innerHeight)}_RAF(){requestAnimationFrame(e=>{this._previousRAF===null&&(this._previousRAF=e),this._RAF(),this._threejs.render(this._scene,this._camera),this._Step(e-this._previousRAF),this._previousRAF=e})}_Update(e){this._mixers&&!this._blockGame&&this._mixers.map(t=>t.update(e)),this._player&&!this._blockGame&&this._player.Update(e),this._starsSpawner&&!this._blockGame&&this._starsSpawner.Update(e),this._heartSpawner&&!this._blockGame&&this._heartSpawner.Update(e),this._swordSpawner&&!this._blockGame&&this._swordSpawner.Update(e),this._mobSpawner&&!this._blockGame&&this._mobSpawner.update(e),this._monsterSpawner&&!this._blockGame&&this._monsterSpawner.update(e),this._bloodSpawner&&!this._blockGame&&this._bloodSpawner.update(),this._world&&!this._blockGame&&this._world.update(e),this._gui&&!this._blockGui&&(this._gui.start.play?(this._blockGame&&(this._player.rotation=new pt(0,1,0,0)),this._blockGame=!1,this._gui.healthBar.show(),this._gui.powerBar.show(),this._gui.starCounter.show(),this._gui.monsterLifeBar.show(),this._gui.transformationTime.show()):this._blockGame=!0,this._gui.monsterLifeBar.update(),this._gui.transformationTime.update(this._player.transformed),this._gui.start.update(),this._difficulty=this._gui.start._difficulty,this._gui._monsterLifeBar.monsterLife=this._monsterSpawner.monsterLife,this._player.transformed?this._gui._transformationTime.time=Math.ceil((this._gui._transformationTime.time=this._player.transformationTime-(Date.now()-this._player.timeTransformed))/1e3):this._gui._transformationTime.time=Math.ceil(this._player.transformationTime/1e3)),this._blockGame||this._thirdPersonCamera.Update(e)}_GameOverWinHandler(){this._gui._healthBar.hearts.length===0&&!this._gameOver&&(this._gameOver=!0,this._gameOverTime=new Date().getTime(),this._gui._gameOver.show()),this._monsterSpawner.monsterState==="death"&&!this._gameWin&&(this._gameWin=!0,this._gameWinTime=new Date().getTime(),this._gui._gameWin.show()),(this._gameOver&&Date.now()-this._gameOverTime>2e3||this._gameWin&&Date.now()-this._gameWinTime>2e3)&&(this._blockGame=!0,this._blockGui=!0)}_CollectorHandler(){this._player.transformed||(this._stars=this._starsSpawner.stars,this._playerPosition=this._player.position,this._stars.map(e=>{e.position.distanceTo(this._playerPosition)<8&&(this._scene.remove(e),this._stars=this._stars.filter(t=>t!==e),this._starsSpawner.stars=this._stars,this._gui._starCounter.addStar())})),this._hearts=this._heartSpawner.hearts,this._playerPosition=this._player.position,this._hearts.map(e=>{e.position.distanceTo(this._playerPosition)<8&&(this._scene.remove(e),this._hearts=this._hearts.filter(t=>t!==e),this._heartSpawner.hearts=this._hearts,this._gui._healthBar.addHeart())}),this._swords=this._swordSpawner.swords,this._playerPosition=this._player.position,this._swords.map(e=>{e.position.distanceTo(this._playerPosition)<8&&(this._scene.remove(e),this._swords=this._swords.filter(t=>t!==e),this._swordSpawner.swords=this._swords,this._gui._powerBar.addSword())})}_MobAttackHandler(){this._mobs=this._mobSpawner.mobs,this._mobAttackDistance=this._mobSpawner.mobAttackDistance,this._mobAttackTime=this._mobSpawner.mobAttackTime,this._player.hitFlag=!1;for(const t of this._mobs)this._playerPosition.distanceTo(t.position)this._mobAttackTime&&!t.deadFlag&&(t.lastHit=new Date().getTime(),this._player.hitFlag=!0,this._player.hitDirection=t.position.clone().sub(this._playerPosition).normalize(),this._player.transformed?this._player.hitIntensity=.3:this._player.hitIntensity=1,this._currentHitFromMobs+=1);this._currentHitFromMobs===this._mobHitsToDamage[this._difficulty]&&(this._gui._healthBar.removeHeart(),this._currentHitFromMobs=0,this._bloodSpawner.create({x:this._player.position.x,y:this._player.position.y,z:this._player.position.z,width:5,height:5,depth:5},30));const e=this._player.damage;if(this._player._stateMachine._currentState&&(this._player._stateMachine._currentState.Name==="attack_1"||this._player._stateMachine._currentState.Name==="attack_2")&&Date.now()-this._lastAttackTime>1e3)for(const t of this._mobs){const n=this._playerPosition.distanceTo(t.position),i=t.position.clone().sub(this._playerPosition).normalize(),o=this._player.position.clone().sub(this._player.previousPosition).normalize().dot(i)>.5;nthis._monsterAttackRange.min&&ethis._monsterAttackTime&&this._monsterState==="attack"&&(this._monsterSpawner.monsterLastHit=new Date().getTime(),this._currentHitFromMonster+=1,this._player.hitFlag=!0,this._player.hitDirection=this._monsterSpawner.monsterPosition.clone().sub(this._playerPosition).normalize(),this._player.transformed?this._player.hitIntensity=1:this._player.hitIntensity=3),this._currentHitFromMonster===this._monsterHitsToDamage[this._difficulty]){for(let t=0;t1e3&&e{new jx}); diff --git a/index.html b/index.html index da1a555..15477fe 100644 --- a/index.html +++ b/index.html @@ -3,7 +3,7 @@ Kill the Monster - +