@wandelbots/wandelbots-js-react-components 6.4.0-pr.fix-3d-view-memory-leak.666.9156851 → 6.4.0-pr.revamp.667.5d2eede

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.
Files changed (33) hide show
  1. package/dist/3d.cjs +1 -1
  2. package/dist/3d.d.ts +2 -0
  3. package/dist/3d.js +14 -11
  4. package/dist/RobotHeader/index.cjs +1 -1
  5. package/dist/RobotHeader/index.js +1 -1
  6. package/dist/SafetyBar/index.cjs +1 -1
  7. package/dist/SafetyBar/index.js +1 -1
  8. package/dist/chunks/Pose3-DIyg-aZA.cjs +1 -0
  9. package/dist/chunks/{useSmoothedMotionState-COMJRcOt.js → Pose3-pocKPrHN.js} +141 -63
  10. package/dist/chunks/Robot-B3vKEVXP.cjs +1 -0
  11. package/dist/chunks/{Robot-DegVn7HE.js → Robot-DXhaz1tq.js} +205 -219
  12. package/dist/chunks/{RobotHeader-BZci9ahT.js → RobotHeader-DDmDkUoV.js} +1 -1
  13. package/dist/chunks/{RobotHeader-CqK0700U.cjs → RobotHeader-Daft80jq.cjs} +1 -1
  14. package/dist/chunks/{SafetyBar-Bbg-o8h9.cjs → SafetyBar-BVk-SH_0.cjs} +1 -1
  15. package/dist/chunks/{SafetyBar-Cuak4ffd.js → SafetyBar-RkN0I1Cb.js} +1 -1
  16. package/dist/chunks/TrajectoryExecutionStore-CKfEoKo8.cjs +3 -0
  17. package/dist/chunks/{TrajectoryExecutionStore-CgXDsq3f.js → TrajectoryExecutionStore-DYVukgCz.js} +1020 -814
  18. package/dist/chunks/converters-BsXgcxCW.cjs +1 -0
  19. package/dist/chunks/{converters-DpNB_WNQ.js → converters-DAr6IQbG.js} +15 -7
  20. package/dist/components/jogging/JoggingStore.d.ts +29 -3
  21. package/dist/core.cjs +1 -1
  22. package/dist/core.d.ts +4 -1
  23. package/dist/core.js +41 -35
  24. package/dist/index.cjs +1 -1
  25. package/dist/index.js +55 -46
  26. package/dist/lib/ControllerStateStream.d.ts +125 -0
  27. package/dist/lib/PoseTransformer.d.ts +22 -3
  28. package/dist/lib/controllerStateSource.d.ts +35 -0
  29. package/package.json +4 -4
  30. package/dist/chunks/Robot-BtP7w2z4.cjs +0 -1
  31. package/dist/chunks/TrajectoryExecutionStore-DMGcu1kk.cjs +0 -3
  32. package/dist/chunks/converters-C8I_A_tA.cjs +0 -1
  33. package/dist/chunks/useSmoothedMotionState-Con0E5Bx.cjs +0 -1
package/dist/3d.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("./chunks/Robot-BtP7w2z4.cjs"),t=require("./chunks/JoggingGizmo-DGbFLWgT.cjs"),i=require("./chunks/JoggingGizmoOrientation-dzned4f4.cjs"),r=require("./chunks/RobotControlPanel-BXtBHEe9.cjs"),e=require("./chunks/useSmoothedMotionState-Con0E5Bx.cjs");exports.CollisionSceneRenderer=o.CollisionSceneRenderer;exports.JointLimitGizmo=o.JointLimitGizmo;exports.LinearAxis=o.LinearAxis;exports.MotionGroupVisualizer=o.MotionGroupVisualizer;exports.MotionGroupVisualizerExact=o.MotionGroupVisualizerExact;exports.PresetEnvironment=o.PresetEnvironment;exports.Robot=o.Robot;exports.SafetyZonesRenderer=o.SafetyZonesRenderer;exports.SupportedLinearAxis=o.SupportedLinearAxis;exports.SupportedLinearAxisExact=o.SupportedLinearAxisExact;exports.SupportedRobot=o.SupportedRobot;exports.SupportedRobotExact=o.SupportedRobotExact;exports.TrajectoryRenderer=o.TrajectoryRenderer;exports.defaultGetModel=o.defaultGetModel;exports.JoggingGizmo=t.JoggingGizmo;exports.JoggingGizmoOrientation=i.JoggingGizmoOrientation;exports.RobotControlPanel=r.RobotControlPanel;exports.ValueInterpolator=e.ValueInterpolator;exports.useSmoothedMotionState=e.useSmoothedMotionState;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("./chunks/Robot-B3vKEVXP.cjs"),t=require("./chunks/JoggingGizmo-DGbFLWgT.cjs"),i=require("./chunks/JoggingGizmoOrientation-dzned4f4.cjs"),r=require("./chunks/RobotControlPanel-BXtBHEe9.cjs"),e=require("./chunks/Pose3-DIyg-aZA.cjs");exports.CollisionSceneRenderer=o.CollisionSceneRenderer;exports.JointLimitGizmo=o.JointLimitGizmo;exports.LinearAxis=o.LinearAxis;exports.MotionGroupVisualizer=o.MotionGroupVisualizer;exports.MotionGroupVisualizerExact=o.MotionGroupVisualizerExact;exports.PresetEnvironment=o.PresetEnvironment;exports.Robot=o.Robot;exports.SafetyZonesRenderer=o.SafetyZonesRenderer;exports.SupportedLinearAxis=o.SupportedLinearAxis;exports.SupportedLinearAxisExact=o.SupportedLinearAxisExact;exports.SupportedRobot=o.SupportedRobot;exports.SupportedRobotExact=o.SupportedRobotExact;exports.TrajectoryRenderer=o.TrajectoryRenderer;exports.defaultGetModel=o.defaultGetModel;exports.JoggingGizmo=t.JoggingGizmo;exports.JoggingGizmoOrientation=i.JoggingGizmoOrientation;exports.RobotControlPanel=r.RobotControlPanel;exports.Pose3=e.Pose3;exports.ValueInterpolator=e.ValueInterpolator;exports.parseRotationToQuaternion=e.parseRotationToQuaternion;exports.quaternionToRotationVector=e.quaternionToRotationVector;exports.useSmoothedMotionState=e.useSmoothedMotionState;
package/dist/3d.d.ts CHANGED
@@ -16,3 +16,5 @@ export * from "./components/robots/SupportedLinearAxis";
16
16
  export * from "./components/robots/SupportedRobot";
17
17
  export { ValueInterpolator, type InterpolationOptions, } from "./components/utils/interpolation";
18
18
  export * from "./components/utils/useSmoothedMotionState";
19
+ export { Pose3 } from "./lib/Pose3";
20
+ export { parseRotationToQuaternion, quaternionToRotationVector, } from "./lib/rotation";
package/dist/3d.js CHANGED
@@ -1,26 +1,29 @@
1
- import { C as a, J as r, L as t, M as s, a as i, P as n, R as p, S as d, b as m, c as u, d as x, e as l, T as R, f as S } from "./chunks/Robot-DegVn7HE.js";
1
+ import { C as a, J as t, L as r, M as s, a as i, P as n, R as p, S as u, b as d, c as m, d as x, e as R, T as l, f as S } from "./chunks/Robot-DXhaz1tq.js";
2
2
  import { J as c } from "./chunks/JoggingGizmo-SuS9MmL7.js";
3
3
  import { J as G } from "./chunks/JoggingGizmoOrientation-x_crT_64.js";
4
4
  import { R as b } from "./chunks/RobotControlPanel-BiLexAWI.js";
5
- import { V as L, a as M } from "./chunks/useSmoothedMotionState-COMJRcOt.js";
5
+ import { P as L, V as M, p as P, q as V, a as E } from "./chunks/Pose3-pocKPrHN.js";
6
6
  export {
7
7
  a as CollisionSceneRenderer,
8
8
  c as JoggingGizmo,
9
9
  G as JoggingGizmoOrientation,
10
- r as JointLimitGizmo,
11
- t as LinearAxis,
10
+ t as JointLimitGizmo,
11
+ r as LinearAxis,
12
12
  s as MotionGroupVisualizer,
13
13
  i as MotionGroupVisualizerExact,
14
+ L as Pose3,
14
15
  n as PresetEnvironment,
15
16
  p as Robot,
16
17
  b as RobotControlPanel,
17
- d as SafetyZonesRenderer,
18
- m as SupportedLinearAxis,
19
- u as SupportedLinearAxisExact,
18
+ u as SafetyZonesRenderer,
19
+ d as SupportedLinearAxis,
20
+ m as SupportedLinearAxisExact,
20
21
  x as SupportedRobot,
21
- l as SupportedRobotExact,
22
- R as TrajectoryRenderer,
23
- L as ValueInterpolator,
22
+ R as SupportedRobotExact,
23
+ l as TrajectoryRenderer,
24
+ M as ValueInterpolator,
24
25
  S as defaultGetModel,
25
- M as useSmoothedMotionState
26
+ P as parseRotationToQuaternion,
27
+ V as quaternionToRotationVector,
28
+ E as useSmoothedMotionState
26
29
  };
@@ -1 +1 @@
1
- "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const e=require("../chunks/RobotHeader-CqK0700U.cjs");exports.RobotHeader=e.RobotHeader;exports.default=e.RobotHeader;
1
+ "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const e=require("../chunks/RobotHeader-Daft80jq.cjs");exports.RobotHeader=e.RobotHeader;exports.default=e.RobotHeader;
@@ -1,4 +1,4 @@
1
- import { R as o, R as r } from "../chunks/RobotHeader-BZci9ahT.js";
1
+ import { R as o, R as r } from "../chunks/RobotHeader-DDmDkUoV.js";
2
2
  export {
3
3
  o as RobotHeader,
4
4
  r as default
@@ -1 +1 @@
1
- "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const e=require("../chunks/SafetyBar-Bbg-o8h9.cjs");exports.SafetyBar=e.SafetyBar;exports.default=e.SafetyBar;
1
+ "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const e=require("../chunks/SafetyBar-BVk-SH_0.cjs");exports.SafetyBar=e.SafetyBar;exports.default=e.SafetyBar;
@@ -1,4 +1,4 @@
1
- import { S as f, S as r } from "../chunks/SafetyBar-Cuak4ffd.js";
1
+ import { S as f, S as r } from "../chunks/SafetyBar-RkN0I1Cb.js";
2
2
  export {
3
3
  f as SafetyBar,
4
4
  r as default
@@ -0,0 +1 @@
1
+ "use strict";const I=require("@wandelbots/nova-js/v2"),v=require("mobx"),l=require("react"),u=require("three");function C(e){l.useEffect(e,[])}function O(e){C(()=>v.autorun(e))}function y(e){return C(()=>{let t;function i(){e(),t=requestAnimationFrame(i)}return t=requestAnimationFrame(i),()=>{cancelAnimationFrame(t)}})}function E(e){return e instanceof I.Nova?e:typeof e=="string"?new I.Nova({instanceUrl:e}):new I.Nova({instanceUrl:e.config.instanceUrl,accessToken:e.accessToken??e.config.accessToken??void 0})}function F(e){return typeof e=="string"?void 0:e.config.cellId}class R{constructor(t=[],i={}){this.currentValues=[],this.targetValues=[],this.previousTargetValues=[],this.targetUpdateTime=0,this.animationId=null,this.updateCount=0,this.velocities=[],this.animate=()=>{this.update(.016666666666666666)?this.animationId=null:this.animationId=requestAnimationFrame(this.animate)},this.options={tension:120,friction:20,threshold:.001,onChange:()=>{},onComplete:()=>{},...i},this.currentValues=[...t],this.targetValues=[...t],this.previousTargetValues=[...t],this.velocities=new Array(t.length).fill(0),this.targetUpdateTime=performance.now(),this.updateCount=0}update(t=1/60){let i=!1,n=!0;this.updateCount++;const o=Math.min(t,1/15),c=this.updateCount===1?.7:1;for(let r=0;r<this.currentValues.length;r++){const h=this.currentValues[r],f=this.targetValues[r],T=this.velocities[r],s=f-h,a=s*this.options.tension*c,d=T*this.options.friction,p=a-d,V=T+p*o,m=h+V*o;Math.abs(s)<this.options.threshold&&Math.abs(V)<this.options.threshold*10?this.currentValues[r]!==f&&(this.currentValues[r]=f,this.velocities[r]=0,i=!0):(n=!1,this.currentValues[r]=m,this.velocities[r]=V,i=!0)}return i&&this.options.onChange(this.currentValues),n&&this.options.onComplete(this.currentValues),n}setTarget(t){const i=performance.now(),n=i-this.targetUpdateTime;this.previousTargetValues=[...this.targetValues],this.targetValues=[...t],this.targetUpdateTime=i,this.updateCount=0;const o=this.previousTargetValues.every((c,r)=>c===this.currentValues[r]);if(n<8&&n>0&&this.previousTargetValues.length>0&&!o){const c=Math.min(n/8,1);for(let r=0;r<this.targetValues.length;r++){const h=this.previousTargetValues[r]||0,f=t[r]||0;Math.abs(f-h)>.1&&(this.targetValues[r]=h+(f-h)*c)}}for(;this.currentValues.length<t.length;)this.currentValues.push(t[this.currentValues.length]),this.velocities.push(0);this.currentValues.length>t.length&&(this.currentValues=this.currentValues.slice(0,t.length),this.velocities=this.velocities.slice(0,t.length))}getCurrentValues(){return[...this.currentValues]}getValue(t){return this.currentValues[t]??0}isInterpolating(){return this.animationId!==null}stop(){this.animationId!==null&&(cancelAnimationFrame(this.animationId),this.animationId=null)}setImmediate(t){this.stop(),this.currentValues=[...t],this.targetValues=[...t],this.previousTargetValues=[...t],this.velocities=new Array(t.length).fill(0),this.targetUpdateTime=performance.now(),this.updateCount=0,this.options.onChange(this.currentValues)}updateOptions(t){this.options={...this.options,...t}}startAutoInterpolation(){this.startInterpolation()}destroy(){this.stop()}startInterpolation(){this.animationId===null&&this.animate()}}function q(e=[],t={}){const i=l.useRef(null);return i.current||(i.current=new R(e,t)),l.useEffect(()=>{var n;(n=i.current)==null||n.updateOptions(t)},[t]),l.useEffect(()=>()=>{var n;(n=i.current)==null||n.destroy()},[]),[i.current]}function N(e,t){const[i]=l.useState(()=>v.observable({...e})),n=l.useRef(null),o=l.useRef(null),c=l.useRef(0);function r(){o.current!==null&&(cancelAnimationFrame(o.current),o.current=null)}function h(){const s=n.current;if(!s)return;const a=performance.now(),d=(a-c.current)/1e3;c.current=a;const p=s.update(d);v.runInAction(()=>{i.joint_position=s.getCurrentValues()}),o.current=p?null:requestAnimationFrame(h)}function f(){o.current===null&&(c.current=performance.now(),o.current=requestAnimationFrame(h))}function T(s){var d;const a=s.joint_position.filter(p=>p!==void 0);(d=n.current)==null||d.setTarget(a),v.runInAction(()=>{const p=s,V=i;for(const m of Object.keys(p))m!=="joint_position"&&V[m]!==p[m]&&(V[m]=p[m])}),f()}return C(()=>{const s=e.joint_position.filter(a=>a!==void 0);return n.current=new R(s,t),()=>{var a;r(),(a=n.current)==null||a.destroy()}}),l.useEffect(()=>{var s;t&&((s=n.current)==null||s.updateOptions(t))},[t]),l.useEffect(()=>v.autorun(()=>T(e)),[e]),i}function w(e,t){if(t==="QUATERNION"&&e)return new u.Quaternion(...e);if(t==="ROTATION_VECTOR"&&e){if(e&&e.length<3)throw new Error(`Invalid rotation vector length: ${e.length}. Expected at least 3 values.`);const i=new u.Vector3(e[0],e[1],e[2]),n=i.length(),o=i.normalize();return new u.Quaternion().setFromAxisAngle(o,n)}else return console.warn(`Unsupported rotation type '${t}'. Only QUATERNION and ROTATION_VECTOR are supported for now.`),new u.Quaternion}function A(e){const t=new u.Vector3(e.x,e.y,e.z),i=2*Math.atan2(t.length(),Math.abs(e.w));t.normalize();const n=(e.w>=0?1:0)-(e.w<0?1:0);return t.multiplyScalar(n).multiplyScalar(i)}class g{constructor(t,i){this.position=t,this.quaternion=i}static fromPose(t){const i=t.orientation?w(t.orientation,"ROTATION_VECTOR"):new u.Quaternion,n=t.position??[0,0,0];return new g(new u.Vector3(n[0]??0,n[1]??0,n[2]??0),i)}static fromRobotTcp(t){const i=t.orientation?w(t.orientation,t.orientation_type??"ROTATION_VECTOR"):new u.Quaternion,n=t.position??[0,0,0];return new g(new u.Vector3(n[0]??0,n[1]??0,n[2]??0),i)}static fromCoordinateSystem(t){const i=t.orientation?w(t.orientation,t.orientation_type??"ROTATION_VECTOR"):new u.Quaternion,n=t.position??[0,0,0];return new g(new u.Vector3(n[0]??0,n[1]??0,n[2]??0),i)}inverse(){const t=this.quaternion.clone().invert();return new g(this.position.clone().applyQuaternion(t).multiplyScalar(-1),t)}multiply(t){return new g(this.position.clone().add(t.position.clone().applyQuaternion(this.quaternion)),this.quaternion.clone().multiply(t.quaternion).normalize())}get orientation(){return A(this.quaternion)}}exports.Pose3=g;exports.ValueInterpolator=R;exports.cellIdOf=F;exports.createNovaClient=E;exports.parseRotationToQuaternion=w;exports.quaternionToRotationVector=A;exports.useAnimationFrame=y;exports.useAutorun=O;exports.useInterpolation=q;exports.useSmoothedMotionState=N;
@@ -1,34 +1,35 @@
1
- import { Nova as d } from "@wandelbots/nova-js/v2";
2
- import { autorun as A, observable as y, runInAction as T } from "mobx";
3
- import V, { useEffect as C, useState as w, useRef as v } from "react";
4
- function I(e) {
5
- C(e, []);
1
+ import { Nova as w } from "@wandelbots/nova-js/v2";
2
+ import { autorun as y, observable as E, runInAction as R } from "mobx";
3
+ import v, { useEffect as A, useState as U, useRef as I } from "react";
4
+ import { Quaternion as d, Vector3 as T } from "three";
5
+ function O(e) {
6
+ A(e, []);
6
7
  }
7
- function _(e) {
8
- I(() => A(e));
8
+ function Q(e) {
9
+ O(() => y(e));
9
10
  }
10
11
  function j(e) {
11
- return I(() => {
12
+ return O(() => {
12
13
  let t;
13
- function n() {
14
- e(), t = requestAnimationFrame(n);
14
+ function i() {
15
+ e(), t = requestAnimationFrame(i);
15
16
  }
16
- return t = requestAnimationFrame(n), () => {
17
+ return t = requestAnimationFrame(i), () => {
17
18
  cancelAnimationFrame(t);
18
19
  };
19
20
  });
20
21
  }
21
22
  function k(e) {
22
- return e instanceof d ? e : typeof e == "string" ? new d({ instanceUrl: e }) : new d({
23
+ return e instanceof w ? e : typeof e == "string" ? new w({ instanceUrl: e }) : new w({
23
24
  instanceUrl: e.config.instanceUrl,
24
25
  accessToken: e.accessToken ?? e.config.accessToken ?? void 0
25
26
  });
26
27
  }
27
- function q(e) {
28
+ function z(e) {
28
29
  return typeof e == "string" ? void 0 : e.config.cellId;
29
30
  }
30
31
  class F {
31
- constructor(t = [], n = {}) {
32
+ constructor(t = [], i = {}) {
32
33
  this.currentValues = [], this.targetValues = [], this.previousTargetValues = [], this.targetUpdateTime = 0, this.animationId = null, this.updateCount = 0, this.velocities = [], this.animate = () => {
33
34
  this.update(0.016666666666666666) ? this.animationId = null : this.animationId = requestAnimationFrame(this.animate);
34
35
  }, this.options = {
@@ -39,7 +40,7 @@ class F {
39
40
  },
40
41
  onComplete: () => {
41
42
  },
42
- ...n
43
+ ...i
43
44
  }, this.currentValues = [...t], this.targetValues = [...t], this.previousTargetValues = [...t], this.velocities = new Array(t.length).fill(0), this.targetUpdateTime = performance.now(), this.updateCount = 0;
44
45
  }
45
46
  /**
@@ -52,14 +53,14 @@ class F {
52
53
  * @returns true when interpolation is complete (all values reached their targets)
53
54
  */
54
55
  update(t = 1 / 60) {
55
- let n = !1, s = !0;
56
+ let i = !1, n = !0;
56
57
  this.updateCount++;
57
58
  const o = Math.min(t, 1 / 15), u = this.updateCount === 1 ? 0.7 : 1;
58
- for (let i = 0; i < this.currentValues.length; i++) {
59
- const l = this.currentValues[i], h = this.targetValues[i], g = this.velocities[i], r = h - l, a = r * this.options.tension * u, f = g * this.options.friction, c = a - f, m = g + c * o, p = l + m * o;
60
- Math.abs(r) < this.options.threshold && Math.abs(m) < this.options.threshold * 10 ? this.currentValues[i] !== h && (this.currentValues[i] = h, this.velocities[i] = 0, n = !0) : (s = !1, this.currentValues[i] = p, this.velocities[i] = m, n = !0);
59
+ for (let r = 0; r < this.currentValues.length; r++) {
60
+ const l = this.currentValues[r], h = this.targetValues[r], V = this.velocities[r], s = h - l, a = s * this.options.tension * u, f = V * this.options.friction, c = a - f, m = V + c * o, p = l + m * o;
61
+ Math.abs(s) < this.options.threshold && Math.abs(m) < this.options.threshold * 10 ? this.currentValues[r] !== h && (this.currentValues[r] = h, this.velocities[r] = 0, i = !0) : (n = !1, this.currentValues[r] = p, this.velocities[r] = m, i = !0);
61
62
  }
62
- return n && this.options.onChange(this.currentValues), s && this.options.onComplete(this.currentValues), s;
63
+ return i && this.options.onChange(this.currentValues), n && this.options.onComplete(this.currentValues), n;
63
64
  }
64
65
  /**
65
66
  * Set new target values for the interpolation to move towards
@@ -68,16 +69,16 @@ class F {
68
69
  * to prevent jarring movements when targets change frequently.
69
70
  */
70
71
  setTarget(t) {
71
- const n = performance.now(), s = n - this.targetUpdateTime;
72
- this.previousTargetValues = [...this.targetValues], this.targetValues = [...t], this.targetUpdateTime = n, this.updateCount = 0;
72
+ const i = performance.now(), n = i - this.targetUpdateTime;
73
+ this.previousTargetValues = [...this.targetValues], this.targetValues = [...t], this.targetUpdateTime = i, this.updateCount = 0;
73
74
  const o = this.previousTargetValues.every(
74
- (u, i) => u === this.currentValues[i]
75
+ (u, r) => u === this.currentValues[r]
75
76
  );
76
- if (s < 8 && s > 0 && this.previousTargetValues.length > 0 && !o) {
77
- const u = Math.min(s / 8, 1);
78
- for (let i = 0; i < this.targetValues.length; i++) {
79
- const l = this.previousTargetValues[i] || 0, h = t[i] || 0;
80
- Math.abs(h - l) > 0.1 && (this.targetValues[i] = l + (h - l) * u);
77
+ if (n < 8 && n > 0 && this.previousTargetValues.length > 0 && !o) {
78
+ const u = Math.min(n / 8, 1);
79
+ for (let r = 0; r < this.targetValues.length; r++) {
80
+ const l = this.previousTargetValues[r] || 0, h = t[r] || 0;
81
+ Math.abs(h - l) > 0.1 && (this.targetValues[r] = l + (h - l) * u);
81
82
  }
82
83
  }
83
84
  for (; this.currentValues.length < t.length; )
@@ -149,66 +150,143 @@ class F {
149
150
  this.animationId === null && this.animate();
150
151
  }
151
152
  }
152
- function O(e = [], t = {}) {
153
- const n = V.useRef(null);
154
- return n.current || (n.current = new F(e, t)), V.useEffect(() => {
155
- var s;
156
- (s = n.current) == null || s.updateOptions(t);
157
- }, [t]), V.useEffect(() => () => {
158
- var s;
159
- (s = n.current) == null || s.destroy();
160
- }, []), [n.current];
153
+ function L(e = [], t = {}) {
154
+ const i = v.useRef(null);
155
+ return i.current || (i.current = new F(e, t)), v.useEffect(() => {
156
+ var n;
157
+ (n = i.current) == null || n.updateOptions(t);
158
+ }, [t]), v.useEffect(() => () => {
159
+ var n;
160
+ (n = i.current) == null || n.destroy();
161
+ }, []), [i.current];
161
162
  }
162
- function E(e, t) {
163
- const [n] = w(
164
- () => y({ ...e })
165
- ), s = v(null), o = v(null), u = v(0);
166
- function i() {
163
+ function S(e, t) {
164
+ const [i] = U(
165
+ () => E({ ...e })
166
+ ), n = I(null), o = I(null), u = I(0);
167
+ function r() {
167
168
  o.current !== null && (cancelAnimationFrame(o.current), o.current = null);
168
169
  }
169
170
  function l() {
170
- const r = s.current;
171
- if (!r) return;
171
+ const s = n.current;
172
+ if (!s) return;
172
173
  const a = performance.now(), f = (a - u.current) / 1e3;
173
174
  u.current = a;
174
- const c = r.update(f);
175
- T(() => {
176
- n.joint_position = r.getCurrentValues();
175
+ const c = s.update(f);
176
+ R(() => {
177
+ i.joint_position = s.getCurrentValues();
177
178
  }), o.current = c ? null : requestAnimationFrame(l);
178
179
  }
179
180
  function h() {
180
181
  o.current === null && (u.current = performance.now(), o.current = requestAnimationFrame(l));
181
182
  }
182
- function g(r) {
183
+ function V(s) {
183
184
  var f;
184
- const a = r.joint_position.filter(
185
+ const a = s.joint_position.filter(
185
186
  (c) => c !== void 0
186
187
  );
187
- (f = s.current) == null || f.setTarget(a), T(() => {
188
- const c = r, m = n;
188
+ (f = n.current) == null || f.setTarget(a), R(() => {
189
+ const c = s, m = i;
189
190
  for (const p of Object.keys(c))
190
191
  p !== "joint_position" && m[p] !== c[p] && (m[p] = c[p]);
191
192
  }), h();
192
193
  }
193
- return I(() => {
194
- const r = e.joint_position.filter(
194
+ return O(() => {
195
+ const s = e.joint_position.filter(
195
196
  (a) => a !== void 0
196
197
  );
197
- return s.current = new F(r, t), () => {
198
+ return n.current = new F(s, t), () => {
198
199
  var a;
199
- i(), (a = s.current) == null || a.destroy();
200
+ r(), (a = n.current) == null || a.destroy();
200
201
  };
201
- }), C(() => {
202
- var r;
203
- t && ((r = s.current) == null || r.updateOptions(t));
204
- }, [t]), C(() => A(() => g(e)), [e]), n;
202
+ }), A(() => {
203
+ var s;
204
+ t && ((s = n.current) == null || s.updateOptions(t));
205
+ }, [t]), A(() => y(() => V(e)), [e]), i;
206
+ }
207
+ function C(e, t) {
208
+ if (t === "QUATERNION" && e)
209
+ return new d(...e);
210
+ if (t === "ROTATION_VECTOR" && e) {
211
+ if (e && e.length < 3)
212
+ throw new Error(
213
+ `Invalid rotation vector length: ${e.length}. Expected at least 3 values.`
214
+ );
215
+ const i = new T(
216
+ e[0],
217
+ e[1],
218
+ e[2]
219
+ ), n = i.length(), o = i.normalize();
220
+ return new d().setFromAxisAngle(o, n);
221
+ } else
222
+ return console.warn(
223
+ `Unsupported rotation type '${t}'. Only QUATERNION and ROTATION_VECTOR are supported for now.`
224
+ ), new d();
225
+ }
226
+ function q(e) {
227
+ const t = new T(e.x, e.y, e.z), i = 2 * Math.atan2(t.length(), Math.abs(e.w));
228
+ t.normalize();
229
+ const n = (e.w >= 0 ? 1 : 0) - (e.w < 0 ? 1 : 0);
230
+ return t.multiplyScalar(n).multiplyScalar(i);
231
+ }
232
+ class g {
233
+ constructor(t, i) {
234
+ this.position = t, this.quaternion = i;
235
+ }
236
+ static fromPose(t) {
237
+ const i = t.orientation ? C(t.orientation, "ROTATION_VECTOR") : new d(), n = t.position ?? [0, 0, 0];
238
+ return new g(
239
+ new T(n[0] ?? 0, n[1] ?? 0, n[2] ?? 0),
240
+ i
241
+ );
242
+ }
243
+ /** A TCP's offset from the flange */
244
+ static fromRobotTcp(t) {
245
+ const i = t.orientation ? C(
246
+ t.orientation,
247
+ t.orientation_type ?? "ROTATION_VECTOR"
248
+ ) : new d(), n = t.position ?? [0, 0, 0];
249
+ return new g(
250
+ new T(n[0] ?? 0, n[1] ?? 0, n[2] ?? 0),
251
+ i
252
+ );
253
+ }
254
+ static fromCoordinateSystem(t) {
255
+ const i = t.orientation ? C(
256
+ t.orientation,
257
+ t.orientation_type ?? "ROTATION_VECTOR"
258
+ ) : new d(), n = t.position ?? [0, 0, 0];
259
+ return new g(
260
+ new T(n[0] ?? 0, n[1] ?? 0, n[2] ?? 0),
261
+ i
262
+ );
263
+ }
264
+ inverse() {
265
+ const t = this.quaternion.clone().invert();
266
+ return new g(
267
+ this.position.clone().applyQuaternion(t).multiplyScalar(-1),
268
+ t
269
+ );
270
+ }
271
+ multiply(t) {
272
+ return new g(
273
+ this.position.clone().add(t.position.clone().applyQuaternion(this.quaternion)),
274
+ this.quaternion.clone().multiply(t.quaternion).normalize()
275
+ );
276
+ }
277
+ get orientation() {
278
+ return q(this.quaternion);
279
+ }
205
280
  }
206
281
  export {
282
+ g as P,
207
283
  F as V,
208
- E as a,
209
- _ as b,
284
+ S as a,
285
+ Q as b,
210
286
  k as c,
211
287
  j as d,
212
- q as e,
213
- O as u
288
+ z as e,
289
+ C as p,
290
+ q,
291
+ L as u
214
292
  };
@@ -0,0 +1 @@
1
+ "use strict";const o=require("react/jsx-runtime"),w=require("three"),C=require("three-stdlib"),S=require("@react-three/drei"),m=require("react"),A=require("./converters-BsXgcxCW.cjs"),O=require("@wandelbots/nova-js/v2"),T=require("./externalizeComponent-BdxGBLIv.cjs"),L=require("./Pose3-DIyg-aZA.cjs"),D=require("react-error-boundary"),$=require("@react-three/fiber");function re(e){const n=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const t in e)if(t!=="default"){const r=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(n,t,r.get?r:{enumerable:!0,get:()=>e[t]})}}return n.default=e,Object.freeze(n)}const R=re(w);function ie(e){switch(e.shape_type){case"convex_hull":return new C.ConvexGeometry(e.vertices.map(t=>new R.Vector3(t[0]/1e3,t[1]/1e3,t[2]/1e3)));case"box":return new R.BoxGeometry(e.size_x/1e3,e.size_y/1e3,e.size_z/1e3);case"sphere":return new R.SphereGeometry(e.radius/1e3);case"capsule":return new R.CapsuleGeometry(e.radius/1e3,e.cylinder_height/1e3);case"cylinder":return new R.CylinderGeometry(e.radius/1e3,e.radius/1e3,e.height/1e3);case"rectangle":return new R.BoxGeometry(e.size_x/1e3,e.size_y/1e3,0);default:return console.warn(`${e.shape_type} is not supported`),new R.BufferGeometry}}function se({name:e,collider:n,children:t}){var c,l;const r=((c=n.pose)==null?void 0:c.position)??[0,0,0],i=((l=n.pose)==null?void 0:l.orientation)??[0,0,0];return n.margin&&console.warn(`${e} margin is not supported`),o.jsx("mesh",{name:e,position:new R.Vector3(r[0],r[1],r[2]).divideScalar(1e3),rotation:new R.Euler(i[0],i[1],i[2],"XYZ"),geometry:ie(n.shape),children:t})}function ae({name:e,colliders:n,meshChildrenProvider:t,...r}){return o.jsx("group",{name:e,...r,children:Object.entries(n).map(([i,c])=>o.jsx(se,{name:i,collider:c,children:t(i,c)},i))})}function ce({scene:e,meshChildrenProvider:n}){const t=e.colliders;return o.jsx("group",{children:t&&o.jsx(ae,{meshChildrenProvider:n,colliders:t})})}function le(e){const n=(e==null?void 0:e.position)??[],t=(e==null?void 0:e.orientation)??[],r=new w.Vector3(t[0]??0,t[1]??0,t[2]??0),i=r.length(),c=i>0?new w.Quaternion().setFromAxisAngle(r.normalize(),i):new w.Quaternion;return new w.Matrix4().compose(new w.Vector3(n[0]??0,n[1]??0,n[2]??0).divideScalar(1e3),c,new w.Vector3(1,1,1))}function ue(e,n=null,t=[]){const r=le(n);return e.map((i,c)=>{const l=r.clone(),s=(i.reverse_rotation_direction?-1:1)*(t[c]??0),a=i.type==="PRISMATIC_JOINT",f=(i.theta??0)+(a?0:s),p=(i.d??0)+(a?s:0);return r.multiply(new w.Matrix4().makeRotationZ(f)).multiply(new w.Matrix4().makeTranslation((i.a??0)/1e3,0,p/1e3)).multiply(new w.Matrix4().makeRotationX(i.alpha??0)),l})}const P="#ff4b4b",q="#2fa8ff",fe="#8a8d9e",pe=96,me=.15,he=new R.Vector3(0,1,0),de=.2,xe=2;function ge(e){const{lower_limit:n,upper_limit:t}=e??{};return typeof n!="number"||typeof t!="number"||!Number.isFinite(n)||!Number.isFinite(t)||!(n<t)?null:{lower_limit:n,upper_limit:t}}function k({base:e,direction:n,size:t,color:r,opacity:i}){const c=new R.Quaternion().setFromUnitVectors(he,n.clone().normalize()),l=e.clone().addScaledVector(n.clone().normalize(),t/2);return o.jsxs("mesh",{position:l,quaternion:c,renderOrder:10,children:[o.jsx("coneGeometry",{args:[t*.35,t,16]}),o.jsx("meshBasicMaterial",{color:r,depthTest:!1,transparent:!0,opacity:i})]})}function V({points:e,color:n,width:t,opacity:r}){return o.jsx(S.Line,{points:e,color:n,lineWidth:t,depthTest:!1,transparent:!0,opacity:r,renderOrder:10})}function J(e,n){const t=[...e];let r=n;for(;t.length>1;){const i=t[t.length-1],c=t[t.length-2],l=i.distanceTo(c);if(l>r)return t[t.length-1]=i.clone().lerp(c,r/l),t;r-=l,t.pop()}return t}function ye(e,n,t,r){const i=t*e,c=t*n,l=Math.abs(c-i),s=Math.max(2,Math.ceil(l/(2*Math.PI)*pe));return Array.from({length:s+1},(a,f)=>{const p=i+(c-i)*f/s,u=l*f/s/(2*Math.PI),y=r*(1+me*u);return new R.Vector3(Math.cos(p)*y,Math.sin(p)*y,0)})}function je(e,n,t,r){const i=e.theta??0,c=e.d??0,l=e.type==="PRISMATIC_JOINT",s=e.reverse_rotation_direction?-1:1,{lower_limit:a,upper_limit:f}=n;return m.useMemo(()=>{const p=new R.Matrix4().makeRotationZ(i).multiply(new R.Matrix4().makeTranslation(0,0,l?c/1e3:0)),u=(M,_,v)=>new R.Vector3(M,_,v).applyMatrix4(p),y=new R.Vector3().applyMatrix4(p),j=u(0,0,t),d=(l?[u(t*.25,0,s*a/1e3),u(t*.25,0,s*f/1e3)]:ye(a,f,s,t*.6)).map(M=>l?M:M.applyMatrix4(p)),h=u(l?t*.25:t*.6,0,0),b=d.slice(1).reduce((M,_,v)=>M+_.distanceTo(d[v]),0),x=Math.min(r,b/3),g=J(J(d,x).reverse(),x).reverse();return{axisPoints:[y,j],axisTip:j,origin:y,restPoints:[y,h],range:d,limitPoints:g,rangeStart:g[0],rangeEnd:g[g.length-1]}},[i,c,l,s,t,a,f,r])}function we({frame:e,dh:n,limit:t,size:r,emphasis:i}){const c=i==="highlighted"?xe:1,l=i==="dimmed"?de:1,s=r*.2*(i==="highlighted"?1.4:1),a=2*c,{axisPoints:f,axisTip:p,origin:u,restPoints:y,range:j,limitPoints:d,rangeStart:h,rangeEnd:b}=je(n,t,r,s),{position:x,quaternion:g}=m.useMemo(()=>{const M=new R.Vector3,_=new R.Quaternion;return e.decompose(M,_,new R.Vector3),{position:M,quaternion:_}},[e]);return o.jsxs("group",{position:x,quaternion:g,children:[o.jsx(V,{points:f,color:q,width:a,opacity:l}),o.jsx(k,{base:p,direction:p.clone().sub(u),size:s,color:q,opacity:l}),o.jsx(V,{points:y,color:fe,width:1.5*c,opacity:l}),o.jsx(V,{points:d,color:P,width:a,opacity:l}),o.jsx(k,{base:h,direction:j[0].clone().sub(h),size:h.distanceTo(j[0]),color:P,opacity:l}),o.jsx(k,{base:b,direction:j[j.length-1].clone().sub(b),size:b.distanceTo(j[j.length-1]),color:P,opacity:l})]})}function Re({dhParameters:e,chainOffset:n=null,limits:t,jointPositions:r,size:i=.15,highlightedJoint:c=null}){const l=m.useMemo(()=>ue(e,n,r),[e,n,r]);return o.jsx("group",{children:l.map((s,a)=>{const f=ge(t[a]);return f?o.jsx(we,{frame:s,dh:e[a],limit:f,size:i,emphasis:c===null?"normal":c===a?"highlighted":"dimmed"},a):null})})}function be(){return o.jsx(S.Environment,{frames:1,children:o.jsx(Se,{})})}const Me=[2,0,2,0,2,0,2,0];function Se({positions:e=Me}){return o.jsxs(o.Fragment,{children:[o.jsx(S.Lightformer,{intensity:5,"rotation-x":Math.PI/2,position:[0,5,-9],scale:[10,10,1]}),o.jsx("group",{rotation:[0,.5,0],children:o.jsx("group",{children:e.map((n,t)=>o.jsx(S.Lightformer,{form:"circle",intensity:5,rotation:[Math.PI/2,0,0],position:[n,4,t*4],scale:[3,1,1]},t))})}),o.jsx(S.Lightformer,{intensity:40,"rotation-y":Math.PI/2,position:[-5,1,-1],scale:[20,.1,1]}),o.jsx(S.Lightformer,{intensity:20,"rotation-y":-Math.PI,position:[-5,-2,-1],scale:[20,.1,1]}),o.jsx(S.Lightformer,{"rotation-y":Math.PI/2,position:[-5,-1,-1],scale:[20,.5,1],intensity:5}),o.jsx(S.Lightformer,{"rotation-y":-Math.PI/2,position:[10,1,0],scale:[20,1,1],intensity:10}),o.jsx(S.Lightformer,{form:"ring",color:"white",intensity:5,scale:10,position:[-15,4,-18],target:[0,0,0]})]})}const N={attach:"material",color:"#009f4d",opacity:.2,depthTest:!1,depthWrite:!1,transparent:!0,polygonOffset:!0};function _e({safetyZones:e,dhParameters:n,...t}){const r=m.useMemo(()=>A.dhParametersToPlaneSize(n??[]),[n]),i=(l,s)=>{var y,j;if(!((y=s==null?void 0:s.pose)!=null&&y.position)||!((j=s==null?void 0:s.pose)!=null&&j.orientation))return null;const a=new R.Vector3(s.pose.position[0]/1e3,s.pose.position[1]/1e3,s.pose.position[2]/1e3),f=new R.Vector3(s.pose.orientation[0],s.pose.orientation[1],s.pose.orientation[2]);let p;const u=s.shape.shape_type==="plane"?{...N,side:R.DoubleSide}:{...N,side:R.FrontSide};switch(s.shape.shape_type){case"plane":p=o.jsx("planeGeometry",{args:[r,r]});break;case"sphere":{const d=(s==null?void 0:s.shape).radius/1e3;p=o.jsx("sphereGeometry",{args:[d]});break}case"capsule":{const d=(s==null?void 0:s.shape).radius/1e3,h=(s==null?void 0:s.shape).cylinder_height/1e3;p=o.jsx("capsuleGeometry",{args:[d,h]});break}case"convex_hull":{const d=(s==null?void 0:s.shape).vertices.map(b=>new R.Vector3(b[0]/1e3,b[1]/1e3,b[2]/1e3)),h=A.verticesToCoplanarity(d);if(h.isCoplanar&&h.normal){const x=new R.Vector3().addVectors(d[0],h.normal.multiplyScalar(1e-4));d.push(x)}try{p=o.jsx("primitive",{object:new C.ConvexGeometry(d),attach:"geometry"})}catch(b){return console.log("Error creating ConvexGeometry:",b),null}break}case"rectangular_capsule":{const d=s.shape,h=d.radius/1e3,b=d.sphere_center_distance_x/1e3,x=d.sphere_center_distance_y/1e3,g=h*2;p=o.jsx("primitive",{object:new C.RoundedBoxGeometry(b,x,g,2,h),attach:"geometry"});break}default:console.warn("Unsupported safety zone shape type:",s.shape.shape_type),p=null}return o.jsxs("mesh",{renderOrder:l,position:a,quaternion:A.orientationToQuaternion(f),children:[p,o.jsx("meshStandardMaterial",{...u,polygonOffsetFactor:-l})]},`safety-zone-${s.shape.shape_type}-${l}`)},c=m.useMemo(()=>Object.values(e??{}).map((l,s)=>i(s,l)),[e,r]);return o.jsx("group",{...t,children:c})}function ve({trajectory:e,...n}){const t=(e==null?void 0:e.map(r=>{if(r.position&&r.position.length>=3){const[i,c,l]=r.position;if(Number.isFinite(i)&&Number.isFinite(c)&&Number.isFinite(l))return new R.Vector3(i/1e3,l/1e3,-c/1e3)}return null}).filter(r=>r!==null))||[];return o.jsx("group",{...n,children:t.length>0&&o.jsx(S.Line,{points:t,lineWidth:3,polygonOffset:!0,polygonOffsetFactor:10,polygonOffsetUnits:10})})}const G=new Map;async function E(e,n){const t=n||"";if(!t)throw new Error(`Cannot download the model "${e}": no NOVA instance. Give defaultGetModel the URL of the instance or a NOVA client, or give the component its instanceUrl or getModel.`);const r=`${Te(t)} ${e}`,i=G.get(r);if(i)return i;const c=(async()=>{const l=L.createNovaClient(t);try{const s=await l.api.motionGroupModels.getMotionGroupGlbModel(e,{responseType:"blob"});return URL.createObjectURL(s)}catch(s){throw console.error("Failed to fetch model:",s),s}})();return G.set(r,c),c.catch(()=>{G.get(r)===c&&G.delete(r)}),c}function Te(e){return typeof e=="string"?e:e.config.instanceUrl}function Q(e){function n(t){return t.children.length===0?[t]:[t,...t.children.flatMap(r=>n(r))]}return n(e).filter(t=>W(t))}function U(e){return e.name.endsWith("_FLG")}function W(e){return/_J[0-9]+$/.test(e.name)}function Le(e,n){let t;function r(i){if(U(i)){if(t)throw Error(`Found multiple flange groups in robot model ${n}; first ${t.name} then ${i.name}. Only one _FLG group is allowed.`);t=i}W(i),i.children.map(r)}if(r(e.scene),!t)throw Error(`No flange group found in robot model ${n}. Flange must be identified with a name ending in _FLG.`);return{gltf:e}}const H=m.forwardRef(function({rapidlyChangingMotionState:n,dhParameters:t,chainOffsetPosition:r,chainOffsetQuaternion:i,onTranslationChanged:c,children:l},s){const a=m.useRef(null),f=m.useRef([]),p=m.useRef(n.joint_position.filter(x=>x!==void 0)),{invalidate:u}=$.useThree(),y=m.useRef(n);y.current=n;function j(x){a.current=x,x&&d()}function d(){a.current&&(f.current=Q(a.current),h(),u())}m.useImperativeHandle(s,()=>({recollectJoints:d}));function h(){const x=p.current;if(c)c(f.current,x);else for(const[g,M]of f.current.entries()){const v=t[g].reverse_rotation_direction?-1:1;M.position.y=v*(x[g]||0)/1e3}}function b(x){p.current=x.joint_position.filter(g=>g!==void 0),h(),u()}return L.useAutorun(()=>{b(y.current)}),o.jsx("group",{ref:j,position:r,quaternion:i,children:l})});function B({rapidlyChangingMotionState:e,dhParameters:n,...t}){const r=new w.Matrix4,i=m.useRef(null),c=m.useRef(null);function l(f){const p=new w.Matrix4;for(let d=0;d<n.length;d++){const h=n[d],b=f[d]??0,x=new w.Matrix4().makeRotationY(h.theta).multiply(new w.Matrix4().makeTranslation(h.a/1e3,(h.d+b*(h.reverse_rotation_direction?-1:1))/1e3,0)).multiply(new w.Matrix4().makeRotationX(h.alpha));p.multiply(x)}const u=new w.Vector3,y=new w.Quaternion,j=new w.Vector3;return p.decompose(u,y,j),u}const s=l(e.joint_position);function a(f,p){r.identity();let u=new w.Vector3;for(let h=0;h<n.length;h++){const b=p[h]??0,x=n[h],g=new w.Matrix4().makeRotationY(x.theta).multiply(new w.Matrix4().makeTranslation(x.a/1e3,(x.d+b*(x.reverse_rotation_direction?-1:1))/1e3,0)).multiply(new w.Matrix4().makeRotationX(x.alpha));r.multiply(g)}const y=new w.Vector3,j=new w.Quaternion,d=new w.Vector3;if(r.decompose(y,j,d),u=y,i.current&&i.current.position.set(u.x,u.y,u.z),c.current){const h=c.current.geometry;h!=null&&h.setPositions&&h.setPositions([0,0,0,u.x,u.y,u.z])}}return o.jsx(H,{rapidlyChangingMotionState:e,dhParameters:n,onTranslationChanged:a,children:o.jsxs("group",{...t,name:"Scene",children:[o.jsxs("mesh",{name:"Base",position:[0,0,0],children:[o.jsx("sphereGeometry",{args:[.02,32,32]}),o.jsx("meshStandardMaterial",{color:"green",depthTest:!0})]}),o.jsx(S.Line,{ref:c,points:[new w.Vector3(0,0,0),s],color:"White",lineWidth:5}),o.jsxs("mesh",{ref:i,name:"TCP",position:s,children:[o.jsx("sphereGeometry",{args:[.025,32,32]}),o.jsx("meshStandardMaterial",{color:"red",depthTest:!0})]})]})})}const Ee=console.warn;function X(){return m.useEffect(()=>{console.warn=e=>{e!=="Cannot call the manual advancement of rafz whilst frameLoop is not set as demand"&&Ee(e)}},[]),null}function Oe(e){return e.type==="Mesh"}function Ge({url:e,flangeRef:n,postModelRender:t,...r}){const i=S.useGLTF(e),l=Le(i,"robot.glb").gltf;m.useEffect(()=>{t==null||t()},[e,t]);function s(a){try{return Oe(a)?a.geometry?o.jsx("mesh",{name:a.name,geometry:a.geometry,material:a.material,position:a.position,rotation:a.rotation},a.uuid):o.jsx("group",{name:a.name,position:a.position,rotation:a.rotation},a.uuid):o.jsx("group",{name:a.name,position:a.position,rotation:a.rotation,ref:U(a)?n:void 0,children:a.children.map(s)},a.uuid)}catch(f){return console.warn("Error rendering node",a.name,f),null}}return o.jsx("group",{...r,dispose:null,children:s(l.scene)})}function Y({modelURL:e,flangeRef:n,postModelRender:t,...r}){const[i,c]=m.useState(null);return m.useEffect(()=>{let l=!1;return(async()=>{try{const a=typeof e=="string"?e:await e;l||c(f=>f===a?f:a)}catch(a){console.error("Failed to resolve model URL:",a)}})(),()=>{l=!0}},[e]),i?o.jsx(Ge,{url:i,flangeRef:n,postModelRender:t,...r}):null}const Z=(e,n)=>{e.userData.isGhost||(e.traverse(t=>{if(t instanceof R.Mesh){t.material instanceof R.Material&&(t.material.colorWrite=!1);const r=t.clone(),i=t.clone();r.material=new R.MeshStandardMaterial({depthTest:!0,depthWrite:!0,colorWrite:!1,polygonOffset:!0,polygonOffsetFactor:-1,side:R.DoubleSide}),r.userData.isGhost=!0,i.material=new R.MeshStandardMaterial({color:n,opacity:.3,depthTest:!0,depthWrite:!1,transparent:!0,polygonOffset:!0,polygonOffsetFactor:-2,side:R.DoubleSide}),i.userData.isGhost=!0,t.parent&&(t.parent.add(r),t.parent.add(i))}}),e.userData.isGhost=!0)},K=e=>{if(!e.userData.isGhost)return;const n=[];e.traverse(t=>{var r;t instanceof R.Mesh&&((r=t.userData)!=null&&r.isGhost?n.push(t):t.material instanceof R.Material&&(t.material.colorWrite=!0))}),n.forEach(t=>{t.parent&&t.parent.remove(t)}),e.userData.isGhost=!1},I=T.externalizeComponent(({rapidlyChangingMotionState:e,modelFromController:n,dhParameters:t,chainOffsetPosition:r,chainOffsetQuaternion:i,getModel:c=E,flangeRef:l,postModelRender:s,transparentColor:a,instanceUrl:f,...p})=>{const[u,y]=m.useState(null),j=m.useRef(null),d=m.useCallback(g=>{y(g)},[]),h=m.useCallback(()=>{var g;(g=j.current)==null||g.recollectJoints(),s==null||s()},[s]);m.useEffect(()=>{u&&(a?Z(u,a):K(u))},[u,a]);const b=m.useMemo(()=>{const g=c(n,f);if(!g){const M=new Blob([],{type:"model/gltf-binary"}),_=new File([M],`${n}.glb`,{type:"model/gltf-binary"});return Promise.resolve(URL.createObjectURL(_))}return g},[n,f,c]),x=o.jsx(B,{rapidlyChangingMotionState:e,dhParameters:t,...p});return o.jsxs(D.ErrorBoundary,{fallback:x,onError:g=>{console.warn(g)},children:[o.jsx(m.Suspense,{fallback:x,children:o.jsx("group",{ref:d,children:o.jsx(H,{ref:j,rapidlyChangingMotionState:e,dhParameters:t,chainOffsetPosition:r,chainOffsetQuaternion:i,children:o.jsx(Y,{modelURL:b,postModelRender:h,flangeRef:l,...p})})})}),o.jsx(X,{})]})}),z=T.externalizeComponent(({rapidlyChangingMotionState:e,...n})=>{const t=L.useSmoothedMotionState(e);return o.jsx(I,{rapidlyChangingMotionState:t,...n})});function Ae({connectedMotionGroup:e,getModel:n,flangeRef:t,transparentColor:r,postModelRender:i,...c}){const l=m.useCallback(y=>E(y,e.nova),[e]),s=n??l;if(!e.dhParameters)return null;const a=e.mountingPosition,f=e.mountingQuaternion,p=e.modelFromController||"";return p?o.jsx(z,{rapidlyChangingMotionState:e.rapidlyChangingMotionState,modelFromController:p,dhParameters:e.dhParameters,getModel:s,flangeRef:t,transparentColor:r,postModelRender:i,chainOffsetPosition:a,chainOffsetQuaternion:f,...c}):o.jsx(B,{rapidlyChangingMotionState:e.rapidlyChangingMotionState,dhParameters:e.dhParameters,chainOffsetPosition:a,chainOffsetQuaternion:f,...c})}const ee=m.forwardRef(function({rapidlyChangingMotionState:n,dhParameters:t,chainOffsetPosition:r,chainOffsetQuaternion:i,onRotationChanged:c,children:l},s){const a=m.useRef(null),f=m.useRef([]),p=m.useRef(n.joint_position.filter(x=>x!==void 0)),{invalidate:u}=$.useThree(),y=m.useRef(n);y.current=n;function j(x){a.current=x,x&&d()}function d(){a.current&&(f.current=Q(a.current),h(),u())}m.useImperativeHandle(s,()=>({recollectJoints:d}));function h(){const x=p.current;if(c)c(f.current,x);else for(const[g,M]of f.current.entries()){const _=t[g],v=_.theta||0,oe=_.reverse_rotation_direction?-1:1;M.rotation.y=oe*(x[g]||0)+v}}function b(x){p.current=x.joint_position.filter(g=>g!==void 0),h(),u()}return L.useAutorun(()=>{b(y.current)}),m.useEffect(()=>{b(n)},[n]),o.jsx("group",{ref:j,position:r,quaternion:i,children:l})}),Pe="line",ke="mesh";function Ve({rapidlyChangingMotionState:e,dhParameters:n,...t}){const r=new w.Matrix4,i=m.useRef([]),c=m.useRef([]);m.useEffect(()=>{i.current=new Array(n.length).fill(null),c.current=new Array(n.length).fill(null)},[n.length]);function l(f,p){const u=new w.Vector3,y=new w.Quaternion,j=new w.Vector3;r.decompose(u,y,j);const d=u.clone(),h=new w.Matrix4().makeRotationY(f.theta+p*(f.reverse_rotation_direction?-1:1)).multiply(new w.Matrix4().makeTranslation(0,f.d/1e3,0)).multiply(new w.Matrix4().makeTranslation(f.a/1e3,0,0)).multiply(new w.Matrix4().makeRotationX(f.alpha));return r.multiply(h),r.decompose(u,y,j),{a:d,b:u}}function s(f,p,u,y){if(!n)return;const j=n[f];if(!j)return;const{a:d,b:h}=l(j,y);p.geometry.setPositions([d.toArray(),h.toArray()].flat()),u.position.set(h.x,h.y,h.z)}function a(f,p){r.identity();for(let u=0;u<Math.min(f.length,p.length);u++){const y=i.current[u],j=c.current[u];y&&j&&s(u,y,j,p[u])}}return o.jsx(ee,{rapidlyChangingMotionState:e,dhParameters:n,onRotationChanged:a,children:o.jsxs("group",{...t,name:"Scene",children:[o.jsxs("mesh",{children:[o.jsx("sphereGeometry",{args:[.01,32,32]}),o.jsx("meshStandardMaterial",{color:"black",depthTest:!0})]}),n==null?void 0:n.map((f,p)=>{const{a:u,b:y}=l(f,e.joint_position[p]??0),j=`dhrobot_J0${p}`;return o.jsxs("group",{name:j,children:[o.jsx(S.Line,{ref:d=>{i.current[p]=d},name:Pe,points:[u,y],color:"white",lineWidth:5}),o.jsxs("mesh",{ref:d=>{c.current[p]=d},name:ke,position:y,children:[o.jsx("sphereGeometry",{args:[.01,32,32]}),o.jsx("meshStandardMaterial",{color:"black",depthTest:!0})]},`mesh_${p}`)]},j)})]})})}const F=T.externalizeComponent(({rapidlyChangingMotionState:e,modelFromController:n,dhParameters:t,chainOffsetPosition:r,chainOffsetQuaternion:i,getModel:c=E,flangeRef:l,postModelRender:s,transparentColor:a,instanceUrl:f,...p})=>{const[u,y]=m.useState(null),j=m.useRef(null),d=m.useCallback(g=>{y(g)},[]),h=m.useCallback(()=>{var g;(g=j.current)==null||g.recollectJoints(),s==null||s()},[s]);m.useEffect(()=>{u&&(a?Z(u,a):K(u))},[u,a]);const b=m.useMemo(()=>{const g=c(n,f);if(!g)throw new Error(`No model found for robot "${n}". Ensure the model is available or provide a custom getModel function.`);return g},[n,f,c]),x=o.jsx(Ve,{rapidlyChangingMotionState:e,dhParameters:t,...p});return o.jsxs(D.ErrorBoundary,{fallback:x,onError:g=>{console.warn(g)},children:[o.jsx(m.Suspense,{fallback:x,children:o.jsx("group",{ref:d,children:o.jsx(ee,{ref:j,rapidlyChangingMotionState:e,dhParameters:t,chainOffsetPosition:r,chainOffsetQuaternion:i,children:o.jsx(Y,{modelURL:b,postModelRender:h,flangeRef:l,...p})})})}),o.jsx(X,{})]})}),te=T.externalizeComponent(({rapidlyChangingMotionState:e,...n})=>{const t=L.useSmoothedMotionState(e);return o.jsx(F,{rapidlyChangingMotionState:t,...n})}),ne=T.externalizeComponent(e=>{const{inverseSolver:n,dhParameters:t,...r}=e,[i,c]=m.useState(O.JointTypeEnum.RevoluteJoint);m.useEffect(()=>{t.length&&c(t[0].type??O.JointTypeEnum.RevoluteJoint)},[t]);const l=m.useMemo(()=>n===null&&i===O.JointTypeEnum.RevoluteJoint,[n,i]),s=m.useMemo(()=>n===null&&i===O.JointTypeEnum.PrismaticJoint,[n,i]);return m.useMemo(()=>!!n,[n])||l?o.jsx(F,{dhParameters:t,...r}):s?o.jsx(I,{dhParameters:t,...r}):null}),Ce=T.externalizeComponent(e=>{const n=L.useSmoothedMotionState(e.rapidlyChangingMotionState);return o.jsx(ne,{...e,rapidlyChangingMotionState:n})});function Ie({connectedMotionGroup:e,getModel:n,flangeRef:t,transparentColor:r,postModelRender:i,...c}){const l=m.useCallback(f=>E(f,e.nova),[e]);if(!e.dhParameters)return null;const s=e.mountingPosition,a=e.mountingQuaternion;return o.jsx(te,{rapidlyChangingMotionState:e.rapidlyChangingMotionState,modelFromController:e.modelFromController||"",dhParameters:e.dhParameters,getModel:n??l,flangeRef:t,transparentColor:r,postModelRender:i,chainOffsetPosition:s,chainOffsetQuaternion:a,...c})}exports.CollisionSceneRenderer=ce;exports.JointLimitGizmo=Re;exports.LinearAxis=Ae;exports.MotionGroupVisualizer=Ce;exports.MotionGroupVisualizerExact=ne;exports.PresetEnvironment=be;exports.Robot=Ie;exports.SafetyZonesRenderer=_e;exports.SupportedLinearAxis=z;exports.SupportedLinearAxisExact=I;exports.SupportedRobot=te;exports.SupportedRobotExact=F;exports.TrajectoryRenderer=ve;exports.defaultGetModel=E;