question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

react-three-fiber: manually have to set `manager.state.models[modelID]` before `createSubset` + `removeSubset` not working

See original GitHub issue

Description

In my react-three-fiber project, I have to manually set ifcManager.state.models[modelId] before making a call to ifcManager.createSubset(). I thought the createSubset method would handle this on it’s own:

const [highlightedModel, setHighlightedModel] = useState({ id: -1 });

function highlight(intersection: Intersection<IFCModel<Event>>, material: Material) {
    const { faceIndex } = intersection;
    const { modelID, geometry } = intersection.object;
    const id = manager.getExpressId(geometry, faceIndex);

    setHighlightedModel({ id: modelID });

    manager.state.models[modelID] = intersection.object;

    manager.createSubset({
      modelID,
      ids: [id],
      material,
      scene,
      removePrevious: true,
    });
  }

Without the call to manager.state.models[modelID] = intersection.object; I get the following error:

Uncaught TypeError: this.state.models[modelID] is undefined
    getGeometry ItemsMap.ts:117
    generateGeometryIndexMap ItemsMap.ts:94
    createSubset SubsetCreator.ts:79
    createSubset BasePropertyManager.ts:9
    createSubset web-ifc-three_IFCLoader.js:54214
    highlight IFCContainer.tsx:44
    handleDblClick IFCContainer.tsx:32
    handlePointer react-three-fiber.esm.js:414
    handleIntersects react-three-fiber.esm.js:289
    handlePointer react-three-fiber.esm.js:376
    connect react-three-fiber.esm.js:1465
    connect react-three-fiber.esm.js:1463
    Provider react-three-fiber.esm.js:1807
    invokePassiveEffectCreate react-reconciler.development.js:16054
    callCallback2 react-reconciler.development.js:12184
    invokeGuardedCallbackDev react-reconciler.development.js:12233
    invokeGuardedCallback react-reconciler.development.js:12292
    flushPassiveEffectsImpl react-reconciler.development.js:16141
    unstable_runWithPriority scheduler.development.js:468
    runWithPriority react-reconciler.development.js:2495
    flushPassiveEffects react-reconciler.development.js:16014
    commitBeforeMutationEffects react-reconciler.development.js:15891
    workLoop scheduler.development.js:417
    flushWork scheduler.development.js:390
    performWorkUntilDeadline scheduler.development.js:157
    js scheduler.development.js:180
    js scheduler.development.js:644
    __require2 chunk-UC7LELEO.js:48
    js index.js:6
    __require2 chunk-UC7LELEO.js:48
    React 2
    __require2 chunk-UC7LELEO.js:48
    js React
    __require2 chunk-UC7LELEO.js:48
    <anonymous> react-dom:1
ItemsMap.ts:117:9

Additionally, when I call removeSubset(modelID, highlightMaterial) visually it appears the highlight remains on the model:

  function handleDblClick(event: Intersection<IFCModel<Event>>) {
    if (Object.keys(manager.state.models).length) {
      manager.removeSubset(highlightedModel.id, highlightMaterial);
    }
    highlight(event, highlightMaterial);
  }

Steps to Reproduce

I have a repo where I reproduce this issue here.

git clone git@github.com:Amar-Gill/r3f-model-highlight-repro.git
cd r3f-model-highlight-repro/
npm i && npm run dev

Double click any mesh, it will be highlighted. Double clicking a new mesh will highlight it also, but the highlight on the previously clicked mesh will remain:

Screen Shot 2022-01-29 at 1 39 11 PM

Next, comment out the line for manager.state.models[modelID] = intersection.object; and double click a mesh. The mesh will not highlight and error will appear on console:

Uncaught TypeError: this.state.models[modelID] is undefined

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:20

github_iconTop GitHub Comments

1reaction
agviegascommented, Mar 15, 2022

This new tutorial might be relevant. 🙂

1reaction
Amar-Gillcommented, Feb 26, 2022

Correct I’m using IFCLoader from web-ifc-three. So I was talking with r3f team, and was able to use the useLoader hook from r3f package to load the load the ifc model. It seems to fix my first issue, where I need to manually set manager.state.models[modelID]. However, the removeSubset functionality is still not working. I will close this issue and make a separate issue for that.

I’ve updated my git repo to show this working. I’ll share the code here as well.

Read more comments on GitHub >

github_iconTop Results From Across the Web

v8.x.x · Discussion #2165 · pmndrs/react-three-fiber - GitHub
It's a simple, powerful, and performant state management library for React. ... PerspectiveCamera or drei/cameras, put manual on it and Fiber will not...
Read more >
Configure 3D models with react-three-fiber - LogRocket Blog
Use react-three-fiber, a React renderer for Three.js, to build and customize 3D models on the web with a less verbose workflow.
Read more >
React Three Fiber Documentation - Pmndrs.docs
React-three-fiber is a React renderer for three.js. Build your scene declaratively with re-usable, self-contained components that react to state, ...
Read more >
I wish I knew this before using React Three Fiber - YouTube
Sometimes the best way to understand a library like React Three Fiber is to compare it to the original 3D web library, Three.js....
Read more >
Building with React and Three.js using React Three Fiber
What's up, everyone! Hope you are all having a great week so far :) In this episode, we are going to work on...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found