threepipe
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

script.ts 2.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. import {
  2. _testFinish,
  3. _testStart,
  4. BaseGroundPlugin,
  5. CanvasSnapshotPlugin,
  6. IObject3D,
  7. LoadingScreenPlugin,
  8. PickingPlugin,
  9. ProgressivePlugin,
  10. ThreeViewer,
  11. TonemapPlugin,
  12. } from 'threepipe'
  13. import {ThreeGpuPathTracerPlugin} from '@threepipe/plugin-path-tracing'
  14. import {TweakpaneUiPlugin} from '@threepipe/plugin-tweakpane'
  15. async function init() {
  16. const viewer = new ThreeViewer({
  17. canvas: document.getElementById('mcanvas') as HTMLCanvasElement,
  18. msaa: false,
  19. debug: true,
  20. renderScale: 'auto',
  21. dropzone: {
  22. allowedExtensions: ['gltf', 'glb', 'hdr', 'bin', 'png', 'jpeg', 'webp', 'jpg', 'exr', 'json'],
  23. addOptions: {
  24. disposeSceneObjects: true,
  25. autoSetEnvironment: true, // when hdr is dropped
  26. autoSetBackground: true,
  27. },
  28. },
  29. plugins: [LoadingScreenPlugin, PickingPlugin, ProgressivePlugin, BaseGroundPlugin, CanvasSnapshotPlugin, ThreeGpuPathTracerPlugin],
  30. })
  31. await viewer.setEnvironmentMap('https://threejs.org/examples/textures/equirectangular/venice_sunset_1k.hdr', {setBackground: true})
  32. const modelUrl = 'https://threejs.org/examples/models/gltf/DamagedHelmet/glTF/DamagedHelmet.gltf'
  33. const result = await viewer.load<IObject3D>(modelUrl, {
  34. autoCenter: true,
  35. autoScale: true,
  36. })
  37. console.log(result)
  38. const ground = viewer.getPlugin(BaseGroundPlugin)?.material
  39. if (ground) {
  40. // make reflective
  41. ground.roughness = 0.1
  42. ground.metalness = 0.9
  43. ground.color.set(0xffffff)
  44. ground.setDirty()
  45. }
  46. // optional
  47. // const controls = viewer.scene.mainCamera.controls as EnvironmentControls2
  48. // result && controls.setTilesRenderer(result.tilesRenderer)
  49. const ui = viewer.addPluginSync(TweakpaneUiPlugin)
  50. // ui.appendChild(controls.uiConfig)
  51. ui.setupPluginUi(ThreeGpuPathTracerPlugin)
  52. ui.setupPluginUi(ProgressivePlugin)
  53. ui.setupPluginUi(CanvasSnapshotPlugin)
  54. ui.setupPluginUi(TonemapPlugin)
  55. ui.setupPluginUi(BaseGroundPlugin)
  56. ui.setupPluginUi(PickingPlugin)
  57. }
  58. _testStart()
  59. init().finally(_testFinish)