JSFiddle - React, Tailwind, and code Playground

by oliverxyz

HTML

<script src="https://unpkg.com/three@0.132.2/build/three.min.js"></script>
<script src="https://unpkg.com/three@0.132.2/examples/js/loaders/GLTFLoader.js"></script>
<script src="https://unpkg.com/three@0.132.2/examples/js/loaders/DRACOLoader.js"></script>
<script src="https://unpkg.com/three@0.132.2/examples/js/controls/OrbitControls.js"></script>

<canvas id="c"></canvas>

CSS

html, body {
  margin: 0;
  padding: 0;
  border: 0;
  overflow: hidden;
}

JavaScript

window.addEventListener('load', init);

function init() {
    const width = window.innerWidth;
    const height = window.innerHeight;

    const canvasElement = document.querySelector('#c');
    const renderer = new THREE.WebGLRenderer({
        canvas: canvasElement,
    });
    renderer.setSize(width, height);

    const scene = new THREE.Scene();

    const camera = new THREE.PerspectiveCamera(75, width / height, 0.1, 10000);
    camera.position.set(0, 2, 3);

    const controls = new THREE.OrbitControls(camera, canvasElement);
    controls.screenSpacePanning = true;
    controls.enableDamping = true;
    controls.dampingFactor = 0.05;
    controls.update();
    
    const directionalLight = new THREE.DirectionalLight(0xffffff);
    directionalLight.position.set(1, 1, 1);
    scene.add(directionalLight);

    const ambientLight = new THREE.AmbientLight(0x333333);
    scene.add(ambientLight);

    const loader = new THREE.GLTFLoader();
    loader.setCrossOrigin('anonymous');

    const dracoLoader = new THREE.DRACOLoader().setDecoderPath('https://unpkg.com/three@0.132.2/examples/js/libs/draco/gltf/');
    loader.setDRACOLoader(dracoLoader);

    loader.load('https://kpxtzbymbthfmdfkhzhh.supabase.co/storage/v1/object/public/assets/d/venus.glb?t=2022-08-14T07%3A41%3A13.563Z', (gltf) => {
        const model = gltf.scene;
        scene.add(model);
    });

    animate();

    function animate() {
        renderer.render(scene, camera);
        requestAnimationFrame(animate);
        controls.update();
    }
}