fixed keyframe dragging

node_mode
Jake 2025-10-06 09:34:56 +08:00
parent 2780ad2859
commit a27551ff9a
1 changed files with 18 additions and 16 deletions

View File

@ -148,7 +148,7 @@ window.onload = () => {
break;
}
}
for (let f = currentFrame; f <= 399; f++) {
for (let f = currentFrame; f <= totalFrames; f++) {
if (keyframes[f] !== undefined) {
nextFrame = f;
break;
@ -628,7 +628,7 @@ window.onload = () => {
if (selectedDial !== null) {
for (let frame in dialKeyframes[selectedDial]) {
const x = (frame / 400) * width;
const x = (frame / totalFrames) * width;
ctx.beginPath();
ctx.moveTo(x, 0);
ctx.lineTo(x, height);
@ -639,7 +639,7 @@ window.onload = () => {
} else {
for (let ch = 0; ch < 5; ch++) {
for (let frame in dialKeyframes[ch]) {
const x = (frame / 400) * width;
const x = (frame / totalFrames) * width;
ctx.beginPath();
ctx.moveTo(x, 0);
ctx.lineTo(x, height);
@ -650,7 +650,7 @@ window.onload = () => {
}
}
const currentX = (currentFrame / 400) * width;
const currentX = (currentFrame / totalFrames) * width;
ctx.beginPath();
ctx.moveTo(currentX, 0);
ctx.lineTo(currentX, height);
@ -674,15 +674,15 @@ window.onload = () => {
canvas.addEventListener('mousedown', (e) => {
const x = e.offsetX;
const frame = Math.round((x / canvas.width) * totalFrames);
const dialIndices = selectedDial !== null ? [selectedDial] : [0, 1, 2, 3, 4];
for (let ch of dialIndices) {
for (let f in dialKeyframes[ch]) {
const fx = (f / totalFrames) * canvas.width;
if (Math.abs(fx - x) < 5) {
draggingKeyframe = { dialIndex: ch, originalFrame: parseInt(f) };
const frameNum = parseInt(f);
const fx = (frameNum / totalFrames) * canvas.width;
if (Math.abs(fx - x) < 15) {
draggingKeyframe = { dialIndex: ch, originalFrame: frameNum };
isDragging = true;
return;
}
@ -690,6 +690,7 @@ window.onload = () => {
}
});
canvas.addEventListener('mousemove', (e) => {
if (!isDragging || !draggingKeyframe) return;
@ -711,6 +712,7 @@ window.onload = () => {
canvas.addEventListener('mouseup', () => {
isDragging = false;
draggingKeyframe = null;
syncMotorsWithTimeline();
});
canvas.addEventListener('dblclick', (e) => {