import * as THREE from "three"; import { GLTFLoader } from…
- User
import * as THREE from "three"; import { GLTFLoader } from "three/examples/jsm/loaders/GLTFLoader.js";
const renderer = new THREE.WebGLRenderer({ antialias: true }); renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.setSize(window.innerWidth, window.innerHeight); renderer.setClearColor(0x000000); renderer.setPixelRatio(window.devicePixelRatio);
const scene = new THREE.Scene();
const camera = new THREE.PerspectiveCamera( 45, window.innerWidth / window.innerHeight, 1, 1000 );
camera.position.set(0, 0, 0);
const groundGeometry = new THREE.PlaneGeometry(20, 20, 32, 32); groundGeometry.rotateX(-Math.PI / 2); const groundMaterial = new THREE.MeshStandardMaterial({ color: 0x555555, side: THREE.DoubleSide, }); const groundMesh = new THREE.Mesh(groundGeometry, groundMaterial); groundMesh.castShadow = false; groundMesh.receiveShadow = true; scene.add(groundMesh);
const spotLight = new THREE.SpotLight(0xffffff, 3000, 100, 0.22, 1); spotLight.position.set(0, 25, 0); spotLight.castShadow = true; spotLight.shadow.bias = -0.0001; scene.add(spotLight); export function isMeshType(object?: THREE.Object3D): object is THREE.Mesh { return object?.type === "Mesh"; } const loader = new GLTFLoader(); loader.load( "scene.gltf", (gltf) => { console.log("loading model"); const mesh = gltf.scene;
mesh.traverse((child) => { if (isMeshType(child) && child.isMesh) { child.castShadow = true; child.receiveShadow = true; } }); mesh.position.set(0, 1.05, -1); scene.add(mesh); document.getElementById("progress-container")!.style.display = "none";}, (xhr: any) => { console.log(
loading ${(xhr.loaded / xhr.total) * 100}%); }, (error: any) => { console.error(error); } ); window.addEventListener("resize", () => { camera.aspect = window.innerWidth / window.innerHeight; camera.updateProjectionMatrix(); renderer.setSize(window.innerWidth, window.innerHeight); }); Нужно чтобы в GLTFLoader был путь к папке public в которой папка d20 - Assistant
To ensure that your GLTFLoader uses the correct path to load a model from a folder called
d20inside apublicdirectory, you need to specify the path relative to where your code is served. If you're using a common setup where thepublicdirectory is served at the root of your application, you can adjust the path like this:- Ensure your
scene.gltffile is inside thepublic/d20directory.
- Ensure your
- User
</head> <body class="max-w-[1920px] flex text-white w-full bg-[#201c1c] h-full"> <header class="w-full h-20 text-[20px] flex gap-5 items-center flex-row-reverse font-bold text-center border-white"> <button class="bg-[#fe4760] p-3 rounded-[15px] hover:border-2">Войти</button> <button class="bg-[#fe4760] p-3 rounded-[15px] hover:border-2">Регистрация</button> <script src="./d20"></script> </header> <slot /> </body> - Assistant
To ensure you have the 3D object rendering on your webpage, there are several elements to check and troubleshoot:
-
JavaScript File: Ensure that the JavaScript file responsible for setting up the Three.js scene is correctly linked in your HTML. Your tag should correctly point to the JavaScript file path, for example:
-