@pan-ya/libgeo3dviewer 1.7.39 → 1.7.40
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1208,7 +1208,7 @@ vPositionW = vec3(worldPos);
|
|
|
1208
1208
|
|
|
1209
1209
|
#define CUSTOM_VERTEX_MAIN_END
|
|
1210
1210
|
vColor = vec4(instanceColor.rgb, instanceColor.a);
|
|
1211
|
-
}`,Yn=({alpha:e,zOffset:t,zOffsetUnits:n,disableDepthWrite:a})=>C.jsx("pbrMaterial",{name:"metal-pbr-material",alpha:e,transparencyMode:e!==void 0&&e<1?u.Material.MATERIAL_ALPHABLEND:u.Material.MATERIAL_OPAQUE,alphaMode:u.Engine.ALPHA_COMBINE,roughness:.25,metallic:1,albedoColor:new u.Color3(.7,.7,.7),metallicF0Factor:.1,zOffset:t,zOffsetUnits:n,disableDepthWrite:a}),Jn=({alpha:e,zOffset:t,zOffsetUnits:n,disableDepthWrite:a})=>C.jsx("pbrMaterial",{name:"metal-pbr-material",alpha:e,transparencyMode:e!==void 0&&e<1?u.Material.MATERIAL_ALPHABLEND:u.Material.MATERIAL_OPAQUE,alphaMode:u.Engine.ALPHA_COMBINE,roughness:.25,metallic:1,albedoColor:new u.Color3(.2,.2,.2),metallicF0Factor:.1,zOffsetUnits:n,zOffset:t,disableDepthWrite:a});var qt=(e=>(e[e.TRIGONOMETRIC=0]="TRIGONOMETRIC",e[e.PLANE=1]="PLANE",e[e.FLAT=2]="FLAT",e))(qt||{});const Kt=e=>{const t=_e.useScene(),[n,a]=m.useState(null),[i,o]=m.useState(null),{tilingFactor:r=.1,sideTilingFactor:l=.1,texture:s,alpha:c=1,mode:p=0,zOffset:f,zOffsetUnits:d,sideTexture:x,uvOffset:h=u.Vector2.Zero(),counterLine:T=void 0,scalePlane:P=1,scaleDepth:v=1,boundingBox:_=void 0,lines:b=[],text:k=[],disableDepthWrite:M,flatModeRotate:w=0}=e,S=N=>{a(N)};return m.useEffect(()=>{n&&s&&(n.setTexture("textureSampler",s),n.setFloat("textureFlatRotate",w),n.setVector2("uvOffset",h))},[w,n,s,h]),m.useEffect(()=>{n&&n.setFloat("alpha",c)},[c,n]),m.useEffect(()=>{n&&n.setFloat("tilingFactor",r),n&&n.setFloat("sideTilingFactor",l)},[r,l,n]),m.useEffect(()=>{n&&n.setInt("mode",p)},[n,p]),m.useEffect(()=>{n&&(x?n.setTexture("textureSideSampler",x):n.setTexture("textureSideSampler",s))},[n,x,s]),m.useEffect(()=>{var N;if(n)if(T&&_){const F=(N=T.startHeight)!=null?N:_.minimumWorld.y/v;return n.setFloat("contourLineStartHeight",F*v),n.setColor3("contourLineColor",T.color),n.setFloat("contourLineWidth",T.width),n.setFloat("contourLineStep",T.stepHeight*v),console.log("[Geo3DViewer] 等高线设置 ",T,_.centerWorld.y,F*v,F*v+16*T.stepHeight*v),()=>{n&&(n.setFloat("contourLineStartHeight",0),n.setColor3("contourLineColor",new u.Color3(0,0,0)),n.setFloat("contourLineWidth",0),n.setFloat("contourLineStep",0))}}else n.setFloat("contourLineStartHeight",0),n.setColor3("contourLineColor",new u.Color3(0,0,0)),n.setFloat("contourLineWidth",0),n.setFloat("contourLineStep",0),console.log("[Geo3DViewer] 等高线设置 关闭")},[T,v,P,_,n]),m.useEffect(()=>{t&&n&&_&&o(N=>{N&&N.dispose();let F=(_.maximum.x-_.minimum.x)/P,B=(_.maximum.z-_.minimum.z)/P,I=0;if(F<B){const L=F;F=B,B=L,I=1}const D=F/B;F*B>2048*2048&&(F=2048,B=2048/D);const E=new u.DynamicTexture("dynamic-texture",{width:F,height:B},t,!1);return E.clear(),console.log("[Geo3DViewer] 设置动态划线 ",_,F,B,P),n.setVector3("oMin",_.minimum),n.setVector3("oMax",_.maximum),n.setFloat("textureOverlayRotate",I),n.setTexture("textureOverlaySampler",E),E})},[_,n,P,t]),m.useEffect(()=>{var N;if(i&&_)if((N=i.getScene())!=null&&N.getEngine()){i.clear();let F=(_.maximum.x-_.minimum.x)/P,B=(_.maximum.z-_.minimum.z)/P;if(F<B){const E=F;F=B,B=E}const I=F/B;F*B>2048*2048&&(F=2048,B=2048/I);const D=i.getContext();b.forEach(E=>{if(E.points.length<2)return;D.beginPath();const L=E.offset?E.offset:new u.Vector2(0,0),y=1-E.points[0].x+L.x,A=1-E.points[0].y+L.y;D.moveTo(y*F,A*B);for(let V=1;V<E.points.length;V++){const $=E.offset?E.offset:new u.Vector2(0,0),W=1-E.points[V].x+$.x,ne=1-E.points[V].y+$.y;D.lineTo(W*F,ne*B)}D.strokeStyle=`rgb(${E.color.r*255}, ${E.color.g*255}, ${E.color.b*255})`,F*B>2048*2048?D.lineWidth=E.width/I:D.lineWidth=E.width,D.stroke()}),k.forEach(E=>{var V,$;D.font=`${E.fontSize}px Arial`;const L=(V=E.color)!=null?V:u.Color3.White(),y=E.offset?E.offset:new u.Vector2(0,0),A=($=E.rotation)!=null?$:0;if(D.save(),D.translate((1-E.position.x+y.x)*F,(1-E.position.y+y.y)*B),D.rotate(A),E.clearArea){const W=D.measureText(E.text);D.clearRect(-W.width*.15,.5*E.fontSize*(1-.3),W.width*1.3,-E.fontSize*1.3)}if(E.background){D.fillStyle=`rgba(${E.background.r*255}, ${E.background.g*255}, ${E.background.b*255})`;const W=D.measureText(E.text);D.fillRect(-W.width*.05,.5*(E.fontSize*(.5-.1)),W.width*1.1,-E.fontSize*1.1)}D.fillStyle=`rgb(${L.r*255}, ${L.g*255}, ${L.b*255})`,D.fillText(E.text,0,0),D.restore()}),i.update()}else console.log("[Geo3DViewer] 动态纹理未准备好,正准备下一次绘制")},[b,k,i,_,P]),C.jsx(lt,{...e,ref:S,vertex:gu,fragment:mu,options:{attributes:["position","color","alpha","normal"],uniforms:["worldViewProjection","tilingFactor","sideTilingFactor","mode","uvOffset","contourLineStartHeight","contourLineColor","contourLineWidth","contourLineStep","oMin","oMax","textureOverlayRotate","textureFlatRotate"],samplers:["textureSampler","textureOverlaySampler","textureSideSampler"],needAlphaBlending:!0,needAlphaTesting:!0},zOffset:f,zOffsetUnits:d,disableDepthWrite:M})},Mt=e=>{const t=_e.useScene(),n=m.useRef(null),a=m.useContext(Vn),[i,o]=m.useState(null),{name:r,colorCodec:l,alpha:s=1,backFaceCulling:c,needDepthPrePass:p=!1,transparencyMode:f=u.Material.MATERIAL_OPAQUE,alphaMode:d=u.Engine.ALPHA_COMBINE,zOffset:x,zOffsetUnits:h,clipPlane:T,counterLine:P=void 0,scalePlane:v=1,scaleDepth:_=1,boundingBox:b,lines:k=[],text:M=[],disableDepthWrite:w}=e;return m.useEffect(()=>{const S=n.current;S&&t&&(S.loadFromSerialization(du,""),S.build(!1,!0,!1))},[t]),m.useEffect(()=>{const S=n.current;S&&(S.name=`${r}-material`,S.backFaceCulling=c!=null?c:!0,S.needDepthPrePass=p,S.transparencyMode=f,S.alphaMode=d,S.alpha=s,S.zOffset=x!=null?x:1,S.zOffsetUnits=h!=null?h:0,S.clipPlane=T!=null?T:null,S.disableDepthWrite=w!=null?w:!1)},[s,d,c,T,w,r,p,f,x,h]),m.useEffect(()=>{if(l){const S=n.current;S&&(S.metadata={colorCodec:l},u.Tags.EnableFor(S),u.Tags.AddTagsTo(S,"remap"))}if(l&&a&&t&&a.colorCodecsImage.current[l]){const S=n.current;if(S){const N=S.getBlockByName("RemappedTexture");N&&(N.texture=a.colorCodecsImage.current[l].texture,S.markAsDirty(u.NodeMaterial.TextureDirtyFlag))}}},[l,t]),m.useEffect(()=>{n.current&&t&&(console.log("[Geo3DViewer] RemapColorByRedChannel 透明度更新 ",s),n.current.alpha=s)},[t,s]),m.useEffect(()=>{var N;const S=n.current;if(S){const F=S.getBlockByName("contourLineStartHeight"),B=S.getBlockByName("contourLineColor"),I=S.getBlockByName("contourLineWidth"),D=S.getBlockByName("contourLineStep");if(P&&b){const E=(N=P.startHeight)!=null?N:b.centerWorld.y/_;return F&&(F.value=E*_),B&&(B.value=P.color),I&&(I.value=P.width),D&&(D.value=P.stepHeight*_),console.log("[Geo3DViewer] 等高线设置 ",P,b.centerWorld,b.centerWorld.y,E*_,E*_+16*P.stepHeight*_),()=>{S&&(F&&(F.value=0),B&&(B.value=new u.Color3(0,0,0)),I&&(I.value=0),D&&(D.value=0))}}else F&&(F.value=0),B&&(B.value=new u.Color3(0,0,0)),I&&(I.value=0),D&&(D.value=0),console.log("[Geo3DViewer] 等高线设置 关闭");S.markAsDirty(u.NodeMaterial.MiscDirtyFlag)}},[P,_,v,b]),m.useEffect(()=>{t&&b&&o(S=>{var y,A;S&&S.dispose();let N=(b.maximum.x-b.minimum.x)/v,F=(b.maximum.z-b.minimum.z)/v,B=0;if(N<F){const V=N;N=F,F=V,B=1}const I=N/F;N*F>2048*2048&&(N=2048,F=2048/I);const D=new u.DynamicTexture("dynamic-texture",{width:N,height:F},t,!1);D.clear(),console.log("[Geo3DViewer] 设置动态划线 ",b,N,F,v);const E=(y=n.current)==null?void 0:y.getBlockByName("angle"),L=(A=n.current)==null?void 0:A.getBlockByName("OverlayTexture");return E&&(E.value=B*(Math.PI/2)),L&&(L.texture=D),D})},[b,v,t]),m.useEffect(()=>{var S;if(i&&b)if((S=i.getScene())!=null&&S.getEngine()){i.clear();let N=(b.maximum.x-b.minimum.x)/v,F=(b.maximum.z-b.minimum.z)/v;if(N<F){const D=N;N=F,F=D}const B=N/F;N*F>2048*2048&&(N=2048,F=2048/B);const I=i.getContext();k.forEach(D=>{if(D.points.length<2)return;I.beginPath();const E=D.offset?D.offset:new u.Vector2(0,0),L=1-D.points[0].x+E.x,y=1-D.points[0].y+E.y;I.moveTo(L*N,y*F);for(let A=1;A<D.points.length;A++){const V=D.offset?D.offset:new u.Vector2(0,0),$=1-D.points[A].x+V.x,W=1-D.points[A].y+V.y;I.lineTo($*N,W*F)}I.strokeStyle=`rgb(${D.color.r*255}, ${D.color.g*255}, ${D.color.b*255})`,N*F>2048*2048?I.lineWidth=D.width/B:I.lineWidth=D.width,I.stroke()}),M.forEach(D=>{var A,V;I.font=`${D.fontSize}px Arial`;const E=(A=D.color)!=null?A:u.Color3.White(),L=D.offset?D.offset:new u.Vector2(0,0),y=(V=D.rotation)!=null?V:0;if(I.save(),I.translate((1-D.position.x+L.x)*N,(1-D.position.y+L.y)*F),I.rotate(y),D.clearArea){const $=I.measureText(D.text);I.clearRect(-$.width*.15,.5*D.fontSize*(1-.3),$.width*1.3,-D.fontSize*1.3)}if(D.background){I.fillStyle=`rgba(${D.background.r*255}, ${D.background.g*255}, ${D.background.b*255})`;const $=I.measureText(D.text);I.fillRect(-$.width*.05,.5*(D.fontSize*(.5-.1)),$.width*1.1,-D.fontSize*1.1)}I.fillStyle=`rgb(${E.r*255}, ${E.g*255}, ${E.b*255})`,I.fillText(D.text,0,0),I.restore()}),i.update()}else console.log("[Geo3DViewer] 动态纹理未准备好,正准备下一次绘制")},[k,i,b,v,M]),C.jsx("nodeMaterial",{ref:n,name:`${r}-material`,backFaceCulling:c,needDepthPrePass:p,transparencyMode:f,alphaMode:d,alpha:s,zOffset:x,zOffsetUnits:h,clipPlane:T,disableDepthWrite:w})},Qi=e=>{const t=_e.useScene(),n=m.useContext(Vn),a=m.useRef(null),[i,o]=m.useState(null),[r,l]=m.useState(null),[s,c]=m.useState(null),[p,f]=m.useState(null),[d,x]=m.useState(null),[h,T]=m.useState(null),[P,v]=m.useState(null),[_,b]=m.useState(null),{boundingBox:k,colorCodec:M,alphaStage:w,cutNormal:S,value:N,zOffset:F,zOffsetUnits:B,counterLine:I=void 0,scaleDepth:D=1,scalePlane:E=1,lines:L=[],text:y=[],disableDepthWrite:A}=e;return m.useEffect(()=>{const V=($,W,ne)=>{if(k){const ee=k.maximumWorld.multiply(W),G=k.minimumWorld.multiply(W),le=k.centerWorld.multiply(W),re=Math.max(ee.x,ee.y,ee.z),oe=Math.max(G.x,G.y,G.z),Y=Math.max(le.x,le.y,le.z),ce=Math.max(Math.abs(W.x),Math.abs(W.z));$(new u.Plane(W.x,W.y,W.z,((re-oe)*(1-ne-.5)*ce+Y)*-1))}else $(null)};k&&_&&(V(o,_.cutPlane1,N.value1),_.cutPlane2&&N.value2?V(l,_.cutPlane2,N.value2):l(null),_.cutPlane3&&N.value3?V(c,_.cutPlane3,N.value3):c(null),_.cutPlane4&&N.value4?V(f,_.cutPlane4,N.value4):f(null),_.cutPlane5&&N.value5?V(x,_.cutPlane5,N.value5):c(null),_.cutPlane6&&N.value6?V(T,_.cutPlane6,N.value6):T(null))},[k,_,N]),m.useEffect(()=>{b({cutPlane1:u.Vector3.Normalize(S.cutPlane1),cutPlane2:S.cutPlane2?u.Vector3.Normalize(S.cutPlane2):void 0,cutPlane3:S.cutPlane3?u.Vector3.Normalize(S.cutPlane3):void 0,cutPlane4:S.cutPlane4?u.Vector3.Normalize(S.cutPlane4):void 0,cutPlane5:S.cutPlane5?u.Vector3.Normalize(S.cutPlane5):void 0,cutPlane6:S.cutPlane6?u.Vector3.Normalize(S.cutPlane6):void 0})},[S]),m.useEffect(()=>{const V=a.current;V&&(V.clipPlane=i,V.clipPlane2=r,V.clipPlane3=s,V.clipPlane4=p,V.clipPlane5=d,V.clipPlane6=h)},[i,r,s,p,d,h]),m.useEffect(()=>{var V,$,W,ne,ee;a.current&&t&&(a.current.setFloat("alpha1",w.alpha1),a.current.setFloat("alpha2",(V=w.alpha2)!=null?V:1),a.current.setFloat("alpha3",($=w.alpha3)!=null?$:1),a.current.setFloat("alpha4",(W=w.alpha4)!=null?W:1),a.current.setFloat("alpha5",(ne=w.alpha5)!=null?ne:1),a.current.setFloat("alpha6",(ee=w.alpha6)!=null?ee:1))},[t,w]),m.useEffect(()=>{if(M){const V=a.current;V&&(V.metadata={colorCodec:M},u.Tags.EnableFor(V),u.Tags.AddTagsTo(V,"remap"))}if(M&&n&&t&&n.colorCodecsImage.current[M]){const V=a.current;V&&(console.log(n.colorCodecsImage.current[M]),V.setTexture("textureSampler",n.colorCodecsImage.current[M].texture),V.metadata={colorCodec:M},u.Tags.EnableFor(V),u.Tags.AddTagsTo(V,"remap"))}},[M,t]),m.useEffect(()=>{var $;const V=a.current;if(V&&k)if(I){const W=($=I.startHeight)!=null?$:k.minimumWorld.y/D;return V.setFloat("contourLineStartHeight",W*D),V.setColor3("contourLineColor",I.color),V.setFloat("contourLineWidth",I.width),V.setFloat("contourLineStep",I.stepHeight*D),console.log("[Geo3DViewer] 等高线设置 ",I,k.centerWorld.y,W*D,W*D+16*I.stepHeight*D),()=>{V&&(V.setFloat("contourLineStartHeight",0),V.setColor3("contourLineColor",new u.Color3(0,0,0)),V.setFloat("contourLineWidth",0),V.setFloat("contourLineStep",0))}}else V.setFloat("contourLineStartHeight",0),V.setColor3("contourLineColor",new u.Color3(0,0,0)),V.setFloat("contourLineWidth",0),V.setFloat("contourLineStep",0),console.log("[Geo3DViewer] 等高线设置 关闭")},[I,D,E,k]),m.useEffect(()=>{t&&k&&v(V=>{var le,re,oe,Y;V&&V.dispose();let $=(k.maximum.x-k.minimum.x)/E,W=(k.maximum.z-k.minimum.z)/E,ne=0;if($<W){const ce=$;$=W,W=ce,ne=1}const ee=$/W;$*W>2048*2048&&($=2048,W=2048/ee);const G=new u.DynamicTexture("dynamic-texture",{width:$,height:W},t,!1);return G.clear(),console.log("[Geo3DViewer] 设置动态划线 ",k,$,W,E),(le=a.current)==null||le.setVector3("oMin",k.minimum),(re=a.current)==null||re.setVector3("oMax",k.maximum),(oe=a.current)==null||oe.setFloat("textureOverlayRotate",ne),(Y=a.current)==null||Y.setTexture("textureOverlaySampler",G),G})},[k,E,t]),m.useEffect(()=>{var V;if(P&&k)if((V=P.getScene())!=null&&V.getEngine()){P.clear();let $=(k.maximum.x-k.minimum.x)/E,W=(k.maximum.z-k.minimum.z)/E;if($<W){const G=$;$=W,W=G}const ne=$/W;$*W>2048*2048&&($=2048,W=2048/ne);const ee=P.getContext();L.forEach(G=>{if(G.points.length<2)return;ee.beginPath();const le=G.offset?G.offset:new u.Vector2(0,0),re=1-G.points[0].x+le.x,oe=1-G.points[0].y+le.y;ee.moveTo(re*$,oe*W);for(let Y=1;Y<G.points.length;Y++){const ce=G.offset?G.offset:new u.Vector2(0,0),ae=1-G.points[Y].x+ce.x,X=1-G.points[Y].y+ce.y;ee.lineTo(ae*$,X*W)}ee.strokeStyle=`rgb(${G.color.r*255}, ${G.color.g*255}, ${G.color.b*255})`,$*W>2048*2048?ee.lineWidth=G.width/ne:ee.lineWidth=G.width,ee.stroke()}),y.forEach(G=>{var Y,ce;ee.font=`${G.fontSize}px Arial`;const le=(Y=G.color)!=null?Y:u.Color3.White(),re=G.offset?G.offset:new u.Vector2(0,0),oe=(ce=G.rotation)!=null?ce:0;if(ee.save(),ee.translate((1-G.position.x+re.x)*$,(1-G.position.y+re.y)*W),ee.rotate(oe),G.clearArea){const ae=ee.measureText(G.text);ee.clearRect(-ae.width*.15,.5*G.fontSize*(1-.3),ae.width*1.3,-G.fontSize*1.3)}if(G.background){ee.fillStyle=`rgba(${G.background.r*255}, ${G.background.g*255}, ${G.background.b*255})`;const ae=ee.measureText(G.text);ee.fillRect(-ae.width*.05,.5*(G.fontSize*(.5-.1)),ae.width*1.1,-G.fontSize*1.1)}ee.fillStyle=`rgb(${le.r*255}, ${le.g*255}, ${le.b*255})`,ee.fillText(G.text,0,0),ee.restore()}),P.update()}else console.log("[Geo3DViewer] 动态纹理未准备好,正准备下一次绘制")},[L,P,k,E,y]),C.jsx(lt,{...e,ref:a,vertex:hu,fragment:pu,options:{attributes:["position","color","normal"],uniforms:["world","worldViewProjection","alpha1","alpha2","alpha3","alpha4","alpha5","alpha6","oMin","oMax","contourLineStartHeight","contourLineColor","contourLineWidth","contourLineStep","textureOverlayRotate"],samplers:["textureOverlaySampler","textureSampler"],needAlphaBlending:!0,needAlphaTesting:!0,useClipPlane:!0},disableDepthWrite:A,zOffset:F,zOffsetUnits:B})},ji=e=>{const t=_e.useScene(),[n,a]=m.useState(null),[i,o]=m.useState(null),[r,l]=m.useState(null),[s,c]=m.useState(null),[p,f]=m.useState(null),[d,x]=m.useState(null),[h,T]=m.useState(null),[P,v]=m.useState(null),[_,b]=m.useState(null),{boundingBox:k=void 0,texture:M,sideTexture:w,alphaStage:S,cutNormal:N,value:F,tilingFactor:B=.1,sideTilingFactor:I=.1,mode:D=0,zOffset:E,zOffsetUnits:L,overlay:y={},counterLine:A=void 0,scalePlane:V=1,scaleDepth:$=1,lines:W=[],text:ne=[],disableDepthWrite:ee,textureFlatRotate:G=0}=e,le=re=>{a(re)};return m.useEffect(()=>{n&&n.setFloat("textureFlatRotate",G)},[n,G]),m.useEffect(()=>{const re=(oe,Y,ce)=>{if(k){const ae=k.maximumWorld.multiply(Y),X=k.minimumWorld.multiply(Y),Pe=k.centerWorld.multiply(Y),ge=Math.max(ae.x,ae.y,ae.z),H=Math.max(X.x,X.y,X.z),Q=Math.max(Pe.x,Pe.y,Pe.z),Ee=Math.max(Math.abs(Y.x),Math.abs(Y.z)),ke=new u.Plane(Y.x,Y.y,Y.z,((ge-H)*(1-ce-.5)*Ee+Q)*-1);oe(ke),console.log("[Geo3DViewer] 设置实际 CutPlane 为 ",ke,Ee)}else oe(null)};k&&_&&(re(o,_.cutPlane1,F.value1),_.cutPlane2&&F.value2?re(l,_.cutPlane2,F.value2):l(null),_.cutPlane3&&F.value3?re(c,_.cutPlane3,F.value3):c(null),_.cutPlane4&&F.value4?re(f,_.cutPlane4,F.value4):f(null),_.cutPlane5&&F.value5?re(x,_.cutPlane5,F.value5):c(null),_.cutPlane6&&F.value6?re(T,_.cutPlane6,F.value6):T(null))},[_,k,F]),m.useEffect(()=>{b({cutPlane1:u.Vector3.Normalize(N.cutPlane1),cutPlane2:N.cutPlane2?u.Vector3.Normalize(N.cutPlane2):void 0,cutPlane3:N.cutPlane3?u.Vector3.Normalize(N.cutPlane3):void 0,cutPlane4:N.cutPlane4?u.Vector3.Normalize(N.cutPlane4):void 0,cutPlane5:N.cutPlane5?u.Vector3.Normalize(N.cutPlane5):void 0,cutPlane6:N.cutPlane6?u.Vector3.Normalize(N.cutPlane6):void 0})},[N]),m.useEffect(()=>{n&&(n.clipPlane=i,n.clipPlane2=r,n.clipPlane3=s,n.clipPlane4=p,n.clipPlane5=d,n.clipPlane6=h)},[n,i,r,s,p,d,h]),m.useEffect(()=>{var re,oe,Y,ce,ae;n&&t&&(n.setFloat("alpha1",S.alpha1),n.setFloat("alpha2",(re=S.alpha2)!=null?re:1),n.setFloat("alpha3",(oe=S.alpha3)!=null?oe:1),n.setFloat("alpha4",(Y=S.alpha4)!=null?Y:1),n.setFloat("alpha5",(ce=S.alpha5)!=null?ce:1),n.setFloat("alpha6",(ae=S.alpha6)!=null?ae:1))},[t,S,n]),m.useEffect(()=>{n&&M&&n.setTexture("textureSampler",M)},[n,M]),m.useEffect(()=>{n&&B&&n.setFloat("tilingFactor",B),n&&I&&n.setFloat("sideTilingFactor",I)},[B,I,n]),m.useEffect(()=>{n&&D&&n.setInt("mode",D)},[n,D]),m.useEffect(()=>{n&&(w?n.setTexture("textureSideSampler",w):n.setTexture("textureSideSampler",M))},[n,w,M]),m.useEffect(()=>{n&&(y.texture1?n.setTexture("textureSampler1",y.texture1):n.setTexture("textureSampler1",M),y.sideTexture1?n.setTexture("textureSideSampler1",y.sideTexture1):n.setTexture("textureSideSampler1",M),y.color1?n.setColor3("vColor1",y.color1):n.setColor3("vColor1",new u.Color3(1,1,1)),y.texture2?n.setTexture("textureSampler2",y.texture2):n.setTexture("textureSampler2",M),y.sideTexture2?n.setTexture("textureSideSampler2",y.sideTexture2):n.setTexture("textureSideSampler2",M),y.color2?n.setColor3("vColor2",y.color2):n.setColor3("vColor2",new u.Color3(1,1,1)),y.texture3?n.setTexture("textureSampler3",y.texture3):n.setTexture("textureSampler3",M),y.sideTexture3?n.setTexture("textureSideSampler3",y.sideTexture3):n.setTexture("textureSideSampler2",M),y.color3?n.setColor3("vColor3",y.color3):n.setColor3("vColor3",new u.Color3(1,1,1)),y.texture4?n.setTexture("textureSampler4",y.texture4):n.setTexture("textureSampler4",M),y.sideTexture4?n.setTexture("textureSideSampler4",y.sideTexture4):n.setTexture("textureSideSampler4",M),y.color4?n.setColor3("vColor4",y.color4):n.setColor3("vColor4",new u.Color3(1,1,1)),y.texture5?n.setTexture("textureSampler5",y.texture5):n.setTexture("textureSampler5",M),y.sideTexture5?n.setTexture("textureSideSampler5",y.sideTexture5):n.setTexture("textureSideSampler5",M),y.color5?n.setColor3("vColor5",y.color5):n.setColor3("vColor5",new u.Color3(1,1,1)),y.texture6?n.setTexture("textureSampler6",y.texture6):n.setTexture("textureSampler6",M),y.sideTexture6?n.setTexture("textureSideSampler6",y.sideTexture6):n.setTexture("textureSideSampler6",M),y.color6?n.setColor3("vColor6",y.color6):n.setColor3("vColor6",new u.Color3(1,1,1)))},[n,y,M]),m.useEffect(()=>{var re;if(n&&k)if(A){const oe=(re=A.startHeight)!=null?re:k.minimumWorld.y/$;return n.setFloat("contourLineStartHeight",oe*$),n.setColor3("contourLineColor",A.color),n.setFloat("contourLineWidth",A.width),n.setFloat("contourLineStep",A.stepHeight*$),console.log("[Geo3DViewer] 等高线设置 ",A,k.centerWorld.y,oe*$,oe*$+16*A.stepHeight*$),()=>{n&&(n.setFloat("contourLineStartHeight",0),n.setColor3("contourLineColor",new u.Color3(0,0,0)),n.setFloat("contourLineWidth",0),n.setFloat("contourLineStep",0))}}else n.setFloat("contourLineStartHeight",0),n.setColor3("contourLineColor",new u.Color3(0,0,0)),n.setFloat("contourLineWidth",0),n.setFloat("contourLineStep",0),console.log("[Geo3DViewer] 等高线设置 关闭")},[A,$,V,k,n]),m.useEffect(()=>{t&&n&&k&&v(re=>{re&&re.dispose();let oe=(k.maximum.x-k.minimum.x)/V,Y=(k.maximum.z-k.minimum.z)/V,ce=0;if(oe<Y){const Pe=oe;oe=Y,Y=Pe,ce=1}const ae=oe/Y;oe*Y>2048*2048&&(oe=2048,Y=2048/ae);const X=new u.DynamicTexture("dynamic-texture",{width:oe,height:Y},t,!1);return X.clear(),console.log("[Geo3DViewer] 设置动态划线 ",k,oe,Y,V),n.setVector3("oMin",k.minimum),n.setVector3("oMax",k.maximum),n.setFloat("textureOverlayRotate",ce),n.setTexture("textureOverlaySampler",X),X})},[k,n,V,t]),m.useEffect(()=>{var re;if(P&&k)if((re=P.getScene())!=null&&re.getEngine()){P.clear();let oe=(k.maximum.x-k.minimum.x)/V,Y=(k.maximum.z-k.minimum.z)/V;if(oe<Y){const X=oe;oe=Y,Y=X}const ce=oe/Y;oe*Y>2048*2048&&(oe=2048,Y=2048/ce);const ae=P.getContext();W.forEach(X=>{if(X.points.length<2)return;ae.beginPath();const Pe=X.offset?X.offset:new u.Vector2(0,0),ge=1-X.points[0].x+Pe.x,H=1-X.points[0].y+Pe.y;ae.moveTo(ge*oe,H*Y);for(let Q=1;Q<X.points.length;Q++){const Ee=X.offset?X.offset:new u.Vector2(0,0),ke=1-X.points[Q].x+Ee.x,te=1-X.points[Q].y+Ee.y;ae.lineTo(ke*oe,te*Y)}ae.strokeStyle=`rgb(${X.color.r*255}, ${X.color.g*255}, ${X.color.b*255})`,oe*Y>2048*2048?ae.lineWidth=X.width/ce:ae.lineWidth=X.width,ae.stroke()}),ne.forEach(X=>{var Q,Ee;ae.font=`${X.fontSize}px Arial`;const Pe=(Q=X.color)!=null?Q:u.Color3.White(),ge=X.offset?X.offset:new u.Vector2(0,0),H=(Ee=X.rotation)!=null?Ee:0;if(ae.save(),ae.translate((1-X.position.x+ge.x)*oe,(1-X.position.y+ge.y)*Y),ae.rotate(H),X.clearArea){const ke=ae.measureText(X.text);ae.clearRect(-ke.width*.15,.5*X.fontSize*(1-.3),ke.width*1.3,-X.fontSize*1.3)}if(X.background){ae.fillStyle=`rgba(${X.background.r*255}, ${X.background.g*255}, ${X.background.b*255})`;const ke=ae.measureText(X.text);ae.fillRect(-ke.width*.05,.5*(X.fontSize*(.5-.1)),ke.width*1.1,-X.fontSize*1.1)}ae.fillStyle=`rgb(${Pe.r*255}, ${Pe.g*255}, ${Pe.b*255})`,ae.fillText(X.text,0,0),ae.restore()}),P.update()}else console.log("[Geo3DViewer] 动态纹理未准备好,正准备下一次绘制")},[W,P,k,V,ne]),C.jsx(lt,{...e,ref:le,vertex:xu,fragment:vu,options:{attributes:["position","color","normal"],uniforms:["world","worldViewProjection","alpha1","alpha2","alpha3","alpha4","alpha5","alpha6","oMin","oMax","tilingFactor","sideTilingFactor","mode","vColor1","vColor2","vColor3","vColor4","vColor5","vColor6","contourLineStartHeight","contourLineColor","contourLineWidth","contourLineStep","textureOverlayRotate","textureFlatRotate"],samplers:["textureSampler","textureOverlaySampler","textureSideSampler","textureSampler1","textureSideSampler1","textureSampler2","textureSideSampler2","textureSampler3","textureSideSampler3","textureSampler4","textureSideSampler4","textureSampler5","textureSideSampler5","textureSampler6","textureSideSampler6"],needAlphaBlending:!0,needAlphaTesting:!0,useClipPlane:!0},zOffset:E,zOffsetUnits:L,disableDepthWrite:ee})},_u=e=>C.jsx(lt,{...e,vertex:Gn,fragment:Zn,options:{needAlphaBlending:!0},zOffset:e.zOffset,zOffsetUnits:e.zOffsetUnits,disableDepthWrite:e.disableDepthWrite}),Pu=()=>C.jsx(lt,{name:"picking-material",vertex:Ac,fragment:Oc,backFaceCulling:!1,options:{attributes:["position","color","normal"],uniforms:["world","worldViewProjection","pickingColor","isPickable"]}}),Su=({name:e,scene:t})=>{const n=u.NodeMaterial.Parse(Nc,t);return n.name=e,n.backFaceCulling=!1,n.build(!1,!0,!1),n},Tu=({name:e,lineColor:t,lineWidth:n=.5})=>{const a=_e.useScene(),[i,o]=m.useState(null);return m.useEffect(()=>{if(a){const r=u.NodeMaterial.Parse(ql,a);return r.name=`${e}-material`,r.backFaceCulling=!1,r.build(!1,!0,!1),o(r),()=>{o(l=>(l==null||l.dispose(!0,!1),null))}}},[e,a]),m.useEffect(()=>{o(r=>r&&t?(r.getBlockByName("Color3").value=t,r.build(!1,!0,!1),r):null)},[t]),m.useEffect(()=>{o(r=>{if(r&&n!==void 0&&n!==null){let l=n;return n<1&&(l=1),r.getBlockByName("offset").value=1-l,r.build(!1,!0,!1),r}return null})},[n]),i},bu=(e,t)=>{const n=m.useRef(null);return m.useEffect(()=>{n.current&&(n.current.setVector4("typeAlpha1",new u.Vector4(e.typeAlpha.typeAlpha0===void 0?1:e.typeAlpha.typeAlpha0,e.typeAlpha.typeAlpha1,e.typeAlpha.typeAlpha2,e.typeAlpha.typeAlpha3)),n.current.setVector4("typeAlpha2",new u.Vector4(e.typeAlpha.typeAlpha4,e.typeAlpha.typeAlpha5,e.typeAlpha.typeAlpha6,e.typeAlpha.typeAlpha7)),n.current.setVector4("typeAlpha3",new u.Vector4(e.typeAlpha.typeAlpha8,e.typeAlpha.typeAlpha9,e.typeAlpha.typeAlpha10,e.typeAlpha.typeAlpha11)),n.current.setVector4("typeAlpha4",new u.Vector4(e.typeAlpha.typeAlpha12,e.typeAlpha.typeAlpha13,e.typeAlpha.typeAlpha14,e.typeAlpha.typeAlpha15)),n.current.setVector4("typeAlpha5",new u.Vector4(e.typeAlpha.typeAlpha16,e.typeAlpha.typeAlpha17,e.typeAlpha.typeAlpha18,e.typeAlpha.typeAlpha19)))},[e.typeAlpha]),m.useImperativeHandle(t,()=>n.current,[]),C.jsx(lt,{ref:n,name:e.name,backFaceCulling:!0,needDepthPrePass:!1,vertex:Cu,fragment:yu,transparencyMode:u.Material.MATERIAL_ALPHABLEND,alphaMode:u.Engine.ALPHA_COMBINE,options:{attributes:["position","color","uv","normal","world0","world1","world2","world3","instanceColor"],uniforms:["world","worldViewProjection","view","viewProjection","typeAlpha1","typeAlpha2","typeAlpha3","typeAlpha4","worldView","projection","previousWorld","vEyePosition"],defines:["#define INSTANCESCOLOR","#define INSTANCES"],needAlphaBlending:!0,needAlphaTesting:!0}})},Mn=e=>{const t=_e.useScene(),[n,a]=m.useState(null),i=m.useRef(null),{boundingBox:o,counterLine:r,scaleDepth:l=1,scalePlane:s=1,color:c,alpha:p=1,lines:f=[],text:d=[],surfaceCanvasOptions:x={textureIncludeSide:!0},disableDepthWrite:h,disableNormalShadow:T=!1}=e,{textureIncludeSide:P}=x;return m.useEffect(()=>{i.current&&(console.log("[Geo3DViewer] 设置材质 ",c,p),i.current.setColor3("vColor",c),i.current.setFloat("vAlpha",p),i.current.setFloat("textureIncludeSide",P==null?1:0))},[c,p,P]),m.useEffect(()=>{var _;const v=i.current;if(v&&o)if(r){const b=(_=r.startHeight)!=null?_:o.maximumWorld.y/l;return v.setFloat("contourLineStartHeight",b*l),v.setColor3("contourLineColor",r.color),v.setFloat("contourLineWidth",r.width),v.setFloat("contourLineStep",r.stepHeight*l),console.log("[Geo3DViewer] 等高线设置 ",r,o.centerWorld.y,b*l,b*l-16*r.stepHeight*l),()=>{v&&(v.setFloat("contourLineStartHeight",0),v.setColor3("contourLineColor",new u.Color3(0,0,0)),v.setFloat("contourLineWidth",0),v.setFloat("contourLineStep",0))}}else v.setFloat("contourLineStartHeight",0),v.setColor3("contourLineColor",new u.Color3(0,0,0)),v.setFloat("contourLineWidth",0),v.setFloat("contourLineStep",0),console.log("[Geo3DViewer] 等高线设置 关闭")},[o,r,l,s]),m.useEffect(()=>{const v=i.current;t&&o&&v&&a(_=>{let b=(o.maximum.x-o.minimum.x)/s,k=(o.maximum.z-o.minimum.z)/s,M=0;if(b<k){const N=b;b=k,k=N,M=1}const w=b/k;b*k>2048*2048&&(b=2048,k=2048/w);let S;return _?(_.scaleTo(b,k),_.update(),S=_):S=new u.DynamicTexture("dynamic-texture",{width:b,height:k},t,!1),S.clear(),S.update(),console.log("[Geo3DViewer] 设置动态划线 ",o,b,k,s),v.setVector3("oMin",o.minimum),v.setVector3("oMax",o.maximum),v.setFloat("textureOverlayRotate",M),v.setTexture("textureOverlaySampler",S),S})},[o,s,t]),m.useEffect(()=>{var v;if(n&&o&&(f.length>0||d.length>0))if((v=n.getScene())!=null&&v.getEngine()){n.clear();let _=(o.maximum.x-o.minimum.x)/s,b=(o.maximum.z-o.minimum.z)/s;if(_<b){const w=_;_=b,b=w}const k=_/b;_*b>2048*2048&&(_=2048,b=2048/k);const M=n.getContext();f.forEach(w=>{if(w.points.length<2)return;M.beginPath();const S=w.offset?w.offset:new u.Vector2(0,0),N=1-w.points[0].x+S.x,F=1-w.points[0].y+S.y;M.moveTo(N*_,F*b);for(let B=1;B<w.points.length;B++){const I=w.offset?w.offset:new u.Vector2(0,0),D=1-w.points[B].x+I.x,E=1-w.points[B].y+I.y;M.lineTo(D*_,E*b)}M.strokeStyle=`rgb(${w.color.r*255}, ${w.color.g*255}, ${w.color.b*255})`,_*b>2048*2048?M.lineWidth=w.width/k:M.lineWidth=w.width,M.stroke()}),d.forEach(w=>{var B,I;M.font=`${w.fontSize}px Arial`;const S=(B=w.color)!=null?B:u.Color3.White(),N=w.offset?w.offset:new u.Vector2(0,0),F=(I=w.rotation)!=null?I:0;if(M.save(),M.translate((1-w.position.x+N.x)*_,(1-w.position.y+N.y)*b),M.rotate(F),w.clearArea){const D=M.measureText(w.text);M.clearRect(-D.width*.15,.5*w.fontSize*(1-.3),D.width*1.3,-w.fontSize*1.3)}if(w.background){M.fillStyle=`rgba(${w.background.r*255}, ${w.background.g*255}, ${w.background.b*255})`;const D=M.measureText(w.text);M.fillRect(-D.width*.05,.5*(w.fontSize*(.5-.1)),D.width*1.1,-w.fontSize*1.1)}M.fillStyle=`rgb(${S.r*255}, ${S.g*255}, ${S.b*255})`,M.fillText(w.text,0,0),M.restore()}),n.update()}else console.log("[Geo3DViewer] 动态纹理未准备好,正准备下一次绘制")},[f,n,o,s,d]),m.useEffect(()=>{const v=i.current;if(v){if(T)return v.setFloat("disableNormalShadow",1),console.log("[Geo3DViewer] 禁用法向阴影 启用"),()=>{v&&v.setFloat("disableNormalShadow",0)};v.setFloat("disableNormalShadow",0),console.log("[Geo3DViewer] 禁用法向阴影 禁用")}},[T]),C.jsx(lt,{ref:i,name:e.name,backFaceCulling:e.backFaceCulling,needDepthPrePass:e.needDepthPrePass,vertex:wc,fragment:Ic,transparencyMode:e.transparencyMode,alphaMode:e.alphaMode,options:{attributes:["position","color","normal"],uniforms:["world","worldViewProjection","vAlpha","vColor","contourLineStartHeight","contourLineColor","contourLineWidth","contourLineStep","oMin","oMax","textureOverlayRotate","textureIncludeSide","disableNormalShadow"],samplers:["textureOverlaySampler"],needAlphaBlending:!0,needAlphaTesting:!0},zOffset:e.zOffset,zOffsetUnits:e.zOffsetUnits,disableDepthWrite:h})},ku=m.forwardRef(bu),ea=({name:e,url:t,offset:n=u.Vector3.Zero(),alpha:a=1,material:i,visible:o=!0,actions:r})=>{const l=_e.useScene(),s=m.useRef(null),c=m.useContext(Le),p=je({url:t,cacheType:Me.URL_PREFIX_MATCH}),f=He({url:i.texture,cacheType:Me.URL_PREFIX_MATCH}),d=He({url:i.sideTexture,cacheType:Me.URL_PREFIX_MATCH}),[x,h]=m.useState(u.Vector3.Zero()),[T,P]=m.useState();return m.useEffect(()=>{console.log("[Geo3DViewer] AttributeBody Loading: ",t)},[t]),m.useEffect(()=>{if(l&&s.current&&t&&p){u.Tags.EnableFor(s.current),u.Tags.AddTagsTo(s.current,"loading");const v=Vo.decode(new Uint8Array(p)),{points:_,indices:b,value:k,center:M}=v,w=new u.VertexData;w.positions=_,w.indices=b,w.colors=k;const S=[];u.VertexData.ComputeNormals(_,b,S),w.normals=S,M&&h(new u.Vector3(M.x,M.y,M.z));const N=s.current;N&&(w.applyToMesh(N),N.getScene().onAfterRenderObservable.addOnce(()=>{if(!N.isDisposed()){const B=N.getBoundingInfo();P(B.boundingBox)}})),u.Tags.RemoveTagsFrom(s.current,"loading")}},[t,l,p]),m.useEffect(()=>{s.current&&(s.current.metadata={pickable:r?{name:e,onLeftClick:r.onLeftClick,onRightClick:r.onRightClick,onMiddleClick:r.onMiddleClick,onHover:r.onHover,needWorldPosition:r.needWorldPosition,extra:r.extra}:null})},[r,e]),C.jsx(C.Fragment,{children:C.jsx("transformNode",{name:`transform-attribute-${e}`,position:x.add(n).multiplyByFloats(c&&c.scalePlane?c.scalePlane:1,c&&c.scaleDepth?c.scaleDepth:1,c&&c.scalePlane?c.scalePlane:1),scaling:new u.Vector3(c?c.scalePlane:1,c?c.scaleDepth:1,c?c.scalePlane:1),children:C.jsx("mesh",{name:`attributebody-${e}-mesh`,ref:s,setEnabled:o,useVertexColors:i.type===$e.COLOR_CODEC,children:i.type===$e.COLOR_CODEC&&i.colorCodec?C.jsx(Mt,{name:`attributebody-${e}-mat`,backFaceCulling:i.backFaceCulling===void 0?!0:i.backFaceCulling,needDepthPrePass:i.needDepthPrePass===void 0?!1:i.needDepthPrePass,alpha:i.alpha?i.alpha:a,transparencyMode:u.Material.MATERIAL_ALPHABLEND,alphaMode:u.Engine.ALPHA_COMBINE,colorCodec:i.colorCodec,boundingBox:T,lines:i.lines,text:i.text,scaleDepth:c?c.scaleDepth:1,scalePlane:c?c.scalePlane:1,disableDepthWrite:i.disableDepthWrite}):i.type===$e.ONE_COLOR&&i.color?C.jsx("standardMaterial",{name:`attributebody-${e}-overwrite-mat`,backFaceCulling:i.backFaceCulling===void 0?!0:i.backFaceCulling,needDepthPrePass:i.needDepthPrePass===void 0?!1:i.needDepthPrePass,transparencyMode:u.Material.MATERIAL_ALPHABLEND,specularColor:new u.Color3(0,0,0),ambientColor:new u.Color3(1,1,1),diffuseColor:new u.Color3(i.color.r,i.color.g,i.color.b),emissiveColor:u.Color3.Black(),alphaMode:u.Engine.ALPHA_COMBINE,alpha:i.alpha?i.alpha:a,zOffset:-3,disableDepthWrite:i.disableDepthWrite}):i.type===$e.TEXTURE&&f?C.jsx(Kt,{name:`attributebody-${e}-texture-mat`,backFaceCulling:i.backFaceCulling===void 0?!0:i.backFaceCulling,needDepthPrePass:i.needDepthPrePass===void 0?!1:i.needDepthPrePass,alpha:i.alpha?i.alpha:a,transparencyMode:u.Material.MATERIAL_ALPHABLEND,alphaMode:u.Engine.ALPHA_COMBINE,texture:f,sideTexture:d,mode:i.textureMode===void 0?qt.PLANE:i.textureMode,boundingBox:T,disableDepthWrite:i.disableDepthWrite}):C.jsx(C.Fragment,{})})})})},ta=({codec:e,showValue:t=!1,showTitle:n=!0,width:a=80,height:i=200})=>{const o=m.useContext(Vn);return C.jsx(C.Fragment,{children:C.jsxs("adtFullscreenUi",{name:`adt-color-codec-${e}`,children:[n?C.jsx("textBlock",{name:`color-codec-title-${e}`,text:e,color:"white",paddingBottomInPixels:i+40/200*i,paddingRightInPixels:30/80*a,textVerticalAlignment:nt.Control.VERTICAL_ALIGNMENT_CENTER,textHorizontalAlignment:nt.Control.HORIZONTAL_ALIGNMENT_RIGHT}):C.jsx(C.Fragment,{}),C.jsx("babylon-image",{name:`color-codec-${e}`,source:o!=null&&o.colorCodecsImage.current[e]?o.colorCodecsImage.current[e].blobUrl:"",height:`${i}px`,width:`${a}px`,verticalAlignment:nt.Control.VERTICAL_ALIGNMENT_CENTER,horizontalAlignment:nt.Control.HORIZONTAL_ALIGNMENT_RIGHT,paddingRightInPixels:20}),t&&(o!=null&&o.colorCodecsImage.current[e])?C.jsxs(C.Fragment,{children:[C.jsx("textBlock",{name:"color-codec-value-min",text:o.colorCodecsImage.current[e].min.toFixed(1).toString(),color:"white",paddingBottomInPixels:-1*i,paddingRightInPixels:90,textVerticalAlignment:nt.Control.VERTICAL_ALIGNMENT_CENTER,textHorizontalAlignment:nt.Control.HORIZONTAL_ALIGNMENT_RIGHT}),C.jsx("textBlock",{name:"color-codec-title-avg",text:((o.colorCodecsImage.current[e].max-o.colorCodecsImage.current[e].min)/2).toFixed(1).toString(),color:"white",paddingBottomInPixels:0,paddingRightInPixels:a+10,textVerticalAlignment:nt.Control.VERTICAL_ALIGNMENT_CENTER,textHorizontalAlignment:nt.Control.HORIZONTAL_ALIGNMENT_RIGHT}),C.jsx("textBlock",{name:"color-codec-title-max",text:o.colorCodecsImage.current[e].max.toFixed(1).toString(),color:"white",paddingBottomInPixels:i,paddingRightInPixels:a+10,textVerticalAlignment:nt.Control.VERTICAL_ALIGNMENT_CENTER,textHorizontalAlignment:nt.Control.HORIZONTAL_ALIGNMENT_RIGHT})]}):null]})})};function Xr(){return{name:"",colorId:0,points:[],indices:[],bottomIndices:[],value:[],vMin:0,vMax:0,border:[],side:[],sideIndices:[],sideValue:[],center:void 0}}const Wt={encode(e,t=se.Writer.create()){e.name!==""&&t.uint32(10).string(e.name),e.colorId!==0&&t.uint32(16).uint32(e.colorId),t.uint32(170).fork();for(const n of e.points)t.float(n);t.ldelim(),t.uint32(178).fork();for(const n of e.indices)t.uint32(n);t.ldelim(),t.uint32(186).fork();for(const n of e.bottomIndices)t.uint32(n);t.ldelim(),t.uint32(194).fork();for(const n of e.value)t.float(n);t.ldelim(),e.vMin!==0&&t.uint32(205).float(e.vMin),e.vMax!==0&&t.uint32(213).float(e.vMax),t.uint32(218).fork();for(const n of e.border)t.uint32(n);t.ldelim(),t.uint32(226).fork();for(const n of e.side)t.float(n);t.ldelim(),t.uint32(234).fork();for(const n of e.sideIndices)t.uint32(n);t.ldelim(),t.uint32(242).fork();for(const n of e.sideValue)t.float(n);return t.ldelim(),e.center!==void 0&&K.encode(e.center,t.uint32(250).fork()).ldelim(),t},decode(e,t){const n=e instanceof se.Reader?e:se.Reader.create(e);let a=t===void 0?n.len:n.pos+t;const i=Xr();for(;n.pos<a;){const o=n.uint32();switch(o>>>3){case 1:if(o!==10)break;i.name=n.string();continue;case 2:if(o!==16)break;i.colorId=n.uint32();continue;case 21:if(o===173){i.points.push(n.float());continue}if(o===170){const r=n.uint32()+n.pos;for(;n.pos<r;)i.points.push(n.float());continue}break;case 22:if(o===176){i.indices.push(n.uint32());continue}if(o===178){const r=n.uint32()+n.pos;for(;n.pos<r;)i.indices.push(n.uint32());continue}break;case 23:if(o===184){i.bottomIndices.push(n.uint32());continue}if(o===186){const r=n.uint32()+n.pos;for(;n.pos<r;)i.bottomIndices.push(n.uint32());continue}break;case 24:if(o===197){i.value.push(n.float());continue}if(o===194){const r=n.uint32()+n.pos;for(;n.pos<r;)i.value.push(n.float());continue}break;case 25:if(o!==205)break;i.vMin=n.float();continue;case 26:if(o!==213)break;i.vMax=n.float();continue;case 27:if(o===216){i.border.push(n.uint32());continue}if(o===218){const r=n.uint32()+n.pos;for(;n.pos<r;)i.border.push(n.uint32());continue}break;case 28:if(o===229){i.side.push(n.float());continue}if(o===226){const r=n.uint32()+n.pos;for(;n.pos<r;)i.side.push(n.float());continue}break;case 29:if(o===232){i.sideIndices.push(n.uint32());continue}if(o===234){const r=n.uint32()+n.pos;for(;n.pos<r;)i.sideIndices.push(n.uint32());continue}break;case 30:if(o===245){i.sideValue.push(n.float());continue}if(o===242){const r=n.uint32()+n.pos;for(;n.pos<r;)i.sideValue.push(n.float());continue}break;case 31:if(o!==250)break;i.center=K.decode(n,n.uint32());continue}if((o&7)===4||o===0)break;n.skipType(o&7)}return i},fromJSON(e){return{name:_n(e.name)?globalThis.String(e.name):"",colorId:_n(e.colorId)?globalThis.Number(e.colorId):0,points:globalThis.Array.isArray(e==null?void 0:e.points)?e.points.map(t=>globalThis.Number(t)):[],indices:globalThis.Array.isArray(e==null?void 0:e.indices)?e.indices.map(t=>globalThis.Number(t)):[],bottomIndices:globalThis.Array.isArray(e==null?void 0:e.bottomIndices)?e.bottomIndices.map(t=>globalThis.Number(t)):[],value:globalThis.Array.isArray(e==null?void 0:e.value)?e.value.map(t=>globalThis.Number(t)):[],vMin:_n(e.vMin)?globalThis.Number(e.vMin):0,vMax:_n(e.vMax)?globalThis.Number(e.vMax):0,border:globalThis.Array.isArray(e==null?void 0:e.border)?e.border.map(t=>globalThis.Number(t)):[],side:globalThis.Array.isArray(e==null?void 0:e.side)?e.side.map(t=>globalThis.Number(t)):[],sideIndices:globalThis.Array.isArray(e==null?void 0:e.sideIndices)?e.sideIndices.map(t=>globalThis.Number(t)):[],sideValue:globalThis.Array.isArray(e==null?void 0:e.sideValue)?e.sideValue.map(t=>globalThis.Number(t)):[],center:_n(e.center)?K.fromJSON(e.center):void 0}},toJSON(e){var n,a,i,o,r,l,s,c;const t={};return e.name!==""&&(t.name=e.name),e.colorId!==0&&(t.colorId=Math.round(e.colorId)),(n=e.points)!=null&&n.length&&(t.points=e.points),(a=e.indices)!=null&&a.length&&(t.indices=e.indices.map(p=>Math.round(p))),(i=e.bottomIndices)!=null&&i.length&&(t.bottomIndices=e.bottomIndices.map(p=>Math.round(p))),(o=e.value)!=null&&o.length&&(t.value=e.value),e.vMin!==0&&(t.vMin=e.vMin),e.vMax!==0&&(t.vMax=e.vMax),(r=e.border)!=null&&r.length&&(t.border=e.border.map(p=>Math.round(p))),(l=e.side)!=null&&l.length&&(t.side=e.side),(s=e.sideIndices)!=null&&s.length&&(t.sideIndices=e.sideIndices.map(p=>Math.round(p))),(c=e.sideValue)!=null&&c.length&&(t.sideValue=e.sideValue),e.center!==void 0&&(t.center=K.toJSON(e.center)),t},create(e){return Wt.fromPartial(e!=null?e:{})},fromPartial(e){var n,a,i,o,r,l,s,c,p,f,d,x;const t=Xr();return t.name=(n=e.name)!=null?n:"",t.colorId=(a=e.colorId)!=null?a:0,t.points=((i=e.points)==null?void 0:i.map(h=>h))||[],t.indices=((o=e.indices)==null?void 0:o.map(h=>h))||[],t.bottomIndices=((r=e.bottomIndices)==null?void 0:r.map(h=>h))||[],t.value=((l=e.value)==null?void 0:l.map(h=>h))||[],t.vMin=(s=e.vMin)!=null?s:0,t.vMax=(c=e.vMax)!=null?c:0,t.border=((p=e.border)==null?void 0:p.map(h=>h))||[],t.side=((f=e.side)==null?void 0:f.map(h=>h))||[],t.sideIndices=((d=e.sideIndices)==null?void 0:d.map(h=>h))||[],t.sideValue=((x=e.sideValue)==null?void 0:x.map(h=>h))||[],t.center=e.center!==void 0&&e.center!==null?K.fromPartial(e.center):void 0,t}};function _n(e){return e!=null}const Eu=64,Nu=32,na='"Noto Sans SC", sans-serif';function Iu(e,t){if(typeof document=="undefined")return{textureWidth:256,textureHeight:128};const a=document.createElement("canvas").getContext("2d");if(!a)return{textureWidth:256,textureHeight:128};const i=Math.max(8,Math.round(t*.35)),o=Math.max(6,Math.round(t*.25));a.font=`600 ${t}px ${na}`;const r=Math.ceil(a.measureText(e||" ").width),l=Math.ceil(t*1.6);return{textureWidth:Math.max(Eu,qr(r+i*2)),textureHeight:Math.max(Nu,qr(l+o*2))}}function qr(e){let t=1;for(;t<e;)t<<=1;return t}function wu(e){if(typeof e=="string")return e;const t=Math.round(e.r*255),n=Math.round(e.g*255),a=Math.round(e.b*255);return`rgba(${t}, ${n}, ${a}, ${e.a})`}const Je=e=>{const t=_e.useScene(),n=m.useRef(null),a=m.useRef(null),{name:i,text:o,fontSize:r,color:l,billboardMode:s=u.Mesh.BILLBOARDMODE_ALL,lowPriority:c=!0}=e;return m.useEffect(()=>{if(!t)return;const p=i!=null?i:"gui-text-no-name",{textureWidth:f,textureHeight:d}=Iu(o,r),x=u.MeshBuilder.CreatePlane(p,{width:1,height:1},t);x.parent=n.current,x.isPickable=!1,x.billboardMode=s,x.alwaysSelectAsActiveMesh=!0;const h=Math.max(r,1);x.scaling.x=h*(f/d),x.scaling.y=h;const T=nt.AdvancedDynamicTexture.CreateForMesh(x,f,d,!1,!1);T.rootContainer.isPointerBlocker=!1;const P=new nt.TextBlock(`${p}-text`,o);P.color=wu(l),P.fontFamily=na,P.fontWeight="600",P.fontSize=`${r}px`,P.resizeToFit=!1,P.textWrapping=!1,P.textHorizontalAlignment=nt.Control.HORIZONTAL_ALIGNMENT_CENTER,P.textVerticalAlignment=nt.Control.VERTICAL_ALIGNMENT_CENTER,T.addControl(P);const v=x.material;return v&&v instanceof u.StandardMaterial&&(v.backFaceCulling=!1,v.disableLighting=!0,v.forceDepthWrite=!1,v.needDepthPrePass=!1,v.transparencyMode=u.Material.MATERIAL_ALPHABLEND,v.zOffset=-2),x.renderingGroupId=2,a.current={plane:x,texture:T},()=>{var _,b;(_=a.current)==null||_.texture.dispose(),(b=a.current)==null||b.plane.dispose(),a.current=null}},[t,i,o,r,l,s,c]),m.useEffect(()=>{a.current&&(a.current.plane.parent=n.current)}),C.jsx("transformNode",{name:i!=null?i:"no-name-text",ref:n})},Xn=({urlTopLayer:e,urlBottomLayer:t,showLayerLabel:n=!1,labelStyle:a,position:i=u.Vector3.Zero(),visible:o=!0,showBottomLayer:r=!1,actions:l,material:s={type:$e.COLOR_ID,alpha:1}})=>{var E,L;const c=m.useRef(null),p=m.useRef(null),[f,d]=m.useState(""),[x,h]=m.useState(null),T=m.useContext(Le),P=m.useContext(Lt),[v,_]=m.useState(u.Color3.White()),b=je({url:e,cacheType:Me.URL_PREFIX_MATCH}),k=je({url:t,cacheType:Me.URL_PREFIX_MATCH}),M=He({url:s==null?void 0:s.texture,cacheType:Me.URL_PREFIX_MATCH}),w=He({url:s==null?void 0:s.sideTexture,cacheType:Me.URL_PREFIX_MATCH});m.useEffect(()=>{console.log("[Geo3DViewer] FormationFace Loading: ",e,t)},[e,t]);const[S,N]=m.useState(),[F,B]=m.useState(u.Vector3.Zero()),[I,D]=m.useState(void 0);return m.useEffect(()=>{if(b){const y=c.current;y&&(u.Tags.EnableFor(y),u.Tags.AddTagsTo(y,"loading"));let A=[],V=[],$=[];const W=Wt.decode(new Uint8Array(b));{const{name:G,points:le,indices:re,colorId:oe,value:Y,center:ce}=W;A=le,V=re,$=Y,h(oe),d(G),ce&&B(new u.Vector3(ce.x,ce.y,ce.z))}const ne=new u.VertexData;ne.positions=A,ne.indices=V,ne.colors=$;const ee=[];if(u.VertexData.ComputeNormals(A,V,ee),ne.normals=ee,y){ne.applyToMesh(y);const G=y.getBoundingInfo();N(G.boundingBox.center.add(new u.Vector3(G.boundingBox.extendSize.x,0,0))),r||y.getScene().onAfterRenderObservable.addOnce(()=>{if(!y.isDisposed()){const re=y.getBoundingInfo();D(re.boundingBox)}})}return y&&u.Tags.RemoveTagsFrom(y,"loading"),()=>{y&&new u.VertexData().applyToMesh(y)}}},[b,r]),m.useEffect(()=>{if(b&&k){const y=p.current;y&&(u.Tags.EnableFor(y),u.Tags.AddTagsTo(y,"loading"));let A=[],V=[],$=[],W=[],ne=[],ee=[],G=[],le=[];{const ge=Wt.decode(new Uint8Array(b)),{points:H,indices:Q,border:Ee,value:ke}=ge;A=H,V=Q,W=Ee,$=ke}{const ge=Wt.decode(new Uint8Array(k)),{points:H,bottomIndices:Q,border:Ee,value:ke}=ge;ne=H,ee=Q,G=Ee,le=ke}const re=new u.VertexData,oe=new Float32Array(A.length+ne.length);let Y=V.length+ee.length;Y=Y+((W.length<1?1:W.length)-1)*6;const ce=new Int32Array(Y),ae=new Float32Array($.length+le.length);oe.set(A),ce.set(V),ae.set($),oe.set(ne,A.length),ce.set(ee,V.length),ae.set(le,$.length);const X=[];for(let ge=0;ge<W.length-1;ge++)X.push(W[ge+1]),X.push(W[ge]),X.push(G[ge]+A.length/3),X.push(G[ge+1]+A.length/3),X.push(G[ge]+A.length/3),X.push(W[ge+1]);ce.set(X,V.length+ee.length),re.positions=oe,re.indices=ce,re.colors=ae;const Pe=[];return u.VertexData.ComputeNormals(oe,ce,Pe),re.normals=Pe,y&&(re.applyToMesh(y),r&&y.getScene().onAfterRenderObservable.addOnce(()=>{if(!y.isDisposed()){const H=y.getBoundingInfo();D(H.boundingBox)}})),y&&u.Tags.RemoveTagsFrom(y,"loading"),()=>{y&&new u.VertexData().applyToMesh(y)}}},[k,b,r]),m.useEffect(()=>{var y;_(s.type===$e.ONE_COLOR?(y=s==null?void 0:s.color)!=null?y:u.Color3.Random():x&&P.colorIDs[x]?new u.Color3(P.colorIDs[x].r,P.colorIDs[x].g,P.colorIDs[x].b):u.Color3.Random())},[P.colorIDs,x,s==null?void 0:s.color,s.type]),m.useEffect(()=>{c.current&&(c.current.metadata={pickable:l?{name:f,onLeftClick:l.onLeftClick,onRightClick:l.onRightClick,onMiddleClick:l.onMiddleClick,onHover:l.onHover,needWorldPosition:l.needWorldPosition,extra:l.extra}:null}),p.current&&(p.current.metadata={pickable:l?{name:f,onLeftClick:l.onLeftClick,onRightClick:l.onRightClick,onMiddleClick:l.onMiddleClick,onHover:l.onHover,needWorldPosition:l.needWorldPosition,extra:l.extra}:null})},[l,f]),C.jsx(C.Fragment,{children:C.jsxs("transformNode",{name:`transform-formation-${f}-${e}`,position:F.add(i).multiplyByFloats(T&&T.scalePlane?T.scalePlane:1,T&&T.scaleDepth?T.scaleDepth:1,T&&T.scalePlane?T.scalePlane:1),scaling:new u.Vector3(T?T.scalePlane:1,T?T.scaleDepth:1,T?T.scalePlane:1),setEnabled:o,children:[C.jsx("mesh",{name:`formation-${f}-mesh-${e}`,ref:c,setEnabled:!r,useVertexColors:s.type===$e.COLOR_CODEC,alwaysSelectAsActiveMesh:!0,children:s.type===$e.TEXTURE?M?C.jsx(Kt,{name:`formation-${f}-mat-${e}`,backFaceCulling:s.backFaceCulling===void 0?!0:s.backFaceCulling,needDepthPrePass:s.needDepthPrePass===void 0?!0:s.needDepthPrePass,transparencyMode:u.Material.MATERIAL_ALPHABLEND,alphaMode:u.Engine.ALPHA_COMBINE,alpha:s.alpha,texture:M,sideTexture:w,tilingFactor:s.tilingFactor,sideTilingFactor:(E=s==null?void 0:s.sideTilingFactor)!=null?E:s==null?void 0:s.tilingFactor,mode:s.textureMode===void 0?qt.PLANE:s.textureMode,boundingBox:I,lines:s.lines,text:s.text,scaleDepth:T?T.scaleDepth:1,scalePlane:T?T.scalePlane:1,disableDepthWrite:s.disableDepthWrite}):C.jsx(C.Fragment,{}):s.type===$e.COLOR_CODEC?s.colorCodec?C.jsx(Mt,{name:`formation-${f}-mat-${e}`,backFaceCulling:s.backFaceCulling===void 0?!0:s.backFaceCulling,needDepthPrePass:s.needDepthPrePass===void 0?!0:s.needDepthPrePass,alpha:s.alpha,transparencyMode:u.Material.MATERIAL_ALPHABLEND,alphaMode:u.Engine.ALPHA_COMBINE,colorCodec:s.colorCodec,boundingBox:I,lines:s.lines,text:s.text,scaleDepth:T?T.scaleDepth:1,scalePlane:T?T.scalePlane:1,disableDepthWrite:s.disableDepthWrite}):C.jsx(C.Fragment,{}):s.type===$e.COLOR_ID?C.jsx(Mn,{name:`formation-${f}-vol-mat-${e}`,backFaceCulling:s.backFaceCulling===void 0?!0:s.backFaceCulling,needDepthPrePass:s.needDepthPrePass===void 0?!0:s.needDepthPrePass,surfaceCanvasOptions:s.surfaceCanvasOptions,color:v,alphaMode:u.Engine.ALPHA_COMBINE,alpha:s.alpha,boundingBox:I,transparencyMode:u.Material.MATERIAL_ALPHABLEND,lines:s.lines,text:s.text,scaleDepth:T?T.scaleDepth:1,scalePlane:T?T.scalePlane:1,disableDepthWrite:s.disableDepthWrite,disableNormalShadow:s.disableNormalShadow}):C.jsx(Mn,{name:`formation-${f}-vol-mat-${e}`,backFaceCulling:s.backFaceCulling===void 0?!0:s.backFaceCulling,needDepthPrePass:s.needDepthPrePass===void 0?!0:s.needDepthPrePass,color:v,surfaceCanvasOptions:s.surfaceCanvasOptions,alphaMode:u.Engine.ALPHA_COMBINE,alpha:s.alpha,boundingBox:I,transparencyMode:u.Material.MATERIAL_ALPHABLEND,lines:s.lines,text:s.text,scaleDepth:T?T.scaleDepth:1,scalePlane:T?T.scalePlane:1,disableDepthWrite:s.disableDepthWrite,disableNormalShadow:s.disableNormalShadow})}),C.jsx("mesh",{name:`formation-${f}-vol-${e}`,ref:p,setEnabled:r,useVertexColors:s.type===$e.COLOR_CODEC,alwaysSelectAsActiveMesh:!0,children:s.type===$e.TEXTURE?M?C.jsx(Kt,{name:`formation-${f}-vol-mat-${e}`,backFaceCulling:s.backFaceCulling===void 0?!0:s.backFaceCulling,needDepthPrePass:s.needDepthPrePass===void 0?!0:s.needDepthPrePass,transparencyMode:u.Material.MATERIAL_ALPHABLEND,alphaMode:u.Engine.ALPHA_COMBINE,alpha:s.alpha,sideTexture:w,texture:M,tilingFactor:s.tilingFactor,sideTilingFactor:(L=s==null?void 0:s.sideTilingFactor)!=null?L:s==null?void 0:s.tilingFactor,mode:s.textureMode===void 0?qt.PLANE:s.textureMode,boundingBox:I,lines:s.lines,text:s.text,scaleDepth:T?T.scaleDepth:1,scalePlane:T?T.scalePlane:1,disableDepthWrite:s.disableDepthWrite}):C.jsx(C.Fragment,{}):s.type===$e.COLOR_CODEC?s.colorCodec?C.jsx(Mt,{name:`formation-${f}-vol-mat-${e}`,backFaceCulling:s.backFaceCulling===void 0?!0:s.backFaceCulling,needDepthPrePass:s.needDepthPrePass===void 0?!0:s.needDepthPrePass,alpha:s.alpha,transparencyMode:u.Material.MATERIAL_ALPHABLEND,alphaMode:u.Engine.ALPHA_COMBINE,colorCodec:s.colorCodec,boundingBox:I,lines:s.lines,text:s.text,scaleDepth:T?T.scaleDepth:1,scalePlane:T?T.scalePlane:1,disableDepthWrite:s.disableDepthWrite}):C.jsx(C.Fragment,{}):s.type===$e.COLOR_ID?C.jsx(Mn,{name:`formation-${f}-vol-mat-${e}`,backFaceCulling:s.backFaceCulling===void 0?!0:s.backFaceCulling,needDepthPrePass:s.needDepthPrePass===void 0?!0:s.needDepthPrePass,surfaceCanvasOptions:s.surfaceCanvasOptions,color:v,alphaMode:u.Engine.ALPHA_COMBINE,alpha:s.alpha,transparencyMode:u.Material.MATERIAL_ALPHABLEND,boundingBox:I,lines:s.lines,text:s.text,scaleDepth:T?T.scaleDepth:1,scalePlane:T?T.scalePlane:1,disableDepthWrite:s.disableDepthWrite,disableNormalShadow:s.disableNormalShadow}):C.jsx(Mn,{name:`formation-${f}-vol-mat-${e}`,backFaceCulling:s.backFaceCulling===void 0?!0:s.backFaceCulling,needDepthPrePass:s.needDepthPrePass===void 0?!0:s.needDepthPrePass,surfaceCanvasOptions:s.surfaceCanvasOptions,color:v,alphaMode:u.Engine.ALPHA_COMBINE,alpha:s.alpha,transparencyMode:u.Material.MATERIAL_ALPHABLEND,boundingBox:I,lines:s.lines,text:s.text,scaleDepth:T?T.scaleDepth:1,scalePlane:T?T.scalePlane:1,disableDepthWrite:s.disableDepthWrite,disableNormalShadow:s.disableNormalShadow})}),f&&S&&C.jsx("transformNode",{name:`${f}-title-${e}`,position:S.add(a!=null&&a.offset?a.offset.multiplyByFloats(T!=null&&T.scalePlane?T==null?void 0:T.scalePlane:1,1,T!=null&&T.scalePlane?T==null?void 0:T.scalePlane:1):u.Vector3.Zero()),scaling:ct(T).multiply(new u.Vector3(3,3,3)),setEnabled:n,children:C.jsx(Je,{text:f,fontSize:a!=null&&a.fontSize?a.fontSize:40,color:a!=null&&a.color?a.color:"white"})})]})})},qn=({url:e,showLayerLabel:t=!1,labelStyle:n,position:a=u.Vector3.Zero(),visible:i=!0,showBottomLayer:o=!1,actions:r,material:l={type:$e.COLOR_ID,counterLine:void 0,alpha:1}})=>{var I,D;const s=m.useRef(null),c=m.useRef(null),[p,f]=m.useState(""),[d,x]=m.useState(null),[h,T]=m.useState(u.Color3.White()),P=m.useContext(Le),v=m.useContext(Lt),[_,b]=m.useState(u.Vector3.Zero()),[k,M]=m.useState(),w=je({url:e,cacheType:Me.URL_PREFIX_MATCH}),S=He({url:l==null?void 0:l.texture,cacheType:Me.URL_PREFIX_MATCH}),N=He({url:l==null?void 0:l.sideTexture,cacheType:Me.URL_PREFIX_MATCH}),[F,B]=m.useState(void 0);return m.useEffect(()=>{console.log("[Geo3DViewer] FormationVolume Loading: ",e)},[e]),m.useEffect(()=>{if(w){const E=s.current,L=c.current;u.Tags.EnableFor(E),u.Tags.AddTagsTo(E,"loading"),u.Tags.EnableFor(c),u.Tags.AddTagsTo(c,"loading");let y=[],A=[],V=[],$=[];const W=Wt.decode(new Uint8Array(w)),{name:ne,points:ee,indices:G,colorId:le,side:re,sideIndices:oe,center:Y,value:ce,sideValue:ae}=W;Y&&b(new u.Vector3(Y.x,Y.y,Y.z)),y=ee,A=G,V=re,$=oe,x(le),f(ne);const X=new u.VertexData,Pe=new u.VertexData,ge=new Float32Array(y.length+V.length),H=new Int32Array(A.length+$.length),Q=new Float32Array(ce.length+ae.length);X.positions=y,X.indices=A,X.colors=ce;const Ee=[];u.VertexData.ComputeNormals(ee,G,Ee),X.normals=Ee,ge.set(y),H.set(A),Q.set(ce),ge.set(V,y.length),H.set($,A.length),Q.set(ae,ce.length),Pe.positions=ge,Pe.indices=H,Pe.colors=Q;const ke=[];if(u.VertexData.ComputeNormals(ge,H,ke),Pe.normals=ke,E){X.applyToMesh(E);const te=E.getBoundingInfo();M(te.boundingBox.center.add(new u.Vector3(te.boundingBox.extendSize.x,0,0))),o||E.getScene().onAfterRenderObservable.addOnce(()=>{if(!E.isDisposed()){const ue=E.getBoundingInfo();B(ue.boundingBox)}})}return L&&(Pe.applyToMesh(L),o&&L.getScene().onAfterRenderObservable.addOnce(()=>{if(!L.isDisposed()){const me=L.getBoundingInfo();B(me.boundingBox)}})),u.Tags.RemoveTagsFrom(E,"loading"),u.Tags.RemoveTagsFrom(c,"loading"),()=>{E&&new u.VertexData().applyToMesh(E),L&&new u.VertexData().applyToMesh(L)}}},[w,o]),m.useEffect(()=>{var E;T(l.type===$e.ONE_COLOR?(E=l==null?void 0:l.color)!=null?E:u.Color3.Random():d&&v.colorIDs[d]?new u.Color3(v.colorIDs[d].r,v.colorIDs[d].g,v.colorIDs[d].b):u.Color3.Random())},[v.colorIDs,d,l==null?void 0:l.color,l.type]),m.useEffect(()=>{s.current&&(s.current.metadata={pickable:r?{name:p,onLeftClick:r.onLeftClick,onRightClick:r.onRightClick,onMiddleClick:r.onMiddleClick,onHover:r.onHover,needWorldPosition:r.needWorldPosition,extra:r.extra}:null}),c.current&&(c.current.metadata={pickable:r?{name:p,onLeftClick:r.onLeftClick,onRightClick:r.onRightClick,onMiddleClick:r.onMiddleClick,onHover:r.onHover,needWorldPosition:r.needWorldPosition,extra:r.extra}:null})},[r,p]),C.jsx(C.Fragment,{children:C.jsxs("transformNode",{name:`transform-formation-${p}-${e}`,position:_.add(a).multiplyByFloats(P&&P.scalePlane?P.scalePlane:1,P&&P.scaleDepth?P.scaleDepth:1,P&&P.scalePlane?P.scalePlane:1),scaling:new u.Vector3(P?P.scalePlane:1,P?P.scaleDepth:1,P?P.scalePlane:1),setEnabled:i,children:[C.jsx("mesh",{name:`formation-${p}-mesh-${e}`,ref:s,setEnabled:!o,useVertexColors:l.type===$e.COLOR_CODEC,children:l.type===$e.TEXTURE?S?C.jsx(Kt,{name:`formation-${p}-mat-${e}`,backFaceCulling:l.backFaceCulling===void 0?!0:l.backFaceCulling,needDepthPrePass:l.needDepthPrePass===void 0?!0:l.needDepthPrePass,transparencyMode:u.Material.MATERIAL_ALPHABLEND,alphaMode:u.Engine.ALPHA_COMBINE,alpha:l.alpha,flatModeRotate:l.flatModeRotate,sideTexture:N,texture:S,tilingFactor:l.tilingFactor,sideTilingFactor:(I=l==null?void 0:l.sideTilingFactor)!=null?I:l==null?void 0:l.tilingFactor,mode:l.textureMode===void 0?qt.PLANE:l.textureMode,counterLine:l.counterLine,boundingBox:F,lines:l.lines,text:l.text,scaleDepth:P?P.scaleDepth:1,scalePlane:P?P.scalePlane:1,disableDepthWrite:l.disableDepthWrite}):C.jsx(C.Fragment,{}):l.type===$e.COLOR_CODEC?l.colorCodec?C.jsx(Mt,{name:`formation-${p}-mat-${e}`,backFaceCulling:l.backFaceCulling===void 0?!0:l.backFaceCulling,needDepthPrePass:l.needDepthPrePass===void 0?!0:l.needDepthPrePass,alpha:l.alpha,transparencyMode:u.Material.MATERIAL_ALPHABLEND,alphaMode:u.Engine.ALPHA_COMBINE,colorCodec:l.colorCodec,counterLine:l.counterLine,boundingBox:F,lines:l.lines,text:l.text,scaleDepth:P?P.scaleDepth:1,scalePlane:P?P.scalePlane:1,disableDepthWrite:l.disableDepthWrite}):C.jsx(C.Fragment,{}):l.type===$e.COLOR_ID?C.jsx(An,{name:`formation-${p}-vol-mat-${e}`,backFaceCulling:l.backFaceCulling===void 0?!0:l.backFaceCulling,needDepthPrePass:l.needDepthPrePass===void 0?!0:l.needDepthPrePass,color:h,alphaMode:u.Engine.ALPHA_COMBINE,alpha:l.alpha,lightPosition:l.lightPosition,intensity:l.intensity,surfaceCanvasOptions:l.surfaceCanvasOptions,transparencyMode:u.Material.MATERIAL_ALPHABLEND,boundingBox:F,lines:l.lines,text:l.text,zOffset:l.zOffset,zOffsetUnits:l.zOffsetUnits,contrast:l.contrast,sideIntensity:l.sideIntensity,cullFace:l.cullFace,scaleDepth:P?P.scaleDepth:1,scalePlane:P?P.scalePlane:1,disableDepthWrite:l.disableDepthWrite}):C.jsx(An,{name:`formation-${p}-vol-mat-${e}`,backFaceCulling:l.backFaceCulling===void 0?!0:l.backFaceCulling,needDepthPrePass:l.needDepthPrePass===void 0?!0:l.needDepthPrePass,color:h,alphaMode:u.Engine.ALPHA_COMBINE,surfaceCanvasOptions:l.surfaceCanvasOptions,alpha:l.alpha,lightPosition:l.lightPosition,intensity:l.intensity,transparencyMode:u.Material.MATERIAL_ALPHABLEND,boundingBox:F,lines:l.lines,text:l.text,zOffset:l.zOffset,zOffsetUnits:l.zOffsetUnits,contrast:l.contrast,sideIntensity:l.sideIntensity,cullFace:l.cullFace,scaleDepth:P?P.scaleDepth:1,scalePlane:P?P.scalePlane:1,disableDepthWrite:l.disableDepthWrite})}),C.jsx("mesh",{name:`formation-${p}-vol-${e}`,ref:c,setEnabled:o,useVertexColors:l.type===$e.COLOR_CODEC,children:l.type===$e.TEXTURE?S?C.jsx(Kt,{name:`formation-${p}-vol-mat-${e}`,backFaceCulling:l.backFaceCulling===void 0?!0:l.backFaceCulling,needDepthPrePass:l.needDepthPrePass===void 0?!0:l.needDepthPrePass,transparencyMode:u.Material.MATERIAL_ALPHABLEND,alphaMode:u.Engine.ALPHA_COMBINE,alpha:l.alpha,sideTexture:N,texture:S,tilingFactor:l.tilingFactor,sideTilingFactor:(D=l==null?void 0:l.sideTilingFactor)!=null?D:l==null?void 0:l.tilingFactor,mode:l.textureMode===void 0?qt.PLANE:l.textureMode,flatModeRotate:l.flatModeRotate,counterLine:l.counterLine,boundingBox:F,lines:l.lines,text:l.text,scaleDepth:P?P.scaleDepth:1,scalePlane:P?P.scalePlane:1,disableDepthWrite:l.disableDepthWrite}):C.jsx(C.Fragment,{}):l.type===$e.COLOR_CODEC?l.colorCodec?C.jsx(Mt,{name:`formation-${p}-vol-mat-${e}`,backFaceCulling:l.backFaceCulling===void 0?!0:l.backFaceCulling,needDepthPrePass:l.needDepthPrePass===void 0?!0:l.needDepthPrePass,alpha:l.alpha,transparencyMode:u.Material.MATERIAL_ALPHABLEND,alphaMode:u.Engine.ALPHA_COMBINE,colorCodec:l.colorCodec,counterLine:l.counterLine,boundingBox:F,lines:l.lines,text:l.text,scaleDepth:P?P.scaleDepth:1,scalePlane:P?P.scalePlane:1,disableDepthWrite:l.disableDepthWrite}):C.jsx(C.Fragment,{}):l.type===$e.COLOR_ID?C.jsx(An,{name:`formation-${p}-vol-mat-${e}`,backFaceCulling:l.backFaceCulling===void 0?!0:l.backFaceCulling,needDepthPrePass:l.needDepthPrePass===void 0?!0:l.needDepthPrePass,color:h,surfaceCanvasOptions:l.surfaceCanvasOptions,alphaMode:u.Engine.ALPHA_COMBINE,alpha:l.alpha,lightPosition:l.lightPosition,intensity:l.intensity,transparencyMode:u.Material.MATERIAL_ALPHABLEND,boundingBox:F,lines:l.lines,text:l.text,zOffset:l.zOffset,zOffsetUnits:l.zOffsetUnits,contrast:l.contrast,sideIntensity:l.sideIntensity,cullFace:l.cullFace,scaleDepth:P?P.scaleDepth:1,scalePlane:P?P.scalePlane:1,disableDepthWrite:l.disableDepthWrite}):C.jsx(An,{name:`formation-${p}-vol-mat-${e}`,backFaceCulling:l.backFaceCulling===void 0?!0:l.backFaceCulling,needDepthPrePass:l.needDepthPrePass===void 0?!0:l.needDepthPrePass,color:h,surfaceCanvasOptions:l.surfaceCanvasOptions,alphaMode:u.Engine.ALPHA_COMBINE,alpha:l.alpha,lightPosition:l.lightPosition,intensity:l.intensity,transparencyMode:u.Material.MATERIAL_ALPHABLEND,boundingBox:F,lines:l.lines,text:l.text,zOffset:l.zOffset,zOffsetUnits:l.zOffsetUnits,contrast:l.contrast,sideIntensity:l.sideIntensity,cullFace:l.cullFace,scaleDepth:P?P.scaleDepth:1,scalePlane:P?P.scalePlane:1,disableDepthWrite:l.disableDepthWrite})}),p&&k&&C.jsx("transformNode",{name:`${p}-title-${e}`,position:k.add(n!=null&&n.offset?n.offset.multiplyByFloats(P!=null&&P.scalePlane?P==null?void 0:P.scalePlane:1,1,P!=null&&P.scalePlane?P==null?void 0:P.scalePlane:1):u.Vector3.Zero()),scaling:ct(P).multiply(new u.Vector3(3,3,3)),setEnabled:t,children:C.jsx(Je,{text:p,fontSize:n!=null&&n.fontSize?n.fontSize:40,color:n!=null&&n.color?n.color:"white"})})]})})};var $o=(e=>(e[e.FACE=0]="FACE",e[e.VOLUME=1]="VOLUME",e[e.UNRECOGNIZED=-1]="UNRECOGNIZED",e))($o||{});function Ou(e){switch(e){case 0:case"FACE":return 0;case 1:case"VOLUME":return 1;case-1:case"UNRECOGNIZED":default:return-1}}function Au(e){switch(e){case 0:return"FACE";case 1:return"VOLUME";case-1:default:return"UNRECOGNIZED"}}function Kr(){return{name:"",formations:[],mode:0,effectMeshs:[]}}const kn={encode(e,t=se.Writer.create()){e.name!==""&&t.uint32(10).string(e.name);for(const n of e.formations)cn.encode(n,t.uint32(34).fork()).ldelim();e.mode!==0&&t.uint32(40).int32(e.mode);for(const n of e.effectMeshs)We.encode(n,t.uint32(50).fork()).ldelim();return t},decode(e,t){const n=e instanceof se.Reader?e:se.Reader.create(e);let a=t===void 0?n.len:n.pos+t;const i=Kr();for(;n.pos<a;){const o=n.uint32();switch(o>>>3){case 1:if(o!==10)break;i.name=n.string();continue;case 4:if(o!==34)break;i.formations.push(cn.decode(n,n.uint32()));continue;case 5:if(o!==40)break;i.mode=n.int32();continue;case 6:if(o!==50)break;i.effectMeshs.push(We.decode(n,n.uint32()));continue}if((o&7)===4||o===0)break;n.skipType(o&7)}return i},fromJSON(e){return{name:Dn(e.name)?globalThis.String(e.name):"",formations:globalThis.Array.isArray(e==null?void 0:e.formations)?e.formations.map(t=>cn.fromJSON(t)):[],mode:Dn(e.mode)?Ou(e.mode):0,effectMeshs:globalThis.Array.isArray(e==null?void 0:e.effectMeshs)?e.effectMeshs.map(t=>We.fromJSON(t)):[]}},toJSON(e){var n,a;const t={};return e.name!==""&&(t.name=e.name),(n=e.formations)!=null&&n.length&&(t.formations=e.formations.map(i=>cn.toJSON(i))),e.mode!==0&&(t.mode=Au(e.mode)),(a=e.effectMeshs)!=null&&a.length&&(t.effectMeshs=e.effectMeshs.map(i=>We.toJSON(i))),t},create(e){return kn.fromPartial(e!=null?e:{})},fromPartial(e){var n,a,i,o;const t=Kr();return t.name=(n=e.name)!=null?n:"",t.formations=((a=e.formations)==null?void 0:a.map(r=>cn.fromPartial(r)))||[],t.mode=(i=e.mode)!=null?i:0,t.effectMeshs=((o=e.effectMeshs)==null?void 0:o.map(r=>We.fromPartial(r)))||[],t}};function Qr(){return{name:"",url:""}}const cn={encode(e,t=se.Writer.create()){return e.name!==""&&t.uint32(10).string(e.name),e.url!==""&&t.uint32(18).string(e.url),t},decode(e,t){const n=e instanceof se.Reader?e:se.Reader.create(e);let a=t===void 0?n.len:n.pos+t;const i=Qr();for(;n.pos<a;){const o=n.uint32();switch(o>>>3){case 1:if(o!==10)break;i.name=n.string();continue;case 2:if(o!==18)break;i.url=n.string();continue}if((o&7)===4||o===0)break;n.skipType(o&7)}return i},fromJSON(e){return{name:Dn(e.name)?globalThis.String(e.name):"",url:Dn(e.url)?globalThis.String(e.url):""}},toJSON(e){const t={};return e.name!==""&&(t.name=e.name),e.url!==""&&(t.url=e.url),t},create(e){return cn.fromPartial(e!=null?e:{})},fromPartial(e){var n,a;const t=Qr();return t.name=(n=e.name)!=null?n:"",t.url=(a=e.url)!=null?a:"",t}};function Dn(e){return e!=null}const Wo=({url:e,alpha:t=1,position:n=u.Vector3.Zero(),visible:a=!0,colorCodec:i,actions:o,counterLine:r=void 0,lines:l,text:s,disableDepthWrite:c})=>{const p=m.useRef(null),[f,d]=m.useState(""),x=m.useContext(Le),h=m.useContext(Lt),[T,P]=m.useState(null),[v,_]=m.useState(u.Color3.White()),b=je({url:e,cacheType:Me.URL_PREFIX_MATCH}),[k,M]=m.useState(u.Vector3.Zero()),[w,S]=m.useState();return m.useEffect(()=>{console.log("[Geo3DViewer] StructureLayer Loading: ",e)},[e]),m.useEffect(()=>{if(b){const N=p.current;u.Tags.EnableFor(N),u.Tags.AddTagsTo(N,"loading");const F=Wt.decode(new Uint8Array(b)),{name:B,points:I,indices:D,value:E,colorId:L,center:y}=F;y&&M(new u.Vector3(y.x,y.y,y.z));const A=new u.VertexData;A.positions=I,A.indices=D,A.colors=E;const V=[];return u.VertexData.ComputeNormals(I,D,V),A.normals=V,P(L),d(B),N&&(A.applyToMesh(N),N.getScene().onAfterRenderObservable.addOnce(()=>{if(!N.isDisposed()){const W=N.getBoundingInfo();S(W.boundingBox)}})),u.Tags.RemoveTagsFrom(N,"loading"),()=>{P(null),d(""),N&&new u.VertexData().applyToMesh(N)}}},[b]),m.useEffect(()=>{const N=T&&h.colorIDs[T]?h.colorIDs[T]:u.Color3.White();_(u.Color3.FromArray([N.r,N.g,N.b]))},[T,h.colorIDs]),m.useEffect(()=>{p.current&&(p.current.metadata={pickable:o?{name:f,onLeftClick:o.onLeftClick,onRightClick:o.onRightClick,onMiddleClick:o.onMiddleClick,onHover:o.onHover,needWorldPosition:o.needWorldPosition,extra:o.extra}:null})},[o,f]),C.jsx(C.Fragment,{children:C.jsxs("transformNode",{name:`transform-structurelayer-${f}`,position:k.add(n).multiplyByFloats(x&&x.scalePlane?x.scalePlane:1,x&&x.scaleDepth?x.scaleDepth:1,x&&x.scalePlane?x.scalePlane:1),scaling:new u.Vector3(x?x.scalePlane:1,x?x.scaleDepth:1,x?x.scalePlane:1),setEnabled:a,children:[C.jsx("transformNode",{name:`structurelayer-${f}-load`}),C.jsx("mesh",{name:`structurelayer-${f}-mesh`,ref:p,useVertexColors:i!=null,children:i?C.jsx(Mt,{name:`structurelayer-${f}-mat`,backFaceCulling:!1,alpha:t,transparencyMode:u.Material.MATERIAL_ALPHABLEND,alphaMode:u.Engine.ALPHA_COMBINE,colorCodec:i,needDepthPrePass:!0,counterLine:r,boundingBox:w,lines:l,scaleDepth:x?x.scaleDepth:1,scalePlane:x?x.scalePlane:1,text:s,disableDepthWrite:c}):C.jsx("standardMaterial",{name:`structurelayer-${f}-mat`,backFaceCulling:!1,specularColor:new u.Color3(0,0,0),ambientColor:new u.Color3(1,1,1),diffuseColor:v,needDepthPrePass:!0,transparencyMode:u.Material.MATERIAL_ALPHABLEND,alphaMode:u.Engine.ALPHA_COMBINE,alpha:t,disableDepthWrite:c})})]})})},Mu=e=>{const{id:t,visible:n=!0,position:a=u.Vector3.Zero(),diffuseTextureUrl:i,diffuseTextureSufaceUrl:o,bumpTextureUrl:r,mesh:l}=e,s=m.useRef(null),c=m.useContext(Le),[p,f]=m.useState(),[d,x]=m.useState(),[h,T]=m.useState();return m.useEffect(()=>{const P=s.current;if(P&&l){const v=new u.VertexData;v.positions=l.vertices,v.indices=l.indices,v.uvs=l.uv;const _=[];u.VertexData.ComputeNormals(l.vertices,l.indices,_),v.normals=_,v.applyToMesh(P)}},[l,l==null?void 0:l.indices,l==null?void 0:l.uv,l==null?void 0:l.vertices]),m.useEffect(()=>{const P=new u.Texture(i);if(P.uScale=500,P.vScale=.5,f(P),o){const _=new u.Texture(o);_.uScale=500,_.vScale=.5,x(_)}const v=new u.Texture(r);v.uScale=500,v.vScale=.5,T(v)},[r,o,i]),C.jsx(C.Fragment,{children:C.jsx("transformNode",{name:`transform-formation-edge-${t}`,position:a.multiplyByFloats(c&&c.scalePlane?c.scalePlane:1,c&&c.scaleDepth?c.scaleDepth:1,c&&c.scalePlane?c.scalePlane:1),scaling:new u.Vector3(c?c.scalePlane:1,c?c.scaleDepth:1,c?c.scalePlane:1),setEnabled:n,children:C.jsx("mesh",{name:"mesh",ref:s,children:C.jsx("standardMaterial",{name:`edge-${t}-material`,zOffset:-1,zOffsetUnits:-1,diffuseTexture:o?d:p,bumpTexture:o?void 0:h})})})})},oa=({url:e,visible:t=!0,filter:n,explodedView:a=0,showLayerLabel:i,labelStyle:o,offset:r=new u.Vector3(0,0,0),showTopLayerAsStructureLayer:l=!1,useColorCodecOnTopLayer:s=!1,colorCodec:c,actions:p,materials:f,topLayerCounterLine:d=void 0,topLayerHeightOffset:x=1,diffuseTextureUrl:h,diffuseTextureSufaceUrl:T,bumpTextureUrl:P,visibleEdgeEffect:v=!1})=>{var D,E;const[_,b]=m.useState(),k=m.useContext(Le),[M,w]=m.useState(!0),[S,N]=m.useState(""),F=je({url:e,cacheType:Me.URL_PREFIX_MATCH}),[B,I]=m.useState([]);return m.useEffect(()=>{console.log("[Geo3DViewer] ComplexFormationManager Loading: ",e)},[e]),m.useEffect(()=>{if(F){const L=kn.decode(new Uint8Array(F)),y=L.formations;if(L.mode==$o.FACE){w(!0),N(L.name);const A=[];y.forEach((V,$)=>{const W={name:V.name,topUrl:V.url,bottomUrl:y[$+1]?y[$+1].url:void 0};A.push(W)}),b(A)}else{w(!1),N(L.name);const A=[];y.forEach(V=>{const $={name:V.name,topUrl:V.url};A.push($)}),b(A)}return console.log(L),I(L.effectMeshs),()=>{b([])}}},[F]),C.jsxs("abstractMesh",{name:`complexformationmanager-${S}`,children:[l&&_&&_.length>1?C.jsx(Wo,{url:_[0].topUrl,alpha:(D=f==null?void 0:f[_[0].name])==null?void 0:D.alpha,position:new u.Vector3(0,x>=0?x*(k&&(E=k.scaleDepth)!=null?E:1):0,0).add(r),visible:t&&(n?n.includes(_[0].name):!0),colorCodec:c,counterLine:d},`${S}-${_[0].name}-SL`):null,_?_.map((L,y)=>M?l&&y===0?C.jsx(C.Fragment,{}):C.jsx("transformNode",{name:`${S}-${L.name}-EV`,position:r.add(new u.Vector3(0,y*(-1*a*(k&&k.scaleDepth?k.scaleDepth:0)),0)),children:C.jsx(Xn,{showLayerLabel:i,labelStyle:o,urlTopLayer:L.topUrl,urlBottomLayer:L.bottomUrl,visible:t&&(n?n.includes(L.name):!0),showBottomLayer:_[y+1]?n?n.includes(_[y+1].name):!0:!1,actions:p,material:y===0&&s?{...f==null?void 0:f[L.name],colorCodec:c,type:$e.COLOR_CODEC}:f==null?void 0:f[L.name]},`${S}-${L.name}`)},`${S}-${L.name}`):l&&y===0?C.jsx(C.Fragment,{}):C.jsx("transformNode",{name:`${S}-${L.name}-EV`,position:r.add(new u.Vector3(0,y*(-1*a*(k&&k.scaleDepth?k.scaleDepth:0)),0)),children:C.jsx(qn,{url:L.topUrl,showLayerLabel:i,labelStyle:o,visible:t&&(n?n.includes(L.name):!0),showBottomLayer:_[y+1]?n?n.includes(_[y+1].name):!0:!1,actions:p,material:f==null?void 0:f[L.name]},`${S}-${L.name}`)},`${S}-${L.name}`)):null,B&&h&&P&&a===0&&B.map((L,y)=>C.jsx(Mu,{visible:v,id:y,diffuseTextureUrl:h,diffuseTextureSufaceUrl:y===0?T:void 0,bumpTextureUrl:P,mesh:L},y))]})},ra=({visible:e=!0,color:t=u.Color3.White(),fontSize:n=80,step:a=200,keyFrameDistance:i=[],keyFrameStep:o=[],keyFrameFontSize:r=[],textureSizeX:l=512,textureSizeY:s=512,init:c=!0})=>{const p=_e.useScene(),f=m.useRef(null),d=m.useContext(Le),[x,h]=m.useState([]),[T,P]=m.useState([]),[v,_]=m.useState([]),[b,k]=m.useState(0),M=m.useCallback(w=>{if(p&&w){const S=new is.GridMaterial("axis-material",p);S.majorUnitFrequency=o.length>0?o[0]:50,S.minorUnitVisibility=0,S.gridRatio=2,S.sideOrientation=u.Material.ClockWiseSideOrientation,S.backFaceCulling=!0,S.mainColor=t,S.lineColor=t,S.opacity=.98,w.material=S}},[t,o,p]);return m.useEffect(()=>()=>{var w;(w=f.current)==null||w.dispose()},[]),m.useEffect(()=>{const w=()=>{const S=(p==null?void 0:p.activeCamera).radius;for(let N=0;N<i.length;N++)if(S<=i[N]){k(N);break}};return p&&p.activeCamera&&(p==null||p.activeCamera.onViewMatrixChangedObservable.add(w)),()=>{p&&p.activeCamera&&(p==null||p.activeCamera.onViewMatrixChangedObservable.removeCallback(w))}},[i,r,o,p,e]),m.useEffect(()=>{if(d&&d.min&&d.max&&c){const w=d.origin||u.Vector3.Zero(),S=[],N=[],F=[],B=[...o];B.length===0&&B.push(a);for(let I=0;I<B.length;I++){let D=B[I]/1;D<1&&(D=200);const E=[];for(let A=0;A<=d.max.x-d.min.x;A+=D)E.push({text:`${A+d.min.x+w.x}`,position:new u.Vector3(A,0,0)}),E.push({text:`${A+d.min.x+w.x}`,position:new u.Vector3(A,d.max.y-d.min.y,d.max.z-d.min.z)}),E.push({text:`${A+d.min.x+w.x}`,position:new u.Vector3(A,d.max.y-d.min.y,0)}),E.push({text:`${A+d.min.x+w.x}`,position:new u.Vector3(A,0,d.max.z-d.min.z)});S.push(E);const L=[];for(let A=0;A<=d.max.y-d.min.y;A+=D)L.push({text:`${A+d.min.y+w.y}`,position:new u.Vector3(0,A,0)}),L.push({text:`${A+d.min.y+w.y}`,position:new u.Vector3(d.max.x-d.min.x,A,d.max.z-d.min.z)}),L.push({text:`${A+d.min.y+w.y}`,position:new u.Vector3(d.max.x-d.min.x,A,0)}),L.push({text:`${A+d.min.y+w.y}`,position:new u.Vector3(0,A,d.max.z-d.min.z)});N.push(L);const y=[];for(let A=0;A<=d.max.z-d.min.z;A+=D)y.push({text:`${A+d.min.z+w.z}`,position:new u.Vector3(0,0,A)}),y.push({text:`${A+d.min.z+w.z}`,position:new u.Vector3(d.max.x-d.min.x,d.max.y-d.min.y,A)}),y.push({text:`${A+d.min.z+w.z}`,position:new u.Vector3(0,d.max.y-d.min.y,A)}),y.push({text:`${A+d.min.z+w.z}`,position:new u.Vector3(d.max.x-d.min.x,0,A)});F.push(y)}h(S),P(N),_(F)}},[c,o,d,a]),d&&d.min&&d.max&&d.max.x-d.min.x>0&&d.max.y-d.min.y>0&&d.max.z-d.min.z>0?C.jsxs("transformNode",{name:"coord",setEnabled:e,position:(d&&d.min&&d.max?u.Vector3.Center(d.min,d.max):u.Vector3.Zero()).multiply(Oe(d)),scaling:new u.Vector3(Oe(d).x,Oe(d).y,Oe(d).z),children:[C.jsx("box",{name:"axis",width:d&&d.min&&d.max?d.max.x-d.min.x:0,height:d&&d.min&&d.max?d.max.y-d.min.y:0,depth:d&&d.min&&d.max?d.max.z-d.min.z:0,ref:M,isPickable:!1,isBlocker:!1},`axis-${d.max.x-d.min.x}-${d.max.y-d.min.y}-${d.max.z-d.min.z}`),C.jsxs("transformNode",{name:"axis-offset",position:d&&d.min&&d.max?new u.Vector3(-(d.max.x-d.min.x)/2,-(d.max.y-d.min.y)/2,-(d.max.z-d.min.z)/2):u.Vector3.Zero(),children:[x.map((w,S)=>w.map((N,F)=>{var I;const B=N;return C.jsx("transformNode",{name:`axis-x-${S}-${F}`,position:B==null?void 0:B.position,setEnabled:S===b,scaling:new u.Vector3(1/Oe(d).x,1/Oe(d).y,1/Oe(d).z),children:C.jsx(Je,{text:`${B?B.text:""}`,fontSize:(I=r[S])!=null?I:n,color:t.toHexString()})},`axis-x-${S}-${F}`)})),T.map((w,S)=>w.map((N,F)=>{var I;const B=N;return C.jsx("transformNode",{name:`axis-x-${S}-${F}`,position:B==null?void 0:B.position,setEnabled:S===b,scaling:new u.Vector3(1/Oe(d).x,1/Oe(d).y,1/Oe(d).z),children:C.jsx(Je,{text:`${B?B.text:""}`,fontSize:(I=r[S])!=null?I:n,color:t.toHexString()})},`axis-x-${S}-${F}`)})),v.map((w,S)=>w.map((N,F)=>{var I;const B=N;return C.jsx("transformNode",{name:`axis-x-${S}-${F}`,position:B==null?void 0:B.position,setEnabled:S===b,scaling:new u.Vector3(1/Oe(d).x,1/Oe(d).y,1/Oe(d).z),children:C.jsx(Je,{text:`${B?B.text:""}`,fontSize:(I=r[S])!=null?I:n,color:t.toHexString()})},`axis-x-${S}-${F}`)}))]})]},`coord-${d.min.x}-${d.min.y}-${d.min.z}-${d.max.x}-${d.max.y}-${d.max.z}-${Math.abs(d.max.x-d.min.x)}-${Math.abs(d.max.y-d.min.y)}-${Math.abs(d.max.z-d.min.z)}`):C.jsx(C.Fragment,{})};function Lu(e){switch(e){case 0:case"NORMAL":return 0;case 1:case"CICLE":return 1;case-1:case"UNRECOGNIZED":default:return-1}}function Ru(e){switch(e){case 0:return"NORMAL";case 1:return"CICLE";case-1:default:return"UNRECOGNIZED"}}function jr(){return{name:"",lines:[]}}const ia={encode(e,t=se.Writer.create()){e.name!==""&&t.uint32(10).string(e.name);for(const n of e.lines)fn.encode(n,t.uint32(18).fork()).ldelim();return t},decode(e,t){const n=e instanceof se.Reader?e:se.Reader.create(e);let a=t===void 0?n.len:n.pos+t;const i=jr();for(;n.pos<a;){const o=n.uint32();switch(o>>>3){case 1:if(o!==10)break;i.name=n.string();continue;case 2:if(o!==18)break;i.lines.push(fn.decode(n,n.uint32()));continue}if((o&7)===4||o===0)break;n.skipType(o&7)}return i},fromJSON(e){return{name:ko(e.name)?globalThis.String(e.name):"",lines:globalThis.Array.isArray(e==null?void 0:e.lines)?e.lines.map(t=>fn.fromJSON(t)):[]}},toJSON(e){var n;const t={};return e.name!==""&&(t.name=e.name),(n=e.lines)!=null&&n.length&&(t.lines=e.lines.map(a=>fn.toJSON(a))),t},create(e){return ia.fromPartial(e!=null?e:{})},fromPartial(e){var n,a;const t=jr();return t.name=(n=e.name)!=null?n:"",t.lines=((a=e.lines)==null?void 0:a.map(i=>fn.fromPartial(i)))||[],t}};function ei(){return{positions:[]}}const un={encode(e,t=se.Writer.create()){for(const n of e.positions)rt.encode(n,t.uint32(10).fork()).ldelim();return t},decode(e,t){const n=e instanceof se.Reader?e:se.Reader.create(e);let a=t===void 0?n.len:n.pos+t;const i=ei();for(;n.pos<a;){const o=n.uint32();switch(o>>>3){case 1:if(o!==10)break;i.positions.push(rt.decode(n,n.uint32()));continue}if((o&7)===4||o===0)break;n.skipType(o&7)}return i},fromJSON(e){return{positions:globalThis.Array.isArray(e==null?void 0:e.positions)?e.positions.map(t=>rt.fromJSON(t)):[]}},toJSON(e){var n;const t={};return(n=e.positions)!=null&&n.length&&(t.positions=e.positions.map(a=>rt.toJSON(a))),t},create(e){return un.fromPartial(e!=null?e:{})},fromPartial(e){var n;const t=ei();return t.positions=((n=e.positions)==null?void 0:n.map(a=>rt.fromPartial(a)))||[],t}};function ti(){return{segments:[],type:0,position:void 0}}const fn={encode(e,t=se.Writer.create()){for(const n of e.segments)un.encode(n,t.uint32(10).fork()).ldelim();return e.type!==0&&t.uint32(16).int32(e.type),e.position!==void 0&&rt.encode(e.position,t.uint32(26).fork()).ldelim(),t},decode(e,t){const n=e instanceof se.Reader?e:se.Reader.create(e);let a=t===void 0?n.len:n.pos+t;const i=ti();for(;n.pos<a;){const o=n.uint32();switch(o>>>3){case 1:if(o!==10)break;i.segments.push(un.decode(n,n.uint32()));continue;case 2:if(o!==16)break;i.type=n.int32();continue;case 3:if(o!==26)break;i.position=rt.decode(n,n.uint32());continue}if((o&7)===4||o===0)break;n.skipType(o&7)}return i},fromJSON(e){return{segments:globalThis.Array.isArray(e==null?void 0:e.segments)?e.segments.map(t=>un.fromJSON(t)):[],type:ko(e.type)?Lu(e.type):0,position:ko(e.position)?rt.fromJSON(e.position):void 0}},toJSON(e){var n;const t={};return(n=e.segments)!=null&&n.length&&(t.segments=e.segments.map(a=>un.toJSON(a))),e.type!==0&&(t.type=Ru(e.type)),e.position!==void 0&&(t.position=rt.toJSON(e.position)),t},create(e){return fn.fromPartial(e!=null?e:{})},fromPartial(e){var n,a;const t=ti();return t.segments=((n=e.segments)==null?void 0:n.map(i=>un.fromPartial(i)))||[],t.type=(a=e.type)!=null?a:0,t.position=e.position!==void 0&&e.position!==null?rt.fromPartial(e.position):void 0,t}};function ko(e){return e!=null}const Uo=({points:e=[],showPoint:t=!0,color:n=u.Color3.White(),pointSize:a=2,alwaysOnTop:i=!1,offset:o=u.Vector3.Zero(),alpha:r,lineWidth:l})=>{const s=_e.useScene(),c=m.useRef(null),p=m.useContext(Le);return m.useEffect(()=>{if(s){const f=[],d=Oe(p);if(e.forEach(x=>{f.push(x.add(o).multiply(d))}),l){const x={path:f,radius:l,updatable:!0};if(c.current)x.instance=c.current,u.MeshBuilder.CreateTube("line",x);else{c.current=u.MeshBuilder.CreateTube("line",x,s);const h=new u.StandardMaterial("line-mat");return h.diffuseColor=n,h.specularColor=u.Color3.Black(),h.emissiveColor=n,r!==void 0&&(h.alpha=r,h.transparencyMode=2),h.depthFunction=i?u.Constants.ALWAYS:0,c.current.material=h,()=>{c.current&&(s.removeMesh(c.current),c.current=null)}}}else{const x={points:f,updateable:!0};if(c.current)x.instance=c.current,u.MeshBuilder.CreateLines("line",x);else{c.current=u.MeshBuilder.CreateLines("line",x,s);const h=new u.StandardMaterial("line-mat");return h.diffuseColor=n,h.specularColor=u.Color3.Black(),h.emissiveColor=n,r!==void 0&&(h.alpha=r,h.transparencyMode=2),h.depthFunction=i?u.Constants.ALWAYS:0,()=>{c.current&&(s.removeMesh(c.current),c.current=null)}}}}},[i,n,p,o,e,s,l,c,r]),C.jsx("transformNode",{name:"transform-line",children:t?C.jsx("transformNode",{name:"lines-point",children:e.map((f,d)=>C.jsx("sphere",{diameter:a,name:`lines-point-${d}`,position:f.add(o).multiply(Oe(p)),scalingDeterminant:l&&(p==null?void 0:p.scalePlane)||1,children:C.jsx("standardMaterial",{name:`lines-point-${d}-mat`,diffuseColor:n,emissiveColor:n,specularColor:u.Color3.White(),depthFunction:i?u.Constants.ALWAYS:void 0})},`lines-point-${f.x}-${f.y}-${f.z}`))}):C.jsx(C.Fragment,{})})},Bu=e=>{const{name:t,prev:n,next:a,textColor:i,fontSize:o}=e,r=_e.useScene(),l=m.useRef(null);return m.useEffect(()=>{const s=r==null?void 0:r.activeCamera,c=r==null?void 0:r.getEngine();if(r&&s&&c&&l.current){const p=l.current.getChildren()[0],f=u.Vector3.Normalize(a.subtract(n)),d=new u.Vector3(1,0,0),x=Math.acos(u.Vector3.Dot(f,d)),h=u.Vector3.Cross(f,d);p.rotation.z=h.y>0?x:Math.PI*2-x,p.rotation.x=Math.PI/2,p.renderingGroupId=3}},[a,n,r]),C.jsx("transformNode",{name:`${t}`,position:u.Vector3.Lerp(n,a,.5),ref:l,children:C.jsx(Je,{text:t,fontSize:o,color:i,billboardMode:u.Mesh.BILLBOARDMODE_NONE})})},Fu=e=>{const{url:t,color:n,alpha:a,visible:i=!0,fontSize:o=30,textColor:r="red",linewidth:l=10}=e,s=_e.useScene(),[c,p]=m.useState([]),[f,d]=m.useState([]),x=m.useContext(Le);return m.useEffect(()=>{Ut.get(t,{responseType:"arraybuffer"}).then(h=>{const T=ia.decode(new Uint8Array(h.data));console.log(T);const P=[],v=[];for(let _=0;_<T.lines.length;_++){const b=T.lines[_];if(b.segments.length<2)continue;const k=[];for(let M=0;M<b.segments.length;M++){const w=[...Ps(b.segments[M].positions)];P.push([...w]),k.push(w[0]),k.push(w[w.length-1])}b.type===1&&k.push(Oi(b.segments[0].positions[0])),v.push(k)}p(P),d(v),console.log(v),console.log(P)})},[s,t]),C.jsxs("transformNode",{name:"contourline",setEnabled:i,children:[c.map((h,T)=>h.length<2||!i?null:C.jsx(Uo,{points:h,showPoint:!1,color:n,alpha:a,lineWidth:l,alwaysOnTop:!0},T)),f.map(h=>h.map((T,P)=>P%2===0||P===h.length-1?null:C.jsx(Bu,{name:T.y.toFixed(0),prev:Oe(x).multiply(T),next:Oe(x).multiply(h[P+1]),fontSize:o,textColor:r},P)))]})};function Du(e){switch(e){case 0:case"X":return 0;case 1:case"Y":return 1;case 2:case"Z":return 2;case 3:case"FREE":return 3;case-1:case"UNRECOGNIZED":default:return-1}}function zu(e){switch(e){case 0:return"X";case 1:return"Y";case 2:return"Z";case 3:return"FREE";case-1:default:return"UNRECOGNIZED"}}function ni(){return{layer:0,direction:0,colorId:0,points:[],indices:[],value:[],vMin:0,vMax:0,center:void 0}}const Ho={encode(e,t=se.Writer.create()){e.layer!==0&&t.uint32(8).uint32(e.layer),e.direction!==0&&t.uint32(16).int32(e.direction),e.colorId!==0&&t.uint32(24).uint32(e.colorId),t.uint32(170).fork();for(const n of e.points)t.float(n);t.ldelim(),t.uint32(178).fork();for(const n of e.indices)t.uint32(n);t.ldelim(),t.uint32(186).fork();for(const n of e.value)t.float(n);return t.ldelim(),e.vMin!==0&&t.uint32(205).float(e.vMin),e.vMax!==0&&t.uint32(213).float(e.vMax),e.center!==void 0&&K.encode(e.center,t.uint32(250).fork()).ldelim(),t},decode(e,t){const n=e instanceof se.Reader?e:se.Reader.create(e);let a=t===void 0?n.len:n.pos+t;const i=ni();for(;n.pos<a;){const o=n.uint32();switch(o>>>3){case 1:if(o!==8)break;i.layer=n.uint32();continue;case 2:if(o!==16)break;i.direction=n.int32();continue;case 3:if(o!==24)break;i.colorId=n.uint32();continue;case 21:if(o===173){i.points.push(n.float());continue}if(o===170){const r=n.uint32()+n.pos;for(;n.pos<r;)i.points.push(n.float());continue}break;case 22:if(o===176){i.indices.push(n.uint32());continue}if(o===178){const r=n.uint32()+n.pos;for(;n.pos<r;)i.indices.push(n.uint32());continue}break;case 23:if(o===189){i.value.push(n.float());continue}if(o===186){const r=n.uint32()+n.pos;for(;n.pos<r;)i.value.push(n.float());continue}break;case 25:if(o!==205)break;i.vMin=n.float();continue;case 26:if(o!==213)break;i.vMax=n.float();continue;case 31:if(o!==250)break;i.center=K.decode(n,n.uint32());continue}if((o&7)===4||o===0)break;n.skipType(o&7)}return i},fromJSON(e){return{layer:tn(e.layer)?globalThis.Number(e.layer):0,direction:tn(e.direction)?Du(e.direction):0,colorId:tn(e.colorId)?globalThis.Number(e.colorId):0,points:globalThis.Array.isArray(e==null?void 0:e.points)?e.points.map(t=>globalThis.Number(t)):[],indices:globalThis.Array.isArray(e==null?void 0:e.indices)?e.indices.map(t=>globalThis.Number(t)):[],value:globalThis.Array.isArray(e==null?void 0:e.value)?e.value.map(t=>globalThis.Number(t)):[],vMin:tn(e.vMin)?globalThis.Number(e.vMin):0,vMax:tn(e.vMax)?globalThis.Number(e.vMax):0,center:tn(e.center)?K.fromJSON(e.center):void 0}},toJSON(e){var n,a,i;const t={};return e.layer!==0&&(t.layer=Math.round(e.layer)),e.direction!==0&&(t.direction=zu(e.direction)),e.colorId!==0&&(t.colorId=Math.round(e.colorId)),(n=e.points)!=null&&n.length&&(t.points=e.points),(a=e.indices)!=null&&a.length&&(t.indices=e.indices.map(o=>Math.round(o))),(i=e.value)!=null&&i.length&&(t.value=e.value),e.vMin!==0&&(t.vMin=e.vMin),e.vMax!==0&&(t.vMax=e.vMax),e.center!==void 0&&(t.center=K.toJSON(e.center)),t},create(e){return Ho.fromPartial(e!=null?e:{})},fromPartial(e){var n,a,i,o,r,l,s,c;const t=ni();return t.layer=(n=e.layer)!=null?n:0,t.direction=(a=e.direction)!=null?a:0,t.colorId=(i=e.colorId)!=null?i:0,t.points=((o=e.points)==null?void 0:o.map(p=>p))||[],t.indices=((r=e.indices)==null?void 0:r.map(p=>p))||[],t.value=((l=e.value)==null?void 0:l.map(p=>p))||[],t.vMin=(s=e.vMin)!=null?s:0,t.vMax=(c=e.vMax)!=null?c:0,t.center=e.center!==void 0&&e.center!==null?K.fromPartial(e.center):void 0,t}};function tn(e){return e!=null}const Zo=({name:e,url:t,visible:n=!0,colorCodec:a,alpha:i=1,position:o=u.Vector3.Zero(),actions:r})=>{const l=m.useRef(null),[s,c]=m.useState(""),[p,f]=m.useState(""),d=m.useContext(Le),x=je({url:t,cacheType:Me.URL_PREFIX_MATCH}),[h,T]=m.useState(u.Vector3.Zero());return m.useEffect(()=>{const P=l.current;if(!x||!P)return;u.Tags.EnableFor(P),u.Tags.AddTagsTo(P,"loading");const v=Ho.decode(new Uint8Array(x)),{layer:_,direction:b,points:k,indices:M,value:w,center:S}=v,N=new u.VertexData;N.positions=k,N.indices=M,N.colors=w;const F=[];u.VertexData.ComputeNormals(k,M,F),N.normals=F,S&&T(new u.Vector3(S.x,S.y,S.z)),N.applyToMesh(P),c(_.toString()),f(b.toString()),u.Tags.RemoveTagsFrom(P,"loading")},[x]),m.useEffect(()=>{l.current&&(l.current.metadata={pickable:r?{name:e,onLeftClick:r.onLeftClick,onRightClick:r.onRightClick,onMiddleClick:r.onMiddleClick,onHover:r.onHover,needWorldPosition:r.needWorldPosition,extra:r.extra}:null})},[r,e]),m.useEffect(()=>{console.log("[Geo3DViewer] DensitySlice Loading: ",t)},[t]),C.jsx(C.Fragment,{children:C.jsx("transformNode",{name:`densityslice-${e}-${p}-${s}-transform`,position:h.add(o).multiplyByFloats(d&&d.scalePlane?d.scalePlane:1,d&&d.scaleDepth?d.scaleDepth:1,d&&d.scalePlane?d.scalePlane:1),scaling:new u.Vector3(d?d.scalePlane:1,d?d.scaleDepth:1,d?d.scalePlane:1),children:C.jsx("mesh",{name:`densityslice-${e}-${p}-${s}-mesh`,ref:l,setEnabled:n,children:C.jsx(Mt,{name:`densityslice-${e}-${p}-${s}-mat`,backFaceCulling:!1,needDepthPrePass:!0,alpha:i,transparencyMode:u.Material.MATERIAL_ALPHABLEND,alphaMode:u.Engine.ALPHA_COMBINE,colorCodec:a})})})})},aa=()=>{const e=_e.useScene(),t=m.useRef(void 0);return m.useEffect(()=>{const n=setInterval(()=>{if(e&&t.current){const a=e.getEngine().getFps();t.current.getControlByName("fps").text=a.toFixed(0)+"FPS"}},1e3);return()=>{clearInterval(n)}},[e]),m.useEffect(()=>{var n,a;if(e&&!t.current){const i=nt.AdvancedDynamicTexture.CreateFullscreenUI("UI",!0,e);t.current=i;const o=new nt.TextBlock("fps");o.text="0FPS",o.color="white",o.fontSize=15,o.width=100,o.height=50;const r=window.devicePixelRatio||1,l=(n=e.getEngine().getRenderingCanvas())==null?void 0:n.clientHeight,s=(a=e.getEngine().getRenderingCanvas())==null?void 0:a.clientWidth;o.left=s?-(s*r/2-50):0,o.top=l?-(l*r/2-25):0,i.addControl(o)}return()=>{e&&t.current}},[e]),null},sa=({url:e,visible:t=!0,filter:n,explodedView:a=0,offset:i=new u.Vector3(0,0,0),showLayerLabel:o,labelStyle:r,actions:l,materials:s})=>{const[c,p]=m.useState(),f=m.useContext(Le),[d,x]=m.useState(!0),[h,T]=m.useState(""),P=je({url:e,cacheType:Me.URL_PREFIX_MATCH});return m.useEffect(()=>{console.log("[Geo3DViewer] FormationManager Loading: ",e)},[e]),m.useEffect(()=>{if(P){const v=kn.decode(new Uint8Array(P)),_=v.formations;if(v.mode==$o.FACE){x(!0),T(v.name);const b=[];_.forEach((k,M)=>{const w={name:k.name,topUrl:k.url,bottomUrl:_[M+1]?_[M+1].url:void 0};b.push(w)}),p(b)}else{x(!1),T(v.name);const b=[];_.forEach(k=>{const M={name:k.name,topUrl:k.url};b.push(M)}),p(b)}return console.log(_),()=>{T(""),p([])}}},[P]),C.jsx("abstractMesh",{name:`formationmanager-${h}`,children:c?c.map((v,_)=>d?C.jsx("transformNode",{name:`${h}-${v.name}-EV`,position:i.add(new u.Vector3(0,_*(-1*a*(f&&f.scaleDepth?f.scaleDepth:0)),0)),children:C.jsx(Xn,{showLayerLabel:o,labelStyle:r,urlTopLayer:v.topUrl,urlBottomLayer:v.bottomUrl,visible:t&&(n?n.includes(v.name):!0),showBottomLayer:c[_+1]?n?n.includes(c[_+1].name):!0:!1,actions:l,material:s==null?void 0:s[v.name]},`${h}-${v.name}`)},`${h}-${v.name}`):C.jsx("transformNode",{name:`${h}-${v.name}-EV`,position:i.add(new u.Vector3(0,_*(-1*a*(f&&f.scaleDepth?f.scaleDepth:0)),0)),children:C.jsx(qn,{url:v.topUrl,showLayerLabel:o,labelStyle:r,visible:t&&(n?n.includes(v.name):!0),showBottomLayer:c[_+1]?n?n.includes(c[_+1].name):!0:!1,actions:l,material:s==null?void 0:s[v.name]},`${h}-${v.name}`)},`${h}-${v.name}`)):null})};function oi(){return{name:"",slices:[],center:void 0}}const Go={encode(e,t=se.Writer.create()){e.name!==""&&t.uint32(10).string(e.name);for(const n of e.slices)dn.encode(n,t.uint32(18).fork()).ldelim();return e.center!==void 0&&K.encode(e.center,t.uint32(250).fork()).ldelim(),t},decode(e,t){const n=e instanceof se.Reader?e:se.Reader.create(e);let a=t===void 0?n.len:n.pos+t;const i=oi();for(;n.pos<a;){const o=n.uint32();switch(o>>>3){case 1:if(o!==10)break;i.name=n.string();continue;case 2:if(o!==18)break;i.slices.push(dn.decode(n,n.uint32()));continue;case 31:if(o!==250)break;i.center=K.decode(n,n.uint32());continue}if((o&7)===4||o===0)break;n.skipType(o&7)}return i},fromJSON(e){return{name:zn(e.name)?globalThis.String(e.name):"",slices:globalThis.Array.isArray(e==null?void 0:e.slices)?e.slices.map(t=>dn.fromJSON(t)):[],center:zn(e.center)?K.fromJSON(e.center):void 0}},toJSON(e){var n;const t={};return e.name!==""&&(t.name=e.name),(n=e.slices)!=null&&n.length&&(t.slices=e.slices.map(a=>dn.toJSON(a))),e.center!==void 0&&(t.center=K.toJSON(e.center)),t},create(e){return Go.fromPartial(e!=null?e:{})},fromPartial(e){var n,a;const t=oi();return t.name=(n=e.name)!=null?n:"",t.slices=((a=e.slices)==null?void 0:a.map(i=>dn.fromPartial(i)))||[],t.center=e.center!==void 0&&e.center!==null?K.fromPartial(e.center):void 0,t}};function ri(){return{name:"",colorId:0,vertices:[],indices:[],edges:[]}}const dn={encode(e,t=se.Writer.create()){e.name!==""&&t.uint32(10).string(e.name),e.colorId!==0&&t.uint32(16).uint32(e.colorId),t.uint32(26).fork();for(const n of e.vertices)t.float(n);t.ldelim(),t.uint32(34).fork();for(const n of e.indices)t.uint32(n);t.ldelim();for(const n of e.edges)K.encode(n,t.uint32(42).fork()).ldelim();return t},decode(e,t){const n=e instanceof se.Reader?e:se.Reader.create(e);let a=t===void 0?n.len:n.pos+t;const i=ri();for(;n.pos<a;){const o=n.uint32();switch(o>>>3){case 1:if(o!==10)break;i.name=n.string();continue;case 2:if(o!==16)break;i.colorId=n.uint32();continue;case 3:if(o===29){i.vertices.push(n.float());continue}if(o===26){const r=n.uint32()+n.pos;for(;n.pos<r;)i.vertices.push(n.float());continue}break;case 4:if(o===32){i.indices.push(n.uint32());continue}if(o===34){const r=n.uint32()+n.pos;for(;n.pos<r;)i.indices.push(n.uint32());continue}break;case 5:if(o!==42)break;i.edges.push(K.decode(n,n.uint32()));continue}if((o&7)===4||o===0)break;n.skipType(o&7)}return i},fromJSON(e){return{name:zn(e.name)?globalThis.String(e.name):"",colorId:zn(e.colorId)?globalThis.Number(e.colorId):0,vertices:globalThis.Array.isArray(e==null?void 0:e.vertices)?e.vertices.map(t=>globalThis.Number(t)):[],indices:globalThis.Array.isArray(e==null?void 0:e.indices)?e.indices.map(t=>globalThis.Number(t)):[],edges:globalThis.Array.isArray(e==null?void 0:e.edges)?e.edges.map(t=>K.fromJSON(t)):[]}},toJSON(e){var n,a,i;const t={};return e.name!==""&&(t.name=e.name),e.colorId!==0&&(t.colorId=Math.round(e.colorId)),(n=e.vertices)!=null&&n.length&&(t.vertices=e.vertices),(a=e.indices)!=null&&a.length&&(t.indices=e.indices.map(o=>Math.round(o))),(i=e.edges)!=null&&i.length&&(t.edges=e.edges.map(o=>K.toJSON(o))),t},create(e){return dn.fromPartial(e!=null?e:{})},fromPartial(e){var n,a,i,o,r;const t=ri();return t.name=(n=e.name)!=null?n:"",t.colorId=(a=e.colorId)!=null?a:0,t.vertices=((i=e.vertices)==null?void 0:i.map(l=>l))||[],t.indices=((o=e.indices)==null?void 0:o.map(l=>l))||[],t.edges=((r=e.edges)==null?void 0:r.map(l=>K.fromPartial(l)))||[],t}};function zn(e){return e!=null}const Vu=(e,t)=>{var y,A,V,$;const n=_e.useScene(),a=m.useRef(null),i=m.useRef(null),o=m.useContext(Le),r=m.useContext(Lt),[l,s]=m.useState(u.Color3.White()),{id:c,visible:p=!0,vertices:f,indices:d,colorId:x,position:h,normals:T,material:P={type:$e.COLOR_ID},children:v,alpha:_=1,style:b,name:k="formation",highStyle:M,lowStyle:w,edges:S=[],actions:N,actionName:F}=e,B=He({url:P==null?void 0:P.texture,cacheType:Me.URL_PREFIX_MATCH}),I=He({url:P==null?void 0:P.sideTexture,cacheType:Me.URL_PREFIX_MATCH}),[D,E]=m.useState();m.useImperativeHandle(t,()=>i.current,[]),m.useEffect(()=>{if(a&&a.current&&n){const W=new u.VertexData;W.positions=f,W.indices=d,W.normals=T;const ne=a.current;W.applyToMesh(ne),ne.getScene().onAfterRenderObservable.addOnce(()=>{if(!ne.isDisposed()){const G=ne.getBoundingInfo();E(G.boundingBox)}})}},[d,f,n,c,T]),m.useEffect(()=>{a.current&&(a.current.metadata={pickable:N?{name:F!=null?F:k,onLeftClick:N.onLeftClick,onRightClick:N.onRightClick,onMiddleClick:N.onMiddleClick,onHover:N.onHover,extra:N.extra,needWorldPosition:N.needWorldPosition}:null})},[F,N,k]),m.useEffect(()=>{var W;s(P.type===$e.ONE_COLOR?(W=P==null?void 0:P.color)!=null?W:u.Color3.Random():x&&r.colorIDs[x]?new u.Color3(r.colorIDs[x].r,r.colorIDs[x].g,r.colorIDs[x].b):u.Color3.Random())},[r.colorIDs,x,P==null?void 0:P.color,P.type]);const L=(W,ne,ee)=>{const G=ne.subtract(W),le=1+1e3/u.Vector3.Distance(W,ne)*(ee-1),re=G.scale(le);return W.add(re)};return C.jsxs("transformNode",{name:`node-${k}-${c}`,setEnabled:p,children:[C.jsxs("transformNode",{name:`${k}`,position:h?h.multiply(Oe(o)):new u.Vector3(0,0,0),scaling:Oe(o),ref:i,children:[C.jsx("mesh",{name:`${k}-mesh`,ref:a,children:P.type===$e.TEXTURE?B?C.jsx(Kt,{name:`formationslice-${k}-mat`,backFaceCulling:!1,needDepthPrePass:P.needDepthPrePass===void 0?!1:P.needDepthPrePass,transparencyMode:u.Material.MATERIAL_ALPHABLEND,alphaMode:u.Engine.ALPHA_COMBINE,alpha:_,sideTexture:I,texture:B,tilingFactor:P.tilingFactor,sideTilingFactor:(y=P==null?void 0:P.sideTilingFactor)!=null?y:P==null?void 0:P.tilingFactor,mode:P.textureMode===void 0?qt.PLANE:P.textureMode,boundingBox:D,lines:P.lines,text:P.text,scaleDepth:o?o.scaleDepth:1,scalePlane:o?o.scalePlane:1,disableDepthWrite:P.disableDepthWrite}):C.jsx(C.Fragment,{}):P.type===$e.COLOR_CODEC?P.colorCodec?C.jsx(Mt,{name:`formation-${k}-mat`,backFaceCulling:!1,needDepthPrePass:P.needDepthPrePass===void 0?!1:P.needDepthPrePass,alpha:_,transparencyMode:u.Material.MATERIAL_ALPHABLEND,alphaMode:u.Engine.ALPHA_COMBINE,colorCodec:P.colorCodec,boundingBox:D,lines:P.lines,text:P.text,scaleDepth:o?o.scaleDepth:1,scalePlane:o?o.scalePlane:1,disableDepthWrite:P.disableDepthWrite}):C.jsx(C.Fragment,{}):P.type===$e.COLOR_ID?C.jsx("standardMaterial",{name:`formation-${k}-mat`,backFaceCulling:!1,needDepthPrePass:P.needDepthPrePass===void 0?!1:P.needDepthPrePass,specularColor:new u.Color3(0,0,0),ambientColor:new u.Color3(1,1,1),diffuseColor:l,alphaMode:u.Engine.ALPHA_COMBINE,alpha:_,transparencyMode:u.Material.MATERIAL_ALPHABLEND,disableDepthWrite:P.disableDepthWrite}):C.jsx("standardMaterial",{name:`formation-${k}-mat`,backFaceCulling:!1,needDepthPrePass:P.needDepthPrePass===void 0?!1:P.needDepthPrePass,specularColor:new u.Color3(0,0,0),ambientColor:new u.Color3(1,1,1),diffuseColor:l,alphaMode:u.Engine.ALPHA_COMBINE,alpha:_,transparencyMode:u.Material.MATERIAL_ALPHABLEND,disableDepthWrite:P.disableDepthWrite})}),b.position&&C.jsx("transformNode",{name:`${k}-title`,position:L(At(b.basePosition==="left"?S[4]:S[5]),b.position,(A=b.offset)!=null?A:1),scaling:ct(o),children:b.title&&C.jsx(Je,{text:b.title,fontSize:b.fontSize?b.fontSize:40,color:b.color?b.color:"black"})}),w&&w.position&&C.jsx("transformNode",{name:`${k}-up-title`,position:L(At(w.basePosition==="left"?S[4]:S[5]),w.position,(V=w.offset)!=null?V:1),scaling:ct(o),children:w.title&&C.jsx(Je,{text:w.title,fontSize:w.fontSize?w.fontSize:40,color:w.color?w.color:"black"})}),M&&M.position&&C.jsx("transformNode",{name:`${k}-down-title`,position:L(At(M.basePosition==="left"?S[4]:S[5]),M.position,($=M.offset)!=null?$:1),scaling:ct(o),children:M.title&&C.jsx(Je,{text:M.title,fontSize:M.fontSize?M.fontSize:40,color:M.color?M.color:"black"})})]}),v]})},$u=m.forwardRef(Vu),Yo=e=>{const[t,n]=m.useState([]),[a,i]=m.useState(""),{url:o,visible:r=!0,materials:l,actions:s,style:c,highStyle:p,lowStyle:f,basePosition:d="left"}=e,x=m.useContext(Le),h=je({url:o,cacheType:Me.URL_PREFIX_MATCH}),[T,P]=m.useState(u.Vector3.Zero());return m.useEffect(()=>{console.log("[Geo3DViewer] FormationSlice Loading: ",o)},[o]),m.useEffect(()=>{if(h){const v=Go.decode(new Uint8Array(h));v.center&&P(new u.Vector3(v.center.x,v.center.y,v.center.z));const _=v.slices.map(b=>{const k=[];return u.VertexData.ComputeNormals(b.vertices,b.indices,k),{name:b.name,colorId:b.colorId,vertices:b.vertices,indices:b.indices,edges:b.edges,normals:k}});return i(v.name),n(_),()=>{i(""),n([])}}},[h]),C.jsx(C.Fragment,{children:C.jsx("transformNode",{name:`foramtionslice-${a}-holder`,setEnabled:r,position:T.multiply(Oe(x)),children:t.map((v,_)=>{const b=v.edges.length>0?At(d==="left"?v.edges[0]:v.edges[2]):new u.Vector3(0,0,0),k=v.edges.length>0?At(d==="left"?v.edges[1]:v.edges[3]):new u.Vector3(0,0,0),M=u.Vector3.Lerp(b,k,.5);return C.jsx($u,{id:_,vertices:v.vertices,indices:v.indices,colorId:v.colorId,normals:v.normals,name:v.name,edges:v.edges,style:c?{position:M,title:v.name,basePosition:d,...c}:{},lowStyle:f?{position:k,title:(T.y+k.y).toFixed(0).toString(),basePosition:d,...f}:{},highStyle:p&&_===t.length-1?{position:b,title:(T.y+b.y).toFixed(0).toString(),basePosition:d,...p}:{},material:l?{...l[v.name],backFaceCulling:!1}:void 0,actions:s,actionName:a},_)})})})},Wu=e=>{const{name:t="node",text:n,fontSize:a,color:i,position:o=u.Vector3.Zero(),scale:r=u.Vector3.One(),blink:l=!1}=e,[s,c]=m.useState(!0);return m.useEffect(()=>{const p=setInterval(()=>{l&&c(f=>!f)},1e3);return()=>{clearInterval(p)}},[l]),C.jsx("transformNode",{name:`${t}-text`,position:o,scaling:r,setEnabled:s,children:C.jsx(Je,{name:t,text:n,fontSize:a,color:i})})};var Bt=(e=>(e[e.NONE=0]="NONE",e[e.BOTTOM_LEFT=1]="BOTTOM_LEFT",e[e.BOTTOM_RIGHT=2]="BOTTOM_RIGHT",e[e.TOP_LEFT=3]="TOP_LEFT",e[e.TOP_RIGHT=4]="TOP_RIGHT",e))(Bt||{});const la=({target:e,radius:t,alpha:n,beta:a,axesViewerOffset:i=u.Vector3.Zero(),panningSensibility:o=2,wheelDeltaPercentage:r=0,axesViewer:l=0,farPlane:s=1e4,skipPickingWhenCameraMoves:c=!1})=>{const p=_e.useScene(),f=m.useContext(Le),[d,x]=m.useState(null),[h,T]=m.useState(null),[P,v]=m.useState(n),[_,b]=m.useState(a),[,k]=m.useState(null),M=m.useCallback(B=>{T(B)},[]),{setViewCamera:w}=m.useContext(Oo),S=m.useCallback(()=>{if(h&&d){const B=new u.Vector3;B.addInPlace(h.position),B.addInPlace(h.getDirection(new u.Vector3(0,0,25))),l==4?(B.addInPlace(h.getDirection(new u.Vector3(0,7+i.y,0))),B.addInPlace(h.getDirection(new u.Vector3(15+i.x,0,0)))):l==3?(B.addInPlace(h.getDirection(new u.Vector3(0,7+i.y,0))),B.addInPlace(h.getDirection(new u.Vector3(-15+i.x,0,0)))):l==2?(B.addInPlace(h.getDirection(new u.Vector3(0,-7+i.y,0))),B.addInPlace(h.getDirection(new u.Vector3(15+i.x,0,0)))):l==1&&(B.addInPlace(h.getDirection(new u.Vector3(0,-7+i.y,0))),B.addInPlace(h.getDirection(new u.Vector3(-15+i.x,0,0)))),d.xAxis.position=B.clone(),d.yAxis.position=B.clone(),d.zAxis.position=B.clone()}},[h,d,l,i.y,i.x]);m.useEffect(()=>{if(p&&l!=0){const B=new u.AxesViewer(p,2,null);return x(B),()=>{B==null||B.dispose(),x(null)}}},[p,l]),m.useEffect(()=>{S()},[S]);const N=m.useCallback(B=>{if(f&&f.min&&f.max)return u.Vector3.Clamp(B,f==null?void 0:f.min,f==null?void 0:f.max)},[f]),F=m.useCallback(B=>{p&&(p.skipPointerMovePicking=B)},[p]);return m.useEffect(()=>{if(!p||!h)return;const B=h.onViewMatrixChangedObservable.add(()=>{c&&(F(!0),k(I=>(I&&clearTimeout(I),setTimeout(()=>{F(!1),k(null)},250)))),v(h.alpha),b(h.beta),S()});return()=>{h.onViewMatrixChangedObservable.remove(B),k(I=>(I&&clearTimeout(I),null)),F(!1)}},[p,l,h,f,d,S,N,F,c]),m.useEffect(()=>{w(p&&h?h:void 0)},[p,h,w]),m.useEffect(()=>{},[N,f,e]),C.jsx(C.Fragment,{children:e&&C.jsx("arcRotateCamera",{name:"rootCamera",target:e,radius:t,alpha:P,beta:_,maxZ:s,panningSensibility:o,wheelDeltaPercentage:r,ref:M,setActiveOnSceneIfNoneActive:!0})})},Uu=(e,t)=>{const{position:n=u.Vector3.Zero(),axesViewer:a=Bt.NONE,axesViewerOffset:i=u.Vector3.Zero(),skipPickingWhenCameraMoves:o=!1,wheelDeltaPercentage:r=3,rotationSensibility:l=1,panningSensibility:s=10}=e,c=_e.useScene(),p=m.useContext(Le),[f,d]=m.useState(null),[x,h]=m.useState(null),{setViewCamera:T,cameraRefObject:P}=m.useContext(Oo),[,v]=m.useState(null),_=m.useRef(null),[b,k]=m.useState(null),M=m.useRef(null),w=m.useCallback(I=>{c&&(c.skipPointerMovePicking=I)},[c]);m.useEffect(()=>(M.current=new u.ArcRotateCamera("dummy-camera",0,0,.1,u.Vector3.Zero(),c||void 0,!1),()=>{var I;(I=M.current)==null||I.dispose()}),[c]),m.useEffect(()=>{if(c){const I=x,D=c.onPointerObservable.add(E=>{if(E.type===u.PointerEventTypes.POINTERDOWN&&(_.current=new u.Vector2(E.event.clientX,E.event.clientY)),E.type===u.PointerEventTypes.POINTERUP&&(_.current=null),E.type===u.PointerEventTypes.POINTERMOVE&&_.current){const L=E.event.clientX-_.current.x,y=E.event.clientY-_.current.y;if(E.event.buttons===1){let A=null;(I.lockedTarget||b)&&(I.lockedTarget&&(A=I.lockedTarget.position),b&&(A=b)),A&&M.current?(M.current.target=A,M.current.position=I.position.clone(),M.current.wheelDeltaPercentage=r,M.current.panningSensibility=s,M.current.alpha+=L/100*l,M.current.beta+=y/100*l,M.current.update(),I.position=M.current.position.clone(),I.rotation=M.current.rotation.clone()):(I.rotation.y-=L/100*l,I.rotation.x-=y/100*l)}E.event.buttons===2&&(I.position.x-=L/100*s,I.position.y+=y/100*s),_.current=new u.Vector2(E.event.clientX,E.event.clientY)}});return()=>{c.onPointerObservable.remove(D)}}},[b,s,x,l,c,r]);const S=m.useCallback(I=>{I&&(I.inputs.addMouseWheel(),I.inputs.removeMouse(),T(I),h(I))},[T]);m.useEffect(()=>{if(x){const I=x.inputs.attached.mousewheel;I.wheelPrecisionX=r,I.wheelPrecisionY=r,I.wheelPrecisionZ=r}},[x,r]);const N=m.useCallback(()=>{if(x&&f){const I=new u.Vector3;I.addInPlace(x.position),I.addInPlace(x.getDirection(new u.Vector3(0,0,25))),a==Bt.TOP_RIGHT?(I.addInPlace(x.getDirection(new u.Vector3(0,7+i.y,0))),I.addInPlace(x.getDirection(new u.Vector3(15+i.x,0,0)))):a==Bt.TOP_LEFT?(I.addInPlace(x.getDirection(new u.Vector3(0,7+i.y,0))),I.addInPlace(x.getDirection(new u.Vector3(-15+i.x,0,0)))):a==Bt.BOTTOM_RIGHT?(I.addInPlace(x.getDirection(new u.Vector3(0,-7+i.y,0))),I.addInPlace(x.getDirection(new u.Vector3(15+i.x,0,0)))):a==Bt.BOTTOM_LEFT&&(I.addInPlace(x.getDirection(new u.Vector3(0,-7+i.y,0))),I.addInPlace(x.getDirection(new u.Vector3(-15+i.x,0,0)))),f.xAxis.position=I.clone(),f.yAxis.position=I.clone(),f.zAxis.position=I.clone()}},[x,f,a,i.y,i.x]);m.useEffect(()=>{if(c&&a!=Bt.NONE){const I=new u.AxesViewer(c,2,null);return d(I),()=>{I==null||I.dispose(),d(null)}}},[c,a]),m.useEffect(()=>{N()},[N]),m.useEffect(()=>{T(c&&x?x:void 0)},[c,x,T]),m.useEffect(()=>{if(!c||!x)return;const I=x.onViewMatrixChangedObservable.add(()=>{o&&(w(!0),v(D=>(D&&clearTimeout(D),setTimeout(()=>{w(!1),v(null)},250)))),N()});return()=>{x.onViewMatrixChangedObservable.remove(I),v(D=>(D&&clearTimeout(D),null)),w(!1)}},[c,a,x,p,f,N,o,w]);const[F,B]=m.useState();return m.useEffect(()=>{if(x){const I={lookAt:D=>{x&&x.setTarget(D)},updatePosition:D=>{x&&(x.position=D)},lockTarget:D=>{x&&(k(null),x.lockedTarget=D)},lockTo:D=>{x&&(x.lockedTarget=null,k(D))}};B(I),P&&P.current&&(P.current.rawCamera=x,P.current.cameraTools=I)}},[P,x]),m.useImperativeHandle(t,()=>({rawCamera:x,cameraTools:F}),[F,x]),C.jsx("universalCamera",{name:"universal-main-camera",position:n,ref:S,maxZ:0})},Hu=m.forwardRef(Uu);class Zu extends u.BaseCameraPointersInput{constructor(){super(...arguments);ve(this,"camera");ve(this,"buttons",[0,1,2,4]);ve(this,"panningSensibility",10);ve(this,"angularSensibility",1e4);ve(this,"_isPanClick",!1);ve(this,"_isPinching",!1)}getClassName(){return"FreeCameraPointersInput"}onButtonDown(n){(n.buttons===1||n.buttons===4)&&(this._isPinching=!0),n.buttons===2&&(this._isPanClick=!0)}onButtonUp(n){n&&(this._isPanClick=!1,this._isPinching=!1)}onTouch(n,a,i){if(this.panningSensibility!==0&&this._isPanClick){const o=-a/this.panningSensibility,r=i/this.panningSensibility;this.camera._localDirection.copyFromFloats(o,r,0),this.camera.getViewMatrix().invertToRef(this.camera._cameraTransformMatrix),u.Vector3.TransformNormalToRef(this.camera._localDirection,this.camera._cameraTransformMatrix,this.camera._transformedDirection),this.camera.cameraDirection.addInPlace(this.camera._transformedDirection)}if(this.angularSensibility!==0&&this._isPinching){const o=u.Quaternion.FromEulerAngles(this.camera.rotation.x,this.camera.rotation.y,this.camera.rotation.z),r=u.Quaternion.RotationAxis(u.Axis.Y,u.Tools.ToDegrees(a/this.angularSensibility)),l=u.Quaternion.RotationAxis(u.Axis.X,u.Tools.ToDegrees(i/this.angularSensibility)),s=o.multiply(r).multiply(l);this.camera.rotation=s.toEulerAngles()}}onLostFocus(){this._isPanClick=!1,this._isPinching=!1}}const Gu=e=>{const{position:t,target:n=new u.Vector3(0,0,0),panningSensibility:a=5,angularSensibility:i=2e3,skipPickingWhenCameraMoves:o=!1}=e,r=_e.useScene(),l=m.useRef(null),s=m.useRef(null),c=m.useCallback(p=>{r&&(r.skipPointerMovePicking=p)},[r]);return m.useEffect(()=>{if(l.current){l.current.inputs.removeByType("FreeCameraMouseInput");const p=new Zu,f=new u.FreeCameraMouseWheelInput;l.current.inputs.add(p),l.current.inputs.add(f)}},[]),m.useEffect(()=>{l.current&&n&&l.current.setTarget(n)},[n]),m.useEffect(()=>{if(!r||!l.current)return;const p=l.current.onViewMatrixChangedObservable.add(()=>{o&&(c(!0),s.current&&clearTimeout(s.current),s.current=setTimeout(()=>{c(!1),s.current=null},250))});return()=>{var f;(f=l.current)==null||f.onViewMatrixChangedObservable.remove(p),s.current&&(clearTimeout(s.current),s.current=null),c(!1)}},[r,c,o]),m.useEffect(()=>{if(l.current){if(l.current.inputs.attached.pointers){const p=l.current.inputs.attached.pointers;p.panningSensibility=Math.abs(a),p.angularSensibility=Math.abs(i)}if(l.current.inputs.attached.pointersPanning){const p=l.current.inputs.attached.pointersPanning;p.panningSensibility=Math.abs(a)}if(l.current.inputs.attached.around){const p=l.current.inputs.attached.around;p.angularSensibility=Math.abs(i)}}},[i,a]),C.jsx("freeCamera",{name:"rootCamera",position:t,ref:l})};class Yu extends u.TransformNode{constructor(n,a,i){super(n,a);ve(this,"_showDepthTexture",!1);ve(this,"_postProcess");this._postProcess=i,this.showDepthTexture=!1,this.inspectableCustomProperties=[{label:"Show Depth Texture",propertyName:"showDepthTexture",type:u.InspectableType.Checkbox}]}set showDepthTexture(n){var a,i;this._showDepthTexture=n,this._postProcess&&(this._showDepthTexture?(a=this.getScene().activeCamera)==null||a.attachPostProcess(this._postProcess):(i=this.getScene().activeCamera)==null||i.detachPostProcess(this._postProcess))}get showDepthTexture(){return this._showDepthTexture}}const Ju=()=>{const e=_e.useEngine(),t=_e.useScene();return m.useEffect(()=>{if(t&&e){u.Effect.ShadersStore.depthbufferPixelShader=`#ifdef GL_ES
|
|
1211
|
+
}`,Yn=({alpha:e,zOffset:t,zOffsetUnits:n,disableDepthWrite:a})=>C.jsx("pbrMaterial",{name:"metal-pbr-material",alpha:e,transparencyMode:e!==void 0&&e<1?u.Material.MATERIAL_ALPHABLEND:u.Material.MATERIAL_OPAQUE,alphaMode:u.Engine.ALPHA_COMBINE,roughness:.25,metallic:1,albedoColor:new u.Color3(.7,.7,.7),metallicF0Factor:.1,zOffset:t,zOffsetUnits:n,disableDepthWrite:a}),Jn=({alpha:e,zOffset:t,zOffsetUnits:n,disableDepthWrite:a})=>C.jsx("pbrMaterial",{name:"metal-pbr-material",alpha:e,transparencyMode:e!==void 0&&e<1?u.Material.MATERIAL_ALPHABLEND:u.Material.MATERIAL_OPAQUE,alphaMode:u.Engine.ALPHA_COMBINE,roughness:.25,metallic:1,albedoColor:new u.Color3(.2,.2,.2),metallicF0Factor:.1,zOffsetUnits:n,zOffset:t,disableDepthWrite:a});var qt=(e=>(e[e.TRIGONOMETRIC=0]="TRIGONOMETRIC",e[e.PLANE=1]="PLANE",e[e.FLAT=2]="FLAT",e))(qt||{});const Kt=e=>{const t=_e.useScene(),[n,a]=m.useState(null),[i,o]=m.useState(null),{tilingFactor:r=.1,sideTilingFactor:l=.1,texture:s,alpha:c=1,mode:p=0,zOffset:f,zOffsetUnits:d,sideTexture:x,uvOffset:h=u.Vector2.Zero(),counterLine:T=void 0,scalePlane:P=1,scaleDepth:v=1,boundingBox:_=void 0,lines:b=[],text:k=[],disableDepthWrite:M,flatModeRotate:w=0}=e,S=N=>{a(N)};return m.useEffect(()=>{n&&s&&(n.setTexture("textureSampler",s),n.setFloat("textureFlatRotate",w),n.setVector2("uvOffset",h))},[w,n,s,h]),m.useEffect(()=>{n&&n.setFloat("alpha",c)},[c,n]),m.useEffect(()=>{n&&n.setFloat("tilingFactor",r),n&&n.setFloat("sideTilingFactor",l)},[r,l,n]),m.useEffect(()=>{n&&n.setInt("mode",p)},[n,p]),m.useEffect(()=>{n&&(x?n.setTexture("textureSideSampler",x):n.setTexture("textureSideSampler",s))},[n,x,s]),m.useEffect(()=>{var N;if(n)if(T&&_){const F=(N=T.startHeight)!=null?N:_.minimumWorld.y/v;return n.setFloat("contourLineStartHeight",F*v),n.setColor3("contourLineColor",T.color),n.setFloat("contourLineWidth",T.width),n.setFloat("contourLineStep",T.stepHeight*v),console.log("[Geo3DViewer] 等高线设置 ",T,_.centerWorld.y,F*v,F*v+16*T.stepHeight*v),()=>{n&&(n.setFloat("contourLineStartHeight",0),n.setColor3("contourLineColor",new u.Color3(0,0,0)),n.setFloat("contourLineWidth",0),n.setFloat("contourLineStep",0))}}else n.setFloat("contourLineStartHeight",0),n.setColor3("contourLineColor",new u.Color3(0,0,0)),n.setFloat("contourLineWidth",0),n.setFloat("contourLineStep",0),console.log("[Geo3DViewer] 等高线设置 关闭")},[T,v,P,_,n]),m.useEffect(()=>{t&&n&&_&&o(N=>{N&&N.dispose();let F=(_.maximum.x-_.minimum.x)/P,B=(_.maximum.z-_.minimum.z)/P,I=0;if(F<B){const L=F;F=B,B=L,I=1}const D=F/B;F*B>2048*2048&&(F=2048,B=2048/D);const E=new u.DynamicTexture("dynamic-texture",{width:F,height:B},t,!1);return E.clear(),console.log("[Geo3DViewer] 设置动态划线 ",_,F,B,P),n.setVector3("oMin",_.minimum),n.setVector3("oMax",_.maximum),n.setFloat("textureOverlayRotate",I),n.setTexture("textureOverlaySampler",E),E})},[_,n,P,t]),m.useEffect(()=>{var N;if(i&&_)if((N=i.getScene())!=null&&N.getEngine()){i.clear();let F=(_.maximum.x-_.minimum.x)/P,B=(_.maximum.z-_.minimum.z)/P;if(F<B){const E=F;F=B,B=E}const I=F/B;F*B>2048*2048&&(F=2048,B=2048/I);const D=i.getContext();b.forEach(E=>{if(E.points.length<2)return;D.beginPath();const L=E.offset?E.offset:new u.Vector2(0,0),y=1-E.points[0].x+L.x,A=1-E.points[0].y+L.y;D.moveTo(y*F,A*B);for(let V=1;V<E.points.length;V++){const $=E.offset?E.offset:new u.Vector2(0,0),W=1-E.points[V].x+$.x,ne=1-E.points[V].y+$.y;D.lineTo(W*F,ne*B)}D.strokeStyle=`rgb(${E.color.r*255}, ${E.color.g*255}, ${E.color.b*255})`,F*B>2048*2048?D.lineWidth=E.width/I:D.lineWidth=E.width,D.stroke()}),k.forEach(E=>{var V,$;D.font=`${E.fontSize}px Arial`;const L=(V=E.color)!=null?V:u.Color3.White(),y=E.offset?E.offset:new u.Vector2(0,0),A=($=E.rotation)!=null?$:0;if(D.save(),D.translate((1-E.position.x+y.x)*F,(1-E.position.y+y.y)*B),D.rotate(A),E.clearArea){const W=D.measureText(E.text);D.clearRect(-W.width*.15,.5*E.fontSize*(1-.3),W.width*1.3,-E.fontSize*1.3)}if(E.background){D.fillStyle=`rgba(${E.background.r*255}, ${E.background.g*255}, ${E.background.b*255})`;const W=D.measureText(E.text);D.fillRect(-W.width*.05,.5*(E.fontSize*(.5-.1)),W.width*1.1,-E.fontSize*1.1)}D.fillStyle=`rgb(${L.r*255}, ${L.g*255}, ${L.b*255})`,D.fillText(E.text,0,0),D.restore()}),i.update()}else console.log("[Geo3DViewer] 动态纹理未准备好,正准备下一次绘制")},[b,k,i,_,P]),C.jsx(lt,{...e,ref:S,vertex:gu,fragment:mu,options:{attributes:["position","color","alpha","normal"],uniforms:["worldViewProjection","tilingFactor","sideTilingFactor","mode","uvOffset","contourLineStartHeight","contourLineColor","contourLineWidth","contourLineStep","oMin","oMax","textureOverlayRotate","textureFlatRotate"],samplers:["textureSampler","textureOverlaySampler","textureSideSampler"],needAlphaBlending:!0,needAlphaTesting:!0},zOffset:f,zOffsetUnits:d,disableDepthWrite:M})},Mt=e=>{const t=_e.useScene(),n=m.useRef(null),a=m.useContext(Vn),[i,o]=m.useState(null),{name:r,colorCodec:l,alpha:s=1,backFaceCulling:c,needDepthPrePass:p=!1,transparencyMode:f=u.Material.MATERIAL_OPAQUE,alphaMode:d=u.Engine.ALPHA_COMBINE,zOffset:x,zOffsetUnits:h,clipPlane:T,counterLine:P=void 0,scalePlane:v=1,scaleDepth:_=1,boundingBox:b,lines:k=[],text:M=[],disableDepthWrite:w}=e;return m.useEffect(()=>{const S=n.current;S&&t&&(S.loadFromSerialization(du,""),S.build(!1,!0,!1))},[t]),m.useEffect(()=>{const S=n.current;S&&(S.name=`${r}-material`,S.backFaceCulling=c!=null?c:!0,S.needDepthPrePass=p,S.transparencyMode=f,S.alphaMode=d,S.alpha=s,S.zOffset=x!=null?x:1,S.zOffsetUnits=h!=null?h:0,S.clipPlane=T!=null?T:null,S.disableDepthWrite=w!=null?w:!1)},[s,d,c,T,w,r,p,f,x,h]),m.useEffect(()=>{if(l){const S=n.current;S&&(S.metadata={colorCodec:l},u.Tags.EnableFor(S),u.Tags.AddTagsTo(S,"remap"))}if(l&&a&&t&&a.colorCodecsImage.current[l]){const S=n.current;if(S){const N=S.getBlockByName("RemappedTexture");N&&(N.texture=a.colorCodecsImage.current[l].texture,S.markAsDirty(u.NodeMaterial.TextureDirtyFlag))}}},[l,t]),m.useEffect(()=>{n.current&&t&&(console.log("[Geo3DViewer] RemapColorByRedChannel 透明度更新 ",s),n.current.alpha=s)},[t,s]),m.useEffect(()=>{var N;const S=n.current;if(S){const F=S.getBlockByName("contourLineStartHeight"),B=S.getBlockByName("contourLineColor"),I=S.getBlockByName("contourLineWidth"),D=S.getBlockByName("contourLineStep");if(P&&b){const E=(N=P.startHeight)!=null?N:b.centerWorld.y/_;return F&&(F.value=E*_),B&&(B.value=P.color),I&&(I.value=P.width),D&&(D.value=P.stepHeight*_),console.log("[Geo3DViewer] 等高线设置 ",P,b.centerWorld,b.centerWorld.y,E*_,E*_+16*P.stepHeight*_),()=>{S&&(F&&(F.value=0),B&&(B.value=new u.Color3(0,0,0)),I&&(I.value=0),D&&(D.value=0))}}else F&&(F.value=0),B&&(B.value=new u.Color3(0,0,0)),I&&(I.value=0),D&&(D.value=0),console.log("[Geo3DViewer] 等高线设置 关闭");S.markAsDirty(u.NodeMaterial.MiscDirtyFlag)}},[P,_,v,b]),m.useEffect(()=>{t&&b&&o(S=>{var y,A;S&&S.dispose();let N=(b.maximum.x-b.minimum.x)/v,F=(b.maximum.z-b.minimum.z)/v,B=0;if(N<F){const V=N;N=F,F=V,B=1}const I=N/F;N*F>2048*2048&&(N=2048,F=2048/I);const D=new u.DynamicTexture("dynamic-texture",{width:N,height:F},t,!1);D.clear(),console.log("[Geo3DViewer] 设置动态划线 ",b,N,F,v);const E=(y=n.current)==null?void 0:y.getBlockByName("angle"),L=(A=n.current)==null?void 0:A.getBlockByName("OverlayTexture");return E&&(E.value=B*(Math.PI/2)),L&&(L.texture=D),D})},[b,v,t]),m.useEffect(()=>{var S;if(i&&b)if((S=i.getScene())!=null&&S.getEngine()){i.clear();let N=(b.maximum.x-b.minimum.x)/v,F=(b.maximum.z-b.minimum.z)/v;if(N<F){const D=N;N=F,F=D}const B=N/F;N*F>2048*2048&&(N=2048,F=2048/B);const I=i.getContext();k.forEach(D=>{if(D.points.length<2)return;I.beginPath();const E=D.offset?D.offset:new u.Vector2(0,0),L=1-D.points[0].x+E.x,y=1-D.points[0].y+E.y;I.moveTo(L*N,y*F);for(let A=1;A<D.points.length;A++){const V=D.offset?D.offset:new u.Vector2(0,0),$=1-D.points[A].x+V.x,W=1-D.points[A].y+V.y;I.lineTo($*N,W*F)}I.strokeStyle=`rgb(${D.color.r*255}, ${D.color.g*255}, ${D.color.b*255})`,N*F>2048*2048?I.lineWidth=D.width/B:I.lineWidth=D.width,I.stroke()}),M.forEach(D=>{var A,V;I.font=`${D.fontSize}px Arial`;const E=(A=D.color)!=null?A:u.Color3.White(),L=D.offset?D.offset:new u.Vector2(0,0),y=(V=D.rotation)!=null?V:0;if(I.save(),I.translate((1-D.position.x+L.x)*N,(1-D.position.y+L.y)*F),I.rotate(y),D.clearArea){const $=I.measureText(D.text);I.clearRect(-$.width*.15,.5*D.fontSize*(1-.3),$.width*1.3,-D.fontSize*1.3)}if(D.background){I.fillStyle=`rgba(${D.background.r*255}, ${D.background.g*255}, ${D.background.b*255})`;const $=I.measureText(D.text);I.fillRect(-$.width*.05,.5*(D.fontSize*(.5-.1)),$.width*1.1,-D.fontSize*1.1)}I.fillStyle=`rgb(${E.r*255}, ${E.g*255}, ${E.b*255})`,I.fillText(D.text,0,0),I.restore()}),i.update()}else console.log("[Geo3DViewer] 动态纹理未准备好,正准备下一次绘制")},[k,i,b,v,M]),C.jsx("nodeMaterial",{ref:n,name:`${r}-material`,backFaceCulling:c,needDepthPrePass:p,transparencyMode:f,alphaMode:d,alpha:s,zOffset:x,zOffsetUnits:h,clipPlane:T,disableDepthWrite:w})},Qi=e=>{const t=_e.useScene(),n=m.useContext(Vn),a=m.useRef(null),[i,o]=m.useState(null),[r,l]=m.useState(null),[s,c]=m.useState(null),[p,f]=m.useState(null),[d,x]=m.useState(null),[h,T]=m.useState(null),[P,v]=m.useState(null),[_,b]=m.useState(null),{boundingBox:k,colorCodec:M,alphaStage:w,cutNormal:S,value:N,zOffset:F,zOffsetUnits:B,counterLine:I=void 0,scaleDepth:D=1,scalePlane:E=1,lines:L=[],text:y=[],disableDepthWrite:A}=e;return m.useEffect(()=>{const V=($,W,ne)=>{if(k){const ee=k.maximumWorld.multiply(W),G=k.minimumWorld.multiply(W),le=k.centerWorld.multiply(W),re=Math.max(ee.x,ee.y,ee.z),oe=Math.max(G.x,G.y,G.z),Y=Math.max(le.x,le.y,le.z),ce=Math.max(Math.abs(W.x),Math.abs(W.z));$(new u.Plane(W.x,W.y,W.z,((re-oe)*(1-ne-.5)*ce+Y)*-1))}else $(null)};k&&_&&(V(o,_.cutPlane1,N.value1),_.cutPlane2&&N.value2?V(l,_.cutPlane2,N.value2):l(null),_.cutPlane3&&N.value3?V(c,_.cutPlane3,N.value3):c(null),_.cutPlane4&&N.value4?V(f,_.cutPlane4,N.value4):f(null),_.cutPlane5&&N.value5?V(x,_.cutPlane5,N.value5):c(null),_.cutPlane6&&N.value6?V(T,_.cutPlane6,N.value6):T(null))},[k,_,N]),m.useEffect(()=>{b({cutPlane1:u.Vector3.Normalize(S.cutPlane1),cutPlane2:S.cutPlane2?u.Vector3.Normalize(S.cutPlane2):void 0,cutPlane3:S.cutPlane3?u.Vector3.Normalize(S.cutPlane3):void 0,cutPlane4:S.cutPlane4?u.Vector3.Normalize(S.cutPlane4):void 0,cutPlane5:S.cutPlane5?u.Vector3.Normalize(S.cutPlane5):void 0,cutPlane6:S.cutPlane6?u.Vector3.Normalize(S.cutPlane6):void 0})},[S]),m.useEffect(()=>{const V=a.current;V&&(V.clipPlane=i,V.clipPlane2=r,V.clipPlane3=s,V.clipPlane4=p,V.clipPlane5=d,V.clipPlane6=h)},[i,r,s,p,d,h]),m.useEffect(()=>{var V,$,W,ne,ee;a.current&&t&&(a.current.setFloat("alpha1",w.alpha1),a.current.setFloat("alpha2",(V=w.alpha2)!=null?V:1),a.current.setFloat("alpha3",($=w.alpha3)!=null?$:1),a.current.setFloat("alpha4",(W=w.alpha4)!=null?W:1),a.current.setFloat("alpha5",(ne=w.alpha5)!=null?ne:1),a.current.setFloat("alpha6",(ee=w.alpha6)!=null?ee:1))},[t,w]),m.useEffect(()=>{if(M){const V=a.current;V&&(V.metadata={colorCodec:M},u.Tags.EnableFor(V),u.Tags.AddTagsTo(V,"remap"))}if(M&&n&&t&&n.colorCodecsImage.current[M]){const V=a.current;V&&(console.log(n.colorCodecsImage.current[M]),V.setTexture("textureSampler",n.colorCodecsImage.current[M].texture),V.metadata={colorCodec:M},u.Tags.EnableFor(V),u.Tags.AddTagsTo(V,"remap"))}},[M,t]),m.useEffect(()=>{var $;const V=a.current;if(V&&k)if(I){const W=($=I.startHeight)!=null?$:k.minimumWorld.y/D;return V.setFloat("contourLineStartHeight",W*D),V.setColor3("contourLineColor",I.color),V.setFloat("contourLineWidth",I.width),V.setFloat("contourLineStep",I.stepHeight*D),console.log("[Geo3DViewer] 等高线设置 ",I,k.centerWorld.y,W*D,W*D+16*I.stepHeight*D),()=>{V&&(V.setFloat("contourLineStartHeight",0),V.setColor3("contourLineColor",new u.Color3(0,0,0)),V.setFloat("contourLineWidth",0),V.setFloat("contourLineStep",0))}}else V.setFloat("contourLineStartHeight",0),V.setColor3("contourLineColor",new u.Color3(0,0,0)),V.setFloat("contourLineWidth",0),V.setFloat("contourLineStep",0),console.log("[Geo3DViewer] 等高线设置 关闭")},[I,D,E,k]),m.useEffect(()=>{t&&k&&v(V=>{var le,re,oe,Y;V&&V.dispose();let $=(k.maximum.x-k.minimum.x)/E,W=(k.maximum.z-k.minimum.z)/E,ne=0;if($<W){const ce=$;$=W,W=ce,ne=1}const ee=$/W;$*W>2048*2048&&($=2048,W=2048/ee);const G=new u.DynamicTexture("dynamic-texture",{width:$,height:W},t,!1);return G.clear(),console.log("[Geo3DViewer] 设置动态划线 ",k,$,W,E),(le=a.current)==null||le.setVector3("oMin",k.minimum),(re=a.current)==null||re.setVector3("oMax",k.maximum),(oe=a.current)==null||oe.setFloat("textureOverlayRotate",ne),(Y=a.current)==null||Y.setTexture("textureOverlaySampler",G),G})},[k,E,t]),m.useEffect(()=>{var V;if(P&&k)if((V=P.getScene())!=null&&V.getEngine()){P.clear();let $=(k.maximum.x-k.minimum.x)/E,W=(k.maximum.z-k.minimum.z)/E;if($<W){const G=$;$=W,W=G}const ne=$/W;$*W>2048*2048&&($=2048,W=2048/ne);const ee=P.getContext();L.forEach(G=>{if(G.points.length<2)return;ee.beginPath();const le=G.offset?G.offset:new u.Vector2(0,0),re=1-G.points[0].x+le.x,oe=1-G.points[0].y+le.y;ee.moveTo(re*$,oe*W);for(let Y=1;Y<G.points.length;Y++){const ce=G.offset?G.offset:new u.Vector2(0,0),ae=1-G.points[Y].x+ce.x,X=1-G.points[Y].y+ce.y;ee.lineTo(ae*$,X*W)}ee.strokeStyle=`rgb(${G.color.r*255}, ${G.color.g*255}, ${G.color.b*255})`,$*W>2048*2048?ee.lineWidth=G.width/ne:ee.lineWidth=G.width,ee.stroke()}),y.forEach(G=>{var Y,ce;ee.font=`${G.fontSize}px Arial`;const le=(Y=G.color)!=null?Y:u.Color3.White(),re=G.offset?G.offset:new u.Vector2(0,0),oe=(ce=G.rotation)!=null?ce:0;if(ee.save(),ee.translate((1-G.position.x+re.x)*$,(1-G.position.y+re.y)*W),ee.rotate(oe),G.clearArea){const ae=ee.measureText(G.text);ee.clearRect(-ae.width*.15,.5*G.fontSize*(1-.3),ae.width*1.3,-G.fontSize*1.3)}if(G.background){ee.fillStyle=`rgba(${G.background.r*255}, ${G.background.g*255}, ${G.background.b*255})`;const ae=ee.measureText(G.text);ee.fillRect(-ae.width*.05,.5*(G.fontSize*(.5-.1)),ae.width*1.1,-G.fontSize*1.1)}ee.fillStyle=`rgb(${le.r*255}, ${le.g*255}, ${le.b*255})`,ee.fillText(G.text,0,0),ee.restore()}),P.update()}else console.log("[Geo3DViewer] 动态纹理未准备好,正准备下一次绘制")},[L,P,k,E,y]),C.jsx(lt,{...e,ref:a,vertex:hu,fragment:pu,options:{attributes:["position","color","normal"],uniforms:["world","worldViewProjection","alpha1","alpha2","alpha3","alpha4","alpha5","alpha6","oMin","oMax","contourLineStartHeight","contourLineColor","contourLineWidth","contourLineStep","textureOverlayRotate"],samplers:["textureOverlaySampler","textureSampler"],needAlphaBlending:!0,needAlphaTesting:!0,useClipPlane:!0},disableDepthWrite:A,zOffset:F,zOffsetUnits:B})},ji=e=>{const t=_e.useScene(),[n,a]=m.useState(null),[i,o]=m.useState(null),[r,l]=m.useState(null),[s,c]=m.useState(null),[p,f]=m.useState(null),[d,x]=m.useState(null),[h,T]=m.useState(null),[P,v]=m.useState(null),[_,b]=m.useState(null),{boundingBox:k=void 0,texture:M,sideTexture:w,alphaStage:S,cutNormal:N,value:F,tilingFactor:B=.1,sideTilingFactor:I=.1,mode:D=0,zOffset:E,zOffsetUnits:L,overlay:y={},counterLine:A=void 0,scalePlane:V=1,scaleDepth:$=1,lines:W=[],text:ne=[],disableDepthWrite:ee,textureFlatRotate:G=0}=e,le=re=>{a(re)};return m.useEffect(()=>{n&&n.setFloat("textureFlatRotate",G)},[n,G]),m.useEffect(()=>{const re=(oe,Y,ce)=>{if(k){const ae=k.maximumWorld.multiply(Y),X=k.minimumWorld.multiply(Y),Pe=k.centerWorld.multiply(Y),ge=Math.max(ae.x,ae.y,ae.z),H=Math.max(X.x,X.y,X.z),Q=Math.max(Pe.x,Pe.y,Pe.z),Ee=Math.max(Math.abs(Y.x),Math.abs(Y.z)),ke=new u.Plane(Y.x,Y.y,Y.z,((ge-H)*(1-ce-.5)*Ee+Q)*-1);oe(ke),console.log("[Geo3DViewer] 设置实际 CutPlane 为 ",ke,Ee)}else oe(null)};k&&_&&(re(o,_.cutPlane1,F.value1),_.cutPlane2&&F.value2?re(l,_.cutPlane2,F.value2):l(null),_.cutPlane3&&F.value3?re(c,_.cutPlane3,F.value3):c(null),_.cutPlane4&&F.value4?re(f,_.cutPlane4,F.value4):f(null),_.cutPlane5&&F.value5?re(x,_.cutPlane5,F.value5):c(null),_.cutPlane6&&F.value6?re(T,_.cutPlane6,F.value6):T(null))},[_,k,F]),m.useEffect(()=>{b({cutPlane1:u.Vector3.Normalize(N.cutPlane1),cutPlane2:N.cutPlane2?u.Vector3.Normalize(N.cutPlane2):void 0,cutPlane3:N.cutPlane3?u.Vector3.Normalize(N.cutPlane3):void 0,cutPlane4:N.cutPlane4?u.Vector3.Normalize(N.cutPlane4):void 0,cutPlane5:N.cutPlane5?u.Vector3.Normalize(N.cutPlane5):void 0,cutPlane6:N.cutPlane6?u.Vector3.Normalize(N.cutPlane6):void 0})},[N]),m.useEffect(()=>{n&&(n.clipPlane=i,n.clipPlane2=r,n.clipPlane3=s,n.clipPlane4=p,n.clipPlane5=d,n.clipPlane6=h)},[n,i,r,s,p,d,h]),m.useEffect(()=>{var re,oe,Y,ce,ae;n&&t&&(n.setFloat("alpha1",S.alpha1),n.setFloat("alpha2",(re=S.alpha2)!=null?re:1),n.setFloat("alpha3",(oe=S.alpha3)!=null?oe:1),n.setFloat("alpha4",(Y=S.alpha4)!=null?Y:1),n.setFloat("alpha5",(ce=S.alpha5)!=null?ce:1),n.setFloat("alpha6",(ae=S.alpha6)!=null?ae:1))},[t,S,n]),m.useEffect(()=>{n&&M&&n.setTexture("textureSampler",M)},[n,M]),m.useEffect(()=>{n&&B&&n.setFloat("tilingFactor",B),n&&I&&n.setFloat("sideTilingFactor",I)},[B,I,n]),m.useEffect(()=>{n&&D&&n.setInt("mode",D)},[n,D]),m.useEffect(()=>{n&&(w?n.setTexture("textureSideSampler",w):n.setTexture("textureSideSampler",M))},[n,w,M]),m.useEffect(()=>{n&&(y.texture1?n.setTexture("textureSampler1",y.texture1):n.setTexture("textureSampler1",M),y.sideTexture1?n.setTexture("textureSideSampler1",y.sideTexture1):n.setTexture("textureSideSampler1",M),y.color1?n.setColor3("vColor1",y.color1):n.setColor3("vColor1",new u.Color3(1,1,1)),y.texture2?n.setTexture("textureSampler2",y.texture2):n.setTexture("textureSampler2",M),y.sideTexture2?n.setTexture("textureSideSampler2",y.sideTexture2):n.setTexture("textureSideSampler2",M),y.color2?n.setColor3("vColor2",y.color2):n.setColor3("vColor2",new u.Color3(1,1,1)),y.texture3?n.setTexture("textureSampler3",y.texture3):n.setTexture("textureSampler3",M),y.sideTexture3?n.setTexture("textureSideSampler3",y.sideTexture3):n.setTexture("textureSideSampler2",M),y.color3?n.setColor3("vColor3",y.color3):n.setColor3("vColor3",new u.Color3(1,1,1)),y.texture4?n.setTexture("textureSampler4",y.texture4):n.setTexture("textureSampler4",M),y.sideTexture4?n.setTexture("textureSideSampler4",y.sideTexture4):n.setTexture("textureSideSampler4",M),y.color4?n.setColor3("vColor4",y.color4):n.setColor3("vColor4",new u.Color3(1,1,1)),y.texture5?n.setTexture("textureSampler5",y.texture5):n.setTexture("textureSampler5",M),y.sideTexture5?n.setTexture("textureSideSampler5",y.sideTexture5):n.setTexture("textureSideSampler5",M),y.color5?n.setColor3("vColor5",y.color5):n.setColor3("vColor5",new u.Color3(1,1,1)),y.texture6?n.setTexture("textureSampler6",y.texture6):n.setTexture("textureSampler6",M),y.sideTexture6?n.setTexture("textureSideSampler6",y.sideTexture6):n.setTexture("textureSideSampler6",M),y.color6?n.setColor3("vColor6",y.color6):n.setColor3("vColor6",new u.Color3(1,1,1)))},[n,y,M]),m.useEffect(()=>{var re;if(n&&k)if(A){const oe=(re=A.startHeight)!=null?re:k.minimumWorld.y/$;return n.setFloat("contourLineStartHeight",oe*$),n.setColor3("contourLineColor",A.color),n.setFloat("contourLineWidth",A.width),n.setFloat("contourLineStep",A.stepHeight*$),console.log("[Geo3DViewer] 等高线设置 ",A,k.centerWorld.y,oe*$,oe*$+16*A.stepHeight*$),()=>{n&&(n.setFloat("contourLineStartHeight",0),n.setColor3("contourLineColor",new u.Color3(0,0,0)),n.setFloat("contourLineWidth",0),n.setFloat("contourLineStep",0))}}else n.setFloat("contourLineStartHeight",0),n.setColor3("contourLineColor",new u.Color3(0,0,0)),n.setFloat("contourLineWidth",0),n.setFloat("contourLineStep",0),console.log("[Geo3DViewer] 等高线设置 关闭")},[A,$,V,k,n]),m.useEffect(()=>{t&&n&&k&&v(re=>{re&&re.dispose();let oe=(k.maximum.x-k.minimum.x)/V,Y=(k.maximum.z-k.minimum.z)/V,ce=0;if(oe<Y){const Pe=oe;oe=Y,Y=Pe,ce=1}const ae=oe/Y;oe*Y>2048*2048&&(oe=2048,Y=2048/ae);const X=new u.DynamicTexture("dynamic-texture",{width:oe,height:Y},t,!1);return X.clear(),console.log("[Geo3DViewer] 设置动态划线 ",k,oe,Y,V),n.setVector3("oMin",k.minimum),n.setVector3("oMax",k.maximum),n.setFloat("textureOverlayRotate",ce),n.setTexture("textureOverlaySampler",X),X})},[k,n,V,t]),m.useEffect(()=>{var re;if(P&&k)if((re=P.getScene())!=null&&re.getEngine()){P.clear();let oe=(k.maximum.x-k.minimum.x)/V,Y=(k.maximum.z-k.minimum.z)/V;if(oe<Y){const X=oe;oe=Y,Y=X}const ce=oe/Y;oe*Y>2048*2048&&(oe=2048,Y=2048/ce);const ae=P.getContext();W.forEach(X=>{if(X.points.length<2)return;ae.beginPath();const Pe=X.offset?X.offset:new u.Vector2(0,0),ge=1-X.points[0].x+Pe.x,H=1-X.points[0].y+Pe.y;ae.moveTo(ge*oe,H*Y);for(let Q=1;Q<X.points.length;Q++){const Ee=X.offset?X.offset:new u.Vector2(0,0),ke=1-X.points[Q].x+Ee.x,te=1-X.points[Q].y+Ee.y;ae.lineTo(ke*oe,te*Y)}ae.strokeStyle=`rgb(${X.color.r*255}, ${X.color.g*255}, ${X.color.b*255})`,oe*Y>2048*2048?ae.lineWidth=X.width/ce:ae.lineWidth=X.width,ae.stroke()}),ne.forEach(X=>{var Q,Ee;ae.font=`${X.fontSize}px Arial`;const Pe=(Q=X.color)!=null?Q:u.Color3.White(),ge=X.offset?X.offset:new u.Vector2(0,0),H=(Ee=X.rotation)!=null?Ee:0;if(ae.save(),ae.translate((1-X.position.x+ge.x)*oe,(1-X.position.y+ge.y)*Y),ae.rotate(H),X.clearArea){const ke=ae.measureText(X.text);ae.clearRect(-ke.width*.15,.5*X.fontSize*(1-.3),ke.width*1.3,-X.fontSize*1.3)}if(X.background){ae.fillStyle=`rgba(${X.background.r*255}, ${X.background.g*255}, ${X.background.b*255})`;const ke=ae.measureText(X.text);ae.fillRect(-ke.width*.05,.5*(X.fontSize*(.5-.1)),ke.width*1.1,-X.fontSize*1.1)}ae.fillStyle=`rgb(${Pe.r*255}, ${Pe.g*255}, ${Pe.b*255})`,ae.fillText(X.text,0,0),ae.restore()}),P.update()}else console.log("[Geo3DViewer] 动态纹理未准备好,正准备下一次绘制")},[W,P,k,V,ne]),C.jsx(lt,{...e,ref:le,vertex:xu,fragment:vu,options:{attributes:["position","color","normal"],uniforms:["world","worldViewProjection","alpha1","alpha2","alpha3","alpha4","alpha5","alpha6","oMin","oMax","tilingFactor","sideTilingFactor","mode","vColor1","vColor2","vColor3","vColor4","vColor5","vColor6","contourLineStartHeight","contourLineColor","contourLineWidth","contourLineStep","textureOverlayRotate","textureFlatRotate"],samplers:["textureSampler","textureOverlaySampler","textureSideSampler","textureSampler1","textureSideSampler1","textureSampler2","textureSideSampler2","textureSampler3","textureSideSampler3","textureSampler4","textureSideSampler4","textureSampler5","textureSideSampler5","textureSampler6","textureSideSampler6"],needAlphaBlending:!0,needAlphaTesting:!0,useClipPlane:!0},zOffset:E,zOffsetUnits:L,disableDepthWrite:ee})},_u=e=>C.jsx(lt,{...e,vertex:Gn,fragment:Zn,options:{needAlphaBlending:!0},zOffset:e.zOffset,zOffsetUnits:e.zOffsetUnits,disableDepthWrite:e.disableDepthWrite}),Pu=()=>C.jsx(lt,{name:"picking-material",vertex:Ac,fragment:Oc,backFaceCulling:!1,options:{attributes:["position","color","normal"],uniforms:["world","worldViewProjection","pickingColor","isPickable"]}}),Su=({name:e,scene:t})=>{const n=u.NodeMaterial.Parse(Nc,t);return n.name=e,n.backFaceCulling=!1,n.build(!1,!0,!1),n},Tu=({name:e,lineColor:t,lineWidth:n=.5})=>{const a=_e.useScene(),[i,o]=m.useState(null);return m.useEffect(()=>{if(a){const r=u.NodeMaterial.Parse(ql,a);return r.name=`${e}-material`,r.backFaceCulling=!1,r.build(!1,!0,!1),o(r),()=>{o(l=>(l==null||l.dispose(!0,!1),null))}}},[e,a]),m.useEffect(()=>{o(r=>r&&t?(r.getBlockByName("Color3").value=t,r.build(!1,!0,!1),r):null)},[t]),m.useEffect(()=>{o(r=>{if(r&&n!==void 0&&n!==null){let l=n;return n<1&&(l=1),r.getBlockByName("offset").value=1-l,r.build(!1,!0,!1),r}return null})},[n]),i},bu=(e,t)=>{const n=m.useRef(null);return m.useEffect(()=>{n.current&&(n.current.setVector4("typeAlpha1",new u.Vector4(e.typeAlpha.typeAlpha0===void 0?1:e.typeAlpha.typeAlpha0,e.typeAlpha.typeAlpha1,e.typeAlpha.typeAlpha2,e.typeAlpha.typeAlpha3)),n.current.setVector4("typeAlpha2",new u.Vector4(e.typeAlpha.typeAlpha4,e.typeAlpha.typeAlpha5,e.typeAlpha.typeAlpha6,e.typeAlpha.typeAlpha7)),n.current.setVector4("typeAlpha3",new u.Vector4(e.typeAlpha.typeAlpha8,e.typeAlpha.typeAlpha9,e.typeAlpha.typeAlpha10,e.typeAlpha.typeAlpha11)),n.current.setVector4("typeAlpha4",new u.Vector4(e.typeAlpha.typeAlpha12,e.typeAlpha.typeAlpha13,e.typeAlpha.typeAlpha14,e.typeAlpha.typeAlpha15)),n.current.setVector4("typeAlpha5",new u.Vector4(e.typeAlpha.typeAlpha16,e.typeAlpha.typeAlpha17,e.typeAlpha.typeAlpha18,e.typeAlpha.typeAlpha19)))},[e.typeAlpha]),m.useImperativeHandle(t,()=>n.current,[]),C.jsx(lt,{ref:n,name:e.name,backFaceCulling:!0,needDepthPrePass:!1,vertex:Cu,fragment:yu,transparencyMode:u.Material.MATERIAL_ALPHABLEND,alphaMode:u.Engine.ALPHA_COMBINE,options:{attributes:["position","color","uv","normal","world0","world1","world2","world3","instanceColor"],uniforms:["world","worldViewProjection","view","viewProjection","typeAlpha1","typeAlpha2","typeAlpha3","typeAlpha4","worldView","projection","previousWorld","vEyePosition"],defines:["#define INSTANCESCOLOR","#define INSTANCES"],needAlphaBlending:!0,needAlphaTesting:!0}})},Mn=e=>{const t=_e.useScene(),[n,a]=m.useState(null),i=m.useRef(null),{boundingBox:o,counterLine:r,scaleDepth:l=1,scalePlane:s=1,color:c,alpha:p=1,lines:f=[],text:d=[],surfaceCanvasOptions:x={textureIncludeSide:!0},disableDepthWrite:h,disableNormalShadow:T=!1}=e,{textureIncludeSide:P}=x;return m.useEffect(()=>{i.current&&(console.log("[Geo3DViewer] 设置材质 ",c,p),i.current.setColor3("vColor",c),i.current.setFloat("vAlpha",p),i.current.setFloat("textureIncludeSide",P==null?1:0))},[c,p,P]),m.useEffect(()=>{var _;const v=i.current;if(v&&o)if(r){const b=(_=r.startHeight)!=null?_:o.maximumWorld.y/l;return v.setFloat("contourLineStartHeight",b*l),v.setColor3("contourLineColor",r.color),v.setFloat("contourLineWidth",r.width),v.setFloat("contourLineStep",r.stepHeight*l),console.log("[Geo3DViewer] 等高线设置 ",r,o.centerWorld.y,b*l,b*l-16*r.stepHeight*l),()=>{v&&(v.setFloat("contourLineStartHeight",0),v.setColor3("contourLineColor",new u.Color3(0,0,0)),v.setFloat("contourLineWidth",0),v.setFloat("contourLineStep",0))}}else v.setFloat("contourLineStartHeight",0),v.setColor3("contourLineColor",new u.Color3(0,0,0)),v.setFloat("contourLineWidth",0),v.setFloat("contourLineStep",0),console.log("[Geo3DViewer] 等高线设置 关闭")},[o,r,l,s]),m.useEffect(()=>{const v=i.current;t&&o&&v&&a(_=>{let b=(o.maximum.x-o.minimum.x)/s,k=(o.maximum.z-o.minimum.z)/s,M=0;if(b<k){const N=b;b=k,k=N,M=1}const w=b/k;b*k>2048*2048&&(b=2048,k=2048/w);let S;return _?(_.scaleTo(b,k),_.update(),S=_):S=new u.DynamicTexture("dynamic-texture",{width:b,height:k},t,!1),S.clear(),S.update(),console.log("[Geo3DViewer] 设置动态划线 ",o,b,k,s),v.setVector3("oMin",o.minimum),v.setVector3("oMax",o.maximum),v.setFloat("textureOverlayRotate",M),v.setTexture("textureOverlaySampler",S),S})},[o,s,t]),m.useEffect(()=>{var v;if(n&&o&&(f.length>0||d.length>0))if((v=n.getScene())!=null&&v.getEngine()){n.clear();let _=(o.maximum.x-o.minimum.x)/s,b=(o.maximum.z-o.minimum.z)/s;if(_<b){const w=_;_=b,b=w}const k=_/b;_*b>2048*2048&&(_=2048,b=2048/k);const M=n.getContext();f.forEach(w=>{if(w.points.length<2)return;M.beginPath();const S=w.offset?w.offset:new u.Vector2(0,0),N=1-w.points[0].x+S.x,F=1-w.points[0].y+S.y;M.moveTo(N*_,F*b);for(let B=1;B<w.points.length;B++){const I=w.offset?w.offset:new u.Vector2(0,0),D=1-w.points[B].x+I.x,E=1-w.points[B].y+I.y;M.lineTo(D*_,E*b)}M.strokeStyle=`rgb(${w.color.r*255}, ${w.color.g*255}, ${w.color.b*255})`,_*b>2048*2048?M.lineWidth=w.width/k:M.lineWidth=w.width,M.stroke()}),d.forEach(w=>{var B,I;M.font=`${w.fontSize}px Arial`;const S=(B=w.color)!=null?B:u.Color3.White(),N=w.offset?w.offset:new u.Vector2(0,0),F=(I=w.rotation)!=null?I:0;if(M.save(),M.translate((1-w.position.x+N.x)*_,(1-w.position.y+N.y)*b),M.rotate(F),w.clearArea){const D=M.measureText(w.text);M.clearRect(-D.width*.15,.5*w.fontSize*(1-.3),D.width*1.3,-w.fontSize*1.3)}if(w.background){M.fillStyle=`rgba(${w.background.r*255}, ${w.background.g*255}, ${w.background.b*255})`;const D=M.measureText(w.text);M.fillRect(-D.width*.05,.5*(w.fontSize*(.5-.1)),D.width*1.1,-w.fontSize*1.1)}M.fillStyle=`rgb(${S.r*255}, ${S.g*255}, ${S.b*255})`,M.fillText(w.text,0,0),M.restore()}),n.update()}else console.log("[Geo3DViewer] 动态纹理未准备好,正准备下一次绘制")},[f,n,o,s,d]),m.useEffect(()=>{const v=i.current;if(v){if(T)return v.setFloat("disableNormalShadow",1),console.log("[Geo3DViewer] 禁用法向阴影 启用"),()=>{v&&v.setFloat("disableNormalShadow",0)};v.setFloat("disableNormalShadow",0),console.log("[Geo3DViewer] 禁用法向阴影 禁用")}},[T]),C.jsx(lt,{ref:i,name:e.name,backFaceCulling:e.backFaceCulling,needDepthPrePass:e.needDepthPrePass,vertex:wc,fragment:Ic,transparencyMode:e.transparencyMode,alphaMode:e.alphaMode,options:{attributes:["position","color","normal"],uniforms:["world","worldViewProjection","vAlpha","vColor","contourLineStartHeight","contourLineColor","contourLineWidth","contourLineStep","oMin","oMax","textureOverlayRotate","textureIncludeSide","disableNormalShadow"],samplers:["textureOverlaySampler"],needAlphaBlending:!0,needAlphaTesting:!0},zOffset:e.zOffset,zOffsetUnits:e.zOffsetUnits,disableDepthWrite:h})},ku=m.forwardRef(bu),ea=({name:e,url:t,offset:n=u.Vector3.Zero(),alpha:a=1,material:i,visible:o=!0,actions:r})=>{const l=_e.useScene(),s=m.useRef(null),c=m.useContext(Le),p=je({url:t,cacheType:Me.URL_PREFIX_MATCH}),f=He({url:i.texture,cacheType:Me.URL_PREFIX_MATCH}),d=He({url:i.sideTexture,cacheType:Me.URL_PREFIX_MATCH}),[x,h]=m.useState(u.Vector3.Zero()),[T,P]=m.useState();return m.useEffect(()=>{console.log("[Geo3DViewer] AttributeBody Loading: ",t)},[t]),m.useEffect(()=>{if(l&&s.current&&t&&p){u.Tags.EnableFor(s.current),u.Tags.AddTagsTo(s.current,"loading");const v=Vo.decode(new Uint8Array(p)),{points:_,indices:b,value:k,center:M}=v,w=new u.VertexData;w.positions=_,w.indices=b,w.colors=k;const S=[];u.VertexData.ComputeNormals(_,b,S),w.normals=S,M&&h(new u.Vector3(M.x,M.y,M.z));const N=s.current;N&&(w.applyToMesh(N),N.getScene().onAfterRenderObservable.addOnce(()=>{if(!N.isDisposed()){const B=N.getBoundingInfo();P(B.boundingBox)}})),u.Tags.RemoveTagsFrom(s.current,"loading")}},[t,l,p]),m.useEffect(()=>{s.current&&(s.current.metadata={pickable:r?{name:e,onLeftClick:r.onLeftClick,onRightClick:r.onRightClick,onMiddleClick:r.onMiddleClick,onHover:r.onHover,needWorldPosition:r.needWorldPosition,extra:r.extra}:null})},[r,e]),C.jsx(C.Fragment,{children:C.jsx("transformNode",{name:`transform-attribute-${e}`,position:x.add(n).multiplyByFloats(c&&c.scalePlane?c.scalePlane:1,c&&c.scaleDepth?c.scaleDepth:1,c&&c.scalePlane?c.scalePlane:1),scaling:new u.Vector3(c?c.scalePlane:1,c?c.scaleDepth:1,c?c.scalePlane:1),children:C.jsx("mesh",{name:`attributebody-${e}-mesh`,ref:s,setEnabled:o,useVertexColors:i.type===$e.COLOR_CODEC,children:i.type===$e.COLOR_CODEC&&i.colorCodec?C.jsx(Mt,{name:`attributebody-${e}-mat`,backFaceCulling:i.backFaceCulling===void 0?!0:i.backFaceCulling,needDepthPrePass:i.needDepthPrePass===void 0?!1:i.needDepthPrePass,alpha:i.alpha?i.alpha:a,transparencyMode:u.Material.MATERIAL_ALPHABLEND,alphaMode:u.Engine.ALPHA_COMBINE,colorCodec:i.colorCodec,boundingBox:T,lines:i.lines,text:i.text,scaleDepth:c?c.scaleDepth:1,scalePlane:c?c.scalePlane:1,disableDepthWrite:i.disableDepthWrite}):i.type===$e.ONE_COLOR&&i.color?C.jsx("standardMaterial",{name:`attributebody-${e}-overwrite-mat`,backFaceCulling:i.backFaceCulling===void 0?!0:i.backFaceCulling,needDepthPrePass:i.needDepthPrePass===void 0?!1:i.needDepthPrePass,transparencyMode:u.Material.MATERIAL_ALPHABLEND,specularColor:new u.Color3(0,0,0),ambientColor:new u.Color3(1,1,1),diffuseColor:new u.Color3(i.color.r,i.color.g,i.color.b),emissiveColor:u.Color3.Black(),alphaMode:u.Engine.ALPHA_COMBINE,alpha:i.alpha?i.alpha:a,zOffset:-3,disableDepthWrite:i.disableDepthWrite}):i.type===$e.TEXTURE&&f?C.jsx(Kt,{name:`attributebody-${e}-texture-mat`,backFaceCulling:i.backFaceCulling===void 0?!0:i.backFaceCulling,needDepthPrePass:i.needDepthPrePass===void 0?!1:i.needDepthPrePass,alpha:i.alpha?i.alpha:a,transparencyMode:u.Material.MATERIAL_ALPHABLEND,alphaMode:u.Engine.ALPHA_COMBINE,texture:f,sideTexture:d,mode:i.textureMode===void 0?qt.PLANE:i.textureMode,boundingBox:T,disableDepthWrite:i.disableDepthWrite}):C.jsx(C.Fragment,{})})})})},ta=({codec:e,showValue:t=!1,showTitle:n=!0,width:a=80,height:i=200})=>{const o=m.useContext(Vn);return C.jsx(C.Fragment,{children:C.jsxs("adtFullscreenUi",{name:`adt-color-codec-${e}`,children:[n?C.jsx("textBlock",{name:`color-codec-title-${e}`,text:e,color:"white",paddingBottomInPixels:i+40/200*i,paddingRightInPixels:30/80*a,textVerticalAlignment:nt.Control.VERTICAL_ALIGNMENT_CENTER,textHorizontalAlignment:nt.Control.HORIZONTAL_ALIGNMENT_RIGHT}):C.jsx(C.Fragment,{}),C.jsx("babylon-image",{name:`color-codec-${e}`,source:o!=null&&o.colorCodecsImage.current[e]?o.colorCodecsImage.current[e].blobUrl:"",height:`${i}px`,width:`${a}px`,verticalAlignment:nt.Control.VERTICAL_ALIGNMENT_CENTER,horizontalAlignment:nt.Control.HORIZONTAL_ALIGNMENT_RIGHT,paddingRightInPixels:20}),t&&(o!=null&&o.colorCodecsImage.current[e])?C.jsxs(C.Fragment,{children:[C.jsx("textBlock",{name:"color-codec-value-min",text:o.colorCodecsImage.current[e].min.toFixed(1).toString(),color:"white",paddingBottomInPixels:-1*i,paddingRightInPixels:90,textVerticalAlignment:nt.Control.VERTICAL_ALIGNMENT_CENTER,textHorizontalAlignment:nt.Control.HORIZONTAL_ALIGNMENT_RIGHT}),C.jsx("textBlock",{name:"color-codec-title-avg",text:((o.colorCodecsImage.current[e].max-o.colorCodecsImage.current[e].min)/2).toFixed(1).toString(),color:"white",paddingBottomInPixels:0,paddingRightInPixels:a+10,textVerticalAlignment:nt.Control.VERTICAL_ALIGNMENT_CENTER,textHorizontalAlignment:nt.Control.HORIZONTAL_ALIGNMENT_RIGHT}),C.jsx("textBlock",{name:"color-codec-title-max",text:o.colorCodecsImage.current[e].max.toFixed(1).toString(),color:"white",paddingBottomInPixels:i,paddingRightInPixels:a+10,textVerticalAlignment:nt.Control.VERTICAL_ALIGNMENT_CENTER,textHorizontalAlignment:nt.Control.HORIZONTAL_ALIGNMENT_RIGHT})]}):null]})})};function Xr(){return{name:"",colorId:0,points:[],indices:[],bottomIndices:[],value:[],vMin:0,vMax:0,border:[],side:[],sideIndices:[],sideValue:[],center:void 0}}const Wt={encode(e,t=se.Writer.create()){e.name!==""&&t.uint32(10).string(e.name),e.colorId!==0&&t.uint32(16).uint32(e.colorId),t.uint32(170).fork();for(const n of e.points)t.float(n);t.ldelim(),t.uint32(178).fork();for(const n of e.indices)t.uint32(n);t.ldelim(),t.uint32(186).fork();for(const n of e.bottomIndices)t.uint32(n);t.ldelim(),t.uint32(194).fork();for(const n of e.value)t.float(n);t.ldelim(),e.vMin!==0&&t.uint32(205).float(e.vMin),e.vMax!==0&&t.uint32(213).float(e.vMax),t.uint32(218).fork();for(const n of e.border)t.uint32(n);t.ldelim(),t.uint32(226).fork();for(const n of e.side)t.float(n);t.ldelim(),t.uint32(234).fork();for(const n of e.sideIndices)t.uint32(n);t.ldelim(),t.uint32(242).fork();for(const n of e.sideValue)t.float(n);return t.ldelim(),e.center!==void 0&&K.encode(e.center,t.uint32(250).fork()).ldelim(),t},decode(e,t){const n=e instanceof se.Reader?e:se.Reader.create(e);let a=t===void 0?n.len:n.pos+t;const i=Xr();for(;n.pos<a;){const o=n.uint32();switch(o>>>3){case 1:if(o!==10)break;i.name=n.string();continue;case 2:if(o!==16)break;i.colorId=n.uint32();continue;case 21:if(o===173){i.points.push(n.float());continue}if(o===170){const r=n.uint32()+n.pos;for(;n.pos<r;)i.points.push(n.float());continue}break;case 22:if(o===176){i.indices.push(n.uint32());continue}if(o===178){const r=n.uint32()+n.pos;for(;n.pos<r;)i.indices.push(n.uint32());continue}break;case 23:if(o===184){i.bottomIndices.push(n.uint32());continue}if(o===186){const r=n.uint32()+n.pos;for(;n.pos<r;)i.bottomIndices.push(n.uint32());continue}break;case 24:if(o===197){i.value.push(n.float());continue}if(o===194){const r=n.uint32()+n.pos;for(;n.pos<r;)i.value.push(n.float());continue}break;case 25:if(o!==205)break;i.vMin=n.float();continue;case 26:if(o!==213)break;i.vMax=n.float();continue;case 27:if(o===216){i.border.push(n.uint32());continue}if(o===218){const r=n.uint32()+n.pos;for(;n.pos<r;)i.border.push(n.uint32());continue}break;case 28:if(o===229){i.side.push(n.float());continue}if(o===226){const r=n.uint32()+n.pos;for(;n.pos<r;)i.side.push(n.float());continue}break;case 29:if(o===232){i.sideIndices.push(n.uint32());continue}if(o===234){const r=n.uint32()+n.pos;for(;n.pos<r;)i.sideIndices.push(n.uint32());continue}break;case 30:if(o===245){i.sideValue.push(n.float());continue}if(o===242){const r=n.uint32()+n.pos;for(;n.pos<r;)i.sideValue.push(n.float());continue}break;case 31:if(o!==250)break;i.center=K.decode(n,n.uint32());continue}if((o&7)===4||o===0)break;n.skipType(o&7)}return i},fromJSON(e){return{name:_n(e.name)?globalThis.String(e.name):"",colorId:_n(e.colorId)?globalThis.Number(e.colorId):0,points:globalThis.Array.isArray(e==null?void 0:e.points)?e.points.map(t=>globalThis.Number(t)):[],indices:globalThis.Array.isArray(e==null?void 0:e.indices)?e.indices.map(t=>globalThis.Number(t)):[],bottomIndices:globalThis.Array.isArray(e==null?void 0:e.bottomIndices)?e.bottomIndices.map(t=>globalThis.Number(t)):[],value:globalThis.Array.isArray(e==null?void 0:e.value)?e.value.map(t=>globalThis.Number(t)):[],vMin:_n(e.vMin)?globalThis.Number(e.vMin):0,vMax:_n(e.vMax)?globalThis.Number(e.vMax):0,border:globalThis.Array.isArray(e==null?void 0:e.border)?e.border.map(t=>globalThis.Number(t)):[],side:globalThis.Array.isArray(e==null?void 0:e.side)?e.side.map(t=>globalThis.Number(t)):[],sideIndices:globalThis.Array.isArray(e==null?void 0:e.sideIndices)?e.sideIndices.map(t=>globalThis.Number(t)):[],sideValue:globalThis.Array.isArray(e==null?void 0:e.sideValue)?e.sideValue.map(t=>globalThis.Number(t)):[],center:_n(e.center)?K.fromJSON(e.center):void 0}},toJSON(e){var n,a,i,o,r,l,s,c;const t={};return e.name!==""&&(t.name=e.name),e.colorId!==0&&(t.colorId=Math.round(e.colorId)),(n=e.points)!=null&&n.length&&(t.points=e.points),(a=e.indices)!=null&&a.length&&(t.indices=e.indices.map(p=>Math.round(p))),(i=e.bottomIndices)!=null&&i.length&&(t.bottomIndices=e.bottomIndices.map(p=>Math.round(p))),(o=e.value)!=null&&o.length&&(t.value=e.value),e.vMin!==0&&(t.vMin=e.vMin),e.vMax!==0&&(t.vMax=e.vMax),(r=e.border)!=null&&r.length&&(t.border=e.border.map(p=>Math.round(p))),(l=e.side)!=null&&l.length&&(t.side=e.side),(s=e.sideIndices)!=null&&s.length&&(t.sideIndices=e.sideIndices.map(p=>Math.round(p))),(c=e.sideValue)!=null&&c.length&&(t.sideValue=e.sideValue),e.center!==void 0&&(t.center=K.toJSON(e.center)),t},create(e){return Wt.fromPartial(e!=null?e:{})},fromPartial(e){var n,a,i,o,r,l,s,c,p,f,d,x;const t=Xr();return t.name=(n=e.name)!=null?n:"",t.colorId=(a=e.colorId)!=null?a:0,t.points=((i=e.points)==null?void 0:i.map(h=>h))||[],t.indices=((o=e.indices)==null?void 0:o.map(h=>h))||[],t.bottomIndices=((r=e.bottomIndices)==null?void 0:r.map(h=>h))||[],t.value=((l=e.value)==null?void 0:l.map(h=>h))||[],t.vMin=(s=e.vMin)!=null?s:0,t.vMax=(c=e.vMax)!=null?c:0,t.border=((p=e.border)==null?void 0:p.map(h=>h))||[],t.side=((f=e.side)==null?void 0:f.map(h=>h))||[],t.sideIndices=((d=e.sideIndices)==null?void 0:d.map(h=>h))||[],t.sideValue=((x=e.sideValue)==null?void 0:x.map(h=>h))||[],t.center=e.center!==void 0&&e.center!==null?K.fromPartial(e.center):void 0,t}};function _n(e){return e!=null}const Eu=64,Nu=32,na='"Noto Sans SC", sans-serif';function Iu(e,t){if(typeof document=="undefined")return{textureWidth:256,textureHeight:128};const a=document.createElement("canvas").getContext("2d");if(!a)return{textureWidth:256,textureHeight:128};const i=Math.max(8,Math.round(t*.35)),o=Math.max(6,Math.round(t*.25));a.font=`600 ${t}px ${na}`;const r=Math.ceil(a.measureText(e||" ").width),l=Math.ceil(t*1.6);return{textureWidth:Math.max(Eu,qr(r+i*2)),textureHeight:Math.max(Nu,qr(l+o*2))}}function qr(e){let t=1;for(;t<e;)t<<=1;return t}function wu(e){if(typeof e=="string")return e;const t=Math.round(e.r*255),n=Math.round(e.g*255),a=Math.round(e.b*255);return`rgba(${t}, ${n}, ${a}, ${e.a})`}const Je=e=>{const t=_e.useScene(),n=m.useRef(null),a=m.useRef(null),{name:i,text:o,fontSize:r,color:l,billboardMode:s=u.Mesh.BILLBOARDMODE_ALL,lowPriority:c=!0}=e;return m.useEffect(()=>{if(!t)return;const p=i!=null?i:"gui-text-no-name",{textureWidth:f,textureHeight:d}=Iu(o,r),x=u.MeshBuilder.CreatePlane(p,{width:1,height:1},t);x.parent=n.current,x.isPickable=!1,x.billboardMode=s,x.alwaysSelectAsActiveMesh=!0;const h=Math.max(r,1);x.scaling.x=h*(f/d),x.scaling.y=h;const T=nt.AdvancedDynamicTexture.CreateForMesh(x,f,d,!1,!1);T.rootContainer.isPointerBlocker=!1;const P=new nt.TextBlock(`${p}-text`,o);P.color=wu(l),P.fontFamily=na,P.fontWeight="600",P.fontSize=`${r}px`,P.resizeToFit=!1,P.textWrapping=!1,P.textHorizontalAlignment=nt.Control.HORIZONTAL_ALIGNMENT_CENTER,P.textVerticalAlignment=nt.Control.VERTICAL_ALIGNMENT_CENTER,T.addControl(P);const v=x.material;return v&&v instanceof u.StandardMaterial&&(v.backFaceCulling=!1,v.disableLighting=!0,v.forceDepthWrite=!1,v.needDepthPrePass=!1,v.transparencyMode=u.Material.MATERIAL_ALPHABLEND,v.zOffset=-2),x.renderingGroupId=2,a.current={plane:x,texture:T},()=>{var _,b;(_=a.current)==null||_.texture.dispose(),(b=a.current)==null||b.plane.dispose(),a.current=null}},[t,i,o,r,l,s,c]),m.useEffect(()=>{a.current&&(a.current.plane.parent=n.current)}),C.jsx("transformNode",{name:i!=null?i:"no-name-text",ref:n})},Xn=({urlTopLayer:e,urlBottomLayer:t,showLayerLabel:n=!1,labelStyle:a,position:i=u.Vector3.Zero(),visible:o=!0,showBottomLayer:r=!1,actions:l,material:s={type:$e.COLOR_ID,alpha:1}})=>{var E,L;const c=m.useRef(null),p=m.useRef(null),[f,d]=m.useState(""),[x,h]=m.useState(null),T=m.useContext(Le),P=m.useContext(Lt),[v,_]=m.useState(u.Color3.White()),b=je({url:e,cacheType:Me.URL_PREFIX_MATCH}),k=je({url:t,cacheType:Me.URL_PREFIX_MATCH}),M=He({url:s==null?void 0:s.texture,cacheType:Me.URL_PREFIX_MATCH}),w=He({url:s==null?void 0:s.sideTexture,cacheType:Me.URL_PREFIX_MATCH});m.useEffect(()=>{console.log("[Geo3DViewer] FormationFace Loading: ",e,t)},[e,t]);const[S,N]=m.useState(),[F,B]=m.useState(u.Vector3.Zero()),[I,D]=m.useState(void 0);return m.useEffect(()=>{if(b){const y=c.current;y&&(u.Tags.EnableFor(y),u.Tags.AddTagsTo(y,"loading"));let A=[],V=[],$=[];const W=Wt.decode(new Uint8Array(b));{const{name:G,points:le,indices:re,colorId:oe,value:Y,center:ce}=W;A=le,V=re,$=Y,h(oe),d(G),ce&&B(new u.Vector3(ce.x,ce.y,ce.z))}const ne=new u.VertexData;ne.positions=A,ne.indices=V,ne.colors=$;const ee=[];if(u.VertexData.ComputeNormals(A,V,ee),ne.normals=ee,y){ne.applyToMesh(y);const G=y.getBoundingInfo();N(G.boundingBox.center.add(new u.Vector3(G.boundingBox.extendSize.x,0,0))),r||y.getScene().onAfterRenderObservable.addOnce(()=>{if(!y.isDisposed()){const re=y.getBoundingInfo();D(re.boundingBox)}})}return y&&u.Tags.RemoveTagsFrom(y,"loading"),()=>{y&&new u.VertexData().applyToMesh(y)}}},[b,r]),m.useEffect(()=>{if(b&&k){const y=p.current;y&&(u.Tags.EnableFor(y),u.Tags.AddTagsTo(y,"loading"));let A=[],V=[],$=[],W=[],ne=[],ee=[],G=[],le=[];{const ge=Wt.decode(new Uint8Array(b)),{points:H,indices:Q,border:Ee,value:ke}=ge;A=H,V=Q,W=Ee,$=ke}{const ge=Wt.decode(new Uint8Array(k)),{points:H,bottomIndices:Q,border:Ee,value:ke}=ge;ne=H,ee=Q,G=Ee,le=ke}const re=new u.VertexData,oe=new Float32Array(A.length+ne.length);let Y=V.length+ee.length;Y=Y+((W.length<1?1:W.length)-1)*6;const ce=new Int32Array(Y),ae=new Float32Array($.length+le.length);oe.set(A),ce.set(V),ae.set($),oe.set(ne,A.length),ce.set(ee,V.length),ae.set(le,$.length);const X=[];for(let ge=0;ge<W.length-1;ge++)X.push(W[ge+1]),X.push(W[ge]),X.push(G[ge]+A.length/3),X.push(G[ge+1]+A.length/3),X.push(G[ge]+A.length/3),X.push(W[ge+1]);ce.set(X,V.length+ee.length),re.positions=oe,re.indices=ce,re.colors=ae;const Pe=[];return u.VertexData.ComputeNormals(oe,ce,Pe),re.normals=Pe,y&&(re.applyToMesh(y),r&&y.getScene().onAfterRenderObservable.addOnce(()=>{if(!y.isDisposed()){const H=y.getBoundingInfo();D(H.boundingBox)}})),y&&u.Tags.RemoveTagsFrom(y,"loading"),()=>{y&&new u.VertexData().applyToMesh(y)}}},[k,b,r]),m.useEffect(()=>{var y;_(s.type===$e.ONE_COLOR?(y=s==null?void 0:s.color)!=null?y:u.Color3.Random():x&&P.colorIDs[x]?new u.Color3(P.colorIDs[x].r,P.colorIDs[x].g,P.colorIDs[x].b):u.Color3.Random())},[P.colorIDs,x,s==null?void 0:s.color,s.type]),m.useEffect(()=>{c.current&&(c.current.metadata={pickable:l?{name:f,onLeftClick:l.onLeftClick,onRightClick:l.onRightClick,onMiddleClick:l.onMiddleClick,onHover:l.onHover,needWorldPosition:l.needWorldPosition,extra:l.extra}:null}),p.current&&(p.current.metadata={pickable:l?{name:f,onLeftClick:l.onLeftClick,onRightClick:l.onRightClick,onMiddleClick:l.onMiddleClick,onHover:l.onHover,needWorldPosition:l.needWorldPosition,extra:l.extra}:null})},[l,f]),C.jsx(C.Fragment,{children:C.jsxs("transformNode",{name:`transform-formation-${f}-${e}`,position:F.add(i).multiplyByFloats(T&&T.scalePlane?T.scalePlane:1,T&&T.scaleDepth?T.scaleDepth:1,T&&T.scalePlane?T.scalePlane:1),scaling:new u.Vector3(T?T.scalePlane:1,T?T.scaleDepth:1,T?T.scalePlane:1),setEnabled:o,children:[C.jsx("mesh",{name:`formation-${f}-mesh-${e}`,ref:c,setEnabled:!r,useVertexColors:s.type===$e.COLOR_CODEC,alwaysSelectAsActiveMesh:!0,children:s.type===$e.TEXTURE?M?C.jsx(Kt,{name:`formation-${f}-mat-${e}`,backFaceCulling:s.backFaceCulling===void 0?!0:s.backFaceCulling,needDepthPrePass:s.needDepthPrePass===void 0?!0:s.needDepthPrePass,transparencyMode:u.Material.MATERIAL_ALPHABLEND,alphaMode:u.Engine.ALPHA_COMBINE,alpha:s.alpha,texture:M,sideTexture:w,tilingFactor:s.tilingFactor,sideTilingFactor:(E=s==null?void 0:s.sideTilingFactor)!=null?E:s==null?void 0:s.tilingFactor,mode:s.textureMode===void 0?qt.PLANE:s.textureMode,boundingBox:I,lines:s.lines,text:s.text,scaleDepth:T?T.scaleDepth:1,scalePlane:T?T.scalePlane:1,disableDepthWrite:s.disableDepthWrite}):C.jsx(C.Fragment,{}):s.type===$e.COLOR_CODEC?s.colorCodec?C.jsx(Mt,{name:`formation-${f}-mat-${e}`,backFaceCulling:s.backFaceCulling===void 0?!0:s.backFaceCulling,needDepthPrePass:s.needDepthPrePass===void 0?!0:s.needDepthPrePass,alpha:s.alpha,transparencyMode:u.Material.MATERIAL_ALPHABLEND,alphaMode:u.Engine.ALPHA_COMBINE,colorCodec:s.colorCodec,boundingBox:I,lines:s.lines,text:s.text,scaleDepth:T?T.scaleDepth:1,scalePlane:T?T.scalePlane:1,disableDepthWrite:s.disableDepthWrite}):C.jsx(C.Fragment,{}):s.type===$e.COLOR_ID?C.jsx(Mn,{name:`formation-${f}-vol-mat-${e}`,backFaceCulling:s.backFaceCulling===void 0?!0:s.backFaceCulling,needDepthPrePass:s.needDepthPrePass===void 0?!0:s.needDepthPrePass,surfaceCanvasOptions:s.surfaceCanvasOptions,color:v,alphaMode:u.Engine.ALPHA_COMBINE,alpha:s.alpha,boundingBox:I,transparencyMode:u.Material.MATERIAL_ALPHABLEND,lines:s.lines,text:s.text,scaleDepth:T?T.scaleDepth:1,scalePlane:T?T.scalePlane:1,disableDepthWrite:s.disableDepthWrite,disableNormalShadow:s.disableNormalShadow}):C.jsx(Mn,{name:`formation-${f}-vol-mat-${e}`,backFaceCulling:s.backFaceCulling===void 0?!0:s.backFaceCulling,needDepthPrePass:s.needDepthPrePass===void 0?!0:s.needDepthPrePass,color:v,surfaceCanvasOptions:s.surfaceCanvasOptions,alphaMode:u.Engine.ALPHA_COMBINE,alpha:s.alpha,boundingBox:I,transparencyMode:u.Material.MATERIAL_ALPHABLEND,lines:s.lines,text:s.text,scaleDepth:T?T.scaleDepth:1,scalePlane:T?T.scalePlane:1,disableDepthWrite:s.disableDepthWrite,disableNormalShadow:s.disableNormalShadow})}),C.jsx("mesh",{name:`formation-${f}-vol-${e}`,ref:p,setEnabled:r,useVertexColors:s.type===$e.COLOR_CODEC,alwaysSelectAsActiveMesh:!0,children:s.type===$e.TEXTURE?M?C.jsx(Kt,{name:`formation-${f}-vol-mat-${e}`,backFaceCulling:s.backFaceCulling===void 0?!0:s.backFaceCulling,needDepthPrePass:s.needDepthPrePass===void 0?!0:s.needDepthPrePass,transparencyMode:u.Material.MATERIAL_ALPHABLEND,alphaMode:u.Engine.ALPHA_COMBINE,alpha:s.alpha,sideTexture:w,texture:M,tilingFactor:s.tilingFactor,sideTilingFactor:(L=s==null?void 0:s.sideTilingFactor)!=null?L:s==null?void 0:s.tilingFactor,mode:s.textureMode===void 0?qt.PLANE:s.textureMode,boundingBox:I,lines:s.lines,text:s.text,scaleDepth:T?T.scaleDepth:1,scalePlane:T?T.scalePlane:1,disableDepthWrite:s.disableDepthWrite}):C.jsx(C.Fragment,{}):s.type===$e.COLOR_CODEC?s.colorCodec?C.jsx(Mt,{name:`formation-${f}-vol-mat-${e}`,backFaceCulling:s.backFaceCulling===void 0?!0:s.backFaceCulling,needDepthPrePass:s.needDepthPrePass===void 0?!0:s.needDepthPrePass,alpha:s.alpha,transparencyMode:u.Material.MATERIAL_ALPHABLEND,alphaMode:u.Engine.ALPHA_COMBINE,colorCodec:s.colorCodec,boundingBox:I,lines:s.lines,text:s.text,scaleDepth:T?T.scaleDepth:1,scalePlane:T?T.scalePlane:1,disableDepthWrite:s.disableDepthWrite}):C.jsx(C.Fragment,{}):s.type===$e.COLOR_ID?C.jsx(Mn,{name:`formation-${f}-vol-mat-${e}`,backFaceCulling:s.backFaceCulling===void 0?!0:s.backFaceCulling,needDepthPrePass:s.needDepthPrePass===void 0?!0:s.needDepthPrePass,surfaceCanvasOptions:s.surfaceCanvasOptions,color:v,alphaMode:u.Engine.ALPHA_COMBINE,alpha:s.alpha,transparencyMode:u.Material.MATERIAL_ALPHABLEND,boundingBox:I,lines:s.lines,text:s.text,scaleDepth:T?T.scaleDepth:1,scalePlane:T?T.scalePlane:1,disableDepthWrite:s.disableDepthWrite,disableNormalShadow:s.disableNormalShadow}):C.jsx(Mn,{name:`formation-${f}-vol-mat-${e}`,backFaceCulling:s.backFaceCulling===void 0?!0:s.backFaceCulling,needDepthPrePass:s.needDepthPrePass===void 0?!0:s.needDepthPrePass,surfaceCanvasOptions:s.surfaceCanvasOptions,color:v,alphaMode:u.Engine.ALPHA_COMBINE,alpha:s.alpha,transparencyMode:u.Material.MATERIAL_ALPHABLEND,boundingBox:I,lines:s.lines,text:s.text,scaleDepth:T?T.scaleDepth:1,scalePlane:T?T.scalePlane:1,disableDepthWrite:s.disableDepthWrite,disableNormalShadow:s.disableNormalShadow})}),f&&S&&C.jsx("transformNode",{name:`${f}-title-${e}`,position:S.add(a!=null&&a.offset?a.offset.multiplyByFloats(T!=null&&T.scalePlane?T==null?void 0:T.scalePlane:1,1,T!=null&&T.scalePlane?T==null?void 0:T.scalePlane:1):u.Vector3.Zero()),scaling:ct(T).multiply(new u.Vector3(3,3,3)),setEnabled:n,children:C.jsx(Je,{text:f,fontSize:a!=null&&a.fontSize?a.fontSize:40,color:a!=null&&a.color?a.color:"white"})})]})})},qn=({url:e,showLayerLabel:t=!1,labelStyle:n,position:a=u.Vector3.Zero(),visible:i=!0,showBottomLayer:o=!1,actions:r,material:l={type:$e.COLOR_ID,counterLine:void 0,alpha:1}})=>{var I,D;const s=m.useRef(null),c=m.useRef(null),[p,f]=m.useState(""),[d,x]=m.useState(null),[h,T]=m.useState(u.Color3.White()),P=m.useContext(Le),v=m.useContext(Lt),[_,b]=m.useState(u.Vector3.Zero()),[k,M]=m.useState(),w=je({url:e,cacheType:Me.URL_PREFIX_MATCH}),S=He({url:l==null?void 0:l.texture,cacheType:Me.URL_PREFIX_MATCH}),N=He({url:l==null?void 0:l.sideTexture,cacheType:Me.URL_PREFIX_MATCH}),[F,B]=m.useState(void 0);return m.useEffect(()=>{console.log("[Geo3DViewer] FormationVolume Loading: ",e)},[e]),m.useEffect(()=>{if(w){const E=s.current,L=c.current;u.Tags.EnableFor(E),u.Tags.AddTagsTo(E,"loading"),u.Tags.EnableFor(c),u.Tags.AddTagsTo(c,"loading");let y=[],A=[],V=[],$=[];const W=Wt.decode(new Uint8Array(w)),{name:ne,points:ee,indices:G,colorId:le,side:re,sideIndices:oe,center:Y,value:ce,sideValue:ae}=W;Y&&b(new u.Vector3(Y.x,Y.y,Y.z)),y=ee,A=G,V=re,$=oe,x(le),f(ne);const X=new u.VertexData,Pe=new u.VertexData,ge=new Float32Array(y.length+V.length),H=new Int32Array(A.length+$.length),Q=new Float32Array(ce.length+ae.length);X.positions=y,X.indices=A,X.colors=ce;const Ee=[];u.VertexData.ComputeNormals(ee,G,Ee),X.normals=Ee,ge.set(y),H.set(A),Q.set(ce),ge.set(V,y.length),H.set($,A.length),Q.set(ae,ce.length),Pe.positions=ge,Pe.indices=H,Pe.colors=Q;const ke=[];if(u.VertexData.ComputeNormals(ge,H,ke),Pe.normals=ke,E){X.applyToMesh(E);const te=E.getBoundingInfo();M(te.boundingBox.center.add(new u.Vector3(te.boundingBox.extendSize.x,0,0))),o||E.getScene().onAfterRenderObservable.addOnce(()=>{if(!E.isDisposed()){const ue=E.getBoundingInfo();B(ue.boundingBox)}})}return L&&(Pe.applyToMesh(L),o&&L.getScene().onAfterRenderObservable.addOnce(()=>{if(!L.isDisposed()){const me=L.getBoundingInfo();B(me.boundingBox)}})),u.Tags.RemoveTagsFrom(E,"loading"),u.Tags.RemoveTagsFrom(c,"loading"),()=>{E&&new u.VertexData().applyToMesh(E),L&&new u.VertexData().applyToMesh(L)}}},[w,o]),m.useEffect(()=>{var E;T(l.type===$e.ONE_COLOR?(E=l==null?void 0:l.color)!=null?E:u.Color3.Random():d&&v.colorIDs[d]?new u.Color3(v.colorIDs[d].r,v.colorIDs[d].g,v.colorIDs[d].b):u.Color3.Random())},[v.colorIDs,d,l==null?void 0:l.color,l.type]),m.useEffect(()=>{s.current&&(s.current.metadata={pickable:r?{name:p,onLeftClick:r.onLeftClick,onRightClick:r.onRightClick,onMiddleClick:r.onMiddleClick,onHover:r.onHover,needWorldPosition:r.needWorldPosition,extra:r.extra}:null}),c.current&&(c.current.metadata={pickable:r?{name:p,onLeftClick:r.onLeftClick,onRightClick:r.onRightClick,onMiddleClick:r.onMiddleClick,onHover:r.onHover,needWorldPosition:r.needWorldPosition,extra:r.extra}:null})},[r,p]),C.jsx(C.Fragment,{children:C.jsxs("transformNode",{name:`transform-formation-${p}-${e}`,position:_.add(a).multiplyByFloats(P&&P.scalePlane?P.scalePlane:1,P&&P.scaleDepth?P.scaleDepth:1,P&&P.scalePlane?P.scalePlane:1),scaling:new u.Vector3(P?P.scalePlane:1,P?P.scaleDepth:1,P?P.scalePlane:1),setEnabled:i,children:[C.jsx("mesh",{name:`formation-${p}-mesh-${e}`,ref:s,setEnabled:!o,useVertexColors:l.type===$e.COLOR_CODEC,children:l.type===$e.TEXTURE?S?C.jsx(Kt,{name:`formation-${p}-mat-${e}`,backFaceCulling:l.backFaceCulling===void 0?!0:l.backFaceCulling,needDepthPrePass:l.needDepthPrePass===void 0?!0:l.needDepthPrePass,transparencyMode:u.Material.MATERIAL_ALPHABLEND,alphaMode:u.Engine.ALPHA_COMBINE,alpha:l.alpha,flatModeRotate:l.flatModeRotate,sideTexture:N,texture:S,tilingFactor:l.tilingFactor,sideTilingFactor:(I=l==null?void 0:l.sideTilingFactor)!=null?I:l==null?void 0:l.tilingFactor,mode:l.textureMode===void 0?qt.PLANE:l.textureMode,counterLine:l.counterLine,boundingBox:F,lines:l.lines,text:l.text,scaleDepth:P?P.scaleDepth:1,scalePlane:P?P.scalePlane:1,disableDepthWrite:l.disableDepthWrite}):C.jsx(C.Fragment,{}):l.type===$e.COLOR_CODEC?l.colorCodec?C.jsx(Mt,{name:`formation-${p}-mat-${e}`,backFaceCulling:l.backFaceCulling===void 0?!0:l.backFaceCulling,needDepthPrePass:l.needDepthPrePass===void 0?!0:l.needDepthPrePass,alpha:l.alpha,transparencyMode:u.Material.MATERIAL_ALPHABLEND,alphaMode:u.Engine.ALPHA_COMBINE,colorCodec:l.colorCodec,counterLine:l.counterLine,boundingBox:F,lines:l.lines,text:l.text,scaleDepth:P?P.scaleDepth:1,scalePlane:P?P.scalePlane:1,disableDepthWrite:l.disableDepthWrite}):C.jsx(C.Fragment,{}):l.type===$e.COLOR_ID?C.jsx(An,{name:`formation-${p}-vol-mat-${e}`,backFaceCulling:l.backFaceCulling===void 0?!0:l.backFaceCulling,needDepthPrePass:l.needDepthPrePass===void 0?!0:l.needDepthPrePass,color:h,alphaMode:u.Engine.ALPHA_COMBINE,alpha:l.alpha,lightPosition:l.lightPosition,intensity:l.intensity,surfaceCanvasOptions:l.surfaceCanvasOptions,transparencyMode:u.Material.MATERIAL_ALPHABLEND,boundingBox:F,lines:l.lines,text:l.text,zOffset:l.zOffset,zOffsetUnits:l.zOffsetUnits,contrast:l.contrast,sideIntensity:l.sideIntensity,cullFace:l.cullFace,scaleDepth:P?P.scaleDepth:1,scalePlane:P?P.scalePlane:1,disableDepthWrite:l.disableDepthWrite}):C.jsx(An,{name:`formation-${p}-vol-mat-${e}`,backFaceCulling:l.backFaceCulling===void 0?!0:l.backFaceCulling,needDepthPrePass:l.needDepthPrePass===void 0?!0:l.needDepthPrePass,color:h,alphaMode:u.Engine.ALPHA_COMBINE,surfaceCanvasOptions:l.surfaceCanvasOptions,alpha:l.alpha,lightPosition:l.lightPosition,intensity:l.intensity,transparencyMode:u.Material.MATERIAL_ALPHABLEND,boundingBox:F,lines:l.lines,text:l.text,zOffset:l.zOffset,zOffsetUnits:l.zOffsetUnits,contrast:l.contrast,sideIntensity:l.sideIntensity,cullFace:l.cullFace,scaleDepth:P?P.scaleDepth:1,scalePlane:P?P.scalePlane:1,disableDepthWrite:l.disableDepthWrite})}),C.jsx("mesh",{name:`formation-${p}-vol-${e}`,ref:c,setEnabled:o,useVertexColors:l.type===$e.COLOR_CODEC,children:l.type===$e.TEXTURE?S?C.jsx(Kt,{name:`formation-${p}-vol-mat-${e}`,backFaceCulling:l.backFaceCulling===void 0?!0:l.backFaceCulling,needDepthPrePass:l.needDepthPrePass===void 0?!0:l.needDepthPrePass,transparencyMode:u.Material.MATERIAL_ALPHABLEND,alphaMode:u.Engine.ALPHA_COMBINE,alpha:l.alpha,sideTexture:N,texture:S,tilingFactor:l.tilingFactor,sideTilingFactor:(D=l==null?void 0:l.sideTilingFactor)!=null?D:l==null?void 0:l.tilingFactor,mode:l.textureMode===void 0?qt.PLANE:l.textureMode,flatModeRotate:l.flatModeRotate,counterLine:l.counterLine,boundingBox:F,lines:l.lines,text:l.text,scaleDepth:P?P.scaleDepth:1,scalePlane:P?P.scalePlane:1,disableDepthWrite:l.disableDepthWrite}):C.jsx(C.Fragment,{}):l.type===$e.COLOR_CODEC?l.colorCodec?C.jsx(Mt,{name:`formation-${p}-vol-mat-${e}`,backFaceCulling:l.backFaceCulling===void 0?!0:l.backFaceCulling,needDepthPrePass:l.needDepthPrePass===void 0?!0:l.needDepthPrePass,alpha:l.alpha,transparencyMode:u.Material.MATERIAL_ALPHABLEND,alphaMode:u.Engine.ALPHA_COMBINE,colorCodec:l.colorCodec,counterLine:l.counterLine,boundingBox:F,lines:l.lines,text:l.text,scaleDepth:P?P.scaleDepth:1,scalePlane:P?P.scalePlane:1,disableDepthWrite:l.disableDepthWrite}):C.jsx(C.Fragment,{}):l.type===$e.COLOR_ID?C.jsx(An,{name:`formation-${p}-vol-mat-${e}`,backFaceCulling:l.backFaceCulling===void 0?!0:l.backFaceCulling,needDepthPrePass:l.needDepthPrePass===void 0?!0:l.needDepthPrePass,color:h,surfaceCanvasOptions:l.surfaceCanvasOptions,alphaMode:u.Engine.ALPHA_COMBINE,alpha:l.alpha,lightPosition:l.lightPosition,intensity:l.intensity,transparencyMode:u.Material.MATERIAL_ALPHABLEND,boundingBox:F,lines:l.lines,text:l.text,zOffset:l.zOffset,zOffsetUnits:l.zOffsetUnits,contrast:l.contrast,sideIntensity:l.sideIntensity,cullFace:l.cullFace,scaleDepth:P?P.scaleDepth:1,scalePlane:P?P.scalePlane:1,disableDepthWrite:l.disableDepthWrite}):C.jsx(An,{name:`formation-${p}-vol-mat-${e}`,backFaceCulling:l.backFaceCulling===void 0?!0:l.backFaceCulling,needDepthPrePass:l.needDepthPrePass===void 0?!0:l.needDepthPrePass,color:h,surfaceCanvasOptions:l.surfaceCanvasOptions,alphaMode:u.Engine.ALPHA_COMBINE,alpha:l.alpha,lightPosition:l.lightPosition,intensity:l.intensity,transparencyMode:u.Material.MATERIAL_ALPHABLEND,boundingBox:F,lines:l.lines,text:l.text,zOffset:l.zOffset,zOffsetUnits:l.zOffsetUnits,contrast:l.contrast,sideIntensity:l.sideIntensity,cullFace:l.cullFace,scaleDepth:P?P.scaleDepth:1,scalePlane:P?P.scalePlane:1,disableDepthWrite:l.disableDepthWrite})}),p&&k&&C.jsx("transformNode",{name:`${p}-title-${e}`,position:k.add(n!=null&&n.offset?n.offset.multiplyByFloats(P!=null&&P.scalePlane?P==null?void 0:P.scalePlane:1,1,P!=null&&P.scalePlane?P==null?void 0:P.scalePlane:1):u.Vector3.Zero()),scaling:ct(P).multiply(new u.Vector3(3,3,3)),setEnabled:t,children:C.jsx(Je,{text:p,fontSize:n!=null&&n.fontSize?n.fontSize:40,color:n!=null&&n.color?n.color:"white"})})]})})};var $o=(e=>(e[e.FACE=0]="FACE",e[e.VOLUME=1]="VOLUME",e[e.UNRECOGNIZED=-1]="UNRECOGNIZED",e))($o||{});function Ou(e){switch(e){case 0:case"FACE":return 0;case 1:case"VOLUME":return 1;case-1:case"UNRECOGNIZED":default:return-1}}function Au(e){switch(e){case 0:return"FACE";case 1:return"VOLUME";case-1:default:return"UNRECOGNIZED"}}function Kr(){return{name:"",formations:[],mode:0,effectMeshs:[]}}const kn={encode(e,t=se.Writer.create()){e.name!==""&&t.uint32(10).string(e.name);for(const n of e.formations)cn.encode(n,t.uint32(34).fork()).ldelim();e.mode!==0&&t.uint32(40).int32(e.mode);for(const n of e.effectMeshs)We.encode(n,t.uint32(50).fork()).ldelim();return t},decode(e,t){const n=e instanceof se.Reader?e:se.Reader.create(e);let a=t===void 0?n.len:n.pos+t;const i=Kr();for(;n.pos<a;){const o=n.uint32();switch(o>>>3){case 1:if(o!==10)break;i.name=n.string();continue;case 4:if(o!==34)break;i.formations.push(cn.decode(n,n.uint32()));continue;case 5:if(o!==40)break;i.mode=n.int32();continue;case 6:if(o!==50)break;i.effectMeshs.push(We.decode(n,n.uint32()));continue}if((o&7)===4||o===0)break;n.skipType(o&7)}return i},fromJSON(e){return{name:Dn(e.name)?globalThis.String(e.name):"",formations:globalThis.Array.isArray(e==null?void 0:e.formations)?e.formations.map(t=>cn.fromJSON(t)):[],mode:Dn(e.mode)?Ou(e.mode):0,effectMeshs:globalThis.Array.isArray(e==null?void 0:e.effectMeshs)?e.effectMeshs.map(t=>We.fromJSON(t)):[]}},toJSON(e){var n,a;const t={};return e.name!==""&&(t.name=e.name),(n=e.formations)!=null&&n.length&&(t.formations=e.formations.map(i=>cn.toJSON(i))),e.mode!==0&&(t.mode=Au(e.mode)),(a=e.effectMeshs)!=null&&a.length&&(t.effectMeshs=e.effectMeshs.map(i=>We.toJSON(i))),t},create(e){return kn.fromPartial(e!=null?e:{})},fromPartial(e){var n,a,i,o;const t=Kr();return t.name=(n=e.name)!=null?n:"",t.formations=((a=e.formations)==null?void 0:a.map(r=>cn.fromPartial(r)))||[],t.mode=(i=e.mode)!=null?i:0,t.effectMeshs=((o=e.effectMeshs)==null?void 0:o.map(r=>We.fromPartial(r)))||[],t}};function Qr(){return{name:"",url:""}}const cn={encode(e,t=se.Writer.create()){return e.name!==""&&t.uint32(10).string(e.name),e.url!==""&&t.uint32(18).string(e.url),t},decode(e,t){const n=e instanceof se.Reader?e:se.Reader.create(e);let a=t===void 0?n.len:n.pos+t;const i=Qr();for(;n.pos<a;){const o=n.uint32();switch(o>>>3){case 1:if(o!==10)break;i.name=n.string();continue;case 2:if(o!==18)break;i.url=n.string();continue}if((o&7)===4||o===0)break;n.skipType(o&7)}return i},fromJSON(e){return{name:Dn(e.name)?globalThis.String(e.name):"",url:Dn(e.url)?globalThis.String(e.url):""}},toJSON(e){const t={};return e.name!==""&&(t.name=e.name),e.url!==""&&(t.url=e.url),t},create(e){return cn.fromPartial(e!=null?e:{})},fromPartial(e){var n,a;const t=Qr();return t.name=(n=e.name)!=null?n:"",t.url=(a=e.url)!=null?a:"",t}};function Dn(e){return e!=null}const Wo=({url:e,alpha:t=1,position:n=u.Vector3.Zero(),visible:a=!0,colorCodec:i,actions:o,counterLine:r=void 0,lines:l,text:s,disableDepthWrite:c})=>{const p=m.useRef(null),[f,d]=m.useState(""),x=m.useContext(Le),h=m.useContext(Lt),[T,P]=m.useState(null),[v,_]=m.useState(u.Color3.White()),b=je({url:e,cacheType:Me.URL_PREFIX_MATCH}),[k,M]=m.useState(u.Vector3.Zero()),[w,S]=m.useState();return m.useEffect(()=>{console.log("[Geo3DViewer] StructureLayer Loading: ",e)},[e]),m.useEffect(()=>{if(b){const N=p.current;u.Tags.EnableFor(N),u.Tags.AddTagsTo(N,"loading");const F=Wt.decode(new Uint8Array(b)),{name:B,points:I,indices:D,value:E,colorId:L,center:y}=F;y&&M(new u.Vector3(y.x,y.y,y.z));const A=new u.VertexData;A.positions=I,A.indices=D,A.colors=E;const V=[];return u.VertexData.ComputeNormals(I,D,V),A.normals=V,P(L),d(B),N&&(A.applyToMesh(N),N.getScene().onAfterRenderObservable.addOnce(()=>{if(!N.isDisposed()){const W=N.getBoundingInfo();S(W.boundingBox)}})),u.Tags.RemoveTagsFrom(N,"loading"),()=>{P(null),d(""),N&&new u.VertexData().applyToMesh(N)}}},[b]),m.useEffect(()=>{const N=T&&h.colorIDs[T]?h.colorIDs[T]:u.Color3.White();_(u.Color3.FromArray([N.r,N.g,N.b]))},[T,h.colorIDs]),m.useEffect(()=>{p.current&&(p.current.metadata={pickable:o?{name:f,onLeftClick:o.onLeftClick,onRightClick:o.onRightClick,onMiddleClick:o.onMiddleClick,onHover:o.onHover,needWorldPosition:o.needWorldPosition,extra:o.extra}:null})},[o,f]),C.jsx(C.Fragment,{children:C.jsxs("transformNode",{name:`transform-structurelayer-${f}`,position:k.add(n).multiplyByFloats(x&&x.scalePlane?x.scalePlane:1,x&&x.scaleDepth?x.scaleDepth:1,x&&x.scalePlane?x.scalePlane:1),scaling:new u.Vector3(x?x.scalePlane:1,x?x.scaleDepth:1,x?x.scalePlane:1),setEnabled:a,children:[C.jsx("transformNode",{name:`structurelayer-${f}-load`}),C.jsx("mesh",{name:`structurelayer-${f}-mesh`,ref:p,useVertexColors:i!=null,children:i?C.jsx(Mt,{name:`structurelayer-${f}-mat`,backFaceCulling:!1,alpha:t,transparencyMode:u.Material.MATERIAL_ALPHABLEND,alphaMode:u.Engine.ALPHA_COMBINE,colorCodec:i,needDepthPrePass:!0,counterLine:r,boundingBox:w,lines:l,scaleDepth:x?x.scaleDepth:1,scalePlane:x?x.scalePlane:1,text:s,disableDepthWrite:c}):C.jsx("standardMaterial",{name:`structurelayer-${f}-mat`,backFaceCulling:!1,specularColor:new u.Color3(0,0,0),ambientColor:new u.Color3(1,1,1),diffuseColor:v,needDepthPrePass:!0,transparencyMode:u.Material.MATERIAL_ALPHABLEND,alphaMode:u.Engine.ALPHA_COMBINE,alpha:t,disableDepthWrite:c})})]})})},Mu=e=>{const{id:t,visible:n=!0,position:a=u.Vector3.Zero(),diffuseTextureUrl:i,diffuseTextureSufaceUrl:o,bumpTextureUrl:r,mesh:l}=e,s=m.useRef(null),c=m.useContext(Le),[p,f]=m.useState(),[d,x]=m.useState(),[h,T]=m.useState();return m.useEffect(()=>{const P=s.current;if(P&&l){const v=new u.VertexData;v.positions=l.vertices,v.indices=l.indices,v.uvs=l.uv;const _=[];u.VertexData.ComputeNormals(l.vertices,l.indices,_),v.normals=_,v.applyToMesh(P)}},[l,l==null?void 0:l.indices,l==null?void 0:l.uv,l==null?void 0:l.vertices]),m.useEffect(()=>{const P=new u.Texture(i);if(P.uScale=500,P.vScale=.5,f(P),o){const _=new u.Texture(o);_.uScale=500,_.vScale=.5,x(_)}const v=new u.Texture(r);v.uScale=500,v.vScale=.5,T(v)},[r,o,i]),C.jsx(C.Fragment,{children:C.jsx("transformNode",{name:`transform-formation-edge-${t}`,position:a.multiplyByFloats(c&&c.scalePlane?c.scalePlane:1,c&&c.scaleDepth?c.scaleDepth:1,c&&c.scalePlane?c.scalePlane:1),scaling:new u.Vector3(c?c.scalePlane:1,c?c.scaleDepth:1,c?c.scalePlane:1),setEnabled:n,children:C.jsx("mesh",{name:"mesh",ref:s,children:C.jsx("standardMaterial",{name:`edge-${t}-material`,zOffset:-1,zOffsetUnits:-1,diffuseTexture:o?d:p,bumpTexture:o?void 0:h})})})})},oa=({url:e,visible:t=!0,filter:n,explodedView:a=0,showLayerLabel:i,labelStyle:o,offset:r=new u.Vector3(0,0,0),showTopLayerAsStructureLayer:l=!1,useColorCodecOnTopLayer:s=!1,colorCodec:c,actions:p,materials:f,topLayerCounterLine:d=void 0,topLayerHeightOffset:x=1,diffuseTextureUrl:h,diffuseTextureSufaceUrl:T,bumpTextureUrl:P,visibleEdgeEffect:v=!1})=>{var D,E;const[_,b]=m.useState(),k=m.useContext(Le),[M,w]=m.useState(!0),[S,N]=m.useState(""),F=je({url:e,cacheType:Me.URL_PREFIX_MATCH}),[B,I]=m.useState([]);return m.useEffect(()=>{console.log("[Geo3DViewer] ComplexFormationManager Loading: ",e)},[e]),m.useEffect(()=>{if(F){const L=kn.decode(new Uint8Array(F)),y=L.formations;if(L.mode==$o.FACE){w(!0),N(L.name);const A=[];y.forEach((V,$)=>{const W={name:V.name,topUrl:V.url,bottomUrl:y[$+1]?y[$+1].url:void 0};A.push(W)}),b(A)}else{w(!1),N(L.name);const A=[];y.forEach(V=>{const $={name:V.name,topUrl:V.url};A.push($)}),b(A)}return console.log(L),I(L.effectMeshs),()=>{b([])}}},[F]),C.jsxs("abstractMesh",{name:`complexformationmanager-${S}`,children:[l&&_&&_.length>1?C.jsx(Wo,{url:_[0].topUrl,alpha:(D=f==null?void 0:f[_[0].name])==null?void 0:D.alpha,position:new u.Vector3(0,x>=0?x*(k&&(E=k.scaleDepth)!=null?E:1):0,0).add(r),visible:t&&(n?n.includes(_[0].name):!0),colorCodec:c,counterLine:d},`${S}-${_[0].name}-SL`):null,_?_.map((L,y)=>M?l&&y===0?C.jsx(C.Fragment,{}):C.jsx("transformNode",{name:`${S}-${L.name}-EV`,position:r.add(new u.Vector3(0,y*(-1*a*(k&&k.scaleDepth?k.scaleDepth:0)),0)),children:C.jsx(Xn,{showLayerLabel:i,labelStyle:o,urlTopLayer:L.topUrl,urlBottomLayer:L.bottomUrl,visible:t&&(n?n.includes(L.name):!0),showBottomLayer:_[y+1]?n?n.includes(_[y+1].name):!0:!1,actions:p,material:y===0&&s?{...f==null?void 0:f[L.name],colorCodec:c,type:$e.COLOR_CODEC}:f==null?void 0:f[L.name]},`${S}-${L.name}`)},`${S}-${L.name}`):l&&y===0?C.jsx(C.Fragment,{}):C.jsx("transformNode",{name:`${S}-${L.name}-EV`,position:r.add(new u.Vector3(0,y*(-1*a*(k&&k.scaleDepth?k.scaleDepth:0)),0)),children:C.jsx(qn,{url:L.topUrl,showLayerLabel:i,labelStyle:o,visible:t&&(n?n.includes(L.name):!0),showBottomLayer:_[y+1]?n?n.includes(_[y+1].name):!0:!1,actions:p,material:f==null?void 0:f[L.name]},`${S}-${L.name}`)},`${S}-${L.name}`)):null,B&&h&&P&&a===0&&B.map((L,y)=>C.jsx(Mu,{visible:v,id:y,diffuseTextureUrl:h,diffuseTextureSufaceUrl:y===0?T:void 0,bumpTextureUrl:P,mesh:L},y))]})},ra=({visible:e=!0,color:t=u.Color3.White(),fontSize:n=80,step:a=200,keyFrameDistance:i=[],keyFrameStep:o=[],keyFrameFontSize:r=[],textureSizeX:l=512,textureSizeY:s=512,init:c=!0})=>{const p=_e.useScene(),f=m.useRef(null),d=m.useContext(Le),[x,h]=m.useState([]),[T,P]=m.useState([]),[v,_]=m.useState([]),[b,k]=m.useState(0),M=m.useCallback(w=>{if(p&&w){const S=new is.GridMaterial("axis-material",p);S.majorUnitFrequency=o.length>0?o[0]:50,S.minorUnitVisibility=0,S.gridRatio=2,S.sideOrientation=u.Material.ClockWiseSideOrientation,S.backFaceCulling=!0,S.mainColor=t,S.lineColor=t,S.opacity=.98,w.material=S}},[t,o,p]);return m.useEffect(()=>()=>{var w;(w=f.current)==null||w.dispose()},[]),m.useEffect(()=>{const w=()=>{const S=(p==null?void 0:p.activeCamera).radius;for(let N=0;N<i.length;N++)if(S<=i[N]){k(N);break}};return p&&p.activeCamera&&(p==null||p.activeCamera.onViewMatrixChangedObservable.add(w)),()=>{p&&p.activeCamera&&(p==null||p.activeCamera.onViewMatrixChangedObservable.removeCallback(w))}},[i,r,o,p,e]),m.useEffect(()=>{if(d&&d.min&&d.max&&c){const w=d.origin||u.Vector3.Zero(),S=[],N=[],F=[],B=[...o];B.length===0&&B.push(a);for(let I=0;I<B.length;I++){let D=B[I]/1;D<1&&(D=200);const E=[];for(let A=0;A<=d.max.x-d.min.x;A+=D)E.push({text:`${A+d.min.x+w.x}`,position:new u.Vector3(A,0,0)}),E.push({text:`${A+d.min.x+w.x}`,position:new u.Vector3(A,d.max.y-d.min.y,d.max.z-d.min.z)}),E.push({text:`${A+d.min.x+w.x}`,position:new u.Vector3(A,d.max.y-d.min.y,0)}),E.push({text:`${A+d.min.x+w.x}`,position:new u.Vector3(A,0,d.max.z-d.min.z)});S.push(E);const L=[];for(let A=0;A<=d.max.y-d.min.y;A+=D)L.push({text:`${A+d.min.y+w.y}`,position:new u.Vector3(0,A,0)}),L.push({text:`${A+d.min.y+w.y}`,position:new u.Vector3(d.max.x-d.min.x,A,d.max.z-d.min.z)}),L.push({text:`${A+d.min.y+w.y}`,position:new u.Vector3(d.max.x-d.min.x,A,0)}),L.push({text:`${A+d.min.y+w.y}`,position:new u.Vector3(0,A,d.max.z-d.min.z)});N.push(L);const y=[];for(let A=0;A<=d.max.z-d.min.z;A+=D)y.push({text:`${A+d.min.z+w.z}`,position:new u.Vector3(0,0,A)}),y.push({text:`${A+d.min.z+w.z}`,position:new u.Vector3(d.max.x-d.min.x,d.max.y-d.min.y,A)}),y.push({text:`${A+d.min.z+w.z}`,position:new u.Vector3(0,d.max.y-d.min.y,A)}),y.push({text:`${A+d.min.z+w.z}`,position:new u.Vector3(d.max.x-d.min.x,0,A)});F.push(y)}h(S),P(N),_(F)}},[c,o,d,a]),d&&d.min&&d.max&&d.max.x-d.min.x>0&&d.max.y-d.min.y>0&&d.max.z-d.min.z>0?C.jsxs("transformNode",{name:"coord",setEnabled:e,position:(d&&d.min&&d.max?u.Vector3.Center(d.min,d.max):u.Vector3.Zero()).multiply(Oe(d)),scaling:new u.Vector3(Oe(d).x,Oe(d).y,Oe(d).z),children:[C.jsx("box",{name:"axis",width:d&&d.min&&d.max?d.max.x-d.min.x:0,height:d&&d.min&&d.max?d.max.y-d.min.y:0,depth:d&&d.min&&d.max?d.max.z-d.min.z:0,ref:M,isPickable:!1,isBlocker:!1},`axis-${d.max.x-d.min.x}-${d.max.y-d.min.y}-${d.max.z-d.min.z}`),C.jsxs("transformNode",{name:"axis-offset",position:d&&d.min&&d.max?new u.Vector3(-(d.max.x-d.min.x)/2,-(d.max.y-d.min.y)/2,-(d.max.z-d.min.z)/2):u.Vector3.Zero(),children:[x.map((w,S)=>w.map((N,F)=>{var I;const B=N;return C.jsx("transformNode",{name:`axis-x-${S}-${F}`,position:B==null?void 0:B.position,setEnabled:S===b,scaling:new u.Vector3(1/Oe(d).x,1/Oe(d).y,1/Oe(d).z),children:C.jsx(Je,{text:`${B?B.text:""}`,fontSize:(I=r[S])!=null?I:n,color:t.toHexString()})},`axis-x-${S}-${F}`)})),T.map((w,S)=>w.map((N,F)=>{var I;const B=N;return C.jsx("transformNode",{name:`axis-x-${S}-${F}`,position:B==null?void 0:B.position,setEnabled:S===b,scaling:new u.Vector3(1/Oe(d).x,1/Oe(d).y,1/Oe(d).z),children:C.jsx(Je,{text:`${B?B.text:""}`,fontSize:(I=r[S])!=null?I:n,color:t.toHexString()})},`axis-x-${S}-${F}`)})),v.map((w,S)=>w.map((N,F)=>{var I;const B=N;return C.jsx("transformNode",{name:`axis-x-${S}-${F}`,position:B==null?void 0:B.position,setEnabled:S===b,scaling:new u.Vector3(1/Oe(d).x,1/Oe(d).y,1/Oe(d).z),children:C.jsx(Je,{text:`${B?B.text:""}`,fontSize:(I=r[S])!=null?I:n,color:t.toHexString()})},`axis-x-${S}-${F}`)}))]})]},`coord-${d.min.x}-${d.min.y}-${d.min.z}-${d.max.x}-${d.max.y}-${d.max.z}-${Math.abs(d.max.x-d.min.x)}-${Math.abs(d.max.y-d.min.y)}-${Math.abs(d.max.z-d.min.z)}`):C.jsx(C.Fragment,{})};function Lu(e){switch(e){case 0:case"NORMAL":return 0;case 1:case"CICLE":return 1;case-1:case"UNRECOGNIZED":default:return-1}}function Ru(e){switch(e){case 0:return"NORMAL";case 1:return"CICLE";case-1:default:return"UNRECOGNIZED"}}function jr(){return{name:"",lines:[]}}const ia={encode(e,t=se.Writer.create()){e.name!==""&&t.uint32(10).string(e.name);for(const n of e.lines)fn.encode(n,t.uint32(18).fork()).ldelim();return t},decode(e,t){const n=e instanceof se.Reader?e:se.Reader.create(e);let a=t===void 0?n.len:n.pos+t;const i=jr();for(;n.pos<a;){const o=n.uint32();switch(o>>>3){case 1:if(o!==10)break;i.name=n.string();continue;case 2:if(o!==18)break;i.lines.push(fn.decode(n,n.uint32()));continue}if((o&7)===4||o===0)break;n.skipType(o&7)}return i},fromJSON(e){return{name:ko(e.name)?globalThis.String(e.name):"",lines:globalThis.Array.isArray(e==null?void 0:e.lines)?e.lines.map(t=>fn.fromJSON(t)):[]}},toJSON(e){var n;const t={};return e.name!==""&&(t.name=e.name),(n=e.lines)!=null&&n.length&&(t.lines=e.lines.map(a=>fn.toJSON(a))),t},create(e){return ia.fromPartial(e!=null?e:{})},fromPartial(e){var n,a;const t=jr();return t.name=(n=e.name)!=null?n:"",t.lines=((a=e.lines)==null?void 0:a.map(i=>fn.fromPartial(i)))||[],t}};function ei(){return{positions:[]}}const un={encode(e,t=se.Writer.create()){for(const n of e.positions)rt.encode(n,t.uint32(10).fork()).ldelim();return t},decode(e,t){const n=e instanceof se.Reader?e:se.Reader.create(e);let a=t===void 0?n.len:n.pos+t;const i=ei();for(;n.pos<a;){const o=n.uint32();switch(o>>>3){case 1:if(o!==10)break;i.positions.push(rt.decode(n,n.uint32()));continue}if((o&7)===4||o===0)break;n.skipType(o&7)}return i},fromJSON(e){return{positions:globalThis.Array.isArray(e==null?void 0:e.positions)?e.positions.map(t=>rt.fromJSON(t)):[]}},toJSON(e){var n;const t={};return(n=e.positions)!=null&&n.length&&(t.positions=e.positions.map(a=>rt.toJSON(a))),t},create(e){return un.fromPartial(e!=null?e:{})},fromPartial(e){var n;const t=ei();return t.positions=((n=e.positions)==null?void 0:n.map(a=>rt.fromPartial(a)))||[],t}};function ti(){return{segments:[],type:0,position:void 0}}const fn={encode(e,t=se.Writer.create()){for(const n of e.segments)un.encode(n,t.uint32(10).fork()).ldelim();return e.type!==0&&t.uint32(16).int32(e.type),e.position!==void 0&&rt.encode(e.position,t.uint32(26).fork()).ldelim(),t},decode(e,t){const n=e instanceof se.Reader?e:se.Reader.create(e);let a=t===void 0?n.len:n.pos+t;const i=ti();for(;n.pos<a;){const o=n.uint32();switch(o>>>3){case 1:if(o!==10)break;i.segments.push(un.decode(n,n.uint32()));continue;case 2:if(o!==16)break;i.type=n.int32();continue;case 3:if(o!==26)break;i.position=rt.decode(n,n.uint32());continue}if((o&7)===4||o===0)break;n.skipType(o&7)}return i},fromJSON(e){return{segments:globalThis.Array.isArray(e==null?void 0:e.segments)?e.segments.map(t=>un.fromJSON(t)):[],type:ko(e.type)?Lu(e.type):0,position:ko(e.position)?rt.fromJSON(e.position):void 0}},toJSON(e){var n;const t={};return(n=e.segments)!=null&&n.length&&(t.segments=e.segments.map(a=>un.toJSON(a))),e.type!==0&&(t.type=Ru(e.type)),e.position!==void 0&&(t.position=rt.toJSON(e.position)),t},create(e){return fn.fromPartial(e!=null?e:{})},fromPartial(e){var n,a;const t=ti();return t.segments=((n=e.segments)==null?void 0:n.map(i=>un.fromPartial(i)))||[],t.type=(a=e.type)!=null?a:0,t.position=e.position!==void 0&&e.position!==null?rt.fromPartial(e.position):void 0,t}};function ko(e){return e!=null}const Uo=({points:e=[],showPoint:t=!0,color:n=u.Color3.White(),pointSize:a=2,alwaysOnTop:i=!1,offset:o=u.Vector3.Zero(),alpha:r,lineWidth:l})=>{const s=_e.useScene(),c=m.useRef(null),p=m.useContext(Le);return m.useEffect(()=>{if(s){const f=[],d=Oe(p);if(e.forEach(x=>{f.push(x.add(o).multiply(d))}),l){const x={path:f,radius:l,updatable:!0};if(c.current)x.instance=c.current,u.MeshBuilder.CreateTube("line",x);else{c.current=u.MeshBuilder.CreateTube("line",x,s);const h=new u.StandardMaterial("line-mat");return h.diffuseColor=n,h.specularColor=u.Color3.Black(),h.emissiveColor=n,r!==void 0&&(h.alpha=r,h.transparencyMode=2),h.depthFunction=i?u.Constants.ALWAYS:0,c.current.material=h,()=>{c.current&&(s.removeMesh(c.current),c.current=null)}}}else{const x={points:f,updateable:!0};if(c.current)x.instance=c.current,u.MeshBuilder.CreateLines("line",x);else{c.current=u.MeshBuilder.CreateLines("line",x,s);const h=new u.StandardMaterial("line-mat");return h.diffuseColor=n,h.specularColor=u.Color3.Black(),h.emissiveColor=n,r!==void 0&&(h.alpha=r,h.transparencyMode=2),h.depthFunction=i?u.Constants.ALWAYS:0,()=>{c.current&&(s.removeMesh(c.current),c.current=null)}}}}},[i,n,p,o,e,s,l,c,r]),C.jsx("transformNode",{name:"transform-line",children:t?C.jsx("transformNode",{name:"lines-point",children:e.map((f,d)=>C.jsx("sphere",{diameter:a,name:`lines-point-${d}`,position:f.add(o).multiply(Oe(p)),scalingDeterminant:l&&(p==null?void 0:p.scalePlane)||1,children:C.jsx("standardMaterial",{name:`lines-point-${d}-mat`,diffuseColor:n,emissiveColor:n,specularColor:u.Color3.White(),depthFunction:i?u.Constants.ALWAYS:void 0})},`lines-point-${f.x}-${f.y}-${f.z}`))}):C.jsx(C.Fragment,{})})},Bu=e=>{const{name:t,prev:n,next:a,textColor:i,fontSize:o}=e,r=_e.useScene(),l=m.useRef(null);return m.useEffect(()=>{const s=r==null?void 0:r.activeCamera,c=r==null?void 0:r.getEngine();if(r&&s&&c&&l.current){const p=l.current.getChildren()[0],f=u.Vector3.Normalize(a.subtract(n)),d=new u.Vector3(1,0,0),x=Math.acos(u.Vector3.Dot(f,d)),h=u.Vector3.Cross(f,d);p.rotation.z=h.y>0?x:Math.PI*2-x,p.rotation.x=Math.PI/2,p.renderingGroupId=3}},[a,n,r]),C.jsx("transformNode",{name:`${t}`,position:u.Vector3.Lerp(n,a,.5),ref:l,children:C.jsx(Je,{text:t,fontSize:o,color:i,billboardMode:u.Mesh.BILLBOARDMODE_NONE})})},Fu=e=>{const{url:t,color:n,alpha:a,visible:i=!0,fontSize:o=30,textColor:r="red",linewidth:l=10}=e,s=_e.useScene(),[c,p]=m.useState([]),[f,d]=m.useState([]),x=m.useContext(Le);return m.useEffect(()=>{Ut.get(t,{responseType:"arraybuffer"}).then(h=>{const T=ia.decode(new Uint8Array(h.data));console.log(T);const P=[],v=[];for(let _=0;_<T.lines.length;_++){const b=T.lines[_];if(b.segments.length<2)continue;const k=[];for(let M=0;M<b.segments.length;M++){const w=[...Ps(b.segments[M].positions)];P.push([...w]),k.push(w[0]),k.push(w[w.length-1])}b.type===1&&k.push(Oi(b.segments[0].positions[0])),v.push(k)}p(P),d(v),console.log(v),console.log(P)})},[s,t]),C.jsxs("transformNode",{name:"contourline",setEnabled:i,children:[c.map((h,T)=>h.length<2||!i?null:C.jsx(Uo,{points:h,showPoint:!1,color:n,alpha:a,lineWidth:l,alwaysOnTop:!0},T)),f.map(h=>h.map((T,P)=>P%2===0||P===h.length-1?null:C.jsx(Bu,{name:T.y.toFixed(0),prev:Oe(x).multiply(T),next:Oe(x).multiply(h[P+1]),fontSize:o,textColor:r},P)))]})};function Du(e){switch(e){case 0:case"X":return 0;case 1:case"Y":return 1;case 2:case"Z":return 2;case 3:case"FREE":return 3;case-1:case"UNRECOGNIZED":default:return-1}}function zu(e){switch(e){case 0:return"X";case 1:return"Y";case 2:return"Z";case 3:return"FREE";case-1:default:return"UNRECOGNIZED"}}function ni(){return{layer:0,direction:0,colorId:0,points:[],indices:[],value:[],vMin:0,vMax:0,center:void 0}}const Ho={encode(e,t=se.Writer.create()){e.layer!==0&&t.uint32(8).uint32(e.layer),e.direction!==0&&t.uint32(16).int32(e.direction),e.colorId!==0&&t.uint32(24).uint32(e.colorId),t.uint32(170).fork();for(const n of e.points)t.float(n);t.ldelim(),t.uint32(178).fork();for(const n of e.indices)t.uint32(n);t.ldelim(),t.uint32(186).fork();for(const n of e.value)t.float(n);return t.ldelim(),e.vMin!==0&&t.uint32(205).float(e.vMin),e.vMax!==0&&t.uint32(213).float(e.vMax),e.center!==void 0&&K.encode(e.center,t.uint32(250).fork()).ldelim(),t},decode(e,t){const n=e instanceof se.Reader?e:se.Reader.create(e);let a=t===void 0?n.len:n.pos+t;const i=ni();for(;n.pos<a;){const o=n.uint32();switch(o>>>3){case 1:if(o!==8)break;i.layer=n.uint32();continue;case 2:if(o!==16)break;i.direction=n.int32();continue;case 3:if(o!==24)break;i.colorId=n.uint32();continue;case 21:if(o===173){i.points.push(n.float());continue}if(o===170){const r=n.uint32()+n.pos;for(;n.pos<r;)i.points.push(n.float());continue}break;case 22:if(o===176){i.indices.push(n.uint32());continue}if(o===178){const r=n.uint32()+n.pos;for(;n.pos<r;)i.indices.push(n.uint32());continue}break;case 23:if(o===189){i.value.push(n.float());continue}if(o===186){const r=n.uint32()+n.pos;for(;n.pos<r;)i.value.push(n.float());continue}break;case 25:if(o!==205)break;i.vMin=n.float();continue;case 26:if(o!==213)break;i.vMax=n.float();continue;case 31:if(o!==250)break;i.center=K.decode(n,n.uint32());continue}if((o&7)===4||o===0)break;n.skipType(o&7)}return i},fromJSON(e){return{layer:tn(e.layer)?globalThis.Number(e.layer):0,direction:tn(e.direction)?Du(e.direction):0,colorId:tn(e.colorId)?globalThis.Number(e.colorId):0,points:globalThis.Array.isArray(e==null?void 0:e.points)?e.points.map(t=>globalThis.Number(t)):[],indices:globalThis.Array.isArray(e==null?void 0:e.indices)?e.indices.map(t=>globalThis.Number(t)):[],value:globalThis.Array.isArray(e==null?void 0:e.value)?e.value.map(t=>globalThis.Number(t)):[],vMin:tn(e.vMin)?globalThis.Number(e.vMin):0,vMax:tn(e.vMax)?globalThis.Number(e.vMax):0,center:tn(e.center)?K.fromJSON(e.center):void 0}},toJSON(e){var n,a,i;const t={};return e.layer!==0&&(t.layer=Math.round(e.layer)),e.direction!==0&&(t.direction=zu(e.direction)),e.colorId!==0&&(t.colorId=Math.round(e.colorId)),(n=e.points)!=null&&n.length&&(t.points=e.points),(a=e.indices)!=null&&a.length&&(t.indices=e.indices.map(o=>Math.round(o))),(i=e.value)!=null&&i.length&&(t.value=e.value),e.vMin!==0&&(t.vMin=e.vMin),e.vMax!==0&&(t.vMax=e.vMax),e.center!==void 0&&(t.center=K.toJSON(e.center)),t},create(e){return Ho.fromPartial(e!=null?e:{})},fromPartial(e){var n,a,i,o,r,l,s,c;const t=ni();return t.layer=(n=e.layer)!=null?n:0,t.direction=(a=e.direction)!=null?a:0,t.colorId=(i=e.colorId)!=null?i:0,t.points=((o=e.points)==null?void 0:o.map(p=>p))||[],t.indices=((r=e.indices)==null?void 0:r.map(p=>p))||[],t.value=((l=e.value)==null?void 0:l.map(p=>p))||[],t.vMin=(s=e.vMin)!=null?s:0,t.vMax=(c=e.vMax)!=null?c:0,t.center=e.center!==void 0&&e.center!==null?K.fromPartial(e.center):void 0,t}};function tn(e){return e!=null}const Zo=({name:e,url:t,visible:n=!0,colorCodec:a,alpha:i=1,position:o=u.Vector3.Zero(),actions:r})=>{const l=m.useRef(null),[s,c]=m.useState(""),[p,f]=m.useState(""),d=m.useContext(Le),x=je({url:t,cacheType:Me.URL_PREFIX_MATCH}),[h,T]=m.useState(u.Vector3.Zero());return m.useEffect(()=>{const P=l.current;if(!x||!P)return;u.Tags.EnableFor(P),u.Tags.AddTagsTo(P,"loading");const v=Ho.decode(new Uint8Array(x)),{layer:_,direction:b,points:k,indices:M,value:w,center:S}=v,N=new u.VertexData;N.positions=k,N.indices=M,N.colors=w;const F=[];u.VertexData.ComputeNormals(k,M,F),N.normals=F,S&&T(new u.Vector3(S.x,S.y,S.z)),N.applyToMesh(P),c(_.toString()),f(b.toString()),u.Tags.RemoveTagsFrom(P,"loading")},[x]),m.useEffect(()=>{l.current&&(l.current.metadata={pickable:r?{name:e,onLeftClick:r.onLeftClick,onRightClick:r.onRightClick,onMiddleClick:r.onMiddleClick,onHover:r.onHover,needWorldPosition:r.needWorldPosition,extra:r.extra}:null})},[r,e]),m.useEffect(()=>{console.log("[Geo3DViewer] DensitySlice Loading: ",t)},[t]),C.jsx(C.Fragment,{children:C.jsx("transformNode",{name:`densityslice-${e}-${p}-${s}-transform`,position:h.add(o).multiplyByFloats(d&&d.scalePlane?d.scalePlane:1,d&&d.scaleDepth?d.scaleDepth:1,d&&d.scalePlane?d.scalePlane:1),scaling:new u.Vector3(d?d.scalePlane:1,d?d.scaleDepth:1,d?d.scalePlane:1),children:C.jsx("mesh",{name:`densityslice-${e}-${p}-${s}-mesh`,ref:l,setEnabled:n,useVertexColors:!0,children:C.jsx(Mt,{name:`densityslice-${e}-${p}-${s}-mat`,backFaceCulling:!1,needDepthPrePass:!0,alpha:i,transparencyMode:u.Material.MATERIAL_ALPHABLEND,alphaMode:u.Engine.ALPHA_COMBINE,colorCodec:a})})})})},aa=()=>{const e=_e.useScene(),t=m.useRef(void 0);return m.useEffect(()=>{const n=setInterval(()=>{if(e&&t.current){const a=e.getEngine().getFps();t.current.getControlByName("fps").text=a.toFixed(0)+"FPS"}},1e3);return()=>{clearInterval(n)}},[e]),m.useEffect(()=>{var n,a;if(e&&!t.current){const i=nt.AdvancedDynamicTexture.CreateFullscreenUI("UI",!0,e);t.current=i;const o=new nt.TextBlock("fps");o.text="0FPS",o.color="white",o.fontSize=15,o.width=100,o.height=50;const r=window.devicePixelRatio||1,l=(n=e.getEngine().getRenderingCanvas())==null?void 0:n.clientHeight,s=(a=e.getEngine().getRenderingCanvas())==null?void 0:a.clientWidth;o.left=s?-(s*r/2-50):0,o.top=l?-(l*r/2-25):0,i.addControl(o)}return()=>{e&&t.current}},[e]),null},sa=({url:e,visible:t=!0,filter:n,explodedView:a=0,offset:i=new u.Vector3(0,0,0),showLayerLabel:o,labelStyle:r,actions:l,materials:s})=>{const[c,p]=m.useState(),f=m.useContext(Le),[d,x]=m.useState(!0),[h,T]=m.useState(""),P=je({url:e,cacheType:Me.URL_PREFIX_MATCH});return m.useEffect(()=>{console.log("[Geo3DViewer] FormationManager Loading: ",e)},[e]),m.useEffect(()=>{if(P){const v=kn.decode(new Uint8Array(P)),_=v.formations;if(v.mode==$o.FACE){x(!0),T(v.name);const b=[];_.forEach((k,M)=>{const w={name:k.name,topUrl:k.url,bottomUrl:_[M+1]?_[M+1].url:void 0};b.push(w)}),p(b)}else{x(!1),T(v.name);const b=[];_.forEach(k=>{const M={name:k.name,topUrl:k.url};b.push(M)}),p(b)}return console.log(_),()=>{T(""),p([])}}},[P]),C.jsx("abstractMesh",{name:`formationmanager-${h}`,children:c?c.map((v,_)=>d?C.jsx("transformNode",{name:`${h}-${v.name}-EV`,position:i.add(new u.Vector3(0,_*(-1*a*(f&&f.scaleDepth?f.scaleDepth:0)),0)),children:C.jsx(Xn,{showLayerLabel:o,labelStyle:r,urlTopLayer:v.topUrl,urlBottomLayer:v.bottomUrl,visible:t&&(n?n.includes(v.name):!0),showBottomLayer:c[_+1]?n?n.includes(c[_+1].name):!0:!1,actions:l,material:s==null?void 0:s[v.name]},`${h}-${v.name}`)},`${h}-${v.name}`):C.jsx("transformNode",{name:`${h}-${v.name}-EV`,position:i.add(new u.Vector3(0,_*(-1*a*(f&&f.scaleDepth?f.scaleDepth:0)),0)),children:C.jsx(qn,{url:v.topUrl,showLayerLabel:o,labelStyle:r,visible:t&&(n?n.includes(v.name):!0),showBottomLayer:c[_+1]?n?n.includes(c[_+1].name):!0:!1,actions:l,material:s==null?void 0:s[v.name]},`${h}-${v.name}`)},`${h}-${v.name}`)):null})};function oi(){return{name:"",slices:[],center:void 0}}const Go={encode(e,t=se.Writer.create()){e.name!==""&&t.uint32(10).string(e.name);for(const n of e.slices)dn.encode(n,t.uint32(18).fork()).ldelim();return e.center!==void 0&&K.encode(e.center,t.uint32(250).fork()).ldelim(),t},decode(e,t){const n=e instanceof se.Reader?e:se.Reader.create(e);let a=t===void 0?n.len:n.pos+t;const i=oi();for(;n.pos<a;){const o=n.uint32();switch(o>>>3){case 1:if(o!==10)break;i.name=n.string();continue;case 2:if(o!==18)break;i.slices.push(dn.decode(n,n.uint32()));continue;case 31:if(o!==250)break;i.center=K.decode(n,n.uint32());continue}if((o&7)===4||o===0)break;n.skipType(o&7)}return i},fromJSON(e){return{name:zn(e.name)?globalThis.String(e.name):"",slices:globalThis.Array.isArray(e==null?void 0:e.slices)?e.slices.map(t=>dn.fromJSON(t)):[],center:zn(e.center)?K.fromJSON(e.center):void 0}},toJSON(e){var n;const t={};return e.name!==""&&(t.name=e.name),(n=e.slices)!=null&&n.length&&(t.slices=e.slices.map(a=>dn.toJSON(a))),e.center!==void 0&&(t.center=K.toJSON(e.center)),t},create(e){return Go.fromPartial(e!=null?e:{})},fromPartial(e){var n,a;const t=oi();return t.name=(n=e.name)!=null?n:"",t.slices=((a=e.slices)==null?void 0:a.map(i=>dn.fromPartial(i)))||[],t.center=e.center!==void 0&&e.center!==null?K.fromPartial(e.center):void 0,t}};function ri(){return{name:"",colorId:0,vertices:[],indices:[],edges:[]}}const dn={encode(e,t=se.Writer.create()){e.name!==""&&t.uint32(10).string(e.name),e.colorId!==0&&t.uint32(16).uint32(e.colorId),t.uint32(26).fork();for(const n of e.vertices)t.float(n);t.ldelim(),t.uint32(34).fork();for(const n of e.indices)t.uint32(n);t.ldelim();for(const n of e.edges)K.encode(n,t.uint32(42).fork()).ldelim();return t},decode(e,t){const n=e instanceof se.Reader?e:se.Reader.create(e);let a=t===void 0?n.len:n.pos+t;const i=ri();for(;n.pos<a;){const o=n.uint32();switch(o>>>3){case 1:if(o!==10)break;i.name=n.string();continue;case 2:if(o!==16)break;i.colorId=n.uint32();continue;case 3:if(o===29){i.vertices.push(n.float());continue}if(o===26){const r=n.uint32()+n.pos;for(;n.pos<r;)i.vertices.push(n.float());continue}break;case 4:if(o===32){i.indices.push(n.uint32());continue}if(o===34){const r=n.uint32()+n.pos;for(;n.pos<r;)i.indices.push(n.uint32());continue}break;case 5:if(o!==42)break;i.edges.push(K.decode(n,n.uint32()));continue}if((o&7)===4||o===0)break;n.skipType(o&7)}return i},fromJSON(e){return{name:zn(e.name)?globalThis.String(e.name):"",colorId:zn(e.colorId)?globalThis.Number(e.colorId):0,vertices:globalThis.Array.isArray(e==null?void 0:e.vertices)?e.vertices.map(t=>globalThis.Number(t)):[],indices:globalThis.Array.isArray(e==null?void 0:e.indices)?e.indices.map(t=>globalThis.Number(t)):[],edges:globalThis.Array.isArray(e==null?void 0:e.edges)?e.edges.map(t=>K.fromJSON(t)):[]}},toJSON(e){var n,a,i;const t={};return e.name!==""&&(t.name=e.name),e.colorId!==0&&(t.colorId=Math.round(e.colorId)),(n=e.vertices)!=null&&n.length&&(t.vertices=e.vertices),(a=e.indices)!=null&&a.length&&(t.indices=e.indices.map(o=>Math.round(o))),(i=e.edges)!=null&&i.length&&(t.edges=e.edges.map(o=>K.toJSON(o))),t},create(e){return dn.fromPartial(e!=null?e:{})},fromPartial(e){var n,a,i,o,r;const t=ri();return t.name=(n=e.name)!=null?n:"",t.colorId=(a=e.colorId)!=null?a:0,t.vertices=((i=e.vertices)==null?void 0:i.map(l=>l))||[],t.indices=((o=e.indices)==null?void 0:o.map(l=>l))||[],t.edges=((r=e.edges)==null?void 0:r.map(l=>K.fromPartial(l)))||[],t}};function zn(e){return e!=null}const Vu=(e,t)=>{var y,A,V,$;const n=_e.useScene(),a=m.useRef(null),i=m.useRef(null),o=m.useContext(Le),r=m.useContext(Lt),[l,s]=m.useState(u.Color3.White()),{id:c,visible:p=!0,vertices:f,indices:d,colorId:x,position:h,normals:T,material:P={type:$e.COLOR_ID},children:v,alpha:_=1,style:b,name:k="formation",highStyle:M,lowStyle:w,edges:S=[],actions:N,actionName:F}=e,B=He({url:P==null?void 0:P.texture,cacheType:Me.URL_PREFIX_MATCH}),I=He({url:P==null?void 0:P.sideTexture,cacheType:Me.URL_PREFIX_MATCH}),[D,E]=m.useState();m.useImperativeHandle(t,()=>i.current,[]),m.useEffect(()=>{if(a&&a.current&&n){const W=new u.VertexData;W.positions=f,W.indices=d,W.normals=T;const ne=a.current;W.applyToMesh(ne),ne.getScene().onAfterRenderObservable.addOnce(()=>{if(!ne.isDisposed()){const G=ne.getBoundingInfo();E(G.boundingBox)}})}},[d,f,n,c,T]),m.useEffect(()=>{a.current&&(a.current.metadata={pickable:N?{name:F!=null?F:k,onLeftClick:N.onLeftClick,onRightClick:N.onRightClick,onMiddleClick:N.onMiddleClick,onHover:N.onHover,extra:N.extra,needWorldPosition:N.needWorldPosition}:null})},[F,N,k]),m.useEffect(()=>{var W;s(P.type===$e.ONE_COLOR?(W=P==null?void 0:P.color)!=null?W:u.Color3.Random():x&&r.colorIDs[x]?new u.Color3(r.colorIDs[x].r,r.colorIDs[x].g,r.colorIDs[x].b):u.Color3.Random())},[r.colorIDs,x,P==null?void 0:P.color,P.type]);const L=(W,ne,ee)=>{const G=ne.subtract(W),le=1+1e3/u.Vector3.Distance(W,ne)*(ee-1),re=G.scale(le);return W.add(re)};return C.jsxs("transformNode",{name:`node-${k}-${c}`,setEnabled:p,children:[C.jsxs("transformNode",{name:`${k}`,position:h?h.multiply(Oe(o)):new u.Vector3(0,0,0),scaling:Oe(o),ref:i,children:[C.jsx("mesh",{name:`${k}-mesh`,ref:a,children:P.type===$e.TEXTURE?B?C.jsx(Kt,{name:`formationslice-${k}-mat`,backFaceCulling:!1,needDepthPrePass:P.needDepthPrePass===void 0?!1:P.needDepthPrePass,transparencyMode:u.Material.MATERIAL_ALPHABLEND,alphaMode:u.Engine.ALPHA_COMBINE,alpha:_,sideTexture:I,texture:B,tilingFactor:P.tilingFactor,sideTilingFactor:(y=P==null?void 0:P.sideTilingFactor)!=null?y:P==null?void 0:P.tilingFactor,mode:P.textureMode===void 0?qt.PLANE:P.textureMode,boundingBox:D,lines:P.lines,text:P.text,scaleDepth:o?o.scaleDepth:1,scalePlane:o?o.scalePlane:1,disableDepthWrite:P.disableDepthWrite}):C.jsx(C.Fragment,{}):P.type===$e.COLOR_CODEC?P.colorCodec?C.jsx(Mt,{name:`formation-${k}-mat`,backFaceCulling:!1,needDepthPrePass:P.needDepthPrePass===void 0?!1:P.needDepthPrePass,alpha:_,transparencyMode:u.Material.MATERIAL_ALPHABLEND,alphaMode:u.Engine.ALPHA_COMBINE,colorCodec:P.colorCodec,boundingBox:D,lines:P.lines,text:P.text,scaleDepth:o?o.scaleDepth:1,scalePlane:o?o.scalePlane:1,disableDepthWrite:P.disableDepthWrite}):C.jsx(C.Fragment,{}):P.type===$e.COLOR_ID?C.jsx("standardMaterial",{name:`formation-${k}-mat`,backFaceCulling:!1,needDepthPrePass:P.needDepthPrePass===void 0?!1:P.needDepthPrePass,specularColor:new u.Color3(0,0,0),ambientColor:new u.Color3(1,1,1),diffuseColor:l,alphaMode:u.Engine.ALPHA_COMBINE,alpha:_,transparencyMode:u.Material.MATERIAL_ALPHABLEND,disableDepthWrite:P.disableDepthWrite}):C.jsx("standardMaterial",{name:`formation-${k}-mat`,backFaceCulling:!1,needDepthPrePass:P.needDepthPrePass===void 0?!1:P.needDepthPrePass,specularColor:new u.Color3(0,0,0),ambientColor:new u.Color3(1,1,1),diffuseColor:l,alphaMode:u.Engine.ALPHA_COMBINE,alpha:_,transparencyMode:u.Material.MATERIAL_ALPHABLEND,disableDepthWrite:P.disableDepthWrite})}),b.position&&C.jsx("transformNode",{name:`${k}-title`,position:L(At(b.basePosition==="left"?S[4]:S[5]),b.position,(A=b.offset)!=null?A:1),scaling:ct(o),children:b.title&&C.jsx(Je,{text:b.title,fontSize:b.fontSize?b.fontSize:40,color:b.color?b.color:"black"})}),w&&w.position&&C.jsx("transformNode",{name:`${k}-up-title`,position:L(At(w.basePosition==="left"?S[4]:S[5]),w.position,(V=w.offset)!=null?V:1),scaling:ct(o),children:w.title&&C.jsx(Je,{text:w.title,fontSize:w.fontSize?w.fontSize:40,color:w.color?w.color:"black"})}),M&&M.position&&C.jsx("transformNode",{name:`${k}-down-title`,position:L(At(M.basePosition==="left"?S[4]:S[5]),M.position,($=M.offset)!=null?$:1),scaling:ct(o),children:M.title&&C.jsx(Je,{text:M.title,fontSize:M.fontSize?M.fontSize:40,color:M.color?M.color:"black"})})]}),v]})},$u=m.forwardRef(Vu),Yo=e=>{const[t,n]=m.useState([]),[a,i]=m.useState(""),{url:o,visible:r=!0,materials:l,actions:s,style:c,highStyle:p,lowStyle:f,basePosition:d="left"}=e,x=m.useContext(Le),h=je({url:o,cacheType:Me.URL_PREFIX_MATCH}),[T,P]=m.useState(u.Vector3.Zero());return m.useEffect(()=>{console.log("[Geo3DViewer] FormationSlice Loading: ",o)},[o]),m.useEffect(()=>{if(h){const v=Go.decode(new Uint8Array(h));v.center&&P(new u.Vector3(v.center.x,v.center.y,v.center.z));const _=v.slices.map(b=>{const k=[];return u.VertexData.ComputeNormals(b.vertices,b.indices,k),{name:b.name,colorId:b.colorId,vertices:b.vertices,indices:b.indices,edges:b.edges,normals:k}});return i(v.name),n(_),()=>{i(""),n([])}}},[h]),C.jsx(C.Fragment,{children:C.jsx("transformNode",{name:`foramtionslice-${a}-holder`,setEnabled:r,position:T.multiply(Oe(x)),children:t.map((v,_)=>{const b=v.edges.length>0?At(d==="left"?v.edges[0]:v.edges[2]):new u.Vector3(0,0,0),k=v.edges.length>0?At(d==="left"?v.edges[1]:v.edges[3]):new u.Vector3(0,0,0),M=u.Vector3.Lerp(b,k,.5);return C.jsx($u,{id:_,vertices:v.vertices,indices:v.indices,colorId:v.colorId,normals:v.normals,name:v.name,edges:v.edges,style:c?{position:M,title:v.name,basePosition:d,...c}:{},lowStyle:f?{position:k,title:(T.y+k.y).toFixed(0).toString(),basePosition:d,...f}:{},highStyle:p&&_===t.length-1?{position:b,title:(T.y+b.y).toFixed(0).toString(),basePosition:d,...p}:{},material:l?{...l[v.name],backFaceCulling:!1}:void 0,actions:s,actionName:a},_)})})})},Wu=e=>{const{name:t="node",text:n,fontSize:a,color:i,position:o=u.Vector3.Zero(),scale:r=u.Vector3.One(),blink:l=!1}=e,[s,c]=m.useState(!0);return m.useEffect(()=>{const p=setInterval(()=>{l&&c(f=>!f)},1e3);return()=>{clearInterval(p)}},[l]),C.jsx("transformNode",{name:`${t}-text`,position:o,scaling:r,setEnabled:s,children:C.jsx(Je,{name:t,text:n,fontSize:a,color:i})})};var Bt=(e=>(e[e.NONE=0]="NONE",e[e.BOTTOM_LEFT=1]="BOTTOM_LEFT",e[e.BOTTOM_RIGHT=2]="BOTTOM_RIGHT",e[e.TOP_LEFT=3]="TOP_LEFT",e[e.TOP_RIGHT=4]="TOP_RIGHT",e))(Bt||{});const la=({target:e,radius:t,alpha:n,beta:a,axesViewerOffset:i=u.Vector3.Zero(),panningSensibility:o=2,wheelDeltaPercentage:r=0,axesViewer:l=0,farPlane:s=1e4,skipPickingWhenCameraMoves:c=!1})=>{const p=_e.useScene(),f=m.useContext(Le),[d,x]=m.useState(null),[h,T]=m.useState(null),[P,v]=m.useState(n),[_,b]=m.useState(a),[,k]=m.useState(null),M=m.useCallback(B=>{T(B)},[]),{setViewCamera:w}=m.useContext(Oo),S=m.useCallback(()=>{if(h&&d){const B=new u.Vector3;B.addInPlace(h.position),B.addInPlace(h.getDirection(new u.Vector3(0,0,25))),l==4?(B.addInPlace(h.getDirection(new u.Vector3(0,7+i.y,0))),B.addInPlace(h.getDirection(new u.Vector3(15+i.x,0,0)))):l==3?(B.addInPlace(h.getDirection(new u.Vector3(0,7+i.y,0))),B.addInPlace(h.getDirection(new u.Vector3(-15+i.x,0,0)))):l==2?(B.addInPlace(h.getDirection(new u.Vector3(0,-7+i.y,0))),B.addInPlace(h.getDirection(new u.Vector3(15+i.x,0,0)))):l==1&&(B.addInPlace(h.getDirection(new u.Vector3(0,-7+i.y,0))),B.addInPlace(h.getDirection(new u.Vector3(-15+i.x,0,0)))),d.xAxis.position=B.clone(),d.yAxis.position=B.clone(),d.zAxis.position=B.clone()}},[h,d,l,i.y,i.x]);m.useEffect(()=>{if(p&&l!=0){const B=new u.AxesViewer(p,2,null);return x(B),()=>{B==null||B.dispose(),x(null)}}},[p,l]),m.useEffect(()=>{S()},[S]);const N=m.useCallback(B=>{if(f&&f.min&&f.max)return u.Vector3.Clamp(B,f==null?void 0:f.min,f==null?void 0:f.max)},[f]),F=m.useCallback(B=>{p&&(p.skipPointerMovePicking=B)},[p]);return m.useEffect(()=>{if(!p||!h)return;const B=h.onViewMatrixChangedObservable.add(()=>{c&&(F(!0),k(I=>(I&&clearTimeout(I),setTimeout(()=>{F(!1),k(null)},250)))),v(h.alpha),b(h.beta),S()});return()=>{h.onViewMatrixChangedObservable.remove(B),k(I=>(I&&clearTimeout(I),null)),F(!1)}},[p,l,h,f,d,S,N,F,c]),m.useEffect(()=>{w(p&&h?h:void 0)},[p,h,w]),m.useEffect(()=>{},[N,f,e]),C.jsx(C.Fragment,{children:e&&C.jsx("arcRotateCamera",{name:"rootCamera",target:e,radius:t,alpha:P,beta:_,maxZ:s,panningSensibility:o,wheelDeltaPercentage:r,ref:M,setActiveOnSceneIfNoneActive:!0})})},Uu=(e,t)=>{const{position:n=u.Vector3.Zero(),axesViewer:a=Bt.NONE,axesViewerOffset:i=u.Vector3.Zero(),skipPickingWhenCameraMoves:o=!1,wheelDeltaPercentage:r=3,rotationSensibility:l=1,panningSensibility:s=10}=e,c=_e.useScene(),p=m.useContext(Le),[f,d]=m.useState(null),[x,h]=m.useState(null),{setViewCamera:T,cameraRefObject:P}=m.useContext(Oo),[,v]=m.useState(null),_=m.useRef(null),[b,k]=m.useState(null),M=m.useRef(null),w=m.useCallback(I=>{c&&(c.skipPointerMovePicking=I)},[c]);m.useEffect(()=>(M.current=new u.ArcRotateCamera("dummy-camera",0,0,.1,u.Vector3.Zero(),c||void 0,!1),()=>{var I;(I=M.current)==null||I.dispose()}),[c]),m.useEffect(()=>{if(c){const I=x,D=c.onPointerObservable.add(E=>{if(E.type===u.PointerEventTypes.POINTERDOWN&&(_.current=new u.Vector2(E.event.clientX,E.event.clientY)),E.type===u.PointerEventTypes.POINTERUP&&(_.current=null),E.type===u.PointerEventTypes.POINTERMOVE&&_.current){const L=E.event.clientX-_.current.x,y=E.event.clientY-_.current.y;if(E.event.buttons===1){let A=null;(I.lockedTarget||b)&&(I.lockedTarget&&(A=I.lockedTarget.position),b&&(A=b)),A&&M.current?(M.current.target=A,M.current.position=I.position.clone(),M.current.wheelDeltaPercentage=r,M.current.panningSensibility=s,M.current.alpha+=L/100*l,M.current.beta+=y/100*l,M.current.update(),I.position=M.current.position.clone(),I.rotation=M.current.rotation.clone()):(I.rotation.y-=L/100*l,I.rotation.x-=y/100*l)}E.event.buttons===2&&(I.position.x-=L/100*s,I.position.y+=y/100*s),_.current=new u.Vector2(E.event.clientX,E.event.clientY)}});return()=>{c.onPointerObservable.remove(D)}}},[b,s,x,l,c,r]);const S=m.useCallback(I=>{I&&(I.inputs.addMouseWheel(),I.inputs.removeMouse(),T(I),h(I))},[T]);m.useEffect(()=>{if(x){const I=x.inputs.attached.mousewheel;I.wheelPrecisionX=r,I.wheelPrecisionY=r,I.wheelPrecisionZ=r}},[x,r]);const N=m.useCallback(()=>{if(x&&f){const I=new u.Vector3;I.addInPlace(x.position),I.addInPlace(x.getDirection(new u.Vector3(0,0,25))),a==Bt.TOP_RIGHT?(I.addInPlace(x.getDirection(new u.Vector3(0,7+i.y,0))),I.addInPlace(x.getDirection(new u.Vector3(15+i.x,0,0)))):a==Bt.TOP_LEFT?(I.addInPlace(x.getDirection(new u.Vector3(0,7+i.y,0))),I.addInPlace(x.getDirection(new u.Vector3(-15+i.x,0,0)))):a==Bt.BOTTOM_RIGHT?(I.addInPlace(x.getDirection(new u.Vector3(0,-7+i.y,0))),I.addInPlace(x.getDirection(new u.Vector3(15+i.x,0,0)))):a==Bt.BOTTOM_LEFT&&(I.addInPlace(x.getDirection(new u.Vector3(0,-7+i.y,0))),I.addInPlace(x.getDirection(new u.Vector3(-15+i.x,0,0)))),f.xAxis.position=I.clone(),f.yAxis.position=I.clone(),f.zAxis.position=I.clone()}},[x,f,a,i.y,i.x]);m.useEffect(()=>{if(c&&a!=Bt.NONE){const I=new u.AxesViewer(c,2,null);return d(I),()=>{I==null||I.dispose(),d(null)}}},[c,a]),m.useEffect(()=>{N()},[N]),m.useEffect(()=>{T(c&&x?x:void 0)},[c,x,T]),m.useEffect(()=>{if(!c||!x)return;const I=x.onViewMatrixChangedObservable.add(()=>{o&&(w(!0),v(D=>(D&&clearTimeout(D),setTimeout(()=>{w(!1),v(null)},250)))),N()});return()=>{x.onViewMatrixChangedObservable.remove(I),v(D=>(D&&clearTimeout(D),null)),w(!1)}},[c,a,x,p,f,N,o,w]);const[F,B]=m.useState();return m.useEffect(()=>{if(x){const I={lookAt:D=>{x&&x.setTarget(D)},updatePosition:D=>{x&&(x.position=D)},lockTarget:D=>{x&&(k(null),x.lockedTarget=D)},lockTo:D=>{x&&(x.lockedTarget=null,k(D))}};B(I),P&&P.current&&(P.current.rawCamera=x,P.current.cameraTools=I)}},[P,x]),m.useImperativeHandle(t,()=>({rawCamera:x,cameraTools:F}),[F,x]),C.jsx("universalCamera",{name:"universal-main-camera",position:n,ref:S,maxZ:0})},Hu=m.forwardRef(Uu);class Zu extends u.BaseCameraPointersInput{constructor(){super(...arguments);ve(this,"camera");ve(this,"buttons",[0,1,2,4]);ve(this,"panningSensibility",10);ve(this,"angularSensibility",1e4);ve(this,"_isPanClick",!1);ve(this,"_isPinching",!1)}getClassName(){return"FreeCameraPointersInput"}onButtonDown(n){(n.buttons===1||n.buttons===4)&&(this._isPinching=!0),n.buttons===2&&(this._isPanClick=!0)}onButtonUp(n){n&&(this._isPanClick=!1,this._isPinching=!1)}onTouch(n,a,i){if(this.panningSensibility!==0&&this._isPanClick){const o=-a/this.panningSensibility,r=i/this.panningSensibility;this.camera._localDirection.copyFromFloats(o,r,0),this.camera.getViewMatrix().invertToRef(this.camera._cameraTransformMatrix),u.Vector3.TransformNormalToRef(this.camera._localDirection,this.camera._cameraTransformMatrix,this.camera._transformedDirection),this.camera.cameraDirection.addInPlace(this.camera._transformedDirection)}if(this.angularSensibility!==0&&this._isPinching){const o=u.Quaternion.FromEulerAngles(this.camera.rotation.x,this.camera.rotation.y,this.camera.rotation.z),r=u.Quaternion.RotationAxis(u.Axis.Y,u.Tools.ToDegrees(a/this.angularSensibility)),l=u.Quaternion.RotationAxis(u.Axis.X,u.Tools.ToDegrees(i/this.angularSensibility)),s=o.multiply(r).multiply(l);this.camera.rotation=s.toEulerAngles()}}onLostFocus(){this._isPanClick=!1,this._isPinching=!1}}const Gu=e=>{const{position:t,target:n=new u.Vector3(0,0,0),panningSensibility:a=5,angularSensibility:i=2e3,skipPickingWhenCameraMoves:o=!1}=e,r=_e.useScene(),l=m.useRef(null),s=m.useRef(null),c=m.useCallback(p=>{r&&(r.skipPointerMovePicking=p)},[r]);return m.useEffect(()=>{if(l.current){l.current.inputs.removeByType("FreeCameraMouseInput");const p=new Zu,f=new u.FreeCameraMouseWheelInput;l.current.inputs.add(p),l.current.inputs.add(f)}},[]),m.useEffect(()=>{l.current&&n&&l.current.setTarget(n)},[n]),m.useEffect(()=>{if(!r||!l.current)return;const p=l.current.onViewMatrixChangedObservable.add(()=>{o&&(c(!0),s.current&&clearTimeout(s.current),s.current=setTimeout(()=>{c(!1),s.current=null},250))});return()=>{var f;(f=l.current)==null||f.onViewMatrixChangedObservable.remove(p),s.current&&(clearTimeout(s.current),s.current=null),c(!1)}},[r,c,o]),m.useEffect(()=>{if(l.current){if(l.current.inputs.attached.pointers){const p=l.current.inputs.attached.pointers;p.panningSensibility=Math.abs(a),p.angularSensibility=Math.abs(i)}if(l.current.inputs.attached.pointersPanning){const p=l.current.inputs.attached.pointersPanning;p.panningSensibility=Math.abs(a)}if(l.current.inputs.attached.around){const p=l.current.inputs.attached.around;p.angularSensibility=Math.abs(i)}}},[i,a]),C.jsx("freeCamera",{name:"rootCamera",position:t,ref:l})};class Yu extends u.TransformNode{constructor(n,a,i){super(n,a);ve(this,"_showDepthTexture",!1);ve(this,"_postProcess");this._postProcess=i,this.showDepthTexture=!1,this.inspectableCustomProperties=[{label:"Show Depth Texture",propertyName:"showDepthTexture",type:u.InspectableType.Checkbox}]}set showDepthTexture(n){var a,i;this._showDepthTexture=n,this._postProcess&&(this._showDepthTexture?(a=this.getScene().activeCamera)==null||a.attachPostProcess(this._postProcess):(i=this.getScene().activeCamera)==null||i.detachPostProcess(this._postProcess))}get showDepthTexture(){return this._showDepthTexture}}const Ju=()=>{const e=_e.useEngine(),t=_e.useScene();return m.useEffect(()=>{if(t&&e){u.Effect.ShadersStore.depthbufferPixelShader=`#ifdef GL_ES
|
|
1212
1212
|
precision highp float;
|
|
1213
1213
|
#endif
|
|
1214
1214
|
|
|
@@ -1241,7 +1241,7 @@ precision highp float;
|
|
|
1241
1241
|
|
|
1242
1242
|
void main(void)
|
|
1243
1243
|
{}`;const a=new u.PostProcess("GPU Picking Display","gpuPickingBuffer",null,null,1,null,void 0,e,!0);a.onApply=r=>{r._bindTexture("textureSampler",n.gpuPickingTexture.current.getInternalTexture())};const i=new Xu("GPU Picking Debugger",t,a),o=t.getTransformNodeByName("Debugger");return o&&(i.parent=o),()=>{var r;(r=t.activeCamera)==null||r.detachPostProcess(a),i&&t.removeTransformNode(i),i.dispose(),a.dispose()}}},[t,e,n]),C.jsx(C.Fragment,{})},Ku=({showDebugLayer:e=!1})=>{const t=_e.useScene(),n=_e.useEngine();return m.useEffect(()=>{n&&t&&(e?(n.captureGPUFrameTime=a=>{},jn.Inspector.Show(t,{embedMode:!0})):jn.Inspector.Hide())},[n,t,e]),m.useEffect(()=>()=>{t&&jn.Inspector.Hide()},[t]),C.jsxs("transformNode",{name:"Debugger",children:[C.jsx(Ju,{}),C.jsx(qu,{})]})},Qu=()=>{const e=_e.useScene(),t=_e.useEngine();return m.useEffect(()=>{const n=t;if(window.BABYLON&&n)return window.BABYLON.EngineStore.Instances.push(n),rs.registerBuiltInLoaders(),()=>{if(window.BABYLON){const a=window.BABYLON.EngineStore.Instances.indexOf(n);a>-1&&window.BABYLON.EngineStore.Instances.splice(a,1)}}},[t]),m.useEffect(()=>{const n=t;if(n)return u.EngineStore.Instances.push(n),()=>{const a=window.BABYLON.EngineStore.Instances.indexOf(n);a>-1&&window.BABYLON.EngineStore.Instances.splice(a,1)}},[t]),m.useEffect(()=>{const n=e;if(window.BABYLON&&n)return window.BABYLON.EngineStore._LastCreatedScene=e,()=>{window.BABYLON&&window.BABYLON.EngineStore._LastCreatedScene===n&&(window.BABYLON.EngineStore._LastCreatedScene=null)}},[e]),m.useEffect(()=>{const n=e;if(n)return u.EngineStore._LastCreatedScene=e,()=>{u.EngineStore._LastCreatedScene===n&&(u.EngineStore._LastCreatedScene=null)}},[e]),m.useEffect(()=>{e&&(e._forceBlockMaterialDirtyMechanism=a=>{e._blockMaterialDirtyMechanism=a})},[e]),C.jsx(C.Fragment,{})};class ju{constructor(){ve(this,"urls",[]);ve(this,"resources",new Map);ve(this,"listeners",new Map);this.urls=[]}addListener(t,n){var a;this.listeners.has(t)?(a=this.listeners.get(t))==null||a.push(n):this.listeners.set(t,[n])}removeListener(t,n){var a,i;if(this.listeners.has(t)){const o=(a=this.listeners.get(t))==null?void 0:a.findIndex(r=>r===n);o!==void 0&&o!==-1&&((i=this.listeners.get(t))==null||i.splice(o,1))}}notifyProgress(t,n){var a;(a=this.listeners.get(t))==null||a.forEach(i=>i.onProgress(n))}notifyComplete(t){var n;(n=this.listeners.get(t))==null||n.forEach(a=>a.onComplete(this.resources.get(t)))}notifyError(t,n){var a;(a=this.listeners.get(t))==null||a.forEach(i=>i.onError(n))}download(t,n="BIN"){if(n==="BIN"){Ut.get(t,{responseType:"arraybuffer"}).then(a=>{console.log(a),this.resources.set(t,a.data),this.notifyComplete(t)}).catch(a=>{this.notifyError(t,a)});return}}load(t,n,a){this.urls.findIndex(o=>o===t)===-1?(this.urls.push(t),this.download(t,n),this.addListener(t,a)):this.resources.get(t)?this.notifyComplete(t):this.addListener(t,a)}}const ca=m.createContext(void 0),ef=(e,t="BIN")=>{const n=m.useContext(ca),[a,i]=m.useState(void 0),o=m.useMemo(()=>{const r={onProgress:function(l){console.log(l)},onComplete:function(l){console.log(e,l),i(l)},onError:function(l){console.log(l),n==null||n.removeListener(e,r)}};return r},[n,e]);return m.useEffect(()=>(n==null||n.load(e,t,o),()=>{n==null||n.removeListener(e,o)}),[o,n,t,e]),a},tf=(e,t)=>{const{children:n,showDebugLayer:a=!1,meta:i,colorProvider:o,cacheProvider:r,options:l={backgroundColor:u.Color4.FromArray([.2,.2,.3,1]),light:{intensity:1,direction:new u.Vector3(1,1,1)}}}=e,{light:s={intensity:1,direction:new u.Vector3(1,1,1)}}=l,{intensity:c=1,direction:p=new u.Vector3(1,1,1)}=s,f=m.useRef(null),[d,x]=m.useState(!1);return m.useEffect(()=>{console.log(`
|
|
1244
|
-
%c Geo3DViewer Library %c Version: 1.7.
|
|
1244
|
+
%c Geo3DViewer Library %c Version: 1.7.40 %c
|
|
1245
1245
|
`,"color:#e0e0e0;background:#873e23;padding:5px 0;border-top-left-radius:5px;border-bottom-left-radius:5px;","color:#455a64;background:#e0e0e0;padding:5px 0;","color:#455a64;background:#e0e0e0;padding:5px 0;border-top-right-radius:5px;border-bottom-right-radius:5px;")},[]),m.useImperativeHandle(t,()=>({scene:f,camera:null}),[f]),m.useEffect(()=>{a&&x(!0)},[a]),C.jsx(_e.Engine,{antialias:!0,adaptToDeviceRatio:!0,canvasId:"rootGeo3DCanvas",engineOptions:{useHighPrecisionFloats:!0,depth:!0,useHighPrecisionMatrix:!0,stencil:!0},children:C.jsxs(_e.Scene,{clearColor:l.backgroundColor,useRightHandedSystem:l.useRightHandedSystem,children:[C.jsx(Qu,{}),C.jsx("ground",{name:"picking-material-holder",setEnabled:!1,children:C.jsx(Pu,{})}),C.jsx(ca.Provider,{value:new ju,children:C.jsxs(bs,{workspaceMeta:i,colorProvider:o,cacheProvider:r,ref:f,children:[d||a?C.jsx(Ku,{showDebugLayer:a}):null,C.jsx("hemisphericLight",{name:"light",intensity:c,direction:p}),n]})}),l.environment?C.jsx("cubeTexture",{assignTo:"environmentTexture",rootUrl:l.environment}):C.jsx(C.Fragment,{})]})})},Jo=m.forwardRef(tf);var Et=(e=>(e[e.ATTRIBUTE=0]="ATTRIBUTE",e[e.COLOR=1]="COLOR",e[e.STATIC_ATTRIBUTE=2]="STATIC_ATTRIBUTE",e[e.STATIC_COLOR=3]="STATIC_COLOR",e[e.UNRECOGNIZED=-1]="UNRECOGNIZED",e))(Et||{});function nf(e){switch(e){case 0:case"ATTRIBUTE":return 0;case 1:case"COLOR":return 1;case 2:case"STATIC_ATTRIBUTE":return 2;case 3:case"STATIC_COLOR":return 3;case-1:case"UNRECOGNIZED":default:return-1}}function of(e){switch(e){case 0:return"ATTRIBUTE";case 1:return"COLOR";case 2:return"STATIC_ATTRIBUTE";case 3:return"STATIC_COLOR";case-1:default:return"UNRECOGNIZED"}}function ii(){return{name:"",step:0,xCount:0,yCount:0,zCount:0,xSliceUrl:"",ySliceUrl:"",zSliceUrl:"",mode:0}}const ua={encode(e,t=se.Writer.create()){return e.name!==""&&t.uint32(10).string(e.name),e.step!==0&&t.uint32(16).uint32(e.step),e.xCount!==0&&t.uint32(24).uint32(e.xCount),e.yCount!==0&&t.uint32(32).uint32(e.yCount),e.zCount!==0&&t.uint32(40).uint32(e.zCount),e.xSliceUrl!==""&&t.uint32(50).string(e.xSliceUrl),e.ySliceUrl!==""&&t.uint32(58).string(e.ySliceUrl),e.zSliceUrl!==""&&t.uint32(66).string(e.zSliceUrl),e.mode!==0&&t.uint32(72).int32(e.mode),t},decode(e,t){const n=e instanceof se.Reader?e:se.Reader.create(e);let a=t===void 0?n.len:n.pos+t;const i=ii();for(;n.pos<a;){const o=n.uint32();switch(o>>>3){case 1:if(o!==10)break;i.name=n.string();continue;case 2:if(o!==16)break;i.step=n.uint32();continue;case 3:if(o!==24)break;i.xCount=n.uint32();continue;case 4:if(o!==32)break;i.yCount=n.uint32();continue;case 5:if(o!==40)break;i.zCount=n.uint32();continue;case 6:if(o!==50)break;i.xSliceUrl=n.string();continue;case 7:if(o!==58)break;i.ySliceUrl=n.string();continue;case 8:if(o!==66)break;i.zSliceUrl=n.string();continue;case 9:if(o!==72)break;i.mode=n.int32();continue}if((o&7)===4||o===0)break;n.skipType(o&7)}return i},fromJSON(e){return{name:kt(e.name)?globalThis.String(e.name):"",step:kt(e.step)?globalThis.Number(e.step):0,xCount:kt(e.xCount)?globalThis.Number(e.xCount):0,yCount:kt(e.yCount)?globalThis.Number(e.yCount):0,zCount:kt(e.zCount)?globalThis.Number(e.zCount):0,xSliceUrl:kt(e.xSliceUrl)?globalThis.String(e.xSliceUrl):"",ySliceUrl:kt(e.ySliceUrl)?globalThis.String(e.ySliceUrl):"",zSliceUrl:kt(e.zSliceUrl)?globalThis.String(e.zSliceUrl):"",mode:kt(e.mode)?nf(e.mode):0}},toJSON(e){const t={};return e.name!==""&&(t.name=e.name),e.step!==0&&(t.step=Math.round(e.step)),e.xCount!==0&&(t.xCount=Math.round(e.xCount)),e.yCount!==0&&(t.yCount=Math.round(e.yCount)),e.zCount!==0&&(t.zCount=Math.round(e.zCount)),e.xSliceUrl!==""&&(t.xSliceUrl=e.xSliceUrl),e.ySliceUrl!==""&&(t.ySliceUrl=e.ySliceUrl),e.zSliceUrl!==""&&(t.zSliceUrl=e.zSliceUrl),e.mode!==0&&(t.mode=of(e.mode)),t},create(e){return ua.fromPartial(e!=null?e:{})},fromPartial(e){var n,a,i,o,r,l,s,c,p;const t=ii();return t.name=(n=e.name)!=null?n:"",t.step=(a=e.step)!=null?a:0,t.xCount=(i=e.xCount)!=null?i:0,t.yCount=(o=e.yCount)!=null?o:0,t.zCount=(r=e.zCount)!=null?r:0,t.xSliceUrl=(l=e.xSliceUrl)!=null?l:"",t.ySliceUrl=(s=e.ySliceUrl)!=null?s:"",t.zSliceUrl=(c=e.zSliceUrl)!=null?c:"",t.mode=(p=e.mode)!=null?p:0,t}};function kt(e){return e!=null}const fa=({name:e,url:t,step:n,visible:a=!0,colorCodec:i,alpha:o=1,actions:r,materials:l})=>{const[s,c]=m.useState(),[p,f]=m.useState(0),d=je({url:t,cacheType:Me.URL_PREFIX_MATCH});return m.useEffect(()=>{console.log("[Geo3DViewer] GriDDiagram Loading: ",t)},[t]),m.useEffect(()=>{if(d){const x=ua.decode(new Uint8Array(d)),{xCount:h,zCount:T,xSliceUrl:P,zSliceUrl:v}=x,_=[];if(x.mode===Et.ATTRIBUTE||x.mode===Et.COLOR){if(n<=0){console.error("[Geo3DViewer] 此文件为动态数据文件,step 值必须大于 0"),c([]),f(0);return}let b=0;for(let k=0;k<h;k+=n)_.push(P.replace("%s",k.toString())),b=k;b>=h&&_.push(P.replace("%s",(h-1).toString()));for(let k=0;k<T;k+=n)_.push(v.replace("%s",k.toString())),b=k;b>=T&&_.push(v.replace("%s",(T-1).toString()))}else if(x.mode===Et.STATIC_ATTRIBUTE||x.mode===Et.STATIC_COLOR){if(n!==0){console.error("[Geo3DViewer] 静态栅状图数据必须传入 step=0 以确认您明确此数据无法使用动态加载模式"),c([]),f(0);return}for(let b=0;b<h;b+=1)_.push(P.replace("%s",b.toString()))}return c(_),f(x.mode===Et.ATTRIBUTE?1:x.mode===Et.COLOR?2:x.mode===Et.STATIC_ATTRIBUTE?1:x.mode===Et.STATIC_COLOR?2:0),()=>{c([]),f(0)}}},[d,n]),C.jsx("abstractMesh",{name:`gridDiagram-${e}`,children:p===1?s?s.map((x,h)=>C.jsx(Zo,{name:e,url:x,visible:a,colorCodec:i,alpha:o,actions:r},`densityslice-group-${e}-${x}-${h}`)):C.jsx(C.Fragment,{}):p===2?s?s.map((x,h)=>C.jsx(Yo,{url:x,visible:a,materials:l,actions:r},`formationslice-group-${e}-${x}-${h}`)):C.jsx(C.Fragment,{}):C.jsx(C.Fragment,{})})},da=({name:e,position:t,width:n,height:a,color:i,lineWidth:o,rotation:r,showDebugPlane:l=!1})=>{const s=m.useContext(Le),c=m.useRef(null),p=Tu({name:e,lineColor:i,lineWidth:o});return m.useEffect(()=>{c.current&&(c.current.material=p)},[p]),C.jsxs("transformNode",{name:`intersecting-line-${e}`,position:t.multiply(Oe(s)),rotation:r||u.Vector3.Zero(),children:[C.jsx("plane",{name:e,width:n,height:a,isPickable:!1,isBlocker:!1,ref:c}),C.jsx("plane",{name:e,width:n,height:a,isPickable:!1,isBlocker:!1,setEnabled:l,children:C.jsx("standardMaterial",{name:"intersecting-line-material",diffuseColor:u.Color3.Gray(),backFaceCulling:!1,alpha:.5,transparencyMode:u.Material.MATERIAL_ALPHABLEND})})]})},pa=e=>{const t=_e.useScene(),{target:n,distance:a}=e;return m.useEffect(()=>{if(t&&t.activeCamera&&n){const i=t.activeCamera;let o=new u.Vector3(0,0,0);if(typeof n=="string"){const r=t.getMeshById(n);r&&(o=r.getBoundingInfo().boundingBox.center)}else n.position?o=n.getBoundingInfo().boundingBox.center:o=n;if(i instanceof u.ArcRotateCamera){i.setTarget(o),i.radius=a;return}if(i instanceof u.FreeCamera){const r=o,l=i.position.clone(),s=a/u.Vector3.Distance(r,l),p=l.subtract(r).scale(s),f=r.add(p);i.position=f,i.setTarget(o)}return}},[a,t,n]),null},ha=e=>{const t=e.getChildren();return t.length>0?[e,...ha(t[0])]:[e]},rf=e=>{if(!e.hasVertexAlpha)return!1;const t=e.getVertexBuffer(u.VertexBuffer.ColorKind),n=e.getVerticesData(u.VertexBuffer.ColorKind);if(!t||!n)return!1;const a=t.getSize();if(a<4)return!1;let i=!1,o=!1;for(let r=3;r<n.length;r+=a){const l=n[r];if(!Number.isFinite(l))return!0;if(i=!0,l>1/255){o=!0;break}}return i&&!o},af=({name:e,url:t,position:n=u.Vector3.Zero(),rotation:a=u.Vector3.Zero(),localScale:i=1,visible:o=!0,showPickingBox:r=!1,useGlobalScale:l=!1,actions:s,alpha:c=1,boneRotation:p,pickingBoxScale:f=u.Vector3.One(),labelStyle:d},x)=>{const h=_e.useScene(),T=Ri({url:t}),P=m.useRef(null),v=m.useRef(null),[_,b]=m.useState(null),[k,M]=m.useState(5),[w,S]=m.useState(5),[N,F]=m.useState(5),[B,I]=m.useState(u.Vector3.Zero()),[D,E]=m.useState(u.Vector3.One()),[L,y]=m.useState([]),A=m.useContext(Le),{scaleWithParent:V=!0}=d||{};return m.useEffect(()=>{console.log("[Geo3DViewer] ModelLoader Loading: ",t)},[t]),m.useImperativeHandle(x,()=>v.current,[]),m.useEffect(()=>{if(T){const $=T.instantiateModelsToScene(W=>`${e}-${W}`,!0);return console.log("[Geo3DViewer] ModelLoader 实例化: ",e),b($),()=>{console.log("[Geo3DViewer] ModelLoader 反实例化: ",e),b(null)}}},[T,e]),m.useEffect(()=>{if(_){const $=_,W=$.skeletons;if(W&&W.length>0){const ee=W[0].bones,G=[];ee.filter(le=>le.name==="MorphBoneBase").forEach((le,re)=>{if(re===0){const oe=ha(le);G.push(...oe.map(Y=>{var ce;return(ce=Y.getTransformNode())!=null?ce:Y}))}}),y(G),console.log("[Geo3DViewer] ModelLoader 设定 Morph 骨骼: ",G)}return()=>{console.log("[Geo3DViewer] ModelLoader 注销 Model"),$.dispose(),y([])}}},[_]),m.useEffect(()=>{p&&L&&(console.log("[Geo3DViewer] ModelLoader 设定骨骼旋转"),L.forEach(($,W)=>{p.length>W?$.rotation=p[W]:$.rotation=u.Vector3.Zero()}),(!p||p.length===0)&&console.log("[Geo3DViewer] ModelLoader 的鼠标拾取功能由于 boneRotation 被禁用"))},[p,L]),m.useEffect(()=>{P.current&&(P.current.metadata={pickable:s?{name:e,onLeftClick:s.onLeftClick,onRightClick:s.onRightClick,onMiddleClick:s.onMiddleClick,onHover:s.onHover,needWorldPosition:s.needWorldPosition,valueCallback:null,extra:s.extra}:null})},[s,e]),m.useEffect(()=>{if(h&&_&&v.current){console.log("[Geo3DViewer] ModelLoader 创建容器: ",e);const $=new u.TransformNode(`amesh-model-${e}`);$.parent=v.current,_.rootNodes.forEach(oe=>{oe&&(oe.parent=$)}),$.computeWorldMatrix(!0),u.PivotTools._RemoveAndStorePivotPoint($);const W=$.parent;$.parent=null;const ne=u.Quaternion.RotationYawPitchRoll($.rotation.y,$.rotation.x,$.rotation.z),ee=new u.Vector3($.position.x,$.position.y,$.position.z);$.rotation.set(0,0,0),$.position.set(0,0,0);const G=$.getHierarchyBoundingVectors(!0),le=G.max.subtract(G.min);M(le.y),S(le.z),F(le.x),E(ne.toEulerAngles());const re=new u.Vector3((G.max.x+G.min.x)/2,(G.max.y+G.min.y)/2,(G.max.z+G.min.z)/2);return I(re),$.position=ee,$.rotationQuaternion=ne,$.parent=W,u.PivotTools._RestorePivotPoint($),console.log("[Geo3DViewer] 创建 ModelLoader 鼠标拾取外框 ",e," 于 ",re," 大小为 ",le.x,le.y,le.z),()=>{console.log("[Geo3DViewer] ModelLoader 注销容器: ",e),$.dispose()}}},[_,e,h]),m.useEffect(()=>{_&&_.rootNodes.forEach($=>{$.getChildMeshes().forEach(W=>{rf(W)&&(console.warn(`[Geo3DViewer] ModelLoader disabled broken vertex alpha for ${W.name||e}`),W.hasVertexAlpha=!1),W.material&&(W.material.alpha=c,W.material.transparencyMode=c<1?u.Material.MATERIAL_ALPHABLEND:u.Material.MATERIAL_OPAQUE)})})},[_,c]),C.jsx("transformNode",{name:`transform-model-${e}`,position:n,rotation:a,scalingDeterminant:i,setEnabled:o,children:C.jsxs("transformNode",{name:`transform-model-global-${e}`,ref:v,scaling:l?new u.Vector3(A&&A.scalePlane?A.scalePlane:1,A&&A.scaleDepth?A.scaleDepth:1,A&&A.scalePlane?A.scalePlane:1):new u.Vector3(1,1,1),children:[d?C.jsx("transformNode",{name:`transform-model-label-${e}`,position:B.add(d!=null&&d.offset?d.offset.multiplyByFloats(A!=null&&A.scalePlane?A==null?void 0:A.scalePlane:1,1,A!=null&&A.scalePlane?A==null?void 0:A.scalePlane:1):u.Vector3.Zero()),scalingDeterminant:V?i*3:3,children:C.jsx(Je,{text:d.title,fontSize:d.fontSize?d.fontSize:40,color:d.color?d.color:"white"})}):C.jsx(C.Fragment,{}),C.jsx("box",{name:`pick-mesh-${e}`,ref:P,size:1,scaling:new u.Vector3(N,k,w).multiply(f),position:B,rotation:D,setEnabled:p?p.length===0:!0,children:C.jsx("standardMaterial",{name:`pick-mesh-${e}-mat`,alpha:r?.5:0})})]})})},Kn=m.forwardRef(af),sf=({name:e,url:t,position:n=u.Vector3.Zero(),rotation:a=u.Vector3.Zero(),localScale:i=1,visible:o=!0},r)=>{const l=_e.useScene(),s=Ri({url:t}),c=m.useRef(null),[p,f]=m.useState(null);return m.useEffect(()=>{console.log("[Geo3DViewer] ModelLoader Loading: ",t)},[t]),m.useImperativeHandle(r,()=>c.current,[]),m.useEffect(()=>{if(s){const d=s.instantiateModelsToScene(x=>`${e}-${x}`,!0);return console.log("[Geo3DViewer] ModelLoader 实例化: ",e),f(d),()=>{console.log("[Geo3DViewer] ModelLoader 反实例化: ",e),f(null)}}},[s,e]),m.useEffect(()=>{l&&p&&c.current&&(l.animationGroups.forEach(d=>{console.log("play animtion:"+d.name),d.start(!0)}),p.rootNodes.forEach(d=>{d&&(d.parent=c.current)}))},[p,e,l]),C.jsx("transformNode",{name:`transform-model-${e}`,position:n,rotation:a,scalingDeterminant:i,setEnabled:o,ref:c})},lf=m.forwardRef(sf),ma=()=>{const e=_e.useScene();return m.useEffect(()=>{if(e){const t=u.SceneOptimizerOptions.ModerateDegradationAllowed();t.optimizations;const n=new u.SceneOptimizer(e,t,!0,!0);return n.start(),console.log("[Geo3DViewer] 渐进式优化器已启动,如遭遇技术性渲染问题,请优先尝试禁用此优化器。"),()=>{n.stop(),n.dispose(),console.log("[Geo3DViewer] 渐进式优化器已停止。")}}},[e]),C.jsx(C.Fragment,{})},cf=e=>{const{name:t,url:n,rootURL:a,doNotStart:i,capacity:o,position:r=new u.Vector3}=e,l=_e.useScene(),[s,c]=m.useState();return m.useEffect(()=>()=>{s&&s.dispose()},[s]),m.useEffect(()=>{if(l&&!s){const p=new u.AssetsManager(l),f=p.addTextFileTask(t!=null?t:"particle-system",n);p.load(),p.onFinish=function(d){console.log("task successful",d);const x=JSON.parse(f.text),h=u.ParticleSystem.Parse(x,l,a,i,o);h.emitter=r,c(h)}}return()=>{s&&(s.dispose(),console.log(t,"effect disposed!"))}},[o,i,t,s,r,a,l,n]),null},uf=e=>{const{id:t,position:n,useGPU:a=!0,renderAsFluid:i,numParticles:o=1e3,emitRate:r=1500*2,blendMode:l=u.ParticleSystem.BLENDMODE_ADD,color1:s,color2:c,colorDead:p,minSize:f,maxSize:d,minLifeTime:x,maxLifeTime:h,gravity:T,minEmitPower:P,maxEmitPower:v,updateSpeed:_,textureUrl:b,angle:k=Math.PI/2,radius:M=4,fluidRender:w}=e,S=_e.useScene(),[N,F]=m.useState(),B=m.useRef(null);return m.useEffect(()=>{N&&(N.blendMode=l,s&&(N.color1=s),c&&(N.color2=c),p&&(N.colorDead=p),f!==void 0&&(N.minSize=f),d!==void 0&&(N.maxSize=d),x!==void 0&&(N.minLifeTime=x),h!==void 0&&(N.maxLifeTime=h),P!==void 0&&(N.minEmitPower=P),v!==void 0&&(N.maxEmitPower=v),_!==void 0&&(N.updateSpeed=_),N.preWarmCycles=60*8,T&&(N.gravity=T),N.createConeEmitter(M,k),b&&(N.particleTexture=new u.Texture(b),N.particleTexture.onLoadObservable.add(()=>{N.start()})))},[k,l,s,c,p,T,v,h,d,P,x,f,N,M,b,_]),m.useEffect(()=>{if(!N&&S)if(a){const I=new u.GPUParticleSystem("particle-"+t,{capacity:o},S);F(I)}else{const I=new u.ParticleSystem("particle-"+t,o,S);F(I)}return()=>{console.log("particlesystem disposed!"),B.current&&(B.current.object.particleSize=0)}},[t,o,N,S,a]),m.useEffect(()=>{N&&(S==null||S.executeWhenReady(()=>{var I,D,E;if(S.updateTransformMatrix(!0),N==null||N.render(),i&&N){const L=S.enableFluidRenderer();if(L){L.addParticleSystem(N);const y=L.getRenderObjectFromParticleSystem(N);B.current=y,y&&(y.object.particleSize=(I=w==null?void 0:w.particleSize)!=null?I:.75,y.object.particleThicknessAlpha=.02,y.object.useTrueRenderingForDiffuseTexture=!0,y.targetRenderer.minimumThickness=y.object.particleThicknessAlpha,y.targetRenderer.blurDepthFilterSize=10,y.targetRenderer.blurDepthDepthScale=10,y.targetRenderer.thicknessMapSize=1024,y.targetRenderer.density=(D=w==null?void 0:w.density)!=null?D:8,y.targetRenderer.fresnelClamp=.04,y.targetRenderer.fluidColor=(E=w==null?void 0:w.fluidColor)!=null?E:new u.Color3(219/255,228/255,1),y.targetRenderer.generateDiffuseTexture=!1)}}}))},[w==null?void 0:w.density,w==null?void 0:w.fluidColor,w==null?void 0:w.particleSize,N,i,S]),m.useEffect(()=>{N&&(N.emitter=n,N.emitRate=r)},[r,N,n]),null},ff=(e,t)=>{var w,S,N;const n=_e.useScene(),a=m.useContext(Le),{name:i,width:o,height:r,localScale:l=u.Vector3.One(),rotation:s=u.Vector3.Zero(),position:c=u.Vector3.Zero(),textureUrl:p,videoUrl:f,canvas:d,backFaceCulling:x=!0,billboard:h=!1,actions:T,labelStyle:P}=e,v=He({url:p}),_=m.useRef(null),b=m.useRef(null),[k,M]=m.useState(null);return m.useEffect(()=>{if(f)return M(F=>{F==null||F.dispose();const B=new u.VideoTexture("video-texture",f,n,!1,!1,void 0,{autoPlay:!0,autoUpdateTexture:!0});return B.hasAlpha=!0,B}),()=>{M(F=>(F==null||F.dispose(),null))}},[f]),m.useEffect(()=>{if(d){const F=new u.DynamicTexture("dyn-texture",d,n);return F.hasAlpha=!0,_.current=F,()=>{var B;(B=_.current)==null||B.dispose()}}},[d]),m.useEffect(()=>{_.current&&(_.current.name=i)},[i]),m.useImperativeHandle(t,()=>_,[_]),m.useEffect(()=>{var B;const F=(B=b.current)==null?void 0:B.getChildMeshes()[0];F&&(F.metadata={pickable:T?{name:i,onLeftClick:T.onLeftClick,onRightClick:T.onRightClick,onMiddleClick:T.onMiddleClick,onHover:T.onHover,needWorldPosition:T.needWorldPosition,extra:T.extra}:null})},[T,i]),C.jsxs("transformNode",{ref:b,name:`transform-planeimage-${i}`,position:c.multiply(a?new u.Vector3((w=a.scalePlane)!=null?w:1,(S=a.scaleDepth)!=null?S:1,(N=a.scalePlane)!=null?N:1):u.Vector3.One()),rotation:h?u.Vector3.Zero():s,billboardMode:h?u.Mesh.BILLBOARDMODE_ALL:u.Mesh.BILLBOARDMODE_NONE,children:[C.jsx("plane",{name:`plane-planeimage-${i}`,width:o,height:r,scaling:l,children:C.jsx("standardMaterial",{name:`plane-planeimage-${i}`,emissiveColor:u.Color3.White(),specularColor:u.Color3.Black(),diffuseTexture:_.current?_.current:k||v,useAlphaFromDiffuseTexture:!0,backFaceCulling:x,transparencyMode:u.Material.MATERIAL_ALPHABLEND})}),P&&C.jsx(Je,{...P})]})},ga=m.forwardRef(ff);var va=(e=>(e[e.TETRAHEDRON=0]="TETRAHEDRON",e[e.OCTAHEDRON=1]="OCTAHEDRON",e[e.DODECAHEDRON=2]="DODECAHEDRON",e[e.ICOSAHEDRON=3]="ICOSAHEDRON",e[e.RHOMBICUBOCTAHEDRON=4]="RHOMBICUBOCTAHEDRON",e))(va||{});const xa=({size:e,alpha:t=1,position:n,visible:a,objectType:i,title:o,actions:r,labelStyle:l,color:s,scaleMode:c})=>{const p=m.useRef(null),f=m.useContext(Le);m.useEffect(()=>{p.current&&(p.current.metadata={pickable:r?{name:o,onLeftClick:r.onLeftClick,onRightClick:r.onRightClick,onMiddleClick:r.onMiddleClick,onHover:r.onHover,needWorldPosition:r.needWorldPosition,extra:r.extra}:null})},[r,o]);const[d,x]=m.useState(1);return m.useEffect(()=>{switch(c){case It.PLANE:x(f&&f.scalePlane?f.scalePlane:1);break;case It.DEPTH:x(f&&f.scaleDepth?f.scaleDepth:1);break;case It.NONE:x(1);break}},[f,c]),C.jsxs("transformNode",{setEnabled:a,name:`transform-spaceheat-${o}`,position:n.multiplyByFloats(f&&f.scalePlane?f.scalePlane:1,f&&f.scaleDepth?f.scaleDepth:1,f&&f.scalePlane?f.scalePlane:1),scalingDeterminant:d,children:[C.jsx("polyhedron",{ref:p,name:`point-${o}`,type:i,size:e,children:C.jsx("standardMaterial",{name:`point-${o}-mat`,backFaceCulling:!1,needDepthPrePass:!0,specularColor:new u.Color3(0,0,0),ambientColor:new u.Color3(1,1,1),emissiveColor:u.Color3.Black(),alphaMode:u.Engine.ALPHA_COMBINE,diffuseColor:s,alpha:t})}),C.jsx("transformNode",{name:`${o}-title`,position:l!=null&&l.offset?l.offset.multiplyByFloats(f!=null&&f.scalePlane?f==null?void 0:f.scalePlane:1,1,f!=null&&f.scalePlane?f==null?void 0:f.scalePlane:1):u.Vector3.Zero(),scaling:ct(f).multiply(new u.Vector3(3,3,3)),children:C.jsx(Je,{text:o,fontSize:l!=null&&l.fontSize?l.fontSize:10,color:l!=null&&l.color?l.color:"white"})})]})},ya=({name:e,url:t,offset:n=u.Vector3.Zero(),alpha:a,color:i,visible:o=!0,cutNormal:r,value:l,actions:s,textureOverride:c,progressTexture:p={},counterLine:f=void 0,lines:d=[],text:x=[],disableDepthWrite:h=!1,checkLines:T=[],checkLineWidth:P=4})=>{var re,oe,Y,ce,ae,X,Pe,ge,H,Q,Ee,ke,te,me,ue,pe,Ne,be,Ae;const v=_e.useScene(),_=m.useRef(null),b=m.useContext(Le),k=je({url:t,cacheType:Me.URL_PREFIX_MATCH}),[M,w]=m.useState(u.Vector3.Zero()),[S,N]=m.useState(void 0),F=He({url:c==null?void 0:c.texture,cacheType:Me.URL_PREFIX_MATCH}),B=He({url:c==null?void 0:c.sideTexture,cacheType:Me.URL_PREFIX_MATCH}),I=He({url:(re=p.segment1)==null?void 0:re.texture,cacheType:Me.URL_PREFIX_MATCH}),D=He({url:(oe=p.segment1)==null?void 0:oe.sideTexture,cacheType:Me.URL_PREFIX_MATCH}),E=He({url:(Y=p.segment2)==null?void 0:Y.texture,cacheType:Me.URL_PREFIX_MATCH}),L=He({url:(ce=p.segment2)==null?void 0:ce.sideTexture,cacheType:Me.URL_PREFIX_MATCH}),y=He({url:(ae=p.segment3)==null?void 0:ae.texture,cacheType:Me.URL_PREFIX_MATCH}),A=He({url:(X=p.segment3)==null?void 0:X.sideTexture,cacheType:Me.URL_PREFIX_MATCH}),V=He({url:(Pe=p.segment4)==null?void 0:Pe.texture,cacheType:Me.URL_PREFIX_MATCH}),$=He({url:(ge=p.segment4)==null?void 0:ge.sideTexture,cacheType:Me.URL_PREFIX_MATCH}),W=He({url:(H=p.segment5)==null?void 0:H.texture,cacheType:Me.URL_PREFIX_MATCH}),ne=He({url:(Q=p.segment5)==null?void 0:Q.sideTexture,cacheType:Me.URL_PREFIX_MATCH}),ee=He({url:(Ee=p.segment6)==null?void 0:Ee.texture,cacheType:Me.URL_PREFIX_MATCH}),G=He({url:(ke=p.segment6)==null?void 0:ke.sideTexture,cacheType:Me.URL_PREFIX_MATCH});m.useEffect(()=>{console.log("[Geo3DViewer] ProgressedAttributeBody Loading: ",t)},[t]),m.useEffect(()=>{if(v&&_.current&&t&&k){const Ie=_.current;u.Tags.EnableFor(Ie),u.Tags.AddTagsTo(Ie,"loading");const we=Vo.decode(new Uint8Array(k)),{points:Re,indices:Ve,value:Ue,center:Be}=we;Be&&w(new u.Vector3(Be.x,Be.y,Be.z));const Ge=new u.VertexData;Ge.positions=Re,Ge.indices=Ve,Ge.colors=Ue;const Ke=[];u.VertexData.ComputeNormals(Re,Ve,Ke),Ge.normals=Ke,Ie&&(Ge.applyToMesh(Ie),Ie.getScene().onAfterRenderObservable.addOnce(()=>{if(!Ie.isDisposed()){const fe=Ie.getBoundingInfo();N(fe.boundingBox)}})),u.Tags.RemoveTagsFrom(Ie,"loading")}},[t,v,k]);function le(Ie,we,Re){const Ve=Re.subtract(we),Ue=Ie.subtract(we),Be=u.Vector3.Dot(u.Vector3.Normalize(Ve),u.Vector3.Normalize(Ue)),Ge=Ue.length()/Be,Ke=we.add(Ve.scale(Ge/u.Vector3.Distance(we,Re)));return u.Vector3.Distance(Ie,Ke)}return m.useEffect(()=>{_.current&&(_.current.metadata={pickable:s?{name:e,valueCallback:(Ie,we,Re)=>{if(console.log(e,Ie,we,Re),_.current&&we){const Ve=_.current.getBoundingInfo().boundingBox;console.log(Ve);for(let Ue=0;Ue<T.length;Ue++){const Be=T[Ue];if(le(new u.Vector3(we.x,0,we.z),Be.start,Be.end)<P){const Ke=[];for(let z=0;z<11;z++){const fe=Be.end.subtract(Be.start),he=Be.start.add(fe.scale(z/10)),xe=new u.Vector3(he.x,we.y+Ve.extendSize.y*4,he.z),Z=new u.Vector3(he.x,we.y+Ve.extendSize.y*2,he.z),ie=u.Vector3.Normalize(Z.subtract(xe)),O=Ve.extendSize.y*10,de=new u.Ray(xe,ie,O),Se=v==null?void 0:v.pickWithRay(de,g=>g===_.current);Se!=null&&Se.hit&&Se.pickedPoint&&Ke.push(Se.pickedPoint)}for(let z=0;z<11;z++){const fe=Be.end.subtract(Be.start),he=Be.start.add(fe.scale(z/10)),xe=new u.Vector3(he.x,we.y-Ve.extendSize.y*4,he.z),Z=new u.Vector3(he.x,we.y-Ve.extendSize.y*2,he.z),ie=u.Vector3.Normalize(Z.subtract(xe)),O=Ve.extendSize.y*10,de=new u.Ray(xe,ie,O),Se=v==null?void 0:v.pickWithRay(de,g=>g===_.current);Se!=null&&Se.hit&&Se.pickedPoint&&Ke.push(Se.pickedPoint)}return{value:Ue,points:Ke}}}}},onLeftClick:s.onLeftClick,onRightClick:s.onRightClick,onMiddleClick:s.onMiddleClick,onHover:s.onHover,needWorldPosition:s.needWorldPosition,extra:s.extra}:null})},[s,e,T]),C.jsx(C.Fragment,{children:C.jsx("transformNode",{name:`transform-progressedattribute-${e}`,position:M.add(n).multiplyByFloats(b&&b.scalePlane?b.scalePlane:1,b&&b.scaleDepth?b.scaleDepth:1,b&&b.scalePlane?b.scalePlane:1),scaling:new u.Vector3(b?b.scalePlane:1,b?b.scaleDepth:1,b?b.scalePlane:1),children:C.jsx("mesh",{name:`attributebody-${e}-mesh`,ref:_,setEnabled:o,useVertexColors:!F,alwaysSelectAsActiveMesh:!0,children:S&&origin?F?C.jsx(ji,{name:`progressedattributebody-${e}-mat`,backFaceCulling:!0,needDepthPrePass:!1,transparencyMode:u.Material.MATERIAL_ALPHABLEND,alphaMode:u.Engine.ALPHA_COMBINE,texture:F,sideTexture:B,alphaStage:a,cutNormal:r,value:l,boundingBox:S,tilingFactor:c==null?void 0:c.tilingFactor,textureFlatRotate:c==null?void 0:c.flatModeRotate,sideTilingFactor:(te=c==null?void 0:c.sideTilingFactor)!=null?te:c==null?void 0:c.tilingFactor,mode:c==null?void 0:c.mode,overlay:{texture1:I,sideTexture1:D,texture2:E,sideTexture2:L,texture3:y,sideTexture3:A,texture4:V,sideTexture4:$,texture5:W,sideTexture5:ne,texture6:ee,sideTexture6:G,color1:(me=p.segment1)==null?void 0:me.color,color2:(ue=p.segment2)==null?void 0:ue.color,color3:(pe=p.segment3)==null?void 0:pe.color,color4:(Ne=p.segment4)==null?void 0:Ne.color,color5:(be=p.segment5)==null?void 0:be.color,color6:(Ae=p.segment6)==null?void 0:Ae.color},scaleDepth:b?b.scaleDepth:1,scalePlane:b?b.scalePlane:1,counterLine:f,lines:d,text:x,disableDepthWrite:h}):i?C.jsx(Qi,{name:`progressedattributebody-${e}-mat`,backFaceCulling:!0,needDepthPrePass:!1,transparencyMode:u.Material.MATERIAL_ALPHABLEND,alphaMode:u.Engine.ALPHA_COMBINE,colorCodec:i,alphaStage:a,cutNormal:r,value:l,boundingBox:S,scaleDepth:b?b.scaleDepth:1,scalePlane:b?b.scalePlane:1,counterLine:f,lines:d,text:x,disableDepthWrite:h}):C.jsx(C.Fragment,{}):C.jsx(C.Fragment,{})})})})},Ca=({onPick:e,pickAll:t=!1})=>{const n=_e.useScene(),a=m.useContext(Le),i=m.useRef(null),o=m.useRef([]),r=m.useRef(!1),l=m.useCallback(d=>{if(!d){e(null);return}let x=1,h=1;a&&(a.scalePlane&&(x=a.scalePlane),a.scaleDepth&&(h=a.scaleDepth)),e(new u.Vector3(d.x/x,d.y/h,d.z/x))},[a,e]),s=m.useCallback(()=>{if(!n)return[];const d=n.meshes.filter(h=>!!h&&!h.isDisposed()&&h.isPickable&&h.isVisible&&h.isEnabled()&&h.isReady(!0)),x=d.length!==o.current.length||d.some((h,T)=>o.current[T]!==h);return i.current||(i.current=new Pi.GPUPicker),x&&(i.current.setPickingList(d.length>0?d.slice():null),o.current=d),d},[n]),c=m.useCallback(async()=>{if(!n||r.current||n.skipPointerMovePicking)return;if(!s().length||!i.current){e(null);return}r.current=!0;try{const x=await i.current.pickAsync(n.pointerX,n.pointerY,!1),h=x==null?void 0:x.mesh;if(!h){e(null);return}const T=n.pick(n.pointerX,n.pointerY,P=>P.uniqueId===h.uniqueId,!1,void 0);if(!(T!=null&&T.pickedPoint)){e(null);return}l(T.pickedPoint)}finally{r.current=!1}},[l,e,n,s]),p=m.useCallback(()=>{var x;if(!n||n.skipPointerMovePicking)return;const d=n.pick(n.pointerX,n.pointerY,void 0,!1,void 0);l((x=d==null?void 0:d.pickedPoint)!=null?x:null)},[l,n]),f=m.useCallback(d=>{switch(d.type){case u.PointerEventTypes.POINTERUP:{t?p():c();break}}},[t,p,c]);return m.useEffect(()=>{if(n){const d=n.onPointerObservable.add(f);return()=>{n.onPointerObservable.remove(d)}}},[f,n]),m.useEffect(()=>()=>{var d;(d=i.current)==null||d.dispose(),i.current=null,o.current=[],r.current=!1},[]),C.jsx(C.Fragment,{})},_a=({name:e,paths:t,color:n,alpha:a,sideOrientation:i=Ai.CounterClockWiseSideOrientation,position:o=u.Vector3.Zero(),rotation:r=u.Vector3.Zero(),scaling:l=u.Vector3.One(),backFaceCulling:s=!1,labelStyle:c,showLayerLabel:p=!1,actions:f})=>{const d=m.useContext(Le),x=Oe(d),h=m.useRef(null),[T,P]=m.useState();return m.useEffect(()=>{if(h.current){const v=h.current.getBoundingInfo();P(v.boundingBox.centerWorld)}},[t,o,r,l]),m.useEffect(()=>{h.current&&(h.current.metadata={pickable:f?{name:e,onLeftClick:f.onLeftClick,onRightClick:f.onRightClick,onMiddleClick:f.onMiddleClick,onHover:f.onHover,needWorldPosition:f.needWorldPosition,extra:f.extra}:null})},[f,e]),C.jsxs("transformNode",{name:`${e}-transform`,position:o.multiply(x),rotation:r,scaling:l.multiply(x),children:[C.jsx("ribbon",{name:`${e}-transform`,pathArray:t,updatable:!0,ref:h,sideOrientation:i,children:C.jsx("standardMaterial",{name:`${e}-material`,diffuseColor:n,alpha:a,specularColor:u.Color3.Black(),ambientColor:u.Color3.White(),transparencyMode:u.Material.MATERIAL_ALPHABLEND,backFaceCulling:s})}),e&&T&&C.jsx("transformNode",{name:`${e}-title`,position:T.add(c!=null&&c.offset?c.offset.multiplyByFloats(d!=null&&d.scalePlane?d==null?void 0:d.scalePlane:1,1,d!=null&&d.scalePlane?d==null?void 0:d.scalePlane:1):u.Vector3.Zero()),scaling:ct(d).multiply(new u.Vector3(3,3,3)),setEnabled:p,children:C.jsx(Je,{text:e,fontSize:c!=null&&c.fontSize?c.fontSize:40,color:c!=null&&c.color?c.color:"white"})})]})},df=`#ifdef GL_ES
|
|
1246
1246
|
precision highp float;
|
|
1247
1247
|
#endif
|
|
@@ -16779,6 +16779,7 @@ const Va = ({
|
|
|
16779
16779
|
name: `densityslice-${e}-${d}-${s}-mesh`,
|
|
16780
16780
|
ref: l,
|
|
16781
16781
|
setEnabled: n,
|
|
16782
|
+
useVertexColors: !0,
|
|
16782
16783
|
children: /* @__PURE__ */ N(
|
|
16783
16784
|
cn,
|
|
16784
16785
|
{
|
|
@@ -17979,7 +17980,7 @@ const Ga = un(void 0), Uf = (e, t = "BIN") => {
|
|
|
17979
17980
|
return ue(() => {
|
|
17980
17981
|
console.log(
|
|
17981
17982
|
`
|
|
17982
|
-
%c Geo3DViewer Library %c Version: 1.7.
|
|
17983
|
+
%c Geo3DViewer Library %c Version: 1.7.40 %c
|
|
17983
17984
|
`,
|
|
17984
17985
|
"color:#e0e0e0;background:#873e23;padding:5px 0;border-top-left-radius:5px;border-bottom-left-radius:5px;",
|
|
17985
17986
|
"color:#455a64;background:#e0e0e0;padding:5px 0;",
|