Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

disable rotation with prop #104

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
8 changes: 3 additions & 5 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} />
<OrbitControls autoRotate={!autoRotateDisabled} autoRotateSpeed={1} />
<ambientLight intensity={Math.PI / 2} />
<pointLight
position={[-10, -10, 10]}
Expand All @@ -80,9 +81,6 @@ export const CadViewerContainer = forwardRef<
borderRadius: "3px",
pointerEvents: "none",
userSelect: "none",
WebkitUserSelect: "none",
MozUserSelect: "none",
msUserSelect: "none",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why remove these lines 👀

}}
>
{hoveredComponent.name}
Expand Down
Loading