@wandelbots/wandelbots-js-react-components
Version:
React UI toolkit for building applications on top of the Wandelbots platform
3 lines (2 loc) • 17.5 kB
JavaScript
;const t=require("./index-DxwppshT.cjs"),w=require("three"),W=require("three-stdlib"),F=require("@react-three/fiber"),y=require("@react-three/drei"),d=require("@mui/material"),X=require("mobx-react-lite"),f=require("react"),Q=require("react-i18next"),R=require("./index-CqMZL0FV.cjs"),ee=require("react-error-boundary");function te(e){const n=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const r in e)if(r!=="default"){const o=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(n,r,o.get?o:{enumerable:!0,get:()=>e[r]})}}return n.default=e,Object.freeze(n)}const m=te(w);function re(e){switch(e.shape_type){case"convex_hull":return new W.ConvexGeometry(e.vertices.map(r=>new m.Vector3(r[0]/1e3,r[1]/1e3,r[2]/1e3)));case"box":return new m.BoxGeometry(e.size_x/1e3,e.size_y/1e3,e.size_z/1e3);case"sphere":return new m.SphereGeometry(e.radius/1e3);case"capsule":return new m.CapsuleGeometry(e.radius/1e3,e.cylinder_height/1e3);case"cylinder":return new m.CylinderGeometry(e.radius/1e3,e.radius/1e3,e.height/1e3);case"rectangle":return new m.BoxGeometry(e.size_x/1e3,e.size_y/1e3,0);default:return console.warn(`${e.shape_type} is not supported`),new m.BufferGeometry}}function ne({name:e,collider:n,children:r}){var l,u;const o=((l=n.pose)==null?void 0:l.position)??[0,0,0],s=((u=n.pose)==null?void 0:u.orientation)??[0,0,0];return n.margin&&console.warn(`${e} margin is not supported`),t.jsxRuntimeExports.jsx("mesh",{name:e,position:new m.Vector3(o[0],o[1],o[2]).divideScalar(1e3),rotation:new m.Euler(s[0],s[1],s[2],"XYZ"),geometry:re(n.shape),children:r})}function se({name:e,colliders:n,meshChildrenProvider:r,...o}){return t.jsxRuntimeExports.jsx("group",{name:e,...o,children:Object.entries(n).map(([s,l])=>t.jsxRuntimeExports.jsx(ne,{name:s,collider:l,children:r(s,l)},s))})}function oe({scene:e,meshChildrenProvider:n}){const r=e.colliders;return t.jsxRuntimeExports.jsx("group",{children:r&&t.jsxRuntimeExports.jsx(se,{meshChildrenProvider:n,colliders:r})})}function D(){return t.jsxRuntimeExports.jsx(y.Environment,{children:t.jsxRuntimeExports.jsx(ie,{})})}function ie({positions:e=[2,0,2,0,2,0,2,0]}){return t.jsxRuntimeExports.jsxs(t.jsxRuntimeExports.Fragment,{children:[t.jsxRuntimeExports.jsx(y.Lightformer,{intensity:5,"rotation-x":Math.PI/2,position:[0,5,-9],scale:[10,10,1]}),t.jsxRuntimeExports.jsx("group",{rotation:[0,.5,0],children:t.jsxRuntimeExports.jsx("group",{children:e.map((n,r)=>t.jsxRuntimeExports.jsx(y.Lightformer,{form:"circle",intensity:5,rotation:[Math.PI/2,0,0],position:[n,4,r*4],scale:[3,1,1]},r))})}),t.jsxRuntimeExports.jsx(y.Lightformer,{intensity:40,"rotation-y":Math.PI/2,position:[-5,1,-1],scale:[20,.1,1]}),t.jsxRuntimeExports.jsx(y.Lightformer,{intensity:20,"rotation-y":-Math.PI,position:[-5,-2,-1],scale:[20,.1,1]}),t.jsxRuntimeExports.jsx(y.Lightformer,{"rotation-y":Math.PI/2,position:[-5,-1,-1],scale:[20,.5,1],intensity:5}),t.jsxRuntimeExports.jsx(y.Lightformer,{"rotation-y":-Math.PI/2,position:[10,1,0],scale:[20,1,1],intensity:10}),t.jsxRuntimeExports.jsx(y.Lightformer,{form:"ring",color:"white",intensity:5,scale:10,position:[-15,4,-18],target:[0,0,0]})]})}function ae(e){if(e.length<3)return console.log("Not enough vertices to define a plane"),{isCoplanar:!1};const n=new m.Vector3(e[0].x,e[0].y,e[0].z),r=new m.Vector3(e[1].x,e[1].y,e[1].z),o=new m.Vector3(e[2].x,e[2].y,e[2].z),s=new m.Vector3().subVectors(r,n),l=new m.Vector3().subVectors(o,n),u=new m.Vector3().crossVectors(s,l).normalize();for(let a=3;a<e.length;a++){const j=new m.Vector3(e[a].x,e[a].y,e[a].z),p=new m.Vector3().subVectors(j,n),x=u.dot(p);if(Math.abs(x)>1e-6)return console.log("Vertices are not on the same plane"),{isCoplanar:!1}}return{isCoplanar:!0,normal:u}}function ue({safetyZones:e,...n}){return t.jsxRuntimeExports.jsx("group",{...n,children:e.map((r,o)=>{let s=[];return r.geometry&&(r.geometry.compound?s=r.geometry.compound.child_geometries:r.geometry.convex_hull&&(s=[r.geometry])),s.map((l,u)=>{if(!l.convex_hull)return null;const a=l.convex_hull.vertices.map(x=>new m.Vector3(x.x/1e3,x.y/1e3,x.z/1e3)),j=ae(a);if(j.isCoplanar&&j.normal){const i=new m.Vector3().addVectors(a[0],j.normal.multiplyScalar(1e-4));a.push(i)}let p;try{p=new W.ConvexGeometry(a)}catch(x){return console.log("Error creating ConvexGeometry:",x),null}return t.jsxRuntimeExports.jsx("mesh",{geometry:p,children:t.jsxRuntimeExports.jsx("meshStandardMaterial",{attach:"material",color:"#009f4d",opacity:.2,depthTest:!1,depthWrite:!1,transparent:!0,polygonOffset:!0,polygonOffsetFactor:-u},o)},`${o}-${u}`)})})})}function ce({trajectory:e,...n}){var o;const r=((o=e.trajectory)==null?void 0:o.map(s=>s.tcp_pose?new m.Vector3(s.tcp_pose.position.x/1e3,s.tcp_pose.position.z/1e3,-s.tcp_pose.position.y/1e3):null).filter(s=>s!==null))||[];return t.jsxRuntimeExports.jsx("group",{...n,children:r.length>0&&t.jsxRuntimeExports.jsx(y.Line,{points:r,lineWidth:3,polygonOffset:!0,polygonOffsetFactor:10,polygonOffsetUnits:10})})}const P="0.0.0-semantically-released";function V(e){let n=P;return P.startsWith("0.")&&(n=""),`https://cdn.jsdelivr.net/gh/wandelbotsgmbh/wandelbots-js-react-components${n?`@${n}`:""}/public/models/${e}.glb`}function le(e){function n(r){return r.children.length===0?[r]:[r,...r.children.flatMap(o=>n(o))]}return n(e).filter(r=>H(r))}function q(e){return e.name.endsWith("_FLG")}function H(e){return/_J[0-9]+$/.test(e.name)}function xe(e,n){let r;function o(s){if(q(s)){if(r)throw Error(`Found multiple flange groups in robot model ${n}; first ${r.name} then ${s.name}. Only one _FLG group is allowed.`);r=s}H(s),s.children.map(o)}if(o(e.scene),!r)throw Error(`No flange group found in robot model ${n}. Flange must be identified with a name ending in _FLG.`);return{gltf:e}}function N({rapidlyChangingMotionState:e,dhParameters:n,onRotationChanged:r,children:o}){const s=f.useRef([]),l=f.useRef([]),u=f.useRef(null),{invalidate:a}=F.useThree();f.useEffect(()=>{const i=e.joint_position.filter(c=>c!==void 0);return u.current=new R.ValueInterpolator(i,{tension:120,friction:20,threshold:.001}),()=>{var c;(c=u.current)==null||c.destroy()}},[]),F.useFrame((i,c)=>{if(u.current){const h=u.current.update(c);x(),h||a()}});function j(i){i&&(l.current=le(i),x(),a())}function p(i){var c;s.current=i,(c=u.current)==null||c.setTarget(i)}function x(){var c;const i=((c=u.current)==null?void 0:c.getCurrentValues())||[];if(r)r(l.current,i);else for(const[h,g]of l.current.entries()){const E=n[h],M=E.theta||0,v=E.reverse_rotation_direction?-1:1;g.rotation.y=v*(i[h]||0)+M}}return R.useAutorun(()=>{const i=e.joint_position.filter(c=>c!==void 0);requestAnimationFrame(()=>p(i))}),t.jsxRuntimeExports.jsx("group",{ref:j,children:o})}const me="line",pe="mesh";function fe({rapidlyChangingMotionState:e,dhParameters:n,...r}){const o=new w.Matrix4,s=f.useRef([]),l=f.useRef([]);f.useEffect(()=>{s.current=new Array(n.length).fill(null),l.current=new Array(n.length).fill(null)},[n.length]);function u(p,x){const i=new w.Vector3,c=new w.Quaternion,h=new w.Vector3;o.decompose(i,c,h);const g=i.clone(),E=new w.Matrix4().makeRotationY(p.theta+x*(p.reverse_rotation_direction?-1:1)).multiply(new w.Matrix4().makeTranslation(0,p.d/1e3,0)).multiply(new w.Matrix4().makeTranslation(p.a/1e3,0,0)).multiply(new w.Matrix4().makeRotationX(p.alpha));return o.multiply(E),o.decompose(i,c,h),{a:g,b:i}}function a(p,x,i,c){if(!n)return;const h=n[p];if(!h)return;const{a:g,b:E}=u(h,c);x.geometry.setPositions([g.toArray(),E.toArray()].flat()),i.position.set(E.x,E.y,E.z)}function j(p,x){o.identity();for(let i=0;i<Math.min(p.length,x.length);i++){const c=s.current[i],h=l.current[i];c&&h&&a(i,c,h,x[i])}}return t.jsxRuntimeExports.jsx(t.jsxRuntimeExports.Fragment,{children:t.jsxRuntimeExports.jsx(N,{rapidlyChangingMotionState:e,dhParameters:n,onRotationChanged:j,children:t.jsxRuntimeExports.jsxs("group",{...r,name:"Scene",children:[t.jsxRuntimeExports.jsxs("mesh",{children:[t.jsxRuntimeExports.jsx("sphereGeometry",{args:[.01,32,32]}),t.jsxRuntimeExports.jsx("meshStandardMaterial",{color:"black",depthTest:!0})]}),n.map((p,x)=>{const{a:i,b:c}=u(p,e.joint_position[x]??0),h=`dhrobot_J0${x}`;return t.jsxRuntimeExports.jsxs("group",{name:h,children:[t.jsxRuntimeExports.jsx(y.Line,{ref:g=>{s.current[x]=g},name:me,points:[i,c],color:"white",lineWidth:5}),t.jsxRuntimeExports.jsxs("mesh",{ref:g=>{l.current[x]=g},name:pe,position:c,children:[t.jsxRuntimeExports.jsx("sphereGeometry",{args:[.01,32,32]}),t.jsxRuntimeExports.jsx("meshStandardMaterial",{color:"black",depthTest:!0})]},"mesh_"+x)]},h)})]})})})}const de=console.warn;function he(){return f.useEffect(()=>{console.warn=e=>{e!=="Cannot call the manual advancement of rafz whilst frameLoop is not set as demand"&&de(e)}},[]),t.jsxRuntimeExports.jsx(t.jsxRuntimeExports.Fragment,{})}function je(e){return e.type==="Mesh"}function Re({modelURL:e,flangeRef:n,postModelRender:r,...o}){const{gltf:s}=xe(y.useGLTF(e),e.split("/").pop()||e),l=f.useCallback(a=>{a&&r&&r()},[e]);function u(a){return je(a)?t.jsxRuntimeExports.jsx("mesh",{name:a.name,geometry:a.geometry,material:a.material,position:a.position,rotation:a.rotation},a.uuid):t.jsxRuntimeExports.jsx("group",{name:a.name,position:a.position,rotation:a.rotation,ref:q(a)?n:void 0,children:a.children.map(u)},a.uuid)}return t.jsxRuntimeExports.jsx("group",{...o,dispose:null,ref:l,children:u(s.scene)})}const ge=(e,n)=>{e.userData.isGhost||(e.traverse(r=>{if(r instanceof m.Mesh){r.material instanceof m.Material&&(r.material.colorWrite=!1);const o=r.clone(),s=r.clone();o.material=new m.MeshStandardMaterial({depthTest:!0,depthWrite:!0,colorWrite:!1,polygonOffset:!0,polygonOffsetFactor:-1,side:m.DoubleSide}),o.userData.isGhost=!0,s.material=new m.MeshStandardMaterial({color:n,opacity:.3,depthTest:!0,depthWrite:!1,transparent:!0,polygonOffset:!0,polygonOffsetFactor:-2,side:m.DoubleSide}),s.userData.isGhost=!0,r.parent&&(r.parent.add(o),r.parent.add(s))}}),e.userData.isGhost=!0)},ye=e=>{if(!e.userData.isGhost)return;const n=[];e.traverse(r=>{var o;r instanceof m.Mesh&&((o=r.userData)!=null&&o.isGhost?n.push(r):r.material instanceof m.Material&&(r.material.colorWrite=!0))}),n.forEach(r=>{r.parent&&r.parent.remove(r)}),e.userData.isGhost=!1},U=t.externalizeComponent(({rapidlyChangingMotionState:e,modelFromController:n,dhParameters:r,getModel:o=V,flangeRef:s,postModelRender:l,transparentColor:u,...a})=>{const[j,p]=f.useState(null),x=f.useCallback(c=>{p(c)},[]);f.useEffect(()=>{j&&(u?ge(j,u):ye(j))},[j,u]);const i=t.jsxRuntimeExports.jsx(fe,{rapidlyChangingMotionState:e,dhParameters:r,...a});return t.jsxRuntimeExports.jsxs(ee.ErrorBoundary,{fallback:i,onError:c=>{console.error(c)},children:[t.jsxRuntimeExports.jsx(f.Suspense,{fallback:i,children:t.jsxRuntimeExports.jsx("group",{ref:x,children:t.jsxRuntimeExports.jsx(N,{rapidlyChangingMotionState:e,dhParameters:r,children:t.jsxRuntimeExports.jsx(Re,{modelURL:o(n),postModelRender:l,flangeRef:s,...a})})})}),t.jsxRuntimeExports.jsx(he,{})]})});function $({connectedMotionGroup:e,getModel:n=V,flangeRef:r,transparentColor:o,postModelRender:s,...l}){return e.dhParameters?t.jsxRuntimeExports.jsx(U,{rapidlyChangingMotionState:e.rapidlyChangingMotionState,modelFromController:e.modelFromController||"",dhParameters:e.dhParameters,getModel:n,flangeRef:r,transparentColor:o,postModelRender:s,...l}):null}const Ee=t.externalizeComponent(X.observer(({robotName:e,programState:n,safetyState:r,operationMode:o,driveToHomeEnabled:s=!1,onDriveToHomePress:l,onDriveToHomeRelease:u,connectedMotionGroup:a,robotComponent:j=$,customContentComponent:p,className:x})=>{var B;const i=d.useTheme(),{t:c}=Q.useTranslation(),[h,g]=f.useState(!1),E=f.useRef(null),M=f.useRef(null),[v,Y]=f.useState(!1),[C,K]=f.useState({width:400,height:600}),[Me,Z]=f.useState(0);f.useEffect(()=>{const I=()=>{if(M.current){const{offsetWidth:L,offsetHeight:z}=M.current;Y(L>z),K({width:L,height:z})}};I();const O=new ResizeObserver(I);return M.current&&O.observe(M.current),()=>{O.disconnect()}},[]);const k=f.useCallback(()=>{Z(I=>I+1)},[]),_=f.useCallback(()=>{!s||!l||(g(!0),l())},[s,l]),S=f.useCallback(()=>{!s||!u||(g(!1),u())},[s,u]),A=f.useCallback(()=>{h&&u&&(g(!1),u())},[h,u]),b=v?C.width<350:C.height<200,G=v?C.height<310:C.height<450;return t.jsxRuntimeExports.jsx(d.Card,{ref:M,className:x,sx:{width:"100%",height:"100%",display:"flex",flexDirection:v?"row":"column",position:"relative",overflow:"hidden",minWidth:{xs:180,sm:220,md:250},minHeight:v?{xs:200,sm:240,md:260}:{xs:150,sm:180,md:220},border:`1px solid ${i.palette.divider}`,borderRadius:"18px",boxShadow:"none",backgroundColor:((B=i.palette.backgroundPaperElevation)==null?void 0:B[8])||"#2A2A3F",backgroundImage:"none"},children:v?t.jsxRuntimeExports.jsxs(t.jsxRuntimeExports.Fragment,{children:[t.jsxRuntimeExports.jsx(d.Box,{sx:{flex:"0 0 50%",position:"relative",height:"100%",minHeight:"100%",maxHeight:"100%",borderRadius:1,m:{xs:1.5,sm:2,md:3},mr:{xs:.75,sm:1,md:1.5},overflow:"hidden",display:b?"none":"block"},children:!b&&t.jsxRuntimeExports.jsxs(F.Canvas,{orthographic:!0,camera:{position:[3,2,3],zoom:1},shadows:!0,frameloop:"demand",style:{borderRadius:i.shape.borderRadius,width:"100%",height:"100%",background:"transparent",position:"absolute",top:0,left:0},dpr:[1,2],gl:{alpha:!0,antialias:!0},children:[t.jsxRuntimeExports.jsx(D,{}),t.jsxRuntimeExports.jsx(y.Bounds,{fit:!0,observe:!0,margin:1,maxDuration:1,children:t.jsxRuntimeExports.jsx(j,{connectedMotionGroup:a,postModelRender:k})})]})}),t.jsxRuntimeExports.jsxs(d.Box,{sx:{flex:"1",display:"flex",flexDirection:"column",justifyContent:"flex-start",width:b?"100%":"50%"},children:[t.jsxRuntimeExports.jsxs(d.Box,{sx:{p:{xs:1.5,sm:2,md:3},pb:{xs:1,sm:1.5,md:2},textAlign:"left"},children:[t.jsxRuntimeExports.jsx(d.Typography,{variant:"h6",component:"h2",sx:{mb:1},children:e}),t.jsxRuntimeExports.jsx(R.ProgramStateIndicator,{programState:n,safetyState:r,operationMode:o})]}),t.jsxRuntimeExports.jsxs(d.Box,{sx:{p:{xs:1.5,sm:2,md:3},pt:0,flex:"1",display:"flex",flexDirection:"column",justifyContent:"space-between"},children:[!G&&p&&t.jsxRuntimeExports.jsxs(d.Box,{children:[t.jsxRuntimeExports.jsx(p,{}),t.jsxRuntimeExports.jsx(d.Divider,{sx:{mt:1,mb:0,borderColor:i.palette.divider,opacity:.5}})]}),t.jsxRuntimeExports.jsx(d.Box,{sx:{mt:!G&&p?"auto":0},children:t.jsxRuntimeExports.jsx(d.Box,{sx:{display:"flex",justifyContent:"flex-start",mt:{xs:1,sm:1.5,md:2},mb:{xs:.5,sm:.75,md:1}},children:t.jsxRuntimeExports.jsx(d.Button,{ref:E,variant:"contained",color:"secondary",size:"small",disabled:!s,onMouseDown:_,onMouseUp:S,onMouseLeave:A,onTouchStart:_,onTouchEnd:S,sx:{textTransform:"none",px:1.5,py:.5},children:c("RobotCard.DriveToHome.bt")})})})]})]})]}):t.jsxRuntimeExports.jsx(t.jsxRuntimeExports.Fragment,{children:t.jsxRuntimeExports.jsxs(d.Box,{sx:{p:3,height:"100%",display:"flex",flexDirection:"column"},children:[t.jsxRuntimeExports.jsxs(d.Box,{children:[t.jsxRuntimeExports.jsx(d.Typography,{variant:"h6",component:"h2",sx:{mb:1},children:e}),t.jsxRuntimeExports.jsx(R.ProgramStateIndicator,{programState:n,safetyState:r,operationMode:o})]}),t.jsxRuntimeExports.jsx(d.Box,{sx:{flex:b?0:1,position:"relative",minHeight:b?0:{xs:120,sm:150,md:200},height:b?0:"auto",borderRadius:1,overflow:"hidden",display:b?"none":"block"},children:!b&&t.jsxRuntimeExports.jsxs(F.Canvas,{orthographic:!0,camera:{position:[3,2,3],zoom:1},shadows:!0,frameloop:"demand",style:{borderRadius:i.shape.borderRadius,width:"100%",height:"100%",background:"transparent",position:"absolute"},dpr:[1,2],gl:{alpha:!0,antialias:!0},children:[t.jsxRuntimeExports.jsx(D,{}),t.jsxRuntimeExports.jsx(y.Bounds,{fit:!0,clip:!0,observe:!0,margin:1,maxDuration:1,children:t.jsxRuntimeExports.jsx(j,{connectedMotionGroup:a,postModelRender:k})})]})}),t.jsxRuntimeExports.jsxs(d.Box,{children:[!G&&p&&t.jsxRuntimeExports.jsxs(t.jsxRuntimeExports.Fragment,{children:[t.jsxRuntimeExports.jsx(p,{}),t.jsxRuntimeExports.jsx(d.Divider,{sx:{mt:1,mb:0,borderColor:i.palette.divider,opacity:.5}})]}),t.jsxRuntimeExports.jsx(d.Box,{sx:{display:"flex",justifyContent:"flex-start",mt:!G&&p?{xs:1,sm:2,md:5}:{xs:.5,sm:1,md:2},mb:{xs:.5,sm:.75,md:1}},children:t.jsxRuntimeExports.jsx(d.Button,{ref:E,variant:"contained",color:"secondary",size:"small",disabled:!s,onMouseDown:_,onMouseUp:S,onMouseLeave:A,onTouchStart:_,onTouchEnd:S,sx:{textTransform:"none",px:1.5,py:.5},children:c("RobotCard.DriveToHome.bt")})})]})]})})})})),be=Array(6).fill(2*Math.PI),T={[R.Manufacturer.Abb]:[0,0,0,0,Math.PI/2,0,0],[R.Manufacturer.Fanuc]:[0,0,0,0,-Math.PI/2,0,0],[R.Manufacturer.Yaskawa]:[0,0,0,0,-Math.PI/2,0,0],[R.Manufacturer.Kuka]:[0,-Math.PI/2,Math.PI/2,0,Math.PI/2,0,0],[R.Manufacturer.Universalrobots]:[0,-Math.PI/2,-Math.PI/2,-Math.PI/2,Math.PI/2,-Math.PI/2,0]};function J(e){const[n]=e.split("_");switch(n){case"ABB":return R.Manufacturer.Abb;case"FANUC":return R.Manufacturer.Fanuc;case"YASKAWA":return R.Manufacturer.Yaskawa;case"KUKA":return R.Manufacturer.Kuka;case"UniversalRobots":return R.Manufacturer.Universalrobots;default:return null}}function we(e,n){const r=J(e);return r&&r in T?T[r]:n||null}exports.CollisionSceneRenderer=oe;exports.MANUFACTURER_HOME_CONFIGS=T;exports.PresetEnvironment=D;exports.Robot=$;exports.RobotCard=Ee;exports.SafetyZonesRenderer=ue;exports.SupportedRobot=U;exports.TrajectoryRenderer=ce;exports.defaultAxisConfig=be;exports.defaultGetModel=V;exports.extractManufacturer=J;exports.getDefaultHomeConfig=we;
//# sourceMappingURL=manufacturerHomePositions-Ca80ycLi.cjs.map