threepipe
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. import {
  2. _testFinish,
  3. AssetExporterPlugin,
  4. CameraViewPlugin,
  5. CanvasSnapshotPlugin,
  6. ChromaticAberrationPlugin,
  7. ClearcoatTintPlugin,
  8. ContactShadowGroundPlugin,
  9. CustomBumpMapPlugin,
  10. DepthBufferPlugin,
  11. DeviceOrientationControlsPlugin,
  12. DropzonePlugin,
  13. EditorViewWidgetPlugin,
  14. FilmicGrainPlugin,
  15. FragmentClippingExtensionPlugin,
  16. FrameFadePlugin,
  17. FullScreenPlugin,
  18. GBufferPlugin,
  19. getUrlQueryParam,
  20. GLTFAnimationPlugin,
  21. GLTFKHRMaterialVariantsPlugin,
  22. GLTFMeshOptDecodePlugin,
  23. HalfFloatType,
  24. HDRiGroundPlugin,
  25. HemisphereLight,
  26. InteractionPromptPlugin,
  27. KTX2LoadPlugin,
  28. KTXLoadPlugin,
  29. LoadingScreenPlugin,
  30. MeshOptSimplifyModifierPlugin,
  31. NoiseBumpMaterialPlugin,
  32. NormalBufferPlugin,
  33. Object3DGeneratorPlugin,
  34. Object3DWidgetsPlugin,
  35. ParallaxMappingPlugin,
  36. PickingPlugin,
  37. PLYLoadPlugin,
  38. PointerLockControlsPlugin,
  39. PopmotionPlugin,
  40. ProgressivePlugin,
  41. RenderTargetPreviewPlugin,
  42. Rhino3dmLoadPlugin,
  43. SceneUiConfigPlugin,
  44. SSAAPlugin,
  45. SSAOPlugin,
  46. STLLoadPlugin,
  47. ThreeFirstPersonControlsPlugin,
  48. ThreeViewer,
  49. TonemapPlugin,
  50. TransformAnimationPlugin,
  51. TransformControlsPlugin,
  52. UnsignedByteType,
  53. USDZLoadPlugin,
  54. ViewerUiConfigPlugin,
  55. VignettePlugin,
  56. VirtualCamerasPlugin,
  57. } from 'threepipe'
  58. import {TweakpaneUiPlugin} from '@threepipe/plugin-tweakpane'
  59. import {HierarchyUiPlugin, TweakpaneEditorPlugin} from '@threepipe/plugin-tweakpane-editor'
  60. import {BlendLoadPlugin} from '@threepipe/plugin-blend-importer'
  61. import {extraImportPlugins} from '@threepipe/plugins-extra-importers'
  62. import {GeometryGeneratorPlugin} from '@threepipe/plugin-geometry-generator'
  63. import {GaussianSplattingPlugin} from '@threepipe/plugin-gaussian-splatting'
  64. import {MaterialConfiguratorPlugin, SwitchNodePlugin} from '@threepipe/plugin-configurator'
  65. import {AWSClientPlugin, TransfrSharePlugin} from '@threepipe/plugin-network'
  66. import {GLTFDracoExportPlugin} from '@threepipe/plugin-gltf-transform'
  67. async function init() {
  68. const viewer = new ThreeViewer({
  69. canvas: document.getElementById('mcanvas') as HTMLCanvasElement,
  70. renderScale: 'auto',
  71. msaa: true,
  72. rgbm: true,
  73. zPrepass: false, // set it to true if you only have opaque objects in the scene to get better performance.
  74. dropzone: {
  75. addOptions: {
  76. clearSceneObjects: false, // clear the scene before adding new objects on drop.
  77. },
  78. },
  79. })
  80. // @ts-expect-error unused
  81. const ui = viewer.addPluginSync(new TweakpaneUiPlugin(true))
  82. const editor = viewer.addPluginSync(new TweakpaneEditorPlugin())
  83. await viewer.addPlugins([
  84. LoadingScreenPlugin,
  85. AssetExporterPlugin,
  86. GLTFDracoExportPlugin,
  87. PopmotionPlugin,
  88. new ProgressivePlugin(),
  89. new SSAAPlugin(),
  90. GLTFAnimationPlugin,
  91. TransformAnimationPlugin,
  92. PickingPlugin,
  93. new TransformControlsPlugin(false),
  94. EditorViewWidgetPlugin,
  95. CameraViewPlugin,
  96. ViewerUiConfigPlugin,
  97. ClearcoatTintPlugin,
  98. FragmentClippingExtensionPlugin,
  99. NoiseBumpMaterialPlugin,
  100. CustomBumpMapPlugin,
  101. new ParallaxMappingPlugin(false),
  102. GLTFKHRMaterialVariantsPlugin,
  103. VirtualCamerasPlugin,
  104. // new SceneUiConfigPlugin(), // this is already in ViewerUiPlugin
  105. new GBufferPlugin(HalfFloatType, true, true, true),
  106. new DepthBufferPlugin(HalfFloatType, false, false),
  107. new NormalBufferPlugin(HalfFloatType, false),
  108. new RenderTargetPreviewPlugin(false),
  109. new FrameFadePlugin(),
  110. new HDRiGroundPlugin(false, true),
  111. new VignettePlugin(false),
  112. new ChromaticAberrationPlugin(false),
  113. new FilmicGrainPlugin(false),
  114. new SSAOPlugin(UnsignedByteType, 1),
  115. KTX2LoadPlugin,
  116. KTXLoadPlugin,
  117. PLYLoadPlugin,
  118. Rhino3dmLoadPlugin,
  119. STLLoadPlugin,
  120. USDZLoadPlugin,
  121. BlendLoadPlugin,
  122. HierarchyUiPlugin,
  123. GeometryGeneratorPlugin,
  124. Object3DWidgetsPlugin,
  125. Object3DGeneratorPlugin,
  126. GaussianSplattingPlugin,
  127. ContactShadowGroundPlugin,
  128. CanvasSnapshotPlugin,
  129. DeviceOrientationControlsPlugin,
  130. PointerLockControlsPlugin,
  131. ThreeFirstPersonControlsPlugin,
  132. // InteractionPromptPlugin, // todo disable when not in Viewer tab, like in webgi
  133. new MeshOptSimplifyModifierPlugin(false, document.head), // will auto-initialize on first use.
  134. new GLTFMeshOptDecodePlugin(true, document.head),
  135. // new BasicSVGRendererPlugin(false, true),
  136. ...extraImportPlugins,
  137. MaterialConfiguratorPlugin,
  138. SwitchNodePlugin,
  139. AWSClientPlugin,
  140. TransfrSharePlugin,
  141. ])
  142. // to show more details in the UI and allow to edit changes in title etc.
  143. viewer.getPlugin(MaterialConfiguratorPlugin)!.enableEditContextMenus = true
  144. viewer.getPlugin(SwitchNodePlugin)!.enableEditContextMenus = true
  145. // disable fading on update
  146. viewer.getPlugin(LoadingScreenPlugin)!.isEditor = true
  147. // disable fading on update
  148. viewer.getPlugin(FrameFadePlugin)!.isEditor = true
  149. const rt = viewer.getOrAddPluginSync(RenderTargetPreviewPlugin)
  150. rt.addTarget({texture: viewer.getPlugin(GBufferPlugin)?.normalDepthTexture}, 'normalDepth')
  151. rt.addTarget({texture: viewer.getPlugin(GBufferPlugin)?.flagsTexture}, 'gBufferFlags')
  152. rt.addTarget(viewer.getPlugin(DepthBufferPlugin)?.target, 'depth', false, false, false)
  153. rt.addTarget(viewer.getPlugin(NormalBufferPlugin)?.target, 'normal', false, true, false)
  154. editor.loadPlugins({
  155. ['Viewer']: [ViewerUiConfigPlugin, SceneUiConfigPlugin, DropzonePlugin, FullScreenPlugin, TweakpaneUiPlugin, LoadingScreenPlugin, InteractionPromptPlugin],
  156. ['Scene']: [SSAAPlugin, ContactShadowGroundPlugin],
  157. ['Interaction']: [HierarchyUiPlugin, TransformControlsPlugin, PickingPlugin, Object3DGeneratorPlugin, GeometryGeneratorPlugin, EditorViewWidgetPlugin, Object3DWidgetsPlugin, MeshOptSimplifyModifierPlugin],
  158. ['GBuffer']: [GBufferPlugin, DepthBufferPlugin, NormalBufferPlugin],
  159. ['Post-processing']: [TonemapPlugin, ProgressivePlugin, SSAOPlugin, FrameFadePlugin, VignettePlugin, ChromaticAberrationPlugin, FilmicGrainPlugin],
  160. ['Export']: [AssetExporterPlugin, CanvasSnapshotPlugin, AWSClientPlugin, TransfrSharePlugin],
  161. ['Configurator']: [MaterialConfiguratorPlugin, SwitchNodePlugin, GLTFKHRMaterialVariantsPlugin],
  162. ['Animation']: [GLTFAnimationPlugin, CameraViewPlugin],
  163. ['Extras']: [HDRiGroundPlugin, Rhino3dmLoadPlugin, ClearcoatTintPlugin, FragmentClippingExtensionPlugin, NoiseBumpMaterialPlugin, CustomBumpMapPlugin, VirtualCamerasPlugin],
  164. ['Debug']: [RenderTargetPreviewPlugin],
  165. })
  166. const hemiLight = viewer.scene.addObject(new HemisphereLight(0xffffff, 0x444444, 5), {addToRoot: true})
  167. hemiLight.name = 'Hemisphere Light'
  168. await viewer.setEnvironmentMap(getUrlQueryParam('env') ?? 'https://threejs.org/examples/textures/equirectangular/venice_sunset_1k.hdr')
  169. viewer.getPlugin(TransfrSharePlugin)!.queryParam = 'm'
  170. const model = getUrlQueryParam('m') || getUrlQueryParam('model')
  171. if (model) {
  172. await viewer.load(model)
  173. }
  174. // const result = await viewer.load<IObject3D>('https://cdn.jsdelivr.net/gh/KhronosGroup/glTF-Blender-Exporter@master/polly/project_polly.gltf', {
  175. // autoCenter: true,
  176. // autoScale: true,
  177. // })
  178. //
  179. // const model = result?.getObjectByName('Correction__MovingCamera')
  180. // const config = model?.uiConfig
  181. // console.log(model, config, result)
  182. // if (config) ui.appendChild(config)
  183. }
  184. init().finally(_testFinish)