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

script.ts 2.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. import {
  2. _testFinish,
  3. DepthBufferPlugin,
  4. DropzonePlugin,
  5. FullScreenPlugin,
  6. HalfFloatType,
  7. KTX2LoadPlugin,
  8. KTXLoadPlugin,
  9. NormalBufferPlugin,
  10. PLYLoadPlugin,
  11. RenderTargetPreviewPlugin,
  12. Rhino3dmLoadPlugin,
  13. SceneUiConfigPlugin,
  14. STLLoadPlugin,
  15. ThreeViewer,
  16. TonemapPlugin,
  17. ViewerUiConfigPlugin,
  18. } from 'threepipe'
  19. import {TweakpaneUiPlugin} from '@threepipe/plugin-tweakpane'
  20. import {TweakpaneEditorPlugin} from '@threepipe/plugin-tweakpane-editor'
  21. async function init() {
  22. const viewer = new ThreeViewer({
  23. canvas: document.getElementById('mcanvas') as HTMLCanvasElement,
  24. msaa: true,
  25. rgbm: true,
  26. zPrepass: false, // set it to true if you only have opaque objects in the scene to get better performance.
  27. dropzone: {
  28. addOptions: {
  29. clearSceneObjects: false, // clear the scene before adding new objects on drop.
  30. },
  31. },
  32. })
  33. viewer.addPluginSync(new TweakpaneUiPlugin(true))
  34. const editor = viewer.addPluginSync(new TweakpaneEditorPlugin())
  35. await viewer.addPlugins([
  36. new ViewerUiConfigPlugin(),
  37. // new SceneUiConfigPlugin(), // this is already in ViewerUiPlugin
  38. new DepthBufferPlugin(HalfFloatType, true, true),
  39. new NormalBufferPlugin(HalfFloatType, false),
  40. new RenderTargetPreviewPlugin(false),
  41. new KTX2LoadPlugin(),
  42. new KTXLoadPlugin(),
  43. new PLYLoadPlugin(),
  44. new Rhino3dmLoadPlugin(),
  45. new STLLoadPlugin(),
  46. ])
  47. const rt = viewer.getOrAddPluginSync(RenderTargetPreviewPlugin)
  48. rt.addTarget(viewer.getPlugin(DepthBufferPlugin)?.target, 'depth', false, false, false)
  49. rt.addTarget(viewer.getPlugin(NormalBufferPlugin)?.target, 'normal', false, true, false)
  50. editor.loadPlugins({
  51. ['Viewer']: [ViewerUiConfigPlugin, SceneUiConfigPlugin, DropzonePlugin, FullScreenPlugin],
  52. ['GBuffer']: [DepthBufferPlugin, NormalBufferPlugin],
  53. ['Post-processing']: [TonemapPlugin],
  54. ['Debug']: [RenderTargetPreviewPlugin],
  55. })
  56. await viewer.setEnvironmentMap('https://threejs.org/examples/textures/equirectangular/venice_sunset_1k.hdr')
  57. // await viewer.load<IObject3D>('https://threejs.org/examples/models/gltf/DamagedHelmet/glTF/DamagedHelmet.gltf', {
  58. // autoCenter: true,
  59. // autoScale: true,
  60. // })
  61. // const model = result?.getObjectByName('node_damagedHelmet_-6514')
  62. // const config = model?.uiConfig
  63. // if (config) ui.appendChild(config)
  64. }
  65. init().then(_testFinish)