time slider now in visual editor overlay

master
Jake Wilkinson 2025-11-23 21:36:03 +08:00
parent ec4896bd93
commit f8ec407a45
4 changed files with 43 additions and 25 deletions

View File

@ -111,6 +111,11 @@ export class CurveEditor {
return new Uint8Array(buffer.slice(0, offset)); return new Uint8Array(buffer.slice(0, offset));
} }
setCurrentTime(time) {
this.currentTime = parseFloat(time);
this.draw();
}
addChannel(motorID) { addChannel(motorID) {
this.setCurves([ this.setCurves([
{ {
@ -128,7 +133,7 @@ export class CurveEditor {
setLength(endTime) { setLength(endTime) {
this.timelineLength = endTime / this.pixelsPerSecond; this.timelineLength = endTime / this.pixelsPerSecond;
this.slider.max = this.timelineLength * this.pixelsPerSecond; this.slider.max = this.timelineLength * this.pixelsPerSecond;
console.log(this.slider.max, this.slider.value); //console.log(this.slider.max, this.slider.value);
if (this.slider.value > this.slider.max) { if (this.slider.value > this.slider.max) {
this.slider.value = this.slider.max; this.slider.value = this.slider.max;
} }
@ -138,6 +143,10 @@ export class CurveEditor {
this.draw(); this.draw();
} }
getLength(){
return this.timelineLength * this.pixelsPerSecond;
}
loadCurveSets(curveSets) { loadCurveSets(curveSets) {
this.curveSets = [] this.curveSets = []
this.curveSets = curveSets; this.curveSets = curveSets;

View File

@ -18,10 +18,11 @@ const SyncMode = {
}; };
export class URDFEditor { export class URDFEditor {
constructor(canvas, sendMotorPosition, serial) { constructor(canvas, sendMotorPosition, serial, curveEditor) {
this.canvas = canvas; this.canvas = canvas;
this.sendMotorPosition = sendMotorPosition; this.sendMotorPosition = sendMotorPosition;
this.serial = serial; this.serial = serial;
this.curveEditor = curveEditor;
this.scene = new THREE.Scene(); this.scene = new THREE.Scene();
this.scene.background = new THREE.Color(0xaaaaaa); this.scene.background = new THREE.Color(0xaaaaaa);
@ -154,6 +155,10 @@ export class URDFEditor {
this.overlay.resetEditor(); this.overlay.resetEditor();
} }
setAnimationLength(totalFrames) {
//this.overlay.
}
async loadURDF() { async loadURDF() {
if (this.robot) { if (this.robot) {
console.log("resetting editor"); console.log("resetting editor");

View File

@ -153,11 +153,22 @@ export class ViewerOverlay {
panel.addElement(rb3); panel.addElement(rb3);
const slider = new Slider( const slider = new Slider(
panel.x + panel.w * 0.025, panel.y + panel.h * 0.85, panel.w * 0.925, 20, panel.x + panel.w * 0.025,
0, 100, 50, panel.y + panel.h * 0.85,
(val) => console.log("Slider value:", val) panel.w * 0.925,
20,
0, // min
this.parent.curveEditor.getLength(), // max
50, // initial
(val) => {
this.parent.curveEditor.setCurrentTime(val.toFixed(0)); // update parent
if (slider.max != this.parent.curveEditor.getLength()) {
slider.max = this.parent.curveEditor.getLength();
}
}
); );
panel.addElement(slider); panel.addElement(slider);
return panel; return panel;

View File

@ -11,9 +11,7 @@ import { URDFEditor } from './ros_robot_visualiser/URDFEditor.js';
window.onload = () => { window.onload = () => {
const serial = new SerialManager();
const urdfCanvas = document.getElementById('urdfCanvas');
const visualEditor = new URDFEditor(urdfCanvas, sendMotorPosition, serial);
const servoMotors = [[], []]; // index 0 = channel 0, index 1 = channel 1 const servoMotors = [[], []]; // index 0 = channel 0, index 1 = channel 1
@ -38,15 +36,17 @@ window.onload = () => {
const frameSlider = document.getElementById('frameSlider');
const frameDisplay = document.getElementById('frameDisplay');
const curveCanvas = document.getElementById('curveCanvas'); const curveCanvas = document.getElementById('curveCanvas');
const curveEditor = new CurveEditor(curveCanvas, 10, frameSlider); const curveEditor = new CurveEditor(curveCanvas, 10, frameSlider);
const serial = new SerialManager();
const urdfCanvas = document.getElementById('urdfCanvas');
const visualEditor = new URDFEditor(urdfCanvas, sendMotorPosition, serial, curveEditor);
// Animation File List // Animation File List
const fileListElement = document.getElementById('fileList'); const fileListElement = document.getElementById('fileList');
@ -212,14 +212,6 @@ window.onload = () => {
deleteButton.disabled = true; deleteButton.disabled = true;
} }
}); });
// Timeline // Timeline
frameSlider.oninput = () => { frameSlider.oninput = () => {
@ -517,6 +509,7 @@ window.onload = () => {
curveEditor.loadCurveSets(curveSets); curveEditor.loadCurveSets(curveSets);
curveEditor.setLength(latestEndTime); curveEditor.setLength(latestEndTime);
visualEditor.setAnimationLength(latestEndTime);
if (offset < view.byteLength) { if (offset < view.byteLength) {
const nodeGraphData = raw.slice(offset); // grab remaining bytes const nodeGraphData = raw.slice(offset); // grab remaining bytes
nodeEditor.loadFromBinary(nodeGraphData); // call your editor's loader nodeEditor.loadFromBinary(nodeGraphData); // call your editor's loader