Skip to content

Commit

Permalink
disable rotation with prop
Browse files Browse the repository at this point in the history
  • Loading branch information
chaadiic committed Jan 9, 2025
1 parent 00cc0a3 commit a1f7388
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
11 changes: 4 additions & 7 deletions src/CadViewer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,13 @@ import { Error3d } from "./three-components/Error3d"

interface Props {
soup?: AnySoupElement[]
autoRotateDisabled?: boolean
}

export const CadViewer = forwardRef<
THREE.Object3D,
React.PropsWithChildren<Props>
>(({ soup, children }, ref) => {
>(({ soup, children, autoRotateDisabled }, ref) => {
const [hoveredComponent, setHoveredComponent] = useState<null | {
cad_component_id: string
name: string
Expand All @@ -46,7 +47,7 @@ export const CadViewer = forwardRef<
const cad_components = su(soup).cad_component.list()

return (
<CadViewerContainer ref={ref} hoveredComponent={hoveredComponent}>
<CadViewerContainer ref={ref} hoveredComponent={hoveredComponent} autoRotateDisabled={autoRotateDisabled}>
{boardStls.map(({ stlUrl, color }, index) => (
<STLModel
key={stlUrl}
Expand All @@ -65,7 +66,6 @@ export const CadViewer = forwardRef<
<AnyCadComponent
key={cad_component.cad_component_id}
onHover={(e) => {
// TODO this should be done by onUnhover
if (!e) {
setHoveredComponent(null)
}
Expand All @@ -81,10 +81,7 @@ export const CadViewer = forwardRef<
})
}}
cad_component={cad_component}
isHovered={
hoveredComponent?.cad_component_id ===
cad_component.cad_component_id
}
isHovered={hoveredComponent?.cad_component_id === cad_component.cad_component_id}
/>
</ThreeErrorBoundary>
))}
Expand Down
5 changes: 3 additions & 2 deletions src/CadViewerContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,13 @@ interface Props {
name: string
mousePosition: [number, number, number]
} | null
autoRotateDisabled?: boolean
}

export const CadViewerContainer = forwardRef<
THREE.Object3D,
React.PropsWithChildren<Props>
>(({ children, hoveredComponent }, ref) => {
>(({ children, hoveredComponent, autoRotateDisabled }, ref) => {
return (
<div style={{ position: "relative", width: "100%", height: "100%" }}>
<div
Expand Down Expand Up @@ -55,7 +56,7 @@ export const CadViewerContainer = forwardRef<
camera={{ up: [0, 0, 1], position: [5, 5, 5] }}
>
<RotationTracker />
<OrbitControls autoRotate autoRotateSpeed={1} />
{!autoRotateDisabled && <OrbitControls autoRotate autoRotateSpeed={1} />}
<ambientLight intensity={Math.PI / 2} />
<pointLight
position={[-10, -10, 10]}
Expand Down

0 comments on commit a1f7388

Please sign in to comment.