Skip to content

Commit

Permalink
Added strut length scrollwheel support to strut dragging
Browse files Browse the repository at this point in the history
  • Loading branch information
vorth committed Nov 1, 2024
1 parent 80d3c7b commit c6f87b0
Show file tree
Hide file tree
Showing 8 changed files with 72 additions and 5 deletions.
24 changes: 23 additions & 1 deletion online/src/app/classic/tools/strutdrag.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,15 @@ of TrackballControls.js and implement the transformations myself. See ObjectTra
const StrutDragTool = props =>
{
const eye = useThree(({ camera }) => camera.position);
const { startPreviewStrut, endPreviewStrut, movePreviewStrut } = useEditor();
const { startPreviewStrut, endPreviewStrut, movePreviewStrut, scalePreviewStrut } = useEditor();

const [ line, setLine ] = createSignal( [ 0, 0, 1 ] );
const [ operating, setOperating ] = createSignal( null );
const [ position, setPosition ] = createSignal( [0,0,0] );

let totalY = 0;
const MOUSE_WHEEL_TICKS_PER_SCALE = 25;

const handlers = {

allowTrackball: false,
Expand All @@ -42,9 +45,28 @@ const StrutDragTool = props =>
bkgdClick: () => {},
onDrag: evt => {},

// untested, since UnifiedTool is in use
onWheel: deltaY => {
if ( operating() ) {
// Logic copied from the desktop implementation, so we are not so sensitive.
// (See LengthCanvasTool.java)
totalY += deltaY;
let increment = 0;
if ( totalY > MOUSE_WHEEL_TICKS_PER_SCALE )
increment = +1;
else if ( totalY < -MOUSE_WHEEL_TICKS_PER_SCALE )
increment = -1;
if ( increment ) {
scalePreviewStrut( -increment ); // sense must be reversed
totalY = 0;
}
}
},

onDragStart: ( evt, id, position, type, selected ) => {
if ( type !== 'ball' )
return;
totalY = 0;
setPosition( position );
const { x, y, z } = new Vector3() .copy( eye() ) .sub( new Vector3( ...position ) ) .normalize();
setLine( [ x, y, z ] );
Expand Down
24 changes: 22 additions & 2 deletions online/src/app/classic/tools/unified.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import { useInteractionTool } from '../../../viewer/context/interaction.jsx';
import { ObjectTrackball } from './trackball.jsx';
import { VectorArrow } from './arrow.jsx';
import { subController, useEditor } from '../../framework/context/editor.jsx';
import { useSymmetry } from "../context/symmetry.jsx";

/*
This combines the behaviors of StrutDragTool and SelectionTool, to better
Expand All @@ -19,14 +18,17 @@ I'd like to reuse their code, but that seems too complicated for the benefit.
const UnifiedTool = props =>
{
const eye = useThree(({ camera }) => camera.position);
const { startPreviewStrut, endPreviewStrut, movePreviewStrut,
const { startPreviewStrut, endPreviewStrut, movePreviewStrut, scalePreviewStrut,
rootController, setState, controllerAction } = useEditor();
const pickingController = () => subController( rootController(), 'picking' );

const [ line, setLine ] = createSignal( [ 0, 0, 1 ] );
const [ operating, setOperating ] = createSignal( null );
const [ position, setPosition ] = createSignal( [0,0,0] );

let totalY = 0;
const MOUSE_WHEEL_TICKS_PER_SCALE = 25;

const handlers = {

allowTrackball: false,
Expand All @@ -44,9 +46,27 @@ const UnifiedTool = props =>
controllerAction( rootController(), 'DeselectAll' );
},

onWheel: deltaY => {
if ( operating() ) {
// Logic copied from the desktop implementation, so we are not so sensitive.
// (See LengthCanvasTool.java)
totalY += deltaY;
let increment = 0;
if ( totalY > MOUSE_WHEEL_TICKS_PER_SCALE )
increment = +1;
else if ( totalY < -MOUSE_WHEEL_TICKS_PER_SCALE )
increment = -1;
if ( increment ) {
scalePreviewStrut( -increment ); // sense must be reversed
totalY = 0;
}
}
},

onDragStart: ( evt, id, position, type, selected ) => {
if ( type !== 'ball' )
return;
totalY = 0;
setPosition( position );
const { x, y, z } = new Vector3() .copy( eye() ) .sub( new Vector3( ...position ) ) .normalize();
setLine( [ x, y, z ] );
Expand Down
1 change: 1 addition & 0 deletions online/src/app/framework/context/editor.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,7 @@ const EditorProvider = props =>
importMeshFile: ( file, format ) => workerClient .postMessage( actions.importMeshFile( file, format ) ),
startPreviewStrut: ( id, dir ) => workerClient .postMessage( actions.startPreviewStrut( id, dir ) ),
movePreviewStrut: ( direction ) => workerClient .postMessage( actions.movePreviewStrut( direction ) ),
scalePreviewStrut: ( increment ) => workerClient .postMessage( actions.scalePreviewStrut( increment ) ),
endPreviewStrut: () => workerClient .postMessage( actions.endPreviewStrut() ),
};

Expand Down
2 changes: 2 additions & 0 deletions online/src/viewer/context/interaction.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ const InteractionToolProvider = (props) =>

bkgdClick: () => tool() ?.bkgdClick(),

onWheel: dY => tool() ?.onWheel && tool() .onWheel( dY ),

onDragStart: ( e, id, position, type, selected ) => {
// Defer the onDragStart until we see sufficient movement
lastPointerDown = e;
Expand Down
13 changes: 11 additions & 2 deletions online/src/viewer/ltcanvas.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,19 @@ export const LightedTrackballCanvas = ( props ) =>
handler( e );
}
}
const handlePointerMissed = ( e ) =>
const handleWheel = ( e ) =>
{
const handler = tool ?.onWheel;
if ( handler ) {
e.preventDefault();
handler( e.deltaY );
}
}
const handlePointerMissed = ( e ) =>
{
const handler = tool ?.bkgdClick;
if ( isLeftMouseButton( e ) && handler ) {
e.stopPropagation()
e.stopPropagation();
handler( e );
}
}
Expand All @@ -130,6 +138,7 @@ export const LightedTrackballCanvas = ( props ) =>
onMount( () => {
// canvas .addEventListener( 'pointermove', handlePointerMove );
canvas .addEventListener( 'pointerup', handlePointerUp );
canvas .addEventListener( 'wheel', handleWheel );
});

return canvas;
Expand Down
2 changes: 2 additions & 0 deletions online/src/viewer/util/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ export const startPreviewStrut = ( ballId, direction ) => workerAction( 'PREVIEW

export const movePreviewStrut = ( direction ) => workerAction( 'PREVIEW_STRUT_MOVE', { direction } );

export const scalePreviewStrut = ( increment ) => workerAction( 'PREVIEW_STRUT_SCALE', { increment } );

export const endPreviewStrut = () => workerAction( 'PREVIEW_STRUT_END', {} );

// This is for buildplane
Expand Down
4 changes: 4 additions & 0 deletions online/src/worker/legacy/controllers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ const createControllers = ( design, renderingChanges, clientEvents ) =>
const [ x, y, z ] = direction;
strutBuilder .previewStrut .zoneBall .setVector( new com.vzome.core.math.RealVector( x, y, z ) );
}
wrapper.scalePreviewStrut = increment => {
const lengthController = strutBuilder .previewStrut .getLengthController();
lengthController .setScale( lengthController .getScale() + increment ); // will trigger side-effects
}
wrapper.endPreviewStrut = () =>
{
strutBuilder .previewStrut .finishPreview();
Expand Down
7 changes: 7 additions & 0 deletions online/src/worker/vzome-worker-static.js
Original file line number Diff line number Diff line change
Expand Up @@ -586,6 +586,13 @@ onmessage = ({ data }) =>
design.wrapper .movePreviewStrut( direction );
break;
}

case 'PREVIEW_STRUT_SCALE':
{
const { increment } = payload;
design.wrapper .scalePreviewStrut( increment );
break;
}

case 'PREVIEW_STRUT_END':
{
Expand Down

0 comments on commit c6f87b0

Please sign in to comment.