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 3.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. import {
  2. _testFinish,
  3. DepthBufferPlugin,
  4. DropzonePlugin,
  5. FrameFadePlugin,
  6. FullScreenPlugin,
  7. GLTFAnimationPlugin,
  8. HalfFloatType,
  9. KTX2LoadPlugin,
  10. KTXLoadPlugin,
  11. NormalBufferPlugin,
  12. PLYLoadPlugin,
  13. ProgressivePlugin,
  14. RenderTargetPreviewPlugin,
  15. Rhino3dmLoadPlugin,
  16. SceneUiConfigPlugin,
  17. STLLoadPlugin,
  18. ThreeViewer,
  19. TonemapPlugin,
  20. USDZLoadPlugin,
  21. ViewerUiConfigPlugin,
  22. } from 'threepipe'
  23. import {TweakpaneUiPlugin} from '@threepipe/plugin-tweakpane'
  24. import {TweakpaneEditorPlugin} from '@threepipe/plugin-tweakpane-editor'
  25. import {extraImportPlugins} from '@threepipe/plugin-extra-importers'
  26. async function init() {
  27. const viewer = new ThreeViewer({
  28. canvas: document.getElementById('mcanvas') as HTMLCanvasElement,
  29. msaa: true,
  30. rgbm: true,
  31. zPrepass: false, // set it to true if you only have opaque objects in the scene to get better performance.
  32. dropzone: {
  33. addOptions: {
  34. clearSceneObjects: false, // clear the scene before adding new objects on drop.
  35. },
  36. },
  37. })
  38. // @ts-expect-error unused
  39. const ui = viewer.addPluginSync(new TweakpaneUiPlugin(true))
  40. const editor = viewer.addPluginSync(new TweakpaneEditorPlugin())
  41. await viewer.addPlugins([
  42. new ProgressivePlugin(),
  43. new GLTFAnimationPlugin(),
  44. new ViewerUiConfigPlugin(),
  45. // new SceneUiConfigPlugin(), // this is already in ViewerUiPlugin
  46. new DepthBufferPlugin(HalfFloatType, true, true),
  47. new NormalBufferPlugin(HalfFloatType, false),
  48. new RenderTargetPreviewPlugin(false),
  49. new FrameFadePlugin(),
  50. KTX2LoadPlugin,
  51. KTXLoadPlugin,
  52. PLYLoadPlugin,
  53. Rhino3dmLoadPlugin,
  54. STLLoadPlugin,
  55. USDZLoadPlugin,
  56. ...extraImportPlugins,
  57. ])
  58. const rt = viewer.getOrAddPluginSync(RenderTargetPreviewPlugin)
  59. rt.addTarget(viewer.getPlugin(DepthBufferPlugin)?.target, 'depth', false, false, false)
  60. rt.addTarget(viewer.getPlugin(NormalBufferPlugin)?.target, 'normal', false, true, false)
  61. editor.loadPlugins({
  62. ['Viewer']: [ViewerUiConfigPlugin, SceneUiConfigPlugin, DropzonePlugin, FullScreenPlugin],
  63. ['GBuffer']: [DepthBufferPlugin, NormalBufferPlugin],
  64. ['Post-processing']: [TonemapPlugin, ProgressivePlugin, FrameFadePlugin],
  65. ['Animation']: [GLTFAnimationPlugin],
  66. ['Debug']: [RenderTargetPreviewPlugin],
  67. })
  68. await viewer.setEnvironmentMap('https://threejs.org/examples/textures/equirectangular/venice_sunset_1k.hdr')
  69. // const result = await viewer.load<IObject3D>('https://cdn.jsdelivr.net/gh/KhronosGroup/glTF-Blender-Exporter@master/polly/project_polly.gltf', {
  70. // autoCenter: true,
  71. // autoScale: true,
  72. // })
  73. //
  74. // const model = result?.getObjectByName('Correction__MovingCamera')
  75. // const config = model?.uiConfig
  76. // console.log(model, config, result)
  77. // if (config) ui.appendChild(config)
  78. }
  79. init().then(_testFinish)