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.1KB

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