@arkitektio/bsx 2.3.0 → 4.0.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.
- package/dist/bsx/language.d.ts.map +1 -1
- package/dist/bsx/language.js +4 -3
- package/dist/bsx/language.js.map +1 -1
- package/dist/bsx/references.d.ts +4 -2
- package/dist/bsx/references.d.ts.map +1 -1
- package/dist/bsx/references.js +34 -6
- package/dist/bsx/references.js.map +1 -1
- package/dist/catalogs/index.d.ts +27 -14
- package/dist/catalogs/index.d.ts.map +1 -1
- package/dist/catalogs/parts/index.d.ts +16 -3
- package/dist/catalogs/parts/index.d.ts.map +1 -1
- package/dist/catalogs/parts/run.d.ts +44 -4
- package/dist/catalogs/parts/run.d.ts.map +1 -1
- package/dist/catalogs/parts/run.js +33 -19
- package/dist/catalogs/parts/run.js.map +1 -1
- package/dist/catalogs/parts/scene.js +7 -7
- package/dist/catalogs/parts/scene.js.map +1 -1
- package/dist/catalogs/scene.d.ts +27 -14
- package/dist/catalogs/scene.d.ts.map +1 -1
- package/dist/catalogs/scene.js +3 -3
- package/dist/catalogs/scene.js.map +1 -1
- package/dist/ports.d.ts +0 -1
- package/dist/ports.d.ts.map +1 -1
- package/dist/ports.js +1 -2
- package/dist/ports.js.map +1 -1
- package/dist/renderer/bloks/run/components.d.ts +15 -2
- package/dist/renderer/bloks/run/components.d.ts.map +1 -1
- package/dist/renderer/bloks/run/components.js +114 -43
- package/dist/renderer/bloks/run/components.js.map +1 -1
- package/dist/renderer/bloks/run/host.d.ts +27 -8
- package/dist/renderer/bloks/run/host.d.ts.map +1 -1
- package/dist/renderer/bloks/run/host.js +8 -4
- package/dist/renderer/bloks/run/host.js.map +1 -1
- package/dist/renderer/bloks/run/index.d.ts +1 -1
- package/dist/renderer/bloks/run/index.d.ts.map +1 -1
- package/dist/renderer/bloks/run/index.js +1 -1
- package/dist/renderer/bloks/run/index.js.map +1 -1
- package/dist/renderer/bloks/run/math.d.ts +3 -20
- package/dist/renderer/bloks/run/math.d.ts.map +1 -1
- package/dist/renderer/bloks/run/math.js +4 -15
- package/dist/renderer/bloks/run/math.js.map +1 -1
- package/dist/renderer/bloks/scene/Scene.d.ts +16 -2
- package/dist/renderer/bloks/scene/Scene.d.ts.map +1 -1
- package/dist/renderer/bloks/scene/Scene.js +11 -3
- package/dist/renderer/bloks/scene/Scene.js.map +1 -1
- package/dist/scene.js +2 -2
- package/dist/scene.js.map +1 -1
- package/dist/spec/bsx_v2.json +277 -62
- package/dist/spec/catalogs/scene@1.json +93 -41
- package/dist/spec/catalogs/scene@1.json.js +93 -41
- package/dist/spec/catalogs.js +1 -1
- package/dist/spec/catalogs.js.map +1 -1
- package/dist/spec/vocabulary.d.ts +1 -1
- package/dist/spec/vocabulary.d.ts.map +1 -1
- package/dist/spec/vocabulary.js +1 -1
- package/dist/spec/vocabulary.js.map +1 -1
- package/dist/spec/vocabulary.json +4 -4
- package/dist/spec/vocabulary.json.js +4 -4
- package/package.json +1 -6
- package/src/bsx/language.test.ts +1 -0
- package/src/bsx/language.ts +4 -3
- package/src/bsx/references.ts +42 -7
- package/src/catalogs/parts/run.ts +39 -19
- package/src/catalogs/parts/scene.ts +7 -7
- package/src/catalogs/scene.ts +3 -3
- package/src/ports.ts +1 -2
- package/src/renderer/bloks/run/components.tsx +227 -103
- package/src/renderer/bloks/run/host.tsx +38 -12
- package/src/renderer/bloks/run/index.ts +1 -1
- package/src/renderer/bloks/run/math.test.ts +1 -24
- package/src/renderer/bloks/run/math.ts +5 -33
- package/src/renderer/bloks/run/run.test.tsx +44 -38
- package/src/renderer/bloks/scene/Scene.tsx +22 -4
- package/src/scene.ts +2 -2
- package/src/spec/bsx_v2.json +277 -62
- package/src/spec/catalogs/scene@1.json +93 -41
- package/src/spec/catalogs.ts +1 -1
- package/src/spec/vocabulary.json +4 -4
- package/src/spec/vocabulary.ts +2 -2
- package/dist/ports/engine/ActionDescription.d.ts +0 -27
- package/dist/ports/engine/ActionDescription.d.ts.map +0 -1
- package/dist/ports/engine/ActionDescription.js +0 -61
- package/dist/ports/engine/ActionDescription.js.map +0 -1
- package/src/ports/engine/ActionDescription.tsx +0 -78
|
@@ -27,14 +27,17 @@ const arm: BlokRunAgent = {id: 'a1', name: 'Arm'};
|
|
|
27
27
|
const scope: BlokRunAgent = {id: 'a3', name: 'Scope'};
|
|
28
28
|
const binding: Record<string, BlokRunAgent[]> = {robot: [arm], frame: [scope]};
|
|
29
29
|
const run: BlokRunHost = {agentsFor: key => binding[key] ?? [], renderAsk: () => null};
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
30
|
+
|
|
31
|
+
/** Where the room keeps the arm: someone moved it to 5 m along x; nobody moved it unless `armKept`. */
|
|
32
|
+
const KEPT_ARM = fromMatrix4(new THREE.Matrix4().setPosition(5, 0, 0));
|
|
33
|
+
|
|
34
|
+
/** The rooms the host keeps, and what it was asked to draw. */
|
|
35
|
+
const spaceOf = (armKept: boolean, drawn: Array<[string, string | null]>): BlokSpaceHost => ({
|
|
36
|
+
useRoom: () => ({poseOf: id => (armKept && id === 'a1' ? KEPT_ARM : null)}),
|
|
37
|
+
renderAgent: (agentId, blok) => {
|
|
38
|
+
drawn.push([agentId, blok]);
|
|
39
|
+
return <group name={`agent-scene:${agentId}`} />;
|
|
40
|
+
},
|
|
38
41
|
});
|
|
39
42
|
|
|
40
43
|
/** The arm's model, as its own scene blok would have loaded it: one mesh. */
|
|
@@ -56,15 +59,17 @@ const armModel = (): ModelContextValue => {
|
|
|
56
59
|
|
|
57
60
|
const prop = (key: string, value: unknown) => ({key, static_value: value});
|
|
58
61
|
|
|
59
|
-
|
|
62
|
+
/** The arm declared 1 m along x and 2 m along z; the scope 3 m along x, drawn with a named scene blok. */
|
|
63
|
+
const room = [
|
|
60
64
|
{
|
|
61
65
|
id: 'root',
|
|
62
|
-
component: '
|
|
66
|
+
component: 'Space',
|
|
67
|
+
props: [prop('room', 'room:test-lab')],
|
|
63
68
|
children: [
|
|
64
69
|
{
|
|
65
70
|
id: 'robot',
|
|
66
|
-
component: '
|
|
67
|
-
props: [prop('dep', 'robot')],
|
|
71
|
+
component: 'Placed',
|
|
72
|
+
props: [prop('dep', 'robot'), prop('matrix', fromMatrix4(new THREE.Matrix4().setPosition(1, 0, 2)))],
|
|
68
73
|
children: [
|
|
69
74
|
{id: 'glow', component: 'Glow', props: [prop('on', true), prop('color', '#ff0000')]},
|
|
70
75
|
{id: 'card', component: 'Popout', props: [prop('open', true), prop('title', 'Arm card')]},
|
|
@@ -72,48 +77,48 @@ const overlay = [
|
|
|
72
77
|
},
|
|
73
78
|
{
|
|
74
79
|
id: 'frame',
|
|
75
|
-
component: '
|
|
76
|
-
props: [prop('dep', 'frame')],
|
|
77
|
-
children: [{id: 'ask', component: 'Popout', props: [prop('open', true), prop('title', 'Scope card')]}],
|
|
80
|
+
component: 'Placed',
|
|
81
|
+
props: [prop('dep', 'frame'), prop('blok', 'scope-3d'), prop('matrix', fromMatrix4(new THREE.Matrix4().setPosition(3, 0, 0)))],
|
|
78
82
|
},
|
|
83
|
+
{id: 'gone', component: 'Placed', props: [prop('dep', 'opentrons')]},
|
|
79
84
|
{id: 'route', component: 'Route', props: [prop('through', ['robot', 'frame']), {key: 'progress', dynamic_value: {path: 'task.progress'}}]},
|
|
80
85
|
],
|
|
81
86
|
},
|
|
82
87
|
];
|
|
83
88
|
|
|
84
|
-
const mount = async (owned?: ModelContextValue
|
|
89
|
+
const mount = async ({owned, armKept = false}: {owned?: ModelContextValue; armKept?: boolean} = {}) => {
|
|
85
90
|
const store = createSceneStore();
|
|
86
91
|
if (owned) store.getState().setOwnedModel('a1', 'device', owned);
|
|
92
|
+
const drawn: Array<[string, string | null]> = [];
|
|
87
93
|
const root = createRoot(document.createElement('canvas'));
|
|
88
94
|
await root.configure({gl: renderer, frameloop: 'never', size: {width: 100, height: 100, top: 0, left: 0}});
|
|
89
95
|
let state!: ReturnType<typeof root.render>;
|
|
90
96
|
await act(async () => {
|
|
91
97
|
state = root.render(
|
|
92
98
|
<BlokRunHostProvider value={run}>
|
|
93
|
-
<BlokSpaceHostProvider value={spaceOf(
|
|
99
|
+
<BlokSpaceHostProvider value={spaceOf(armKept, drawn)}>
|
|
94
100
|
<SceneStoreProvider value={store}>
|
|
95
101
|
<BlokSceneEmbedProvider value>
|
|
96
|
-
<BlokRenderer catalog={testCatalog()} embedded uiComponents={
|
|
102
|
+
<BlokRenderer catalog={testCatalog()} embedded uiComponents={room} initialState={{task: {progress: 50}}} />
|
|
97
103
|
</BlokSceneEmbedProvider>
|
|
98
104
|
</SceneStoreProvider>
|
|
99
105
|
</BlokSpaceHostProvider>
|
|
100
106
|
</BlokRunHostProvider>,
|
|
101
107
|
);
|
|
102
108
|
});
|
|
103
|
-
return {store, scene: state.getState().scene, unmount: () => root.unmount()};
|
|
109
|
+
return {store, drawn, scene: state.getState().scene, unmount: () => root.unmount()};
|
|
104
110
|
};
|
|
105
111
|
|
|
106
112
|
let unmount: (() => void) | undefined;
|
|
107
113
|
afterEach(() => unmount?.());
|
|
108
114
|
|
|
109
|
-
describe('
|
|
110
|
-
it('stands
|
|
115
|
+
describe('a space placing the run\'s dependencies', () => {
|
|
116
|
+
it('stands a Placed where it says while nobody moved it, and a Glow without a node lights the device', async () => {
|
|
111
117
|
const model = armModel();
|
|
112
|
-
const mounted = await mount(model);
|
|
118
|
+
const mounted = await mount({owned: model});
|
|
113
119
|
unmount = mounted.unmount;
|
|
114
120
|
|
|
115
|
-
|
|
116
|
-
expect(anchor?.position.toArray()).toEqual([1, 0, 2]);
|
|
121
|
+
expect(mounted.scene.getObjectByName('placed:robot:a1')?.position.toArray()).toEqual([1, 0, 2]);
|
|
117
122
|
// The glow works on the model the device's scene blok loaded, not on a copy.
|
|
118
123
|
const mesh = model.instance.root.children[0] as THREE.Mesh;
|
|
119
124
|
const lit = mesh.material as THREE.MeshStandardMaterial;
|
|
@@ -121,40 +126,41 @@ describe('an overlay drawn into a space', () => {
|
|
|
121
126
|
expect(lit.emissive.getHexString()).toBe('ff0000');
|
|
122
127
|
});
|
|
123
128
|
|
|
124
|
-
it('
|
|
129
|
+
it('stands a device where the room keeps it, over what its Placed says', async () => {
|
|
130
|
+
const mounted = await mount({armKept: true});
|
|
131
|
+
unmount = mounted.unmount;
|
|
132
|
+
|
|
133
|
+
expect(mounted.scene.getObjectByName('placed:robot:a1')?.position.toArray()).toEqual([5, 0, 0]);
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
it('draws each agent with its own scene blok inside its placement: the default, or the one named', async () => {
|
|
125
137
|
const mounted = await mount();
|
|
126
138
|
unmount = mounted.unmount;
|
|
127
139
|
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
const popouts = overlays.filter(card => card.mode === 'popout').map(card => card.title);
|
|
131
|
-
expect(panels).toEqual(expect.arrayContaining(['Scope', 'Scope card']));
|
|
132
|
-
expect(popouts).toEqual(['Arm card']);
|
|
133
|
-
expect(mounted.scene.getObjectByName('at:a3')).toBeUndefined();
|
|
140
|
+
expect(mounted.drawn).toEqual(expect.arrayContaining([['a1', null], ['a3', 'scope-3d']]));
|
|
141
|
+
expect(mounted.scene.getObjectByName('agent-scene:a3')?.parent?.name).toBe('placed:frame:a3');
|
|
134
142
|
});
|
|
135
143
|
|
|
136
|
-
it('anchors a card at the
|
|
144
|
+
it('anchors a card at the placement while the device has no model in the scene', async () => {
|
|
137
145
|
const mounted = await mount();
|
|
138
146
|
unmount = mounted.unmount;
|
|
139
147
|
|
|
140
148
|
const card = [...mounted.store.getState().overlays.values()].find(overlay => overlay.title === 'Arm card');
|
|
141
|
-
expect(card?.anchor()).toBe(mounted.scene.getObjectByName('
|
|
149
|
+
expect(card?.anchor()).toBe(mounted.scene.getObjectByName('placed:robot:a1'));
|
|
142
150
|
});
|
|
143
151
|
|
|
144
|
-
it('
|
|
152
|
+
it('says so when the run has no agent for a dependency', async () => {
|
|
145
153
|
const mounted = await mount();
|
|
146
154
|
unmount = mounted.unmount;
|
|
147
155
|
|
|
148
|
-
expect(mounted.
|
|
149
|
-
expect([...mounted.store.getState().notices.values()].map(notice => notice.title)).toContain('A route with nowhere to go');
|
|
156
|
+
expect([...mounted.store.getState().notices.values()].map(notice => notice.title)).toContain('Nothing is bound to "opentrons"');
|
|
150
157
|
});
|
|
151
158
|
|
|
152
159
|
it('draws a route through the placed agents, its head where the run is', async () => {
|
|
153
|
-
const mounted = await mount(
|
|
160
|
+
const mounted = await mount();
|
|
154
161
|
unmount = mounted.unmount;
|
|
155
162
|
|
|
156
163
|
const route = mounted.scene.getObjectByName('route');
|
|
157
|
-
expect([...mounted.store.getState().notices.values()]).toEqual([]);
|
|
158
164
|
expect(route).toBeDefined();
|
|
159
165
|
const head = route?.children.find(child => (child as THREE.Mesh).isMesh && (child as THREE.Mesh).geometry.type === 'SphereGeometry');
|
|
160
166
|
// Half way from (1, 0, 2) to (3, 0, 0), over the floor.
|
|
@@ -24,7 +24,7 @@ import {
|
|
|
24
24
|
type BlokRender,
|
|
25
25
|
type BlokRenderArgs,
|
|
26
26
|
} from '../../runtime';
|
|
27
|
-
import type
|
|
27
|
+
import {sceneSchema, type sceneContracts} from '../../../catalogs/parts/scene';
|
|
28
28
|
import {
|
|
29
29
|
createSceneStore,
|
|
30
30
|
SceneStoreProvider,
|
|
@@ -808,8 +808,21 @@ const SceneChildren = ({component, buildChild}: Pick<SceneRenderArgs, 'component
|
|
|
808
808
|
</>
|
|
809
809
|
);
|
|
810
810
|
|
|
811
|
-
|
|
812
|
-
|
|
811
|
+
export type SceneFrameProps = Pick<SceneRenderArgs, 'component' | 'buildChild'> & {
|
|
812
|
+
/** HTML over the canvas (beside the scene's own controls). */
|
|
813
|
+
overlay?: React.ReactNode;
|
|
814
|
+
/** What the scene holds; the component's children when left out. */
|
|
815
|
+
children?: React.ReactNode;
|
|
816
|
+
};
|
|
817
|
+
|
|
818
|
+
/**
|
|
819
|
+
* A scene with a canvas of its own, sized and kept as a `Scene` asks: its
|
|
820
|
+
* camera, grid, height and (with `persist`) the viewer's camera on this device.
|
|
821
|
+
* A `Space` is one too, with its room around what it holds. The props are read
|
|
822
|
+
* through the scene schema, which every such root extends.
|
|
823
|
+
*/
|
|
824
|
+
export const SceneFrame = ({component, buildChild, overlay, children}: SceneFrameProps) => {
|
|
825
|
+
const blok = useBlok(component, sceneSchema);
|
|
813
826
|
const camera = useValue(blok.camera) ?? 'iso';
|
|
814
827
|
const grid = useValue(blok.grid) ?? true;
|
|
815
828
|
const declaredHeight = useValue(blok.height);
|
|
@@ -840,12 +853,17 @@ const StandaloneScene = ({component, schema, buildChild}: SceneRenderArgs) => {
|
|
|
840
853
|
frameRef={frameRef}
|
|
841
854
|
className={fill ? 'relative w-full overflow-hidden' : 'relative w-full overflow-hidden rounded-xl bg-muted/20'}
|
|
842
855
|
style={{height}}
|
|
856
|
+
overlay={overlay}
|
|
843
857
|
>
|
|
844
|
-
<SceneChildren component={component} buildChild={buildChild} />
|
|
858
|
+
{children ?? <SceneChildren component={component} buildChild={buildChild} />}
|
|
845
859
|
</SceneSurface>
|
|
846
860
|
);
|
|
847
861
|
};
|
|
848
862
|
|
|
863
|
+
const StandaloneScene = ({component, buildChild}: SceneRenderArgs) => (
|
|
864
|
+
<SceneFrame component={component} buildChild={buildChild} />
|
|
865
|
+
);
|
|
866
|
+
|
|
849
867
|
export const SceneRender: BlokRender<Contracts['Scene']> = args =>
|
|
850
868
|
// Inside a scene that is already open, this one only adds what it holds:
|
|
851
869
|
// the camera, grid and size are the surrounding scene's.
|
package/src/scene.ts
CHANGED
|
@@ -12,7 +12,6 @@ const renders = {...sceneRenders, ...runRenders};
|
|
|
12
12
|
|
|
13
13
|
/** scene@1, drawn with three. */
|
|
14
14
|
export const threeScene = implementBlokCatalog(sceneCatalog, {
|
|
15
|
-
Anchor: renders.Anchor,
|
|
16
15
|
Animate: renders.Animate,
|
|
17
16
|
Attach: renders.Attach,
|
|
18
17
|
Beam: renders.Beam,
|
|
@@ -20,12 +19,13 @@ export const threeScene = implementBlokCatalog(sceneCatalog, {
|
|
|
20
19
|
Model: renders.Model,
|
|
21
20
|
Move: renders.Move,
|
|
22
21
|
OnClick: renders.OnClick,
|
|
23
|
-
|
|
22
|
+
Placed: renders.Placed,
|
|
24
23
|
Popout: renders.Popout,
|
|
25
24
|
Robot: renders.Robot,
|
|
26
25
|
Rotate: renders.Rotate,
|
|
27
26
|
Route: renders.Route,
|
|
28
27
|
Scene: renders.Scene,
|
|
28
|
+
Space: renders.Space,
|
|
29
29
|
Tint: renders.Tint,
|
|
30
30
|
Transform: renders.Transform,
|
|
31
31
|
Visible: renders.Visible,
|