threepipe
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

script.ts 1.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. import {
  2. _testFinish, _testStart,
  3. CustomBumpMapPlugin,
  4. ITexture,
  5. LoadingScreenPlugin,
  6. Mesh,
  7. PhysicalMaterial,
  8. PlaneGeometry,
  9. ThreeViewer,
  10. } from 'threepipe'
  11. import {TweakpaneUiPlugin} from '@threepipe/plugin-tweakpane'
  12. async function init() {
  13. const viewer = new ThreeViewer({
  14. canvas: document.getElementById('mcanvas') as HTMLCanvasElement,
  15. msaa: true,
  16. plugins: [LoadingScreenPlugin],
  17. })
  18. const customBump = viewer.addPluginSync(CustomBumpMapPlugin)
  19. const ui = viewer.addPluginSync(new TweakpaneUiPlugin(true))
  20. await viewer.setEnvironmentMap('https://threejs.org/examples/textures/equirectangular/venice_sunset_1k.hdr')
  21. const model = new Mesh(new PlaneGeometry(4, 2), new PhysicalMaterial())
  22. const material = model.material
  23. viewer.scene.addObject(model)
  24. const bumpMap1 = await viewer.load<ITexture>('https://threejs.org/examples/textures/brick_bump.jpg')
  25. const bumpMap2 = await viewer.load<ITexture>('https://threejs.org/examples/textures/planets/earth_specular_2048.jpg')
  26. customBump.enableCustomBump(material, bumpMap2, -0.2)
  27. material.bumpMap = bumpMap1 || null
  28. material.bumpScale = -0.01
  29. material.setDirty()
  30. // set properties like this or from the UI
  31. // material.userData._customBumpMat = texture
  32. // material.setDirty()
  33. // to disable
  34. // material.userData._hasCustomBump = false
  35. // material.setDirty()
  36. ui.setupPluginUi(CustomBumpMapPlugin)
  37. const config = material.uiConfig!
  38. ui.appendChild(customBump.materialExtension.getUiConfig?.(material), {expanded: true})
  39. ui.appendChild(config)
  40. }
  41. _testStart()
  42. init().finally(_testFinish)