diff options
Diffstat (limited to 'public/bluebey-studio/src/clip.js')
| -rw-r--r-- | public/bluebey-studio/src/clip.js | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/public/bluebey-studio/src/clip.js b/public/bluebey-studio/src/clip.js index b5b03f4..4fdcfd9 100644 --- a/public/bluebey-studio/src/clip.js +++ b/public/bluebey-studio/src/clip.js @@ -138,16 +138,22 @@ export function createClipper({ scene, renderer, model }) { * @param {{x?:number,y?:number,z?:number}} [offset] the character's own * translation. A wall's position is stored *relative to the character*, so * adding this makes the walls travel with the body when it is moved. + * @param {number} [yaw] the character's own turn about Y, in radians. The stored + * position is rotated by it (and added to the wall's own `yaw`), so a wall + * stays glued to the body when the character is turned. * * The guide is drawn only when `wall.guide` is on, which is also when the wall * can be grabbed in the viewport. Off, the wall is invisible: the cut still * applies, so you can see the character half-hidden with nothing in the way. */ - function apply(walls, offset) { + function apply(walls, offset, yaw = 0) { const list = Array.isArray(walls) ? walls : [walls]; const ox = offset?.x ?? 0; const oy = offset?.y ?? 0; const oz = offset?.z ?? 0; + const cos = Math.cos(yaw); + const sin = Math.sin(yaw); + const yawDeg = (yaw * 180) / Math.PI; slots.forEach((slot, index) => { const wall = list[index]; if (!wall || wall.on !== true) { @@ -155,10 +161,14 @@ export function createClipper({ scene, renderer, model }) { slot.guide.visible = false; return; } - const x = (wall.x ?? 0) + ox; + // The stored position is relative to the character, so it turns with the + // body: rotate (x, z) about Y by the character's yaw, then add the offset. + const lx = wall.x ?? 0; + const lz = wall.z ?? 0; + const x = cos * lx + sin * lz + ox; const y = (wall.y ?? 0) + oy; - const z = (wall.z ?? 0) + oz; - const { normal } = wallPlane({ yaw: wall.yaw, tilt: wall.tilt, x, y, z }); + const z = -sin * lx + cos * lz + oz; + const { normal } = wallPlane({ yaw: (wall.yaw ?? 0) + yawDeg, tilt: wall.tilt, x, y, z }); slot.normal.set(normal[0], normal[1], normal[2]); const span = guideSpan * Math.max(0.05, wall.size ?? 1); // The wall and its guide are the same rectangle, turned to face along the |
