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(); 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(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 = 5; const geometry = new THREE.BoxGeometry(1, 1, 1); const material = new THREE.MeshStandardMaterial({ color: 0x00ff00 }); const cube = new THREE.Mesh(geometry, material); scene.add(cube); function animate() { requestAnimationFrame(animate); cube.rotation.x += 0.01; cube.rotation.y += 0.01; // If your model has animations or needs interaction, you'd handle it here renderer.render(scene, camera); } animate(); }); - Assistant