<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <link rel="icon"…
- User
<title>Vite App</title> <style> *, *::after, *::before { padding: 0; margin: 0; box-sizing: border-box; } #custom-three-js { height: 500px; width: 500px; } </style> <script type="module" integrity="sha512-zTnt1Hf43YVf2to5DC6GE6cPRSC/xgPJDf3PLQussTsaDak1uHdbnWtIYnOQiL40AIa2OZfFkayQXVdzL1/DqA==" crossorigin="anonymous" referrerpolicy="no-referrer" > import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.170.0/three.module.min.js"; const container = document.getElementById("custom-three-js"); const scene = new THREE.Scene(); const camera = new THREE.PerspectiveCamera( 75, window.innerWidth / window.innerHeight, 0.1, 1000 ); const renderer = new THREE.WebGLRenderer(); renderer.setSize(window.innerWidth, window.innerHeight); renderer.setAnimationLoop(animate); document.body.appendChild(renderer.domElement); const geometry = new THREE.BoxGeometry(1, 1, 1); const material = new THREE.MeshBasicMaterial({ color: 0x00ff00 }); const cube = new THREE.Mesh(geometry, material); scene.add(cube); camera.position.z = 5; function animate() { cube.rotation.x += 0.01; cube.rotation.y += 0.01; renderer.render(scene, camera); } </script>"dont create new canvase use this canvas id="custom-three-js""
- Assistant
- User
load glb model model name is red-diamond.glb
- Assistant
- User
import { GLTFLoader } from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.170.0/examples/jsm/loaders/GLTFLoader.js"; not found
- Assistant
- User
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.170.0/three.module.min.js"; import { GLTFLoader } from "https://cdn.jsdelivr.net/npm/three@0.126.1/examples/jsm/loaders/GLTFLoader.js";
document.addEventListener("DOMContentLoaded", () => { const container = document.getElementById("custom-three-js"); const scene = new THREE.Scene(); const camera = new THREE.PerspectiveCamera( 75, container.clientWidth / container.clientHeight, 0.1, 1000 ); const renderer = new THREE.WebGLRenderer({ canvas: container }); renderer.setSize(container.clientWidth, container.clientHeight); const loader = new GLTFLoader(); loader.load( "/react/red-diamond.glb", (gltf) => { scene.add(gltf.scene); }, undefined, (error) => { console.error("An error occurred while loading the model", error); } ); const light = new THREE.AmbientLight(0x404040); // Soft white light scene.add(light); camera.position.z = 5; function animate() { requestAnimationFrame(animate); // If your model has animations or needs interaction, you'd handle it here renderer.render(scene, camera); } animate(); }); - Assistant