Skip to content

Cache GLTF model loads#920

Closed
JacKane21 wants to merge 1 commit into
tscircuit:mainfrom
JacKane21:codex/cache-gltf-models-93
Closed

Cache GLTF model loads#920
JacKane21 wants to merge 1 commit into
tscircuit:mainfrom
JacKane21:codex/cache-gltf-models-93

Conversation

@JacKane21
Copy link
Copy Markdown

Closes #93

/claim #93

Changes

  • Adds a shared GLTF/GLB scene cache keyed by normalized model URL, matching the existing OBJ-path idea so repeated models do not refetch/reparse.
  • Clones cached scenes per rendered instance and clones mesh materials so hover/translucency/env-map mutations do not leak across repeated parts.
  • Splits GLTF loading from isTranslucent updates, so translucency changes update materials on the loaded scene without triggering a fresh model load.
  • Disposes cloned instance materials when a model is replaced, unmounted, or finishes loading after cancellation.

Validation

  • ./node_modules/.bin/biome check src/three-components/GltfModel.tsx src/utils/gltf-model-cache.ts tests/gltf-model-cache.test.ts
  • npx --yes tsc --noEmit --pretty false
  • npx --yes bun test tests/gltf-model-cache.test.ts tests/cad-model-transform.test.ts tests/cad-model-fit.test.ts -> 17 passed
  • npm run build
  • git diff --check

Note: the local shell does not have a global bun, so I used npx --yes bun for the focused Bun tests and npm-installed tooling for build/type/format verification.

@vercel
Copy link
Copy Markdown

vercel Bot commented May 22, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
3d-viewer Ready Ready Preview, Comment May 22, 2026 6:02pm

Request Review

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 45b72930e1

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

}

export const cloneGltfSceneForInstance = (scene: THREE.Group) => {
const clonedScene = scene.clone(true)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Clone GLTF scenes with SkeletonUtils

Replace scene.clone(true) here with SkeletonUtils.clone(...) for cached instance creation. Object3D.clone does not reliably preserve bone associations for SkinnedMesh hierarchies, so rigs/animations can break or share incorrect skeleton state when the loaded GLTF contains skinned content. This only appears for GLTF assets that include skinning, but in that case repeated cached instances may render or animate incorrectly.

Useful? React with 👍 / 👎.

@JacKane21
Copy link
Copy Markdown
Author

Closing this out as part of wrapping up my bounty/OSS cleanup. Thanks for the time and review.

@JacKane21 JacKane21 closed this May 26, 2026
@JacKane21 JacKane21 deleted the codex/cache-gltf-models-93 branch May 26, 2026 04:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Improve 3d model loading to avoid laggy browser

1 participant