JSFiddle - React, Tailwind, and code Playground
JavaScript
import * as THREE from 'https://cdn.skypack.dev/[email protected]/build/three.module.js';
let camera, scene, renderer;
let group, box3;
init();
animate();
function init() {
camera = new THREE.PerspectiveCamera( 70, window.innerWidth / window.innerHeight, 0.01, 10 );
camera.position.z = 6;
scene = new THREE.Scene();
group = new THREE.Group();
const geometry = new THREE.BoxGeometry();
const mesh1 = new THREE.Mesh( geometry, new THREE.MeshBasicMaterial( { color: 'red' } ) );
mesh1.position.x = 1;
group.add( mesh1 );
const mesh2 = new THREE.Mesh( geometry, new THREE.MeshBasicMaterial( { color: 'blue' } ) );
mesh2.position.x = - 1;
group.add( mesh2 );
scene.add( group );
box3 = new THREE.Box3().setFromObject( group );
const helper = new THREE.Box3Helper( box3 );
scene.add( helper );
renderer = new THREE.WebGLRenderer( { antialias: true } );
renderer.setSize( window.innerWidth, window.innerHeight );
document.body.appendChild( renderer.domElement );
}
function animate() {
requestAnimationFrame( animate );
group.rotation.x += 0.01;
group.rotation.y += 0.02;
box3.setFromObject( group );
renderer.render( scene, camera );
}