There’s a newer version of this floating around but it must be on another topic.
Anyways to decide what face is on rope you can do a dot product with all the face normals and the one that’s the most positive is on top.
Typically you’d calculate the normal using three vertices from each face and doing a cross product. However since it’s a cube you can get the normal from just two vertices: one one the face and one on the opposite side of the cube.
The strategy I’d go with is make a list of those two vertices for each face and put them in an array sized 6,4,1.
At(I, 1) would be the first vertex, at(I,2) would be the second. For bookkeeping you’d set at(I,3) to the face value. You’d set at(I,0) to the dot product of each pair to the ground normal. Roughly:
Dot= (v2-v1) dot vec(0,0,1)
Then you’d sort the array and the first index will be the top face.
That’s the general idea at least. It’s just busy work to work that out. Another idea would be to calculate the orientation and work out a formula to spit out the top face.