JSFiddle - React, Tailwind, and code Playground
by forerun
HTML
<!-- Import maps polyfill -->
<!-- Remove this when import maps will be widely supported -->
<script async src="https://unpkg.com/es-module-shims@1.3.6/dist/es-module-shims.js"></script>
<script type="importmap">
{
"imports": {
"three": "https://unpkg.com/three@0.160.0/build/three.module.js",
"three/addons/": "https://unpkg.com/three@0.160.0/examples/jsm/"
}
}
</script>
CSS
body {
margin: 0;
overflow: hidden;
}
JavaScript
import * as THREE from 'three';
import {
OrbitControls
} from 'three/addons/controls/OrbitControls.js';
import {
GUI
} from 'three/addons/libs/lil-gui.module.min.js';
//-----------------
// --- Debug params
//-----------------
const parameters = {
textureScale: new THREE.Vector2(1, 1),
size: 1024,
repeat: 2,
margin: 24,
gap: 24,
radius: 36,
background: "#fff",
textColor: "#fff",
color1: "#444",
color2: "#666",
textScale: 1,
topLeftText: "Box Prototype",
topRightText: "1x1 Meter",
bottomLeftText: "",
bottomRightText: "1024 x 1024",
}
const parametersO = {
textureScale: new THREE.Vector2(1, 1),
size: 1024,
repeat: 2,
margin: 24,
gap: 24,
radius: 36,
background: "#fff",
textColor: "#fff",
color1: "#444",
color2: "#666",
textScale: 1,
topLeftText: "Box Prototype",
topRightText: "1x1 Meter",
bottomLeftText: "",
bottomRightText: "1024 x 1024",
}
//----------
// --- init
//----------
const camera = new THREE.PerspectiveCamera(70, window.innerWidth / window.innerHeight, 0.01, 100);
camera.position.z = 3;
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x99aaee);
const geometry = new THREE.BoxGeometry(1, 1, 1);
const material = createGridPrototypeShaderMaterial(0xFFFFFF);
updateGridTexture();
const mesh = new THREE.Mesh(geometry, material);
scene.add(mesh);
const renderer = new THREE.WebGLRenderer({
antialias: true
});
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setAnimationLoop(animation);
document.body.appendChild(renderer.domElement);
const controls = new OrbitControls(camera, renderer.domElement);
function animation(time) {
renderer.render(scene, camera);
}
window.onresize = () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
}
//-------------------
// --- Material
//-------------------
function createGridPrototypeShaderMaterial(color) {
...