The task is to imitate the roll of a die. On each side of a separate texture - the value of the bone. How to determine which side of the cube is on top?

Update

The problem is that I have a cube as an object. And it is impossible to determine the position of the sides of the cube.

For example:
Conventionally, we denote the sides of the cube 1-6. Cube with position:

cube.position.x=0; .position.y=0; .position.z=0;

I set the rotation of the cube:

 cube.rotation.x += 0.02; 

As a result, on top of me, I first have one side of the cube, then the other, etc. The position of the object itself remains the same 0/0/0. The task is to determine which side of the cube is "above".

As I see the solution to this problem, get the sides of a cube as an object and compare position.y.

How to get the side of the cube? Or other options ...

  • The problem is that as an object I have a cube. And it is impossible to determine the position of the sides of the cube. For example: Conventionally, we denote the sides of a cube 1-6. Cube with position - cube.position.x = 0; .position.y = 0; .position.z = 0; In ask the rotation of the cube. cube.rotation.x + = 0.02; As a result, on top of me, I first have one side of the cube, then the other, etc. The position of the object itself remains the same 0/0/0. The task is to determine which side of the cube is "above". As I see the solution to this problem, get the sides of a cube as an object and compare position.y. How to get the side of the cube? or other options ... - Vort

1 answer 1

  1. Connect the library .
  2. You can determine either by the rotation of the dice relative to world coordinates

Ready example: http://jsfiddle.net/4x3wgvvb/

Of course, the calculations can be made into a separate function, and call it once after the animation engine performs the animation.

The world mesh matrix determines the direction of the vectors for the three axes for each pair of faces.

  • I already use the library - thanks. Tops of faces - console.log (cube.geometry.faces); thank. I will read - try. - Vort
  • I try to determine by face'am, but so far there is no result. The face array is the same in different positions of the cube. There is an option to determine by the rotation attribute, but so far it is impossible to cope with the algorithm for determining the side. - Vort
  • Built a cube by hand. I asked each side a different color. I get a ray and see the color. Here's what happened: threejs.wisp.su/cubesideselect - Vort
  • for such a use raikast is generally not optimal, it is better to calculate by rotation. Updated the answer - Ni55aN