From 05b77e8b261293f05e7df6a45ca195e7206306f3 Mon Sep 17 00:00:00 2001 From: "Saffo, David" Date: Tue, 2 Apr 2024 11:49:12 -0400 Subject: [PATCH] types and code hints for bind and create --- anu-examples/examples/FirstSteps/Box.js | 1 + .../examples/FirstSteps/Box_With_Data.js | 2 +- anu-examples/package.json | 1 - docs/vue_components/galleryView.vue | 0 src/bind.ts | 6 ++- src/create.ts | 45 ++++++++++++++++--- src/selection/bind/bind.ts | 6 ++- 7 files changed, 50 insertions(+), 11 deletions(-) delete mode 100644 docs/vue_components/galleryView.vue diff --git a/anu-examples/examples/FirstSteps/Box.js b/anu-examples/examples/FirstSteps/Box.js index 084fe74a..87517ac1 100644 --- a/anu-examples/examples/FirstSteps/Box.js +++ b/anu-examples/examples/FirstSteps/Box.js @@ -15,5 +15,6 @@ export const box = function(engine){ camera.attachControl(true) let box = anu.create('box', 'ourBox', {size: 2}, [{count: 2}]); + return scene; }; \ No newline at end of file diff --git a/anu-examples/examples/FirstSteps/Box_With_Data.js b/anu-examples/examples/FirstSteps/Box_With_Data.js index f96ecd92..1941dde7 100644 --- a/anu-examples/examples/FirstSteps/Box_With_Data.js +++ b/anu-examples/examples/FirstSteps/Box_With_Data.js @@ -21,7 +21,7 @@ export const box_data = function(engine){ { height: (d) => d.goals, width: (d) => d.assits, - depth: (d) => d.points + depth: (d) => d.points, }, {goals: 5, assits: 10, points: 2}) diff --git a/anu-examples/package.json b/anu-examples/package.json index 4d58a132..f30e1235 100644 --- a/anu-examples/package.json +++ b/anu-examples/package.json @@ -15,7 +15,6 @@ "@babylonjs/core": "^6.46.0", "@babylonjs/gui": "^6.46.0", "@babylonjs/inspector": "^6.12.3", - "@jpmorganchase/anu": "^0.0.43", "d3": "^7.6.1", "d3-force-3d": "^3.0.5", "simplify-3d": "^1.0.0", diff --git a/docs/vue_components/galleryView.vue b/docs/vue_components/galleryView.vue deleted file mode 100644 index e69de29b..00000000 diff --git a/src/bind.ts b/src/bind.ts index 37e4bba7..972708c8 100644 --- a/src/bind.ts +++ b/src/bind.ts @@ -3,7 +3,9 @@ import { Node, ActionManager, Tags, Mesh, Scene, InstancedMesh } from '@babylonjs/core'; import { Selection } from './index'; -import { create } from './create'; +import { create, MeshTypes } from './create'; + +type Property = T[K]; /** * Take a shape type, a scene, and data. For each index in the data create a new mesh for each node in the selection as the parent. @@ -16,7 +18,7 @@ import { create } from './create'; * @returns An instance of Selection, a class containing a array of selected nodes, the scene, and the functions of the class Selection, * or undefined if a selection could not be made. */ -export function bind(shape: string, options?: object, data: Array = [{}], scene?: Scene): Selection { +export function bind(shape: K, options?: Property, data: Array = [{}], scene?: Scene): Selection { let meshes: Node[] = []; data.forEach((element, i) => { var mesh = create(shape, shape, options, element, scene); diff --git a/src/create.ts b/src/create.ts index 331fae2b..20ef9f11 100644 --- a/src/create.ts +++ b/src/create.ts @@ -1,7 +1,7 @@ // SPDX-License-Identifier: Apache-2.0 // Copyright : J.P. Morgan Chase & Co. -import { Mesh, MeshBuilder, TransformNode, Scene, Nullable, ActionManager, Tags, CreateGreasedLine, GreasedLineMeshBuilderOptions, Node, BoundingInfo, Observable, AbstractMesh } from '@babylonjs/core'; +import { Mesh, MeshBuilder, TransformNode, Scene, ActionManager, Tags, CreateGreasedLine, GreasedLineMeshBuilderOptions } from '@babylonjs/core'; import { createPlaneText } from './prefabs/Text/planeText'; import { createContainer } from './prefabs/Misc/container'; @@ -55,6 +55,41 @@ const meshList: StringByFunc = { container: createContainer, }; +export interface MeshTypes { + "box": Parameters[1], + "cot": any, + "sphere": Parameters[1], + "tiledBox": Parameters[1], + "cylinder": Parameters[1], + "capsule": Parameters[1], + "plane": Parameters[1], + "tiledPlane": Parameters[1], + "disc": Parameters[1], + "torus": Parameters[1], + "torusKnot": Parameters[1], + "ground": Parameters[1], + "tiledGround": Parameters[1], + "lines": Parameters[1], + "dashedLines": Parameters[1], + "lineSystem": Parameters[1], + "ribbon": Parameters[1], + "tube": Parameters[1], + "extrude": Parameters[1], + "extrudeCustom": Parameters[1], + "lathe": Parameters[1], + "polygon": Parameters[1], + "extrudePolygon": Parameters[1], + "polyhedra": Parameters[1], + "icosphere": Parameters[1], + "geodesic": Parameters[1], + "goldberg": Parameters[1], + 'planeText': Parameters[1], + "greasedLine": Parameters[1], + "container": Parameters[1], +} + +type Property = T[K]; + /** * Helper function to build meshes of a specified type with options optionally set with functions and data. * @@ -65,17 +100,17 @@ const meshList: StringByFunc = { * @param scene The scene to create the mesh in. * @returns A mesh object created with the passed parameters. */ -export function create( - shape: string, +export function create( + shape: K, name: string, - options: object = {}, + options: Property = {}, data: object = {}, scene?: Scene ): Mesh { let executedOptions: StringByAny = {}; for (let [key, value] of Object.entries(options)) { - value instanceof Function ? (executedOptions[key] = value(data)) : (executedOptions[key] = value); + value instanceof Function ? (executedOptions[key] = (value as Function)(data)) : (executedOptions[key] = value); } let builder: Function = meshList[shape]; diff --git a/src/selection/bind/bind.ts b/src/selection/bind/bind.ts index 8de01031..9f501be9 100644 --- a/src/selection/bind/bind.ts +++ b/src/selection/bind/bind.ts @@ -3,7 +3,9 @@ import { Node, ActionManager, Tags, Mesh, InstancedMesh } from '@babylonjs/core'; import { Selection } from '../index'; -import { create } from '../../create'; +import { create, MeshTypes } from '../../create'; + +type Property = T[K]; /** * Take a selection, a shape type, and data. For each index in the data create a new mesh for each node in the selection as the parent. @@ -15,7 +17,7 @@ import { create } from '../../create'; * @returns An instance of Selection, a class containing a array of selected nodes, the scene, and the functions of the class Selection, * or undefined if a selection could not be made. */ -export function bind(this: Selection, shape: string, options: object = {}, data: Array = [{}]): Selection { +export function bind(this: Selection, shape: K, options: Property = {}, data: Array = [{}]): Selection { let meshes: Node[] = []; this.selected.forEach((node) => { data.forEach((element, i) => {