@viamrobotics/motion-tools 1.13.1 → 1.14.0

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.
@@ -1,5 +1,6 @@
1
- import { LineSegments, Vector3, Object3D } from 'three';
2
- export declare class OBBHelper extends LineSegments {
1
+ import { Vector3, Object3D } from 'three';
2
+ import { LineSegments2 } from 'three/examples/jsm/lines/LineSegments2.js';
3
+ export declare class OBBHelper extends LineSegments2 {
3
4
  constructor(color?: number, linewidth?: number);
4
5
  setFromOBB(obb: {
5
6
  center: Vector3;
@@ -1,4 +1,7 @@
1
- import { LineSegments, LineBasicMaterial, EdgesGeometry, BoxGeometry, Vector3, Quaternion, Matrix4, Object3D, Mesh, BufferGeometry, Matrix3, } from 'three';
1
+ import { EdgesGeometry, BoxGeometry, Vector3, Quaternion, Matrix4, Object3D, Mesh, BufferGeometry, Matrix3, } from 'three';
2
+ import { LineMaterial } from 'three/addons/lines/LineMaterial.js';
3
+ import { LineSegments2 } from 'three/examples/jsm/lines/LineSegments2.js';
4
+ import { LineSegmentsGeometry } from 'three/examples/jsm/lines/LineSegmentsGeometry.js';
2
5
  const center = new Vector3();
3
6
  const half = new Vector3();
4
7
  const size = new Vector3();
@@ -6,13 +9,22 @@ const quaternion = new Quaternion();
6
9
  const scale = new Vector3();
7
10
  const absScale = new Vector3();
8
11
  const worldCenter = new Vector3();
9
- export class OBBHelper extends LineSegments {
10
- constructor(color = 0x000000, linewidth = 1) {
11
- const geometry = new EdgesGeometry(new BoxGeometry());
12
- const material = new LineBasicMaterial({ color, linewidth });
12
+ export class OBBHelper extends LineSegments2 {
13
+ constructor(color = 0x000000, linewidth = 2) {
14
+ const edges = new EdgesGeometry(new BoxGeometry());
15
+ const geometry = new LineSegmentsGeometry();
16
+ geometry.setPositions(edges.getAttribute('position').array);
17
+ const material = new LineMaterial({
18
+ color,
19
+ linewidth,
20
+ depthTest: false,
21
+ depthWrite: false,
22
+ transparent: true,
23
+ });
13
24
  super(geometry, material);
14
25
  this.matrixAutoUpdate = false;
15
26
  this.frustumCulled = false;
27
+ this.renderOrder = 999;
16
28
  }
17
29
  setFromOBB(obb) {
18
30
  // position/rotation
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@viamrobotics/motion-tools",
3
- "version": "1.13.1",
3
+ "version": "1.14.0",
4
4
  "description": "Motion visualization with Viam",
5
5
  "license": "Apache-2.0",
6
6
  "type": "module",
@@ -1,27 +0,0 @@
1
- import type { PlainMessage, Struct } from '@viamrobotics/sdk';
2
- import { BatchedMesh, Color, Vector3 } from 'three';
3
- import type { GLTF } from 'three/examples/jsm/Addons.js';
4
- import type { OBB } from 'three/addons/math/OBB.js';
5
- declare enum SupportedShapes {
6
- points = "points",
7
- line = "line",
8
- arrow = "arrow"
9
- }
10
- type Metadata = {
11
- colors?: Float32Array<ArrayBufferLike>;
12
- color?: Color;
13
- opacity?: number;
14
- gltf?: GLTF;
15
- points?: Vector3[];
16
- pointSize?: number;
17
- lineWidth?: number;
18
- lineDotColor?: Color;
19
- batched?: {
20
- id: number;
21
- object: BatchedMesh;
22
- };
23
- shape?: SupportedShapes;
24
- getBoundingBoxAt?: (box: OBB) => void;
25
- };
26
- export declare const parseMetadata: (fields?: PlainMessage<Struct>["fields"]) => Metadata;
27
- export {};
@@ -1,127 +0,0 @@
1
- import { BatchedMesh, Color, Vector3 } from 'three';
2
- import { isColorRepresentation, isRGB, parseColor, parseOpacity, parseRGB } from './color';
3
- var SupportedShapes;
4
- (function (SupportedShapes) {
5
- SupportedShapes["points"] = "points";
6
- SupportedShapes["line"] = "line";
7
- SupportedShapes["arrow"] = "arrow";
8
- })(SupportedShapes || (SupportedShapes = {}));
9
- const METADATA_KEYS = [
10
- 'colors',
11
- 'color',
12
- 'opacity',
13
- 'gltf',
14
- 'points',
15
- 'pointSize',
16
- 'lineWidth',
17
- 'lineDotColor',
18
- 'batched',
19
- 'shape',
20
- ];
21
- const isMetadataKey = (key) => {
22
- return METADATA_KEYS.includes(key);
23
- };
24
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
25
- const unwrapValue = (value) => {
26
- if (!value?.kind)
27
- return value;
28
- switch (value.kind.case) {
29
- case 'numberValue':
30
- case 'stringValue':
31
- case 'boolValue': {
32
- return value.kind.value;
33
- }
34
- case 'structValue': {
35
- const result = {};
36
- for (const [key, val] of Object.entries(value.kind.value.fields || {})) {
37
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
38
- result[key] = unwrapValue(val);
39
- }
40
- return result;
41
- }
42
- case 'listValue': {
43
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
44
- return value.kind.value.values?.map((value) => unwrapValue(value)) || [];
45
- }
46
- case 'nullValue': {
47
- return null;
48
- }
49
- default: {
50
- return value.kind.value;
51
- }
52
- }
53
- };
54
- export const parseMetadata = (fields = {}) => {
55
- const json = {};
56
- for (const [k, v] of Object.entries(fields)) {
57
- if (!isMetadataKey(k))
58
- continue;
59
- const unwrappedValue = unwrapValue(v);
60
- switch (k) {
61
- case 'color':
62
- case 'lineDotColor': {
63
- json[k] = readColor(unwrappedValue);
64
- break;
65
- }
66
- case 'colors': {
67
- let colorBytes;
68
- // Handle base64-encoded string (from protobuf Struct)
69
- if (typeof unwrappedValue === 'string') {
70
- const binary = atob(unwrappedValue);
71
- colorBytes = new Uint8Array(binary.length);
72
- for (let i = 0; i < binary.length; i++) {
73
- colorBytes[i] = binary.charCodeAt(i);
74
- }
75
- }
76
- else if (Array.isArray(unwrappedValue)) {
77
- colorBytes = unwrappedValue;
78
- }
79
- if (colorBytes && colorBytes.length >= 3) {
80
- const r = (colorBytes[0] ?? 0) / 255;
81
- const g = (colorBytes[1] ?? 0) / 255;
82
- const b = (colorBytes[2] ?? 0) / 255;
83
- const a = colorBytes.length >= 4 ? (colorBytes[3] ?? 255) / 255 : 1;
84
- json.color = new Color(r, g, b);
85
- json.opacity = a;
86
- }
87
- break;
88
- }
89
- case 'opacity': {
90
- json[k] = parseOpacity(unwrappedValue);
91
- break;
92
- }
93
- case 'gltf': {
94
- json[k] = unwrappedValue;
95
- break;
96
- }
97
- case 'points': {
98
- json[k] = unwrappedValue;
99
- break;
100
- }
101
- case 'pointSize': {
102
- json[k] = unwrappedValue;
103
- break;
104
- }
105
- case 'lineWidth': {
106
- json[k] = unwrappedValue;
107
- break;
108
- }
109
- case 'batched': {
110
- json[k] = unwrappedValue;
111
- break;
112
- }
113
- case 'shape': {
114
- json[k] = unwrappedValue;
115
- break;
116
- }
117
- }
118
- }
119
- return json;
120
- };
121
- const readColor = (color) => {
122
- if (isColorRepresentation(color))
123
- return parseColor(color);
124
- if (isRGB(color))
125
- return parseRGB(color);
126
- return new Color('black');
127
- };