threepipe
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

script.ts 2.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. import {
  2. _testFinish,
  3. IObject3D,
  4. IPipelinePass,
  5. LoadingScreenPlugin, onChange,
  6. PhysicalMaterial,
  7. SSAAPlugin,
  8. ThreeViewer, uiFolderContainer, uiSlider,
  9. Vector2, UiObjectConfig,
  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: 8,
  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. init().then(_testFinish)