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

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