1

When applying a texture to a flat GLTF model (Floor) I only get a single colour from the texture rather than the desired yellow & black stripe effect. Any help is much appreciated!

  • Could it be a UV map is required or an adjustment to the actual mesh.
  • Tried it with various repeat parameters with no luck

Texture used:

Texture Used

Example of texture applied to child within GLTF model: Texture applied to GLTF

new THREE.TextureLoader().load( textures[2], function(texture){
                    texture.flipY = false;
                    var material = new THREE.MeshBasicMaterial({map: texture});
                    child.material = material;
                });

1 Answer 1

2

When this happens it usually means there are no texture coordinates defined. It's best to check this with a tool like Blender and add add texture coordinates if necessary.

Besides, if you replace or add a color texture to a loaded glTF asset in three.js, you have to add an additional line of code:

texture.flipY = false;
texture.encoding = THREE.sRGBEncoding; // define color space
const material = new THREE.MeshBasicMaterial({map: texture});
Sign up to request clarification or add additional context in comments.

3 Comments

I generate my own glTF data procedurally (points, triangles, buffers, everything). No Blender or anything. How do I generate texture coordinates??
There is no general solution for this. You usually author texture coordinates in a tool like Blender. Otherwise you have to do it analytically but that means you need knowledge over the geometry. E.g. if you generate cubes, it's easy to generate texture coordinates. This is not true for arbitrary geometries. That usually requires a uv-unwrapping algorithm. three.js does not support such routines by default though.
Well after some digging around, it's quite easy actually. I just have to map each 3D point of the geometry to a 2D point in the texture, where the texture size is normalized to 1x1. So for example, let's say I have a triangle made of three points: (0, 0, 0), (10, 0, 0), (0, 10, 0), then a UV map could be (0, 0), (1, 0), (0, 1). I agree this is not as easy for arbitrary shapes!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.