From 410898dc8085ad88cec9e60dbf79ccc9b1383f1d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lancelot=20de=20Ferri=C3=A8re?= Date: Fri, 11 Mar 2022 15:58:28 +0100 Subject: [PATCH] Fix copy-paste issue where the raycasting didn't account for the size of the copied item --- src/FeatureFlags.ts | 4 +--- .../inputs/input_states/BuilderInputState.ts | 15 +++++++------- src/builder/inputs/input_states/CopyPaste.ts | 20 ++++++++++++------- 3 files changed, 22 insertions(+), 17 deletions(-) diff --git a/src/FeatureFlags.ts b/src/FeatureFlags.ts index 99151b9e..f4352224 100644 --- a/src/FeatureFlags.ts +++ b/src/FeatureFlags.ts @@ -4,7 +4,7 @@ import { reactive, watchEffect } from 'vue'; import { logDebug } from "./Messages"; export const featureFlags = reactive({ - briq_copy_paste: false, + briq_copy_paste: true, }); const admins = [ @@ -20,11 +20,9 @@ async function checkOnStore() { if (admins.indexOf(store?.store?.state?.wallet?.userWalletAddress) !== -1) { // Admin-only. - featureFlags.briq_copy_paste = true; } else { - featureFlags.briq_copy_paste = false; } }) }; diff --git a/src/builder/inputs/input_states/BuilderInputState.ts b/src/builder/inputs/input_states/BuilderInputState.ts index 17620954..20a84a16 100644 --- a/src/builder/inputs/input_states/BuilderInputState.ts +++ b/src/builder/inputs/input_states/BuilderInputState.ts @@ -57,20 +57,21 @@ export class MouseInputState extends BuilderInputState ] } - _getIntersectionPos(x: number, y: number, overlay = false): [number, number, number] | undefined + _getIntersectionPos(x: number, y: number, overlay = false) { let [start, end] = getCameraRay(...this.getCanvasRelativePosition(x, y)); const intersection = voxWorld.intersectRay(start, end); - if (!intersection) - return undefined; - return intersection.position.map((v, ndx) => { - return v + intersection.normal[ndx] * (overlay ? -0.5 : +0.5); - }); + return intersection; } getIntersectionPos(x: number, y: number, overlay = false): [number, number, number] | undefined { - return this._getIntersectionPos(x, y, overlay)?.map(x => Math.floor(x)); + let intersection = this._getIntersectionPos(x, y, overlay); + if (!intersection) + return undefined; + return intersection.position.map((v, ndx) => { + return Math.floor(v + intersection.normal[ndx] * (overlay ? -0.5 : +0.5)); + }); } canvasSize() { diff --git a/src/builder/inputs/input_states/CopyPaste.ts b/src/builder/inputs/input_states/CopyPaste.ts index fd340f3a..103157a1 100644 --- a/src/builder/inputs/input_states/CopyPaste.ts +++ b/src/builder/inputs/input_states/CopyPaste.ts @@ -66,11 +66,13 @@ export class CopyPasteInput extends MouseInputState { } async onPointerMove() { - let pos = this._getIntersectionPos(this.curX, this.curY); - if (!pos || pos[1] < 0) { + let intersection = this._getIntersectionPos(this.curX, this.curY); + if (!intersection) return; - } - this._specialClamp(pos); + let pos = intersection.position.map((v, ndx) => { + return v + intersection.normal[ndx] * (this.max[ndx] - this.min[ndx] + 1) / 2; + }); + pos = this._specialClamp(pos); selectionRender.parent.position.set( Math.round(pos[0] - this.selectionCenter.x), Math.round(pos[1] - this.selectionCenter.y), @@ -109,12 +111,16 @@ export class CopyPasteInput extends MouseInputState { async doPaste() { - let pos = this._getIntersectionPos(this.curX, this.curY); - if (!pos || pos[1] < 0) { + let intersection = this._getIntersectionPos(this.curX, this.curY); + if (!intersection) + { this.fsm.switchTo("inspect"); return; } - this._specialClamp(pos); + let pos = intersection.position.map((v, ndx) => { + return v + intersection.normal[ndx] * (this.max[ndx] - this.min[ndx] + 1) / 2; + }); + pos = this._specialClamp(pos); Math.round(pos[0] - this.selectionCenter.x); Math.round(pos[1] - this.selectionCenter.y); Math.round(pos[2] - this.selectionCenter.z);