|
1 | 1 | // import * as ui from "./ui.js" |
2 | 2 | import createModule from "l2f-interface"; |
| 3 | +import * as THREE from "three" |
3 | 4 | // const DEBUG = true |
4 | 5 | const DEBUG = false |
5 | 6 |
|
@@ -82,6 +83,7 @@ export class L2F{ |
82 | 83 | this.control() |
83 | 84 | }); |
84 | 85 | this.dt = null |
| 86 | + this.references = null |
85 | 87 | } |
86 | 88 | async change_num_quadrotors(num){ |
87 | 89 | const diff = num - this.states.length |
@@ -113,6 +115,21 @@ export class L2F{ |
113 | 115 | } |
114 | 116 | simulate_step(){ |
115 | 117 | const actions = this.policy.evaluate_step(this.states) |
| 118 | + const references = this.policy.get_reference(this.states) |
| 119 | + if(this.references === null){ |
| 120 | + // create three.js reference ball |
| 121 | + this.references_ui = references.map((reference, i) => { |
| 122 | + const geometry = new THREE.SphereGeometry(Math.cbrt(this.parameters[i].dynamics.mass) / 20, 32, 32); |
| 123 | + const material = new THREE.MeshStandardMaterial({ color: 0xff4444 }); |
| 124 | + const ball = new THREE.Mesh(geometry, material); |
| 125 | + const reference_ui_objects = this.ui_state.simulator.add(ball) |
| 126 | + return ball |
| 127 | + }) |
| 128 | + } |
| 129 | + this.references = references |
| 130 | + this.references.forEach((reference, i) => { |
| 131 | + this.references_ui[i].position.set(reference[0], reference[1], reference[2]) |
| 132 | + }) |
116 | 133 | console.assert(actions.length === this.states.length, "Action dimension mismatch") |
117 | 134 | this.states.forEach((state, i) => { |
118 | 135 | const action = actions[i] |
@@ -176,6 +193,7 @@ export class L2F{ |
176 | 193 | if(this.render_states && this.render_actions){ |
177 | 194 | this.ui.render_multi(this.ui_state, this.parameters, this.render_states, this.render_actions) |
178 | 195 | } |
| 196 | + this.ui_state |
179 | 197 | requestAnimationFrame(() => this.render()); |
180 | 198 | if(this.DEBUG){ |
181 | 199 | this.stats.end() |
|
0 commit comments