import * as THREE from…
- User
import * as THREE from "https://cdn.jsdelivr.net/npm/three@0.121.1/build/three.module.js"; import { GLTFLoader } from "https://cdn.jsdelivr.net/npm/three@0.121.1/examples/jsm/loaders/GLTFLoader.js";
codedocument.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, alpha: true, }); renderer.setSize(container.clientWidth, container.clientHeight); renderer.setClearColor(0x000000, 0); const loader = new GLTFLoader(); let model; // Declare a variable to store the loaded model loader.load( "/react/red-diamond.glb", (gltf) => { model = gltf.scene; // Assign the loaded scene (model) to the variable model.rotation.y = -Math.PI * 0.3; scene.add(model); }, undefined, (error) => { console.error("An error occurred while loading the model", error); } ); const light = new THREE.AmbientLight(0xffffff); // Soft white light scene.add(light); const environmentTexture = new THREE.CubeTextureLoader() .setPath("/react/env/") .load(["px.png", "nx.png", "py.png", "ny.png", "pz.png", "nz.png"]); scene.environment = environmentTexture; camera.position.z = 4; function animate() { requestAnimationFrame(animate); if (model) { model.rotation.x += 0.01; } renderer.render(scene, camera); } animate(); }); - Assistant