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.

script.ts 2.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. import {
  2. _testFinish,
  3. DepthBufferPlugin,
  4. DropzonePlugin,
  5. FullScreenPlugin,
  6. HalfFloatType,
  7. IObject3D,
  8. NormalBufferPlugin,
  9. RenderTargetPreviewPlugin,
  10. SceneUiConfigPlugin,
  11. ThreeViewer,
  12. TonemapPlugin,
  13. ViewerUiConfigPlugin,
  14. } from 'threepipe'
  15. import {TweakpaneUiPlugin} from '@threepipe/plugin-tweakpane'
  16. import {TweakpaneEditorPlugin} from '@threepipe/plugin-tweakpane-editor'
  17. async function init() {
  18. const viewer = new ThreeViewer({
  19. canvas: document.getElementById('mcanvas') as HTMLCanvasElement,
  20. msaa: true,
  21. rgbm: true,
  22. dropzone: {
  23. addOptions: {
  24. clearSceneObjects: false, // clear the scene before adding new objects on drop.
  25. },
  26. },
  27. })
  28. viewer.addPluginSync(new TweakpaneUiPlugin(true))
  29. const editor = viewer.addPluginSync(new TweakpaneEditorPlugin())
  30. await viewer.addPlugins([
  31. new ViewerUiConfigPlugin(),
  32. // new SceneUiConfigPlugin(),
  33. new DepthBufferPlugin(HalfFloatType, true, true),
  34. new NormalBufferPlugin(HalfFloatType, false),
  35. new RenderTargetPreviewPlugin(false),
  36. new TonemapPlugin(),
  37. ])
  38. const rt = viewer.getOrAddPluginSync(RenderTargetPreviewPlugin)
  39. rt.addTarget(viewer.getPlugin(DepthBufferPlugin)?.target, 'depth', false, false, false)
  40. rt.addTarget(viewer.getPlugin(NormalBufferPlugin)?.target, 'normal', false, true, false)
  41. editor.loadPlugins({
  42. ['Viewer']: [ViewerUiConfigPlugin, SceneUiConfigPlugin, DropzonePlugin, FullScreenPlugin],
  43. ['GBuffer']: [DepthBufferPlugin, NormalBufferPlugin],
  44. ['Post-processing']: [TonemapPlugin],
  45. ['Debug']: [RenderTargetPreviewPlugin],
  46. })
  47. await viewer.setEnvironmentMap('https://threejs.org/examples/textures/equirectangular/venice_sunset_1k.hdr', {
  48. setBackground: true,
  49. })
  50. await viewer.load<IObject3D>('https://threejs.org/examples/models/gltf/DamagedHelmet/glTF/DamagedHelmet.gltf', {
  51. autoCenter: true,
  52. autoScale: true,
  53. })
  54. // const model = result?.getObjectByName('node_damagedHelmet_-6514')
  55. // const config = model?.uiConfig
  56. // if (config) ui.appendChild(config)
  57. }
  58. init().then(_testFinish)