Skip to content
Merged
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
4 changes: 2 additions & 2 deletions apps/storybook/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"react": "18.3.1",
"react-dom": "18.3.1",
"react-icons": "5.4.0",
"three": "0.182.0"
"three": "0.185.1"
},
"devDependencies": {
"@esrf/eslint-config": "2.3.1",
Expand All @@ -37,7 +37,7 @@
"@types/node": "^24.13.2",
"@types/react": "^18.3.31",
"@types/react-dom": "^18.3.7",
"@types/three": "0.183.1",
"@types/three": "0.185.3",
"eslint": "9.39.4",
"remark-gfm": "4.0.1",
"storybook": "10.4.6",
Expand Down
2 changes: 1 addition & 1 deletion apps/storybook/src/GettingStarted.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { Meta } from '@storybook/addon-docs/blocks';
1. Install the library and its peer dependencies:

```bash
npm install @h5web/lib "three<=0.182" @react-three/fiber@8
npm install @h5web/lib three @react-three/fiber@8
```

1. Install `ndarray` and, if you use TypeScript, its types package:
Expand Down
2 changes: 1 addition & 1 deletion packages/app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
"react-error-boundary": "6.1.2",
"react-icons": "5.4.0",
"react-resizable-panels": "4.12.0",
"three": "0.182.0",
"three": "0.185.1",
"zustand": "5.0.14"
},
"devDependencies": {
Expand Down
7 changes: 6 additions & 1 deletion packages/app/src/setupTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,12 @@ vi.mock(import('./providers/mock/utils'), { spy: true });

enableBigIntSerialization();

failOnConsole();
failOnConsole({

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

We have to ignore this deprecation warning since it is only fixed in R3F v10: pmndrs/react-three-fiber#3741

silenceMessage: (message) =>
message.includes(
'THREE.Clock: This module has been deprecated. Please use THREE.Timer instead.',
),
});

beforeEach(() => {
localStorage.clear();
Expand Down
3 changes: 1 addition & 2 deletions packages/lib/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,9 @@ separate `@types/` package.
>
> - React v18.*
> - React-three-fiber v8.*
> - three <= v0.182

```bash
npm install @h5web/lib "three<=0.182" @react-three/fiber@8 ndarray
npm install @h5web/lib three @react-three/fiber@8 ndarray
```

```tsx
Expand Down
8 changes: 4 additions & 4 deletions packages/lib/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@
"@react-three/fiber": "8.x",
"@types/react": "18.x",
"@types/react-dom": "18.x",
"@types/three": ">=0.138 <=0.182",
"@types/three": ">=0.138",
"react": "18.x",
"react-dom": "18.x",
"three": ">=0.138 <=0.182",
"three": ">=0.138",
"typescript": ">=4.5"
},
"peerDependenciesMeta": {
Expand Down Expand Up @@ -93,15 +93,15 @@
"@types/node": "^24.13.2",
"@types/react": "^18.3.31",
"@types/react-dom": "^18.3.7",
"@types/three": "0.183.1",
"@types/three": "0.185.3",
"@vitejs/plugin-react": "6.0.3",
"dot-json": "1.3.0",
"eslint": "9.39.4",
"react": "18.3.1",
"react-dom": "18.3.1",
"rollup": "4.62.2",
"rollup-plugin-dts": "6.4.1",
"three": "0.182.0",
"three": "0.185.1",
"typescript": "5.9.3",
"vite": "8.1.2",
"vite-css-modules": "1.16.0",
Expand Down
17 changes: 5 additions & 12 deletions packages/lib/src/vis/shared/R3FCanvas.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Canvas } from '@react-three/fiber';
import { type PropsWithChildren } from 'react';
import { type PropsWithChildren, useMemo } from 'react';

import { CAMERA_FAR, CAMERA_NEAR, CAMERA_Z } from '../utils';
import { ScaledOrthographicCamera } from './ScaledOrthographicCamera';

interface Props {
className?: string;
Expand All @@ -11,6 +11,8 @@ interface Props {
function R3FCanvas(props: PropsWithChildren<Props>) {
const { className, orthographic, children } = props;

const camera = useMemo(() => new ScaledOrthographicCamera(), []);

return (
<Canvas
className={className}
Expand All @@ -20,16 +22,7 @@ function R3FCanvas(props: PropsWithChildren<Props>) {
dpr={[1, 3]} // https://discoverthreejs.com/tips-and-tricks/#performance
resize={{ debounce: { scroll: 20, resize: 200 }, scroll: false }} // https://github.com/pmndrs/react-three-fiber/discussions/1906
gl={{ preserveDrawingBuffer: true }} // for "Save Image As..." and snapshot feature to work
camera={
orthographic
? {
// Customize visible `z` range: https://github.com/silx-kit/h5web/issues/1626
near: CAMERA_NEAR,
far: CAMERA_FAR,
position: [0, 0, CAMERA_Z],
}
: undefined
}
camera={orthographic ? camera : undefined}
>
<ambientLight />
{children}
Expand Down
29 changes: 29 additions & 0 deletions packages/lib/src/vis/shared/ScaledOrthographicCamera.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { OrthographicCamera } from 'three';

import { CAMERA_FAR, CAMERA_NEAR, CAMERA_Z } from '../utils';

export class ScaledOrthographicCamera extends OrthographicCamera {
/* An OrthographicCamera that keeps the scale in matrixWorldInverse (removed in three@0.183) */
public constructor() {
super();
// Customize visible `z` range: https://github.com/silx-kit/h5web/issues/1626
this.near = CAMERA_NEAR;
this.far = CAMERA_FAR;
this.translateZ(CAMERA_Z);
}

// https://github.com/mrdoob/three.js/pull/32805/changes
public override updateMatrixWorld(force?: boolean): void {
super.updateMatrixWorld(force);
this.matrixWorldInverse.copy(this.matrixWorld).invert();
}

// https://github.com/mrdoob/three.js/pull/32805/changes
public override updateWorldMatrix(
updateParents: boolean,
updateChildren: boolean,
): void {
super.updateWorldMatrix(updateParents, updateChildren);
this.matrixWorldInverse.copy(this.matrixWorld).invert();
}
}
Loading