Advertisement
Guest User

Untitled

a guest
Jul 21st, 2024
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.82 KB | None | 0 0
  1. /** @jsxImportSource react */
  2. import React, { useEffect } from 'react';
  3. import { qwikify$ } from '@builder.io/qwik-react';
  4. import { GLTFLoader } from 'three/addons/loaders/GLTFLoader.js';
  5.  
  6. import * as THREE from 'three';
  7.  
  8. const ThreeJSScene = () => {
  9. useEffect(() => {
  10. const renderer = new THREE.WebGLRenderer({ antialias: true });
  11. renderer.outputColorSpace = THREE.SRGBColorSpace;
  12.  
  13. renderer.setSize(window.innerWidth, window.innerHeight);
  14. renderer.setClearColor(0x000000);
  15. renderer.setPixelRatio(window.devicePixelRatio);
  16.  
  17. document.body.appendChild(renderer.domElement);
  18.  
  19. const scene = new THREE.Scene();
  20. const camera = new THREE.PerspectiveCamera(45, window.innerWidth / window.innerHeight, 1, 1000);
  21. camera.position.set(4, 5, 11);
  22. camera.lookAt(0, 0, 0);
  23.  
  24. const groundGeometry = new THREE.PlaneGeometry(20, 20, 32, 32);
  25. groundGeometry.rotateX(-Math.PI / 2);
  26. const groundMaterial = new THREE.MeshStandardMaterial({
  27. color: 0x555555,
  28. side: THREE.DoubleSide
  29. });
  30.  
  31. const groundMesh = new THREE.Mesh(groundGeometry, groundMaterial);
  32. scene.add(groundMesh);
  33.  
  34. const spotLight = new THREE.SpotLight(0xffffff, 3000, 100, 0.2, 0.5);
  35. spotLight.position.set(0, 25, 0);
  36. scene.add(spotLight);
  37.  
  38. const loader = new GLTFLoader().setPath('frontend/public');
  39. loader.load('bane10-20.gltf', (gltf) => {
  40. const mesh = gltf.scene;
  41. mesh.position.set(0,1.05,-1);
  42. scene.add(mesh);
  43. });
  44.  
  45. function animate() {
  46. requestAnimationFrame(animate);
  47. renderer.render(scene, camera);
  48. }
  49.  
  50. animate();
  51.  
  52. return () => {
  53. // Clean up on component unmount
  54. document.body.removeChild(renderer.domElement);
  55. };
  56. }, []);
  57.  
  58. return <div />;
  59. };
  60.  
  61. export const QThreeJSScene = qwikify$(ThreeJSScene);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement