likwifi

Hi, I'm trying to construct UV array based on vertex points however code like this shows image completely messed.
let uvs= new Array(vertices.length);
for (let i=0;i<vertices.length;i+=2) {
uvs[i]=vertices[i]/boundingBoxDx;
uvs[i+1]=vertices[i+1]/boundingBoxDy;
}
Can you please suggest the way that uvs needs to be constructed.

Best.
likwifi
  • Сообщения: 2

Nate

Note that UVs are provided by MeshAttachment.

UVs are floats in the range of 0-1, a pair for each vertex. I'm not sure exactly what you are doing, but you probably need something like:
boundingBoxDx = boundingBoxMaxX - boundingBoxMinX;
boundingBoxDy = boundingBoxMaxY - boundingBoxMinY;
for (let i=0;i<vertices.length;i+=2) {
uvs[i] = (vertices[i] - boundingBoxMinX) / boundingBoxDx;
uvs[i+1] = (vertices[i+1] - boundingBoxMinY) / boundingBoxDy;
}
Аватара пользователя
Nate

Nate
  • Сообщения: 9264


Вернуться в Runtimes