JSFiddle - React, Tailwind, and code Playground
by smombartz
HTML
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>Low-Poly OK Hand</title>
<style>
body {
margin: 0;
overflow: hidden;
}
</style>
</head>
<body>
<script type="module">
// Import modules using absolute URLs from a CDN
import * as THREE from 'https://cdn.jsdelivr.net/npm/[email protected]/build/three.module.js';
import { GLTFLoader } from 'https://cdn.jsdelivr.net/npm/[email protected]/examples/jsm/loaders/GLTFLoader.js';
import { OrbitControls } from 'https://cdn.jsdelivr.net/npm/[email protected]/examples/jsm/controls/OrbitControls.js';
// Create the scene, camera, and renderer
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x202020);
const camera = new THREE.PerspectiveCamera(
60,
window.innerWidth / window.innerHeight,
0.1,
1000
);
camera.position.set(0, 1, 3);
const renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setSize(window.innerWidth, window.innerHeight);
document.body.appendChild(renderer.domElement);
// Add ambient and directional lighting
const ambientLight = new THREE.AmbientLight(0xffffff, 0.5);
scene.add(ambientLight);
const directionalLight = new THREE.DirectionalLight(0xffffff, 1);
directionalLight.position.set(5, 5, 5);
scene.add(directionalLight);
// Load the low-poly OK hand model (ensure "lowpoly_ok_hand.glb" is available)
const loader = new GLTFLoader();
loader.load(
'lowpoly_ok_hand.glb',
(gltf) => {
const handModel = gltf.scene;
// Adjust the scale and position of the model if needed
handModel.scale.set(0.5, 0.5, 0.5);
handModel.position.set(0, 0, 0);
scene.add(handModel);
},
undefined,
(error) => {
console.error('An error occurred while loading the model:', error);
...