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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  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. // @ts-expect-error todo fix
  68. import {BloomPlugin, TemporalAAPlugin, VelocityBufferPlugin, DepthOfFieldPlugin, SSContactShadowsPlugin, SSReflectionPlugin} from '@threepipe/webgi-plugins'
  69. function checkQuery(key: string, def = true) {
  70. return !['false', 'no', 'f'].includes(getUrlQueryParam(key, def ? 'yes' : 'no').toLowerCase())
  71. }
  72. // const rgbm = !['false', 'no', 'f'].includes(getUrlQueryParam('rgbm', 'yes').toLowerCase())
  73. // const msaa = !['false', 'no', 'f'].includes(getUrlQueryParam('msaa', 'no').toLowerCase())
  74. // const debug = !['false', 'no', 'f'].includes(getUrlQueryParam('debug', 'no').toLowerCase())
  75. // const caching = !['false', 'no', 'f'].includes(getUrlQueryParam('cache', 'yes').toLowerCase())
  76. // const depthTonemap = !['no', 'false', 'f'].includes(getUrlQueryParam('depthTonemap', 'yes').toLowerCase() as any) // default is true
  77. // const depthPrepass = !['no', 'false', 'f'].includes(getUrlQueryParam('depthPrepass', 'yes').toLowerCase() as any) // default is true
  78. async function init() {
  79. const viewer = new ThreeViewer({
  80. canvas: document.getElementById('mcanvas') as HTMLCanvasElement,
  81. renderScale: 'auto',
  82. msaa: checkQuery('msaa', false),
  83. rgbm: checkQuery('rgbm', true),
  84. debug: checkQuery('debug', false),
  85. assetManager: {
  86. storage: checkQuery('cache', true),
  87. },
  88. // set it to true if you only have opaque objects in the scene to get better performance.
  89. zPrepass: checkQuery('depthPrepass', checkQuery('zPrepass', false)),
  90. dropzone: {
  91. addOptions: {
  92. clearSceneObjects: false, // clear the scene before adding new objects on drop.
  93. },
  94. },
  95. })
  96. // @ts-expect-error unused
  97. const ui = viewer.addPluginSync(new TweakpaneUiPlugin(true))
  98. const editor = viewer.addPluginSync(new TweakpaneEditorPlugin())
  99. await viewer.addPlugins([
  100. LoadingScreenPlugin,
  101. AssetExporterPlugin,
  102. GLTFDracoExportPlugin,
  103. PopmotionPlugin,
  104. new ProgressivePlugin(),
  105. new SSAAPlugin(),
  106. GLTFAnimationPlugin,
  107. TransformAnimationPlugin,
  108. PickingPlugin,
  109. new TransformControlsPlugin(false),
  110. EditorViewWidgetPlugin,
  111. CameraViewPlugin,
  112. ViewerUiConfigPlugin,
  113. ClearcoatTintPlugin,
  114. FragmentClippingExtensionPlugin,
  115. NoiseBumpMaterialPlugin,
  116. CustomBumpMapPlugin,
  117. new ParallaxMappingPlugin(false),
  118. GLTFKHRMaterialVariantsPlugin,
  119. VirtualCamerasPlugin,
  120. // new SceneUiConfigPlugin(), // this is already in ViewerUiPlugin
  121. new GBufferPlugin(HalfFloatType, true, true, true),
  122. new DepthBufferPlugin(HalfFloatType, false, false),
  123. new NormalBufferPlugin(HalfFloatType, false),
  124. new RenderTargetPreviewPlugin(false),
  125. new FrameFadePlugin(),
  126. new HDRiGroundPlugin(false, true),
  127. new VignettePlugin(false),
  128. new ChromaticAberrationPlugin(false),
  129. new FilmicGrainPlugin(false),
  130. new SSAOPlugin(UnsignedByteType, 1),
  131. SSReflectionPlugin,
  132. new SSContactShadowsPlugin(false),
  133. new DepthOfFieldPlugin(false),
  134. BloomPlugin,
  135. TemporalAAPlugin,
  136. new VelocityBufferPlugin(UnsignedByteType, false),
  137. KTX2LoadPlugin,
  138. KTXLoadPlugin,
  139. PLYLoadPlugin,
  140. Rhino3dmLoadPlugin,
  141. STLLoadPlugin,
  142. USDZLoadPlugin,
  143. BlendLoadPlugin,
  144. HierarchyUiPlugin,
  145. GeometryGeneratorPlugin,
  146. new Object3DWidgetsPlugin(false),
  147. Object3DGeneratorPlugin,
  148. GaussianSplattingPlugin,
  149. ContactShadowGroundPlugin,
  150. CanvasSnapshotPlugin,
  151. DeviceOrientationControlsPlugin,
  152. PointerLockControlsPlugin,
  153. ThreeFirstPersonControlsPlugin,
  154. // InteractionPromptPlugin, // todo disable when not in Viewer tab, like in webgi
  155. new MeshOptSimplifyModifierPlugin(false, document.head), // will auto-initialize on first use.
  156. new GLTFMeshOptDecodePlugin(true, document.head),
  157. // new BasicSVGRendererPlugin(false, true),
  158. ...extraImportPlugins,
  159. MaterialConfiguratorPlugin,
  160. SwitchNodePlugin,
  161. AWSClientPlugin,
  162. TransfrSharePlugin,
  163. ])
  164. // to show more details in the UI and allow to edit changes in title etc.
  165. viewer.getPlugin(MaterialConfiguratorPlugin)!.enableEditContextMenus = true
  166. viewer.getPlugin(SwitchNodePlugin)!.enableEditContextMenus = true
  167. // todo do same in blueprint editor
  168. // disable fading on update
  169. viewer.getPlugin(LoadingScreenPlugin)!.isEditor = true
  170. // disable fading on update
  171. viewer.getPlugin(FrameFadePlugin)!.isEditor = true
  172. viewer.getPlugin(TemporalAAPlugin)!.stableNoise = true
  173. const rt = viewer.getOrAddPluginSync(RenderTargetPreviewPlugin)
  174. rt.addTarget({texture: viewer.getPlugin(GBufferPlugin)?.normalDepthTexture}, 'normalDepth')
  175. rt.addTarget({texture: viewer.getPlugin(GBufferPlugin)?.flagsTexture}, 'gBufferFlags')
  176. rt.addTarget(viewer.getPlugin(DepthBufferPlugin)?.target, 'depth', false, false, false)
  177. rt.addTarget(viewer.getPlugin(NormalBufferPlugin)?.target, 'normal', false, true, false)
  178. editor.loadPlugins({
  179. ['Viewer']: [ViewerUiConfigPlugin, DropzonePlugin, FullScreenPlugin, TweakpaneUiPlugin, LoadingScreenPlugin, InteractionPromptPlugin],
  180. ['Scene']: [SSAAPlugin, SceneUiConfigPlugin, ContactShadowGroundPlugin],
  181. ['Interaction']: [HierarchyUiPlugin, TransformControlsPlugin, PickingPlugin, Object3DGeneratorPlugin, GeometryGeneratorPlugin, EditorViewWidgetPlugin, Object3DWidgetsPlugin, MeshOptSimplifyModifierPlugin],
  182. ['GBuffer']: [GBufferPlugin, DepthBufferPlugin, NormalBufferPlugin],
  183. ['Post-processing']: [TonemapPlugin, ProgressivePlugin, SSAOPlugin, SSReflectionPlugin, BloomPlugin, DepthOfFieldPlugin, FrameFadePlugin, VignettePlugin, ChromaticAberrationPlugin, FilmicGrainPlugin, TemporalAAPlugin, VelocityBufferPlugin, SSContactShadowsPlugin],
  184. ['Export']: [AssetExporterPlugin, CanvasSnapshotPlugin, AWSClientPlugin, TransfrSharePlugin],
  185. ['Configurator']: [MaterialConfiguratorPlugin, SwitchNodePlugin, GLTFKHRMaterialVariantsPlugin],
  186. ['Animation']: [GLTFAnimationPlugin, CameraViewPlugin],
  187. ['Extras']: [HDRiGroundPlugin, Rhino3dmLoadPlugin, ClearcoatTintPlugin, FragmentClippingExtensionPlugin, NoiseBumpMaterialPlugin, CustomBumpMapPlugin, VirtualCamerasPlugin],
  188. ['Debug']: [RenderTargetPreviewPlugin],
  189. })
  190. const hemiLight = viewer.scene.addObject(new HemisphereLight(0xffffff, 0x444444, 5), {addToRoot: true})
  191. hemiLight.name = 'Hemisphere Light'
  192. await viewer.setEnvironmentMap(getUrlQueryParam('env') ?? 'https://threejs.org/examples/textures/equirectangular/venice_sunset_1k.hdr')
  193. viewer.getPlugin(TransfrSharePlugin)!.queryParam = 'm'
  194. const model = getUrlQueryParam('m') || getUrlQueryParam('model')
  195. if (model) {
  196. await viewer.load(model)
  197. }
  198. // const result = await viewer.load<IObject3D>('https://cdn.jsdelivr.net/gh/KhronosGroup/glTF-Blender-Exporter@master/polly/project_polly.gltf', {
  199. // autoCenter: true,
  200. // autoScale: true,
  201. // })
  202. //
  203. // const model = result?.getObjectByName('Correction__MovingCamera')
  204. // const config = model?.uiConfig
  205. // console.log(model, config, result)
  206. // if (config) ui.appendChild(config)
  207. }
  208. init().finally(_testFinish)