JSFiddle - React, Tailwind, and code Playground
HTML
<script src="https://threejs.org/build/three.min.js"></script>
<script src="https://threejs.org/examples/js/controls/OrbitControls.js"></script>
<script src="https://threejs.org/examples/js/loaders/GLTFLoader.js"></script>
JavaScript
let renderer, camera, scene, orbit;
let mesh, ground, hemi, light;
let loader;
let init = () => {
const w = window.innerWidth;
const h = window.innerHeight;
renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setSize(w, h);
renderer.setClearColor(0xFFFFFF);
document.body.appendChild(renderer.domElement);
scene = new THREE.Scene()
scene.background = new THREE.Color( 0xffFFFF );
camera = new THREE.PerspectiveCamera(40, w / h, 1, 1000);
camera.position.set(0, 5, -10);
orbit = new THREE.OrbitControls(camera, renderer.domElement);
orbit.enableDamping = true;
orbit.dampingFactor = .08;
orbit.addEventListener('end', ()=> {
console.log('END')
})
orbit.addEventListener('change', ()=> {
console.log('CHANGE')
})
// LIGHTS
hemi = new THREE.HemisphereLight(0xFFFFFF, 0xFFFFFF, .5);
scene.add(hemi);
light = new THREE.SpotLight(0xFFFFFF, .3);
light.position.set(10, 10, 10);
light.castShadows = true
scene.add(light);
ground = new THREE.Mesh(new THREE.PlaneGeometry(1000, 1000), new THREE.MeshStandardMaterial({color:0xFFFFFF}));
ground.rotateX(-Math.PI / 2)
ground.receiveShadows = true;
scene.add(ground);
mesh = new THREE.Mesh(new THREE.BoxGeometry(), new THREE.MeshStandardMaterial({
color: 0x000000,
metalness: .13,
roughness: .38
}));
mesh.position.set(0, 1, 0);
mesh.castShadows = true;
mesh.receiveShadows = true;
scene.add(mesh);
// GLTF
/*
loader = new THREE.GLTFLoader();
loader.setCrossOrigin( 'anonymous' );
let url = "https://rawcdn.githack.com/BabylonJS/MeshesLibrary/55f475726670be2e7e4017b5f88c5762a90508c2/shark.glb";
loader.load(url, function (data) {
gltf = data;
let object = gltf.scene;
object.position.x = 4;
object.castShadow = true;
object.receiveShadow = true;
scene.add(object);
});
*/
}
let loop = () => {
...