threejsCube2

threejs cube using incremented time

HTML

<script src="https://min.gitcdn.link/repo/mrdoob/three.js/dev/build/three.js"></script> 
<canvas id="c"></canvas>

JavaScript

// import * as THREE from 'https://threejsfundamentals.org/threejs/resources/threejs/r132/build/three.module.js';

function main() {
  
  console.clear();
  
  
  const canvas = document.querySelector('#c');
  const renderer = new THREE.WebGLRenderer({canvas});

  const fov = 75;
  const aspect = 2;  // the canvas default
  const near = 0.1;
  const far = 5;
  const camera = new THREE.PerspectiveCamera(fov, aspect, near, far);
  camera.position.z = 2;

  const scene = new THREE.Scene();

  const boxWidth = 1;
  const boxHeight = 1;
  const boxDepth = 1;
  const geometry = new THREE.BoxGeometry(boxWidth, boxHeight, boxDepth);

  const material = new THREE.MeshBasicMaterial({color: 0x44aa88});  // greenish blue

  const cube = new THREE.Mesh(geometry, material);
  scene.add(cube);
//////////////////////////////////////////////////////////
  function render1(time) {
    
    time *= 0.001;  // convert time to seconds
    
   cube.rotation.x = time;
   cube.rotation.y = time;

 
    
    
    
    renderer.render(scene, camera);

 let animationID =   requestAnimationFrame(render1);
   // console.log(xx);
  }
  requestAnimationFrame(render1);

}

main();