The box is twisted using some simple math, to look like in the image. The problem is that the texture on the divisions looks distorted, like with some saw cuts.
I’m just changing points xz positions:
[edit]
It’s more visible what’s happening with less segments. It looks like the problem is happening because the mesh is made from many triangles. If it would behave like polygons with 4 vertex, I think it would work good.
It looks like the perspective texture issue, which manifests itself whenever a texture is mapped on trapezoid, or on a twisted quadrilateral. The explanation is that internally, mapping uses affine transformation, but for cases like yours you need perspective transformation.
Try with a cube with more divisions along X and Z, not only Y, as it is now. This will reduce the texture tearing to acceptable level. Here is a demo (I rewrote the code for twisting, but the rest is your code):