Spaces:
Runtime error
Runtime error
add modifier key guide
Browse files- app.py +17 -12
- static/poseEditor.js +32 -4
app.py
CHANGED
@@ -109,6 +109,10 @@ with gr.Blocks(css="""button { min-width: 80px; }""") as demo:
|
|
109 |
json = gr.JSON(label="Json")
|
110 |
jsonInput = gr.Textbox(label="Json source", lines=10)
|
111 |
jsonInputBtn = gr.Button(value="Import Json")
|
|
|
|
|
|
|
|
|
112 |
with gr.Column(scale=2):
|
113 |
html = gr.HTML(html_text)
|
114 |
with gr.Row():
|
@@ -116,18 +120,19 @@ with gr.Blocks(css="""button { min-width: 80px; }""") as demo:
|
|
116 |
saveBtn = gr.Button(value="Save")
|
117 |
with gr.Column(scale=7):
|
118 |
gr.Markdown("""
|
119 |
-
- "ctrl + drag" to scale
|
120 |
-
- "alt + drag" to
|
121 |
-
- "shift + drag" to rotate(move right first, release shift, then up or down)
|
122 |
-
- "space + drag" to move
|
123 |
-
- "[", "]" or mouse wheel to shrink or expand range
|
124 |
-
- "ctrl + z", "shift + ctrl + z" to undo
|
125 |
-
- "
|
126 |
-
- "
|
127 |
-
- "
|
128 |
-
- "
|
129 |
-
- "
|
130 |
-
|
|
|
131 |
""")
|
132 |
|
133 |
width.change(fn=None, inputs=[width], _js="(w) => { resizeCanvas(w,null); }")
|
|
|
109 |
json = gr.JSON(label="Json")
|
110 |
jsonInput = gr.Textbox(label="Json source", lines=10)
|
111 |
jsonInputBtn = gr.Button(value="Import Json")
|
112 |
+
with gr.Accordion(label="Notes", open=False):
|
113 |
+
gr.Markdown("""
|
114 |
+
Points to note for pseudo-3D rotation: When performing pseudo-3D rotation on the X and Y axes, the projection is converted to 2D and Z-axis information is lost when the mouse button is released. This means that if you finish dragging while the shape is collapsed, you may not be able to restore it to its original state. In such a case, please use the "undo" function.
|
115 |
+
""")
|
116 |
with gr.Column(scale=2):
|
117 |
html = gr.HTML(html_text)
|
118 |
with gr.Row():
|
|
|
120 |
saveBtn = gr.Button(value="Save")
|
121 |
with gr.Column(scale=7):
|
122 |
gr.Markdown("""
|
123 |
+
- "ctrl + drag" to **scale**
|
124 |
+
- "alt + drag" to **move**
|
125 |
+
- "shift + drag" to **rotate** (move right first, release shift, then up or down)
|
126 |
+
- "space + drag" to **range-move**
|
127 |
+
- "[", "]" or mouse wheel to shrink or expand **range**
|
128 |
+
- "ctrl + z", "shift + ctrl + z" to **undo**, **redo**
|
129 |
+
- "ctrl + N" **add** new person
|
130 |
+
- "Q + click" to **delete** person
|
131 |
+
- "X + drag" to **x-axis** pseudo-3D rotation
|
132 |
+
- "C + drag" to **y-axis** pseudo-3D rotation
|
133 |
+
- "R + click" to **repair**
|
134 |
+
|
135 |
+
When using Q, X, C, R, pressing and dont release until the operation is complete.
|
136 |
""")
|
137 |
|
138 |
width.change(fn=None, inputs=[width], _js="(w) => { resizeCanvas(w,null); }")
|
static/poseEditor.js
CHANGED
@@ -2,6 +2,8 @@ console.log("hello from poseEditor.js")
|
|
2 |
var canvas = null;
|
3 |
var ctx = null;
|
4 |
|
|
|
|
|
5 |
const limbSeq = [
|
6 |
[1, 2], [2, 3], [3, 4], // 右腕
|
7 |
[1, 5], [5, 6], [6, 7], // 左腕
|
@@ -258,7 +260,7 @@ let lastWheeling = 0;
|
|
258 |
|
259 |
function drawUI() {
|
260 |
if (keyDownFlags['Space'] || keyDownFlags['BracketLeft'] || keyDownFlags['BracketRight'] ||
|
261 |
-
new Date().getTime() - lastWheeling <
|
262 |
ctx.beginPath();
|
263 |
ctx.arc(mouseCursor[0], mouseCursor[1], dragRange, 0, 2 * Math.PI);
|
264 |
ctx.strokeStyle = 'rgb(255,255,255)';
|
@@ -273,6 +275,29 @@ function drawUI() {
|
|
273 |
ctx.lineTo(dragStart[0]+rotateBaseVector[0], dragStart[1]+rotateBaseVector[1]);
|
274 |
ctx.stroke();
|
275 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
276 |
}
|
277 |
|
278 |
function Redraw() {
|
@@ -480,23 +505,25 @@ function handleMouseUp(event) {
|
|
480 |
function ModifyDragRange(delta) { dragRange = Math.max(dragRangeDelta, Math.min(512, dragRange + delta)); }
|
481 |
|
482 |
document.addEventListener('wheel', function(event) {
|
|
|
483 |
const deltaY = event.deltaY;
|
484 |
if (deltaY < 0) {ModifyDragRange(-dragRangeDelta);}
|
485 |
if (0 < deltaY) {ModifyDragRange(dragRangeDelta);}
|
486 |
lastWheeling = new Date().getTime();
|
487 |
Redraw();
|
488 |
-
window.setTimeout(function() { Redraw(); },
|
489 |
-
}, {passive:
|
490 |
|
491 |
document.addEventListener("keydown", (event) => {
|
492 |
if (event.code == "BracketLeft") { ModifyDragRange(-dragRangeDelta); }
|
493 |
if (event.code == "BracketRight") { ModifyDragRange(dragRangeDelta); }
|
494 |
keyDownFlags[event.code] = true;
|
495 |
Redraw();
|
|
|
496 |
});
|
497 |
document.addEventListener("keyup", (event) => {
|
498 |
keyDownFlags[event.code] = false;
|
499 |
-
if (event.code == "
|
500 |
addPerson();
|
501 |
}
|
502 |
if (event.ctrlKey && event.code == "KeyZ") {
|
@@ -507,6 +534,7 @@ document.addEventListener("keyup", (event) => {
|
|
507 |
}
|
508 |
}
|
509 |
Redraw();
|
|
|
510 |
});
|
511 |
|
512 |
function initializeEditor() {
|
|
|
2 |
var canvas = null;
|
3 |
var ctx = null;
|
4 |
|
5 |
+
const wheelDisplayTime = 500;
|
6 |
+
|
7 |
const limbSeq = [
|
8 |
[1, 2], [2, 3], [3, 4], // 右腕
|
9 |
[1, 5], [5, 6], [6, 7], // 左腕
|
|
|
260 |
|
261 |
function drawUI() {
|
262 |
if (keyDownFlags['Space'] || keyDownFlags['BracketLeft'] || keyDownFlags['BracketRight'] ||
|
263 |
+
new Date().getTime() - lastWheeling < wheelDisplayTime) {
|
264 |
ctx.beginPath();
|
265 |
ctx.arc(mouseCursor[0], mouseCursor[1], dragRange, 0, 2 * Math.PI);
|
266 |
ctx.strokeStyle = 'rgb(255,255,255)';
|
|
|
275 |
ctx.lineTo(dragStart[0]+rotateBaseVector[0], dragStart[1]+rotateBaseVector[1]);
|
276 |
ctx.stroke();
|
277 |
}
|
278 |
+
|
279 |
+
let operationTextFlags = {
|
280 |
+
"Space": "Range Move",
|
281 |
+
"AltLeft": "Body Move",
|
282 |
+
"AltRight": "Body Move",
|
283 |
+
"ControlLeft": "Scale",
|
284 |
+
"ControlRight": "Scale",
|
285 |
+
"ShiftLeft": "Rotate",
|
286 |
+
"ShiftRight": "Rotate",
|
287 |
+
"KeyQ": "Delete",
|
288 |
+
"KeyX": "X-Axis",
|
289 |
+
"KeyC": "Y-Axis",
|
290 |
+
"KeyR": "Repair",
|
291 |
+
}
|
292 |
+
|
293 |
+
// operationTextFlagsに含まれるものがkeyDownFlagsに含まれるばあい、そのキーの文字列を取得
|
294 |
+
let activeOperations = Object.keys(operationTextFlags).filter(key => keyDownFlags[key]);
|
295 |
+
if (activeOperations.length > 0) {
|
296 |
+
// 左上に表示
|
297 |
+
ctx.font = '20px serif';
|
298 |
+
ctx.fillStyle = 'rgb(255,255,255)';
|
299 |
+
ctx.fillText(operationTextFlags[activeOperations[0]], 10, 30);
|
300 |
+
}
|
301 |
}
|
302 |
|
303 |
function Redraw() {
|
|
|
505 |
function ModifyDragRange(delta) { dragRange = Math.max(dragRangeDelta, Math.min(512, dragRange + delta)); }
|
506 |
|
507 |
document.addEventListener('wheel', function(event) {
|
508 |
+
event.preventDefault();
|
509 |
const deltaY = event.deltaY;
|
510 |
if (deltaY < 0) {ModifyDragRange(-dragRangeDelta);}
|
511 |
if (0 < deltaY) {ModifyDragRange(dragRangeDelta);}
|
512 |
lastWheeling = new Date().getTime();
|
513 |
Redraw();
|
514 |
+
window.setTimeout(function() { Redraw(); }, wheelDisplayTime+10);
|
515 |
+
}, {passive: false});
|
516 |
|
517 |
document.addEventListener("keydown", (event) => {
|
518 |
if (event.code == "BracketLeft") { ModifyDragRange(-dragRangeDelta); }
|
519 |
if (event.code == "BracketRight") { ModifyDragRange(dragRangeDelta); }
|
520 |
keyDownFlags[event.code] = true;
|
521 |
Redraw();
|
522 |
+
event.preventDefault();
|
523 |
});
|
524 |
document.addEventListener("keyup", (event) => {
|
525 |
keyDownFlags[event.code] = false;
|
526 |
+
if (event.ctrlKey && event.code == "KeyN") {
|
527 |
addPerson();
|
528 |
}
|
529 |
if (event.ctrlKey && event.code == "KeyZ") {
|
|
|
534 |
}
|
535 |
}
|
536 |
Redraw();
|
537 |
+
event.preventDefault();
|
538 |
});
|
539 |
|
540 |
function initializeEditor() {
|