Skip to content

Commit 85e77d1

Browse files
reference marker adjustment
1 parent 83075e2 commit 85e77d1

File tree

1 file changed

+27
-16
lines changed

1 file changed

+27
-16
lines changed

l2f.js

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -144,26 +144,36 @@ export class L2F{
144144
})
145145
this.state_update_callbacks.forEach(callback => callback(combined_state))
146146
}
147+
remove_reference_markers(){
148+
if(this.references !== null){
149+
this.references_ui.forEach(ball => {
150+
this.ui_state.simulator.remove(ball)
151+
})
152+
}
153+
this.references_ui = []
154+
this.references = null
155+
}
156+
update_reference_markers(references){
157+
if(this.references === null || this.references.length !== references.length){
158+
// create three.js reference ball
159+
if(this.references !== null){
160+
this.remove_reference_markers()
161+
}
162+
this.references_ui = references.map((reference, i) => {
163+
const geometry = new THREE.SphereGeometry(Math.cbrt(this.parameters[i].dynamics.mass) / 50, 32, 32);
164+
const material = new THREE.MeshStandardMaterial({ color: 0xff4444 });
165+
const ball = new THREE.Mesh(geometry, material);
166+
const reference_ui_objects = this.ui_state.simulator.add(ball)
167+
return ball
168+
})
169+
}
170+
this.references = references
171+
}
147172
simulate_step(){
148173
const actions = this.policy.evaluate_step(this.states)
149174
const references = this.policy.get_reference(this.states)
150175
if(references !== null){
151-
if(this.references === null || this.references.length !== references.length){
152-
// create three.js reference ball
153-
if(this.references !== null){
154-
this.references_ui.forEach(ball => {
155-
this.ui_state.simulator.remove(ball)
156-
})
157-
}
158-
this.references_ui = references.map((reference, i) => {
159-
const geometry = new THREE.SphereGeometry(Math.cbrt(this.parameters[i].dynamics.mass) / 50, 32, 32);
160-
const material = new THREE.MeshStandardMaterial({ color: 0xff4444 });
161-
const ball = new THREE.Mesh(geometry, material);
162-
const reference_ui_objects = this.ui_state.simulator.add(ball)
163-
return ball
164-
})
165-
}
166-
this.references = references
176+
this.update_reference_markers(references)
167177
this.references.forEach((reference, i) => {
168178
this.references_ui[i].position.set(reference[0], reference[1], reference[2])
169179
})
@@ -245,6 +255,7 @@ export class L2F{
245255
this.states[id].set_parameters(JSON.stringify(parameters[i]))
246256
})
247257
await this.ui.episode_init_multi(this.ui_state, this.parameters)
258+
this.remove_reference_markers()
248259
}
249260
async set_perturbed_parameters(ids, parameters){
250261
await this.initialized

0 commit comments

Comments
 (0)