diff --git a/src/physics/function_cluster_objects.js b/src/physics/function_cluster_objects.js new file mode 100644 index 0000000..c086347 --- /dev/null +++ b/src/physics/function_cluster_objects.js @@ -0,0 +1,16 @@ +export const function_name = "cluster_objects"; + +export const schema = { + "type": "function", + "function": { + "name": "cluster_objects", + "description": "Use the position of all objects in the scene, by object type, to calculate k-means clusters, suggest new positions for each object at the centerpoint of each respective cluster." + } +}; + +export function cluster_objects (worldState, params) { + const stuff = { + "objects": worldState.objects.map(obj => obj.json) + }; + return JSON.stringify(stuff); +} diff --git a/src/physics/physics.js b/src/physics/physics.js index 51354f7..bd0cb11 100644 --- a/src/physics/physics.js +++ b/src/physics/physics.js @@ -8,6 +8,7 @@ import * as AddObjectsFunction from './function_add_objects.js'; import * as RemoveObjectsFunction from './function_remove_objects.js'; import * as GetSpatialLayoutFunction from './function_get_spatial_layout.js'; +import * as ClusterObjectsFunction from './function_cluster_objects.js'; import { Simulation } from '../simulation.js'; @@ -67,6 +68,7 @@ export class PhysicsSimulation extends Simulation { get toolSchemas () { return [ GetSpatialLayoutFunction.schema, + ClusterObjectsFunction.schema, AddObjectsFunction.schema, RemoveObjectsFunction.schema, ]; @@ -83,6 +85,9 @@ export class PhysicsSimulation extends Simulation { "remove_objects": args => { return RemoveObjectsFunction.remove_objects(this.worldState, args); }, + "cluster_objects": args => { + return ClusterObjectsFunction.cluster_objects(this.worldState, args); + } }; }