Rotate a texture map on only one face of a cube

Hello everyone!
I’ve got a question for you:

is there a way to rotate by 90° the texture map on only one face of an imported mtl+obj cube that comes with its own UVMap?

I mean, I can do it by cloning material in order to have a 6 identical material array, assigning to every clone a cloned texture, applying it to the cube and then rotate the wrong uvmapped cloned texture only.
I’m wondering if there’s a better way to do it cause I’ve got to do that thing lots of times.

If you’re going to ask: I can’t modify the UV on Blender before to import because I’m exporting OBJ from a little software (from a third company) we use in our company to build parametric 3D models and I’m trying to build a web viewer. I asked many times to the SW house to correct this bug but they won’t do that in a reasonable time frame.

Thank you in advance!

Instead of cloning material and textures, you could introduce a new buffer attribute that marks the respective vertices of the mentioned face. Meaning the attribute holds a simple integer value for each vertex. 0 means no rotation, 1 means applying the rotation. Or you pass in the actual rotation value per vertex.

However, this approach only works for built-in materials if you monkey-patch the shader code via Material.onBeforeCompile(). The following example demonstrates how this is done:

https://threejs.org/examples/webgl_materials_modified

Also not that this approach only works for non-indexed geometries since your faces are not allowed to share vertices. You might want to use BufferGeometry.toNonIndexed() to convert your geometry.

1 Like

Thank you @Mugen87! For this answer and for the million times you solved my problems indiectly in the past. You’re a huge contributor, I really really appreciate your work.

Let’s get deeper if you don’t mind.
So, I believe I have to study a little more threejs. Let’s just say that I don’t really know how to accomplish what you suggest me. Do you have any example to see?

I’m in this situation: I’m traversing an imported obj witch every child is called Objectxxx (where xxx is a three digit number) in order to identify, rename and apply material to every single one basing on their dimension and position. I do it by using my beloved IF CLAUSES. Now I can manipulate every children looking for them by name or material.
How can I reach the right face vertices and set a new attribute?
How can I tell to the texture “rotate if this.attribute.value = 1” ?

Sorry for my infinite ignorance.