test commit

master
Jake 2025-11-03 11:04:53 +08:00
parent c1c7b41135
commit 7fbc41f8b7
2 changed files with 30 additions and 20 deletions

View File

@ -5,7 +5,7 @@ export class CurveEditor {
canvas.height = canvas.offsetHeight;
this.ctx = canvas.getContext('2d');
this.timelineLength = timelineLength;
this.logicalHeight = 800;
this.scale = 1;
this.scaleX = 1;
@ -101,10 +101,11 @@ export class CurveEditor {
view.setUint16(offset, seg.endHandleX, true); offset += 2;
view.setInt16(offset, this.yToExportRange(seg.endHandleY), true); offset += 2;
view.setInt16(offset, this.yToExportRange(seg.endPointY), true); offset += 2;
console.log(seg.startPointY, seg.endPointY);
console.log(this.yToExportRange(seg.startPointY), this.yToExportRange(seg.endPointY));
});
//console.log("🧵 Curve segments packed:", curveSegments.length);
//console.log(curveSegments);
return new Uint8Array(buffer.slice(0, offset));
@ -140,6 +141,7 @@ export class CurveEditor {
loadCurveSets(curveSets) {
this.curveSets = []
this.curveSets = curveSets;
console.log(curveSets);
// If selectedMotorID is present in the new set, load its curves
if (curveSets[this.selectedMotorID]) {
@ -148,8 +150,11 @@ export class CurveEditor {
this.setCurves([]); // fallback to empty
}
console.log("LOADED");
console.log()
setSelectedMotor(10); // Global defined in script.js
console.log(this.curveSets);
console.log(Object.keys(curveSets)[0]);
setSelectedMotor(parseInt(Object.keys(curveSets)[0]));
// hello
//this.selectAdjacentMotor(1);
// Optional: update motor selector UI or redraw timeline
//this.refreshMotorSelector?.(); // if you have a method for that
@ -168,35 +173,39 @@ export class CurveEditor {
valueToY(v) {
return (this.canvas.height / 2 - v * (this.canvas.height / 2)) * this.scaleY + this.offset.y;
// valueToY(v) {
// return (this.canvas.height / 2 - v * (this.canvas.height / 2)) * this.scaleY + this.offset.y;
// }
valueToYNoOffset(v) {
return (this.canvas.height / 2 - v * (this.canvas.height / 2));
}
// Maps pixel value of y axis to -1 to 1 normalised value
yToValue(y) {
return ((this.canvas.height / 2 - (y - this.offset.y) / this.scaleY) / (this.canvas.height / 2));
valueToY(v) {
return (this.logicalHeight / 2 - v * (this.logicalHeight / 2)) * this.scaleY + this.offset.y;
}
yToValue(y) {
return ((this.logicalHeight / 2 - (y - this.offset.y) / this.scaleY) / (this.logicalHeight / 2));
}
// Maps normalised -1 to 1 value to motor range (0, 4095)
yToExportRange(y) {
const [minOut, maxOut] = this.exportRange;
// Normalize y from [-1, 1] to [0, 1]
const normalized = (this.yToValue(y) + 1) / 2;
// Scale to export range
return Math.round(normalized * (maxOut - minOut) + minOut);
const clampedY = Math.max(0, Math.min(y, this.logicalHeight)); // optional safety
const normalized = clampedY / this.logicalHeight; // maps to [0, 1]
return Math.round(normalized * (maxOut - minOut) + minOut); // maps to [minOut, maxOut]
}
exportRangeToY(value) {
const [minOut, maxOut] = this.exportRange;
// Reverse the scaling
const normalized = (value - minOut) / (maxOut - minOut);
// Convert from [0, 1] back to [-1, 1]
const yValue = normalized * 2 - 1;
// Apply inverse mapping from value space to editor Y
return this.valueToY(yValue);
const normalized = 1 - (value - minOut) / (maxOut - minOut); // flipped
return this.valueToYNoOffset(normalized * 2 - 1);
}
valueToX(value) {
return value * this.pixelsPerSecond * this.scaleX + this.offset.x;
}

View File

@ -595,7 +595,8 @@ window.onload = () => {
//console.log(startTime, endTime, startPointY, endPointY);
const toFloat = v => (v / 65535) * 2 - 1;
console.log(startPointY);
console.log(curveEditor.exportRangeToY(startPointY));
const curve = {
startPoint: {
x: startTime,