Open6

【React Three Fiber】Reactで作る3D【#15Particles Stars】で演習した際の覚書き

tatsuyashinseitatsuyashinsei

https://www.youtube.com/watch?v=m6f53MtvlnU&list=PL0nRHdsrjvJgIPxe1OCizHOmOIbfBM8V8&index=15

※1:55あたりまでのコード

Geostars.tsx
import { Stars } from "@react-three/drei"

const Geostars = () => {
  return (
    <>
      <Stars />
    </>
  )
}

export default Geostars
App.tsx
import { Canvas } from "@react-three/fiber";
import { OrbitControls } from "@react-three/drei"
import GeoBox from './components/GeoBox'
import GeoText from './components/GeoText'
import GeoText3d from './components/GeoText3d'
import GeoTexture from "./components/GeoTexture";
import GeoEnv from "./components/GeoEnv";
import GeoGltf from './components/GeoGltf';
import Geostars from "./components/Geostars";

function App() {
  return (
    <div className=" w-full h-screen">
      helloooooooo
      <Canvas shadows 
      camera={{ position: [0,0,10] }}
      >
        <ambientLight intensity={0.5} />
        <directionalLight position={[0, 0, 5]} castShadow/>
        {/* <GeoBox /> */}
        {/* <GeoText /> */}
        {/* <GeoText3d /> */}
        {/* <GeoTexture/> */}
        {/* <GeoEnv /> */}
        {/* <GeoGltf /> */}
        <Geostars />
        <OrbitControls />
      </Canvas>
    </div>
  );
}

export default App;
tatsuyashinseitatsuyashinsei

※4:30あたりまでのコード(最終)

Geostars.tsx
import { Stars } from "@react-three/drei"
import { useFrame } from "@react-three/fiber"
import { useRef } from "react"
import { Group } from "three"

const Geostars = () => {
  const starRef = useRef<Group>(null!)

  useFrame(() => {
    starRef.current.rotation.y += 0.001
  })
  return (
    <>
      <group ref={starRef}>
        <Stars />
      </group>
    </>
  )
}

export default Geostars
tatsuyashinseitatsuyashinsei

所感:46歳の素人ポンコツでもこのあたりまでは難なくできる。