Each quadrangle is orientated in 3 dimensions (x, y, z).
2 subdivisions example:
----------- -------------
| | | | |
| | => |----- |----- |
| | | | |
----------- ------------
The scaling of each new quadrangle subdivision is simple enough:
Original Quadrangle Size / Number Subdivisions
The problem I am encountering is how to offset each one of the quadrangle subdivisions so they patch together to recreate the original texture seamlessly.
This might also appear simple but I am working in 3D and I need to take all dimensions into account:
for (int x = 0; x < numSubDivisions; ++x)
{
for (int y = 0; y < numSubDivisions; ++y)
{
for (int z = 0; z < numSubDivisions; ++z)
{
as I am subdividing quadrangle faces on a cube.
So far I have tried determining the offset based on the rotation of the quadrangle but that doesn't offset the textures correctly:
Vector3 uvOffset = new Vector3();
uvOffset.X = x * subDivSize;
uvOffset.Y = y * subDivSize;
uvOffset.Z = z * subDivSize;
tile.Faces[0].UVScaleOffset(scale, scale, Math.Abs(Vector3.Dot(uvOffset, tile.Faces[0].Rotation.Right)), Math.Abs(Vector3.Dot(uvOffset, tile.Faces[0].Rotation.Up)));
tile.Faces[1].UVScaleOffset(scale, scale, Math.Abs(Vector3.Dot(uvOffset, tile.Faces[1].Rotation.Right)), Math.Abs(Vector3.Dot(uvOffset, tile.Faces[1].Rotation.Up)));
tile.Faces[2].UVScaleOffset(scale, scale, Math.Abs(Vector3.Dot(uvOffset, tile.Faces[2].Rotation.Right)), Math.Abs(Vector3.Dot(uvOffset, tile.Faces[2].Rotation.Up)));
tile.Faces[3].UVScaleOffset(scale, scale, Math.Abs(Vector3.Dot(uvOffset, tile.Faces[3].Rotation.Right)), Math.Abs(Vector3.Dot(uvOffset, tile.Faces[3].Rotation.Up)));
tile.Faces[4].UVScaleOffset(scale, scale, Math.Abs(Vector3.Dot(uvOffset, tile.Faces[4].Rotation.Right)), Math.Abs(Vector3.Dot(uvOffset, tile.Faces[4].Rotation.Up)));
tile.Faces[5].UVScaleOffset(scale, scale, Math.Abs(Vector3.Dot(uvOffset, tile.Faces[5].Rotation.Right)), Math.Abs(Vector3.Dot(uvOffset, tile.Faces[5].Rotation.Up)));
The UVScaleOffset method is as follows:
public void UVScaleOffset(float uScale, float vScale, float uOffset, float vOffset)
{
// Always use original full range coordinates for scaling
vertices[0].TexCoordDimension.X = textureCoordinates[0].X * uScale;
vertices[0].TexCoordDimension.Y = textureCoordinates[0].Y * vScale;
vertices[1].TexCoordDimension.X = textureCoordinates[1].X * uScale;
vertices[1].TexCoordDimension.Y = textureCoordinates[1].Y * vScale;
vertices[2].TexCoordDimension.X = textureCoordinates[2].X * uScale;
vertices[2].TexCoordDimension.Y = textureCoordinates[2].Y * vScale;
vertices[3].TexCoordDimension.X = textureCoordinates[3].X * uScale;
vertices[3].TexCoordDimension.Y = textureCoordinates[3].Y * vScale;
vertices[0].TexCoordDimension.X += uOffset;
vertices[0].TexCoordDimension.Y += vOffset;
vertices[1].TexCoordDimension.X += uOffset;
vertices[1].TexCoordDimension.Y += vOffset;
vertices[2].TexCoordDimension.X += uOffset;
vertices[2].TexCoordDimension.Y += vOffset;
vertices[3].TexCoordDimension.X += uOffset;
vertices[3].TexCoordDimension.Y += vOffset;
}
Has anyone got any ideas that might help, or advice on how to approach this differently?