index.tsx 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. import React, { Suspense, useCallback, useRef } from 'react'
  2. import styles from './index.module.scss'
  3. import { useSelector } from 'react-redux'
  4. import { RootState } from '@/store'
  5. import classNames from 'classnames'
  6. // import * as THREE from 'three'
  7. import { Canvas } from '@react-three/fiber'
  8. import Model from './Model'
  9. import A0btn from './A0btn'
  10. function A0model() {
  11. const { isShow } = useSelector((state: RootState) => state.A0model)
  12. const modelRef = useRef<any>(null)
  13. const cutModelFu = useCallback((val: string) => {
  14. if (val) {
  15. modelRef.current.focusOnPart(val)
  16. } else modelRef.current.showAllModels()
  17. }, [])
  18. return (
  19. <div
  20. style={{ backgroundImage: `url(${serverUrl}model/bac.jpg)` }}
  21. className={classNames(styles.A0model, isShow ? styles.A0modelShow : '')}
  22. >
  23. <div className='A0main'>
  24. <Canvas
  25. shadows
  26. camera={{ position: [0, 1000, 5], fov: 50 }}
  27. gl={{
  28. antialias: true, // 开启抗锯齿,使边缘更平滑
  29. alpha: true // 允许 Canvas 背景透明
  30. }}
  31. // onCreated={({ gl }) => {
  32. // gl.setClearColor(new THREE.Color(0x000000))
  33. // }}
  34. >
  35. <Suspense>
  36. {/* 场景与控制器 */}
  37. <Model ref={modelRef} />
  38. </Suspense>
  39. </Canvas>
  40. </div>
  41. <A0btn cutModelFu={val => cutModelFu(val)} />
  42. </div>
  43. )
  44. }
  45. const MemoA0model = React.memo(A0model)
  46. export default MemoA0model