W
W
Wasya UK2020-02-05 16:26:46
three.js
Wasya UK, 2020-02-05 16:26:46

Why is the texture not being applied to the model?

I loaded the .fbx model, but it has the path to the default textures (as I understand it). I am getting this error:

HTTP504: GATEWAY TIMEOUT — таймаут запроса в ожидании шлюза.
GET — http://localhost:3000/assets/models/texLOD1_NRM.png

HTTP504: GATEWAY TIMEOUT — таймаут запроса в ожидании шлюза.
GET — http://localhost:3000/assets/models/texMain.png

HTTP504: GATEWAY TIMEOUT — таймаут запроса в ожидании шлюза.
GET — http://localhost:3000/assets/models/tex1.png

HTTP504: GATEWAY TIMEOUT — таймаут запроса в ожидании шлюза.
GET — http://localhost:3000/assets/models/texLOD1.png

HTTP504: GATEWAY TIMEOUT — таймаут запроса в ожидании шлюза.
GET — http://localhost:3000/assets/models/tex1_NRM.png

HTTP504: GATEWAY TIMEOUT — таймаут запроса в ожидании шлюза.
GET — http://localhost:3000/assets/models/texMain_NRM.png


Wrote code for loading and replacing textures. Textures are loaded but not applied to the model. In the typescript, he writes that there are no such properties as material.needsUpdate and material.map , but in simple js this works. I had to apply @ts-ignore .
/img/tex1_DSP.png
map-component.tsx (92,1)

/img/tex1.png
map-component.tsx (92,1)

/img/texLOD1.png
map-component.tsx (92,1)

/img/texMain_DSP.png
map-component.tsx (92,1)

/img/texMain.png
map-component.tsx (92,1)

/img/texMain_NRM.png
map-component.tsx (92,1)

load texture: /img/tex1_DSP.png 1 6
map-component.tsx (89,1)

load texture: /img/tex1.png 2 6
map-component.tsx (89,1)

load texture: /img/texMain_DSP.png 3 6
map-component.tsx (89,1)

load texture: /img/texMain.png 4 6
map-component.tsx (89,1)

load texture: /img/texMain_NRM.png 5 6
map-component.tsx (89,1)

load texture: /img/texLOD1.png 6 6


How then to apply texture to fbx? Haven't found any other options yet.
const manager = new LoadingManager();
    manager.onProgress = function (item, loaded, total) {
      console.log("load texture:", item, loaded, total);
    };
    manager.setURLModifier((url: string): string => {
      console.log(url);
      return url;
    });

    const textureLoader = new TextureLoader(manager);

    const vehicleTextureMain1: THREE.Texture = textureLoader.load('/img/tex1_DSP.png');
    const vehicleTextureMain2: THREE.Texture = textureLoader.load('/img/tex1.png');
    const vehicleTextureMain3: THREE.Texture = textureLoader.load('/img/texLOD1.png');
    const vehicleTextureMain4: THREE.Texture = textureLoader.load('/img/texMain_DSP.png');
    const vehicleTextureMain5: THREE.Texture = textureLoader.load('/img/texMain.png');
    const vehicleTextureMain6: THREE.Texture = textureLoader.load('/img/texMain_NRM.png');

    const loader = new FBXLoader();
    loader.load(
      'assets/models/tesla_ct_export1123.fbx',
      (model: any) => {
        model.traverse(function(child: THREE.Mesh) {
  	      // if ( child instanceof THREE.Mesh ) {
            console.log('texture');
            // @ts-ignore
  	        child.material.map = [
              vehicleTextureMain1,
              vehicleTextureMain2,
              vehicleTextureMain3,
              vehicleTextureMain4,
              vehicleTextureMain5,
              vehicleTextureMain6
            ];
            // @ts-ignore
            child.material.needsUpdate = true;
  	      // }
  	    });
        this.scene.add(model);
      }
    );

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Robur, 2020-02-05
@Robur

in order not to write @ts-ignore, it is necessary that there are correct types. If no one wrote them for you, then you need to do it yourself.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question