Can we apply uScale, vScale per mesh? For example, if we want to apply the same material to two different sized meshes, we need different uv scales.
Yes.
If you don’t need to have different u and v scale you can use the scale property.
If you need more granular control, such as different orientation of texture based on whatever criteria you can also edit the UVs. Here’s a snippet:
const positions = mesh.getVerticesData(BABYLON.VertexBuffer.PositionKind);
const normals = mesh.getVerticesData(BABYLON.VertexBuffer.NormalKind);
const uvs = mesh.getVerticesData(BABYLON.VertexBuffer.UVKind);
if(!positions || ! normals || !uvs ) return;
const numberOfVertices = positions.length/3;
for(let i = 0; i < numberOfVertices; i++){
const normal = BABYLON.Vector3.FromArray(normals,i*3);
const position = BABYLON.Vector3.FromArray(positions,i*3);
position.multiplyInPlace(scaling).scaleInPlace(1/100);
if (normal.equalsWithEpsilon(BABYLON.Vector3.Left()) ||
normal.equalsWithEpsilon(BABYLON.Vector3.Right())){
uvs[i*2] = position.z
uvs[i*2+1] = position.y;
}
}
mesh.setVerticesData(BABYLON.VertexBuffer.UVKind, uvs, true);
}
1 Like