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.

index.html 2.0KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>Threepipe React/JSX Sample</title>
  6. <style>
  7. html, body{
  8. width: 100%;
  9. height: 100%;
  10. margin: 0;
  11. overflow: hidden;
  12. }
  13. </style>
  14. <script type="module" src="../examples-utils/simple-code-preview.mjs"></script>
  15. <!-- Include Babel for JSX transformation -->
  16. <script src="https://unpkg.com/@babel/standalone/babel.min.js"></script>
  17. </head>
  18. <body>
  19. <div id="root"></div>
  20. <script id="example-script" type="text/babel" data-scripts="./index.html" data-type="module">
  21. // import {ThreeViewer, LoadingScreenPlugin} from 'https://unpkg.com/threepipe@latest/dist/index.mjs'
  22. import {ThreeViewer, LoadingScreenPlugin} from './../../dist/index.mjs'
  23. import React from 'https://esm.sh/react@18'
  24. import ReactDOM from 'https://esm.sh/react-dom@18'
  25. function ThreeViewerComponent({ src, env }) {
  26. const canvasRef = React.useRef(null);
  27. React.useEffect(() => {
  28. const viewer = new ThreeViewer({canvas: canvasRef.current,
  29. plugins: [LoadingScreenPlugin],
  30. })
  31. // Load an environment map
  32. const envPromise = viewer.setEnvironmentMap(env)
  33. const modelPromise = viewer.load(src, {
  34. autoCenter: true,
  35. autoScale: true,
  36. })
  37. Promise.all([envPromise, modelPromise]).then(([env, model])=>{
  38. console.log('Loaded', model, env, viewer)
  39. })
  40. return () => {
  41. viewer.dispose()
  42. }
  43. }, []);
  44. return (
  45. <canvas id="three-canvas" style={{ width: 800, height: 600 }} ref={canvasRef} />
  46. )
  47. }
  48. ReactDOM.render(
  49. <ThreeViewerComponent
  50. src={'https://threejs.org/examples/models/gltf/DamagedHelmet/glTF/DamagedHelmet.gltf'}
  51. env={'https://threejs.org/examples/textures/equirectangular/venice_sunset_1k.hdr'}
  52. />,
  53. document.getElementById('root')
  54. )
  55. </script>
  56. </body>
  57. </html>