Spaces:
Runtime error
Runtime error
fix renderer
Browse files- static/poseEditor.js +19 -13
static/poseEditor.js
CHANGED
@@ -249,48 +249,54 @@ function rotateAndProject(f, p, c, angle) {
|
|
249 |
}
|
250 |
|
251 |
function drawBodyPose() {
|
252 |
-
|
|
|
|
|
253 |
|
254 |
const colors = [[255, 0, 0], [255, 85, 0], [255, 170, 0], [255, 255, 0], [170, 255, 0], [85, 255, 0], [0, 255, 0],
|
255 |
[0, 255, 85], [0, 255, 170], [0, 255, 255], [0, 170, 255], [0, 85, 255], [0, 0, 255], [85, 0, 255],
|
256 |
[170, 0, 255], [255, 0, 255], [255, 0, 170], [255, 0, 85]];
|
257 |
|
258 |
-
ctx.globalAlpha = 0.
|
259 |
|
|
|
260 |
for (let i = 0; i < poseData.length; i++) {
|
261 |
const pose = poseData[i];
|
262 |
|
263 |
-
// edge
|
264 |
for (let j = 0; j < 17; j++) {
|
265 |
const p = pose[limbSeq[j][0]];
|
266 |
const q = pose[limbSeq[j][1]];
|
267 |
if (p == null || q == null) continue;
|
268 |
const [X0, Y0] = p;
|
269 |
const [X1, Y1] = q;
|
270 |
-
|
271 |
-
|
272 |
-
|
273 |
-
|
274 |
-
ctx.
|
275 |
-
ctx.
|
276 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
277 |
|
278 |
-
// node
|
279 |
ctx.font = '12px serif';
|
280 |
for (let j = 0; j < 18; j++) {
|
281 |
const p = pose[j];
|
282 |
if (p == null) continue;
|
283 |
const [x, y] = p;
|
284 |
ctx.beginPath();
|
285 |
-
ctx.arc(x, y, stickWidth
|
286 |
ctx.fillStyle = `rgb(${colors[j].join(',')})`;
|
287 |
ctx.fill();
|
288 |
// ctx.fillStyle = 'rgb(255,255,255)'
|
289 |
// ctx.fillText(j, x-3, y+4);
|
290 |
}
|
291 |
}
|
292 |
-
|
293 |
-
ctx.globalAlpha = 1.0;
|
294 |
}
|
295 |
|
296 |
let lastWheeling = 0;
|
|
|
249 |
}
|
250 |
|
251 |
function drawBodyPose() {
|
252 |
+
let stickWidth = 4;
|
253 |
+
let imageSize = Math.min(canvas.width, canvas.height);
|
254 |
+
stickWidth *= imageSize / 512;
|
255 |
|
256 |
const colors = [[255, 0, 0], [255, 85, 0], [255, 170, 0], [255, 255, 0], [170, 255, 0], [85, 255, 0], [0, 255, 0],
|
257 |
[0, 255, 85], [0, 255, 170], [0, 255, 255], [0, 170, 255], [0, 85, 255], [0, 0, 255], [85, 0, 255],
|
258 |
[170, 0, 255], [255, 0, 255], [255, 0, 170], [255, 0, 85]];
|
259 |
|
260 |
+
ctx.globalAlpha = 0.6;
|
261 |
|
262 |
+
// edge
|
263 |
for (let i = 0; i < poseData.length; i++) {
|
264 |
const pose = poseData[i];
|
265 |
|
|
|
266 |
for (let j = 0; j < 17; j++) {
|
267 |
const p = pose[limbSeq[j][0]];
|
268 |
const q = pose[limbSeq[j][1]];
|
269 |
if (p == null || q == null) continue;
|
270 |
const [X0, Y0] = p;
|
271 |
const [X1, Y1] = q;
|
272 |
+
let angle = Math.atan2(Y1 - Y0, X1 - X0);
|
273 |
+
let magnitude = ((X0 - X1) ** 2 + (Y0 - Y1) ** 2) ** 0.5
|
274 |
+
let polygon = new Path2D();
|
275 |
+
polygon.ellipse((X0+X1)/2, (Y0+Y1)/2, magnitude / 2, stickWidth, angle, 0, 2 * Math.PI);
|
276 |
+
ctx.fillStyle = `rgb(${colors[j].join(',')})`;
|
277 |
+
ctx.fill(polygon);
|
278 |
}
|
279 |
+
}
|
280 |
+
|
281 |
+
ctx.globalAlpha = 1.0;
|
282 |
+
|
283 |
+
// node
|
284 |
+
for (let i = 0; i < poseData.length; i++) {
|
285 |
+
const pose = poseData[i];
|
286 |
|
|
|
287 |
ctx.font = '12px serif';
|
288 |
for (let j = 0; j < 18; j++) {
|
289 |
const p = pose[j];
|
290 |
if (p == null) continue;
|
291 |
const [x, y] = p;
|
292 |
ctx.beginPath();
|
293 |
+
ctx.arc(x, y, stickWidth, 0, 2 * Math.PI);
|
294 |
ctx.fillStyle = `rgb(${colors[j].join(',')})`;
|
295 |
ctx.fill();
|
296 |
// ctx.fillStyle = 'rgb(255,255,255)'
|
297 |
// ctx.fillText(j, x-3, y+4);
|
298 |
}
|
299 |
}
|
|
|
|
|
300 |
}
|
301 |
|
302 |
let lastWheeling = 0;
|