-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #842 from vorth/snap
Added snap behavior
- Loading branch information
Showing
19 changed files
with
160 additions
and
85 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
|
||
import { createContext, createSignal, useContext } from "solid-js"; | ||
|
||
import { controllerProperty, subController, useEditor } from "../../../viewer/context/editor.jsx"; | ||
import { useCamera } from "../../../viewer/context/camera.jsx"; | ||
import { useWorkerClient } from "../../../viewer/context/worker.jsx"; | ||
|
||
import { ShapesDialog } from "../dialogs/shapes.jsx"; | ||
import { OrbitsDialog } from "../dialogs/orbits.jsx"; | ||
import { PolytopesDialog } from "../dialogs/polytopes.jsx"; | ||
import { unwrap } from "solid-js/store"; | ||
|
||
|
||
const SymmetryContext = createContext(); | ||
|
||
export const SymmetryProvider = (props) => | ||
{ | ||
const { subscribeFor } = useWorkerClient(); | ||
const { state, setCamera } = useCamera(); | ||
const { rootController, controllerAction } = useEditor(); | ||
|
||
const symmetry = () => controllerProperty( rootController(), 'symmetry' ); | ||
const strutBuilder = () => subController( rootController(), 'strutBuilder' ); | ||
const symmController = () => subController( strutBuilder(), `symmetry.${symmetry()}` ); | ||
|
||
const [ showShapesDialog, setShowShapesDialog ] = createSignal( false ); | ||
const [ showOrbitsDialog, setShowOrbitsDialog ] = createSignal( false ); | ||
const [ showPolytopesDialog, setShowPolytopesDialog ] = createSignal( false ); | ||
|
||
const [ snapping, setSnapping ] = createSignal( false ); | ||
const snapCamera = () => | ||
{ | ||
if ( snapping() ) { | ||
const { up, lookDir } = state.camera; | ||
controllerAction( symmController(), 'snapCamera', { up: unwrap(up), lookDir: unwrap(lookDir) } ); | ||
} | ||
} | ||
|
||
const api = { | ||
snapping, snapCamera, | ||
toggleSnapping: () => setSnapping( v => !v ), | ||
symmetryDefined: () => !!symmetry(), | ||
symmetryController: () => symmController(), | ||
showShapesDialog: () => setShowShapesDialog( true ), | ||
showOrbitsDialog: () => setShowOrbitsDialog( true ), | ||
showPolytopesDialog: () => { | ||
controllerAction( subController( symmController(), 'polytopes' ), 'setQuaternion' ); | ||
setShowPolytopesDialog( true ); | ||
}, | ||
}; | ||
|
||
subscribeFor( 'CAMERA_SNAPPED', ( data ) => { | ||
const { up, lookDir } = data; | ||
setCamera( data ); | ||
}) | ||
|
||
return ( | ||
<SymmetryContext.Provider value={api}> | ||
|
||
{props.children} | ||
|
||
<Show when={!!symmetry()}> | ||
<ShapesDialog controller={symmController()} open={showShapesDialog()} close={ ()=>setShowShapesDialog(false) } /> | ||
|
||
<OrbitsDialog controller={symmController()} open={showOrbitsDialog()} close={ ()=>setShowOrbitsDialog(false) } /> | ||
|
||
<PolytopesDialog controller={symmController()} open={showPolytopesDialog()} close={ ()=>setShowPolytopesDialog(false) } /> | ||
</Show> | ||
|
||
</SymmetryContext.Provider> | ||
); | ||
} | ||
|
||
export const useSymmetry = () => useContext( SymmetryContext ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
|
||
import { onMount } from "solid-js"; | ||
|
||
import { useInteractionTool, grabTool } from "../../../viewer/context/interaction.jsx"; | ||
import { useSymmetry } from "../context/symmetry.jsx"; | ||
|
||
|
||
export const SnapCameraTool = props => | ||
{ | ||
const { snapCamera } = useSymmetry(); | ||
|
||
const [ _, setTool ] = useInteractionTool(); | ||
const cursor = 'url(rotate.svg) 9 9, url(rotate.png) 9 9, grab'; | ||
onMount( () => setTool( { ...grabTool, cursor, onTrackballEnd: snapCamera } ) ); | ||
|
||
return null; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.