Jeff R.
Jeff R.

Reputation: 381

Adding materials/textures to an existing THREE.Mesh (three.js)

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?

Upvotes: 3

Views: 2857

Answers (1)

mrdoob
mrdoob

Reputation: 19602

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.

Upvotes: 2

Related Questions