Spaces:
Runtime error
Runtime error
add cut off
Browse files- static/poseEditor.js +35 -2
static/poseEditor.js
CHANGED
|
@@ -21,6 +21,25 @@ function findParentNodeIndex(nodeIndex) {
|
|
| 21 |
return limbIndex === -1 ? -1 : limbSeq[limbIndex][0];
|
| 22 |
}
|
| 23 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
function repairPose(sourcePose) {
|
| 25 |
// TODO: ループには対応してないかも
|
| 26 |
var pose = sourcePose;
|
|
@@ -123,6 +142,14 @@ function repairPerson(personIndex) {
|
|
| 123 |
Redraw();
|
| 124 |
}
|
| 125 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 126 |
// ドラッグ中の各キーが押されているかどうかのフラグ
|
| 127 |
var keyDownFlags = {};
|
| 128 |
// マウスカーソル
|
|
@@ -291,7 +318,8 @@ function drawUI() {
|
|
| 291 |
"ControlRight": "Scale",
|
| 292 |
"ShiftLeft": "Rotate",
|
| 293 |
"ShiftRight": "Rotate",
|
| 294 |
-
"KeyQ": "
|
|
|
|
| 295 |
"KeyX": "X-Axis",
|
| 296 |
"KeyC": "Y-Axis",
|
| 297 |
"KeyR": "Repair",
|
|
@@ -399,9 +427,14 @@ function handleMouseDown(event) {
|
|
| 399 |
const p = getCanvasPosition(event);
|
| 400 |
const [personIndex, nodeIndex, minDist] = getNearestNode(p);
|
| 401 |
|
| 402 |
-
if (keyDownFlags["
|
| 403 |
if (keyDownFlags["KeyR"]) {repairPerson(personIndex);return;}
|
| 404 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 405 |
// ドラッグ処理の開始
|
| 406 |
dragStart = p;
|
| 407 |
dragMarks = poseData.map(pose => pose.map(node => false));
|
|
|
|
| 21 |
return limbIndex === -1 ? -1 : limbSeq[limbIndex][0];
|
| 22 |
}
|
| 23 |
|
| 24 |
+
function cutOffLimb(pose, cutOffIndex) {
|
| 25 |
+
console.log(`cutOffLimb: ${cutOffIndex}`);
|
| 26 |
+
// 末端ノードの座標を削除する
|
| 27 |
+
var newPose = deepCopy(pose);
|
| 28 |
+
for (let i = 0; i < 18; i++) {
|
| 29 |
+
// ルートまで検索し、その間にcuttOffIndexがあれば削除
|
| 30 |
+
if (i == 1) {continue;} // ルートは削除しない
|
| 31 |
+
while (true) {
|
| 32 |
+
let parent = findParentNodeIndex(i);
|
| 33 |
+
if (parent === cutOffIndex) {
|
| 34 |
+
console.log(`cutOffLimb: ${i} -> ${cutOffIndex}`);
|
| 35 |
+
newPose[i] = null;
|
| 36 |
+
break;
|
| 37 |
+
}
|
| 38 |
+
}
|
| 39 |
+
}
|
| 40 |
+
return newPose;
|
| 41 |
+
}
|
| 42 |
+
|
| 43 |
function repairPose(sourcePose) {
|
| 44 |
// TODO: ループには対応してないかも
|
| 45 |
var pose = sourcePose;
|
|
|
|
| 142 |
Redraw();
|
| 143 |
}
|
| 144 |
|
| 145 |
+
function cutOffPersonLimb(personIndex, limbIndex) {
|
| 146 |
+
poseData[personIndex] = cutOffLimb(poseData[personIndex], limbIndex);
|
| 147 |
+
console.log(poseData[personIndex]);
|
| 148 |
+
console.log(poseData);
|
| 149 |
+
addHistory();
|
| 150 |
+
Redraw();
|
| 151 |
+
}
|
| 152 |
+
|
| 153 |
// ドラッグ中の各キーが押されているかどうかのフラグ
|
| 154 |
var keyDownFlags = {};
|
| 155 |
// マウスカーソル
|
|
|
|
| 318 |
"ControlRight": "Scale",
|
| 319 |
"ShiftLeft": "Rotate",
|
| 320 |
"ShiftRight": "Rotate",
|
| 321 |
+
"KeyQ": "CutOff",
|
| 322 |
+
"KeyD": "Delete",
|
| 323 |
"KeyX": "X-Axis",
|
| 324 |
"KeyC": "Y-Axis",
|
| 325 |
"KeyR": "Repair",
|
|
|
|
| 427 |
const p = getCanvasPosition(event);
|
| 428 |
const [personIndex, nodeIndex, minDist] = getNearestNode(p);
|
| 429 |
|
| 430 |
+
if (keyDownFlags["KeyD"]) {removePerson(personIndex);return;}
|
| 431 |
if (keyDownFlags["KeyR"]) {repairPerson(personIndex);return;}
|
| 432 |
|
| 433 |
+
if (keyDownFlags["KeyQ"] && minDist < 16 && nodeIndex != 1) {
|
| 434 |
+
cutOffPersonLimb(personIndex, nodeIndex);
|
| 435 |
+
return;
|
| 436 |
+
}
|
| 437 |
+
|
| 438 |
// ドラッグ処理の開始
|
| 439 |
dragStart = p;
|
| 440 |
dragMarks = poseData.map(pose => pose.map(node => false));
|