threepipe
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

script.ts 1.7KB

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