Spaces:
Runtime error
Runtime error
support multiple indivisuals
Browse files- static/poseEditor.js +51 -30
static/poseEditor.js
CHANGED
|
@@ -22,13 +22,16 @@ const candidateSource = [
|
|
| 22 |
[245, 148, 0.93967074],
|
| 23 |
[208, 158, 0.92053992],
|
| 24 |
[258, 154, 0.73533273]
|
| 25 |
-
|
| 26 |
-
const candidate = candidateSource.map(point => [point[0], point[1] - 70, point[2]]);
|
| 27 |
|
| 28 |
// subsetの形式:[[index1, index2, ..., -1], [index1, index2, ..., -1], ...]
|
| 29 |
-
const subset = [
|
| 30 |
-
|
| 31 |
-
];
|
|
|
|
|
|
|
|
|
|
|
|
|
| 32 |
|
| 33 |
function clearCanvas() {
|
| 34 |
var w = canvas.width;
|
|
@@ -90,7 +93,7 @@ function drawBodyPose(candidate, subset) {
|
|
| 90 |
}
|
| 91 |
}
|
| 92 |
|
| 93 |
-
function
|
| 94 |
let minDist = Infinity;
|
| 95 |
let minIndex = -1;
|
| 96 |
for (let i = 0; i < candidate.length; i++) {
|
|
@@ -100,10 +103,7 @@ function getNearestCandidateIndex(x, y) {
|
|
| 100 |
minIndex = i;
|
| 101 |
}
|
| 102 |
}
|
| 103 |
-
|
| 104 |
-
return -1;
|
| 105 |
-
}
|
| 106 |
-
return minIndex;
|
| 107 |
}
|
| 108 |
|
| 109 |
// ドラッグ中に座標を保持するための変数
|
|
@@ -112,6 +112,7 @@ let dragIndex = -1;
|
|
| 112 |
let dragStartX = 0;
|
| 113 |
let dragStartY = 0;
|
| 114 |
let draggingCandidate = null;
|
|
|
|
| 115 |
|
| 116 |
function getCanvasPosition(event) {
|
| 117 |
const rect = canvas.getBoundingClientRect();
|
|
@@ -123,15 +124,36 @@ function getCanvasPosition(event) {
|
|
| 123 |
// Canvas要素上でマウスが押された場合に呼び出される関数
|
| 124 |
function handleMouseDown(event) {
|
| 125 |
const [x, y] = getCanvasPosition(event);
|
| 126 |
-
const index =
|
| 127 |
|
| 128 |
// ドラッグ処理の開始
|
| 129 |
-
if (
|
| 130 |
isDragging = true;
|
| 131 |
dragIndex = index;
|
| 132 |
dragStartX = x;
|
| 133 |
dragStartY = y;
|
| 134 |
draggingCandidate = JSON.parse(JSON.stringify(candidate))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 135 |
}
|
| 136 |
}
|
| 137 |
|
|
@@ -146,30 +168,29 @@ function handleMouseMove(event) {
|
|
| 146 |
const dragOffsetX = x - dragStartX;
|
| 147 |
const dragOffsetY = y - dragStartY;
|
| 148 |
|
| 149 |
-
|
| 150 |
if (event.ctrlKey) {
|
|
|
|
| 151 |
let xScale = 1 + dragOffsetX / canvas.width;
|
| 152 |
let yScale = 1 + dragOffsetY / canvas.height;
|
| 153 |
-
|
| 154 |
-
candidate[
|
| 155 |
-
candidate[
|
| 156 |
-
}
|
| 157 |
} else if (event.shiftKey) {
|
| 158 |
-
//
|
| 159 |
let angle = Math.atan2(dragOffsetY, dragOffsetX);
|
| 160 |
-
|
| 161 |
-
let x = draggingCandidate[
|
| 162 |
-
let y = draggingCandidate[
|
| 163 |
-
candidate[
|
| 164 |
-
candidate[
|
| 165 |
-
}
|
| 166 |
-
|
| 167 |
} else if (event.altKey) {
|
| 168 |
-
// 全体移動
|
| 169 |
-
|
| 170 |
-
candidate[
|
| 171 |
-
candidate[
|
| 172 |
-
}
|
| 173 |
} else {
|
| 174 |
// 個別移動
|
| 175 |
candidate[dragIndex][0] = draggingCandidate[dragIndex][0] + dragOffsetX;
|
|
|
|
| 22 |
[245, 148, 0.93967074],
|
| 23 |
[208, 158, 0.92053992],
|
| 24 |
[258, 154, 0.73533273]
|
| 25 |
+
];
|
|
|
|
| 26 |
|
| 27 |
// subsetの形式:[[index1, index2, ..., -1], [index1, index2, ..., -1], ...]
|
| 28 |
+
const subset = [[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 33.81122635, 18]];
|
| 29 |
+
|
| 30 |
+
// const candidateSource = [[618.00, 0.00], [618.00, 44.00], [304.00, 81.00], [482.00, 96.00], [66.00, 270.00], [171.00, 280.00], [618.00, 82.00], [307.00, 112.00], [460.00, 143.00], [0.00, 301.00], [65.00, 301.00], [172.00, 303.00], [584.00, 86.00], [275.00, 119.00], [420.00, 139.00], [0.00, 301.00], [41.00, 301.00], [144.00, 303.00], [544.00, 131.00], [348.00, 139.00], [262.00, 160.00], [0.00, 337.00], [52.00, 339.00], [130.00, 348.00], [570.00, 175.00], [283.00, 177.00], [78.00, 338.00], [172.00, 380.00], [651.00, 78.00], [338.00, 111.00], [505.00, 144.00], [92.00, 301.00], [198.00, 305.00], [661.00, 132.00], [349.00, 156.00], [541.00, 179.00], [106.00, 336.00], [203.00, 348.00], [305.00, 159.00], [665.00, 160.00], [563.00, 192.00], [80.00, 343.00], [181.00, 385.00], [614.00, 205.00], [291.00, 220.00], [432.00, 320.00], [152.00, 372.00], [43.00, 380.00], [0.00, 386.00], [623.00, 281.00], [306.00, 290.00], [92.00, 357.00], [509.00, 434.00], [304.00, 357.00], [622.00, 368.00], [47.00, 394.00], [0.00, 395.00], [142.00, 405.00], [535.00, 565.00], [655.00, 200.00], [337.00, 217.00], [467.00, 322.00], [191.00, 372.00], [83.00, 375.00], [344.00, 282.00], [655.00, 282.00], [103.00, 343.00], [237.00, 368.00], [22.00, 377.00], [0.00, 379.00], [460.00, 459.00], [305.00, 352.00], [638.00, 355.00], [0.00, 401.00], [110.00, 412.00], [411.00, 570.00], [608.00, 0.00], [608.00, 40.00], [297.00, 75.00], [469.00, 84.00], [0.00, 261.00], [58.00, 263.00], [165.00, 275.00], [625.00, 0.00], [625.00, 39.00], [309.00, 74.00], [486.00, 83.00], [71.00, 264.00], [180.00, 276.00], [599.00, 0.00], [599.00, 44.00], [284.00, 80.00], [440.00, 93.00], [48.00, 271.00], [0.00, 272.00], [157.00, 277.00], [634.00, 0.00], [633.00, 41.00], [319.00, 77.00], [79.00, 269.00], [190.00, 277.00]];
|
| 31 |
+
// const subset = [[1.00,6.00,12.00,18.00,24.00,28.00,33.00,39.00,43.00,49.00,54.00,59.00,65.00,72.00,77.00,84.00,90.00,97.00,32.98,18.00],[5.00,11.00,17.00,23.00,27.00,32.00,37.00,42.00,46.00,-1.00,-1.00,62.00,67.00,-1.00,82.00,88.00,95.00,100.00,25.45,15.00],[4.00,10.00,16.00,22.00,26.00,31.00,36.00,41.00,47.00,51.00,57.00,63.00,66.00,74.00,81.00,87.00,93.00,99.00,26.97,18.00],[3.00,8.00,14.00,19.00,25.00,30.00,35.00,40.00,45.00,52.00,58.00,61.00,70.00,75.00,79.00,86.00,92.00,-1.00,30.45,17.00],[2.00,7.00,13.00,20.00,-1.00,29.00,34.00,38.00,44.00,50.00,53.00,60.00,64.00,71.00,78.00,85.00,91.00,98.00,27.89,17.00],[0.00,-1.00,-1.00,-1.00,-1.00,-1.00,-1.00,-1.00,-1.00,-1.00,-1.00,-1.00,-1.00,-1.00,76.00,83.00,-1.00,96.00,3.33,4.00]];
|
| 32 |
+
|
| 33 |
+
const candidate = candidateSource.map(point => [point[0], point[1] - 70]);
|
| 34 |
+
|
| 35 |
|
| 36 |
function clearCanvas() {
|
| 37 |
var w = canvas.width;
|
|
|
|
| 93 |
}
|
| 94 |
}
|
| 95 |
|
| 96 |
+
function getNearestCandidate(x, y) {
|
| 97 |
let minDist = Infinity;
|
| 98 |
let minIndex = -1;
|
| 99 |
for (let i = 0; i < candidate.length; i++) {
|
|
|
|
| 103 |
minIndex = i;
|
| 104 |
}
|
| 105 |
}
|
| 106 |
+
return [minIndex,minDist];
|
|
|
|
|
|
|
|
|
|
| 107 |
}
|
| 108 |
|
| 109 |
// ドラッグ中に座標を保持するための変数
|
|
|
|
| 112 |
let dragStartX = 0;
|
| 113 |
let dragStartY = 0;
|
| 114 |
let draggingCandidate = null;
|
| 115 |
+
let dragPersonIndex = -1;
|
| 116 |
|
| 117 |
function getCanvasPosition(event) {
|
| 118 |
const rect = canvas.getBoundingClientRect();
|
|
|
|
| 124 |
// Canvas要素上でマウスが押された場合に呼び出される関数
|
| 125 |
function handleMouseDown(event) {
|
| 126 |
const [x, y] = getCanvasPosition(event);
|
| 127 |
+
const [index, minDist] = getNearestCandidate(x, y);
|
| 128 |
|
| 129 |
// ドラッグ処理の開始
|
| 130 |
+
if (event.altKey || event.ctrlKey || event.shiftKey || minDist < 16) {
|
| 131 |
isDragging = true;
|
| 132 |
dragIndex = index;
|
| 133 |
dragStartX = x;
|
| 134 |
dragStartY = y;
|
| 135 |
draggingCandidate = JSON.parse(JSON.stringify(candidate))
|
| 136 |
+
|
| 137 |
+
// indexが含まれる人間を探す
|
| 138 |
+
for (let i = 0; i < subset.length; i++) {
|
| 139 |
+
var found = subset[i].indexOf(index);
|
| 140 |
+
if (found != -1 && found < 18) {
|
| 141 |
+
dragPersonIndex = i;
|
| 142 |
+
break;
|
| 143 |
+
}
|
| 144 |
+
}
|
| 145 |
+
}
|
| 146 |
+
}
|
| 147 |
+
|
| 148 |
+
function forEachCandidateOfPerson(personIndex, callback) {
|
| 149 |
+
if (personIndex === -1) { return; }
|
| 150 |
+
|
| 151 |
+
for (let i = 0; i < 18; i++) {
|
| 152 |
+
const index = subset[personIndex][i];
|
| 153 |
+
if (index === -1) {
|
| 154 |
+
continue;
|
| 155 |
+
}
|
| 156 |
+
callback(index);
|
| 157 |
}
|
| 158 |
}
|
| 159 |
|
|
|
|
| 168 |
const dragOffsetX = x - dragStartX;
|
| 169 |
const dragOffsetY = y - dragStartY;
|
| 170 |
|
|
|
|
| 171 |
if (event.ctrlKey) {
|
| 172 |
+
// 拡大縮小(人間ごと)
|
| 173 |
let xScale = 1 + dragOffsetX / canvas.width;
|
| 174 |
let yScale = 1 + dragOffsetY / canvas.height;
|
| 175 |
+
forEachCandidateOfPerson(dragPersonIndex, (index) => {
|
| 176 |
+
candidate[index][0] = (draggingCandidate[index][0] - dragStartX) * xScale + dragStartX;
|
| 177 |
+
candidate[index][1] = (draggingCandidate[index][1] - dragStartY) * yScale + dragStartY;
|
| 178 |
+
});
|
| 179 |
} else if (event.shiftKey) {
|
| 180 |
+
// 回転(人間ごと)
|
| 181 |
let angle = Math.atan2(dragOffsetY, dragOffsetX);
|
| 182 |
+
forEachCandidateOfPerson(dragPersonIndex, (index) => {
|
| 183 |
+
let x = draggingCandidate[index][0] - dragStartX;
|
| 184 |
+
let y = draggingCandidate[index][1] - dragStartY;
|
| 185 |
+
candidate[index][0] = x * Math.cos(angle) - y * Math.sin(angle) + dragStartX;
|
| 186 |
+
candidate[index][1] = x * Math.sin(angle) + y * Math.cos(angle) + dragStartY;
|
| 187 |
+
});
|
|
|
|
| 188 |
} else if (event.altKey) {
|
| 189 |
+
// 全体移動(人間ごと
|
| 190 |
+
forEachCandidateOfPerson(dragPersonIndex, (index) => {
|
| 191 |
+
candidate[index][0] = draggingCandidate[index][0] + dragOffsetX;
|
| 192 |
+
candidate[index][1] = draggingCandidate[index][1] + dragOffsetY;
|
| 193 |
+
});
|
| 194 |
} else {
|
| 195 |
// 個別移動
|
| 196 |
candidate[dragIndex][0] = draggingCandidate[dragIndex][0] + dragOffsetX;
|