2

I'm looking for the ability to pull images (from a database or wherever) and overlay these onto a THREE.Mesh (three.js) based on some user input. What I think I need to do is the following:

1) Create a new material with texture from an image and add to geometry

2) Determine the faces onto which the image will be overlaid

3) For each vertex, determine and assign the UV coordinates for the image

4) Change the materialIndex for each face to the new material

I'm just uncertain whether this will work and how to make the proper assignments to an existing Mesh. Any help would be greatly appreciated.

UPDATE

Anyone know if this is possible/easier using another library such as SceneJS?

Jeff R.
  • 371
  • 1
  • 3
  • 9

1 Answers1

2

You don't have to create a new material, only a new texture and replace the material's one. Then you need to set the UVs of the vertices you need to. Then set geometry.uvsNeedUpdate to true.

mrdoob
  • 19,334
  • 4
  • 63
  • 62
  • The number of images and the number of faces each one would cover is unknown. I start with one material for the entire model, then need to texture sections of the model as images are pulled from my server (per user request). This is why I need to add materials on the fly (I think), unless I can set multiple textures for a material. – Jeff R. Sep 13 '12 at 19:38
  • Is there a maximum number of images? – mrdoob Sep 13 '12 at 19:46
  • Ideally, there is no maximum, but let's say I go ahead and set one arbitrarily at 100 images. Is it possible if I set a limit? – Jeff R. Sep 14 '12 at 13:30
  • Ok but this still doesn't answer the question - if I have a mesh (constructor already called) - and I want to ADD a material to this mesh, how do I do this? – cybafelo Jan 22 '18 at 14:55