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

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. import {
  2. _testFinish,
  3. BoxGeometry,
  4. ITexture,
  5. Mesh,
  6. ParallaxMappingPlugin,
  7. PhysicalMaterial,
  8. SSAAPlugin,
  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: [new SSAAPlugin(4)],
  17. dropzone: {
  18. addOptions: {
  19. disposeSceneObjects: true,
  20. },
  21. },
  22. })
  23. const parallaxMapping = viewer.addPluginSync(ParallaxMappingPlugin)
  24. console.log(parallaxMapping)
  25. const ui = viewer.addPluginSync(new TweakpaneUiPlugin(true))
  26. ui.setupPluginUi(ParallaxMappingPlugin, {expanded: true})
  27. await viewer.setEnvironmentMap('https://threejs.org/examples/textures/equirectangular/venice_sunset_1k.hdr')
  28. const cube = new Mesh(
  29. new BoxGeometry(1, 1, 1),
  30. new PhysicalMaterial({
  31. // roughness: 0,
  32. // metalness: 1,
  33. }))
  34. const maps = [
  35. 'https://threejs.org/examples/textures/sprite0.png',
  36. 'https://threejs.org/examples/textures/uv_grid_opengl.jpg',
  37. 'https://threejs.org/examples/models/svg/style-css-inside-defs.svg',
  38. 'https://cdn.jsdelivr.net/gh/Rabbid76/graphics-snippets/resource/texture/lookuptable.png',
  39. 'https://cdn.jsdelivr.net/gh/Rabbid76/graphics-snippets/resource/texture/perlin3_cp.png',
  40. 'https://cdn.jsdelivr.net/gh/Rabbid76/graphics-snippets/resource/texture/perlin4_cp.png',
  41. 'https://cdn.jsdelivr.net/gh/Rabbid76/graphics-snippets/resource/texture/ObjectSheet.png',
  42. 'https://cdn.jsdelivr.net/gh/Rabbid76/graphics-snippets/resource/texture/512x512_Texel_Density_Texture_1.png',
  43. 'https://cdn.jsdelivr.net/gh/Rabbid76/graphics-snippets/resource/texture/toy_box_normal.png',
  44. 'https://cdn.jsdelivr.net/gh/Rabbid76/graphics-snippets/resource/texture/example_1_texture.png',
  45. ]
  46. const bumps = [
  47. maps[0],
  48. maps[1],
  49. maps[2],
  50. maps[3],
  51. maps[4],
  52. maps[5],
  53. maps[6],
  54. maps[7],
  55. 'https://cdn.jsdelivr.net/gh/Rabbid76/graphics-snippets/resource/texture/toy_box_disp.png',
  56. 'https://cdn.jsdelivr.net/gh/Rabbid76/graphics-snippets/resource/texture/example_1_heightmap.png',
  57. ]
  58. cube.material.bumpMap = await viewer.load<ITexture>(bumps[0]) || null
  59. cube.material.map = await viewer.load<ITexture>(maps[0]) || null
  60. cube.material.bumpScale = 0.1
  61. viewer.scene.addObject(cube)
  62. ui.appendChild({
  63. type: 'dropdown',
  64. value: maps[0],
  65. label: 'Bump Texture',
  66. children: ['none', ...maps].map((url: string) => ({
  67. label: url.split('/').pop(),
  68. value: url,
  69. })),
  70. onChange: async(ev) => {
  71. console.log(ev.value)
  72. const url = ev.value
  73. const tex = await viewer.load<ITexture>(url) || null
  74. cube.material.map = tex
  75. const bumpUrl = bumps[maps.indexOf(url)]
  76. const bumpTex = await viewer.load<ITexture>(bumpUrl) || null
  77. cube.material.bumpMap = bumpTex
  78. cube.material.setDirty()
  79. },
  80. })
  81. ui.appendChild(cube.material.uiConfig)
  82. }
  83. init().finally(_testFinish)