How to load asset?

I was trying to load the asset via the following code, but it didn’t work.

        const loader = new THREE.GLTFLoader()
        const gltf = loader.load('./assets/piano.glb')

The error message was Error: fetch for "https://xxxxxxxxxxxxxxxxxxxxxx/assets/piano.glb" responded with 404: .

Thanks

Could you share a screenshot of your assets folder in the project? A capture of the entire editor window would be even more helpful.

Sure. Here it is.

Have you tried wrapping the path to your asset in require()? That function maps the asset name to the actual location on CDN

e.g.

const gltf = loader.load(require('./assets/piano.glb'))

You can use ecs.assets.load() as well, just pass in the asset path.

I’ll edit this comment with the docs link once we get it published.

It returns “undefined”, so it seems failed.

Thanks for your suggestion. I tried but ended up not working.

Could you give a code snippet of getting the animations attribute from loading a glb model file?

Solved by myself.

   ecs.GltfModel.set(world, component.eid, {
        animationClip: animationName,
        loop: shouldLoop,
        paused: false,
      })
1 Like

This topic was automatically closed 4 days after the last reply. New replies are no longer allowed.