@kiberon-labs/behave-graph-scene 1.0.0 → 2.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/.storybook/main.ts +18 -0
- package/.storybook/preview.ts +16 -0
- package/.storybook/vscode.css +822 -0
- package/.turbo/turbo-build.log +8 -0
- package/CHANGELOG.md +84 -0
- package/LICENSE +6 -0
- package/README.md +13 -0
- package/dist/Abstractions/Drivers/DummyScene.d.ts +64 -0
- package/dist/Abstractions/Drivers/DummyScene.d.ts.map +1 -0
- package/dist/Abstractions/Drivers/DummyScene.js +115 -0
- package/dist/Abstractions/Drivers/DummyScene.js.map +1 -0
- package/dist/Abstractions/IScene.d.ts +75 -0
- package/dist/Abstractions/IScene.d.ts.map +1 -0
- package/dist/Abstractions/IScene.js +19 -0
- package/dist/Abstractions/IScene.js.map +1 -0
- package/dist/GLTFJson.d.ts +33 -0
- package/dist/GLTFJson.d.ts.map +1 -0
- package/dist/Nodes/Actions/AddLight.d.ts +21 -0
- package/dist/Nodes/Actions/AddLight.d.ts.map +1 -0
- package/dist/Nodes/Actions/AddLight.js +38 -0
- package/dist/Nodes/Actions/AddLight.js.map +1 -0
- package/dist/Nodes/Actions/CloneMesh.d.ts +16 -0
- package/dist/Nodes/Actions/CloneMesh.d.ts.map +1 -0
- package/dist/Nodes/Actions/CloneMesh.js +28 -0
- package/dist/Nodes/Actions/CloneMesh.js.map +1 -0
- package/dist/Nodes/Actions/CreateMesh.d.ts +22 -0
- package/dist/Nodes/Actions/CreateMesh.d.ts.map +1 -0
- package/dist/Nodes/Actions/CreateMesh.js +44 -0
- package/dist/Nodes/Actions/CreateMesh.js.map +1 -0
- package/dist/Nodes/Actions/DeleteMesh.d.ts +15 -0
- package/dist/Nodes/Actions/DeleteMesh.d.ts.map +1 -0
- package/dist/Nodes/Actions/DeleteMesh.js +27 -0
- package/dist/Nodes/Actions/DeleteMesh.js.map +1 -0
- package/dist/Nodes/Actions/EaseSceneProperty.d.ts +23 -0
- package/dist/Nodes/Actions/EaseSceneProperty.d.ts.map +1 -0
- package/dist/Nodes/Actions/EaseSceneProperty.js +73 -0
- package/dist/Nodes/Actions/EaseSceneProperty.js.map +1 -0
- package/dist/Nodes/Actions/LookAt.d.ts +16 -0
- package/dist/Nodes/Actions/LookAt.d.ts.map +1 -0
- package/dist/Nodes/Actions/LookAt.js +35 -0
- package/dist/Nodes/Actions/LookAt.js.map +1 -0
- package/dist/Nodes/Actions/MoveTowards.d.ts +21 -0
- package/dist/Nodes/Actions/MoveTowards.d.ts.map +1 -0
- package/dist/Nodes/Actions/MoveTowards.js +46 -0
- package/dist/Nodes/Actions/MoveTowards.js.map +1 -0
- package/dist/Nodes/Actions/RemoveLight.d.ts +15 -0
- package/dist/Nodes/Actions/RemoveLight.d.ts.map +1 -0
- package/dist/Nodes/Actions/RemoveLight.js +27 -0
- package/dist/Nodes/Actions/RemoveLight.js.map +1 -0
- package/dist/Nodes/Actions/SetLightProperty.d.ts +25 -0
- package/dist/Nodes/Actions/SetLightProperty.d.ts.map +1 -0
- package/dist/Nodes/Actions/SetLightProperty.js +64 -0
- package/dist/Nodes/Actions/SetLightProperty.js.map +1 -0
- package/dist/Nodes/Actions/SetMaterialProperty.d.ts +25 -0
- package/dist/Nodes/Actions/SetMaterialProperty.d.ts.map +1 -0
- package/dist/Nodes/Actions/SetMaterialProperty.js +69 -0
- package/dist/Nodes/Actions/SetMaterialProperty.js.map +1 -0
- package/dist/Nodes/Actions/SetMeshPosition.d.ts +18 -0
- package/dist/Nodes/Actions/SetMeshPosition.d.ts.map +1 -0
- package/dist/Nodes/Actions/SetMeshPosition.js +34 -0
- package/dist/Nodes/Actions/SetMeshPosition.js.map +1 -0
- package/dist/Nodes/Actions/SetMeshVisible.d.ts +16 -0
- package/dist/Nodes/Actions/SetMeshVisible.d.ts.map +1 -0
- package/dist/Nodes/Actions/SetMeshVisible.js +28 -0
- package/dist/Nodes/Actions/SetMeshVisible.js.map +1 -0
- package/dist/Nodes/Actions/SetSceneProperty.d.ts +16 -0
- package/dist/Nodes/Actions/SetSceneProperty.d.ts.map +1 -0
- package/dist/Nodes/Actions/SetSceneProperty.js +28 -0
- package/dist/Nodes/Actions/SetSceneProperty.js.map +1 -0
- package/dist/Nodes/Events/OnAnyMeshClicked.d.ts +13 -0
- package/dist/Nodes/Events/OnAnyMeshClicked.d.ts.map +1 -0
- package/dist/Nodes/Events/OnAnyMeshClicked.js +34 -0
- package/dist/Nodes/Events/OnAnyMeshClicked.js.map +1 -0
- package/dist/Nodes/Events/OnSceneChanged.d.ts +12 -0
- package/dist/Nodes/Events/OnSceneChanged.d.ts.map +1 -0
- package/dist/Nodes/Events/OnSceneChanged.js +28 -0
- package/dist/Nodes/Events/OnSceneChanged.js.map +1 -0
- package/dist/Nodes/Events/OnSceneNodeClick.d.ts +18 -0
- package/dist/Nodes/Events/OnSceneNodeClick.d.ts.map +1 -0
- package/dist/Nodes/Events/OnSceneNodeClick.js +39 -0
- package/dist/Nodes/Events/OnSceneNodeClick.js.map +1 -0
- package/dist/Nodes/Logic/ColorNodes.d.ts +23 -0
- package/dist/Nodes/Logic/ColorNodes.d.ts.map +1 -0
- package/dist/Nodes/Logic/ColorNodes.js +137 -0
- package/dist/Nodes/Logic/ColorNodes.js.map +1 -0
- package/dist/Nodes/Logic/EulerNodes.d.ts +22 -0
- package/dist/Nodes/Logic/EulerNodes.d.ts.map +1 -0
- package/dist/Nodes/Logic/EulerNodes.js +132 -0
- package/dist/Nodes/Logic/EulerNodes.js.map +1 -0
- package/dist/Nodes/Logic/Mat3Nodes.d.ts +31 -0
- package/dist/Nodes/Logic/Mat3Nodes.d.ts.map +1 -0
- package/dist/Nodes/Logic/Mat3Nodes.js +199 -0
- package/dist/Nodes/Logic/Mat3Nodes.js.map +1 -0
- package/dist/Nodes/Logic/Mat4Nodes.d.ts +38 -0
- package/dist/Nodes/Logic/Mat4Nodes.d.ts.map +1 -0
- package/dist/Nodes/Logic/Mat4Nodes.js +267 -0
- package/dist/Nodes/Logic/Mat4Nodes.js.map +1 -0
- package/dist/Nodes/Logic/QuatNodes.d.ts +28 -0
- package/dist/Nodes/Logic/QuatNodes.d.ts.map +1 -0
- package/dist/Nodes/Logic/QuatNodes.js +173 -0
- package/dist/Nodes/Logic/QuatNodes.js.map +1 -0
- package/dist/Nodes/Logic/Vec2Nodes.d.ts +22 -0
- package/dist/Nodes/Logic/Vec2Nodes.d.ts.map +1 -0
- package/dist/Nodes/Logic/Vec2Nodes.js +115 -0
- package/dist/Nodes/Logic/Vec2Nodes.js.map +1 -0
- package/dist/Nodes/Logic/Vec3Nodes.d.ts +23 -0
- package/dist/Nodes/Logic/Vec3Nodes.d.ts.map +1 -0
- package/dist/Nodes/Logic/Vec3Nodes.js +137 -0
- package/dist/Nodes/Logic/Vec3Nodes.js.map +1 -0
- package/dist/Nodes/Logic/Vec4Nodes.d.ts +22 -0
- package/dist/Nodes/Logic/Vec4Nodes.d.ts.map +1 -0
- package/dist/Nodes/Logic/Vec4Nodes.js +132 -0
- package/dist/Nodes/Logic/Vec4Nodes.js.map +1 -0
- package/dist/Nodes/Logic/VecElements.d.ts +9 -0
- package/dist/Nodes/Logic/VecElements.d.ts.map +1 -0
- package/dist/Nodes/Logic/VecElements.js +22 -0
- package/dist/Nodes/Logic/VecElements.js.map +1 -0
- package/dist/Nodes/Queries/GetDistanceBetween.d.ts +18 -0
- package/dist/Nodes/Queries/GetDistanceBetween.d.ts.map +1 -0
- package/dist/Nodes/Queries/GetDistanceBetween.js +30 -0
- package/dist/Nodes/Queries/GetDistanceBetween.js.map +1 -0
- package/dist/Nodes/Queries/GetLightProperty.d.ts +23 -0
- package/dist/Nodes/Queries/GetLightProperty.d.ts.map +1 -0
- package/dist/Nodes/Queries/GetLightProperty.js +68 -0
- package/dist/Nodes/Queries/GetLightProperty.js.map +1 -0
- package/dist/Nodes/Queries/GetMaterialProperty.d.ts +23 -0
- package/dist/Nodes/Queries/GetMaterialProperty.d.ts.map +1 -0
- package/dist/Nodes/Queries/GetMaterialProperty.js +69 -0
- package/dist/Nodes/Queries/GetMaterialProperty.js.map +1 -0
- package/dist/Nodes/Queries/GetMeshPosition.d.ts +16 -0
- package/dist/Nodes/Queries/GetMeshPosition.d.ts.map +1 -0
- package/dist/Nodes/Queries/GetMeshPosition.js +29 -0
- package/dist/Nodes/Queries/GetMeshPosition.js.map +1 -0
- package/dist/Nodes/Queries/GetSceneProperty.d.ts +14 -0
- package/dist/Nodes/Queries/GetSceneProperty.d.ts.map +1 -0
- package/dist/Nodes/Queries/GetSceneProperty.js +23 -0
- package/dist/Nodes/Queries/GetSceneProperty.js.map +1 -0
- package/dist/Values/ColorValue.d.ts +7 -0
- package/dist/Values/ColorValue.d.ts.map +1 -0
- package/dist/Values/ColorValue.js +20 -0
- package/dist/Values/ColorValue.js.map +1 -0
- package/dist/Values/EulerValue.d.ts +7 -0
- package/dist/Values/EulerValue.d.ts.map +1 -0
- package/dist/Values/EulerValue.js +20 -0
- package/dist/Values/EulerValue.js.map +1 -0
- package/dist/Values/Internal/Mat3.d.ts +43 -0
- package/dist/Values/Internal/Mat3.d.ts.map +1 -0
- package/dist/Values/Internal/Mat3.js +276 -0
- package/dist/Values/Internal/Mat3.js.map +1 -0
- package/dist/Values/Internal/Mat4.d.ts +53 -0
- package/dist/Values/Internal/Mat4.d.ts.map +1 -0
- package/dist/Values/Internal/Mat4.js +443 -0
- package/dist/Values/Internal/Mat4.js.map +1 -0
- package/dist/Values/Internal/Vec2.d.ts +25 -0
- package/dist/Values/Internal/Vec2.d.ts.map +1 -0
- package/dist/Values/Internal/Vec2.js +64 -0
- package/dist/Values/Internal/Vec2.js.map +1 -0
- package/dist/Values/Internal/Vec3.d.ts +38 -0
- package/dist/Values/Internal/Vec3.d.ts.map +1 -0
- package/dist/Values/Internal/Vec3.js +157 -0
- package/dist/Values/Internal/Vec3.js.map +1 -0
- package/dist/Values/Internal/Vec4.d.ts +49 -0
- package/dist/Values/Internal/Vec4.d.ts.map +1 -0
- package/dist/Values/Internal/Vec4.js +190 -0
- package/dist/Values/Internal/Vec4.js.map +1 -0
- package/dist/Values/Mat3Value.d.ts +7 -0
- package/dist/Values/Mat3Value.d.ts.map +1 -0
- package/dist/Values/Mat3Value.js +16 -0
- package/dist/Values/Mat3Value.js.map +1 -0
- package/dist/Values/Mat4Value.d.ts +7 -0
- package/dist/Values/Mat4Value.d.ts.map +1 -0
- package/dist/Values/Mat4Value.js +16 -0
- package/dist/Values/Mat4Value.js.map +1 -0
- package/dist/Values/QuatValue.d.ts +7 -0
- package/dist/Values/QuatValue.d.ts.map +1 -0
- package/dist/Values/QuatValue.js +21 -0
- package/dist/Values/QuatValue.js.map +1 -0
- package/dist/Values/Vec2Value.d.ts +7 -0
- package/dist/Values/Vec2Value.d.ts.map +1 -0
- package/dist/Values/Vec2Value.js +16 -0
- package/dist/Values/Vec2Value.js.map +1 -0
- package/dist/Values/Vec3Value.d.ts +7 -0
- package/dist/Values/Vec3Value.d.ts.map +1 -0
- package/dist/Values/Vec3Value.js +20 -0
- package/dist/Values/Vec3Value.js.map +1 -0
- package/dist/Values/Vec4Value.d.ts +7 -0
- package/dist/Values/Vec4Value.d.ts.map +1 -0
- package/dist/Values/Vec4Value.js +21 -0
- package/dist/Values/Vec4Value.js.map +1 -0
- package/dist/_virtual/rolldown_runtime.js +35 -0
- package/dist/behave-graph.manifest.json +6082 -0
- package/dist/buildScene.d.ts +74 -0
- package/dist/buildScene.d.ts.map +1 -0
- package/dist/buildScene.js +304 -0
- package/dist/buildScene.js.map +1 -0
- package/dist/index.d.ts +57 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +49 -0
- package/dist/manifest.source.d.ts +7 -0
- package/dist/manifest.source.d.ts.map +1 -0
- package/dist/manifest.source.js +54 -0
- package/dist/manifest.source.js.map +1 -0
- package/dist/node_modules/.pnpm/react@19.2.3/node_modules/react/cjs/react-jsx-runtime.development.js +207 -0
- package/dist/node_modules/.pnpm/react@19.2.3/node_modules/react/cjs/react-jsx-runtime.development.js.map +1 -0
- package/dist/node_modules/.pnpm/react@19.2.3/node_modules/react/cjs/react-jsx-runtime.production.js +40 -0
- package/dist/node_modules/.pnpm/react@19.2.3/node_modules/react/cjs/react-jsx-runtime.production.js.map +1 -0
- package/dist/node_modules/.pnpm/react@19.2.3/node_modules/react/cjs/react.development.js +766 -0
- package/dist/node_modules/.pnpm/react@19.2.3/node_modules/react/cjs/react.development.js.map +1 -0
- package/dist/node_modules/.pnpm/react@19.2.3/node_modules/react/cjs/react.production.js +367 -0
- package/dist/node_modules/.pnpm/react@19.2.3/node_modules/react/cjs/react.production.js.map +1 -0
- package/dist/node_modules/.pnpm/react@19.2.3/node_modules/react/index.js +15 -0
- package/dist/node_modules/.pnpm/react@19.2.3/node_modules/react/index.js.map +1 -0
- package/dist/node_modules/.pnpm/react@19.2.3/node_modules/react/jsx-runtime.js +15 -0
- package/dist/node_modules/.pnpm/react@19.2.3/node_modules/react/jsx-runtime.js.map +1 -0
- package/dist/packages/nodes/scene/package.js +7 -0
- package/dist/packages/nodes/scene/package.js.map +1 -0
- package/dist/registerSceneProfile.d.ts +10 -0
- package/dist/registerSceneProfile.d.ts.map +1 -0
- package/dist/registerSceneProfile.js +112 -0
- package/dist/registerSceneProfile.js.map +1 -0
- package/dist/ui/controls/vec3.d.ts +9 -0
- package/dist/ui/controls/vec3.d.ts.map +1 -0
- package/dist/ui/controls/vec3.js +99 -0
- package/dist/ui/controls/vec3.js.map +1 -0
- package/package.json +42 -13
- package/src/Abstractions/Drivers/DummyScene.ts +110 -2
- package/src/Abstractions/IScene.ts +74 -3
- package/src/Nodes/Actions/AddLight.ts +46 -0
- package/src/Nodes/Actions/CloneMesh.ts +31 -0
- package/src/Nodes/Actions/CreateMesh.ts +47 -0
- package/src/Nodes/Actions/DeleteMesh.ts +29 -0
- package/src/Nodes/Actions/EaseSceneProperty.ts +6 -2
- package/src/Nodes/Actions/LookAt.ts +34 -0
- package/src/Nodes/Actions/MoveTowards.ts +55 -0
- package/src/Nodes/Actions/RemoveLight.ts +29 -0
- package/src/Nodes/Actions/SetLightProperty.ts +60 -0
- package/src/Nodes/Actions/SetMaterialProperty.ts +62 -0
- package/src/Nodes/Actions/SetMeshPosition.ts +37 -0
- package/src/Nodes/Actions/SetMeshVisible.ts +31 -0
- package/src/Nodes/Actions/SetSceneProperty.ts +3 -5
- package/src/Nodes/Events/OnAnyMeshClicked.ts +48 -0
- package/src/Nodes/Events/OnSceneChanged.ts +43 -0
- package/src/Nodes/Events/OnSceneNodeClick.ts +3 -3
- package/src/Nodes/Logic/Mat3Nodes.ts +0 -10
- package/src/Nodes/Logic/QuatNodes.ts +11 -11
- package/src/Nodes/Queries/GetDistanceBetween.ts +37 -0
- package/src/Nodes/Queries/GetLightProperty.ts +53 -0
- package/src/Nodes/Queries/GetMaterialProperty.ts +55 -0
- package/src/Nodes/Queries/GetMeshPosition.ts +32 -0
- package/src/Nodes/Queries/GetSceneProperty.ts +4 -5
- package/src/Values/Internal/Mat3.ts +3 -3
- package/src/Values/Internal/Mat4.ts +5 -4
- package/src/Values/Internal/Vec3.ts +5 -4
- package/src/Values/Internal/Vec4.ts +3 -2
- package/src/buildScene.ts +36 -2
- package/src/index.ts +26 -2
- package/src/manifest.source.ts +61 -0
- package/src/registerSceneProfile.ts +41 -4
- package/src/ui/controls/vec3.tsx +69 -0
- package/stories/click.stories.tsx +112 -0
- package/stories/components/DemoScene.ts +610 -0
- package/stories/components/SceneViewer.tsx +204 -0
- package/stories/components/SceneViewerPanel.tsx +41 -0
- package/stories/data/clickDemo.json +94 -0
- package/stories/data/rotate.json +402 -0
- package/stories/index.stories.tsx +90 -0
- package/stories/plugin/sceneViewerPlugin.tsx +88 -0
- package/tests/graphs/logic/Color.json +53 -53
- package/tests/graphs/logic/Euler.json +53 -53
- package/tests/graphs/logic/Quaternion.json +56 -56
- package/tests/graphs/logic/Vector2.json +50 -50
- package/tests/graphs/logic/Vector3.json +53 -53
- package/tests/graphs/logic/Vector4.json +56 -56
- package/tests/manifest.test.ts +65 -0
- package/tests/readSceneGraphs.test.ts +8 -1
- package/tests/registerSceneProfile.test.ts +6 -5
- package/tests/tsconfig.json +10 -10
- package/tsconfig.json +61 -54
- package/tsdown.config.ts +5 -1
- package/vite.config.js +7 -0
- package/src/Values/Internal/Mat2.ts +0 -214
- package/src/loadScene.ts +0 -81
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import {
|
|
2
|
+
makeFunctionNodeDefinition,
|
|
3
|
+
NodeCategory
|
|
4
|
+
} from '@kiberon-labs/behave-graph';
|
|
5
|
+
|
|
6
|
+
const lightPropertyChoices = [
|
|
7
|
+
{ text: 'color', value: 'color' },
|
|
8
|
+
{ text: 'intensity', value: 'intensity' },
|
|
9
|
+
{ text: 'position', value: 'position' }
|
|
10
|
+
];
|
|
11
|
+
|
|
12
|
+
export const GetLightProperty = makeFunctionNodeDefinition({
|
|
13
|
+
typeName: 'scene/getLightProperty',
|
|
14
|
+
category: NodeCategory.Query,
|
|
15
|
+
label: 'Get Light Property',
|
|
16
|
+
in: {
|
|
17
|
+
name: (_, graphApi) => {
|
|
18
|
+
const scene = graphApi.getDependency('IScene');
|
|
19
|
+
return {
|
|
20
|
+
valueType: 'string',
|
|
21
|
+
choices: scene?.getLightNames()
|
|
22
|
+
};
|
|
23
|
+
},
|
|
24
|
+
property: (_) => ({
|
|
25
|
+
valueType: 'string',
|
|
26
|
+
choices: lightPropertyChoices
|
|
27
|
+
})
|
|
28
|
+
},
|
|
29
|
+
out: {
|
|
30
|
+
floatValue: 'float',
|
|
31
|
+
colorValue: 'color',
|
|
32
|
+
vec3Value: 'vec3'
|
|
33
|
+
},
|
|
34
|
+
exec: ({ graph, read, write }) => {
|
|
35
|
+
const scene = graph.getDependency('IScene');
|
|
36
|
+
const name = read<string>('name');
|
|
37
|
+
const property = read<string>('property');
|
|
38
|
+
|
|
39
|
+
const value = scene?.getLightProperty(name, property);
|
|
40
|
+
|
|
41
|
+
switch (property) {
|
|
42
|
+
case 'intensity':
|
|
43
|
+
write('floatValue', value ?? 0);
|
|
44
|
+
break;
|
|
45
|
+
case 'color':
|
|
46
|
+
write('colorValue', value ?? { r: 0, g: 0, b: 0 });
|
|
47
|
+
break;
|
|
48
|
+
case 'position':
|
|
49
|
+
write('vec3Value', value ?? { x: 0, y: 0, z: 0 });
|
|
50
|
+
break;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
});
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import {
|
|
2
|
+
makeFunctionNodeDefinition,
|
|
3
|
+
NodeCategory
|
|
4
|
+
} from '@kiberon-labs/behave-graph';
|
|
5
|
+
|
|
6
|
+
const materialPropertyChoices = [
|
|
7
|
+
{ text: 'color', value: 'color' },
|
|
8
|
+
{ text: 'opacity', value: 'opacity' },
|
|
9
|
+
{ text: 'visible', value: 'visible' },
|
|
10
|
+
{ text: 'wireframe', value: 'wireframe' }
|
|
11
|
+
];
|
|
12
|
+
|
|
13
|
+
export const GetMaterialProperty = makeFunctionNodeDefinition({
|
|
14
|
+
typeName: 'scene/getMaterialProperty',
|
|
15
|
+
category: NodeCategory.Query,
|
|
16
|
+
label: 'Get Material Property',
|
|
17
|
+
in: {
|
|
18
|
+
meshName: (_, graphApi) => {
|
|
19
|
+
const scene = graphApi.getDependency('IScene');
|
|
20
|
+
return {
|
|
21
|
+
valueType: 'string',
|
|
22
|
+
choices: scene?.getMeshNames()
|
|
23
|
+
};
|
|
24
|
+
},
|
|
25
|
+
property: (_) => ({
|
|
26
|
+
valueType: 'string',
|
|
27
|
+
choices: materialPropertyChoices
|
|
28
|
+
})
|
|
29
|
+
},
|
|
30
|
+
out: {
|
|
31
|
+
floatValue: 'float',
|
|
32
|
+
booleanValue: 'boolean',
|
|
33
|
+
colorValue: 'color'
|
|
34
|
+
},
|
|
35
|
+
exec: ({ graph, read, write }) => {
|
|
36
|
+
const scene = graph.getDependency('IScene');
|
|
37
|
+
const meshName = read<string>('meshName');
|
|
38
|
+
const property = read<string>('property');
|
|
39
|
+
|
|
40
|
+
const value = scene?.getMaterialProperty(meshName, property);
|
|
41
|
+
|
|
42
|
+
switch (property) {
|
|
43
|
+
case 'color':
|
|
44
|
+
write('colorValue', value ?? { r: 0, g: 0, b: 0 });
|
|
45
|
+
break;
|
|
46
|
+
case 'opacity':
|
|
47
|
+
write('floatValue', (value as number) ?? 1);
|
|
48
|
+
break;
|
|
49
|
+
case 'visible':
|
|
50
|
+
case 'wireframe':
|
|
51
|
+
write('booleanValue', (value as boolean) ?? false);
|
|
52
|
+
break;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
});
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import {
|
|
2
|
+
makeFunctionNodeDefinition,
|
|
3
|
+
NodeCategory
|
|
4
|
+
} from '@kiberon-labs/behave-graph';
|
|
5
|
+
|
|
6
|
+
// Get the world-space position of a mesh.
|
|
7
|
+
export const GetMeshPosition = makeFunctionNodeDefinition({
|
|
8
|
+
typeName: 'scene/getMeshPosition',
|
|
9
|
+
category: NodeCategory.Query,
|
|
10
|
+
label: 'Get Mesh Position',
|
|
11
|
+
in: {
|
|
12
|
+
meshName: (_, graphApi) => {
|
|
13
|
+
const scene = graphApi.getDependency('IScene');
|
|
14
|
+
return {
|
|
15
|
+
valueType: 'string',
|
|
16
|
+
choices: scene?.getMeshNames()
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
},
|
|
20
|
+
out: {
|
|
21
|
+
x: 'float',
|
|
22
|
+
y: 'float',
|
|
23
|
+
z: 'float'
|
|
24
|
+
},
|
|
25
|
+
exec: ({ graph, read, write }) => {
|
|
26
|
+
const scene = graph.getDependency('IScene');
|
|
27
|
+
const pos = scene?.getMeshPosition(read<string>('meshName'));
|
|
28
|
+
write('x', pos?.x ?? 0);
|
|
29
|
+
write('y', pos?.y ?? 0);
|
|
30
|
+
write('z', pos?.z ?? 0);
|
|
31
|
+
}
|
|
32
|
+
});
|
|
@@ -2,21 +2,20 @@ import {
|
|
|
2
2
|
makeFunctionNodeDefinition,
|
|
3
3
|
NodeCategory
|
|
4
4
|
} from '@kiberon-labs/behave-graph';
|
|
5
|
-
import type { IScene } from '../../Abstractions/IScene.js';
|
|
6
5
|
|
|
7
6
|
export const GetSceneProperty = (valueTypeNames: string[]) =>
|
|
8
7
|
valueTypeNames.map((valueTypeName) =>
|
|
9
8
|
makeFunctionNodeDefinition({
|
|
10
9
|
typeName: `scene/get/${valueTypeName}`,
|
|
11
10
|
category: NodeCategory.Query,
|
|
12
|
-
label: `Scene
|
|
11
|
+
label: `Scene get ${valueTypeName}`,
|
|
13
12
|
in: {
|
|
14
13
|
jsonPath: (_, graphApi) => {
|
|
15
|
-
const scene = graphApi.getDependency
|
|
14
|
+
const scene = graphApi.getDependency('IScene');
|
|
16
15
|
|
|
17
16
|
return {
|
|
18
17
|
valueType: 'string',
|
|
19
|
-
choices: scene?.getProperties()
|
|
18
|
+
choices: scene?.getProperties(valueTypeName)
|
|
20
19
|
};
|
|
21
20
|
}
|
|
22
21
|
},
|
|
@@ -24,7 +23,7 @@ export const GetSceneProperty = (valueTypeNames: string[]) =>
|
|
|
24
23
|
value: valueTypeName
|
|
25
24
|
},
|
|
26
25
|
exec: ({ graph, read, write }) => {
|
|
27
|
-
const scene = graph.getDependency
|
|
26
|
+
const scene = graph.getDependency('IScene');
|
|
28
27
|
const propertyValue = scene?.getProperty(
|
|
29
28
|
read('jsonPath'),
|
|
30
29
|
valueTypeName
|
|
@@ -5,10 +5,10 @@ import {
|
|
|
5
5
|
toSafeString
|
|
6
6
|
} from '@kiberon-labs/behave-graph';
|
|
7
7
|
|
|
8
|
-
import { Mat4 } from './Mat4.js';
|
|
8
|
+
import type { Mat4 } from './Mat4.js';
|
|
9
9
|
import { Vec2 } from './Vec2.js';
|
|
10
10
|
import { Vec3 } from './Vec3.js';
|
|
11
|
-
import { Vec4 } from './Vec4.js';
|
|
11
|
+
import type { Vec4 } from './Vec4.js';
|
|
12
12
|
|
|
13
13
|
// uses OpenGL matrix layout where each column is specified subsequently in order from left to right.
|
|
14
14
|
// ( x, y, 1 ) x [ 0 3 6 ] = ( x', y', 1 )
|
|
@@ -80,7 +80,7 @@ export function mat3SetRow3(
|
|
|
80
80
|
result = new Mat3()
|
|
81
81
|
): Mat3 {
|
|
82
82
|
const re = result.set(m.elements).elements;
|
|
83
|
-
re[rowIndex
|
|
83
|
+
re[rowIndex] = row.x;
|
|
84
84
|
re[rowIndex + NUM_COLUMNS * 1] = row.y;
|
|
85
85
|
re[rowIndex + NUM_COLUMNS * 2] = row.z;
|
|
86
86
|
return result;
|
|
@@ -5,8 +5,9 @@ import {
|
|
|
5
5
|
toSafeString
|
|
6
6
|
} from '@kiberon-labs/behave-graph';
|
|
7
7
|
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
8
|
+
import type { Mat3 } from './Mat3.js';
|
|
9
|
+
import { eulerToMat3, quatToMat3 } from './Mat3.js';
|
|
10
|
+
import type { Vec2 } from './Vec2.js';
|
|
10
11
|
import {
|
|
11
12
|
Vec3,
|
|
12
13
|
vec3Cross,
|
|
@@ -15,7 +16,7 @@ import {
|
|
|
15
16
|
vec3Normalize,
|
|
16
17
|
vec3Subtract
|
|
17
18
|
} from './Vec3.js';
|
|
18
|
-
import { Vec4 } from './Vec4.js';
|
|
19
|
+
import type { Vec4 } from './Vec4.js';
|
|
19
20
|
|
|
20
21
|
// uses OpenGL matrix layout where each column is specified subsequently in order from left to right.
|
|
21
22
|
// ( x, y, z, 1 ) x [ 0 4 8 12] = ( x', y', z', 1 )
|
|
@@ -99,7 +100,7 @@ export function mat4SetRow4(
|
|
|
99
100
|
): Mat4 {
|
|
100
101
|
const re = result.set(m.elements).elements;
|
|
101
102
|
const base = Number(rowIndex);
|
|
102
|
-
re[base
|
|
103
|
+
re[base] = row.x;
|
|
103
104
|
re[base + NUM_COLUMNS * 1] = row.y;
|
|
104
105
|
re[base + NUM_COLUMNS * 2] = row.z;
|
|
105
106
|
re[base + NUM_COLUMNS * 3] = row.w;
|
|
@@ -6,11 +6,12 @@ import {
|
|
|
6
6
|
toSafeString
|
|
7
7
|
} from '@kiberon-labs/behave-graph';
|
|
8
8
|
|
|
9
|
-
import { Mat3
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
9
|
+
import type { Mat3 } from './Mat3.js';
|
|
10
|
+
import { mat4ToMat3, quatToMat3 } from './Mat3.js';
|
|
11
|
+
import type { Mat4 } from './Mat4.js';
|
|
12
|
+
import type { Vec4 } from './Vec4.js';
|
|
12
13
|
|
|
13
|
-
export type Vec3JSON = number
|
|
14
|
+
export type Vec3JSON = [number, number, number];
|
|
14
15
|
|
|
15
16
|
export class Vec3 {
|
|
16
17
|
public x: number;
|
|
@@ -5,8 +5,9 @@ import {
|
|
|
5
5
|
toSafeString
|
|
6
6
|
} from '@kiberon-labs/behave-graph';
|
|
7
7
|
|
|
8
|
-
import { Mat3
|
|
9
|
-
import {
|
|
8
|
+
import type { Mat3 } from './Mat3.js';
|
|
9
|
+
import { mat4ToMat3 } from './Mat3.js';
|
|
10
|
+
import type { Mat4 } from './Mat4.js';
|
|
10
11
|
import { Vec3 } from './Vec3.js';
|
|
11
12
|
|
|
12
13
|
export type Vec4JSON = number[];
|
package/src/buildScene.ts
CHANGED
|
@@ -172,7 +172,6 @@ function applyNodeModifier(property: string, objectRef: Object3D, value: any) {
|
|
|
172
172
|
}
|
|
173
173
|
case 'scale': {
|
|
174
174
|
const v = value as Vec3;
|
|
175
|
-
console.log(v.x);
|
|
176
175
|
objectRef.scale.set(v.x, v.y, v.z);
|
|
177
176
|
break;
|
|
178
177
|
}
|
|
@@ -464,6 +463,18 @@ export const buildScene = ({
|
|
|
464
463
|
onSceneChanged.removeListener(listener);
|
|
465
464
|
};
|
|
466
465
|
|
|
466
|
+
// This scene is backed by a loaded glTF model and exposes it through the
|
|
467
|
+
// json-path property API (getProperty/setProperty/...). The procedural
|
|
468
|
+
// mesh/light/material API (added to IScene for scene backends like the demo
|
|
469
|
+
// scene) is not supported here, so those operations fail loudly rather than
|
|
470
|
+
// silently doing the wrong thing. Name-enumeration getters return empty so
|
|
471
|
+
// generic choice UIs degrade gracefully instead of throwing.
|
|
472
|
+
const notSupported = (op: string): never => {
|
|
473
|
+
throw new Error(
|
|
474
|
+
`The glTF-backed scene does not support "${op}". Use a scene backend that implements the procedural mesh/light API (e.g. the demo scene) for that operation.`
|
|
475
|
+
);
|
|
476
|
+
};
|
|
477
|
+
|
|
467
478
|
const scene: IScene = {
|
|
468
479
|
getProperty,
|
|
469
480
|
setProperty,
|
|
@@ -472,7 +483,30 @@ export const buildScene = ({
|
|
|
472
483
|
addOnClickedListener,
|
|
473
484
|
removeOnClickedListener,
|
|
474
485
|
addOnSceneChangedListener,
|
|
475
|
-
removeOnSceneChangedListener
|
|
486
|
+
removeOnSceneChangedListener,
|
|
487
|
+
|
|
488
|
+
// --- procedural mesh/light/material API: unsupported on a glTF scene ---
|
|
489
|
+
createMesh: () => notSupported('createMesh'),
|
|
490
|
+
deleteMesh: () => notSupported('deleteMesh'),
|
|
491
|
+
getMeshNames: () => [],
|
|
492
|
+
addLight: () => notSupported('addLight'),
|
|
493
|
+
removeLight: () => notSupported('removeLight'),
|
|
494
|
+
setLightProperty: () => notSupported('setLightProperty'),
|
|
495
|
+
getLightProperty: () => notSupported('getLightProperty'),
|
|
496
|
+
getLightNames: () => [],
|
|
497
|
+
setMaterialProperty: () => notSupported('setMaterialProperty'),
|
|
498
|
+
getMaterialProperty: () => notSupported('getMaterialProperty'),
|
|
499
|
+
addOnAnyMeshClickedListener: () =>
|
|
500
|
+
notSupported('addOnAnyMeshClickedListener'),
|
|
501
|
+
removeOnAnyMeshClickedListener: () =>
|
|
502
|
+
notSupported('removeOnAnyMeshClickedListener'),
|
|
503
|
+
getMeshPosition: () => notSupported('getMeshPosition'),
|
|
504
|
+
setMeshPosition: () => notSupported('setMeshPosition'),
|
|
505
|
+
getDistanceBetween: () => notSupported('getDistanceBetween'),
|
|
506
|
+
lookAt: () => notSupported('lookAt'),
|
|
507
|
+
moveTowards: () => notSupported('moveTowards'),
|
|
508
|
+
cloneMesh: () => notSupported('cloneMesh'),
|
|
509
|
+
setMeshVisible: () => notSupported('setMeshVisible')
|
|
476
510
|
};
|
|
477
511
|
|
|
478
512
|
return scene;
|
package/src/index.ts
CHANGED
|
@@ -1,4 +1,11 @@
|
|
|
1
|
-
|
|
1
|
+
import type { IScene } from './Abstractions/IScene.js';
|
|
2
|
+
|
|
3
|
+
declare module '@kiberon-labs/behave-graph' {
|
|
4
|
+
interface Dependencies {
|
|
5
|
+
IScene: IScene;
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
|
|
2
9
|
export * from './Abstractions/IScene.js';
|
|
3
10
|
export * from './Abstractions/Drivers/DummyScene.js';
|
|
4
11
|
|
|
@@ -17,9 +24,22 @@ export * from './Values/Vec3Value.js';
|
|
|
17
24
|
export * from './Values/Vec4Value.js';
|
|
18
25
|
export * from './Values/QuatValue.js';
|
|
19
26
|
|
|
20
|
-
export * from './Nodes/Actions/
|
|
27
|
+
export * from './Nodes/Actions/AddLight.js';
|
|
28
|
+
export * from './Nodes/Actions/CloneMesh.js';
|
|
29
|
+
export * from './Nodes/Actions/CreateMesh.js';
|
|
30
|
+
export * from './Nodes/Actions/DeleteMesh.js';
|
|
21
31
|
export * from './Nodes/Actions/EaseSceneProperty.js';
|
|
32
|
+
export * from './Nodes/Actions/LookAt.js';
|
|
33
|
+
export * from './Nodes/Actions/MoveTowards.js';
|
|
34
|
+
export * from './Nodes/Actions/RemoveLight.js';
|
|
35
|
+
export * from './Nodes/Actions/SetLightProperty.js';
|
|
36
|
+
export * from './Nodes/Actions/SetMaterialProperty.js';
|
|
37
|
+
export * from './Nodes/Actions/SetMeshPosition.js';
|
|
38
|
+
export * from './Nodes/Actions/SetMeshVisible.js';
|
|
39
|
+
export * from './Nodes/Actions/SetSceneProperty.js';
|
|
22
40
|
|
|
41
|
+
export * from './Nodes/Events/OnAnyMeshClicked.js';
|
|
42
|
+
export * from './Nodes/Events/OnSceneChanged.js';
|
|
23
43
|
export * from './Nodes/Events/OnSceneNodeClick.js';
|
|
24
44
|
|
|
25
45
|
export * as ColorNodes from './Nodes/Logic/ColorNodes.js';
|
|
@@ -32,6 +52,10 @@ export * as Vec4Nodes from './Nodes/Logic/Vec4Nodes.js';
|
|
|
32
52
|
export * as QuatNodes from './Nodes/Logic/QuatNodes.js';
|
|
33
53
|
export * from './Nodes/Logic/VecElements.js';
|
|
34
54
|
|
|
55
|
+
export * from './Nodes/Queries/GetDistanceBetween.js';
|
|
56
|
+
export * from './Nodes/Queries/GetLightProperty.js';
|
|
57
|
+
export * from './Nodes/Queries/GetMaterialProperty.js';
|
|
58
|
+
export * from './Nodes/Queries/GetMeshPosition.js';
|
|
35
59
|
export * from './Nodes/Queries/GetSceneProperty.js';
|
|
36
60
|
|
|
37
61
|
export * from './registerSceneProfile.js';
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ContributionKind,
|
|
3
|
+
PackageCategory,
|
|
4
|
+
defineManifestSource,
|
|
5
|
+
type ContributionSpec,
|
|
6
|
+
type Dependencies
|
|
7
|
+
} from '@kiberon-labs/behave-graph';
|
|
8
|
+
import { getSceneNodesMap, getSceneValuesMap } from './registerSceneProfile.js';
|
|
9
|
+
import { DummyScene } from './Abstractions/Drivers/DummyScene.js';
|
|
10
|
+
import pkg from '../package.json' with { type: 'json' };
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Build-time manifest source for the scene package.
|
|
14
|
+
*
|
|
15
|
+
* The registry projects scene's own nodes + value types into static specs
|
|
16
|
+
* (instantiation only — nodes are never run, no IScene driver needed). The
|
|
17
|
+
* executable profile (`registerSceneProfile`) lives behind the `runtime` entry,
|
|
18
|
+
* loaded only by a runner. Contributions point into the built `dist`: the vec3
|
|
19
|
+
* input control, plus each scene value type so a trusted host can swap the
|
|
20
|
+
* editor's pass-through implementations for the real serializers.
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
// (file, export, valueType name) for each scene value type.
|
|
24
|
+
const valueTypeContributions: ContributionSpec[] = [
|
|
25
|
+
['Vec2Value', 'vec2'],
|
|
26
|
+
['Vec3Value', 'vec3'],
|
|
27
|
+
['Vec4Value', 'vec4'],
|
|
28
|
+
['ColorValue', 'color'],
|
|
29
|
+
['EulerValue', 'euler'],
|
|
30
|
+
['QuatValue', 'quat'],
|
|
31
|
+
['Mat3Value', 'mat3'],
|
|
32
|
+
['Mat4Value', 'mat4']
|
|
33
|
+
].map(([exportName, valueType]) => ({
|
|
34
|
+
id: `${valueType}-value`,
|
|
35
|
+
kind: ContributionKind.ValueType,
|
|
36
|
+
export: `./Values/${exportName}.js#${exportName}`,
|
|
37
|
+
bind: { valueType }
|
|
38
|
+
}));
|
|
39
|
+
|
|
40
|
+
export default defineManifestSource({
|
|
41
|
+
package: { name: pkg.name, version: pkg.version },
|
|
42
|
+
registry: () => ({
|
|
43
|
+
nodes: getSceneNodesMap(),
|
|
44
|
+
values: getSceneValuesMap(),
|
|
45
|
+
// The DummyScene driver satisfies IScene-dependent nodes during spec
|
|
46
|
+
// generation (it never runs them); the real driver is host-provided at run
|
|
47
|
+
// time. Without it, scene-property nodes log "IScene not registered".
|
|
48
|
+
dependencies: { IScene: new DummyScene() } as unknown as Dependencies
|
|
49
|
+
}),
|
|
50
|
+
runtime: './index.js',
|
|
51
|
+
categories: [PackageCategory.Effect],
|
|
52
|
+
contributions: [
|
|
53
|
+
{
|
|
54
|
+
id: 'vec3-control',
|
|
55
|
+
kind: ContributionKind.Control,
|
|
56
|
+
export: './ui/controls/vec3.js#Vec3Control',
|
|
57
|
+
bind: { controlName: 'vec3' }
|
|
58
|
+
},
|
|
59
|
+
...valueTypeContributions
|
|
60
|
+
]
|
|
61
|
+
});
|
|
@@ -11,7 +11,20 @@ import type {
|
|
|
11
11
|
ValueTypeMap
|
|
12
12
|
} from '@kiberon-labs/behave-graph';
|
|
13
13
|
|
|
14
|
+
import { AddLight } from './Nodes/Actions/AddLight.js';
|
|
15
|
+
import { CloneMesh } from './Nodes/Actions/CloneMesh.js';
|
|
16
|
+
import { CreateMesh } from './Nodes/Actions/CreateMesh.js';
|
|
17
|
+
import { DeleteMesh } from './Nodes/Actions/DeleteMesh.js';
|
|
18
|
+
import { LookAt } from './Nodes/Actions/LookAt.js';
|
|
19
|
+
import { MoveTowards } from './Nodes/Actions/MoveTowards.js';
|
|
20
|
+
import { RemoveLight } from './Nodes/Actions/RemoveLight.js';
|
|
21
|
+
import { SetLightProperty } from './Nodes/Actions/SetLightProperty.js';
|
|
22
|
+
import { SetMaterialProperty } from './Nodes/Actions/SetMaterialProperty.js';
|
|
23
|
+
import { SetMeshPosition } from './Nodes/Actions/SetMeshPosition.js';
|
|
24
|
+
import { SetMeshVisible } from './Nodes/Actions/SetMeshVisible.js';
|
|
14
25
|
import { SetSceneProperty } from './Nodes/Actions/SetSceneProperty.js';
|
|
26
|
+
import { OnAnyMeshClicked } from './Nodes/Events/OnAnyMeshClicked.js';
|
|
27
|
+
import { OnSceneChanged } from './Nodes/Events/OnSceneChanged.js';
|
|
15
28
|
import { OnSceneNodeClick } from './Nodes/Events/OnSceneNodeClick.js';
|
|
16
29
|
import * as ColorNodes from './Nodes/Logic/ColorNodes.js';
|
|
17
30
|
import * as EulerNodes from './Nodes/Logic/EulerNodes.js';
|
|
@@ -21,6 +34,10 @@ import * as QuatNodes from './Nodes/Logic/QuatNodes.js';
|
|
|
21
34
|
import * as Vec2Nodes from './Nodes/Logic/Vec2Nodes.js';
|
|
22
35
|
import * as Vec3Nodes from './Nodes/Logic/Vec3Nodes.js';
|
|
23
36
|
import * as Vec4Nodes from './Nodes/Logic/Vec4Nodes.js';
|
|
37
|
+
import { GetDistanceBetween } from './Nodes/Queries/GetDistanceBetween.js';
|
|
38
|
+
import { GetLightProperty } from './Nodes/Queries/GetLightProperty.js';
|
|
39
|
+
import { GetMaterialProperty } from './Nodes/Queries/GetMaterialProperty.js';
|
|
40
|
+
import { GetMeshPosition } from './Nodes/Queries/GetMeshPosition.js';
|
|
24
41
|
import { GetSceneProperty } from './Nodes/Queries/GetSceneProperty.js';
|
|
25
42
|
import { ColorValue } from './Values/ColorValue.js';
|
|
26
43
|
import { EulerValue } from './Values/EulerValue.js';
|
|
@@ -74,9 +91,31 @@ export const getSceneNodesMap = memo<Record<string, NodeDefinition>>(() => {
|
|
|
74
91
|
|
|
75
92
|
// events
|
|
76
93
|
OnSceneNodeClick,
|
|
77
|
-
|
|
94
|
+
OnSceneChanged,
|
|
95
|
+
OnAnyMeshClicked,
|
|
96
|
+
// actions - property
|
|
78
97
|
...SetSceneProperty(allValueTypeNames),
|
|
98
|
+
// actions - mesh lifecycle
|
|
99
|
+
CreateMesh,
|
|
100
|
+
DeleteMesh,
|
|
101
|
+
CloneMesh,
|
|
102
|
+
// actions - spatial
|
|
103
|
+
MoveTowards,
|
|
104
|
+
LookAt,
|
|
105
|
+
SetMeshPosition,
|
|
106
|
+
SetMeshVisible,
|
|
107
|
+
// actions - lighting
|
|
108
|
+
AddLight,
|
|
109
|
+
RemoveLight,
|
|
110
|
+
SetLightProperty,
|
|
111
|
+
// actions - material
|
|
112
|
+
SetMaterialProperty,
|
|
113
|
+
// queries
|
|
79
114
|
...GetSceneProperty(allValueTypeNames),
|
|
115
|
+
GetLightProperty,
|
|
116
|
+
GetMaterialProperty,
|
|
117
|
+
GetMeshPosition,
|
|
118
|
+
GetDistanceBetween,
|
|
80
119
|
|
|
81
120
|
...getSceneStringConversions(getSceneValuesMap())
|
|
82
121
|
];
|
|
@@ -98,8 +137,6 @@ export const registerSceneProfile = (registry: IRegistry): IRegistry => {
|
|
|
98
137
|
return {
|
|
99
138
|
values,
|
|
100
139
|
nodes: { ...registry.nodes, ...getSceneNodesMap() },
|
|
101
|
-
dependencies:
|
|
102
|
-
...registry.dependencies
|
|
103
|
-
}
|
|
140
|
+
dependencies: registry.dependencies
|
|
104
141
|
};
|
|
105
142
|
};
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
|
|
3
|
+
import { VscodeTextfield } from '@vscode-elements/react-elements';
|
|
4
|
+
import type { ControlProps } from '@kiberon-labs/behave-graph-flow';
|
|
5
|
+
import type { Vec3JSON } from '@/Values/Internal/Vec3';
|
|
6
|
+
|
|
7
|
+
// The @vscode-elements/react-elements typings surface the underlying custom
|
|
8
|
+
// element's DOM events, so its `onChange` hands back a plain `Event`. Pull the
|
|
9
|
+
// value out via the input target (same hack the flow number control uses).
|
|
10
|
+
const readNumber = (e: Event): number | undefined => {
|
|
11
|
+
const stringValue = (e as unknown as React.ChangeEvent<HTMLInputElement>)
|
|
12
|
+
.currentTarget.value;
|
|
13
|
+
const num = parseFloat(stringValue);
|
|
14
|
+
return isNaN(num) ? undefined : num;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export const Vec3Control: React.FC<ControlProps<Vec3JSON>> = ({
|
|
18
|
+
value,
|
|
19
|
+
onChange
|
|
20
|
+
}) => {
|
|
21
|
+
const vec = value ?? [0, 0, 0];
|
|
22
|
+
|
|
23
|
+
const handleChangeX = (e: Event) => {
|
|
24
|
+
const num = readNumber(e);
|
|
25
|
+
if (num !== undefined) onChange([num, vec[1], vec[2]]);
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
const handleChangeY = (e: Event) => {
|
|
29
|
+
const num = readNumber(e);
|
|
30
|
+
if (num !== undefined) onChange([vec[0], num, vec[2]]);
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
const handleChangeZ = (e: Event) => {
|
|
34
|
+
const num = readNumber(e);
|
|
35
|
+
if (num !== undefined) onChange([vec[0], vec[1], num]);
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
return (
|
|
39
|
+
<div style={{ display: 'flex', gap: '4px', alignItems: 'center' }}>
|
|
40
|
+
<label style={{ fontSize: '11px', opacity: 0.7, minWidth: '12px' }}>
|
|
41
|
+
X
|
|
42
|
+
</label>
|
|
43
|
+
<VscodeTextfield
|
|
44
|
+
type="number"
|
|
45
|
+
value={vec[0].toString()}
|
|
46
|
+
onChange={handleChangeX}
|
|
47
|
+
style={{ flex: 1 }}
|
|
48
|
+
/>
|
|
49
|
+
<label style={{ fontSize: '11px', opacity: 0.7, minWidth: '12px' }}>
|
|
50
|
+
Y
|
|
51
|
+
</label>
|
|
52
|
+
<VscodeTextfield
|
|
53
|
+
type="number"
|
|
54
|
+
value={vec[1].toString()}
|
|
55
|
+
onChange={handleChangeY}
|
|
56
|
+
style={{ flex: 1 }}
|
|
57
|
+
/>
|
|
58
|
+
<label style={{ fontSize: '11px', opacity: 0.7, minWidth: '12px' }}>
|
|
59
|
+
Z
|
|
60
|
+
</label>
|
|
61
|
+
<VscodeTextfield
|
|
62
|
+
type="number"
|
|
63
|
+
value={vec[2].toString()}
|
|
64
|
+
onChange={handleChangeZ}
|
|
65
|
+
style={{ flex: 1 }}
|
|
66
|
+
/>
|
|
67
|
+
</div>
|
|
68
|
+
);
|
|
69
|
+
};
|