UNPKG

ocearo-ui

Version:

Ocean Robot UI: Sailing made smarter

1 lines 16.1 kB
"use strict";(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[909],{11909:function(e,t,a){a.d(t,{Z:function(){return I}});var o=a(57437),r=a(2265),i=a(21276),s=a(53082),n=a(63321),l=a(41106),m=a(72079);function h(e,t,a){return e/1.9438444924574*Math.pow(t/10,a)*1.9438444924574}var c=a(53359),u=a(31378),g=a(70262),p=new WeakMap,d=new WeakMap;class f{calcShape(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:1;(0,g._)(this,d,[]);let t=this.chordTackLevel/((0,c._)(this,p)[(0,c._)(this,p).length-1].x-(0,c._)(this,p)[0].x);for(let a of(0,c._)(this,p)){let o=a.clone().multiplyScalar(t);1!==e&&(o.y*=e),(0,c._)(this,d).push(o)}let a=new m.FM8(0,0);for(let e of(0,c._)(this,d))e.y>a.y&&(a=e);this.draftDepth=a.y,this.draftPosition=a.x,this.girth=0;let o=null;for(let e of(0,c._)(this,d))null!==o&&(this.girth+=e.distanceTo(o)),o=e;this.sag=this.chordTackLevel-this.girth,this.entryAngleRad=(0,c._)(this,d)[1].clone().sub((0,c._)(this,d)[0]).angle(),this.exitAngleRad=(0,c._)(this,d)[(0,c._)(this,d).length-1].clone().sub((0,c._)(this,d)[(0,c._)(this,d).length-2]).angle()-2*Math.PI,this.mastAngleRad=this.calcMastAngle(),this.forceAngleRad=(this.entryAngleRad+this.exitAngleRad)/2,this.draftDepthRatio=this.draftDepth/this.chordTackLevel,this.draftPositionRatio=this.draftPosition/this.chordTackLevel}calcMastAngle(){let e=0,t=null,a=this.mastWidth*this.chordTackLevel/this.chordMastTop;for(let o of(0,c._)(this,d)){if(null!==t&&(e+=o.distanceTo(t))>=a)return o.angle();t=o}return NaN}getVerticesAngles(e,t){let a=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null,o=(this.girth-t)/(e-1),r=0,i=0,s=[],n=null;for(let l of(0,c._)(this,d)){if(null!==n&&(((i+=l.distanceTo(n))>=r*o+t||a&&i>a)&&(r++,s.push(l.angle())),r>=e))break;n=l}return s}pointAtGirthDistance(e){let t=0,a=null;for(let o of(0,c._)(this,d))if(null!==a&&(t+=o.distanceTo(a)),a=o,t>=e)return a.clone()}constructor(e,t,a,o=1){(0,u._)(this,p,{writable:!0,value:void 0}),(0,u._)(this,d,{writable:!0,value:void 0}),(0,g._)(this,p,[]),(0,g._)(this,d,[]),this.chordMastTop=t,this.chordTackLevel=e,this.mastWidth=a;let r=function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:1;return new m.FM8(t*e**2,2*t*e)},i=1.001+.95*(o-1)/10,s=(i-.001)/1e3,n=r(.001),l=r(i).clone().sub(n).angle(),h=new m.FM8(0,0);for(let e=.001;e<=i;e+=s){let t=r(e);t.sub(n),t.rotateAround(h,-l),(0,c._)(this,p).push(t)}this.calcShape(1-.25*(o-1)/10)}}let y=Math.floor(20),_=Math.ceil(160),M={waterlineToMastFootHeight:.45,maxMastRotation:Math.PI/2,maxChordRotationPerSailLevel:Math.PI/3*2};var x=e=>{let{windParams:t={speed:5,hellman:.27},boatParams:a={mastrotation:0,heading:130,speed:5},sailParams:i={mastArea:0,sailArea:0,cunningham:1,angleOfAttack:20}}=e,{getSignalKValue:n}=(0,s.yC)(),l=(0,r.useRef)(),c=(0,r.useRef)(null),u=(0,r.useRef)(0),g=(0,r.useRef)(null),p=(0,r.useRef)(null),d=(0,r.useRef)(),x=(0,r.useRef)({}),b=(0,r.useMemo)(()=>{let e=new m.ZAu,t=new m.b_z(.1,.2,12),a=new m.Wid({color:s.gK,opacity:.5,transparent:!0}),o=new m.Kj0(t,a);return o.position.set(0,-.1,0),e.add(o),e},[]);(0,r.useEffect)(()=>{let e=new m.ZAu,t={};for(let a=0;a<8;a+=.5){let o=b.clone();o.position.set(0,a,0),t[2*a]=o,e.add(o)}return e.position.set(0,0,0),d.current&&d.current.add(e),x.current=t,()=>{e.clear()}},[b]);let P=(e,t)=>{let a=x.current;if(!a){console.error("apparentWindField is not initialized.");return}for(let o=0;o<8;o+=.5){let r=h(e,o,t),i=a[2*o];if(!i){console.warn("Apparent wind field cone at height ".concat(o," is not defined."));continue}i.scale.set(.1*r,r,.1*r),i.rotation.set(0,-Math.PI,Math.PI/2)}},{geometry:v,sailClipWidthPerLevel:j}=(0,r.useMemo)(()=>{let e=new m.u9r,t=[],a=[],o=[];for(let e=0;e<=_;e++){let r,i;let s=Math.min(50*e,8e3);s<900?(r=3600,i=3800+-200*s/900):i=r=3600-3210*(s-900)/7100+600*Math.sin((s-900)/7100*Math.PI);let n=0;for(let o=0;o<y;o++){let l=r/(y-1),m=l*o-i,h=l;m>.1&&(h=m>l?0:l-m),t.push(0===o?0:(n+h)/1e3,s/1e3,0),n=0===o?0:n+h;let c=Math.floor(_/10);a.push(...e%c==0?[.8,0,.047]:[.596,.596,.596])}o.push(i===r?null:i)}let r=[];for(let e=0;e<_;e++)for(let t=1;t<y;t++){let a=e*y+t;r.push(a-1,a,a+y-1,a,a+y,a+y-1)}return e.setAttribute("position",new m.a$l(t,3)),e.setAttribute("color",new m.a$l(a,3)),e.setIndex(r),e.computeVertexNormals(),{geometry:e,sailClipWidthPerLevel:o}},[]),I=(0,r.useMemo)(()=>n("environment.wind.angleApparent")||0,[n]),A=(0,r.useMemo)(()=>n("environment.wind.speedApparent")||0,[n]);return(0,r.useEffect)(()=>{if(!l.current)return;P(A,t.hellman);let e=l.current.geometry,o=e.attributes.position.array;i.cunningham!==g.current&&(p.current=new f(3600,390,200,i.cunningham),g.current=i.cunningham),c.current||(c.current=e.clone());let r=1e3*M.waterlineToMastFootHeight,s=I;for(;s<0;)s+=2*Math.PI;for(;s>=2*Math.PI;)s-=2*Math.PI;let n=s>Math.PI?-1:1,d=s;d>Math.PI&&(d=2*Math.PI-d);let x=m.M8C.degToRad(i.angleOfAttack),b=p.current.mastAngleRad;d<.01&&(x=0);let v=Math.min(d-x+b,M.maxMastRotation),w=new m.Pa4(0,1,0),R=null;for(let e=0;e<=_;e++){h(A,(50*e+r)/1e3,t.hellman);let a=d-x;a<0?a=0:a>Math.PI/2&&(a=Math.PI/2);let i=a-v;R&&i-R>M.maxChordRotationPerSailLevel&&(i=R+M.maxChordRotationPerSailLevel),R=i;let s=j[e],l=p.current.getVerticesAngles(y,200,s);for(let t=1;t<y;t++){let a=(e*y+t)*3,r=new m.Pa4(c.current.attributes.position.array[a],c.current.attributes.position.array[a+1],c.current.attributes.position.array[a+2]);r.applyAxisAngle(w,-(i+l[t])*n),o[a]=r.x,o[a+1]=r.y,o[a+2]=r.z}}e.attributes.position.needsUpdate=!0;let T={...a,mastrotation:v*n};l.current&&l.current.rotateY(u.current-T.mastrotation),u.current=T.mastrotation},[A,I,t.hellman,i.cunningham,i.angleOfAttack,a,j]),(0,o.jsxs)("mesh",{ref:l,position:[0,2,-1],rotation:[0,-Math.PI/2,0],children:[(0,o.jsx)("bufferGeometry",{...v}),(0,o.jsx)("group",{ref:d}),(0,o.jsx)("meshBasicMaterial",{vertexColors:!0,transparent:!0,opacity:.7,side:m.ehD})]})};let b=a(40257).env.ASSET_PREFIX||"./",P=function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"default";return"".concat(b,"/boats/").concat(e,"/assets/scene-transformed.glb")},v={name:"Default",modelPath:"default",capabilities:["navigation","rudder","sail","color"]},j=(0,r.forwardRef)((e,t)=>{let{showSail:a=!1,onUpdateInfoPanel:h,...c}=e,u=(0,r.useRef)(),g=(0,r.useRef)(),{getSignalKValue:p}=(0,s.yC)(),d=n.Z.getAll(),[f,y]=(0,r.useState)(()=>n.Z.getSelectedBoat()||v);(0,r.useEffect)(()=>{y(n.Z.getSelectedBoat()||v)},[d]);let _=(0,r.useMemo)(()=>P(f.modelPath),[f]),M=(null==f?void 0:f.capabilities)||[],{nodes:j,materials:I}=(0,l.L)(_,"".concat(b,"/draco/")),A=(0,r.useMemo)(()=>({primaryColor:d.primaryColor,metallicEffect:d.metallicEffect||!1}),[d.primaryColor,d.metallicEffect]);(0,r.useEffect)(()=>{if("default"===f.modelPath){if(!(null==I?void 0:I.fiberglass))return;I.fiberglass.color.set(A.primaryColor),I.fiberglass.metalness=A.metallicEffect?1:0,I.fiberglass.roughness=A.metallicEffect?.2:1}else u.current&&u.current.traverse(e=>{e.isMesh&&e.material&&(Array.isArray(e.material)?e.material.forEach(e=>{e.color.set(A.primaryColor),e.metalness=A.metallicEffect?1:0,e.roughness=A.metallicEffect?.2:1}):(e.material.color.set(A.primaryColor),e.material.metalness=A.metallicEffect?1:0,e.material.roughness=A.metallicEffect?.2:1))});Object.values(I).forEach(e=>{e.map&&(e.map.minFilter=m.wem,e.map.magFilter=m.wem,e.map.anisotropy=1)})},[I,A,f,u]);let w=(0,r.useMemo)(()=>new m.yGw,[]),R=(0,r.useMemo)(()=>new m.Pa4(1,0,0),[]);(0,i.F)(()=>{if(!u.current)return;let e=p("navigation.attitude.roll")||0,t=p("steering.rudderAngle")||0;u.current.rotation.z!==e&&(u.current.rotation.z=e),g.current&&(w.makeRotationFromEuler(new m.USm(-Math.PI/2,Math.PI/2,0)),g.current.setRotationFromMatrix(w),g.current.rotateOnAxis(R,-m.M8C.degToRad(180*t/Math.PI)))});let T=(0,r.useMemo)(()=>{let e={Default:()=>(0,o.jsxs)(o.Fragment,{children:[(0,o.jsx)("mesh",{geometry:j.baba_metal_0.geometry,material:I.metal,position:[.24,.895,-5.546],rotation:[-Math.PI/2,0,1.968],scale:.027}),(0,o.jsx)("mesh",{geometry:j.camadadirek_fiberglass_0.geometry,material:I.fiberglass,position:[0,5.267,-3.711],rotation:[2.054,0,Math.PI],scale:[-.042,.042,4.707]}),(0,o.jsx)("mesh",{geometry:j.camadanyelkeni_bez_0.geometry,material:I.mcaterial,position:[0,5.267,-3.711],rotation:[2.054,0,Math.PI],scale:[-.042,.042,4.707]}),(0,o.jsx)("mesh",{geometry:j.camadaonbaglay_metal_0.geometry,material:I.metal,position:[0,.891,-5.958],rotation:[-Math.PI/2,0,0],scale:.02}),(0,o.jsx)("mesh",{geometry:j.capa_metal_0.geometry,material:I.metal,position:[0,.671,-6.173],rotation:[-Math.PI/2,0,0],scale:.348}),(0,o.jsx)("mesh",{geometry:j.direk_fiberglass_0.geometry,material:I.fiberglass,position:[0,4.315,-1.056],rotation:[Math.PI/2,0,Math.PI],scale:[-.113,.113,5.203]}),(0,o.jsx)("mesh",{geometry:j.duman_ahsap_0.geometry,material:I.ahsap,position:[-.011,.854,3.487],rotation:[Math.PI,0,Math.PI/2],scale:[.045,.045,.011]}),(0,o.jsx)("mesh",{geometry:j.dumenyuvasi_ahsap_0.geometry,material:I.ahsap,position:[-.011,.299,3.441],rotation:[-Math.PI/2,0,1.571],scale:.094}),(0,o.jsx)("mesh",{geometry:j.dumenyuvasi_cam_0.geometry,material:I.material_5,position:[-.011,.299,3.441],rotation:[-Math.PI/2,0,1.571],scale:.094}),(0,o.jsx)("mesh",{geometry:j.dumenyuvasi_fiberglass_0.geometry,material:I.fiberglass,position:[-.011,.299,3.441],rotation:[-Math.PI/2,0,1.571],scale:.094}),(0,o.jsx)("mesh",{geometry:j.govde_fiberglass2_0.geometry,material:I.fiberglass2,position:[0,.32,-.897],rotation:[0,Math.PI/2,0],scale:[5.11,.454,1.212]}),(0,o.jsx)("mesh",{geometry:j.govde_fiberglass_0.geometry,material:I.fiberglass,position:[0,.32,-.897],rotation:[0,Math.PI/2,0],scale:[5.11,.454,1.212]}),(0,o.jsx)("mesh",{geometry:j.govde_metal_0.geometry,material:I.metal,position:[0,.32,-.897],rotation:[0,Math.PI/2,0],scale:[5.11,.454,1.212]}),(0,o.jsx)("mesh",{geometry:j.halattutucu_fiberglass2_0.geometry,material:I.fiberglass2,position:[-1.044,.939,1.809],rotation:[-Math.PI/2,0,0],scale:[.016,.059,.016]}),(0,o.jsx)("mesh",{geometry:j.ip001_metal_0.geometry,material:I.metal,position:[-.231,7.608,-.621],rotation:[-2.322,.222,-1.556],scale:[.007,.007,.011]}),(0,o.jsx)("mesh",{geometry:j.pervan_fiberglass_0.geometry,material:I.fiberglass,position:[0,-1.005,1.561],rotation:[-Math.PI/2,Math.PI/2,0],scale:[.154,.094,.104]}),(0,o.jsx)("mesh",{geometry:j.pervane_metal_0.geometry,material:I.metal,position:[0,-1.122,1.75],scale:.034}),(0,o.jsx)("mesh",{ref:g,geometry:j.rudder_fiberglass_0.geometry,material:I.fiberglass,position:[0,-1.153,3.486],rotation:[-Math.PI/2,Math.PI/2,0],scale:[.573,.262,.262]}),(0,o.jsx)("mesh",{geometry:j.salma_fiberglass_0.geometry,material:I.fiberglass,position:[0,-1.953,-.739],scale:[.149,.108,.756]}),(0,o.jsx)("mesh",{geometry:j.ustcam_cam_0.geometry,material:I.material_5,position:[-.337,.974,-3.127],rotation:[-Math.PI/2,0,0],scale:[-.183,.133,.025]}),(0,o.jsx)("mesh",{geometry:j.ustcam_fiberglass_0.geometry,material:I.fiberglass,position:[-.337,.974,-3.127],rotation:[-Math.PI/2,0,0],scale:[-.183,.133,.025]}),(0,o.jsx)("mesh",{geometry:j.ustgovde_fiberglass_0.geometry,material:I.fiberglass,position:[0,.832,-2.741],rotation:[-Math.PI/2,0,0],scale:[.566,.7,1.212]}),(0,o.jsx)("mesh",{geometry:j.ustgovdekzak_ahsap_0.geometry,material:I.ahsap,position:[0,.862,-2.741],rotation:[-Math.PI/2,0,0],scale:[.566,.7,1.212]}),(0,o.jsx)("mesh",{geometry:j.vinc_metal_0.geometry,material:I.metal,position:[-1.07,.977,2.02],rotation:[-Math.PI/2,0,0],scale:.065}),(0,o.jsx)("mesh",{geometry:j.yancam002_cam_0.geometry,material:I.material_5,position:[-.984,.591,-3.772],rotation:[Math.PI,-1.241,-Math.PI/2],scale:[.095,.28,.014]}),(0,o.jsx)("mesh",{geometry:j.yancam002_fiberglass_0.geometry,material:I.fiberglass,position:[-.984,.591,-3.772],rotation:[Math.PI,-1.241,-Math.PI/2],scale:[.095,.28,.014]}),(0,o.jsx)("mesh",{geometry:j.yankoruma_metal_0.geometry,material:I.metal,position:[-1.641,.946,2.868],rotation:[-Math.PI/2,0,0],scale:[.01,.01,.159]}),(0,o.jsx)("mesh",{geometry:j.yankoruma_metal_0001.geometry,material:I.metal,position:[-1.641,.946,2.868],rotation:[-Math.PI/2,0,0],scale:[.01,.01,.159]}),(0,o.jsx)("mesh",{geometry:j.yankoruma_metal_0002.geometry,material:I.metal,position:[-1.641,.946,2.868],rotation:[-Math.PI/2,0,0],scale:[.01,.01,.159]}),(0,o.jsx)("mesh",{geometry:j.zincir_metal_0.geometry,material:I.metal,position:[-.001,.88,-6.258],rotation:[-1.56,-.031,-.149],scale:.004}),(0,o.jsx)("mesh",{geometry:j.zincir_metal_0001.geometry,material:I.metal,position:[-.001,.88,-6.258],rotation:[-1.56,-.031,-.149],scale:.004}),(0,o.jsx)("mesh",{geometry:j.zincirdeposu_fiberglass2_0.geometry,material:I.fiberglass2,position:[0,.863,-5.779],rotation:[-Math.PI/2,0,0],scale:[.103,.088,.009]}),(0,o.jsx)("mesh",{geometry:j.zincirmakara_metal_0.geometry,material:I.metal,position:[0,.869,-6.305],rotation:[-2.159,1.564,.59],scale:[.01,.01,.016]}),(0,o.jsx)("mesh",{geometry:j.zincirray_ahsap_0.geometry,material:I.ahsap,position:[0,.864,-6.113],rotation:[-Math.PI/2,0,0],scale:[.017,.181,.003]})]}),Optimist:()=>(0,o.jsxs)(o.Fragment,{children:[(0,o.jsx)("mesh",{geometry:j.body_body_0.geometry,material:I.body,position:[-.054,.272,-.022],rotation:[-1.571,.01,.01],scale:[1,5.242,1]}),(0,o.jsx)("mesh",{geometry:j.boom_aluminium_0.geometry,material:I.aluminium,position:[-.019,2.771,.964],rotation:[0,.01,-.01],scale:[.15,.15,4.609]}),(0,o.jsx)("mesh",{geometry:j.rubber_joint__0.geometry,material:I.rubber_joint__0,position:[-.008,1.407,3.453],rotation:[1.571,-.01,-.01],scale:[-.037,.056,.079]}),(0,o.jsx)("mesh",{geometry:j.sail_sail_0.geometry,material:I.sail,position:[.038,8.739,.698],rotation:[2.356,1.557,2.356],scale:[-5.728,4.361,4.361]})]}),Ship:()=>(0,o.jsx)("mesh",{geometry:j.Object_10.geometry,material:I.material_0,position:[0,-.55,0],rotation:[-1.558,.002,3.139],scale:.004}),Windsurf:()=>(0,o.jsx)("mesh",{geometry:j["body_Material_#30_0"].geometry,material:I.Material_30,position:[-.007,0,-.071],rotation:[-Math.PI/2,0,0],scale:.002}),Sailboat:()=>(0,o.jsx)("mesh",{geometry:j.sailboat.geometry,material:I.texture,position:[0,-1.5,0],rotation:[-Math.PI,.011,-Math.PI],scale:.219})};return e[f.name]||e.Default},[f.name,j,I]),k=(0,r.useMemo)(()=>({name:f.name||"Sailboat",type:"sailboat",trueWindAngle:p("environment.wind.angleTrueWater")||0,trueWindSpeed:p("environment.wind.speedTrue")||0,appWindAngle:p("environment.wind.angleApparent")||0,appWindSpeed:p("environment.wind.speedApparent")||0,beatAngle:p("performance.beatAngle")||0,polarSpeed:p("performance.polarSpeed")||0,polarSpeedRatio:p("performance.polarSpeedRatio")||0,velocityMadeGood:p("performance.velocityMadeGood")||0,speedThroughWater:p("navigation.speedThroughWater")||0,headingTrue:p("navigation.headingTrue")||0,courseOverGroundTrue:p("navigation.courseOverGroundTrue")||0,position:p("navigation.position")||{latitude:0,longitude:0}}),[p,f.name]),S=e=>{let t=[];return e.name&&t.push("Name: ".concat(e.name)),e.trueWindSpeed&&t.push("Wind: ".concat((0,s.Qj)(e.trueWindSpeed),"kn @ ").concat((0,s.Ux)(e.trueWindAngle),"\xb0")),e.appWindSpeed&&t.push("App Wind: ".concat((0,s.Qj)(e.appWindSpeed),"kn @ ").concat((0,s.Ux)(e.appWindAngle),"\xb0")),e.speedThroughWater&&t.push("Speed: ".concat((0,s.Qj)(e.speedThroughWater),"kn")),void 0!==e.headingTrue&&null!==e.headingTrue&&t.push("Heading: ".concat((0,s.Ux)(e.headingTrue),"\xb0")),void 0!==e.courseOverGroundTrue&&null!==e.courseOverGroundTrue&&t.push("COG: ".concat((0,s.Ux)(e.courseOverGroundTrue),"\xb0")),e.velocityMadeGood&&t.push("VMG: ".concat((0,s.Qj)(e.velocityMadeGood),"kn")),e.polarSpeedRatio&&t.push("Polar: ".concat((100*e.polarSpeedRatio).toFixed(0),"%")),e.position&&void 0!==e.position.latitude&&void 0!==e.position.longitude&&t.push("Position: ".concat(e.position.latitude.toFixed(4),"\xb0, ").concat(e.position.longitude.toFixed(4),"\xb0")),t.join("\n")},[W,E]=(0,r.useState)(!1);return(0,o.jsxs)("group",{...c,ref:u,dispose:null,onClick:()=>{let e=!W;E(e),h&&h(e?S(k):null)},children:[M.includes("sail")&&a&&(0,o.jsx)(x,{}),(0,o.jsx)(T,{})]})});l.L.preload(P(),"".concat(b,"/draco/")),j.displayName="SailBoat3D";var I=j}}]);