JSFiddle - React, Tailwind, and code Playground
CSS
body {
margin: 0;
}
canvas {
display: block;
}
JavaScript
var camera, scene, renderer;
var geometry, material, mesh, container;
import * as THREE from 'https://cdn.jsdelivr.net/npm/[email protected]/build/three.module.js';
import { OrbitControls } from 'https://cdn.jsdelivr.net/npm/[email protected]/examples/jsm/controls/OrbitControls.js';
init();
animate();
function init() {
camera = new THREE.PerspectiveCamera( 70, window.innerWidth / window.innerHeight, 0.01, 100 );
camera.position.z = 10;
camera.position.y = 5;
scene = new THREE.Scene();
scene.add(new THREE.AxisHelper(5))
geometry = new THREE.BoxBufferGeometry();
mesh = new THREE.Mesh( geometry, new THREE.MeshNormalMaterial() );
mesh.add(new THREE.AxisHelper(1))
mesh.position.set(0, 0, 3);
// scene.add( mesh );
container = new THREE.Object3D();
container.position.set(5, 0, 0);
container.add(mesh);
container.add(new THREE.AxisHelper(3))
container.rotateY(Math.PI / 4)
scene.add(container);
renderer = new THREE.WebGLRenderer( { antialias: true } );
renderer.setSize( window.innerWidth, window.innerHeight );
document.body.appendChild( renderer.domElement );
var controls = new OrbitControls( camera, renderer.domElement );
mesh.updateMatrixWorld( true );
container.updateMatrixWorld( true );
console.log(mesh.position, mesh.rotation);
let worldPosition = new THREE.Vector3();
let worldQuaternion = new THREE.Quaternion();
mesh.getWorldPosition(worldPosition);
mesh.getWorldQuaternion(worldQuaternion);
let eulerRotation = new THREE.Euler().setFromQuaternion(worldQuaternion)
console.log(worldPosition, eulerRotation);
}
function animate() {
requestAnimationFrame( animate );
renderer.render( scene, camera );
}