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

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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(), // this is already in ViewerUiPlugin
  33. new DepthBufferPlugin(HalfFloatType, true, true),
  34. new NormalBufferPlugin(HalfFloatType, false),
  35. new RenderTargetPreviewPlugin(false),
  36. ])
  37. const rt = viewer.getOrAddPluginSync(RenderTargetPreviewPlugin)
  38. rt.addTarget(viewer.getPlugin(DepthBufferPlugin)?.target, 'depth', false, false, false)
  39. rt.addTarget(viewer.getPlugin(NormalBufferPlugin)?.target, 'normal', false, true, false)
  40. editor.loadPlugins({
  41. ['Viewer']: [ViewerUiConfigPlugin, SceneUiConfigPlugin, DropzonePlugin, FullScreenPlugin],
  42. ['GBuffer']: [DepthBufferPlugin, NormalBufferPlugin],
  43. ['Post-processing']: [TonemapPlugin],
  44. ['Debug']: [RenderTargetPreviewPlugin],
  45. })
  46. await viewer.setEnvironmentMap('https://threejs.org/examples/textures/equirectangular/venice_sunset_1k.hdr', {
  47. setBackground: true,
  48. })
  49. await viewer.load<IObject3D>('https://threejs.org/examples/models/gltf/DamagedHelmet/glTF/DamagedHelmet.gltf', {
  50. autoCenter: true,
  51. autoScale: true,
  52. })
  53. // const model = result?.getObjectByName('node_damagedHelmet_-6514')
  54. // const config = model?.uiConfig
  55. // if (config) ui.appendChild(config)
  56. }
  57. init().then(_testFinish)