Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions src/physics/function_cluster_objects.js
Original file line number Diff line number Diff line change
@@ -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);
}
5 changes: 5 additions & 0 deletions src/physics/physics.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -67,6 +68,7 @@ export class PhysicsSimulation extends Simulation {
get toolSchemas () {
return [
GetSpatialLayoutFunction.schema,
ClusterObjectsFunction.schema,
AddObjectsFunction.schema,
RemoveObjectsFunction.schema,
];
Expand All @@ -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);
}
};
}

Expand Down