threepipe
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. import {
  2. _testFinish,
  3. CameraViewPlugin,
  4. DepthBufferPlugin,
  5. DropzonePlugin,
  6. FrameFadePlugin,
  7. FullScreenPlugin,
  8. GLTFAnimationPlugin,
  9. HalfFloatType,
  10. HemisphereLight,
  11. KTX2LoadPlugin,
  12. KTXLoadPlugin,
  13. NormalBufferPlugin,
  14. PLYLoadPlugin,
  15. ProgressivePlugin,
  16. RenderTargetPreviewPlugin,
  17. Rhino3dmLoadPlugin,
  18. SceneUiConfigPlugin,
  19. STLLoadPlugin,
  20. ThreeViewer,
  21. TonemapPlugin,
  22. USDZLoadPlugin,
  23. ViewerUiConfigPlugin,
  24. } from 'threepipe'
  25. import {TweakpaneUiPlugin} from '@threepipe/plugin-tweakpane'
  26. import {TweakpaneEditorPlugin} from '@threepipe/plugin-tweakpane-editor'
  27. import {extraImportPlugins} from '@threepipe/plugin-extra-importers'
  28. async function init() {
  29. const viewer = new ThreeViewer({
  30. canvas: document.getElementById('mcanvas') as HTMLCanvasElement,
  31. msaa: true,
  32. rgbm: true,
  33. zPrepass: false, // set it to true if you only have opaque objects in the scene to get better performance.
  34. dropzone: {
  35. addOptions: {
  36. clearSceneObjects: false, // clear the scene before adding new objects on drop.
  37. },
  38. },
  39. })
  40. // @ts-expect-error unused
  41. const ui = viewer.addPluginSync(new TweakpaneUiPlugin(true))
  42. const editor = viewer.addPluginSync(new TweakpaneEditorPlugin())
  43. await viewer.addPlugins([
  44. new ProgressivePlugin(),
  45. new GLTFAnimationPlugin(),
  46. new CameraViewPlugin(),
  47. new ViewerUiConfigPlugin(),
  48. // new SceneUiConfigPlugin(), // this is already in ViewerUiPlugin
  49. new DepthBufferPlugin(HalfFloatType, true, true),
  50. new NormalBufferPlugin(HalfFloatType, false),
  51. new RenderTargetPreviewPlugin(false),
  52. new FrameFadePlugin(),
  53. KTX2LoadPlugin,
  54. KTXLoadPlugin,
  55. PLYLoadPlugin,
  56. Rhino3dmLoadPlugin,
  57. STLLoadPlugin,
  58. USDZLoadPlugin,
  59. ...extraImportPlugins,
  60. ])
  61. const rt = viewer.getOrAddPluginSync(RenderTargetPreviewPlugin)
  62. rt.addTarget(viewer.getPlugin(DepthBufferPlugin)?.target, 'depth', false, false, false)
  63. rt.addTarget(viewer.getPlugin(NormalBufferPlugin)?.target, 'normal', false, true, false)
  64. editor.loadPlugins({
  65. ['Viewer']: [ViewerUiConfigPlugin, SceneUiConfigPlugin, DropzonePlugin, FullScreenPlugin],
  66. ['GBuffer']: [DepthBufferPlugin, NormalBufferPlugin],
  67. ['Post-processing']: [TonemapPlugin, ProgressivePlugin, FrameFadePlugin],
  68. ['Animation']: [GLTFAnimationPlugin, CameraViewPlugin],
  69. ['Debug']: [RenderTargetPreviewPlugin],
  70. })
  71. viewer.scene.addObject(new HemisphereLight(0xffffff, 0x444444, 5))
  72. await viewer.setEnvironmentMap('https://threejs.org/examples/textures/equirectangular/venice_sunset_1k.hdr')
  73. // const result = await viewer.load<IObject3D>('https://cdn.jsdelivr.net/gh/KhronosGroup/glTF-Blender-Exporter@master/polly/project_polly.gltf', {
  74. // autoCenter: true,
  75. // autoScale: true,
  76. // })
  77. //
  78. // const model = result?.getObjectByName('Correction__MovingCamera')
  79. // const config = model?.uiConfig
  80. // console.log(model, config, result)
  81. // if (config) ui.appendChild(config)
  82. }
  83. init().then(_testFinish)