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

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. import {_testFinish, IObject3D, NoiseBumpMaterialPlugin, PhysicalMaterial, ThreeViewer} from 'threepipe'
  2. import {TweakpaneUiPlugin} from '@threepipe/plugin-tweakpane'
  3. async function init() {
  4. const viewer = new ThreeViewer({
  5. canvas: document.getElementById('mcanvas') as HTMLCanvasElement,
  6. msaa: true,
  7. })
  8. const noiseBump = viewer.addPluginSync(NoiseBumpMaterialPlugin)
  9. const ui = viewer.addPluginSync(new TweakpaneUiPlugin(true))
  10. await viewer.setEnvironmentMap('https://threejs.org/examples/textures/equirectangular/venice_sunset_1k.hdr', {
  11. setBackground: true,
  12. })
  13. const result = await viewer.load<IObject3D>('https://threejs.org/examples/models/gltf/DamagedHelmet/glTF/DamagedHelmet.gltf', {
  14. autoCenter: true,
  15. autoScale: true,
  16. })
  17. const model = result?.getObjectByName('node_damagedHelmet_-6514')
  18. const materials = (model?.materials || []) as PhysicalMaterial[]
  19. for (const material of materials) {
  20. NoiseBumpMaterialPlugin.AddNoiseBumpMaterial(material, {
  21. flakeScale: 300,
  22. })
  23. // set properties like this or from the UI
  24. // material.userData._noiseBumpMat!.bumpNoiseParams = [1, 1]
  25. // material.setDirty()
  26. // Add extra noise bump extension ui mapped to this material.
  27. // This is also added inside the material ui by default by the material extension automatically.
  28. const config = material.uiConfig
  29. if (!config) continue
  30. ui.appendChild(noiseBump.materialExtension.getUiConfig?.(material), {expanded: true})
  31. ui.appendChild(config)
  32. }
  33. }
  34. init().finally(_testFinish)