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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. import {
  2. _testFinish,
  3. CameraViewPlugin,
  4. CanvasSnapshotPlugin,
  5. ChromaticAberrationPlugin,
  6. ClearcoatTintPlugin,
  7. ContactShadowGroundPlugin,
  8. CustomBumpMapPlugin,
  9. DeviceOrientationControlsPlugin,
  10. DropzonePlugin,
  11. EditorViewWidgetPlugin,
  12. FilmicGrainPlugin,
  13. FragmentClippingExtensionPlugin,
  14. FrameFadePlugin,
  15. GBufferPlugin,
  16. getUrlQueryParam,
  17. GLTFAnimationPlugin,
  18. GLTFKHRMaterialVariantsPlugin,
  19. GLTFMeshOptDecodePlugin,
  20. HalfFloatType,
  21. HDRiGroundPlugin,
  22. HemisphereLight,
  23. InteractionPromptPlugin,
  24. KTX2LoadPlugin,
  25. KTXLoadPlugin,
  26. LoadingScreenPlugin,
  27. NoiseBumpMaterialPlugin,
  28. Object3DGeneratorPlugin,
  29. Object3DWidgetsPlugin,
  30. ParallaxMappingPlugin,
  31. PickingPlugin,
  32. PLYLoadPlugin,
  33. PointerLockControlsPlugin, PopmotionPlugin,
  34. ProgressivePlugin,
  35. RenderTargetPreviewPlugin,
  36. Rhino3dmLoadPlugin,
  37. SSAAPlugin,
  38. SSAOPlugin,
  39. STLLoadPlugin,
  40. ThreeFirstPersonControlsPlugin,
  41. ThreeViewer, TransformAnimationPlugin,
  42. TransformControlsPlugin,
  43. UnsignedByteType,
  44. USDZLoadPlugin,
  45. ViewerUiConfigPlugin,
  46. VignettePlugin,
  47. VirtualCamerasPlugin,
  48. } from 'threepipe'
  49. import {GaussianSplattingPlugin} from '@threepipe/plugin-gaussian-splatting'
  50. import {MaterialConfiguratorPlugin, SwitchNodePlugin} from '@threepipe/plugin-configurator'
  51. import {BlendLoadPlugin} from '@threepipe/plugin-blend-importer'
  52. import {extraImportPlugins} from '@threepipe/plugins-extra-importers'
  53. import {AWSClientPlugin} from '@threepipe/plugin-network'
  54. import {
  55. B3DMLoadPlugin,
  56. CMPTLoadPlugin,
  57. DeepZoomImageLoadPlugin,
  58. I3DMLoadPlugin,
  59. PNTSLoadPlugin,
  60. TilesRendererPlugin,
  61. } from '@threepipe/plugin-3d-tiles-renderer'
  62. // @ts-expect-error todo fix import
  63. import {BloomPlugin, DepthOfFieldPlugin, SSContactShadowsPlugin, SSReflectionPlugin, TemporalAAPlugin, VelocityBufferPlugin, SSGIPlugin, AnisotropyPlugin} from '@threepipe/webgi-plugins'
  64. function checkQuery(key: string, def = true) {
  65. return !['false', 'no', 'f'].includes(getUrlQueryParam(key, def ? 'yes' : 'no').toLowerCase())
  66. }
  67. async function init() {
  68. const viewer = new ThreeViewer({
  69. canvas: document.getElementById('mcanvas') as HTMLCanvasElement,
  70. renderScale: 'auto',
  71. msaa: checkQuery('msaa', true),
  72. rgbm: checkQuery('rgbm', true),
  73. debug: checkQuery('debug', false),
  74. assetManager: {
  75. storage: checkQuery('cache', true),
  76. },
  77. // set it to true if you only have opaque objects in the scene to get better performance.
  78. zPrepass: checkQuery('depthPrepass', checkQuery('zPrepass', false)),
  79. modelRootScale: parseFloat(getUrlQueryParam('modelRootScale', '1')),
  80. dropzone: { // this can also be set to true and configured by getting a reference to the DropzonePlugin
  81. // allowedExtensions: ['gltf', 'glb', 'hdr', 'bin', 'png', 'jpeg', 'webp', 'jpg', 'exr', 'fbx', 'obj'], // only allow these file types. If undefined, all files are allowed.
  82. addOptions: {
  83. disposeSceneObjects: true, // auto dispose of old scene objects
  84. autoSetEnvironment: true, // when hdr is dropped
  85. autoSetBackground: true, // when any image is dropped
  86. autoScale: checkQuery('autoScale', true), // auto scale according to radius
  87. autoCenter: checkQuery('autoCenter', true), // auto center the object
  88. autoScaleRadius: parseFloat(getUrlQueryParam('autoScaleRadius', '2')),
  89. // license: 'Imported from dropzone', // Any license to set on imported objects
  90. importConfig: true, // import config from file
  91. },
  92. },
  93. })
  94. await viewer.addPlugins([
  95. LoadingScreenPlugin,
  96. PopmotionPlugin,
  97. new ProgressivePlugin(),
  98. new SSAAPlugin(),
  99. GLTFAnimationPlugin,
  100. TransformAnimationPlugin,
  101. new GBufferPlugin(HalfFloatType, true, true, true),
  102. PickingPlugin,
  103. new TransformControlsPlugin(false),
  104. // OutlinePlugin,
  105. EditorViewWidgetPlugin,
  106. CameraViewPlugin,
  107. ViewerUiConfigPlugin,
  108. ClearcoatTintPlugin,
  109. FragmentClippingExtensionPlugin,
  110. NoiseBumpMaterialPlugin,
  111. CustomBumpMapPlugin,
  112. AnisotropyPlugin,
  113. new ParallaxMappingPlugin(false),
  114. GLTFKHRMaterialVariantsPlugin,
  115. VirtualCamerasPlugin,
  116. // new SceneUiConfigPlugin(), // this is already in ViewerUiPlugin
  117. new RenderTargetPreviewPlugin(false),
  118. new FrameFadePlugin(),
  119. new HDRiGroundPlugin(false, true),
  120. new VignettePlugin(false),
  121. new ChromaticAberrationPlugin(false),
  122. new FilmicGrainPlugin(false),
  123. new SSAOPlugin(UnsignedByteType, 1),
  124. SSReflectionPlugin,
  125. new SSContactShadowsPlugin(false),
  126. new DepthOfFieldPlugin(false),
  127. BloomPlugin,
  128. TemporalAAPlugin,
  129. new VelocityBufferPlugin(UnsignedByteType, false),
  130. new SSGIPlugin(UnsignedByteType, 1, false),
  131. KTX2LoadPlugin,
  132. KTXLoadPlugin,
  133. PLYLoadPlugin,
  134. Rhino3dmLoadPlugin,
  135. STLLoadPlugin,
  136. USDZLoadPlugin,
  137. BlendLoadPlugin,
  138. Object3DWidgetsPlugin,
  139. Object3DGeneratorPlugin,
  140. GaussianSplattingPlugin,
  141. ContactShadowGroundPlugin,
  142. CanvasSnapshotPlugin,
  143. DeviceOrientationControlsPlugin,
  144. PointerLockControlsPlugin,
  145. ThreeFirstPersonControlsPlugin,
  146. InteractionPromptPlugin,
  147. // new MeshOptSimplifyModifierPlugin(false, document.head), // will auto-initialize on first use.
  148. new GLTFMeshOptDecodePlugin(true, document.head),
  149. // new BasicSVGRendererPlugin(false, true),
  150. ...extraImportPlugins,
  151. MaterialConfiguratorPlugin,
  152. SwitchNodePlugin,
  153. AWSClientPlugin,
  154. B3DMLoadPlugin, I3DMLoadPlugin, PNTSLoadPlugin, CMPTLoadPlugin,
  155. TilesRendererPlugin, DeepZoomImageLoadPlugin, /* SlippyMapTilesLoadPlugin,*/
  156. ])
  157. const hemiLight = viewer.scene.addObject(new HemisphereLight(0xffffff, 0x444444, 5), {addToRoot: true})
  158. hemiLight.name = 'Hemisphere Light'
  159. await viewer.setEnvironmentMap(getUrlQueryParam('env') ?? 'https://threejs.org/examples/textures/equirectangular/venice_sunset_1k.hdr')
  160. const model = getUrlQueryParam('m') || getUrlQueryParam('model')
  161. if (model) {
  162. const ext = getUrlQueryParam('ext') || getUrlQueryParam('model-extension')
  163. const loader = viewer.getPlugin(DropzonePlugin) ?? viewer
  164. const obj = await loader.load(model, {fileExtension: ext})
  165. console.log(obj)
  166. const promptDiv = document.getElementById('prompt-div')!
  167. promptDiv.style.display = 'none'
  168. }
  169. const dropzone = viewer.getPlugin(DropzonePlugin)!
  170. dropzone.addEventListener('drop', (e: any) => {
  171. if (!e.assets?.length) return // no assets imported
  172. console.log('Dropped Event:', e)
  173. const promptDiv = document.getElementById('prompt-div')!
  174. promptDiv.style.display = 'none'
  175. })
  176. }
  177. init().finally(_testFinish)