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.

OBJLoader doesn't work

See original GitHub issue

I tried to load an OBJ model to <primitive /> using useMemo, as in README, but it doesn’t work 😕

Repo

In the error stack trace, it says that error is dropped by react-reconciler:

TypeError: instance is undefined
    createInstance index.js:200
    completeWork react-reconciler.development.js:8883
    completeUnitOfWork react-reconciler.development.js:11125
    performUnitOfWork react-reconciler.development.js:11323
    workLoop react-reconciler.development.js:11335
    renderRoot react-reconciler.development.js:11418
    performWorkOnRoot react-reconciler.development.js:12325
    performWork react-reconciler.development.js:12237
    performSyncWork react-reconciler.development.js:12211
    requestWork react-reconciler.development.js:12080
    scheduleWork react-reconciler.development.js:11894
    scheduleRootUpdate react-reconciler.development.js:12555
    updateContainerAtExpirationTime react-reconciler.development.js:12583
    updateContainer react-reconciler.development.js:12640
    render index.js:414
    Canvas index.js:680
    React 8
    unstable_runWithPriority scheduler.development.js:255
    React 7
    dispatchAction self-hosted:1104
    _useState2 index.js:484
    broadcastActive ResizeObserver.es.js:858
    updateObservers_ ResizeObserver.es.js:317
    forEach self-hosted:266
    updateObservers_ ResizeObserver.es.js:317
    refresh ResizeObserver.es.js:292
    <anonymous> self-hosted:1001
    resolvePending ResizeObserver.es.js:164

I tried to load the model using OBJLoader from THREE:

import React, { useMemo } from 'react'
import { OBJLoader } from 'three/examples/jsm/loaders/OBJLoader'

const Model = ({ url }) => {
  const obj = useMemo(() => new OBJLoader().load(url), [url])
	return <primitive object={obj} />
}
export default Model

and then, in App.js:

import React from 'react'
import { render } from 'react-dom'
import { Canvas } from 'react-three-fiber'
import Model from '/Model'
import Controls from '/Controls'

const App = () => {
  return (
    <main>
      <Canvas>
        <Model url="C:\Users\User\Desktop\Coding\learn-threejs\demo.obj" />
        <Controls />
      </Canvas>
    </main>
  )
}
render(<App />, document.getElementById('app'))

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

6reactions
drcmdacommented, Jun 12, 2019

i think you’re passing undefined to primitive, since objloader is probably async. you can either look into reacts new suspense api (https://codesandbox.io/s/reactthreefiber-suspense-gltf-loader-vk48w) or do something like this:

function Model({ url }) {
  const [obj, set] = useState()
  useMemo(() => new OBJLoader().load(url, set), [url])
  return obj ? <primitive object={obj} /> : null
2reactions
drcmdacommented, Aug 7, 2021

this has gotten easier though, no need for useMemo/useEffect

const obj = useLoader(OBJLoader, url)
return <primitive object={obj} />
Read more comments on GitHub >

github_iconTop Results From Across the Web

OBJLoader doesn't work - Questions - three.js forum
js file in my HTML page, but I cannot seem to use OBJLoader? I downloaded the master zip, and looked in the src...
Read more >
THREE.OBJLoader not working (TypeError) - Stack Overflow
The code I used to try to load the model is here: var loader = new THREE.OBJLoader(); loader.load('3d/models/ ...
Read more >
OBJ Loader won't work - OpenGL: Basic Coding
I'm currently trying to implement my own OBJ Loader and I finally feel like I've got close to getting it working. This is...
Read more >
Three.js Loading a .OBJ File
OBJLoader2();; objLoader.load('resources/models/windmill/windmill.obj', ... OBJ files don't have material parameters. The .OBJ loader can be passed an ...
Read more >
Local .OBJ file won't render, but remote URL one does : r/threejs
When I change the URL in OBJLoader.load() to a remote URL of an .OBJ file, it does load. I would like to be...
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