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.

How can I use GLTFLoader?

See original GitHub issue

Hi, i’m trying to load a scene

function GLTFScene({ gltfUrl }) {
  const object = useMemo(() => new GLTFLoader().load(gltfUrl), [gltfUrl])
  return (
    <>
      {
        object &&
          <primitive object={object} position={[0,0,0]}/>
      }
    </>
  )
}

and my jsx

    <div className="main" style={{ color: '#172717' }}>
      <Canvas style={{ background: '#A2CCB6', height: "100vh", width: "100hw" }} camera={{ position: [0, 0, 1000] }}>
        <ambientLight intensity={0.5} />
        <spotLight intensity={0.5} position={[300, 300, 4000]} />
        <GLTFScene gltfUrl={url} />
      </Canvas>
    </div>

And i’m getting img path error, i’ve tried to import the same gltf file in threejs editor and works fine. Anyone who has done this before can helpme. Thanks in advance

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:2
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

10reactions
dellwatsoncommented, Jan 27, 2020

Never used gltf before, but seems to work if i take out the mesh: https://codesandbox.io/s/xvvn4vxqnz

Not sure right now why it doesnt work if i just put the scene into primitive object={…}

it doesn’t work again right now, the codesandbox also shows nothing after i click.

I currently facing this problem, not sure why, im new to 3 and it doesn’t load anything, still blank with GLTFLoader

3reactions
drcmdacommented, Apr 15, 2019

From how it looks to me you load something, but there’s no callback to give you the thing that you want to load, whenever its ready. But if the fetch request itself errors out, then your path is probably wrong, too.

here’s one example using svgloader: https://codesandbox.io/s/v8439q295l?from-embed

and the docs for gltf loader: https://threejs.org/docs/index.html#examples/loaders/GLTFLoader

it says loader.load(url, callback), so maybe something like this …

const [gltf, set] = useState()
useMemo(() => new GLTFLoader().load(url, set), [url])

return gltf ? <primitive object={gltf.scene} /> : null

If i understand docs correctly, load will end up calling the “set” method with the gltf object as the first argument. And that re-renders the component.

Read more comments on GitHub >

github_iconTop Results From Across the Web

GLTFLoader – three.js docs
A loader for glTF 2.0 resources. glTF (GL Transmission Format) is an open format specification for efficient delivery and loading of 3D content....
Read more >
GLTF Model Loader - Three.js Tutorials - sbcode.net
Description. A loader for loading glTF models into the Threejs scene. glTF is a specification for the efficient transmission and loading of 3D...
Read more >
Load 3D Models in glTF Format - Discover three.js!
Once you have created a model in Blender, you can export your work using a 3D format such as glTF, then use the...
Read more >
Three.js Loading a .GLTF File
The gLTF format is actually a format designed from the ground up for be used for displaying graphics. 3D formats can be divided...
Read more >
three-gltf-loader examples - CodeSandbox
Learn how to use three-gltf-loader by viewing and forking three-gltf-loader example apps on CodeSandbox.
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