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

script.ts 1.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. import {_testFinish, CustomBumpMapPlugin, ITexture, Mesh, PhysicalMaterial, PlaneGeometry, 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 customBump = viewer.addPluginSync(CustomBumpMapPlugin)
  9. const ui = viewer.addPluginSync(new TweakpaneUiPlugin(true))
  10. await viewer.setEnvironmentMap('https://threejs.org/examples/textures/equirectangular/venice_sunset_1k.hdr')
  11. const model = new Mesh(new PlaneGeometry(4, 2), new PhysicalMaterial())
  12. const material = model.material
  13. viewer.scene.addObject(model)
  14. const bumpMap1 = await viewer.load<ITexture>('https://threejs.org/examples/textures/brick_bump.jpg')
  15. const bumpMap2 = await viewer.load<ITexture>('https://threejs.org/examples/textures/planets/earth_specular_2048.jpg')
  16. customBump.enableCustomBump(material, bumpMap2, -0.2)
  17. material.bumpMap = bumpMap1 || null
  18. material.bumpScale = -0.01
  19. material.setDirty()
  20. // set properties like this or from the UI
  21. // material.userData._customBumpMat = texture
  22. // material.setDirty()
  23. // to disable
  24. // material.userData._hasCustomBump = false
  25. // material.setDirty()
  26. ui.setupPluginUi(CustomBumpMapPlugin)
  27. const config = material.uiConfig!
  28. ui.appendChild(customBump.materialExtension.getUiConfig?.(material), {expanded: true})
  29. ui.appendChild(config)
  30. }
  31. init().finally(_testFinish)