JSFiddle - React, Tailwind, and code Playground

by Chrisssie

HTML

<script type="importmap">
            {
            "imports": {
              "three": "https://unpkg.com/[email protected]/build/three.module.js",
              "three/addons/": "https://unpkg.com/[email protected]/examples/jsm/"
            }
            }
        </script>
        <div id="container"></div>

CSS

body {
	margin: 0;
	background-color: #000;
	color: #fff;
	font-family: Monospace;
	font-size: 13px;
	line-height: 24px;
	overscroll-behavior: none;
}

a {
	color: #ff0;
	text-decoration: none;
}

a:hover {
	text-decoration: underline;
}

button {
	cursor: pointer;
	text-transform: uppercase;
}

#info {
	position: absolute;
	top: 0px;
	width: 100%;
	padding: 10px;
	box-sizing: border-box;
	text-align: center;
	-moz-user-select: none;
	-webkit-user-select: none;
	-ms-user-select: none;
	user-select: none;
	pointer-events: none;
	z-index: 1; /* TODO Solve this in HTML */
}

a, button, input, select {
	pointer-events: auto;
}

.lil-gui {
	z-index: 2 !important; /* TODO Solve this in HTML */
}

@media all and ( max-width: 640px ) {
	.lil-gui.root { 
		right: auto;
		top: auto;
		max-height: 50%;
		max-width: 80%;
		bottom: 0;
		left: 0;
	}
}

#overlay {
	position: absolute;
	font-size: 16px;
	z-index: 2;
	top: 0;
	left: 0;
	width: 100%;
	height: 100%;
	display: flex;
	align-items: center;
	justify-content: center;
	flex-direction: column;
	background: rgba(0,0,0,0.7);
}

	#overlay button {
		background: transparent;
		border: 0;
		border: 1px solid rgb(255, 255, 255);
		border-radius: 4px;
		color: #ffffff;
		padding: 12px 18px;
		text-transform: uppercase;
		cursor: pointer;
	}

#notSupported {
	width: 50%;
	margin: auto;
	background-color: #f00;
	margin-top: 20px;
	padding: 10px;
}

JavaScript

import * as THREE from 'three';
            import { GUI } from 'three/addons/libs/lil-gui.module.min.js';
            import { OrbitControls } from 'three/addons/controls/OrbitControls.js';
            import { SVGLoader } from 'three/addons/loaders/SVGLoader.js';

            let renderer, scene, camera, gui, guiData;

            init();

            //

            function init() {

                const container = document.getElementById( 'container' );

                //

                camera = new THREE.PerspectiveCamera( 50, window.innerWidth / window.innerHeight, 1, 1000 );
                camera.position.set( 0, 0, 200 );

                //

                renderer = new THREE.WebGLRenderer( { antialias: true } );
                renderer.setPixelRatio( window.devicePixelRatio );
                renderer.setSize( window.innerWidth, window.innerHeight );
                container.appendChild( renderer.domElement );

                //

                const controls = new OrbitControls( camera, renderer.domElement );
                controls.addEventListener( 'change', render );
                controls.screenSpacePanning = true;

                //

                window.addEventListener( 'resize', onWindowResize );

                guiData = {
                    currentURL: 'https://vielzutun.ch/wordpress/public/veins.svg',
                    drawFillShapes: true,
                    drawStrokes: true,
                    fillShapesWireframe: false,
                    strokesWireframe: false
                };

                loadSVG( guiData.currentURL );

                createGUI();

            }

            function createGUI() {

                if ( gui ) gui.destroy();

                gui = new GUI();

                gui.add( guiData, 'currentURL', {

                    'Veins': 'https://vielzutun.ch/wordpress/public/veins.svg',

                } ).name( 'SVG File' ).onChange( update );

                gui.add( guiData,...