threepipe
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

пре 2 година
1234567891011121314151617181920212223242526272829303132333435363738394041
  1. import {_testFinish, ThreeViewer} from 'threepipe'
  2. // @ts-expect-error no need react here
  3. import React from 'react'
  4. // @ts-expect-error no need react-dom here
  5. import ReactDOM from 'react-dom'
  6. function ThreeViewerComponent({src, env}: {src: string, env: string}) {
  7. const canvasRef = React.useRef(null)
  8. React.useEffect(() => {
  9. const viewer = new ThreeViewer({canvas: canvasRef.current})
  10. // Load an environment map
  11. const envPromise = viewer.setEnvironmentMap(env)
  12. const modelPromise = viewer.load(src, {
  13. autoCenter: true,
  14. autoScale: true,
  15. })
  16. Promise.all([envPromise, modelPromise]).then(([env, model])=>{
  17. console.log('Loaded', model, env, viewer)
  18. })
  19. return () => {
  20. viewer.dispose()
  21. }
  22. }, [])
  23. return (
  24. <canvas id="three-canvas" style={{width: 800, height: 600}} ref={canvasRef} />
  25. )
  26. }
  27. async function init() {
  28. ReactDOM.render(
  29. <ThreeViewerComponent
  30. src={'https://threejs.org/examples/models/gltf/DamagedHelmet/glTF/DamagedHelmet.gltf'}
  31. env={'https://threejs.org/examples/textures/equirectangular/venice_sunset_1k.hdr'}
  32. />,
  33. document.getElementById('root')
  34. )
  35. }
  36. init().then(_testFinish)