threepipe
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

script.ts 5.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. import {
  2. _testFinish,
  3. CameraViewPlugin,
  4. ChromaticAberrationPlugin,
  5. ClearcoatTintPlugin,
  6. CustomBumpMapPlugin,
  7. DepthBufferPlugin,
  8. DropzonePlugin,
  9. EditorViewWidgetPlugin,
  10. FilmicGrainPlugin,
  11. FragmentClippingExtensionPlugin,
  12. FrameFadePlugin,
  13. FullScreenPlugin,
  14. GBufferPlugin,
  15. GLTFAnimationPlugin,
  16. HalfFloatType,
  17. HDRiGroundPlugin,
  18. HemisphereLight,
  19. KTX2LoadPlugin,
  20. KTXLoadPlugin,
  21. NoiseBumpMaterialPlugin,
  22. NormalBufferPlugin,
  23. Object3DGeneratorPlugin,
  24. Object3DWidgetsPlugin,
  25. PickingPlugin,
  26. PLYLoadPlugin,
  27. ProgressivePlugin,
  28. RenderTargetPreviewPlugin,
  29. Rhino3dmLoadPlugin,
  30. SceneUiConfigPlugin,
  31. STLLoadPlugin,
  32. ThreeViewer,
  33. TonemapPlugin,
  34. TransformControlsPlugin,
  35. USDZLoadPlugin,
  36. ViewerUiConfigPlugin,
  37. VignettePlugin,
  38. VirtualCamerasPlugin,
  39. } from 'threepipe'
  40. import {TweakpaneUiPlugin} from '@threepipe/plugin-tweakpane'
  41. import {HierarchyUiPlugin, TweakpaneEditorPlugin} from '@threepipe/plugin-tweakpane-editor'
  42. import {BlendLoadPlugin} from '@threepipe/plugin-blend-importer'
  43. import {extraImportPlugins} from '@threepipe/plugin-extra-importers'
  44. import {GeometryGeneratorPlugin} from '@threepipe/plugin-geometry-generator'
  45. async function init() {
  46. const viewer = new ThreeViewer({
  47. canvas: document.getElementById('mcanvas') as HTMLCanvasElement,
  48. msaa: true,
  49. rgbm: true,
  50. zPrepass: false, // set it to true if you only have opaque objects in the scene to get better performance.
  51. dropzone: {
  52. addOptions: {
  53. clearSceneObjects: false, // clear the scene before adding new objects on drop.
  54. },
  55. },
  56. })
  57. // @ts-expect-error unused
  58. const ui = viewer.addPluginSync(new TweakpaneUiPlugin(true))
  59. const editor = viewer.addPluginSync(new TweakpaneEditorPlugin())
  60. await viewer.addPlugins([
  61. new ProgressivePlugin(),
  62. GLTFAnimationPlugin,
  63. PickingPlugin,
  64. new TransformControlsPlugin(false),
  65. EditorViewWidgetPlugin,
  66. CameraViewPlugin,
  67. ViewerUiConfigPlugin,
  68. ClearcoatTintPlugin,
  69. FragmentClippingExtensionPlugin,
  70. NoiseBumpMaterialPlugin,
  71. CustomBumpMapPlugin,
  72. VirtualCamerasPlugin,
  73. // new SceneUiConfigPlugin(), // this is already in ViewerUiPlugin
  74. new GBufferPlugin(HalfFloatType, true, true, true),
  75. new DepthBufferPlugin(HalfFloatType, false, false),
  76. new NormalBufferPlugin(HalfFloatType, false),
  77. new RenderTargetPreviewPlugin(false),
  78. new FrameFadePlugin(),
  79. new HDRiGroundPlugin(false, true),
  80. new VignettePlugin(false),
  81. new ChromaticAberrationPlugin(false),
  82. new FilmicGrainPlugin(false),
  83. KTX2LoadPlugin,
  84. KTXLoadPlugin,
  85. PLYLoadPlugin,
  86. Rhino3dmLoadPlugin,
  87. STLLoadPlugin,
  88. USDZLoadPlugin,
  89. BlendLoadPlugin,
  90. HierarchyUiPlugin,
  91. GeometryGeneratorPlugin,
  92. Object3DWidgetsPlugin,
  93. Object3DGeneratorPlugin,
  94. ...extraImportPlugins,
  95. ])
  96. const rt = viewer.getOrAddPluginSync(RenderTargetPreviewPlugin)
  97. rt.addTarget({texture: viewer.getPlugin(GBufferPlugin)?.normalDepthTexture}, 'normalDepth')
  98. rt.addTarget({texture: viewer.getPlugin(GBufferPlugin)?.flagsTexture}, 'gBufferFlags')
  99. rt.addTarget(viewer.getPlugin(DepthBufferPlugin)?.target, 'depth', false, false, false)
  100. rt.addTarget(viewer.getPlugin(NormalBufferPlugin)?.target, 'normal', false, true, false)
  101. editor.loadPlugins({
  102. ['Viewer']: [ViewerUiConfigPlugin, SceneUiConfigPlugin, DropzonePlugin, FullScreenPlugin, TweakpaneUiPlugin],
  103. ['Interaction']: [HierarchyUiPlugin, TransformControlsPlugin, PickingPlugin, Object3DGeneratorPlugin, GeometryGeneratorPlugin, EditorViewWidgetPlugin, Object3DWidgetsPlugin],
  104. ['GBuffer']: [GBufferPlugin, DepthBufferPlugin, NormalBufferPlugin],
  105. ['Post-processing']: [TonemapPlugin, ProgressivePlugin, FrameFadePlugin, VignettePlugin, ChromaticAberrationPlugin, FilmicGrainPlugin],
  106. ['Animation']: [GLTFAnimationPlugin, CameraViewPlugin],
  107. ['Extras']: [HDRiGroundPlugin, Rhino3dmLoadPlugin, ClearcoatTintPlugin, FragmentClippingExtensionPlugin, NoiseBumpMaterialPlugin, CustomBumpMapPlugin, VirtualCamerasPlugin],
  108. ['Debug']: [RenderTargetPreviewPlugin],
  109. })
  110. const hemiLight = viewer.scene.addObject(new HemisphereLight(0xffffff, 0x444444, 5))
  111. hemiLight.name = 'Hemisphere Light'
  112. await viewer.setEnvironmentMap('https://threejs.org/examples/textures/equirectangular/venice_sunset_1k.hdr')
  113. // const result = await viewer.load<IObject3D>('https://cdn.jsdelivr.net/gh/KhronosGroup/glTF-Blender-Exporter@master/polly/project_polly.gltf', {
  114. // autoCenter: true,
  115. // autoScale: true,
  116. // })
  117. //
  118. // const model = result?.getObjectByName('Correction__MovingCamera')
  119. // const config = model?.uiConfig
  120. // console.log(model, config, result)
  121. // if (config) ui.appendChild(config)
  122. }
  123. init().then(_testFinish)