time slider now in visual editor overlay
parent
ec4896bd93
commit
f8ec407a45
|
|
@ -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;
|
||||||
|
|
@ -152,7 +161,7 @@ export class CurveEditor {
|
||||||
console.log("LOADED");
|
console.log("LOADED");
|
||||||
console.log(this.curveSets);
|
console.log(this.curveSets);
|
||||||
console.log(Object.keys(curveSets)[0]);
|
console.log(Object.keys(curveSets)[0]);
|
||||||
setSelectedMotor(parseInt(Object.keys(curveSets)[0]));
|
setSelectedMotor(parseInt(Object.keys(curveSets)[0]));
|
||||||
// hello
|
// hello
|
||||||
|
|
||||||
//this.selectAdjacentMotor(1);
|
//this.selectAdjacentMotor(1);
|
||||||
|
|
|
||||||
|
|
@ -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");
|
||||||
|
|
|
||||||
|
|
@ -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;
|
||||||
|
|
|
||||||
31
script.js
31
script.js
|
|
@ -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
|
||||||
|
|
@ -35,18 +33,20 @@ window.onload = () => {
|
||||||
|
|
||||||
let draggingKeyframe = null; // { dialIndex, originalFrame }
|
let draggingKeyframe = null; // { dialIndex, originalFrame }
|
||||||
let isDragging = false;
|
let isDragging = false;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
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
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue