jak spustit tento kod na pc? import { useState, useEffect } from 'react'; import {…
- User
jak spustit tento kod na pc?
import { useState, useEffect } from 'react'; import { Canvas, useThree } from '@react-three/fiber'; import { OrbitControls, Line, Text } from '@react-three/drei'; import * as THREE from 'three';
const Circle3D = ({ plane, color, numPoints, rotationAngle }) => { const points = []; for (let i = 0; i <= 64; i++) { const angle = (i / 64) * Math.PI * 2; const x = Math.cos(angle); const y = Math.sin(angle); switch (plane) { case 'XY': points.push(new THREE.Vector3(x, y, 0)); break; case 'YZ': points.push(new THREE.Vector3(0, x, y)); break; case 'XZ': points.push(new THREE.Vector3(x, 0, -y)); // Counterclockwise for XZ plane break; } }
return ( <group rotation={[ plane === 'YZ' ? rotationAngle : 0, plane === 'XZ' ? rotationAngle : 0, plane === 'XY' ? rotationAngle : 0 ]}> {/* Increased line width /} {Array.from({ length: numPoints }).map((_, index) => { const angle = (index / numPoints) * Math.PI * 2; const x = Math.cos(angle); const y = Math.sin(angle); let position; switch (plane) { case 'XY': position = [x, y, 0]; break; case 'YZ': position = [0, x, y]; break; case 'XZ': position = [x, 0, -y]; break; } return ( <sphereGeometry args={[0.05, 16, 16]} /> {/ Increased point size */} <Text position={[position[0] * 1.1, position[1] * 1.1, position[2] * 1.1]} fontSize={0.1} color={color} anchorX="center" anchorY="middle" > {index + 1} ); })} ); };
const Scene = ({ circles, lines, triangles, fillTriangles }) => { const { scene, camera } = useThree(); useEffect(() => { scene.background = new THREE.Color(0x111111); camera.position.set(5, 5, 5); // Adjusted camera position camera.lookAt(0, 0, 0); }, [scene, camera]);
const getPointOnCircle = (plane, index, totalPoints, rotationAngle) => { const angle = (index / totalPoints) * Math.PI * 2 + rotationAngle; const x = Math.cos(angle); const y = Math.sin(angle); switch (plane) { case 'XY': return new THREE.Vector3(x, y, 0); case 'YZ': return new THREE.Vector3(0, x, y); case 'XZ': return new THREE.Vector3(x, 0, -y); default: return new THREE.Vector3(0, 0, 0); } };
return ( <> <pointLight position={[10, 10, 10]} intensity={1} /> <pointLight position={[-10, -10, -10]} intensity={0.5} /> {circles.map((circle, index) => ( ))} {lines.map((line, index) => { const point1 = getPointOnCircle(circles[line[0].circle].plane, line[0].point, circles[line[0].circle].numPoints, circles[line[0].circle].rotationAngle); const point2 = getPointOnCircle(circles[line[1].circle].plane, line[1].point, circles[line[1].circle].numPoints, circles[line[1].circle].rotationAngle); return <Line key={index} points={[point1, point2]} color="#00FFFF" lineWidth={8} />; })} {triangles.map((triangle, index) => { const points = triangle.map(t => getPointOnCircle(circles[t.circle].plane, t.point, circles[t.circle].numPoints, circles[t.circle].rotationAngle)); return ( <bufferAttribute attach="attributes-position" array={new Float32Array(points.flatMap(v => [v.x, v.y, v.z]))} itemSize={3} count={3} /> <meshPhongMaterial color="#FFFF00" side={THREE.DoubleSide} transparent opacity={fillTriangles ? 0.7 : 0} /> <Line points={[...points, points[0]]} color="#FF00FF" lineWidth={4} /> ); })} </> ); };
- Assistant