uniform float u_Time; // note: do not use value of Date.now() for passing time, it somehow breaks everything - probably because the number is too big?

attribute vec3 translation; // we need translation info as attribute when cube geometries are merged together
attribute float pickingId;

varying float v_pickingId;
varying vec2 v_Uv;


const float oneTurnDurationMs = 2000.0;

void main()
{
  // no picking id = current vertex belongs to spinning info cube
  if (pickingId == 0.0)
  {
    // cube will make full turn (i.e. rotate by 360 degrees) each 2000ms
    float angle = mix (0.0, 6.28,  mod (u_Time,oneTurnDurationMs) / oneTurnDurationMs);

    // perform rotation
    float cosAngle = cos (angle);
    float sinAngle = sin (angle);

    // rotation on y-axis
    mat4 rotation = mat4(
    cosAngle, 0, sinAngle, 0,
    0, 1, 0, 0,
    -sinAngle, 0, cosAngle, 0,
    0, 0, 0, 1
    );

    // account for cube's translation
    mat4 translationForRotation = mat4(
    1, 0, 0, 0,
    0, 1, 0, 0,
    0, 0, 1, 0,
    translation.x, translation.y, translation.z, 1
    );

      // x axis
  //        mat4 rot = mat4 (
  //        1, 0, 0, 0,
  //        0, cos (angle), -sin (angle), 0,
  //        0, sin (angle), cos (angle), 0,
  //        0, 0, 0, 1
  //        );

    // compose final rotation matrix for the cube
    mat4 finalRotation = translationForRotation * rotation;

    gl_Position =  projectionMatrix * modelViewMatrix * finalRotation * vec4(position,1.0);
  }
  // some picking id = current vertex belongs to static info cube
  else
  {
    gl_Position =  projectionMatrix * modelViewMatrix * vec4(position,1.0);
  }

  v_pickingId = pickingId;
  v_Uv = uv;
}