Skip to content

Commit

Permalink
Fix copy-paste issue where the raycasting didn't account for the size…
Browse files Browse the repository at this point in the history
… of the copied item
  • Loading branch information
wraitii committed Mar 11, 2022
1 parent 08d6e2f commit 410898d
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 17 deletions.
4 changes: 1 addition & 3 deletions src/FeatureFlags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand All @@ -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;
}
})
};
Expand Down
15 changes: 8 additions & 7 deletions src/builder/inputs/input_states/BuilderInputState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
20 changes: 13 additions & 7 deletions src/builder/inputs/input_states/CopyPaste.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 410898d

Please sign in to comment.