Three.js tile which has multiple textures using plane geometry

拈花ヽ惹草 提交于 2019-12-04 10:25:13
Wilt

I think you have to take a look at what is called a multi material object.

THREE.SceneUtils.createMultiMaterialObject( geometry, materials );

If you google for those you find several examples. Like this answer on a similar question.


Or take a look at THREE.MeshFaceMaterial. You can use it to assign multiple materials for the same geometry.

var mesh = new THREE.Mesh( geometry, new THREE.MeshFaceMaterial( materials ) );

Where materials is an array of materials and the faces use a materialIndex paramater to get appointed the right material

Similar questions here and here


EDIT:

Here is a fiddle to demonstrate that it is possible. I used the code from one of the links.

vals

If your textures have all the same size, you can do the following:

  1. Create a texture 10x the size of an individual texture (you can do that automatically, create a canvas, draw the texture file on the canvas at the correct coordinates, get the texture from the canvas). This allows for 100 (10x10) textures.

  2. Assign to the tiles a base uv coordinates in the range 0 - 0.1 (since a single texture occupies 1/10th of the global texture),

  3. Add to the previous uv values the offset of the individual texture (for the second texture, offset of 0.1 in u and 0 in v, for the 3rd texture 0.2 and 0; for the 10th 0 and 0.1.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!