threepipe
Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

script.ts 7.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  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. const rt = viewer.getOrAddPluginSync(RenderTargetPreviewPlugin)
  146. rt.addTarget({texture: viewer.getPlugin(GBufferPlugin)?.normalDepthTexture}, 'normalDepth')
  147. rt.addTarget({texture: viewer.getPlugin(GBufferPlugin)?.flagsTexture}, 'gBufferFlags')
  148. rt.addTarget(viewer.getPlugin(DepthBufferPlugin)?.target, 'depth', false, false, false)
  149. rt.addTarget(viewer.getPlugin(NormalBufferPlugin)?.target, 'normal', false, true, false)
  150. editor.loadPlugins({
  151. ['Viewer']: [ViewerUiConfigPlugin, SceneUiConfigPlugin, DropzonePlugin, FullScreenPlugin, TweakpaneUiPlugin, LoadingScreenPlugin, InteractionPromptPlugin],
  152. ['Scene']: [SSAAPlugin, ContactShadowGroundPlugin],
  153. ['Interaction']: [HierarchyUiPlugin, TransformControlsPlugin, PickingPlugin, Object3DGeneratorPlugin, GeometryGeneratorPlugin, EditorViewWidgetPlugin, Object3DWidgetsPlugin, MeshOptSimplifyModifierPlugin],
  154. ['GBuffer']: [GBufferPlugin, DepthBufferPlugin, NormalBufferPlugin],
  155. ['Post-processing']: [TonemapPlugin, ProgressivePlugin, SSAOPlugin, FrameFadePlugin, VignettePlugin, ChromaticAberrationPlugin, FilmicGrainPlugin],
  156. ['Export']: [AssetExporterPlugin, CanvasSnapshotPlugin, AWSClientPlugin, TransfrSharePlugin],
  157. ['Configurator']: [MaterialConfiguratorPlugin, SwitchNodePlugin, GLTFKHRMaterialVariantsPlugin],
  158. ['Animation']: [GLTFAnimationPlugin, CameraViewPlugin],
  159. ['Extras']: [HDRiGroundPlugin, Rhino3dmLoadPlugin, ClearcoatTintPlugin, FragmentClippingExtensionPlugin, NoiseBumpMaterialPlugin, CustomBumpMapPlugin, VirtualCamerasPlugin],
  160. ['Debug']: [RenderTargetPreviewPlugin],
  161. })
  162. const hemiLight = viewer.scene.addObject(new HemisphereLight(0xffffff, 0x444444, 5), {addToRoot: true})
  163. hemiLight.name = 'Hemisphere Light'
  164. await viewer.setEnvironmentMap(getUrlQueryParam('env') ?? 'https://threejs.org/examples/textures/equirectangular/venice_sunset_1k.hdr')
  165. viewer.getPlugin(TransfrSharePlugin)!.queryParam = 'm'
  166. const model = getUrlQueryParam('m') || getUrlQueryParam('model')
  167. if (model) {
  168. await viewer.load(model)
  169. }
  170. // const result = await viewer.load<IObject3D>('https://cdn.jsdelivr.net/gh/KhronosGroup/glTF-Blender-Exporter@master/polly/project_polly.gltf', {
  171. // autoCenter: true,
  172. // autoScale: true,
  173. // })
  174. //
  175. // const model = result?.getObjectByName('Correction__MovingCamera')
  176. // const config = model?.uiConfig
  177. // console.log(model, config, result)
  178. // if (config) ui.appendChild(config)
  179. }
  180. init().finally(_testFinish)