import { Canvas, useThree } from "@react-three/fiber"; import { OrbitControls,…
- User
import { Canvas, useThree } from "@react-three/fiber"; import { OrbitControls, Environment, Loader, useGLTF } from "@react-three/drei"; import * as THREE from "three"; import { useEffect, useRef } from "react"; import { MeshSurfaceSampler } from "three/examples/jsm/Addons.js";
const Particles = () => { let sampler: any; const vertices: number[] = []; const tempPosition = new THREE.Vector3();
const { scene } = useThree(); const ref = useRef<THREE.Points>(null); const gltf = useGLTF("/earth.glb");
useEffect(() => { gltf.scene.traverse((obj) => { if ((obj as THREE.Mesh).isMesh) { sampler = new MeshSurfaceSampler(obj as THREE.Mesh).build(); } }); transformMesh(); }, [gltf.scene]);
function transformMesh() { // Sample positions for points for (let i = 0; i < 5000; i++) { sampler.sample(tempPosition); vertices.push(tempPosition.x, tempPosition.y, tempPosition.z); }
code// BufferGeometry for points const pointsGeometry = new THREE.BufferGeometry(); pointsGeometry.setAttribute( "position", new THREE.Float32BufferAttribute(vertices, 3) ); // Points material const pointsMaterial = new THREE.PointsMaterial({ color: 0xffffff, size: 0.05, // blending: THREE.AdditiveBlending, transparent: true, opacity: 1, depthWrite: false, sizeAttenuation: true, alphaMap: new THREE.TextureLoader().load("/particle-texture.jpg"), }); const points = new THREE.Points(pointsGeometry, pointsMaterial); scene.add(points); if (ref.current) { ref.current.add(points); }}
return <></>; };
const World = () => { return ( <> </> ); };
export default World;
particles scaling is not work and everytime react hot reload add more particles without destroy previous
- Assistant
- User
scaling
- Assistant
- User
no no i am not talking about particles scale i am talking about model scale
- Assistant