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.

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. import {
  2. _testFinish,
  3. IObject3D,
  4. IPipelinePass,
  5. LoadingScreenPlugin, onChange,
  6. PhysicalMaterial,
  7. SSAAPlugin,
  8. ThreeViewer, uiFolderContainer, uiSlider,
  9. Vector2, UiObjectConfig, _testStart,
  10. } from 'threepipe'
  11. import {TweakpaneUiPlugin} from '@threepipe/plugin-tweakpane'
  12. import {UnrealBloomPass} from 'three/examples/jsm/postprocessing/UnrealBloomPass.js'
  13. // @ts-expect-error todo fix ts import
  14. import {TemporalAAPlugin} from '@threepipe/webgi-plugins'
  15. async function init() {
  16. const viewer = new ThreeViewer({
  17. canvas: document.getElementById('mcanvas') as HTMLCanvasElement,
  18. msaa: true,
  19. rgbm: false, // The pass from three.js doesn't support RGBM encoded render targets
  20. zPrepass: false,
  21. renderScale: 1,
  22. maxHDRIntensity: 100,
  23. dropzone: {
  24. addOptions: {
  25. disposeSceneObjects: true,
  26. },
  27. },
  28. plugins: [LoadingScreenPlugin, SSAAPlugin, TemporalAAPlugin],
  29. })
  30. // Extend the pass to add UI and pipeline pass options
  31. @uiFolderContainer('Unreal Bloom')
  32. class UnrealBloomPass2 extends UnrealBloomPass implements IPipelinePass {
  33. declare uiConfig: UiObjectConfig
  34. passId = 'unrealBloom'
  35. after = ['render', 'progressive']
  36. before = ['screen']
  37. required = ['render']
  38. @uiSlider('Strength', [0, 5], 0.01)
  39. @onChange(UnrealBloomPass2.prototype.setDirty)
  40. declare strength
  41. @uiSlider('Radius', [0, 1], 0.01)
  42. @onChange(UnrealBloomPass2.prototype.setDirty)
  43. declare radius
  44. @uiSlider('Threshold', [0, 8], 0.01)
  45. @onChange(UnrealBloomPass2.prototype.setDirty)
  46. declare threshold
  47. setDirty() {
  48. viewer.setDirty()
  49. }
  50. }
  51. const bloomPass = new UnrealBloomPass2(new Vector2(window.innerWidth, window.innerHeight), 1., 0.5, 1.5)
  52. viewer.renderManager.registerPass(bloomPass)
  53. const ui = viewer.addPluginSync(new TweakpaneUiPlugin(true))
  54. await viewer.setEnvironmentMap('https://threejs.org/examples/textures/equirectangular/venice_sunset_1k.hdr', {
  55. setBackground: true,
  56. })
  57. const result = await viewer.load<IObject3D>('https://threejs.org/examples/models/gltf/DamagedHelmet/glTF/DamagedHelmet.gltf', {
  58. autoCenter: true,
  59. autoScale: true,
  60. })
  61. const model = result?.getObjectByName('node_damagedHelmet_-6514')
  62. const materials = (model?.materials || []) as PhysicalMaterial[]
  63. ui.appendChild(bloomPass.uiConfig)
  64. for (const material of materials) {
  65. ui.appendChild(material.uiConfig)
  66. }
  67. }
  68. _testStart()
  69. init().then(_testFinish)