0

I'm having trouble UV mapping each side of a cube. The cube was made as a BufferGeometry where each side is a rotated copy of one side (sort of a working template) and rotated accordingly by applying a quarternion. UVs are copied as well. I'll skip any vertex coordinate I've seen before and rely on indices.

This leaves me with a total of 8 vertices and 12 faces. But I think I'm running short on vertices when I have to set all of my UVs. As obvious on the screenshot I've "correctly" mapped each side of the cube. But the top and bottom is lacking. I don't know how to set the vertex UV top and bottom faces.

Can I in some way apply several UVs on the same vertex depending on which face it is used in or have I completely lost the plot?

I could solve the problem by applying 6 PlaneBufferGeometry but that would leave me with 4*6=24 vertices. That is a whole lot more than 8.

I haven't been able to figure this one out. Either I've complete misunderstood how it works or what I'm trying to accomplish is impossible given my constraints.

enter image description here

WestLangley
  • 102,557
  • 10
  • 276
  • 276
Hoxer
  • 3
  • 4
  • I tried embedding the image directly in the post to avoid needless clicks. I couldn't figure out how or was not allowed to. Sorry for the inconvenience. – Hoxer Feb 25 '18 at 21:27

1 Answers1

3

With BufferGeometry, vertices can only be reused if all the attributes for that vertex match. Since each corner of the cube has 3 perpendicular normals, there must be 3 copies of that vertex.

If you have uvs, it is the same issue -- vertices must be duplicated if the uvs are different.

Study BoxBufferGeometry, which is implemented as "indexed-BufferGeometry".

three.js r.90

WestLangley
  • 102,557
  • 10
  • 276
  • 276
  • Thanks. As I understand the BoxBufferGeometry at least 12 vertices are needed. Removing the last 4 of the 12 in my example will not cut it. This however is still far better than the original 24 I started out. Furthermore BoxGeometry.js gives a nice insight on how to achieve my goal. – Hoxer Feb 25 '18 at 22:22
  • To add, these are referred to as "uv splits", "uv islands", "hard edges". – pailhead Feb 27 '18 at 20:44
  • You can unwrap the box into 14 uvs i believe, if you unwrap it as a cross. Still to get the proper shading of a cube you need 6 x 4 vertices, there's no way to go around it. – pailhead Feb 27 '18 at 20:45