Skip to content

Remove three.js types from public LoadSpec interface#405

Open
frasercl wants to merge 12 commits into
mainfrom
refactor/remove-three-types
Open

Remove three.js types from public LoadSpec interface#405
frasercl wants to merge 12 commits into
mainfrom
refactor/remove-three-types

Conversation

@frasercl
Copy link
Copy Markdown
Collaborator

@frasercl frasercl commented May 5, 2026

Review time: smallish (~15min)

Resolves #254: removes the three.js type Box3 from LoadSpec in favor of a vanilla JS variant. This has two benefits:

  • Client packages don't have to depend on three to talk to this package using this type. I believe this is the last spot where three.js types are used in the public interface, so client packages now shouldn't have to depend on three at all.
  • We don't have to recreate the Box3's prototype chain when a LoadSpec arrives from the volume load worker.

@frasercl frasercl requested a review from a team as a code owner May 5, 2026 20:01
@frasercl frasercl requested review from rugeli and toloudis and removed request for a team May 5, 2026 20:01
Comment thread src/VolumeDrawable.ts Outdated
@frasercl
Copy link
Copy Markdown
Collaborator Author

frasercl commented May 5, 2026

Might investigate the possibility of allowing Box3 to still be used in this type, otherwise merging this change will require a major version bump.

Copy link
Copy Markdown
Contributor

@toloudis toloudis left a comment

Choose a reason for hiding this comment

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

I love this change and wonder whether we have other threejs type leaks through the public api of this package

Comment thread src/loaders/IVolumeLoader.ts Outdated

import { CImageInfo, type ImageInfo } from "../ImageInfo.js";
import { LoadSpec } from "./IVolumeLoader.js";
import { LoadSpec, type Region, regionToBox3 } from "./IVolumeLoader.js";
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: is there a place that is more "math utils"-like to put the regionToBox3 and box3toRegion functions?

Copy link
Copy Markdown
Collaborator Author

@frasercl frasercl May 12, 2026

Choose a reason for hiding this comment

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

There's utils/num_utils.ts, but it seems to be geared more towards formatting numbers for display

const { loader } = getLoader(loaderId);

return await loader.createImageInfo(rebuildLoadSpec(loadSpec));
return await loader.createImageInfo(loadSpec);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

is this safe to do now because it now uses primitive types instead of the threejs classes?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Yep! All rebuildLoadSpec was doing was re-creating the Box3 to get the prototype chain back.

@toloudis
Copy link
Copy Markdown
Contributor

toloudis commented May 5, 2026

I wonder if there is some static analysis check we can do to make sure no threejs types are part of the public api...

@ShrimpCryptid
Copy link
Copy Markdown
Contributor

I love this change and wonder whether we have other threejs type leaks through the public api of this package

I think there are some exposed types (Color, Vector3, Texture) through some of the drawable objects and the colorize configuration added to vole-core.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

refactor: remove Box3 from LoadSpec

4 participants